File tree Expand file tree Collapse file tree 3 files changed +11
-10
lines changed Expand file tree Collapse file tree 3 files changed +11
-10
lines changed Original file line number Diff line number Diff line change @@ -50,8 +50,8 @@ int main(void) {
50
50
printf ("Failed to generate randomness\n" );
51
51
return 1 ;
52
52
}
53
- if (secp256k1_ec_seckey_verify (ctx , seckey1 ) && secp256k1_ec_seckey_verify (ctx , seckey2 )) {
54
- break ;
53
+ if (! secp256k1_ec_seckey_verify (ctx , seckey1 ) || ! secp256k1_ec_seckey_verify (ctx , seckey2 )) {
54
+ return 1 ;
55
55
}
56
56
57
57
/* Public key creation using a valid context with a verified secret key should never fail */
Original file line number Diff line number Diff line change @@ -51,14 +51,14 @@ int main(void) {
51
51
/*** Key Generation ***/
52
52
53
53
/* If the secret key is zero or out of range (bigger than secp256k1's
54
- * order), we try to sample a new key . Note that the probability of this
55
- * happening is negligible. */
54
+ * order), we return 1 . Note that the probability of this
55
+ * happening is negligible, though it could indicate a faulty RNG */
56
56
if (!fill_random (seckey , sizeof (seckey ))) {
57
57
printf ("Failed to generate randomness\n" );
58
58
return 1 ;
59
59
}
60
- if (secp256k1_ec_seckey_verify (ctx , seckey )) {
61
- break ;
60
+ if (! secp256k1_ec_seckey_verify (ctx , seckey )) {
61
+ return 1 ;
62
62
}
63
63
64
64
/* Public key creation using a valid context with a verified secret key should never fail */
Original file line number Diff line number Diff line change @@ -49,14 +49,15 @@ int main(void) {
49
49
/*** Generate secret keys ***/
50
50
51
51
/* If the secret key is zero or out of range (bigger than secp256k1's
52
- * order), we try to sample a new key . Note that the probability of this
53
- * happening is negligible. */
52
+ * order), we return 1 . Note that the probability of this
53
+ * happening is negligible, though it could indicate a faulty RNG */
54
54
if (!fill_random (seckey1 , sizeof (seckey1 )) || !fill_random (seckey2 , sizeof (seckey2 ))) {
55
55
printf ("Failed to generate randomness\n" );
56
56
return 1 ;
57
57
}
58
- if (secp256k1_ec_seckey_verify (ctx , seckey1 ) && secp256k1_ec_seckey_verify (ctx , seckey2 )) {
59
- break ;
58
+ if (!secp256k1_ec_seckey_verify (ctx , seckey1 ) || !secp256k1_ec_seckey_verify (ctx , seckey2 )) {
59
+ printf ("Generated secret key is invalid. This could indicate an issue with the random number generator.\n" )
60
+ return 1 ;
60
61
}
61
62
62
63
/* Generate ElligatorSwift public keys. This should never fail with valid context and
You can’t perform that action at this time.
0 commit comments