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_init,
7       BN_RECP_CTX_free, BN_RECP_CTX_set - modular multiplication using
8       reciprocal
9

SYNOPSIS

11        #include <openssl/bn.h>
12
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);
16
17        int BN_RECP_CTX_set(BN_RECP_CTX *recp, const BIGNUM *m, BN_CTX *ctx);
18
19        int BN_div_recp(BIGNUM *dv, BIGNUM *rem, BIGNUM *a, BN_RECP_CTX *recp,
20               BN_CTX *ctx);
21
22        int BN_mod_mul_reciprocal(BIGNUM *r, BIGNUM *a, BIGNUM *b,
23               BN_RECP_CTX *recp, BN_CTX *ctx);
24

DESCRIPTION

26       BN_mod_mul_reciprocal() can be used to perform an efficient
27       BN_mod_mul(3) operation when the operation will be performed repeatedly
28       with the same modulus. It computes r=(a*b)%m using recp=1/m, which is
29       set as described below.  ctx is a previously allocated BN_CTX used for
30       temporary variables.
31
32       BN_RECP_CTX_new() allocates and initializes a BN_RECP structure.
33       BN_RECP_CTX_init() initializes an existing uninitialized BN_RECP.
34
35       BN_RECP_CTX_free() frees the components of the BN_RECP, and, if it was
36       created by BN_RECP_CTX_new(), also the structure itself.
37
38       BN_RECP_CTX_set() stores m in recp and sets it up for computing 1/m and
39       shifting it left by BN_num_bits(m)+1 to make it an integer. The result
40       and the number of bits it was shifted left will later be stored in
41       recp.
42
43       BN_div_recp() divides a by m using recp. It places the quotient in dv
44       and the remainder in rem.
45
46       The BN_RECP_CTX structure is defined as follows:
47
48        typedef struct bn_recp_ctx_st
49               {
50               BIGNUM N;       /* the divisor */
51               BIGNUM Nr;      /* the reciprocal */
52               int num_bits;
53               int shift;
54               int flags;
55               } BN_RECP_CTX;
56
57       It cannot be shared between threads.
58

RETURN VALUES

60       BN_RECP_CTX_new() returns the newly allocated BN_RECP_CTX, and NULL on
61       error.
62
63       BN_RECP_CTX_init() and BN_RECP_CTX_free() have no return values.
64
65       For the other functions, 1 is returned for success, 0 on error.  The
66       error codes can be obtained by ERR_get_error(3).
67

SEE ALSO

69       bn(3), ERR_get_error(3), BN_add(3), BN_CTX_new(3)
70

HISTORY

72       BN_RECP_CTX was added in SSLeay 0.9.0. Before that, the function
73       BN_reciprocal() was used instead, and the BN_mod_mul_reciprocal()
74       arguments were different.
75
76
77
781.0.2o                            2018-03-27          BN_mod_mul_reciprocal(3)
Impressum