BN_mod_exp_mont.pod 2.6 KB

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