File tree Expand file tree Collapse file tree 7 files changed +31
-27
lines changed Expand file tree Collapse file tree 7 files changed +31
-27
lines changed Original file line number Diff line number Diff line change @@ -47,8 +47,8 @@ int main(void) {
47
47
return 1 ;
48
48
}
49
49
/* If the secret key is zero or out of range (greater than secp256k1's
50
- * order), we fail. Note that the probability of this occurring
51
- * is negligible with a properly functioning random number generator. */
50
+ * order), we fail. Note that the probability of this occurring is negligible
51
+ * with a properly functioning random number generator. */
52
52
if (!secp256k1_ec_seckey_verify (ctx , seckey1 ) || !secp256k1_ec_seckey_verify (ctx , seckey2 )) {
53
53
printf ("Generated secret key is invalid. This indicates an issue with the random number generator.\n" );
54
54
return 1 ;
Original file line number Diff line number Diff line change @@ -49,13 +49,13 @@ int main(void) {
49
49
assert (return_val );
50
50
51
51
/*** Key Generation ***/
52
- /* If the secret key is zero or out of range (greater than secp256k1's
53
- * order), we return 1. Note that the probability of this occurring
54
- * is negligible with a properly functioning random number generator. */
55
52
if (!fill_random (seckey , sizeof (seckey ))) {
56
53
printf ("Failed to generate randomness\n" );
57
54
return 1 ;
58
55
}
56
+ /* If the secret key is zero or out of range (greater than secp256k1's
57
+ * order), we fail. Note that the probability of this occurring is negligible
58
+ * with a properly functioning random number generator. */
59
59
if (!secp256k1_ec_seckey_verify (ctx , seckey )) {
60
60
printf ("Generated secret key is invalid. This indicates an issue with the random number generator.\n" );
61
61
return 1 ;
Original file line number Diff line number Diff line change @@ -47,14 +47,13 @@ int main(void) {
47
47
assert (return_val );
48
48
49
49
/*** Generate secret keys ***/
50
-
51
- /* If the secret key is zero or out of range (greater than secp256k1's
52
- * order), we return 1. Note that the probability of this occurring
53
- * is negligible with a properly functioning random number generator. */
54
50
if (!fill_random (seckey1 , sizeof (seckey1 )) || !fill_random (seckey2 , sizeof (seckey2 ))) {
55
51
printf ("Failed to generate randomness\n" );
56
52
return 1 ;
57
53
}
54
+ /* If the secret key is zero or out of range (greater than secp256k1's
55
+ * order), we fail. Note that the probability of this occurring is negligible
56
+ * with a properly functioning random number generator. */
58
57
if (!secp256k1_ec_seckey_verify (ctx , seckey1 ) || !secp256k1_ec_seckey_verify (ctx , seckey2 )) {
59
58
printf ("Generated secret key is invalid. This indicates an issue with the random number generator.\n" );
60
59
return 1 ;
Original file line number Diff line number Diff line change @@ -38,14 +38,17 @@ struct signer {
38
38
/* Create a key pair, store it in signer_secrets->keypair and signer->pubkey */
39
39
static int create_keypair (const secp256k1_context * ctx , struct signer_secrets * signer_secrets , struct signer * signer ) {
40
40
unsigned char seckey [32 ];
41
- while (1 ) {
42
- if (!fill_random (seckey , sizeof (seckey ))) {
43
- printf ("Failed to generate randomness\n" );
44
- return 0 ;
45
- }
46
- if (secp256k1_keypair_create (ctx , & signer_secrets -> keypair , seckey )) {
47
- break ;
48
- }
41
+
42
+ if (!fill_random (seckey , sizeof (seckey ))) {
43
+ printf ("Failed to generate randomness\n" );
44
+ return 0 ;
45
+ }
46
+ /* Try to create a keypair with a valid context. This only fails if the
47
+ * secret key is zero or out of range (greater than secp256k1's order). Note
48
+ * that the probability of this occurring is negligible with a properly
49
+ * functioning random number generator. */
50
+ if (!secp256k1_keypair_create (ctx , & signer_secrets -> keypair , seckey )) {
51
+ return 0 ;
49
52
}
50
53
if (!secp256k1_keypair_pub (ctx , & signer -> pubkey , & signer_secrets -> keypair )) {
51
54
return 0 ;
Original file line number Diff line number Diff line change @@ -43,18 +43,17 @@ int main(void) {
43
43
assert (return_val );
44
44
45
45
/*** Key Generation ***/
46
- /* If the secret key is zero or out of range (greater than secp256k1's
47
- * order), we return 1. Note that the probability of this occurring
48
- * is negligible with a properly functioning random number generator. */
49
46
if (!fill_random (seckey , sizeof (seckey ))) {
50
47
printf ("Failed to generate randomness\n" );
51
48
return 1 ;
52
49
}
53
- /* Try to create a keypair with a valid context, it should only fail if
54
- * the secret key is zero or out of range. */
50
+ /* Try to create a keypair with a valid context. This only fails if the
51
+ * secret key is zero or out of range (greater than secp256k1's order). Note
52
+ * that the probability of this occurring is negligible with a properly
53
+ * functioning random number generator. */
55
54
if (!secp256k1_keypair_create (ctx , & keypair , seckey )) {
56
55
printf ("Generated secret key is invalid. This indicates an issue with the random number generator.\n" );
57
- return 1 ;
56
+ return 1 ;
58
57
}
59
58
60
59
/* Extract the X-only public key from the keypair. We pass NULL for
Original file line number Diff line number Diff line change @@ -684,7 +684,7 @@ SECP256K1_API int secp256k1_ecdsa_sign(
684
684
* A secret key is valid if it is not 0 and less than the secp256k1 curve order
685
685
* when interpreted as an integer (most significant byte first). The
686
686
* probability of choosing a 32-byte string uniformly at random which is an
687
- * invalid secret key is negligible. However, if it does happen it should
687
+ * invalid secret key is negligible. However, if it does happen it should
688
688
* be assumed that the randomness source is severely broken and there should
689
689
* be no retry.
690
690
*
Original file line number Diff line number Diff line change @@ -155,10 +155,13 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_xonly_pubkey_tweak_add_
155
155
const unsigned char * tweak32
156
156
) SECP256K1_ARG_NONNULL (1 ) SECP256K1_ARG_NONNULL (2 ) SECP256K1_ARG_NONNULL (4 ) SECP256K1_ARG_NONNULL (5 );
157
157
158
- /** Compute the keypair for a secret key.
158
+ /** Compute the keypair for a valid secret key.
159
159
*
160
- * Returns: 1: secret was valid, keypair is ready to use
161
- * 0: secret was invalid, try again with a different secret
160
+ * See the documentation of `secp256k1_ec_seckey_verify` for more information
161
+ * about the validity of secret keys.
162
+ *
163
+ * Returns: 1: secret key is valid
164
+ * 0: secret key is invalid
162
165
* Args: ctx: pointer to a context object (not secp256k1_context_static).
163
166
* Out: keypair: pointer to the created keypair.
164
167
* In: seckey: pointer to a 32-byte secret key.
You can’t perform that action at this time.
0 commit comments