Path: blob/main/crypto/openssl/crypto/bn/rsaz_exp.h
34884 views
/*1* Copyright 2013-2025 The OpenSSL Project Authors. All Rights Reserved.2* Copyright (c) 2020, Intel Corporation. All Rights Reserved.3*4* Licensed under the Apache License 2.0 (the "License"). You may not use5* this file except in compliance with the License. You can obtain a copy6* in the file LICENSE in the source distribution or at7* https://www.openssl.org/source/license.html8*9* Originally written by Shay Gueron (1, 2), and Vlad Krasnov (1)10* (1) Intel Corporation, Israel Development Center, Haifa, Israel11* (2) University of Haifa, Israel12*/1314#ifndef OSSL_CRYPTO_BN_RSAZ_EXP_H15# define OSSL_CRYPTO_BN_RSAZ_EXP_H1617# undef RSAZ_ENABLED18# if defined(OPENSSL_BN_ASM_MONT) && \19(defined(__x86_64) || defined(__x86_64__) || \20defined(_M_AMD64) || defined(_M_X64))21# define RSAZ_ENABLED2223# include <openssl/bn.h>24# include "internal/constant_time.h"25# include "bn_local.h"2627void RSAZ_1024_mod_exp_avx2(BN_ULONG result[16],28const BN_ULONG base_norm[16],29const BN_ULONG exponent[16],30const BN_ULONG m_norm[16], const BN_ULONG RR[16],31BN_ULONG k0);32int rsaz_avx2_eligible(void);3334void RSAZ_512_mod_exp(BN_ULONG result[8],35const BN_ULONG base_norm[8], const BN_ULONG exponent[8],36const BN_ULONG m_norm[8], BN_ULONG k0,37const BN_ULONG RR[8]);383940int ossl_rsaz_avx512ifma_eligible(void);4142int ossl_rsaz_avxifma_eligible(void);4344int ossl_rsaz_mod_exp_avx512_x2(BN_ULONG *res1,45const BN_ULONG *base1,46const BN_ULONG *exponent1,47const BN_ULONG *m1,48const BN_ULONG *RR1,49BN_ULONG k0_1,50BN_ULONG *res2,51const BN_ULONG *base2,52const BN_ULONG *exponent2,53const BN_ULONG *m2,54const BN_ULONG *RR2,55BN_ULONG k0_2,56int factor_size);5758static ossl_inline void bn_select_words(BN_ULONG *r, BN_ULONG mask,59const BN_ULONG *a,60const BN_ULONG *b, size_t num)61{62size_t i;6364for (i = 0; i < num; i++) {65r[i] = constant_time_select_64(mask, a[i], b[i]);66}67}6869static ossl_inline BN_ULONG bn_reduce_once_in_place(BN_ULONG *r,70BN_ULONG carry,71const BN_ULONG *m,72BN_ULONG *tmp, size_t num)73{74carry -= bn_sub_words(tmp, r, m, num);75bn_select_words(r, carry, r /* tmp < 0 */, tmp /* tmp >= 0 */, num);76return carry;77}7879# endif8081#endif828384