comparison libtommath/bn_mp_is_square.c @ 1436:60fc6476e044

Update to libtommath v1.0
author Matt Johnston <matt@ucc.asn.au>
date Sat, 24 Jun 2017 22:37:14 +0800
parents 5ff8218bcee9
children 8bba51a55704
comparison
equal deleted inserted replaced
1435:f849a5ca2efc 1436:60fc6476e044
1 #include <tommath.h> 1 #include <tommath_private.h>
2 #ifdef BN_MP_IS_SQUARE_C 2 #ifdef BN_MP_IS_SQUARE_C
3 /* LibTomMath, multiple-precision integer library -- Tom St Denis 3 /* LibTomMath, multiple-precision integer library -- Tom St Denis
4 * 4 *
5 * LibTomMath is a library that provides multiple-precision 5 * LibTomMath is a library that provides multiple-precision
6 * integer arithmetic as well as number theoretic functionality. 6 * integer arithmetic as well as number theoretic functionality.
10 * additional optimizations in place. 10 * additional optimizations in place.
11 * 11 *
12 * The library is free for all purposes without any express 12 * The library is free for all purposes without any express
13 * guarantee it works. 13 * guarantee it works.
14 * 14 *
15 * Tom St Denis, [email protected], http://math.libtomcrypt.com 15 * Tom St Denis, [email protected], http://libtom.org
16 */ 16 */
17 17
18 /* Check if remainders are possible squares - fast exclude non-squares */ 18 /* Check if remainders are possible squares - fast exclude non-squares */
19 static const char rem_128[128] = { 19 static const char rem_128[128] = {
20 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 20 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1,
80 r = mp_get_int(&t); 80 r = mp_get_int(&t);
81 /* Check for other prime modules, note it's not an ERROR but we must 81 /* Check for other prime modules, note it's not an ERROR but we must
82 * free "t" so the easiest way is to goto ERR. We know that res 82 * free "t" so the easiest way is to goto ERR. We know that res
83 * is already equal to MP_OKAY from the mp_mod call 83 * is already equal to MP_OKAY from the mp_mod call
84 */ 84 */
85 if ( (1L<<(r%11)) & 0x5C4L ) goto ERR; 85 if (((1L<<(r%11)) & 0x5C4L) != 0L) goto ERR;
86 if ( (1L<<(r%13)) & 0x9E4L ) goto ERR; 86 if (((1L<<(r%13)) & 0x9E4L) != 0L) goto ERR;
87 if ( (1L<<(r%17)) & 0x5CE8L ) goto ERR; 87 if (((1L<<(r%17)) & 0x5CE8L) != 0L) goto ERR;
88 if ( (1L<<(r%19)) & 0x4F50CL ) goto ERR; 88 if (((1L<<(r%19)) & 0x4F50CL) != 0L) goto ERR;
89 if ( (1L<<(r%23)) & 0x7ACCA0L ) goto ERR; 89 if (((1L<<(r%23)) & 0x7ACCA0L) != 0L) goto ERR;
90 if ( (1L<<(r%29)) & 0xC2EDD0CL ) goto ERR; 90 if (((1L<<(r%29)) & 0xC2EDD0CL) != 0L) goto ERR;
91 if ( (1L<<(r%31)) & 0x6DE2B848L ) goto ERR; 91 if (((1L<<(r%31)) & 0x6DE2B848L) != 0L) goto ERR;
92 92
93 /* Final check - is sqr(sqrt(arg)) == arg ? */ 93 /* Final check - is sqr(sqrt(arg)) == arg ? */
94 if ((res = mp_sqrt(arg,&t)) != MP_OKAY) { 94 if ((res = mp_sqrt(arg,&t)) != MP_OKAY) {
95 goto ERR; 95 goto ERR;
96 } 96 }
102 ERR:mp_clear(&t); 102 ERR:mp_clear(&t);
103 return res; 103 return res;
104 } 104 }
105 #endif 105 #endif
106 106
107 /* $Source: /cvs/libtom/libtommath/bn_mp_is_square.c,v $ */ 107 /* $Source$ */
108 /* $Revision: 1.3 $ */ 108 /* $Revision$ */
109 /* $Date: 2006/03/31 14:18:44 $ */ 109 /* $Date$ */