@@ -1512,14 +1512,22 @@ void test_ecdsa_end_to_end(void) {
15121512 CHECK (secp256k1_ec_pubkey_create (ctx , pubkey , & pubkeylen , privkey , (secp256k1_rand32 () & 3 ) != 0 ) == 1 );
15131513 if (secp256k1_rand32 () & 1 ) {
15141514 unsigned char pubkey2 [65 ] = {0 };
1515- int pubkey2len = pubkeylen ;
1515+ unsigned char pubkey3RE [33 ] = {0 };
1516+ int pubkey2len = pubkeylen , pubkey3len = pubkeylen ;
1517+
15161518 /* Decompress into a new array */
15171519 CHECK (secp256k1_ec_pubkey_decompress (ctx , pubkey , pubkey2 , & pubkey2len ));
1520+
1521+ /* Compress into a new array */
1522+ CHECK (secp256k1_ec_pubkey_compress (ctx , pubkey , pubkey3RE , & pubkey3len ));
1523+
15181524 /* Check that the key was changed iff it was originally compressed */
15191525 if (pubkeylen == 65 ) {
1520- CHECK (memcmp (pubkey , pubkey2 , 65 ) == 0 );
1526+ CHECK (memcmp (pubkey , pubkey2 , 65 ) == 0 ); /* Values should be the same */
1527+ CHECK (memcmp (pubkey3RE , pubkey , 33 ) != 0 ); /* Means it should have been compressed */
15211528 } else {
1522- CHECK (memcmp (pubkey , pubkey2 , 65 ) != 0 );
1529+ CHECK (memcmp (pubkey , pubkey2 , 65 ) != 0 ); /* Should have been decompressed */
1530+ CHECK (memcmp (pubkey3RE , pubkey , 33 ) == 0 ); /* Therefore compressed key should equal initial pubkey */
15231531 }
15241532 /* Decompress in place */
15251533 CHECK (secp256k1_ec_pubkey_decompress (ctx , pubkey , pubkey , & pubkeylen ));
0 commit comments