@@ -447,10 +447,19 @@ const secp256k1_nonce_function secp256k1_nonce_function_rfc6979 = nonce_function
447
447
const secp256k1_nonce_function secp256k1_nonce_function_default = nonce_function_rfc6979 ;
448
448
449
449
/* TODO: re-order functions in this file so forward declarations are not needed? */
450
- static int secp256k1_ecdsa_sign_helper (const secp256k1_context * ctx , secp256k1_ecdsa_signature * signature , secp256k1_s2c_opening * s2c_opening , const unsigned char * msg32 , const unsigned char * seckey , const unsigned char * s2c_data32 , secp256k1_nonce_function noncefp , const void * noncedata );
450
+ static int secp256k1_ecdsa_sign_helper (const secp256k1_context * ctx , secp256k1_scalar * r , secp256k1_scalar * s , secp256k1_s2c_opening * s2c_opening , const unsigned char * msg32 , const unsigned char * seckey , const unsigned char * s2c_data32 , secp256k1_nonce_function noncefp , const void * noncedata , int * recid );
451
451
452
452
int secp256k1_ecdsa_sign (const secp256k1_context * ctx , secp256k1_ecdsa_signature * signature , const unsigned char * msg32 , const unsigned char * seckey , secp256k1_nonce_function noncefp , const void * noncedata ) {
453
- return secp256k1_ecdsa_sign_helper (ctx , signature , NULL , msg32 , seckey , NULL , noncefp , noncedata );
453
+ secp256k1_scalar r , s ;
454
+ int ret ;
455
+ ARG_CHECK (signature != NULL );
456
+ ret = secp256k1_ecdsa_sign_helper (ctx , & r , & s , NULL , msg32 , seckey , NULL , noncefp , noncedata , NULL );
457
+ if (ret ) {
458
+ secp256k1_ecdsa_signature_save (signature , & r , & s );
459
+ } else {
460
+ memset (signature , 0 , sizeof (* signature ));
461
+ }
462
+ return ret ;
454
463
}
455
464
456
465
int secp256k1_ec_seckey_verify (const secp256k1_context * ctx , const unsigned char * seckey ) {
@@ -758,16 +767,15 @@ int secp256k1_s2c_opening_serialize(const secp256k1_context* ctx, unsigned char
758
767
return secp256k1_ec_pubkey_serialize (ctx , & output34 [1 ], & outputlen , & opening -> original_pubnonce , SECP256K1_EC_COMPRESSED );
759
768
}
760
769
761
- static int secp256k1_ecdsa_sign_helper (const secp256k1_context * ctx , secp256k1_ecdsa_signature * signature , secp256k1_s2c_opening * s2c_opening , const unsigned char * msg32 , const unsigned char * seckey , const unsigned char * s2c_data32 , secp256k1_nonce_function noncefp , const void * noncedata ) {
762
- secp256k1_scalar r , s ;
770
+ static int secp256k1_ecdsa_sign_helper (const secp256k1_context * ctx , secp256k1_scalar * r , secp256k1_scalar * s , secp256k1_s2c_opening * s2c_opening , const unsigned char * msg32 , const unsigned char * seckey , const unsigned char * s2c_data32 , secp256k1_nonce_function noncefp , const void * noncedata , int * recid ) {
763
771
secp256k1_scalar sec , non , msg ;
764
772
int ret = 0 ;
765
773
int overflow = 0 ;
766
774
unsigned char ndata [32 ];
767
775
VERIFY_CHECK (ctx != NULL );
768
776
ARG_CHECK (secp256k1_ecmult_gen_context_is_built (& ctx -> ecmult_gen_ctx ));
769
777
ARG_CHECK (msg32 != NULL );
770
- ARG_CHECK (signature != NULL );
778
+ ARG_CHECK (r != NULL && s != NULL );
771
779
ARG_CHECK (seckey != NULL );
772
780
if (noncefp == NULL ) {
773
781
noncefp = secp256k1_nonce_function_default ;
@@ -829,7 +837,7 @@ static int secp256k1_ecdsa_sign_helper(const secp256k1_context *ctx, secp256k1_e
829
837
}
830
838
831
839
if (!overflow && !is_zero ) {
832
- if (secp256k1_ecdsa_sig_sign (& ctx -> ecmult_gen_ctx , & r , & s , & sec , & msg , & non , NULL )) {
840
+ if (secp256k1_ecdsa_sig_sign (& ctx -> ecmult_gen_ctx , r , s , & sec , & msg , & non , recid )) {
833
841
break ;
834
842
}
835
843
}
@@ -841,11 +849,6 @@ static int secp256k1_ecdsa_sign_helper(const secp256k1_context *ctx, secp256k1_e
841
849
secp256k1_scalar_clear (& non );
842
850
secp256k1_scalar_clear (& sec );
843
851
}
844
- if (ret ) {
845
- secp256k1_ecdsa_signature_save (signature , & r , & s );
846
- } else {
847
- memset (signature , 0 , sizeof (* signature ));
848
- }
849
852
return ret ;
850
853
}
851
854
0 commit comments