@@ -950,6 +950,55 @@ static int s_ecdsa_p256_test_small_coordinate_verification(struct aws_allocator
950950}
951951AWS_TEST_CASE (ecdsa_p256_test_small_coordinate_verification , s_ecdsa_p256_test_small_coordinate_verification );
952952
953+ static int s_ecdsa_signature_encode_helper_roundtrip (struct aws_allocator * allocator , void * ctx ) {
954+ (void )ctx ;
955+ aws_cal_library_test_init (allocator );
956+
957+ struct aws_byte_cursor signature_value_cursor = aws_byte_cursor_from_string (s_signature_value );
958+ size_t binary_length = 0 ;
959+ if (aws_hex_compute_decoded_len (signature_value_cursor .len , & binary_length )) {
960+ return AWS_OP_ERR ;
961+ }
962+ struct aws_byte_buf binary_signature ;
963+ AWS_ZERO_STRUCT (binary_signature );
964+
965+ aws_byte_buf_init (& binary_signature , allocator , binary_length );
966+
967+ ASSERT_SUCCESS (aws_hex_decode (& signature_value_cursor , & binary_signature ));
968+
969+ struct aws_byte_cursor r ;
970+ AWS_ZERO_STRUCT (r );
971+ struct aws_byte_cursor s ;
972+ AWS_ZERO_STRUCT (s );
973+ struct aws_byte_cursor bin_cursor = aws_byte_cursor_from_buf (& binary_signature );
974+ ASSERT_SUCCESS (aws_ecc_decode_signature_der_to_raw (allocator , bin_cursor , & r , & s ));
975+
976+ uint8_t expected_r [] = {0x7c , 0xfd , 0x51 , 0xaf , 0x2b , 0x72 , 0x2f , 0x8d , 0x1f , 0xa1 , 0xaf ,
977+ 0xb6 , 0x5b , 0x4d , 0x54 , 0x86 , 0xed , 0x59 , 0xa6 , 0x7b , 0xcf , 0x9f ,
978+ 0x3a , 0xcc , 0x62 , 0xaa , 0xd6 , 0xdd , 0xd3 , 0x7d , 0xb1 };
979+ struct aws_byte_cursor expected_r_cur = aws_byte_cursor_from_array (expected_r , sizeof (expected_r ));
980+ uint8_t expected_s [] = {0x9d , 0x4c , 0x9f , 0x9a , 0x37 , 0x10 , 0x4f , 0xc0 , 0x1a , 0x8d , 0xaf ,
981+ 0xfc , 0x9a , 0x6b , 0xd1 , 0x05 , 0x6b , 0x7b , 0x43 , 0xc1 , 0x19 , 0x6e ,
982+ 0xdd , 0xe0 , 0xb5 , 0x28 , 0x78 , 0xb7 , 0x59 , 0x62 , 0x8f , 0x8c };
983+ struct aws_byte_cursor expected_s_cur = aws_byte_cursor_from_array (expected_s , sizeof (expected_s ));
984+
985+ ASSERT_BIN_ARRAYS_EQUALS (expected_r_cur .ptr , expected_r_cur .len , r .ptr , r .len );
986+ ASSERT_BIN_ARRAYS_EQUALS (expected_s_cur .ptr , expected_s_cur .len , s .ptr , s .len );
987+
988+ struct aws_byte_buf encoded_sig ;
989+ aws_byte_buf_init (& encoded_sig , allocator , 128 );
990+ ASSERT_SUCCESS (aws_ecc_encode_signature_raw_to_der (allocator , r , s , & encoded_sig ));
991+
992+ ASSERT_BIN_ARRAYS_EQUALS (binary_signature .buffer , binary_signature .len , encoded_sig .buffer , encoded_sig .len );
993+
994+ aws_byte_buf_clean_up (& binary_signature );
995+ aws_byte_buf_clean_up (& encoded_sig );
996+
997+ aws_cal_library_clean_up ();
998+ return AWS_OP_SUCCESS ;
999+ }
1000+ AWS_TEST_CASE (ecdsa_signature_encode_helper_roundtrip , s_ecdsa_signature_encode_helper_roundtrip );
1001+
9531002#ifdef AWS_OS_APPLE
9541003
9551004static int s_test_key_gen_from_private_fuzz (
0 commit comments