497b68e9a941404109c4090e11cd54c3989e89fd
[openssl.git] / doc / crypto / BN_mod_mul_reciprocal.pod
1 =pod
2
3 =head1 NAME
4
5 BN_mod_mul_reciprocal,  BN_div_recp, BN_RECP_CTX_new, BN_RECP_CTX_init,
6 BN_RECP_CTX_free, BN_RECP_CTX_set - modular multiplication using
7 reciprocal
8
9 =head1 SYNOPSIS
10
11  #include <openssl/bn.h>
12
13  BN_RECP_CTX *BN_RECP_CTX_new(void);
14  void BN_RECP_CTX_free(BN_RECP_CTX *recp);
15
16  int BN_RECP_CTX_set(BN_RECP_CTX *recp, const BIGNUM *m, BN_CTX *ctx);
17
18  int BN_div_recp(BIGNUM *dv, BIGNUM *rem, BIGNUM *a, BN_RECP_CTX *recp,
19         BN_CTX *ctx);
20
21  int BN_mod_mul_reciprocal(BIGNUM *r, BIGNUM *a, BIGNUM *b,
22         BN_RECP_CTX *recp, BN_CTX *ctx);
23
24 =head1 DESCRIPTION
25
26 BN_mod_mul_reciprocal() can be used to perform an efficient
27 L<BN_mod_mul(3)> operation when the operation will be performed
28 repeatedly with the same modulus. It computes B<r>=(B<a>*B<b>)%B<m>
29 using B<recp>=1/B<m>, which is set as described below.  B<ctx> is a
30 previously allocated B<BN_CTX> used for temporary variables.
31
32 BN_RECP_CTX_new() allocates and initializes a B<BN_RECP> structure.
33 BN_RECP_CTX_init() initializes an existing uninitialized B<BN_RECP>.
34
35 BN_RECP_CTX_free() frees the components of the B<BN_RECP>, and, if it
36 was created by BN_RECP_CTX_new(), also the structure itself.
37 If B<recp> is NULL, nothing is done.
38
39 BN_RECP_CTX_set() stores B<m> in B<recp> and sets it up for computing
40 1/B<m> and shifting it left by BN_num_bits(B<m>)+1 to make it an
41 integer. The result and the number of bits it was shifted left will
42 later be stored in B<recp>.
43
44 BN_div_recp() divides B<a> by B<m> using B<recp>. It places the quotient
45 in B<dv> and the remainder in B<rem>.
46
47 The B<BN_RECP_CTX> structure cannot be shared between threads.
48
49 =head1 RETURN VALUES
50
51 BN_RECP_CTX_new() returns the newly allocated B<BN_RECP_CTX>, and NULL
52 on error.
53
54 BN_RECP_CTX_init() and BN_RECP_CTX_free() have no return values.
55
56 For the other functions, 1 is returned for success, 0 on error.
57 The error codes can be obtained by L<ERR_get_error(3)>.
58
59 =head1 REMOVED FUNCTIONALITY
60
61  void BN_RECP_CTX_init(BN_RECP_CTX *recp);
62
63 BN_RECP_CTX_init() is no longer available as of OpenSSL 1.1.0. It was used to
64 initialize an existing uninitialized B<BN_RECP_CTX>. Typically this would be
65 done as follows:
66
67  BN_RECP_CTX ctx;
68  BN_RECP_CTX_init(&ctx);
69
70 Applications should replace use of BN_RECP_CTX_init with BN_RECP_CTX_new
71 instead:
72
73  BN_RECP_CTX *ctx;
74  ctx = BN_RECP_CTX_new();
75  if(!ctx) /* Handle error */
76  ...
77  BN_RECP_CTX_free(ctx);
78
79 =head1 SEE ALSO
80
81 L<bn(3)>, L<ERR_get_error(3)>, L<BN_add(3)>,
82 L<BN_CTX_new(3)>
83
84 =head1 HISTORY
85
86 BN_RECP_CTX_init was removed in OpenSSL 1.1.0
87
88 =cut
89
90 =head1 COPYRIGHT
91
92 Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved.
93
94 Licensed under the OpenSSL license (the "License").  You may not use
95 this file except in compliance with the License.  You can obtain a copy
96 in the file LICENSE in the source distribution or at
97 L<https://www.openssl.org/source/license.html>.
98
99 =cut