1BN_MOD_MUL_RECIPROCAL(3)            OpenSSL           BN_MOD_MUL_RECIPROCAL(3)
2
3
4

NAME

6       BN_mod_mul_reciprocal, BN_div_recp, BN_RECP_CTX_new, BN_RECP_CTX_free,
7       BN_RECP_CTX_set - modular multiplication using reciprocal
8

SYNOPSIS

10        #include <openssl/bn.h>
11
12        BN_RECP_CTX *BN_RECP_CTX_new(void);
13        void BN_RECP_CTX_free(BN_RECP_CTX *recp);
14
15        int BN_RECP_CTX_set(BN_RECP_CTX *recp, const BIGNUM *m, BN_CTX *ctx);
16
17        int BN_div_recp(BIGNUM *dv, BIGNUM *rem, BIGNUM *a, BN_RECP_CTX *recp,
18                        BN_CTX *ctx);
19
20        int BN_mod_mul_reciprocal(BIGNUM *r, BIGNUM *a, BIGNUM *b,
21                                  BN_RECP_CTX *recp, BN_CTX *ctx);
22

DESCRIPTION

24       BN_mod_mul_reciprocal() can be used to perform an efficient
25       BN_mod_mul(3) operation when the operation will be performed repeatedly
26       with the same modulus. It computes r=(a*b)%m using recp=1/m, which is
27       set as described below.  ctx is a previously allocated BN_CTX used for
28       temporary variables.
29
30       BN_RECP_CTX_new() allocates and initializes a BN_RECP structure.
31
32       BN_RECP_CTX_free() frees the components of the BN_RECP, and, if it was
33       created by BN_RECP_CTX_new(), also the structure itself.  If recp is
34       NULL, nothing is done.
35
36       BN_RECP_CTX_set() stores m in recp and sets it up for computing 1/m and
37       shifting it left by BN_num_bits(m)+1 to make it an integer. The result
38       and the number of bits it was shifted left will later be stored in
39       recp.
40
41       BN_div_recp() divides a by m using recp. It places the quotient in dv
42       and the remainder in rem.
43
44       The BN_RECP_CTX structure cannot be shared between threads.
45

RETURN VALUES

47       BN_RECP_CTX_new() returns the newly allocated BN_RECP_CTX, and NULL on
48       error.
49
50       BN_RECP_CTX_free() has no return value.
51
52       For the other functions, 1 is returned for success, 0 on error.  The
53       error codes can be obtained by ERR_get_error(3).
54

SEE ALSO

56       ERR_get_error(3), BN_add(3), BN_CTX_new(3)
57

HISTORY

59       BN_RECP_CTX_init() was removed in OpenSSL 1.1.0
60
62       Copyright 2000-2017 The OpenSSL Project Authors. All Rights Reserved.
63
64       Licensed under the OpenSSL license (the "License").  You may not use
65       this file except in compliance with the License.  You can obtain a copy
66       in the file LICENSE in the source distribution or at
67       <https://www.openssl.org/source/license.html>.
68
69
70
711.1.1q                            2022-07-07          BN_MOD_MUL_RECIPROCAL(3)
Impressum