1 .\" $OpenBSD: BN_mod_mul_reciprocal.3,v 1.9 2018/03/21 09:03:49 schwarze Exp $
2 .\" OpenSSL 6859cf74 Sep 25 13:33:28 2002 +0000
4 .\" This file was written by Ulf Moeller <ulf@openssl.org>.
5 .\" Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 .\" Redistribution and use in source and binary forms, with or without
8 .\" modification, are permitted provided that the following conditions
11 .\" 1. Redistributions of source code must retain the above copyright
12 .\" notice, this list of conditions and the following disclaimer.
14 .\" 2. Redistributions in binary form must reproduce the above copyright
15 .\" notice, this list of conditions and the following disclaimer in
16 .\" the documentation and/or other materials provided with the
19 .\" 3. All advertising materials mentioning features or use of this
20 .\" software must display the following acknowledgment:
21 .\" "This product includes software developed by the OpenSSL Project
22 .\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24 .\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25 .\" endorse or promote products derived from this software without
26 .\" prior written permission. For written permission, please contact
27 .\" openssl-core@openssl.org.
29 .\" 5. Products derived from this software may not be called "OpenSSL"
30 .\" nor may "OpenSSL" appear in their names without prior written
31 .\" permission of the OpenSSL Project.
33 .\" 6. Redistributions of any form whatsoever must retain the following
35 .\" "This product includes software developed by the OpenSSL Project
36 .\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38 .\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39 .\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41 .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42 .\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43 .\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44 .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45 .\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47 .\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49 .\" OF THE POSSIBILITY OF SUCH DAMAGE.
51 .Dd $Mdocdate: March 21 2018 $
52 .Dt BN_MOD_MUL_RECIPROCAL 3
55 .Nm BN_mod_mul_reciprocal ,
57 .Nm BN_RECP_CTX_init ,
58 .Nm BN_RECP_CTX_free ,
61 .Nd modular multiplication using reciprocal
65 .Fo BN_mod_mul_reciprocal
69 .Fa "BN_RECP_CTX *recp"
78 .Fa "BN_RECP_CTX *recp"
82 .Fa "BN_RECP_CTX *recp"
86 .Fa "BN_RECP_CTX *recp"
95 .Fa "BN_RECP_CTX *recp"
99 .Fn BN_mod_mul_reciprocal
100 can be used to perform an efficient
102 operation when the operation will be performed repeatedly with the same
105 .Fa r Ns =( Ns Fa a Ns * Ns Fa b Ns )% Ns Fa m
107 .Fa recp Ns =1/ Ns Fa m ,
108 which is set as described below.
110 is a previously allocated
112 used for temporary variables.
115 allocates and initializes a
120 initializes an existing uninitialized
122 It is deprecated and dangerous: see
126 frees the components of the
128 and, if it was created by
129 .Fn BN_RECP_CTX_new ,
130 also the structure itself.
135 pointer, no action occurs.
142 and sets it up for computing
144 and shifting it left by
145 .Fn BN_num_bits m Ns +1
146 to make it an integer.
147 The result and the number of bits it was shifted left will later be
158 It places the quotient in
165 structure is defined as follows:
167 typedef struct bn_recp_ctx_st {
168 BIGNUM N; /* the divisor */
169 BIGNUM Nr; /* the reciprocal */
176 It cannot be shared between threads.
179 returns the newly allocated
185 For the other functions, 1 is returned for success or 0 on error.
186 The error codes can be obtained by
187 .Xr ERR_get_error 3 .
193 .Fn BN_mod_mul_reciprocal
194 appeared before SSLeay 0.8 and has been available since
198 was added in SSLeay 0.9.0.
199 Before that, a function
201 was used instead, and the
202 .Fn BN_mod_mul_reciprocal
203 arguments were different.
205 .Fn BN_RECP_CTX_new ,
206 .Fn BN_RECP_CTX_init ,
207 .Fn BN_RECP_CTX_free ,
208 .Fn BN_RECP_CTX_set ,
211 first appeared in SSLeay 0.9.1 and have been available since
215 must not be called on a context that was used previously, or
216 memory used by the embedded
218 structures is leaked immediately.
219 Besides, it must not be called on a context created with
220 .Fn BN_RECP_CTX_new ,
221 or the context itself will likely be leaked later.
222 It can only be used on a static
224 structure, on one located on the stack, or on one
226 manually, but all these options are discouraged because they
227 will no longer work once