@@ -627,6 +627,42 @@ int check_fe_inverse(const secp256k1_fe_t *a, const secp256k1_fe_t *ai) {
627627 return check_fe_equal (& x , & one );
628628}
629629
630+ void run_field_convert (void ) {
631+ static const unsigned char b32 [32 ] = {
632+ 0x00 , 0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x06 , 0x07 ,
633+ 0x11 , 0x12 , 0x13 , 0x14 , 0x15 , 0x16 , 0x17 , 0x18 ,
634+ 0x22 , 0x23 , 0x24 , 0x25 , 0x26 , 0x27 , 0x28 , 0x29 ,
635+ 0x33 , 0x34 , 0x35 , 0x36 , 0x37 , 0x38 , 0x39 , 0x40
636+ };
637+ static const char * c64 = "0001020304050607111213141516171822232425262728293334353637383940" ;
638+ static const secp256k1_fe_storage_t fes = SECP256K1_FE_STORAGE_CONST (
639+ 0x00010203UL , 0x04050607UL , 0x11121314UL , 0x15161718UL ,
640+ 0x22232425UL , 0x26272829UL , 0x33343536UL , 0x37383940UL
641+ );
642+ static const secp256k1_fe_t fe = SECP256K1_FE_CONST (
643+ 0x00010203UL , 0x04050607UL , 0x11121314UL , 0x15161718UL ,
644+ 0x22232425UL , 0x26272829UL , 0x33343536UL , 0x37383940UL
645+ );
646+ secp256k1_fe_t fe2 ;
647+ unsigned char b322 [32 ];
648+ char c642 [64 ];
649+ secp256k1_fe_storage_t fes2 ;
650+ /* Check conversions to fe. */
651+ CHECK (secp256k1_fe_set_b32 (& fe2 , b32 ));
652+ CHECK (secp256k1_fe_equal_var (& fe , & fe2 ));
653+ CHECK (secp256k1_fe_set_hex (& fe2 , c64 ));
654+ CHECK (secp256k1_fe_equal_var (& fe , & fe2 ));
655+ secp256k1_fe_from_storage (& fe2 , & fes );
656+ CHECK (secp256k1_fe_equal_var (& fe , & fe2 ));
657+ /* Check conversion from fe. */
658+ secp256k1_fe_get_b32 (b322 , & fe );
659+ CHECK (memcmp (b322 , b32 , 32 ) == 0 );
660+ secp256k1_fe_get_hex (c642 , & fe );
661+ CHECK (memcmp (c642 , c64 , 64 ) == 0 );
662+ secp256k1_fe_to_storage (& fes2 , & fe );
663+ CHECK (memcmp (& fes2 , & fes , sizeof (fes )) == 0 );
664+ }
665+
630666void run_field_misc (void ) {
631667 const unsigned char f32_5 [32 ] = {
632668 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
@@ -1668,6 +1704,7 @@ int main(int argc, char **argv) {
16681704 run_field_inv_var ();
16691705 run_field_inv_all_var ();
16701706 run_field_misc ();
1707+ run_field_convert ();
16711708 run_sqr ();
16721709 run_sqrt ();
16731710
0 commit comments