File tree Expand file tree Collapse file tree 1 file changed +11
-8
lines changed Expand file tree Collapse file tree 1 file changed +11
-8
lines changed 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 ;
You can’t perform that action at this time.
0 commit comments