examples: make key generation doc consistent
This commit is contained in:
@@ -47,8 +47,8 @@ int main(void) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
/* If the secret key is zero or out of range (greater than secp256k1's
|
/* If the secret key is zero or out of range (greater than secp256k1's
|
||||||
* order), we fail. Note that the probability of this occurring
|
* order), we fail. Note that the probability of this occurring is negligible
|
||||||
* is negligible with a properly functioning random number generator. */
|
* with a properly functioning random number generator. */
|
||||||
if (!secp256k1_ec_seckey_verify(ctx, seckey1) || !secp256k1_ec_seckey_verify(ctx, seckey2)) {
|
if (!secp256k1_ec_seckey_verify(ctx, seckey1) || !secp256k1_ec_seckey_verify(ctx, seckey2)) {
|
||||||
printf("Generated secret key is invalid. This indicates an issue with the random number generator.\n");
|
printf("Generated secret key is invalid. This indicates an issue with the random number generator.\n");
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
@@ -49,13 +49,13 @@ int main(void) {
|
|||||||
assert(return_val);
|
assert(return_val);
|
||||||
|
|
||||||
/*** Key Generation ***/
|
/*** Key Generation ***/
|
||||||
/* If the secret key is zero or out of range (greater than secp256k1's
|
|
||||||
* order), we return 1. Note that the probability of this occurring
|
|
||||||
* is negligible with a properly functioning random number generator. */
|
|
||||||
if (!fill_random(seckey, sizeof(seckey))) {
|
if (!fill_random(seckey, sizeof(seckey))) {
|
||||||
printf("Failed to generate randomness\n");
|
printf("Failed to generate randomness\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
/* If the secret key is zero or out of range (greater than secp256k1's
|
||||||
|
* order), we fail. Note that the probability of this occurring is negligible
|
||||||
|
* with a properly functioning random number generator. */
|
||||||
if (!secp256k1_ec_seckey_verify(ctx, seckey)) {
|
if (!secp256k1_ec_seckey_verify(ctx, seckey)) {
|
||||||
printf("Generated secret key is invalid. This indicates an issue with the random number generator.\n");
|
printf("Generated secret key is invalid. This indicates an issue with the random number generator.\n");
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
@@ -47,14 +47,13 @@ int main(void) {
|
|||||||
assert(return_val);
|
assert(return_val);
|
||||||
|
|
||||||
/*** Generate secret keys ***/
|
/*** Generate secret keys ***/
|
||||||
|
|
||||||
/* If the secret key is zero or out of range (greater than secp256k1's
|
|
||||||
* order), we return 1. Note that the probability of this occurring
|
|
||||||
* is negligible with a properly functioning random number generator. */
|
|
||||||
if (!fill_random(seckey1, sizeof(seckey1)) || !fill_random(seckey2, sizeof(seckey2))) {
|
if (!fill_random(seckey1, sizeof(seckey1)) || !fill_random(seckey2, sizeof(seckey2))) {
|
||||||
printf("Failed to generate randomness\n");
|
printf("Failed to generate randomness\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
/* If the secret key is zero or out of range (greater than secp256k1's
|
||||||
|
* order), we fail. Note that the probability of this occurring is negligible
|
||||||
|
* with a properly functioning random number generator. */
|
||||||
if (!secp256k1_ec_seckey_verify(ctx, seckey1) || !secp256k1_ec_seckey_verify(ctx, seckey2)) {
|
if (!secp256k1_ec_seckey_verify(ctx, seckey1) || !secp256k1_ec_seckey_verify(ctx, seckey2)) {
|
||||||
printf("Generated secret key is invalid. This indicates an issue with the random number generator.\n");
|
printf("Generated secret key is invalid. This indicates an issue with the random number generator.\n");
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
@@ -43,18 +43,17 @@ int main(void) {
|
|||||||
assert(return_val);
|
assert(return_val);
|
||||||
|
|
||||||
/*** Key Generation ***/
|
/*** Key Generation ***/
|
||||||
/* If the secret key is zero or out of range (greater than secp256k1's
|
|
||||||
* order), we return 1. Note that the probability of this occurring
|
|
||||||
* is negligible with a properly functioning random number generator. */
|
|
||||||
if (!fill_random(seckey, sizeof(seckey))) {
|
if (!fill_random(seckey, sizeof(seckey))) {
|
||||||
printf("Failed to generate randomness\n");
|
printf("Failed to generate randomness\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
/* Try to create a keypair with a valid context, it should only fail if
|
/* Try to create a keypair with a valid context. This only fails if the
|
||||||
* the secret key is zero or out of range. */
|
* secret key is zero or out of range (greater than secp256k1's order). Note
|
||||||
|
* that the probability of this occurring is negligible with a properly
|
||||||
|
* functioning random number generator. */
|
||||||
if (!secp256k1_keypair_create(ctx, &keypair, seckey)) {
|
if (!secp256k1_keypair_create(ctx, &keypair, seckey)) {
|
||||||
printf("Generated secret key is invalid. This indicates an issue with the random number generator.\n");
|
printf("Generated secret key is invalid. This indicates an issue with the random number generator.\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Extract the X-only public key from the keypair. We pass NULL for
|
/* Extract the X-only public key from the keypair. We pass NULL for
|
||||||
|
|||||||
Reference in New Issue
Block a user