Skip to content

Commit b2eb63b

Browse files
committed
Merge pull request bitcoin#293
dc0ce9f [API BREAK] Change argument order to out/outin/in (Pieter Wuille)
2 parents 6d947ca + dc0ce9f commit b2eb63b

File tree

14 files changed

+242
-227
lines changed

14 files changed

+242
-227
lines changed

include/secp256k1.h

Lines changed: 91 additions & 76 deletions
Large diffs are not rendered by default.

include/secp256k1_ecdh.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ extern "C" {
1010
/** Compute an EC Diffie-Hellman secret in constant time
1111
* Returns: 1: exponentiation was successful
1212
* 0: scalar was invalid (zero or overflow)
13-
* In: ctx: pointer to a context object (cannot be NULL)
14-
* point: pointer to a public point
15-
* scalar: a 32-byte scalar with which to multiply the point
13+
* Args: ctx: pointer to a context object (cannot be NULL)
1614
* Out: result: a 32-byte array which will be populated by an ECDH
1715
* secret computed from the point and scalar
16+
* In: point: pointer to a public point
17+
* scalar: a 32-byte scalar with which to multiply the point
1818
*/
1919
SECP256K1_WARN_UNUSED_RESULT int secp256k1_ecdh(
2020
const secp256k1_context_t* ctx,

include/secp256k1_recovery.h

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ typedef struct {
2828
/** Parse a compact ECDSA signature (64 bytes + recovery id).
2929
*
3030
* Returns: 1 when the signature could be parsed, 0 otherwise
31-
* In: ctx: a secp256k1 context object
32-
* input64: a pointer to a 64-byte compact signature
33-
* recid: the recovery id (0, 1, 2 or 3)
34-
* Out: sig: a pointer to a signature object
31+
* Args: ctx: a secp256k1 context object
32+
* Out: sig: a pointer to a signature object
33+
* In: input64: a pointer to a 64-byte compact signature
34+
* recid: the recovery id (0, 1, 2 or 3)
3535
*/
3636
int secp256k1_ecdsa_recoverable_signature_parse_compact(
3737
const secp256k1_context_t* ctx,
@@ -43,8 +43,8 @@ int secp256k1_ecdsa_recoverable_signature_parse_compact(
4343
/** Convert a recoverable signature into a normal signature.
4444
*
4545
* Returns: 1
46-
* In: sigin: a pointer to a recoverable signature (cannot be NULL).
4746
* Out: sig: a pointer to a normal signature (cannot be NULL).
47+
* In: sigin: a pointer to a recoverable signature (cannot be NULL).
4848
*/
4949
int secp256k1_ecdsa_recoverable_signature_convert(
5050
const secp256k1_context_t* ctx,
@@ -55,10 +55,10 @@ int secp256k1_ecdsa_recoverable_signature_convert(
5555
/** Serialize an ECDSA signature in compact format (64 bytes + recovery id).
5656
*
5757
* Returns: 1
58-
* In: ctx: a secp256k1 context object
59-
* sig: a pointer to an initialized signature object (cannot be NULL)
60-
* Out: output64: a pointer to a 64-byte array of the compact signature (cannot be NULL)
61-
* recid: a pointer to an integer to hold the recovery id (can be NULL).
58+
* Args: ctx: a secp256k1 context object
59+
* Out: output64: a pointer to a 64-byte array of the compact signature (cannot be NULL)
60+
* recid: a pointer to an integer to hold the recovery id (can be NULL).
61+
* In: sig: a pointer to an initialized signature object (cannot be NULL)
6262
*/
6363
int secp256k1_ecdsa_recoverable_signature_serialize_compact(
6464
const secp256k1_context_t* ctx,
@@ -71,17 +71,17 @@ int secp256k1_ecdsa_recoverable_signature_serialize_compact(
7171
*
7272
* Returns: 1: signature created
7373
* 0: the nonce generation function failed, or the private key was invalid.
74-
* In: ctx: pointer to a context object, initialized for signing (cannot be NULL)
75-
* msg32: the 32-byte message hash being signed (cannot be NULL)
74+
* Args: ctx: pointer to a context object, initialized for signing (cannot be NULL)
75+
* Out: sig: pointer to an array where the signature will be placed (cannot be NULL)
76+
* In: msg32: the 32-byte message hash being signed (cannot be NULL)
7677
* seckey: pointer to a 32-byte secret key (cannot be NULL)
7778
* noncefp:pointer to a nonce generation function. If NULL, secp256k1_nonce_function_default is used
7879
* ndata: pointer to arbitrary data used by the nonce generation function (can be NULL)
79-
* Out: sig: pointer to an array where the signature will be placed (cannot be NULL)
8080
*/
8181
int secp256k1_ecdsa_sign_recoverable(
8282
const secp256k1_context_t* ctx,
83-
const unsigned char *msg32,
8483
secp256k1_ecdsa_recoverable_signature_t *sig,
84+
const unsigned char *msg32,
8585
const unsigned char *seckey,
8686
secp256k1_nonce_function_t noncefp,
8787
const void *ndata
@@ -91,16 +91,16 @@ int secp256k1_ecdsa_sign_recoverable(
9191
*
9292
* Returns: 1: public key successfully recovered (which guarantees a correct signature).
9393
* 0: otherwise.
94-
* In: ctx: pointer to a context object, initialized for verification (cannot be NULL)
95-
* msg32: the 32-byte message hash assumed to be signed (cannot be NULL)
96-
* sig: pointer to initialized signature that supports pubkey recovery (cannot be NULL)
94+
* Args: ctx: pointer to a context object, initialized for verification (cannot be NULL)
9795
* Out: pubkey: pointer to the recoved public key (cannot be NULL)
96+
* In: sig: pointer to initialized signature that supports pubkey recovery (cannot be NULL)
97+
* msg32: the 32-byte message hash assumed to be signed (cannot be NULL)
9898
*/
9999
SECP256K1_WARN_UNUSED_RESULT int secp256k1_ecdsa_recover(
100100
const secp256k1_context_t* ctx,
101-
const unsigned char *msg32,
101+
secp256k1_pubkey_t *pubkey,
102102
const secp256k1_ecdsa_recoverable_signature_t *sig,
103-
secp256k1_pubkey_t *pubkey
103+
const unsigned char *msg32
104104
) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4);
105105

106106
# ifdef __cplusplus

include/secp256k1_schnorr.h

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,21 @@ extern "C" {
1313
* Returns: 1: signature created
1414
* 0: the nonce generation function failed, or the private key was
1515
* invalid.
16-
* In: ctx: pointer to a context object, initialized for signing
16+
* Args: ctx: pointer to a context object, initialized for signing
1717
* (cannot be NULL)
18-
* msg32: the 32-byte message hash being signed (cannot be NULL)
18+
* Out: sig64: pointer to a 64-byte array where the signature will be
19+
* placed (cannot be NULL)
20+
* In: msg32: the 32-byte message hash being signed (cannot be NULL)
1921
* seckey: pointer to a 32-byte secret key (cannot be NULL)
2022
* noncefp:pointer to a nonce generation function. If NULL,
2123
* secp256k1_nonce_function_default is used
2224
* ndata: pointer to arbitrary data used by the nonce generation
2325
* function (can be NULL)
24-
* Out: sig64: pointer to a 64-byte array where the signature will be
25-
* placed (cannot be NULL)
2626
*/
2727
int secp256k1_schnorr_sign(
2828
const secp256k1_context_t* ctx,
29-
const unsigned char *msg32,
3029
unsigned char *sig64,
30+
const unsigned char *msg32,
3131
const unsigned char *seckey,
3232
secp256k1_nonce_function_t noncefp,
3333
const void *ndata
@@ -36,15 +36,15 @@ int secp256k1_schnorr_sign(
3636
/** Verify a signature created by secp256k1_schnorr_sign.
3737
* Returns: 1: correct signature
3838
* 0: incorrect signature
39-
* In: ctx: a secp256k1 context object, initialized for verification.
39+
* Args: ctx: a secp256k1 context object, initialized for verification.
40+
* In: sig64: the 64-byte signature being verified (cannot be NULL)
4041
* msg32: the 32-byte message hash being verified (cannot be NULL)
41-
* sig64: the 64-byte signature being verified (cannot be NULL)
4242
* pubkey: the public key to verify with (cannot be NULL)
4343
*/
4444
SECP256K1_WARN_UNUSED_RESULT int secp256k1_schnorr_verify(
4545
const secp256k1_context_t* ctx,
46-
const unsigned char *msg32,
4746
const unsigned char *sig64,
47+
const unsigned char *msg32,
4848
const secp256k1_pubkey_t *pubkey
4949
) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4);
5050

@@ -53,47 +53,47 @@ SECP256K1_WARN_UNUSED_RESULT int secp256k1_schnorr_verify(
5353
* Returns: 1: public key successfully recovered (which guarantees a correct
5454
* signature).
5555
* 0: otherwise.
56-
* In: ctx: pointer to a context object, initialized for
56+
* Args: ctx: pointer to a context object, initialized for
5757
* verification (cannot be NULL)
58-
* msg32: the 32-byte message hash assumed to be signed (cannot
59-
* be NULL)
60-
* sig64: signature as 64 byte array (cannot be NULL)
6158
* Out: pubkey: pointer to a pubkey to set to the recovered public key
6259
* (cannot be NULL).
60+
* In: sig64: signature as 64 byte array (cannot be NULL)
61+
* msg32: the 32-byte message hash assumed to be signed (cannot
62+
* be NULL)
6363
*/
6464
int secp256k1_schnorr_recover(
6565
const secp256k1_context_t* ctx,
66-
const unsigned char *msg32,
66+
secp256k1_pubkey_t *pubkey,
6767
const unsigned char *sig64,
68-
secp256k1_pubkey_t *pubkey
68+
const unsigned char *msg32
6969
) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4);
7070

7171
/** Generate a nonce pair deterministically for use with
7272
* secp256k1_schnorr_partial_sign.
7373
* Returns: 1: valid nonce pair was generated.
7474
* 0: otherwise (nonce generation function failed)
75-
* In: ctx: pointer to a context object, initialized for signing
75+
* Args: ctx: pointer to a context object, initialized for signing
7676
* (cannot be NULL)
77-
* msg32: the 32-byte message hash assumed to be signed (cannot
77+
* Out: pubnonce: public side of the nonce (cannot be NULL)
78+
* privnonce32: private side of the nonce (32 byte) (cannot be NULL)
79+
* In: msg32: the 32-byte message hash assumed to be signed (cannot
7880
* be NULL)
7981
* sec32: the 32-byte private key (cannot be NULL)
8082
* noncefp: pointer to a nonce generation function. If NULL,
8183
* secp256k1_nonce_function_default is used
8284
* noncedata: pointer to arbitrary data used by the nonce generation
8385
* function (can be NULL)
84-
* Out: pubnonce: public side of the nonce (cannot be NULL)
85-
* privnonce32: private side of the nonce (32 byte) (cannot be NULL)
8686
*
8787
* Do not use the output as a private/public key pair for signing/validation.
8888
*/
8989
int secp256k1_schnorr_generate_nonce_pair(
9090
const secp256k1_context_t* ctx,
91+
secp256k1_pubkey_t *pubnonce,
92+
unsigned char *privnonce32,
9193
const unsigned char *msg32,
9294
const unsigned char *sec32,
9395
secp256k1_nonce_function_t noncefp,
94-
const void* noncedata,
95-
secp256k1_pubkey_t *pubnonce,
96-
unsigned char *privnonce32
96+
const void* noncedata
9797
) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(6) SECP256K1_ARG_NONNULL(7);
9898

9999
/** Produce a partial Schnorr signature, which can be combined using
@@ -103,14 +103,14 @@ int secp256k1_schnorr_generate_nonce_pair(
103103
* 0: no valid signature exists with this combination of keys, nonces
104104
* and message (chance around 1 in 2^128)
105105
* -1: invalid private key, nonce, or public nonces.
106-
* In: ctx: pointer to context object, initialized for signing (cannot
106+
* Args: ctx: pointer to context object, initialized for signing (cannot
107107
* be NULL)
108-
* msg32: pointer to 32-byte message to sign
108+
* Out: sig64: pointer to 64-byte array to put partial signature in
109+
* In: msg32: pointer to 32-byte message to sign
109110
* sec32: pointer to 32-byte private key
110-
* secnonce32: pointer to 32-byte array containing our nonce
111111
* pubnonce_others: pointer to pubkey containing the sum of the other's
112112
* nonces (see secp256k1_ec_pubkey_combine)
113-
* Out: sig64: pointer to 64-byte array to put partial signature in
113+
* secnonce32: pointer to 32-byte array containing our nonce
114114
*
115115
* The intended procedure for creating a multiparty signature is:
116116
* - Each signer S[i] with private key x[i] and public key Q[i] runs
@@ -140,31 +140,31 @@ int secp256k1_schnorr_generate_nonce_pair(
140140
*/
141141
SECP256K1_WARN_UNUSED_RESULT int secp256k1_schnorr_partial_sign(
142142
const secp256k1_context_t* ctx,
143-
const unsigned char *msg32,
144143
unsigned char *sig64,
144+
const unsigned char *msg32,
145145
const unsigned char *sec32,
146-
const unsigned char *secnonce32,
147-
const secp256k1_pubkey_t *pubnonce_others
146+
const secp256k1_pubkey_t *pubnonce_others,
147+
const unsigned char *secnonce32
148148
) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4) SECP256K1_ARG_NONNULL(5) SECP256K1_ARG_NONNULL(6);
149149

150150
/** Combine multiple Schnorr partial signatures.
151151
* Returns: 1: the passed signatures were succesfully combined.
152152
* 0: the resulting signature is not valid (chance of 1 in 2^256)
153153
* -1: some inputs were invalid, or the signatures were not created
154154
* using the same set of nonces
155-
* In: ctx: pointer to a context object
156-
* sig64: pointer to a 64-byte array to place the combined signature
155+
* Args: ctx: pointer to a context object
156+
* Out: sig64: pointer to a 64-byte array to place the combined signature
157157
* (cannot be NULL)
158-
* n: the number of signatures to combine (at least 1)
159-
* Out: sig64sin: pointer to an array of n pointers to 64-byte input
158+
* In: sig64sin: pointer to an array of n pointers to 64-byte input
160159
* signatures
160+
* n: the number of signatures to combine (at least 1)
161161
*/
162162
SECP256K1_WARN_UNUSED_RESULT int secp256k1_schnorr_partial_combine(
163163
const secp256k1_context_t* ctx,
164164
unsigned char *sig64,
165-
int n,
166-
const unsigned char * const * sig64sin
167-
) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(4);
165+
const unsigned char * const * sig64sin,
166+
int n
167+
) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3);
168168

169169
# ifdef __cplusplus
170170
}

src/bench_recover.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ void bench_recover(void* arg) {
2626
int pubkeylen = 33;
2727
secp256k1_ecdsa_recoverable_signature_t sig;
2828
CHECK(secp256k1_ecdsa_recoverable_signature_parse_compact(data->ctx, &sig, data->sig, i % 2));
29-
CHECK(secp256k1_ecdsa_recover(data->ctx, data->msg, &sig, &pubkey));
29+
CHECK(secp256k1_ecdsa_recover(data->ctx, &pubkey, &sig, data->msg));
3030
CHECK(secp256k1_ec_pubkey_serialize(data->ctx, pubkeyc, &pubkeylen, &pubkey, 1));
3131
for (j = 0; j < 32; j++) {
3232
data->sig[j + 32] = data->msg[j]; /* Move former message to S. */

src/bench_schnorr_verify.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ static void benchmark_schnorr_init(void* arg) {
3434
for (k = 0; k < data->numsigs; k++) {
3535
secp256k1_pubkey_t pubkey;
3636
for (i = 0; i < 32; i++) data->sigs[k].key[i] = 33 + i + k;
37-
secp256k1_schnorr_sign(data->ctx, data->msg, data->sigs[k].sig, data->sigs[k].key, NULL, NULL);
37+
secp256k1_schnorr_sign(data->ctx, data->sigs[k].sig, data->msg, data->sigs[k].key, NULL, NULL);
3838
data->sigs[k].pubkeylen = 33;
3939
CHECK(secp256k1_ec_pubkey_create(data->ctx, &pubkey, data->sigs[k].key));
4040
CHECK(secp256k1_ec_pubkey_serialize(data->ctx, data->sigs[k].pubkey, &data->sigs[k].pubkeylen, &pubkey, 1));
@@ -49,7 +49,7 @@ static void benchmark_schnorr_verify(void* arg) {
4949
secp256k1_pubkey_t pubkey;
5050
data->sigs[0].sig[(i >> 8) % 64] ^= (i & 0xFF);
5151
CHECK(secp256k1_ec_pubkey_parse(data->ctx, &pubkey, data->sigs[0].pubkey, data->sigs[0].pubkeylen));
52-
CHECK(secp256k1_schnorr_verify(data->ctx, data->msg, data->sigs[0].sig, &pubkey) == ((i & 0xFF) == 0));
52+
CHECK(secp256k1_schnorr_verify(data->ctx, data->sigs[0].sig, data->msg, &pubkey) == ((i & 0xFF) == 0));
5353
data->sigs[0].sig[(i >> 8) % 64] ^= (i & 0xFF);
5454
}
5555
}

src/bench_sign.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ static void bench_sign(void* arg) {
3131
int siglen = 74;
3232
int j;
3333
secp256k1_ecdsa_signature_t signature;
34-
CHECK(secp256k1_ecdsa_sign(data->ctx, data->msg, &signature, data->key, NULL, NULL));
34+
CHECK(secp256k1_ecdsa_sign(data->ctx, &signature, data->msg, data->key, NULL, NULL));
3535
CHECK(secp256k1_ecdsa_signature_serialize_der(data->ctx, sig, &siglen, &signature));
3636
for (j = 0; j < 32; j++) {
3737
data->msg[j] = sig[j];

src/bench_verify.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ static void benchmark_verify(void* arg) {
3333
data->sig[data->siglen - 3] ^= ((i >> 16) & 0xFF);
3434
CHECK(secp256k1_ec_pubkey_parse(data->ctx, &pubkey, data->pubkey, data->pubkeylen) == 1);
3535
CHECK(secp256k1_ecdsa_signature_parse_der(data->ctx, &sig, data->sig, data->siglen) == 1);
36-
CHECK(secp256k1_ecdsa_verify(data->ctx, data->msg, &sig, &pubkey) == (i == 0));
36+
CHECK(secp256k1_ecdsa_verify(data->ctx, &sig, data->msg, &pubkey) == (i == 0));
3737
data->sig[data->siglen - 1] ^= (i & 0xFF);
3838
data->sig[data->siglen - 2] ^= ((i >> 8) & 0xFF);
3939
data->sig[data->siglen - 3] ^= ((i >> 16) & 0xFF);
@@ -51,7 +51,7 @@ int main(void) {
5151
for (i = 0; i < 32; i++) data.msg[i] = 1 + i;
5252
for (i = 0; i < 32; i++) data.key[i] = 33 + i;
5353
data.siglen = 72;
54-
CHECK(secp256k1_ecdsa_sign(data.ctx, data.msg, &sig, data.key, NULL, NULL));
54+
CHECK(secp256k1_ecdsa_sign(data.ctx, &sig, data.msg, data.key, NULL, NULL));
5555
CHECK(secp256k1_ecdsa_signature_serialize_der(data.ctx, data.sig, &data.siglen, &sig));
5656
CHECK(secp256k1_ec_pubkey_create(data.ctx, &pubkey, data.key));
5757
CHECK(secp256k1_ec_pubkey_serialize(data.ctx, data.pubkey, &data.pubkeylen, &pubkey, 1) == 1);

src/modules/recovery/main_impl.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ int secp256k1_ecdsa_recoverable_signature_convert(const secp256k1_context_t* ctx
8383
return 1;
8484
}
8585

86-
int secp256k1_ecdsa_sign_recoverable(const secp256k1_context_t* ctx, const unsigned char *msg32, secp256k1_ecdsa_recoverable_signature_t *signature, const unsigned char *seckey, secp256k1_nonce_function_t noncefp, const void* noncedata) {
86+
int secp256k1_ecdsa_sign_recoverable(const secp256k1_context_t* ctx, secp256k1_ecdsa_recoverable_signature_t *signature, const unsigned char *msg32, const unsigned char *seckey, secp256k1_nonce_function_t noncefp, const void* noncedata) {
8787
secp256k1_scalar_t r, s;
8888
secp256k1_scalar_t sec, non, msg;
8989
int recid;
@@ -105,7 +105,7 @@ int secp256k1_ecdsa_sign_recoverable(const secp256k1_context_t* ctx, const unsig
105105
secp256k1_scalar_set_b32(&msg, msg32, NULL);
106106
while (1) {
107107
unsigned char nonce32[32];
108-
ret = noncefp(nonce32, msg32, seckey, NULL, count, noncedata);
108+
ret = noncefp(nonce32, seckey, msg32, NULL, noncedata, count);
109109
if (!ret) {
110110
break;
111111
}
@@ -130,7 +130,7 @@ int secp256k1_ecdsa_sign_recoverable(const secp256k1_context_t* ctx, const unsig
130130
return ret;
131131
}
132132

133-
int secp256k1_ecdsa_recover(const secp256k1_context_t* ctx, const unsigned char *msg32, const secp256k1_ecdsa_recoverable_signature_t *signature, secp256k1_pubkey_t *pubkey) {
133+
int secp256k1_ecdsa_recover(const secp256k1_context_t* ctx, secp256k1_pubkey_t *pubkey, const secp256k1_ecdsa_recoverable_signature_t *signature, const unsigned char *msg32) {
134134
secp256k1_ge_t q;
135135
secp256k1_scalar_t r, s;
136136
secp256k1_scalar_t m;

0 commit comments

Comments
 (0)