@@ -22,11 +22,11 @@ int mp_sqrtmod_prime(const mp_int *n, const mp_int *prime, mp_int *ret)
22
22
mp_digit i ;
23
23
24
24
/* first handle the simple cases */
25
- if (mp_cmp_d (n , 0 ) == MP_EQ ) {
25
+ if (mp_cmp_d (n , 0uL ) == MP_EQ ) {
26
26
mp_zero (ret );
27
27
return MP_OKAY ;
28
28
}
29
- if (mp_cmp_d (prime , 2 ) == MP_EQ ) return MP_VAL ; /* prime must be odd */
29
+ if (mp_cmp_d (prime , 2uL ) == MP_EQ ) return MP_VAL ; /* prime must be odd */
30
30
if ((res = mp_jacobi (n , prime , & legendre )) != MP_OKAY ) return res ;
31
31
if (legendre == -1 ) return MP_VAL ; /* quadratic non-residue mod prime */
32
32
@@ -38,9 +38,9 @@ int mp_sqrtmod_prime(const mp_int *n, const mp_int *prime, mp_int *ret)
38
38
* compute directly: res = n^(prime+1)/4 mod prime
39
39
* Handbook of Applied Cryptography algorithm 3.36
40
40
*/
41
- if ((res = mp_mod_d (prime , 4 , & i )) != MP_OKAY ) goto cleanup ;
41
+ if ((res = mp_mod_d (prime , 4uL , & i )) != MP_OKAY ) goto cleanup ;
42
42
if (i == 3 ) {
43
- if ((res = mp_add_d (prime , 1 , & t1 )) != MP_OKAY ) goto cleanup ;
43
+ if ((res = mp_add_d (prime , 1uL , & t1 )) != MP_OKAY ) goto cleanup ;
44
44
if ((res = mp_div_2 (& t1 , & t1 )) != MP_OKAY ) goto cleanup ;
45
45
if ((res = mp_div_2 (& t1 , & t1 )) != MP_OKAY ) goto cleanup ;
46
46
if ((res = mp_exptmod (n , & t1 , prime , ret )) != MP_OKAY ) goto cleanup ;
@@ -52,14 +52,14 @@ int mp_sqrtmod_prime(const mp_int *n, const mp_int *prime, mp_int *ret)
52
52
53
53
/* factor out powers of 2 from prime-1, defining Q and S as: prime-1 = Q*2^S */
54
54
if ((res = mp_copy (prime , & Q )) != MP_OKAY ) goto cleanup ;
55
- if ((res = mp_sub_d (& Q , 1 , & Q )) != MP_OKAY ) goto cleanup ;
55
+ if ((res = mp_sub_d (& Q , 1uL , & Q )) != MP_OKAY ) goto cleanup ;
56
56
/* Q = prime - 1 */
57
57
mp_zero (& S );
58
58
/* S = 0 */
59
59
while (mp_iseven (& Q ) != MP_NO ) {
60
60
if ((res = mp_div_2 (& Q , & Q )) != MP_OKAY ) goto cleanup ;
61
61
/* Q = Q / 2 */
62
- if ((res = mp_add_d (& S , 1 , & S )) != MP_OKAY ) goto cleanup ;
62
+ if ((res = mp_add_d (& S , 1uL , & S )) != MP_OKAY ) goto cleanup ;
63
63
/* S = S + 1 */
64
64
}
65
65
@@ -69,13 +69,13 @@ int mp_sqrtmod_prime(const mp_int *n, const mp_int *prime, mp_int *ret)
69
69
while (1 ) {
70
70
if ((res = mp_jacobi (& Z , prime , & legendre )) != MP_OKAY ) goto cleanup ;
71
71
if (legendre == -1 ) break ;
72
- if ((res = mp_add_d (& Z , 1 , & Z )) != MP_OKAY ) goto cleanup ;
72
+ if ((res = mp_add_d (& Z , 1uL , & Z )) != MP_OKAY ) goto cleanup ;
73
73
/* Z = Z + 1 */
74
74
}
75
75
76
76
if ((res = mp_exptmod (& Z , & Q , prime , & C )) != MP_OKAY ) goto cleanup ;
77
77
/* C = Z ^ Q mod prime */
78
- if ((res = mp_add_d (& Q , 1 , & t1 )) != MP_OKAY ) goto cleanup ;
78
+ if ((res = mp_add_d (& Q , 1uL , & t1 )) != MP_OKAY ) goto cleanup ;
79
79
if ((res = mp_div_2 (& t1 , & t1 )) != MP_OKAY ) goto cleanup ;
80
80
/* t1 = (Q + 1) / 2 */
81
81
if ((res = mp_exptmod (n , & t1 , prime , & R )) != MP_OKAY ) goto cleanup ;
@@ -91,7 +91,7 @@ int mp_sqrtmod_prime(const mp_int *n, const mp_int *prime, mp_int *ret)
91
91
if ((res = mp_copy (& T , & t1 )) != MP_OKAY ) goto cleanup ;
92
92
i = 0 ;
93
93
while (1 ) {
94
- if (mp_cmp_d (& t1 , 1 ) == MP_EQ ) break ;
94
+ if (mp_cmp_d (& t1 , 1uL ) == MP_EQ ) break ;
95
95
if ((res = mp_exptmod (& t1 , & two , prime , & t1 )) != MP_OKAY ) goto cleanup ;
96
96
i ++ ;
97
97
}
@@ -101,7 +101,7 @@ int mp_sqrtmod_prime(const mp_int *n, const mp_int *prime, mp_int *ret)
101
101
goto cleanup ;
102
102
}
103
103
if ((res = mp_sub_d (& M , i , & t1 )) != MP_OKAY ) goto cleanup ;
104
- if ((res = mp_sub_d (& t1 , 1 , & t1 )) != MP_OKAY ) goto cleanup ;
104
+ if ((res = mp_sub_d (& t1 , 1uL , & t1 )) != MP_OKAY ) goto cleanup ;
105
105
if ((res = mp_exptmod (& two , & t1 , prime , & t1 )) != MP_OKAY ) goto cleanup ;
106
106
/* t1 = 2 ^ (M - i - 1) */
107
107
if ((res = mp_exptmod (& C , & t1 , prime , & t1 )) != MP_OKAY ) goto cleanup ;
0 commit comments