Skip to content

Commit ba732ef

Browse files
committed
f address some of pieter's comments
1 parent 2e4ed39 commit ba732ef

File tree

4 files changed

+20
-19
lines changed

4 files changed

+20
-19
lines changed

include/secp256k1.h

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ SECP256K1_API int secp256k1_ecdsa_signature_serialize_compact(
447447
/** Verify an ECDSA signature.
448448
*
449449
* Returns: 1: correct signature
450-
* 0: incorrect or unparseable signature
450+
* 0: incorrect signature
451451
* Args: ctx: a secp256k1 context object, initialized for verification.
452452
* In: sig: the signature being verified (cannot be NULL)
453453
* msg32: the 32-byte message hash being verified (cannot be NULL)
@@ -524,9 +524,14 @@ SECP256K1_API int secp256k1_ecdsa_signature_normalize(
524524
SECP256K1_API extern const secp256k1_nonce_function secp256k1_nonce_function_rfc6979;
525525

526526
/** An implementation of the nonce generation function as defined in BIP-schnorr.
527+
*
527528
* If a data pointer is passed, it is assumed to be a pointer to 32 bytes of
528-
* extra entropy. The attempt argument must be 0 or the function will fail and
529-
* return 0.
529+
* extra entropy. If the data pointer is NULL and this function is used in
530+
* schnorrsig_sign, it produces BIP-schnorr compliant signatures.
531+
* When this function is used in ecdsa_sign, it generates a nonce using an
532+
* analogue of the bip-schnorr nonce generation algorithm, but with tag
533+
* "BIPSchnorrNULL" instead of "BIPSchnorrDerive".
534+
* The attempt argument must be 0 or the function will fail and return 0.
530535
*/
531536
SECP256K1_API extern const secp256k1_nonce_function secp256k1_nonce_function_bipschnorr;
532537

@@ -710,10 +715,8 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_combine(
710715

711716
/** Opaque data structure that holds a parsed and valid "x-only" public key.
712717
* An x-only pubkey encodes a positive point. That is a point whose Y
713-
* coordinate is a quadratic residue. It is serialized using only its X
714-
* coordinate (32 bytes). A secp256k1_xonly_pubkey is also a secp256k1_pubkey
715-
* but the inverse is not true. Therefore, a secp256k1_pubkey must never be
716-
* interpreted as or copied into a secp256k1_xonly_pubkey.
718+
* coordinate is square. It is serialized using only its X coordinate (32
719+
* bytes).
717720
*
718721
* The exact representation of data inside is implementation defined and not
719722
* guaranteed to be portable between different platforms or versions. It is
@@ -758,10 +761,8 @@ SECP256K1_API int secp256k1_xonly_pubkey_serialize(
758761
const secp256k1_xonly_pubkey* pubkey
759762
) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3);
760763

761-
/** Compute the xonly public key for a secret key. Just as ec_pubkey_create this
762-
* function computes the point P by multiplying the seckey (interpreted as a scalar)
763-
* with the generator. The public key corresponds to P if the Y coordinate of P is a
764-
* quadratic residue or -P otherwise.
764+
/** Compute the xonly public key for a secret key. Same as ec_pubkey_create, but
765+
* for xonly public keys.
765766
*
766767
* Returns: 1 if secret was valid, public key stores
767768
* 0 if secret was invalid, try again

include/secp256k1_schnorrsig.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,11 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_schnorrsig_verify(
103103
*
104104
* Args: ctx: a secp256k1 context object, initialized for verification.
105105
* scratch: scratch space used for the multiexponentiation
106-
* In: sig: array of signatures, or NULL if there are no signatures
107-
* msg32: array of messages, or NULL if there are no signatures
108-
* pk: array of x-only public keys, or NULL if there are no signatures
109-
* n_sigs: number of signatures in above arrays. Must be smaller than
110-
* 2^31 and smaller than half the maximum size_t value. Must be 0
111-
* if above arrays are NULL.
106+
* In: sig: array of pointers to signatures, or NULL if there are no signatures
107+
* msg32: array of pointers to messages, or NULL if there are no signatures
108+
* pk: array of pointers to x-only public keys, or NULL if there are no signatures
109+
* n_sigs: number of signatures in above arrays. Must be below the
110+
* minimum of 2^31 and SIZE_MAX/2. Must be 0 if above arrays are NULL.
112111
*/
113112
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_schnorrsig_verify_batch(
114113
const secp256k1_context* ctx,

src/hash_impl.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,7 @@ static void secp256k1_sha256_finalize(secp256k1_sha256 *hash, unsigned char *out
164164
}
165165

166166
/* Initializes a sha256 struct and writes the 64 byte string
167-
* SHA256(tag)||SHA256(tag) into it. The taglen should be less than or equal to
168-
* 64. */
167+
* SHA256(tag)||SHA256(tag) into it. */
169168
static void secp256k1_sha256_initialize_tagged(secp256k1_sha256 *hash, const unsigned char *tag, size_t taglen) {
170169
unsigned char buf[32];
171170
secp256k1_sha256_initialize(hash);

src/modules/schnorrsig/main_impl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,12 @@ int secp256k1_schnorrsig_sign(const secp256k1_context* ctx, secp256k1_schnorrsig
8383
}
8484

8585
if (!noncefp(buf, msg32, seckey, (unsigned char *) "BIPSchnorrDerive", (void*)ndata, 0)) {
86+
secp256k1_scalar_clear(&x);
8687
return 0;
8788
}
8889
secp256k1_scalar_set_b32(&k, buf, NULL);
8990
if (secp256k1_scalar_is_zero(&k)) {
91+
secp256k1_scalar_clear(&x);
9092
return 0;
9193
}
9294

0 commit comments

Comments
 (0)