comparison bn_mp_exptmod.c @ 190:d8254fc979e9 libtommath-orig LTM_0.35

Initial import of libtommath 0.35
author Matt Johnston <matt@ucc.asn.au>
date Fri, 06 May 2005 08:59:30 +0000
parents d29b64170cf0
children c5c969ed76f3
comparison
equal deleted inserted replaced
142:d29b64170cf0 190:d8254fc979e9
59 err = mp_exptmod(&tmpG, &tmpX, P, Y); 59 err = mp_exptmod(&tmpG, &tmpX, P, Y);
60 mp_clear_multi(&tmpG, &tmpX, NULL); 60 mp_clear_multi(&tmpG, &tmpX, NULL);
61 return err; 61 return err;
62 #else 62 #else
63 /* no invmod */ 63 /* no invmod */
64 return MP_VAL 64 return MP_VAL;
65 #endif 65 #endif
66 } 66 }
67
68 /* modified diminished radix reduction */
69 #if defined(BN_MP_REDUCE_IS_2K_L_C) && defined(BN_MP_REDUCE_2K_L_C)
70 if (mp_reduce_is_2k_l(P) == MP_YES) {
71 return s_mp_exptmod(G, X, P, Y, 1);
72 }
73 #endif
67 74
68 #ifdef BN_MP_DR_IS_MODULUS_C 75 #ifdef BN_MP_DR_IS_MODULUS_C
69 /* is it a DR modulus? */ 76 /* is it a DR modulus? */
70 dr = mp_dr_is_modulus(P); 77 dr = mp_dr_is_modulus(P);
71 #else 78 #else
79 /* default to no */
72 dr = 0; 80 dr = 0;
73 #endif 81 #endif
74 82
75 #ifdef BN_MP_REDUCE_IS_2K_C 83 #ifdef BN_MP_REDUCE_IS_2K_C
76 /* if not, is it a uDR modulus? */ 84 /* if not, is it a unrestricted DR modulus? */
77 if (dr == 0) { 85 if (dr == 0) {
78 dr = mp_reduce_is_2k(P) << 1; 86 dr = mp_reduce_is_2k(P) << 1;
79 } 87 }
80 #endif 88 #endif
81 89
82 /* if the modulus is odd or dr != 0 use the fast method */ 90 /* if the modulus is odd or dr != 0 use the montgomery method */
83 #ifdef BN_MP_EXPTMOD_FAST_C 91 #ifdef BN_MP_EXPTMOD_FAST_C
84 if (mp_isodd (P) == 1 || dr != 0) { 92 if (mp_isodd (P) == 1 || dr != 0) {
85 return mp_exptmod_fast (G, X, P, Y, dr); 93 return mp_exptmod_fast (G, X, P, Y, dr);
86 } else { 94 } else {
87 #endif 95 #endif
88 #ifdef BN_S_MP_EXPTMOD_C 96 #ifdef BN_S_MP_EXPTMOD_C
89 /* otherwise use the generic Barrett reduction technique */ 97 /* otherwise use the generic Barrett reduction technique */
90 return s_mp_exptmod (G, X, P, Y); 98 return s_mp_exptmod (G, X, P, Y, 0);
91 #else 99 #else
92 /* no exptmod for evens */ 100 /* no exptmod for evens */
93 return MP_VAL; 101 return MP_VAL;
94 #endif 102 #endif
95 #ifdef BN_MP_EXPTMOD_FAST_C 103 #ifdef BN_MP_EXPTMOD_FAST_C