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_free,
7       BN_MONT_CTX_set, BN_MONT_CTX_copy, BN_from_montgomery, BN_to_montgomery
8       - Montgomery multiplication
9

SYNOPSIS

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

DESCRIPTION

29       These functions implement Montgomery multiplication. They are used
30       automatically when BN_mod_exp(3) is called with suitable input, but
31       they may be useful when several operations are to be performed using
32       the same modulus.
33
34       BN_MONT_CTX_new() allocates and initializes a BN_MONT_CTX structure.
35
36       BN_MONT_CTX_set() sets up the mont structure from the modulus m by
37       precomputing its inverse and a value R.
38
39       BN_MONT_CTX_copy() copies the BN_MONT_CTX from to to.
40
41       BN_MONT_CTX_free() frees the components of the BN_MONT_CTX, and, if it
42       was created by BN_MONT_CTX_new(), also the structure itself.  If mont
43       is NULL, nothing is done.
44
45       BN_mod_mul_montgomery() computes Mont(a,b):=a*b*R^-1 and places the
46       result in r.
47
48       BN_from_montgomery() performs the Montgomery reduction r = a*R^-1.
49
50       BN_to_montgomery() computes Mont(a,R^2), i.e. a*R.  Note that a must be
51       nonnegative and smaller than the modulus.
52
53       For all functions, ctx is a previously allocated BN_CTX used for
54       temporary variables.
55

RETURN VALUES

57       BN_MONT_CTX_new() returns the newly allocated BN_MONT_CTX, and NULL on
58       error.
59
60       BN_MONT_CTX_free() has no return value.
61
62       For the other functions, 1 is returned for success, 0 on error.  The
63       error codes can be obtained by ERR_get_error(3).
64

WARNINGS

66       The inputs must be reduced modulo m, otherwise the result will be
67       outside the expected range.
68

SEE ALSO

70       ERR_get_error(3), BN_add(3), BN_CTX_new(3)
71

HISTORY

73       BN_MONT_CTX_init() was removed in OpenSSL 1.1.0
74
76       Copyright 2000-2020 The OpenSSL Project Authors. All Rights Reserved.
77
78       Licensed under the OpenSSL license (the "License").  You may not use
79       this file except in compliance with the License.  You can obtain a copy
80       in the file LICENSE in the source distribution or at
81       <https://www.openssl.org/source/license.html>.
82
83
84
851.1.1i                            2021-07-22          BN_MOD_MUL_MONTGOMERY(3)
Impressum