xref: /openbsd/lib/libcrypto/bn/bn_mod.c (revision ca1d80d6)
1*ca1d80d6Sbeck /* $OpenBSD: bn_mod.c,v 1.22 2023/07/08 12:21:58 beck Exp $ */
2da347917Sbeck /* Includes code written by Lenka Fibikova <fibikova@exp-math.uni-essen.de>
3da347917Sbeck  * for the OpenSSL project. */
4da347917Sbeck /* ====================================================================
5da347917Sbeck  * Copyright (c) 1998-2000 The OpenSSL Project.  All rights reserved.
6da347917Sbeck  *
7da347917Sbeck  * Redistribution and use in source and binary forms, with or without
8da347917Sbeck  * modification, are permitted provided that the following conditions
9da347917Sbeck  * are met:
10da347917Sbeck  *
11da347917Sbeck  * 1. Redistributions of source code must retain the above copyright
12da347917Sbeck  *    notice, this list of conditions and the following disclaimer.
13da347917Sbeck  *
14da347917Sbeck  * 2. Redistributions in binary form must reproduce the above copyright
15da347917Sbeck  *    notice, this list of conditions and the following disclaimer in
16da347917Sbeck  *    the documentation and/or other materials provided with the
17da347917Sbeck  *    distribution.
18da347917Sbeck  *
19da347917Sbeck  * 3. All advertising materials mentioning features or use of this
20da347917Sbeck  *    software must display the following acknowledgment:
21da347917Sbeck  *    "This product includes software developed by the OpenSSL Project
22da347917Sbeck  *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
23da347917Sbeck  *
24da347917Sbeck  * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25da347917Sbeck  *    endorse or promote products derived from this software without
26da347917Sbeck  *    prior written permission. For written permission, please contact
27da347917Sbeck  *    openssl-core@openssl.org.
28da347917Sbeck  *
29da347917Sbeck  * 5. Products derived from this software may not be called "OpenSSL"
30da347917Sbeck  *    nor may "OpenSSL" appear in their names without prior written
31da347917Sbeck  *    permission of the OpenSSL Project.
32da347917Sbeck  *
33da347917Sbeck  * 6. Redistributions of any form whatsoever must retain the following
34da347917Sbeck  *    acknowledgment:
35da347917Sbeck  *    "This product includes software developed by the OpenSSL Project
36da347917Sbeck  *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37da347917Sbeck  *
38da347917Sbeck  * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39da347917Sbeck  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40da347917Sbeck  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41da347917Sbeck  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
42da347917Sbeck  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43da347917Sbeck  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44da347917Sbeck  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45da347917Sbeck  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46da347917Sbeck  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47da347917Sbeck  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48da347917Sbeck  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49da347917Sbeck  * OF THE POSSIBILITY OF SUCH DAMAGE.
50da347917Sbeck  * ====================================================================
51da347917Sbeck  *
52da347917Sbeck  * This product includes cryptographic software written by Eric Young
53da347917Sbeck  * (eay@cryptsoft.com).  This product includes software written by Tim
54da347917Sbeck  * Hudson (tjh@cryptsoft.com).
55da347917Sbeck  *
56da347917Sbeck  */
57da347917Sbeck /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
58da347917Sbeck  * All rights reserved.
59da347917Sbeck  *
60da347917Sbeck  * This package is an SSL implementation written
61da347917Sbeck  * by Eric Young (eay@cryptsoft.com).
62da347917Sbeck  * The implementation was written so as to conform with Netscapes SSL.
63da347917Sbeck  *
64da347917Sbeck  * This library is free for commercial and non-commercial use as long as
65da347917Sbeck  * the following conditions are aheared to.  The following conditions
66da347917Sbeck  * apply to all code found in this distribution, be it the RC4, RSA,
67da347917Sbeck  * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
68da347917Sbeck  * included with this distribution is covered by the same copyright terms
69da347917Sbeck  * except that the holder is Tim Hudson (tjh@cryptsoft.com).
70da347917Sbeck  *
71da347917Sbeck  * Copyright remains Eric Young's, and as such any Copyright notices in
72da347917Sbeck  * the code are not to be removed.
73da347917Sbeck  * If this package is used in a product, Eric Young should be given attribution
74da347917Sbeck  * as the author of the parts of the library used.
75da347917Sbeck  * This can be in the form of a textual message at program startup or
76da347917Sbeck  * in documentation (online or textual) provided with the package.
77da347917Sbeck  *
78da347917Sbeck  * Redistribution and use in source and binary forms, with or without
79da347917Sbeck  * modification, are permitted provided that the following conditions
80da347917Sbeck  * are met:
81da347917Sbeck  * 1. Redistributions of source code must retain the copyright
82da347917Sbeck  *    notice, this list of conditions and the following disclaimer.
83da347917Sbeck  * 2. Redistributions in binary form must reproduce the above copyright
84da347917Sbeck  *    notice, this list of conditions and the following disclaimer in the
85da347917Sbeck  *    documentation and/or other materials provided with the distribution.
86da347917Sbeck  * 3. All advertising materials mentioning features or use of this software
87da347917Sbeck  *    must display the following acknowledgement:
88da347917Sbeck  *    "This product includes cryptographic software written by
89da347917Sbeck  *     Eric Young (eay@cryptsoft.com)"
90da347917Sbeck  *    The word 'cryptographic' can be left out if the rouines from the library
91da347917Sbeck  *    being used are not cryptographic related :-).
92da347917Sbeck  * 4. If you include any Windows specific code (or a derivative thereof) from
93da347917Sbeck  *    the apps directory (application code) you must include an acknowledgement:
94da347917Sbeck  *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
95da347917Sbeck  *
96da347917Sbeck  * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
97da347917Sbeck  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
98da347917Sbeck  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
99da347917Sbeck  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
100da347917Sbeck  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
101da347917Sbeck  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
102da347917Sbeck  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
103da347917Sbeck  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
104da347917Sbeck  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
105da347917Sbeck  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
106da347917Sbeck  * SUCH DAMAGE.
107da347917Sbeck  *
108da347917Sbeck  * The licence and distribution terms for any publically available version or
109da347917Sbeck  * derivative of this code cannot be changed.  i.e. this code cannot simply be
110da347917Sbeck  * copied and put under another distribution licence
111da347917Sbeck  * [including the GNU Public Licence.]
112da347917Sbeck  */
113da347917Sbeck 
114b6ab114eSjsing #include <openssl/err.h>
115b6ab114eSjsing 
116c9675a23Stb #include "bn_local.h"
117da347917Sbeck 
1182bd9bb84Sjsing int
BN_mod_ct(BIGNUM * r,const BIGNUM * a,const BIGNUM * m,BN_CTX * ctx)1197bb0769bSjsing BN_mod_ct(BIGNUM *r, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx)
1207bb0769bSjsing {
1217bb0769bSjsing 	return BN_div_ct(NULL, r, a, m, ctx);
1227bb0769bSjsing }
1237bb0769bSjsing 
1247bb0769bSjsing int
BN_mod_nonct(BIGNUM * r,const BIGNUM * a,const BIGNUM * m,BN_CTX * ctx)1257bb0769bSjsing BN_mod_nonct(BIGNUM *r, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx)
1267bb0769bSjsing {
1277bb0769bSjsing 	return BN_div_nonct(NULL, r, a, m, ctx);
1287bb0769bSjsing }
1297bb0769bSjsing 
130ee5d149bSjsing /*
131ee5d149bSjsing  * BN_nnmod() is like BN_mod(), but always returns a non-negative remainder
132ee5d149bSjsing  * (that is 0 <= r < |m| always holds). If both a and m have the same sign then
133ee5d149bSjsing  * the result is already non-negative. Otherwise, -|m| < r < 0, which needs to
134ee5d149bSjsing  * be adjusted as r := r + |m|. This equates to r := |m| - |r|.
135ee5d149bSjsing  */
1367bb0769bSjsing int
BN_nnmod(BIGNUM * r,const BIGNUM * a,const BIGNUM * m,BN_CTX * ctx)137ee5d149bSjsing BN_nnmod(BIGNUM *r, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx)
138da347917Sbeck {
13912ca9b0dStb 	if (r == m) {
14012ca9b0dStb 		BNerror(BN_R_INVALID_ARGUMENT);
14112ca9b0dStb 		return 0;
14212ca9b0dStb 	}
143ee5d149bSjsing 	if (!BN_mod_ct(r, a, m, ctx))
144da347917Sbeck 		return 0;
145ee5d149bSjsing 	if (BN_is_negative(r))
146ee5d149bSjsing 		return BN_usub(r, m, r);
147da347917Sbeck 	return 1;
148da347917Sbeck }
149*ca1d80d6Sbeck LCRYPTO_ALIAS(BN_nnmod);
150da347917Sbeck 
1512bd9bb84Sjsing int
BN_mod_add(BIGNUM * r,const BIGNUM * a,const BIGNUM * b,const BIGNUM * m,BN_CTX * ctx)1522bd9bb84Sjsing BN_mod_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m,
1532bd9bb84Sjsing     BN_CTX *ctx)
154da347917Sbeck {
15512ca9b0dStb 	if (r == m) {
15612ca9b0dStb 		BNerror(BN_R_INVALID_ARGUMENT);
15712ca9b0dStb 		return 0;
15812ca9b0dStb 	}
1592bd9bb84Sjsing 	if (!BN_add(r, a, b))
1602bd9bb84Sjsing 		return 0;
161da347917Sbeck 	return BN_nnmod(r, r, m, ctx);
162da347917Sbeck }
163*ca1d80d6Sbeck LCRYPTO_ALIAS(BN_mod_add);
164da347917Sbeck 
1655169a775Sjsing /*
1665169a775Sjsing  * BN_mod_add() variant that may only be used if both a and b are non-negative
1675169a775Sjsing  * and have already been reduced (less than m).
1685169a775Sjsing  */
1692bd9bb84Sjsing int
BN_mod_add_quick(BIGNUM * r,const BIGNUM * a,const BIGNUM * b,const BIGNUM * m)1702bd9bb84Sjsing BN_mod_add_quick(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m)
171da347917Sbeck {
17212ca9b0dStb 	if (r == m) {
17312ca9b0dStb 		BNerror(BN_R_INVALID_ARGUMENT);
17412ca9b0dStb 		return 0;
17512ca9b0dStb 	}
1762bd9bb84Sjsing 	if (!BN_uadd(r, a, b))
1772bd9bb84Sjsing 		return 0;
178da347917Sbeck 	if (BN_ucmp(r, m) >= 0)
179da347917Sbeck 		return BN_usub(r, r, m);
180da347917Sbeck 	return 1;
181da347917Sbeck }
182*ca1d80d6Sbeck LCRYPTO_ALIAS(BN_mod_add_quick);
183da347917Sbeck 
1842bd9bb84Sjsing int
BN_mod_sub(BIGNUM * r,const BIGNUM * a,const BIGNUM * b,const BIGNUM * m,BN_CTX * ctx)1852bd9bb84Sjsing BN_mod_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m,
1862bd9bb84Sjsing     BN_CTX *ctx)
187da347917Sbeck {
18812ca9b0dStb 	if (r == m) {
18912ca9b0dStb 		BNerror(BN_R_INVALID_ARGUMENT);
19012ca9b0dStb 		return 0;
19112ca9b0dStb 	}
1922bd9bb84Sjsing 	if (!BN_sub(r, a, b))
1932bd9bb84Sjsing 		return 0;
194da347917Sbeck 	return BN_nnmod(r, r, m, ctx);
195da347917Sbeck }
196*ca1d80d6Sbeck LCRYPTO_ALIAS(BN_mod_sub);
197da347917Sbeck 
1985169a775Sjsing /*
1995169a775Sjsing  * BN_mod_sub() variant that may only be used if both a and b are non-negative
2005169a775Sjsing  * and have already been reduced (less than m).
2015169a775Sjsing  */
2022bd9bb84Sjsing int
BN_mod_sub_quick(BIGNUM * r,const BIGNUM * a,const BIGNUM * b,const BIGNUM * m)2032bd9bb84Sjsing BN_mod_sub_quick(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m)
204da347917Sbeck {
20512ca9b0dStb 	if (r == m) {
20612ca9b0dStb 		BNerror(BN_R_INVALID_ARGUMENT);
20712ca9b0dStb 		return 0;
20812ca9b0dStb 	}
2095169a775Sjsing 	if (BN_ucmp(a, b) >= 0)
2105169a775Sjsing 		return BN_usub(r, a, b);
2115169a775Sjsing 	if (!BN_usub(r, b, a))
2122bd9bb84Sjsing 		return 0;
2135169a775Sjsing 	return BN_usub(r, m, r);
214da347917Sbeck }
215*ca1d80d6Sbeck LCRYPTO_ALIAS(BN_mod_sub_quick);
216da347917Sbeck 
2172bd9bb84Sjsing int
BN_mod_mul(BIGNUM * r,const BIGNUM * a,const BIGNUM * b,const BIGNUM * m,BN_CTX * ctx)2182bd9bb84Sjsing BN_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m,
219da347917Sbeck     BN_CTX *ctx)
220da347917Sbeck {
221a4910a19Sjsing 	BIGNUM *rr;
222da347917Sbeck 	int ret = 0;
223da347917Sbeck 
224da347917Sbeck 	BN_CTX_start(ctx);
225a4910a19Sjsing 
22612ca9b0dStb 	if (r == m) {
22712ca9b0dStb 		BNerror(BN_R_INVALID_ARGUMENT);
22812ca9b0dStb 		goto err;
22912ca9b0dStb 	}
23012ca9b0dStb 
231a4910a19Sjsing 	rr = r;
232a4910a19Sjsing 	if (rr == a || rr == b)
233a4910a19Sjsing 		rr = BN_CTX_get(ctx);
234a4910a19Sjsing 	if (rr == NULL)
2352bd9bb84Sjsing 		goto err;
236a4910a19Sjsing 
2372bd9bb84Sjsing 	if (a == b) {
238a4910a19Sjsing 		if (!BN_sqr(rr, a, ctx))
2392bd9bb84Sjsing 			goto err;
2402bd9bb84Sjsing 	} else {
241a4910a19Sjsing 		if (!BN_mul(rr, a, b, ctx))
2422bd9bb84Sjsing 			goto err;
2432bd9bb84Sjsing 	}
244a4910a19Sjsing 	if (!BN_nnmod(r, rr, m, ctx))
2452bd9bb84Sjsing 		goto err;
246a4910a19Sjsing 
247da347917Sbeck 	ret = 1;
2482bd9bb84Sjsing 
249da347917Sbeck  err:
250da347917Sbeck 	BN_CTX_end(ctx);
251a4910a19Sjsing 
252a4910a19Sjsing 	return ret;
253da347917Sbeck }
254*ca1d80d6Sbeck LCRYPTO_ALIAS(BN_mod_mul);
255da347917Sbeck 
2562bd9bb84Sjsing int
BN_mod_sqr(BIGNUM * r,const BIGNUM * a,const BIGNUM * m,BN_CTX * ctx)2572bd9bb84Sjsing BN_mod_sqr(BIGNUM *r, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx)
258da347917Sbeck {
259a4910a19Sjsing 	return BN_mod_mul(r, a, a, m, ctx);
260da347917Sbeck }
261*ca1d80d6Sbeck LCRYPTO_ALIAS(BN_mod_sqr);
262da347917Sbeck 
2632bd9bb84Sjsing int
BN_mod_lshift1(BIGNUM * r,const BIGNUM * a,const BIGNUM * m,BN_CTX * ctx)2642bd9bb84Sjsing BN_mod_lshift1(BIGNUM *r, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx)
265da347917Sbeck {
26612ca9b0dStb 	if (r == m) {
26712ca9b0dStb 		BNerror(BN_R_INVALID_ARGUMENT);
26812ca9b0dStb 		return 0;
26912ca9b0dStb 	}
2702bd9bb84Sjsing 	if (!BN_lshift1(r, a))
2712bd9bb84Sjsing 		return 0;
272da347917Sbeck 	return BN_nnmod(r, r, m, ctx);
273da347917Sbeck }
274*ca1d80d6Sbeck LCRYPTO_ALIAS(BN_mod_lshift1);
275da347917Sbeck 
2765169a775Sjsing /*
2775169a775Sjsing  * BN_mod_lshift1() variant that may be used if a is non-negative
2785169a775Sjsing  * and has already been reduced (less than m).
2795169a775Sjsing  */
2802bd9bb84Sjsing int
BN_mod_lshift1_quick(BIGNUM * r,const BIGNUM * a,const BIGNUM * m)2812bd9bb84Sjsing BN_mod_lshift1_quick(BIGNUM *r, const BIGNUM *a, const BIGNUM *m)
282da347917Sbeck {
28312ca9b0dStb 	if (r == m) {
28412ca9b0dStb 		BNerror(BN_R_INVALID_ARGUMENT);
28512ca9b0dStb 		return 0;
28612ca9b0dStb 	}
2872bd9bb84Sjsing 	if (!BN_lshift1(r, a))
2882bd9bb84Sjsing 		return 0;
2895169a775Sjsing 	if (BN_ucmp(r, m) >= 0)
2905169a775Sjsing 		return BN_usub(r, r, m);
291da347917Sbeck 	return 1;
292da347917Sbeck }
293*ca1d80d6Sbeck LCRYPTO_ALIAS(BN_mod_lshift1_quick);
294da347917Sbeck 
2952bd9bb84Sjsing int
BN_mod_lshift(BIGNUM * r,const BIGNUM * a,int n,const BIGNUM * m,BN_CTX * ctx)2962bd9bb84Sjsing BN_mod_lshift(BIGNUM *r, const BIGNUM *a, int n, const BIGNUM *m, BN_CTX *ctx)
297da347917Sbeck {
298cd283ea4Sjsing 	BIGNUM *abs_m;
299cd283ea4Sjsing 	int ret = 0;
300cd283ea4Sjsing 
301cd283ea4Sjsing 	BN_CTX_start(ctx);
302da347917Sbeck 
30312ca9b0dStb 	if (r == m) {
30412ca9b0dStb 		BNerror(BN_R_INVALID_ARGUMENT);
30512ca9b0dStb 		goto err;
30612ca9b0dStb 	}
30712ca9b0dStb 
3082bd9bb84Sjsing 	if (!BN_nnmod(r, a, m, ctx))
309cd283ea4Sjsing 		goto err;
310da347917Sbeck 
311cd283ea4Sjsing 	if (BN_is_negative(m)) {
312cd283ea4Sjsing 		if ((abs_m = BN_CTX_get(ctx)) == NULL)
313cd283ea4Sjsing 			goto err;
31458460d4fStb 		if (!bn_copy(abs_m, m))
315cd283ea4Sjsing 			goto err;
316cd283ea4Sjsing 		BN_set_negative(abs_m, 0);
317cd283ea4Sjsing 		m = abs_m;
318da347917Sbeck 	}
319cd283ea4Sjsing 	if (!BN_mod_lshift_quick(r, r, n, m))
320cd283ea4Sjsing 		goto err;
321da347917Sbeck 
322cd283ea4Sjsing 	ret = 1;
323cd283ea4Sjsing  err:
324cd283ea4Sjsing 	BN_CTX_end(ctx);
325da347917Sbeck 
326da347917Sbeck 	return ret;
327da347917Sbeck }
328*ca1d80d6Sbeck LCRYPTO_ALIAS(BN_mod_lshift);
329da347917Sbeck 
330cd283ea4Sjsing /*
331cd283ea4Sjsing  * BN_mod_lshift() variant that may be used if a is non-negative
332cd283ea4Sjsing  * and has already been reduced (less than m).
333cd283ea4Sjsing  */
3342bd9bb84Sjsing int
BN_mod_lshift_quick(BIGNUM * r,const BIGNUM * a,int n,const BIGNUM * m)3352bd9bb84Sjsing BN_mod_lshift_quick(BIGNUM *r, const BIGNUM *a, int n, const BIGNUM *m)
336da347917Sbeck {
337da347917Sbeck 	int max_shift;
338da347917Sbeck 
33912ca9b0dStb 	if (r == m) {
34012ca9b0dStb 		BNerror(BN_R_INVALID_ARGUMENT);
34112ca9b0dStb 		return 0;
34212ca9b0dStb 	}
34312ca9b0dStb 
34458460d4fStb 	if (!bn_copy(r, a))
345cd283ea4Sjsing 		return 0;
346da347917Sbeck 
347cd283ea4Sjsing 	while (n > 0) {
348cd283ea4Sjsing 		if ((max_shift = BN_num_bits(m) - BN_num_bits(r)) < 0) {
3495067ae9fSbeck 			BNerror(BN_R_INPUT_NOT_REDUCED);
350da347917Sbeck 			return 0;
351da347917Sbeck 		}
352cd283ea4Sjsing 		if (max_shift == 0)
353cd283ea4Sjsing 			max_shift = 1;
354da347917Sbeck 		if (max_shift > n)
355da347917Sbeck 			max_shift = n;
356da347917Sbeck 
3572bd9bb84Sjsing 		if (!BN_lshift(r, r, max_shift))
3582bd9bb84Sjsing 			return 0;
359da347917Sbeck 		n -= max_shift;
360da347917Sbeck 
361cd283ea4Sjsing 		if (BN_ucmp(r, m) >= 0) {
362cd283ea4Sjsing 			if (!BN_usub(r, r, m))
3632bd9bb84Sjsing 				return 0;
364da347917Sbeck 		}
365da347917Sbeck 	}
366da347917Sbeck 
367da347917Sbeck 	return 1;
368da347917Sbeck }
369*ca1d80d6Sbeck LCRYPTO_ALIAS(BN_mod_lshift_quick);
370