BN_mod_mul_montgomery.pod 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. =pod
  2. =head1 NAME
  3. BN_mod_mul_montgomery, BN_MONT_CTX_new,
  4. BN_MONT_CTX_free, BN_MONT_CTX_set, BN_MONT_CTX_copy,
  5. BN_from_montgomery, BN_to_montgomery - Montgomery multiplication
  6. =head1 SYNOPSIS
  7. #include <openssl/bn.h>
  8. BN_MONT_CTX *BN_MONT_CTX_new(void);
  9. void BN_MONT_CTX_free(BN_MONT_CTX *mont);
  10. int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *m, BN_CTX *ctx);
  11. BN_MONT_CTX *BN_MONT_CTX_copy(BN_MONT_CTX *to, BN_MONT_CTX *from);
  12. int BN_mod_mul_montgomery(BIGNUM *r, BIGNUM *a, BIGNUM *b,
  13. BN_MONT_CTX *mont, BN_CTX *ctx);
  14. int BN_from_montgomery(BIGNUM *r, BIGNUM *a, BN_MONT_CTX *mont,
  15. BN_CTX *ctx);
  16. int BN_to_montgomery(BIGNUM *r, BIGNUM *a, BN_MONT_CTX *mont,
  17. BN_CTX *ctx);
  18. =head1 DESCRIPTION
  19. These functions implement Montgomery multiplication. They are used
  20. automatically when L<BN_mod_exp(3)> is called with suitable input,
  21. but they may be useful when several operations are to be performed
  22. using the same modulus.
  23. BN_MONT_CTX_new() allocates and initializes a B<BN_MONT_CTX> structure.
  24. BN_MONT_CTX_set() sets up the I<mont> structure from the modulus I<m>
  25. by precomputing its inverse and a value R.
  26. BN_MONT_CTX_copy() copies the B<BN_MONT_CTX> I<from> to I<to>.
  27. BN_MONT_CTX_free() frees the components of the B<BN_MONT_CTX>, and, if
  28. it was created by BN_MONT_CTX_new(), also the structure itself.
  29. If B<mont> is NULL, nothing is done.
  30. BN_mod_mul_montgomery() computes Mont(I<a>,I<b>):=I<a>*I<b>*R^-1 and places
  31. the result in I<r>.
  32. BN_from_montgomery() performs the Montgomery reduction I<r> = I<a>*R^-1.
  33. BN_to_montgomery() computes Mont(I<a>,R^2), i.e. I<a>*R.
  34. Note that I<a> must be non-negative and smaller than the modulus.
  35. For all functions, I<ctx> is a previously allocated B<BN_CTX> used for
  36. temporary variables.
  37. =head1 RETURN VALUES
  38. BN_MONT_CTX_new() returns the newly allocated B<BN_MONT_CTX>, and NULL
  39. on error.
  40. BN_MONT_CTX_free() has no return value.
  41. For the other functions, 1 is returned for success, 0 on error.
  42. The error codes can be obtained by L<ERR_get_error(3)>.
  43. =head1 WARNING
  44. The inputs must be reduced modulo B<m>, otherwise the result will be
  45. outside the expected range.
  46. =head1 SEE ALSO
  47. L<ERR_get_error(3)>, L<BN_add(3)>,
  48. L<BN_CTX_new(3)>
  49. =head1 HISTORY
  50. BN_MONT_CTX_init() was removed in OpenSSL 1.1.0
  51. =head1 COPYRIGHT
  52. Copyright 2000-2017 The OpenSSL Project Authors. All Rights Reserved.
  53. Licensed under the OpenSSL license (the "License"). You may not use
  54. this file except in compliance with the License. You can obtain a copy
  55. in the file LICENSE in the source distribution or at
  56. L<https://www.openssl.org/source/license.html>.
  57. =cut