5 BN_mod_mul_reciprocal, BN_div_recp, BN_RECP_CTX_new,
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_free(BN_RECP_CTX *recp);
16 int BN_RECP_CTX_set(BN_RECP_CTX *recp, const BIGNUM *m, BN_CTX *ctx);
18 int BN_div_recp(BIGNUM *dv, BIGNUM *rem, BIGNUM *a, BN_RECP_CTX *recp,
21 int BN_mod_mul_reciprocal(BIGNUM *r, BIGNUM *a, BIGNUM *b,
22 BN_RECP_CTX *recp, BN_CTX *ctx);
26 BN_mod_mul_reciprocal() can be used to perform an efficient
27 L<BN_mod_mul(3)> operation when the operation will be performed
28 repeatedly with the same modulus. It computes B<r>=(B<a>*B<b>)%B<m>
29 using B<recp>=1/B<m>, which is set as described below. B<ctx> is a
30 previously allocated B<BN_CTX> used for temporary variables.
32 BN_RECP_CTX_new() allocates and initializes a B<BN_RECP> structure.
34 BN_RECP_CTX_free() frees the components of the B<BN_RECP>, and, if it
35 was created by BN_RECP_CTX_new(), also the structure itself.
36 If B<recp> is NULL, nothing is done.
38 BN_RECP_CTX_set() stores B<m> in B<recp> and sets it up for computing
39 1/B<m> and shifting it left by BN_num_bits(B<m>)+1 to make it an
40 integer. The result and the number of bits it was shifted left will
41 later be stored in B<recp>.
43 BN_div_recp() divides B<a> by B<m> using B<recp>. It places the quotient
44 in B<dv> and the remainder in B<rem>.
46 The B<BN_RECP_CTX> structure cannot be shared between threads.
50 BN_RECP_CTX_new() returns the newly allocated B<BN_RECP_CTX>, and NULL
53 BN_RECP_CTX_free() has no return value.
55 For the other functions, 1 is returned for success, 0 on error.
56 The error codes can be obtained by L<ERR_get_error(3)>.
60 L<bn(3)>, L<ERR_get_error(3)>, L<BN_add(3)>,
65 BN_RECP_CTX_init() was removed in OpenSSL 1.1.0
69 Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved.
71 Licensed under the OpenSSL license (the "License"). You may not use
72 this file except in compliance with the License. You can obtain a copy
73 in the file LICENSE in the source distribution or at
74 L<https://www.openssl.org/source/license.html>.