File tree 3 files changed +12
-10
lines changed
3 files changed +12
-10
lines changed Original file line number Diff line number Diff line change @@ -38,14 +38,16 @@ 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
+ /* If the secret key is zero or out of range (greater than secp256k1's
47
+ * order), we fail. Note that the probability of this occurring
48
+ * is negligible with a properly functioning random number generator. */
49
+ if (secp256k1_keypair_create (ctx , & signer_secrets -> keypair , seckey )) {
50
+ return 0 ;
49
51
}
50
52
if (!secp256k1_keypair_pub (ctx , & signer -> pubkey , & signer_secrets -> keypair )) {
51
53
return 0 ;
Original file line number Diff line number Diff line change @@ -54,7 +54,7 @@ int main(void) {
54
54
* the secret key is zero or out of range. */
55
55
if (!secp256k1_keypair_create (ctx , & keypair , seckey )) {
56
56
printf ("Generated secret key is invalid. This indicates an issue with the random number generator.\n" );
57
- return 1 ;
57
+ return 1 ;
58
58
}
59
59
60
60
/* 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
*
You can’t perform that action at this time.
0 commit comments