1*b077aed3SPierre Pronchery=pod 2*b077aed3SPierre Pronchery 3*b077aed3SPierre Pronchery=head1 NAME 4*b077aed3SPierre Pronchery 5*b077aed3SPierre ProncheryBN_mod_exp_mont, BN_mod_exp_mont_consttime, BN_mod_exp_mont_consttime_x2 - 6*b077aed3SPierre ProncheryMontgomery exponentiation 7*b077aed3SPierre Pronchery 8*b077aed3SPierre Pronchery=head1 SYNOPSIS 9*b077aed3SPierre Pronchery 10*b077aed3SPierre Pronchery #include <openssl/bn.h> 11*b077aed3SPierre Pronchery 12*b077aed3SPierre Pronchery int BN_mod_exp_mont(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p, 13*b077aed3SPierre Pronchery const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont); 14*b077aed3SPierre Pronchery 15*b077aed3SPierre Pronchery int BN_mod_exp_mont_consttime(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p, 16*b077aed3SPierre Pronchery const BIGNUM *m, BN_CTX *ctx, 17*b077aed3SPierre Pronchery BN_MONT_CTX *in_mont); 18*b077aed3SPierre Pronchery 19*b077aed3SPierre Pronchery int BN_mod_exp_mont_consttime_x2(BIGNUM *rr1, const BIGNUM *a1, 20*b077aed3SPierre Pronchery const BIGNUM *p1, const BIGNUM *m1, 21*b077aed3SPierre Pronchery BN_MONT_CTX *in_mont1, BIGNUM *rr2, 22*b077aed3SPierre Pronchery const BIGNUM *a2, const BIGNUM *p2, 23*b077aed3SPierre Pronchery const BIGNUM *m2, BN_MONT_CTX *in_mont2, 24*b077aed3SPierre Pronchery BN_CTX *ctx); 25*b077aed3SPierre Pronchery 26*b077aed3SPierre Pronchery=head1 DESCRIPTION 27*b077aed3SPierre Pronchery 28*b077aed3SPierre ProncheryBN_mod_exp_mont() computes I<a> to the I<p>-th power modulo I<m> (C<rr=a^p % m>) 29*b077aed3SPierre Proncheryusing Montgomery multiplication. I<in_mont> is a Montgomery context and can be 30*b077aed3SPierre ProncheryNULL. In the case I<in_mont> is NULL, it will be initialized within the 31*b077aed3SPierre Proncheryfunction, so you can save time on initialization if you provide it in advance. 32*b077aed3SPierre Pronchery 33*b077aed3SPierre ProncheryBN_mod_exp_mont_consttime() computes I<a> to the I<p>-th power modulo I<m> 34*b077aed3SPierre Pronchery(C<rr=a^p % m>) using Montgomery multiplication. It is a variant of 35*b077aed3SPierre ProncheryL<BN_mod_exp_mont(3)> that uses fixed windows and the special precomputation 36*b077aed3SPierre Proncherymemory layout to limit data-dependency to a minimum to protect secret exponents. 37*b077aed3SPierre ProncheryIt is called automatically when L<BN_mod_exp_mont(3)> is called with parameters 38*b077aed3SPierre ProncheryI<a>, I<p>, I<m>, any of which have B<BN_FLG_CONSTTIME> flag. 39*b077aed3SPierre Pronchery 40*b077aed3SPierre ProncheryBN_mod_exp_mont_consttime_x2() computes two independent exponentiations I<a1> to 41*b077aed3SPierre Proncherythe I<p1>-th power modulo I<m1> (C<rr1=a1^p1 % m1>) and I<a2> to the I<p2>-th 42*b077aed3SPierre Proncherypower modulo I<m2> (C<rr2=a2^p2 % m2>) using Montgomery multiplication. For some 43*b077aed3SPierre Proncheryfixed and equal modulus sizes I<m1> and I<m2> it uses optimizations that allow 44*b077aed3SPierre Proncheryto speedup two exponentiations. In all other cases the function reduces to two 45*b077aed3SPierre Proncherycalls of L<BN_mod_exp_mont_consttime(3)>. 46*b077aed3SPierre Pronchery 47*b077aed3SPierre Pronchery=head1 RETURN VALUES 48*b077aed3SPierre Pronchery 49*b077aed3SPierre ProncheryFor all functions 1 is returned for success, 0 on error. 50*b077aed3SPierre ProncheryThe error codes can be obtained by L<ERR_get_error(3)>. 51*b077aed3SPierre Pronchery 52*b077aed3SPierre Pronchery=head1 SEE ALSO 53*b077aed3SPierre Pronchery 54*b077aed3SPierre ProncheryL<ERR_get_error(3)>, L<BN_mod_exp_mont(3)> 55*b077aed3SPierre Pronchery 56*b077aed3SPierre Pronchery=head1 COPYRIGHT 57*b077aed3SPierre Pronchery 58*b077aed3SPierre ProncheryCopyright 2000-2021 The OpenSSL Project Authors. All Rights Reserved. 59*b077aed3SPierre Pronchery 60*b077aed3SPierre ProncheryLicensed under the Apache License 2.0 (the "License"). You may not use 61*b077aed3SPierre Proncherythis file except in compliance with the License. You can obtain a copy 62*b077aed3SPierre Proncheryin the file LICENSE in the source distribution or at 63*b077aed3SPierre ProncheryL<https://www.openssl.org/source/license.html>. 64*b077aed3SPierre Pronchery 65*b077aed3SPierre Pronchery=cut 66