Changeset View
Changeset View
Standalone View
Standalone View
src/secp256k1/examples/schnorr.c
| Show All 9 Lines | |||||
| #include <stdio.h> | #include <stdio.h> | ||||
| #include <assert.h> | #include <assert.h> | ||||
| #include <string.h> | #include <string.h> | ||||
| #include <secp256k1.h> | #include <secp256k1.h> | ||||
| #include <secp256k1_extrakeys.h> | #include <secp256k1_extrakeys.h> | ||||
| #include <secp256k1_schnorrsig.h> | #include <secp256k1_schnorrsig.h> | ||||
| #include "random.h" | #include "examples_util.h" | ||||
| int main(void) { | int main(void) { | ||||
| unsigned char msg[] = {'H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd', '!'}; | unsigned char msg[] = {'H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd', '!'}; | ||||
| unsigned char msg_hash[32]; | unsigned char msg_hash[32]; | ||||
| unsigned char tag[] = {'m', 'y', '_', 'f', 'a', 'n', 'c', 'y', '_', 'p', 'r', 'o', 't', 'o', 'c', 'o', 'l'}; | unsigned char tag[] = {'m', 'y', '_', 'f', 'a', 'n', 'c', 'y', '_', 'p', 'r', 'o', 't', 'o', 'c', 'o', 'l'}; | ||||
| unsigned char seckey[32]; | unsigned char seckey[32]; | ||||
| unsigned char randomize[32]; | unsigned char randomize[32]; | ||||
| unsigned char auxiliary_rand[32]; | unsigned char auxiliary_rand[32]; | ||||
| ▲ Show 20 Lines • Show All 108 Lines • ▼ Show 20 Lines | int main(void) { | ||||
| /* This will clear everything from the context and free the memory */ | /* This will clear everything from the context and free the memory */ | ||||
| secp256k1_context_destroy(ctx); | secp256k1_context_destroy(ctx); | ||||
| /* It's best practice to try to clear secrets from memory after using them. | /* It's best practice to try to clear secrets from memory after using them. | ||||
| * This is done because some bugs can allow an attacker to leak memory, for | * This is done because some bugs can allow an attacker to leak memory, for | ||||
| * example through "out of bounds" array access (see Heartbleed), Or the OS | * example through "out of bounds" array access (see Heartbleed), Or the OS | ||||
| * swapping them to disk. Hence, we overwrite the secret key buffer with zeros. | * swapping them to disk. Hence, we overwrite the secret key buffer with zeros. | ||||
| * | * | ||||
| * TODO: Prevent these writes from being optimized out, as any good compiler | * Here we are preventing these writes from being optimized out, as any good compiler | ||||
| * will remove any writes that aren't used. */ | * will remove any writes that aren't used. */ | ||||
| memset(seckey, 0, sizeof(seckey)); | secure_erase(seckey, sizeof(seckey)); | ||||
| return 0; | return 0; | ||||
| } | } | ||||