Skip to content

Commit

Permalink
improving examples bitcoin-core#2: fixing my mistakes; changing comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Cheapshot003 committed Aug 29, 2024
1 parent 9ac3bcc commit d9dca14
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
4 changes: 2 additions & 2 deletions examples/ecdh.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ int main(void) {
printf("Failed to generate randomness\n");
return 1;
}
if (secp256k1_ec_seckey_verify(ctx, seckey1) && secp256k1_ec_seckey_verify(ctx, seckey2)) {
break;
if (!secp256k1_ec_seckey_verify(ctx, seckey1) || !secp256k1_ec_seckey_verify(ctx, seckey2)) {
return 1;
}

/* Public key creation using a valid context with a verified secret key should never fail */
Expand Down
8 changes: 4 additions & 4 deletions examples/ecdsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ int main(void) {
/*** Key Generation ***/

/* If the secret key is zero or out of range (bigger than secp256k1's
* order), we try to sample a new key. Note that the probability of this
* happening is negligible. */
* order), we return 1. Note that the probability of this
* happening is negligible, though it could indicate a faulty RNG */
if (!fill_random(seckey, sizeof(seckey))) {
printf("Failed to generate randomness\n");
return 1;
}
if (secp256k1_ec_seckey_verify(ctx, seckey)) {
break;
if (!secp256k1_ec_seckey_verify(ctx, seckey)) {
return 1;
}

/* Public key creation using a valid context with a verified secret key should never fail */
Expand Down
9 changes: 5 additions & 4 deletions examples/ellswift.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,15 @@ int main(void) {
/*** Generate secret keys ***/

/* If the secret key is zero or out of range (bigger than secp256k1's
* order), we try to sample a new key. Note that the probability of this
* happening is negligible. */
* order), we return 1. Note that the probability of this
* happening is negligible, though it could indicate a faulty RNG */
if (!fill_random(seckey1, sizeof(seckey1)) || !fill_random(seckey2, sizeof(seckey2))) {
printf("Failed to generate randomness\n");
return 1;
}
if (secp256k1_ec_seckey_verify(ctx, seckey1) && secp256k1_ec_seckey_verify(ctx, seckey2)) {
break;
if (!secp256k1_ec_seckey_verify(ctx, seckey1) || !secp256k1_ec_seckey_verify(ctx, seckey2)) {
printf("Generated secret key is invalid. This could indicate an issue with the random number generator.\n")
return 1;
}

/* Generate ElligatorSwift public keys. This should never fail with valid context and
Expand Down

0 comments on commit d9dca14

Please sign in to comment.