Skip to content

Commit

Permalink
schnorrsig: Add BIP340 varlen test vectors
Browse files Browse the repository at this point in the history
  • Loading branch information
real-or-random committed May 11, 2023
1 parent 97a98be commit 28687b0
Showing 1 changed file with 141 additions and 0 deletions.
141 changes: 141 additions & 0 deletions src/modules/schnorrsig/tests_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,147 @@ static void test_schnorrsig_bip_vectors(void) {
/* No need to check the signature of the test vector as parsing the pubkey already fails */
CHECK(!secp256k1_xonly_pubkey_parse(CTX, &pk_parsed, pk));
}
{
/* Test vector 15 */
const unsigned char sk[32] = {
0x03, 0x40, 0x03, 0x40, 0x03, 0x40, 0x03, 0x40,
0x03, 0x40, 0x03, 0x40, 0x03, 0x40, 0x03, 0x40,
0x03, 0x40, 0x03, 0x40, 0x03, 0x40, 0x03, 0x40,
0x03, 0x40, 0x03, 0x40, 0x03, 0x40, 0x03, 0x40,
};
const unsigned char pk[32] = {
0x77, 0x8C, 0xAA, 0x53, 0xB4, 0x39, 0x3A, 0xC4,
0x67, 0x77, 0x4D, 0x09, 0x49, 0x7A, 0x87, 0x22,
0x4B, 0xF9, 0xFA, 0xB6, 0xF6, 0xE6, 0x8B, 0x23,
0x08, 0x64, 0x97, 0x32, 0x4D, 0x6F, 0xD1, 0x17,
};
const unsigned char aux_rand[32] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
/* const unsigned char msg[0] = {}; */
const unsigned char sig[64] = {
0x71, 0x53, 0x5D, 0xB1, 0x65, 0xEC, 0xD9, 0xFB,
0xBC, 0x04, 0x6E, 0x5F, 0xFA, 0xEA, 0x61, 0x18,
0x6B, 0xB6, 0xAD, 0x43, 0x67, 0x32, 0xFC, 0xCC,
0x25, 0x29, 0x1A, 0x55, 0x89, 0x54, 0x64, 0xCF,
0x60, 0x69, 0xCE, 0x26, 0xBF, 0x03, 0x46, 0x62,
0x28, 0xF1, 0x9A, 0x3A, 0x62, 0xDB, 0x8A, 0x64,
0x9F, 0x2D, 0x56, 0x0F, 0xAC, 0x65, 0x28, 0x27,
0xD1, 0xAF, 0x05, 0x74, 0xE4, 0x27, 0xAB, 0x63,
};
test_schnorrsig_bip_vectors_check_signing(sk, pk, aux_rand, NULL, 0, sig);
test_schnorrsig_bip_vectors_check_verify(pk, NULL, 0, sig, 1);
}
{
/* Test vector 16 */
const unsigned char sk[32] = {
0x03, 0x40, 0x03, 0x40, 0x03, 0x40, 0x03, 0x40,
0x03, 0x40, 0x03, 0x40, 0x03, 0x40, 0x03, 0x40,
0x03, 0x40, 0x03, 0x40, 0x03, 0x40, 0x03, 0x40,
0x03, 0x40, 0x03, 0x40, 0x03, 0x40, 0x03, 0x40,
};
const unsigned char pk[32] = {
0x77, 0x8C, 0xAA, 0x53, 0xB4, 0x39, 0x3A, 0xC4,
0x67, 0x77, 0x4D, 0x09, 0x49, 0x7A, 0x87, 0x22,
0x4B, 0xF9, 0xFA, 0xB6, 0xF6, 0xE6, 0x8B, 0x23,
0x08, 0x64, 0x97, 0x32, 0x4D, 0x6F, 0xD1, 0x17,
};
const unsigned char aux_rand[32] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
const unsigned char msg[] = { 0x11 };
const unsigned char sig[64] = {
0x08, 0xA2, 0x0A, 0x0A, 0xFE, 0xF6, 0x41, 0x24,
0x64, 0x92, 0x32, 0xE0, 0x69, 0x3C, 0x58, 0x3A,
0xB1, 0xB9, 0x93, 0x4A, 0xE6, 0x3B, 0x4C, 0x35,
0x11, 0xF3, 0xAE, 0x11, 0x34, 0xC6, 0xA3, 0x03,
0xEA, 0x31, 0x73, 0xBF, 0xEA, 0x66, 0x83, 0xBD,
0x10, 0x1F, 0xA5, 0xAA, 0x5D, 0xBC, 0x19, 0x96,
0xFE, 0x7C, 0xAC, 0xFC, 0x5A, 0x57, 0x7D, 0x33,
0xEC, 0x14, 0x56, 0x4C, 0xEC, 0x2B, 0xAC, 0xBF,
};
test_schnorrsig_bip_vectors_check_signing(sk, pk, aux_rand, msg, sizeof(msg), sig);
test_schnorrsig_bip_vectors_check_verify(pk, msg, sizeof(msg), sig, 1);
}
{
/* Test vector 17 */
const unsigned char sk[32] = {
0x03, 0x40, 0x03, 0x40, 0x03, 0x40, 0x03, 0x40,
0x03, 0x40, 0x03, 0x40, 0x03, 0x40, 0x03, 0x40,
0x03, 0x40, 0x03, 0x40, 0x03, 0x40, 0x03, 0x40,
0x03, 0x40, 0x03, 0x40, 0x03, 0x40, 0x03, 0x40,
};
const unsigned char pk[32] = {
0x77, 0x8C, 0xAA, 0x53, 0xB4, 0x39, 0x3A, 0xC4,
0x67, 0x77, 0x4D, 0x09, 0x49, 0x7A, 0x87, 0x22,
0x4B, 0xF9, 0xFA, 0xB6, 0xF6, 0xE6, 0x8B, 0x23,
0x08, 0x64, 0x97, 0x32, 0x4D, 0x6F, 0xD1, 0x17,
};
const unsigned char aux_rand[32] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
const unsigned char msg[] = {
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10,
0x11,
};
const unsigned char sig[64] = {
0x51, 0x30, 0xF3, 0x9A, 0x40, 0x59, 0xB4, 0x3B,
0xC7, 0xCA, 0xC0, 0x9A, 0x19, 0xEC, 0xE5, 0x2B,
0x5D, 0x86, 0x99, 0xD1, 0xA7, 0x1E, 0x3C, 0x52,
0xDA, 0x9A, 0xFD, 0xB6, 0xB5, 0x0A, 0xC3, 0x70,
0xC4, 0xA4, 0x82, 0xB7, 0x7B, 0xF9, 0x60, 0xF8,
0x68, 0x15, 0x40, 0xE2, 0x5B, 0x67, 0x71, 0xEC,
0xE1, 0xE5, 0xA3, 0x7F, 0xD8, 0x0E, 0x5A, 0x51,
0x89, 0x7C, 0x55, 0x66, 0xA9, 0x7E, 0xA5, 0xA5,
};
test_schnorrsig_bip_vectors_check_signing(sk, pk, aux_rand, msg, sizeof(msg), sig);
test_schnorrsig_bip_vectors_check_verify(pk, msg, sizeof(msg), sig, 1);
}
{
/* Test vector 18 */
const unsigned char sk[32] = {
0x03, 0x40, 0x03, 0x40, 0x03, 0x40, 0x03, 0x40,
0x03, 0x40, 0x03, 0x40, 0x03, 0x40, 0x03, 0x40,
0x03, 0x40, 0x03, 0x40, 0x03, 0x40, 0x03, 0x40,
0x03, 0x40, 0x03, 0x40, 0x03, 0x40, 0x03, 0x40,
};
const unsigned char pk[32] = {
0x77, 0x8C, 0xAA, 0x53, 0xB4, 0x39, 0x3A, 0xC4,
0x67, 0x77, 0x4D, 0x09, 0x49, 0x7A, 0x87, 0x22,
0x4B, 0xF9, 0xFA, 0xB6, 0xF6, 0xE6, 0x8B, 0x23,
0x08, 0x64, 0x97, 0x32, 0x4D, 0x6F, 0xD1, 0x17,
};
const unsigned char aux_rand[32] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
const unsigned char sig[64] = {
0x40, 0x3B, 0x12, 0xB0, 0xD8, 0x55, 0x5A, 0x34,
0x41, 0x75, 0xEA, 0x7E, 0xC7, 0x46, 0x56, 0x63,
0x03, 0x32, 0x1E, 0x5D, 0xBF, 0xA8, 0xBE, 0x6F,
0x09, 0x16, 0x35, 0x16, 0x3E, 0xCA, 0x79, 0xA8,
0x58, 0x5E, 0xD3, 0xE3, 0x17, 0x08, 0x07, 0xE7,
0xC0, 0x3B, 0x72, 0x0F, 0xC5, 0x4C, 0x7B, 0x23,
0x89, 0x7F, 0xCB, 0xA0, 0xE9, 0xD0, 0xB4, 0xA0,
0x68, 0x94, 0xCF, 0xD2, 0x49, 0xF2, 0x23, 0x67,
};
unsigned char msg[100];
memset(msg, 0x99, sizeof(msg));
test_schnorrsig_bip_vectors_check_signing(sk, pk, aux_rand, msg, sizeof(msg), sig);
test_schnorrsig_bip_vectors_check_verify(pk, msg, sizeof(msg), sig, 1);
}
}

/* Nonce function that returns constant 0 */
Expand Down

0 comments on commit 28687b0

Please sign in to comment.