Skip to content

Commit

Permalink
f fix tagged hash by setting and add test
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasnick committed Feb 5, 2019
1 parent c5e9fa2 commit 950054e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/modules/musig/main_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ static void secp256k1_musig_sha256_init_tagged(secp256k1_sha256 *sha) {
sha->s[5] = 0xaca1a22ful;
sha->s[6] = 0x6f43b801ul;
sha->s[7] = 0x85ce27cdul;
sha->bytes = 64;
}

/* Compute r = SHA256(ell, idx). The four bytes of idx are serialized least significant byte first. */
Expand Down
6 changes: 6 additions & 0 deletions src/modules/musig/tests_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,7 @@ void sha256_tag_test(void) {
secp256k1_sha256 sha;
secp256k1_sha256 sha_tagged;
unsigned char buf[32];
unsigned char buf2[32];
size_t i;

secp256k1_sha256_initialize(&sha);
Expand All @@ -731,6 +732,11 @@ void sha256_tag_test(void) {
for (i = 0; i < 8; i++) {
CHECK(sha_tagged.s[i] == sha.s[i]);
}
secp256k1_sha256_write(&sha, buf, 32);
secp256k1_sha256_write(&sha_tagged, buf, 32);
secp256k1_sha256_finalize(&sha, buf);
secp256k1_sha256_finalize(&sha_tagged, buf2);
CHECK(memcmp(buf, buf2, 32) == 0);
}

void run_musig_tests(void) {
Expand Down

0 comments on commit 950054e

Please sign in to comment.