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