Path: blob/main/crypto/openssl/crypto/bn/rsaz_exp.h
107750 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) && (defined(__x86_64) || defined(__x86_64__) || defined(_M_AMD64) || defined(_M_X64))19#define RSAZ_ENABLED2021#include <openssl/bn.h>22#include "internal/constant_time.h"23#include "bn_local.h"2425void RSAZ_1024_mod_exp_avx2(BN_ULONG result[16],26const BN_ULONG base_norm[16],27const BN_ULONG exponent[16],28const BN_ULONG m_norm[16], const BN_ULONG RR[16],29BN_ULONG k0);30int rsaz_avx2_eligible(void);3132void RSAZ_512_mod_exp(BN_ULONG result[8],33const BN_ULONG base_norm[8], const BN_ULONG exponent[8],34const BN_ULONG m_norm[8], BN_ULONG k0,35const BN_ULONG RR[8]);3637int ossl_rsaz_avx512ifma_eligible(void);3839int ossl_rsaz_avxifma_eligible(void);4041int ossl_rsaz_mod_exp_avx512_x2(BN_ULONG *res1,42const BN_ULONG *base1,43const BN_ULONG *exponent1,44const BN_ULONG *m1,45const BN_ULONG *RR1,46BN_ULONG k0_1,47BN_ULONG *res2,48const BN_ULONG *base2,49const BN_ULONG *exponent2,50const BN_ULONG *m2,51const BN_ULONG *RR2,52BN_ULONG k0_2,53int factor_size);5455static ossl_inline void bn_select_words(BN_ULONG *r, BN_ULONG mask,56const BN_ULONG *a,57const BN_ULONG *b, size_t num)58{59size_t i;6061for (i = 0; i < num; i++) {62r[i] = constant_time_select_64(mask, a[i], b[i]);63}64}6566static ossl_inline BN_ULONG bn_reduce_once_in_place(BN_ULONG *r,67BN_ULONG carry,68const BN_ULONG *m,69BN_ULONG *tmp, size_t num)70{71carry -= bn_sub_words(tmp, r, m, num);72bn_select_words(r, carry, r /* tmp < 0 */, tmp /* tmp >= 0 */, num);73return carry;74}7576#endif7778#endif798081