typo
[openssl.git] / doc / crypto / BN_mod_mul_montgomery.pod
1 =pod
2
3 =head1 NAME
4
5 BN_mod_mul_montgomery, BN_MONT_CTX_new, BN_MONT_CTX_init,
6 BN_MONT_CTX_free, BN_MONT_CTX_set, BN_MONT_CTX_copy,
7 BN_from_montgomery, BN_to_montgomery - Montgomery multiplication
8
9 =head1 SYNOPSIS
10
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
29 =head1 DESCRIPTION
30
31 These functions implement Montgomery multiplication. They are used
32 automatically when L<BN_mod_exp(3)|BN_mod_exp(3)> is called with suitable input,
33 but they may be useful when several operations are to be performed
34 using the same modulus.
35
36 BN_MONT_CTX_new() allocates and initializes a B<BN_MONT_CTX> structure.
37 BN_MONT_CTX_init() initializes an existing uninitialized B<BN_MONT_CTX>.
38
39 BN_MONT_CTX_set() sets up the B<mont> structure from the modulus B<m>
40 by precomputing its inverse and a value R.
41
42 BN_MONT_CTX_copy() copies the B<BN_MONT_CTX> B<from> to B<to>.
43
44 BN_MONT_CTX_free() frees the components of the B<BN_MONT_CTX>, and, if
45 it was created by BN_MONT_CTX_new(), also the structure itself.
46
47 BN_mod_mul_montgomery() computes Mont(B<a>,B<b>):=B<a>*B<b>*R^-1 and places
48 the result in B<r>.
49
50 BN_from_montgomery() performs the Montgomery reduction B<r> = B<a>*R^-1.
51
52 BN_to_montgomery() computes Mont(B<a>,R^2), i.e. B<a>*R.
53
54 For all functions, B<ctx> is a previously allocated B<BN_CTX> used for
55 temporary variables.
56
57 The B<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
72 =head1 RETURN VALUES
73
74 BN_MONT_CTX_new() returns the newly allocated B<BN_MONT_CTX>, and NULL
75 on error.
76
77 BN_MONT_CTX_init() and BN_MONT_CTX_free() have no return values.
78
79 For the other functions, 1 is returned for success, 0 on error.
80 The error codes can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>.
81
82 =head1 SEE ALSO
83
84 L<bn(3)|bn(3)>, L<err(3)|err(3)>, L<BN_add(3)|BN_add(3)>,
85 L<BN_CTX_new(3)|BN_CTX_new(3)>
86
87 =head1 HISTORY
88
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 =cut