@@ -153,6 +153,56 @@ static int test_trivial_stuff(void)
153
153
return EXIT_FAILURE ;
154
154
}
155
155
156
+ static int test_mp_hash (void )
157
+ {
158
+ mp_int a ;
159
+ mp_hval hash ;
160
+ int i ;
161
+ int len = 5 ;
162
+
163
+ const char * input [] = {
164
+ "0" ,
165
+ "///////////////////////////////////////////////////////////////////" ,
166
+ "4n9cbk886QtLQmofprid3l2Q0GD8Yv979Lh8BdZkFE8g2pDUUSMBET/+M/YFyVZ3mBp" ,
167
+ "5NlgzHhmIX05O5YoW5yW5reAlVNtRAlIcN2dfoATnNdc1Cw5lHZUTwNthmK6/ZLKfY6" ,
168
+ "3gweiHDX+ji5utraSe46IJX+uuh7iggs63xIpMP5MriU4Np+LpHI5are8RzS9pKh9xP"
169
+ };
170
+ const mp_hval hvals [] = {
171
+ #if (MP_DIGIT_BIT == 15 )
172
+ 0x50c5d1f ,
173
+ 0x51b3ba04 ,
174
+ 0xf83febd7 ,
175
+ 0x2dc8624c ,
176
+ 0xf5c2996b
177
+ #elif (MP_DIGIT_BIT == 60 )
178
+ 0xaf63bd4c8601b7df ,
179
+ 0xdb090f8a5cd75210 ,
180
+ 0xabae35c7872c107d ,
181
+ 0xfec74888bcef5fcd ,
182
+ 0x27ba96030abceda5
183
+ #else
184
+ 0xaf63bd4c8601b7df ,
185
+ 0x7e868fbf541faf44 ,
186
+ 0x420cca3a4cb623bb ,
187
+ 0x16636d996304ee7f ,
188
+ 0x33afc9f1b274fa67
189
+ #endif
190
+ };
191
+
192
+ DOR (mp_init (& a ));
193
+ for (i = 0 ; i < len ; ++ i ) {
194
+ DO (mp_read_radix (& a , input [i ], 64 ));
195
+ DO (mp_hash (& a , & hash ));
196
+ EXPECT (hash == hvals [i ]);
197
+ }
198
+
199
+ mp_clear (& a );
200
+ return EXIT_SUCCESS ;
201
+ LBL_ERR :
202
+ mp_clear (& a );
203
+ return EXIT_FAILURE ;
204
+ }
205
+
156
206
static int check_get_set_i32 (mp_int * a , int32_t b )
157
207
{
158
208
mp_clear (a );
@@ -2164,6 +2214,7 @@ static int unit_tests(int argc, char **argv)
2164
2214
#define T3 (n , o1 , o2 , o3 ) { #n, (MP_HAS(o1) && MP_HAS(o2) && MP_HAS(o3)) ? test_##n : NULL }
2165
2215
T0 (feature_detection ),
2166
2216
T0 (trivial_stuff ),
2217
+ T1 (mp_hash , MP_HASH ),
2167
2218
T2 (mp_get_set_i32 , MP_GET_I32 , MP_GET_MAG_U32 ),
2168
2219
T2 (mp_get_set_i64 , MP_GET_I64 , MP_GET_MAG_U64 ),
2169
2220
T1 (mp_and , MP_AND ),
0 commit comments