BN_mod_mul_reciprocal.pod 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. =pod
  2. =head1 NAME
  3. BN_mod_mul_reciprocal, BN_div_recp, BN_RECP_CTX_new, BN_RECP_CTX_init,
  4. BN_RECP_CTX_free, BN_RECP_CTX_set - modular multiplication using
  5. reciprocal
  6. =head1 SYNOPSIS
  7. #include <openssl/bn.h>
  8. BN_RECP_CTX *BN_RECP_CTX_new(void);
  9. void BN_RECP_CTX_init(BN_RECP_CTX *recp);
  10. void BN_RECP_CTX_free(BN_RECP_CTX *recp);
  11. int BN_RECP_CTX_set(BN_RECP_CTX *recp, const BIGNUM *m, BN_CTX *ctx);
  12. int BN_div_recp(BIGNUM *dv, BIGNUM *rem, BIGNUM *a, BN_RECP_CTX *recp,
  13. BN_CTX *ctx);
  14. int BN_mod_mul_reciprocal(BIGNUM *r, BIGNUM *a, BIGNUM *b,
  15. BN_RECP_CTX *recp, BN_CTX *ctx);
  16. =head1 DESCRIPTION
  17. BN_mod_mul_reciprocal() can be used to perform an efficient
  18. L<BN_mod_mul(3)|BN_mod_mul(3)> operation when the operation will be performed
  19. repeatedly with the same modulus. It computes B<r>=(B<a>*B<b>)%B<m>
  20. using B<recp>=1/B<m>, which is set as described below. B<ctx> is a
  21. previously allocated B<BN_CTX> used for temporary variables.
  22. BN_RECP_CTX_new() allocates and initializes a B<BN_RECP> structure.
  23. BN_RECP_CTX_init() initializes an existing uninitialized B<BN_RECP>.
  24. BN_RECP_CTX_free() frees the components of the B<BN_RECP>, and, if it
  25. was created by BN_RECP_CTX_new(), also the structure itself.
  26. BN_RECP_CTX_set() stores B<m> in B<recp> and sets it up for computing
  27. 1/B<m> and shifting it left by BN_num_bits(B<m>)+1 to make it an
  28. integer. The result and the number of bits it was shifted left will
  29. later be stored in B<recp>.
  30. BN_div_recp() divides B<a> by B<m> using B<recp>. It places the quotient
  31. in B<dv> and the remainder in B<rem>.
  32. The B<BN_RECP_CTX> structure is defined as follows:
  33. typedef struct bn_recp_ctx_st
  34. {
  35. BIGNUM N; /* the divisor */
  36. BIGNUM Nr; /* the reciprocal */
  37. int num_bits;
  38. int shift;
  39. int flags;
  40. } BN_RECP_CTX;
  41. It cannot be shared between threads.
  42. =head1 RETURN VALUES
  43. BN_RECP_CTX_new() returns the newly allocated B<BN_RECP_CTX>, and NULL
  44. on error.
  45. BN_RECP_CTX_init() and BN_RECP_CTX_free() have no return values.
  46. For the other functions, 1 is returned for success, 0 on error.
  47. The error codes can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
  48. =head1 SEE ALSO
  49. L<bn(3)|bn(3)>, L<ERR_get_error(3)|ERR_get_error(3)>, L<BN_add(3)|BN_add(3)>,
  50. L<BN_CTX_new(3)|BN_CTX_new(3)>
  51. =head1 HISTORY
  52. B<BN_RECP_CTX> was added in SSLeay 0.9.0. Before that, the function
  53. BN_reciprocal() was used instead, and the BN_mod_mul_reciprocal()
  54. arguments were different.
  55. =cut