@@ -77,42 +77,73 @@ SECP256K1_WARN_UNUSED_RESULT int secp256k1_ecdsa_verify(
7777 int pubkeylen
7878) SECP256K1_ARG_NONNULL (1 ) SECP256K1_ARG_NONNULL (2 ) SECP256K1_ARG_NONNULL (4 );
7979
80+ /** A pointer to a function to deterministically generate a nonce.
81+ * Returns: 1 if a nonce was succesfully generated. 0 will cause signing to fail.
82+ * In: msg32: the 32-byte message hash being verified (will not be NULL)
83+ * key32: pointer to a 32-byte secret key (will not be NULL)
84+ * attempt: how many iterations we have tried to find a nonce.
85+ * This will almost always be 0, but different attempt values
86+ * are required to result in a different nonce.
87+ * data: Arbitrary data pointer that is passed through.
88+ * Out: nonce32: pointer to a 32-byte array to be filled by the function.
89+ * Except for test cases, this function should compute some cryptographic hash of
90+ * the message, the key and the attempt.
91+ */
92+ typedef int (* secp256k1_nonce_function_t )(
93+ unsigned char * nonce32 ,
94+ const unsigned char * msg32 ,
95+ const unsigned char * key32 ,
96+ unsigned int attempt ,
97+ const void * data
98+ );
99+
100+ /** An implementation of RFC6979 (using HMAC-SHA256) as nonce generation function. */
101+ extern const secp256k1_nonce_function_t secp256k1_nonce_function_rfc6979 ;
102+
103+ /** A default safe nonce generation function (currently equal to secp256k1_nonce_function_rfc6979). */
104+ extern const secp256k1_nonce_function_t secp256k1_nonce_function_default ;
105+
106+
80107/** Create an ECDSA signature.
81108 * Returns: 1: signature created
82- * 0: nonce invalid, try another one
109+ * 0: the nonce generation function failed
83110 * In: msg32: the 32-byte message hash being signed (cannot be NULL)
84111 * seckey: pointer to a 32-byte secret key (cannot be NULL, assumed to be valid)
85- * nonce: pointer to a 32-byte nonce (cannot be NULL, generated with a cryptographic PRNG)
112+ * noncefp:pointer to a nonce generation function. If NULL, secp256k1_nonce_function_default is used
113+ * ndata: pointer to arbitrary data used by the nonce generation function (can be NULL)
86114 * Out: sig: pointer to an array where the signature will be placed (cannot be NULL)
87115 * In/Out: siglen: pointer to an int with the length of sig, which will be updated
88116 * to contain the actual signature length (<=72).
89117 * Requires starting using SECP256K1_START_SIGN.
90118 */
91- SECP256K1_WARN_UNUSED_RESULT int secp256k1_ecdsa_sign (
119+ int secp256k1_ecdsa_sign (
92120 const unsigned char * msg32 ,
93121 unsigned char * sig ,
94122 int * siglen ,
95123 const unsigned char * seckey ,
96- const unsigned char * nonce
97- ) SECP256K1_ARG_NONNULL (1 ) SECP256K1_ARG_NONNULL (2 ) SECP256K1_ARG_NONNULL (3 ) SECP256K1_ARG_NONNULL (4 ) SECP256K1_ARG_NONNULL (5 );
124+ secp256k1_nonce_function_t noncefp ,
125+ const void * ndata
126+ ) SECP256K1_ARG_NONNULL (1 ) SECP256K1_ARG_NONNULL (2 ) SECP256K1_ARG_NONNULL (3 ) SECP256K1_ARG_NONNULL (4 );
98127
99128/** Create a compact ECDSA signature (64 byte + recovery id).
100129 * Returns: 1: signature created
101- * 0: nonce invalid, try another one
130+ * 0: the nonce generation function failed
102131 * In: msg32: the 32-byte message hash being signed (cannot be NULL)
103132 * seckey: pointer to a 32-byte secret key (cannot be NULL, assumed to be valid)
104- * nonce: pointer to a 32-byte nonce (cannot be NULL, generated with a cryptographic PRNG)
133+ * noncefp:pointer to a nonce generation function. If NULL, secp256k1_nonce_function_default is used
134+ * ndata: pointer to arbitrary data used by the nonce generation function (can be NULL)
105135 * Out: sig: pointer to a 64-byte array where the signature will be placed (cannot be NULL)
106136 * recid: pointer to an int, which will be updated to contain the recovery id (can be NULL)
107137 * Requires starting using SECP256K1_START_SIGN.
108138 */
109- SECP256K1_WARN_UNUSED_RESULT int secp256k1_ecdsa_sign_compact (
139+ int secp256k1_ecdsa_sign_compact (
110140 const unsigned char * msg32 ,
111141 unsigned char * sig64 ,
112142 const unsigned char * seckey ,
113- const unsigned char * nonce ,
143+ secp256k1_nonce_function_t noncefp ,
144+ const void * ndata ,
114145 int * recid
115- ) SECP256K1_ARG_NONNULL (1 ) SECP256K1_ARG_NONNULL (2 ) SECP256K1_ARG_NONNULL (3 ) SECP256K1_ARG_NONNULL ( 4 ) ;
146+ ) SECP256K1_ARG_NONNULL (1 ) SECP256K1_ARG_NONNULL (2 ) SECP256K1_ARG_NONNULL (3 );
116147
117148/** Recover an ECDSA public key from a compact signature.
118149 * Returns: 1: public key successfully recovered (which guarantees a correct signature).
0 commit comments