1BN_mod_mul_montgomery(3)            OpenSSL           BN_mod_mul_montgomery(3)
2
3
4

NAME

6       BN_mod_mul_montgomery, BN_MONT_CTX_new, BN_MONT_CTX_init,
7       BN_MONT_CTX_free, BN_MONT_CTX_set, BN_MONT_CTX_copy, BN_from_mont‐
8       gomery, BN_to_montgomery - Montgomery multiplication
9

SYNOPSIS

11        #include <openssl/bn.h>
12
13        BN_MONT_CTX *BN_MONT_CTX_new(void);
14        void BN_MONT_CTX_init(BN_MONT_CTX *ctx);
15        void BN_MONT_CTX_free(BN_MONT_CTX *mont);
16
17        int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *m, BN_CTX *ctx);
18        BN_MONT_CTX *BN_MONT_CTX_copy(BN_MONT_CTX *to, BN_MONT_CTX *from);
19
20        int BN_mod_mul_montgomery(BIGNUM *r, BIGNUM *a, BIGNUM *b,
21                BN_MONT_CTX *mont, BN_CTX *ctx);
22
23        int BN_from_montgomery(BIGNUM *r, BIGNUM *a, BN_MONT_CTX *mont,
24                BN_CTX *ctx);
25
26        int BN_to_montgomery(BIGNUM *r, BIGNUM *a, BN_MONT_CTX *mont,
27                BN_CTX *ctx);
28

DESCRIPTION

30       These functions implement Montgomery multiplication. They are used
31       automatically when BN_mod_exp(3) is called with suitable input, but
32       they may be useful when several operations are to be performed using
33       the same modulus.
34
35       BN_MONT_CTX_new() allocates and initializes a BN_MONT_CTX structure.
36       BN_MONT_CTX_init() initializes an existing uninitialized BN_MONT_CTX.
37
38       BN_MONT_CTX_set() sets up the mont structure from the modulus m by pre‐
39       computing its inverse and a value R.
40
41       BN_MONT_CTX_copy() copies the BN_MONT_CTX from to to.
42
43       BN_MONT_CTX_free() frees the components of the BN_MONT_CTX, and, if it
44       was created by BN_MONT_CTX_new(), also the structure itself.
45
46       BN_mod_mul_montgomery() computes Mont(a,b):=a*b*R^-1 and places the
47       result in r.
48
49       BN_from_montgomery() performs the Montgomery reduction r = a*R^-1.
50
51       BN_to_montgomery() computes Mont(a,R^2), i.e. a*R.  Note that a must be
52       non-negative and smaller than the modulus.
53
54       For all functions, ctx is a previously allocated BN_CTX used for tempo‐
55       rary variables.
56
57       The BN_MONT_CTX structure is defined as follows:
58
59        typedef struct bn_mont_ctx_st
60               {
61               int ri;         /* number of bits in R */
62               BIGNUM RR;      /* R^2 (used to convert to Montgomery form) */
63               BIGNUM N;       /* The modulus */
64               BIGNUM Ni;      /* R*(1/R mod N) - N*Ni = 1
65                                * (Ni is only stored for bignum algorithm) */
66               BN_ULONG n0;    /* least significant word of Ni */
67               int flags;
68               } BN_MONT_CTX;
69
70       BN_to_montgomery() is a macro.
71

RETURN VALUES

73       BN_MONT_CTX_new() returns the newly allocated BN_MONT_CTX, and NULL on
74       error.
75
76       BN_MONT_CTX_init() and BN_MONT_CTX_free() have no return values.
77
78       For the other functions, 1 is returned for success, 0 on error.  The
79       error codes can be obtained by ERR_get_error(3).
80

WARNING

82       The inputs must be reduced modulo m, otherwise the result will be out‐
83       side the expected range.
84

SEE ALSO

86       bn(3), ERR_get_error(3), BN_add(3), BN_CTX_new(3)
87

HISTORY

89       BN_MONT_CTX_new(), BN_MONT_CTX_free(), BN_MONT_CTX_set(),
90       BN_mod_mul_montgomery(), BN_from_montgomery() and BN_to_montgomery()
91       are available in all versions of SSLeay and OpenSSL.
92
93       BN_MONT_CTX_init() and BN_MONT_CTX_copy() were added in SSLeay 0.9.1b.
94
95
96
970.9.8b                            2002-09-25          BN_mod_mul_montgomery(3)
Impressum