5 BN_mod_mul_reciprocal, BN_RECP_CTX_new, BN_RECP_CTX_init,
6 BN_RECP_CTX_free, BN_RECP_CTX_set - Modular multiplication using
11 #include <openssl/bn.h>
13 BN_RECP_CTX *BN_RECP_CTX_new(void);
14 void BN_RECP_CTX_init(BN_RECP_CTX *recp);
15 void BN_RECP_CTX_free(BN_RECP_CTX *recp);
17 int BN_RECP_CTX_set(BN_RECP_CTX *recp, const BIGNUM *m, BN_CTX *ctx);
19 int BN_mod_mul_reciprocal(BIGNUM *r, BIGNUM *a, BIGNUM *b,
20 BN_RECP_CTX *recp, BN_CTX *ctx);
24 BN_mod_mul_reciprocal() can be used to perform an efficient
25 L<BN_mod_mul(3)|BN_mod_mul(3)> operation when the operation will be performed
26 repeatedly with the same modulus. It computes B<r>=(B<a>*B<b>)%B<m>
27 using B<recp>=1/B<m>, which is set as described below. B<ctx> is a
28 previously allocated B<BN_CTX> used for temporary variables.
30 BN_RECP_CTX_new() allocates and initializes a B<BN_RECP> structure.
31 BN_RECP_CTX_init() initializes an existing uninitialized B<BN_RECP>.
33 BN_RECP_CTX_free() frees the components of the B<BN_RECP>, and, if it
34 was created by BN_RECP_CTX_new(), also the structure itself.
36 BN_RECP_CTX_set() computes 1/B<m> and shifts it left by
37 BN_num_bits(B<m>)+1 to make it an integer. The result and the
38 number of bits it was shifted left are stored in B<recp>.
40 The B<BN_RECP_CTX> structure is defined as follows:
42 typedef struct bn_recp_ctx_st
44 BIGNUM N; /* the divisor */
45 BIGNUM Nr; /* the reciprocal */
51 It cannot be shared between threads.
55 BN_RECP_CTX_new() returns the newly allocated B<BN_RECP_CTX>, and NULL
58 BN_RECP_CTX_init() and BN_RECP_CTX_free() have no return values.
60 For the other functions, 1 is returned for success, 0 on error.
61 The error codes can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
65 L<bn(3)|bn(3)>, L<err(3)|err(3)>, L<BN_add(3)|BN_add(3)>,
66 L<BN_CTX_new(3)|BN_CTX_new(3)>
70 B<BN_RECP_CTX> was added in SSLeay 0.9.0. Before that, the function
71 BN_reciprocal() was used instead, and the BN_mod_mul_reciprocal()
72 arguments were different.