mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-06 14:19:59 -05:00
Comment copyediting.
This commit is contained in:
parent
b4d17da903
commit
269d422703
6 changed files with 21 additions and 16 deletions
|
@ -229,7 +229,7 @@ SECP256K1_API void secp256k1_context_set_illegal_callback(
|
||||||
* crashing.
|
* crashing.
|
||||||
*
|
*
|
||||||
* Args: ctx: an existing context object (cannot be NULL)
|
* Args: ctx: an existing context object (cannot be NULL)
|
||||||
* In: fun: a pointer to a function to call when an interal error occurs,
|
* In: fun: a pointer to a function to call when an internal error occurs,
|
||||||
* taking a message and an opaque pointer (NULL restores a default
|
* taking a message and an opaque pointer (NULL restores a default
|
||||||
* handler that calls abort).
|
* handler that calls abort).
|
||||||
* data: the opaque pointer to pass to fun above.
|
* data: the opaque pointer to pass to fun above.
|
||||||
|
|
|
@ -92,7 +92,7 @@ SECP256K1_API int secp256k1_ecdsa_sign_recoverable(
|
||||||
* Returns: 1: public key successfully recovered (which guarantees a correct signature).
|
* Returns: 1: public key successfully recovered (which guarantees a correct signature).
|
||||||
* 0: otherwise.
|
* 0: otherwise.
|
||||||
* Args: ctx: pointer to a context object, initialized for verification (cannot be NULL)
|
* Args: ctx: pointer to a context object, initialized for verification (cannot be NULL)
|
||||||
* Out: pubkey: pointer to the recoved public key (cannot be NULL)
|
* Out: pubkey: pointer to the recovered public key (cannot be NULL)
|
||||||
* In: sig: pointer to initialized signature that supports pubkey recovery (cannot be NULL)
|
* In: sig: pointer to initialized signature that supports pubkey recovery (cannot be NULL)
|
||||||
* msg32: the 32-byte message hash assumed to be signed (cannot be NULL)
|
* msg32: the 32-byte message hash assumed to be signed (cannot be NULL)
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -99,7 +99,7 @@ SECP256K1_API int secp256k1_schnorr_generate_nonce_pair(
|
||||||
/** Produce a partial Schnorr signature, which can be combined using
|
/** Produce a partial Schnorr signature, which can be combined using
|
||||||
* secp256k1_schnorr_partial_combine, to end up with a full signature that is
|
* secp256k1_schnorr_partial_combine, to end up with a full signature that is
|
||||||
* verifiable using secp256k1_schnorr_verify.
|
* verifiable using secp256k1_schnorr_verify.
|
||||||
* Returns: 1: signature created succesfully.
|
* Returns: 1: signature created successfully.
|
||||||
* 0: no valid signature exists with this combination of keys, nonces
|
* 0: no valid signature exists with this combination of keys, nonces
|
||||||
* and message (chance around 1 in 2^128)
|
* and message (chance around 1 in 2^128)
|
||||||
* -1: invalid private key, nonce, or public nonces.
|
* -1: invalid private key, nonce, or public nonces.
|
||||||
|
@ -148,7 +148,7 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_schnorr_partial_sign(
|
||||||
) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4) SECP256K1_ARG_NONNULL(5) SECP256K1_ARG_NONNULL(6);
|
) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4) SECP256K1_ARG_NONNULL(5) SECP256K1_ARG_NONNULL(6);
|
||||||
|
|
||||||
/** Combine multiple Schnorr partial signatures.
|
/** Combine multiple Schnorr partial signatures.
|
||||||
* Returns: 1: the passed signatures were succesfully combined.
|
* Returns: 1: the passed signatures were successfully combined.
|
||||||
* 0: the resulting signature is not valid (chance of 1 in 2^256)
|
* 0: the resulting signature is not valid (chance of 1 in 2^256)
|
||||||
* -1: some inputs were invalid, or the signatures were not created
|
* -1: some inputs were invalid, or the signatures were not created
|
||||||
* using the same set of nonces
|
* using the same set of nonces
|
||||||
|
|
|
@ -75,8 +75,9 @@ static int secp256k1_der_read_len(const unsigned char **sigp, const unsigned cha
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if ((size_t)lenleft > sizeof(size_t)) {
|
if ((size_t)lenleft > sizeof(size_t)) {
|
||||||
/* The resulthing length would exceed the range of a size_t, so
|
/* The resulting length would exceed the range of a size_t, so
|
||||||
certainly longer than the passed array size. */
|
* certainly longer than the passed array size.
|
||||||
|
*/
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
while (lenleft > 0) {
|
while (lenleft > 0) {
|
||||||
|
@ -267,13 +268,17 @@ static int secp256k1_ecdsa_sig_sign(const secp256k1_ecmult_gen_context *ctx, sec
|
||||||
secp256k1_fe_get_b32(b, &r.x);
|
secp256k1_fe_get_b32(b, &r.x);
|
||||||
secp256k1_scalar_set_b32(sigr, b, &overflow);
|
secp256k1_scalar_set_b32(sigr, b, &overflow);
|
||||||
if (secp256k1_scalar_is_zero(sigr)) {
|
if (secp256k1_scalar_is_zero(sigr)) {
|
||||||
/* P.x = order is on the curve, so technically sig->r could end up zero, which would be an invalid signature. */
|
/* P.x = order is on the curve, so technically sig->r could end up zero, which would be an invalid signature.
|
||||||
/* This branch is cryptographically unreachable as hitting it requires finding the discrete log of P.x = N. */
|
* This branch is cryptographically unreachable as hitting it requires finding the discrete log of P.x = N.
|
||||||
|
*/
|
||||||
secp256k1_gej_clear(&rp);
|
secp256k1_gej_clear(&rp);
|
||||||
secp256k1_ge_clear(&r);
|
secp256k1_ge_clear(&r);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (recid) {
|
if (recid) {
|
||||||
|
/* The overflow condition is cryptographically unreachable as hitting it requires finding the discrete log
|
||||||
|
* of some P where P.x >= order, and only 1 in about 2^127 points meet this criteria.
|
||||||
|
*/
|
||||||
*recid = (overflow ? 2 : 0) | (secp256k1_fe_is_odd(&r.y) ? 1 : 0);
|
*recid = (overflow ? 2 : 0) | (secp256k1_fe_is_odd(&r.y) ? 1 : 0);
|
||||||
}
|
}
|
||||||
secp256k1_scalar_mul(&n, sigr, seckey);
|
secp256k1_scalar_mul(&n, sigr, seckey);
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
/** Field element module.
|
/** Field element module.
|
||||||
*
|
*
|
||||||
* Field elements can be represented in several ways, but code accessing
|
* Field elements can be represented in several ways, but code accessing
|
||||||
* it (and implementations) need to take certain properaties into account:
|
* it (and implementations) need to take certain properties into account:
|
||||||
* - Each field element can be normalized or not.
|
* - Each field element can be normalized or not.
|
||||||
* - Each field element has a magnitude, which represents how far away
|
* - Each field element has a magnitude, which represents how far away
|
||||||
* its representation is away from normalization. Normalized elements
|
* its representation is away from normalization. Normalized elements
|
||||||
|
|
14
src/tests.c
14
src/tests.c
|
@ -594,7 +594,7 @@ void scalar_test(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
/* Test that multipying the scalars is equal to multiplying their numbers modulo the order. */
|
/* Test that multiplying the scalars is equal to multiplying their numbers modulo the order. */
|
||||||
secp256k1_scalar r;
|
secp256k1_scalar r;
|
||||||
secp256k1_num r2num;
|
secp256k1_num r2num;
|
||||||
secp256k1_num rnum;
|
secp256k1_num rnum;
|
||||||
|
@ -840,7 +840,7 @@ void run_scalar_tests(void) {
|
||||||
|
|
||||||
{
|
{
|
||||||
/* Static test vectors.
|
/* Static test vectors.
|
||||||
* These were reduced from ~10^12 random vectors based on comparision-decision
|
* These were reduced from ~10^12 random vectors based on comparison-decision
|
||||||
* and edge-case coverage on 32-bit and 64-bit implementations.
|
* and edge-case coverage on 32-bit and 64-bit implementations.
|
||||||
* The responses were generated with Sage 5.9.
|
* The responses were generated with Sage 5.9.
|
||||||
*/
|
*/
|
||||||
|
@ -1737,7 +1737,7 @@ void test_ge(void) {
|
||||||
/* Points: (infinity, p1, p1, -p1, -p1, p2, p2, -p2, -p2, p3, p3, -p3, -p3, p4, p4, -p4, -p4).
|
/* Points: (infinity, p1, p1, -p1, -p1, p2, p2, -p2, -p2, p3, p3, -p3, -p3, p4, p4, -p4, -p4).
|
||||||
* The second in each pair of identical points uses a random Z coordinate in the Jacobian form.
|
* The second in each pair of identical points uses a random Z coordinate in the Jacobian form.
|
||||||
* All magnitudes are randomized.
|
* All magnitudes are randomized.
|
||||||
* All 17*17 combinations of points are added to eachother, using all applicable methods.
|
* All 17*17 combinations of points are added to each other, using all applicable methods.
|
||||||
*
|
*
|
||||||
* When the endomorphism code is compiled in, p5 = lambda*p1 and p6 = lambda^2*p1 are added as well.
|
* When the endomorphism code is compiled in, p5 = lambda*p1 and p6 = lambda^2*p1 are added as well.
|
||||||
*/
|
*/
|
||||||
|
@ -2420,7 +2420,7 @@ void run_ecmult_constants(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_ecmult_gen_blind(void) {
|
void test_ecmult_gen_blind(void) {
|
||||||
/* Test ecmult_gen() blinding and confirm that the blinding changes, the affline points match, and the z's don't match. */
|
/* Test ecmult_gen() blinding and confirm that the blinding changes, the affine points match, and the z's don't match. */
|
||||||
secp256k1_scalar key;
|
secp256k1_scalar key;
|
||||||
secp256k1_scalar b;
|
secp256k1_scalar b;
|
||||||
unsigned char seed32[32];
|
unsigned char seed32[32];
|
||||||
|
@ -3139,7 +3139,7 @@ static int nonce_function_test_retry(unsigned char *nonce32, const unsigned char
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
/* Retry rate of 6979 is negligible esp. as we only call this in determinstic tests. */
|
/* Retry rate of 6979 is negligible esp. as we only call this in deterministic tests. */
|
||||||
/* If someone does fine a case where it retries for secp256k1, we'd like to know. */
|
/* If someone does fine a case where it retries for secp256k1, we'd like to know. */
|
||||||
if (counter > 5) {
|
if (counter > 5) {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -3966,7 +3966,7 @@ void test_ecdsa_edge_cases(void) {
|
||||||
CHECK(secp256k1_ecdsa_sign(ctx, &sig2, msg, key, nonce_function_rfc6979, extra) == 1);
|
CHECK(secp256k1_ecdsa_sign(ctx, &sig2, msg, key, nonce_function_rfc6979, extra) == 1);
|
||||||
CHECK(!is_empty_signature(&sig2));
|
CHECK(!is_empty_signature(&sig2));
|
||||||
CHECK(memcmp(&sig, &sig2, sizeof(sig)) == 0);
|
CHECK(memcmp(&sig, &sig2, sizeof(sig)) == 0);
|
||||||
/* The default nonce function is determinstic. */
|
/* The default nonce function is deterministic. */
|
||||||
CHECK(secp256k1_ecdsa_sign(ctx, &sig2, msg, key, NULL, extra) == 1);
|
CHECK(secp256k1_ecdsa_sign(ctx, &sig2, msg, key, NULL, extra) == 1);
|
||||||
CHECK(!is_empty_signature(&sig2));
|
CHECK(!is_empty_signature(&sig2));
|
||||||
CHECK(memcmp(&sig, &sig2, sizeof(sig)) == 0);
|
CHECK(memcmp(&sig, &sig2, sizeof(sig)) == 0);
|
||||||
|
@ -3998,7 +3998,7 @@ void test_ecdsa_edge_cases(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
/* Check that optional nonce arguments do not have equivilent effect. */
|
/* Check that optional nonce arguments do not have equivalent effect. */
|
||||||
const unsigned char zeros[32] = {0};
|
const unsigned char zeros[32] = {0};
|
||||||
unsigned char nonce[32];
|
unsigned char nonce[32];
|
||||||
unsigned char nonce2[32];
|
unsigned char nonce2[32];
|
||||||
|
|
Loading…
Add table
Reference in a new issue