Last active
December 11, 2021 11:19
-
-
Save siv2r/3f443c06bbb62aa3a2e0f7d8d9e86c71 to your computer and use it in GitHub Desktop.
using secp256k1_sha256 internal api
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* this is the main function of test.c of libsecp */ | |
/* you can find my complete code here: https://github.com/siv2r/secp256k1/commit/b3a1437f715dad7478515a55728ecb12aaf4dad1 */ | |
#include "modules/debug/main_impl.h" | |
int main() { | |
unsigned char msg[40] = "Hey, this message is going to be hashed"; | |
unsigned char out[32]; | |
secp256k1_sha256 hash; | |
printf("message : %s\n", msg); | |
secp256k1_sha256_initialize(&hash); | |
printf("sha256 (init) : "); | |
print_sha(&hash); // prints the 256 bit hash.s array | |
secp256k1_sha256_write(&hash, msg, 40); | |
printf("sha256 (write) : "); | |
print_sha(&hash); | |
secp256k1_sha256_finalize(&hash, out); | |
printf("sha256 : "); | |
print_sha(&hash); | |
printf("out : "); | |
print_buf(out, 32); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
message : Hey, this message is going to be hashed | |
sha256 (init) : 6a09e667 bb67ae85 3c6ef372 a54ff53a 510e527f 9b05688c 1f83d9ab 5be0cd19 | |
sha256 (write) : 6a09e667 bb67ae85 3c6ef372 a54ff53a 510e527f 9b05688c 1f83d9ab 5be0cd19 | |
sha256 (finalize): 00 00 00 00 00 00 00 00 | |
out : af af fe d8 5c db 5e dd bd 75 04 5a b1 54 ba 0c 04 eb 92 6c d2 6f 01 68 e8 fb d0 f4 a8 35 2a 43 | |
# the out value above is incorrect | |
# the correct value is: | |
2e1d05c3a72fe13a1770451c103503be5ae1381282ea1ea1587180e512aae33f |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment