Skip to content

Commit a757656

Browse files
committed
f renamed 'opening' to 'original_nonce' and 'data_commitment' to 'data_hash'
1 parent 03300d5 commit a757656

File tree

6 files changed

+35
-34
lines changed

6 files changed

+35
-34
lines changed

include/secp256k1.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ typedef struct {
9292
*/
9393
typedef struct {
9494
unsigned char data[32];
95-
unsigned char data_commitment[32];
95+
unsigned char data_hash[32];
9696
secp256k1_pubkey original_pubnonce;
9797
} secp256k1_s2c_commit_context;
9898

@@ -500,17 +500,18 @@ SECP256K1_API int secp256k1_s2c_commit_context_create(
500500
const unsigned char *data32
501501
) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3);
502502

503-
/** Gets the opening of a sign-to-contract commitment from an s2c_ctx after signing.
504-
* The "opening" is the original public nonce before adding the s2c commitment tweak.
503+
/** Gets the original nonce of a sign-to-contract commitment from an s2c_ctx after signing.
504+
* The original nonce is the signature nonce minus the s2c commitment tweak. Together
505+
* with the committed data this is the opening of the commitment.
505506
*
506-
* Returns: 1 if getting the opening was successful, 0 otherwise
507-
* Args: ctx: a secp256k1 context object
508-
* Out: opening: pointer to a pubkey object where the opening will be placed (cannot be NULL)
509-
* In: s2c_ctx: pointer to an s2c context to get the opening from (cannot be NULL)
507+
* Returns: 1 if getting the original nonce was successful, 0 otherwise
508+
* Args: ctx: a secp256k1 context object
509+
* Out: original_nonce: pointer to a pubkey object where the original nonce will be placed (cannot be NULL)
510+
* In: s2c_ctx: pointer to an s2c context to get the original nonce from (cannot be NULL)
510511
*/
511-
SECP256K1_API int secp256k1_s2c_commit_get_opening(
512+
SECP256K1_API int secp256k1_s2c_commit_get_original_nonce(
512513
secp256k1_context *ctx,
513-
secp256k1_pubkey *opening,
514+
secp256k1_pubkey *original_nonce,
514515
const secp256k1_s2c_commit_context *s2c_ctx
515516
) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3);
516517

include/secp256k1_schnorrsig.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,19 +66,19 @@ SECP256K1_API int secp256k1_schnorrsig_parse(
6666
* commit-reveal protocol as follows:
6767
* 1. The host draws the randomness, commits to it with the anti_nonce_sidechan_host_commit
6868
* function and sends the commitment to the client.
69-
* 2. The client commits to its sign-to-contract opening (which is the nonce without the
69+
* 2. The client commits to its sign-to-contract original nonce (which is the nonce without the
7070
* sign-to-contract tweak) using the hosts commitment by calling the
71-
* secp256k1_schnorrsig_anti_nonce_sidechan_client_commit function. The client gets the opening
72-
* of the sign-to-contract commitment using secp256k1_s2c_commit_get_opening and sends it to the
73-
* host.
71+
* secp256k1_schnorrsig_anti_nonce_sidechan_client_commit function. The client gets the original
72+
* nonce of the sign-to-contract commitment using secp256k1_s2c_commit_get_original_nonce and
73+
* sends it to the host.
7474
* 3. The host replies with the randomness generated in step 1.
7575
* 4. The client uses anti_nonce_sidechan_client_setrand to check that the hosts commitment opens
7676
* to the provided randomness. If not, it waits until the host sends the correct randomness or
7777
* the protocol restarts. If the randomness matches the commitment, the client signs with the
7878
* nonce_function_bipschnorr using the s2c context as nonce data and sends the signature and
7979
* negated nonce flag to the host.
8080
* 5. The host checks that the signature contains an sign-to-contract commitment to the randomness
81-
* by calling verify_s2c_commit with the opening received in step 2 and the signature and
81+
* by calling verify_s2c_commit with the original nonce received in step 2 and the signature and
8282
* negated nonce flag received in step 4. If verification does not succeed, it waits until the
8383
* client sends a signature with a correct commitment or the protocol is restarted.
8484
*/
@@ -196,14 +196,14 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_schnorrsig_verify_batch
196196
* Args: ctx: a secp256k1 context object, initialized for verification.
197197
* In: sig: the signature containing the sign-to-contract commitment (cannot be NULL)
198198
* data32: the 32-byte data that was committed to (cannot be NULL)
199-
* opening: pointer to the opening created when signing (cannot be NULL)
199+
* original_nonce: pointer to the original_nonce created when signing (cannot be NULL)
200200
* negated_nonce: integer indicating if signing algorithm negated the nonce (can be NULL)
201201
*/
202202
SECP256K1_API int secp256k1_schnorrsig_verify_s2c_commit(
203203
const secp256k1_context* ctx,
204204
const secp256k1_schnorrsig *sig,
205205
const unsigned char *data32,
206-
const secp256k1_pubkey *opening,
206+
const secp256k1_pubkey *original_nonce,
207207
int negated_nonce
208208
) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4);
209209

src/modules/schnorrsig/main_impl.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ int secp256k1_schnorrsig_parse(const secp256k1_context* ctx, secp256k1_schnorrsi
2929
return 1;
3030
}
3131

32-
int secp256k1_schnorrsig_verify_s2c_commit(const secp256k1_context* ctx, const secp256k1_schnorrsig *sig, const unsigned char *data32, const secp256k1_pubkey *opening, int negated_nonce) {
32+
int secp256k1_schnorrsig_verify_s2c_commit(const secp256k1_context* ctx, const secp256k1_schnorrsig *sig, const unsigned char *data32, const secp256k1_pubkey *original_nonce, int negated_nonce) {
3333
secp256k1_fe rx;
3434
secp256k1_ge R;
3535
secp256k1_pubkey pubnonce;
3636

3737
VERIFY_CHECK(ctx != NULL);
3838
ARG_CHECK(sig != NULL);
3939
ARG_CHECK(data32 != NULL);
40-
ARG_CHECK(opening != NULL);
40+
ARG_CHECK(original_nonce != NULL);
4141

4242
if (!secp256k1_fe_set_b32(&rx, &sig->data[0])) {
4343
return 0;
@@ -49,7 +49,7 @@ int secp256k1_schnorrsig_verify_s2c_commit(const secp256k1_context* ctx, const s
4949
secp256k1_ge_neg(&R, &R);
5050
}
5151
secp256k1_pubkey_save(&pubnonce, &R);
52-
return secp256k1_ec_commit_verify(ctx, &pubnonce, opening, data32, 32);
52+
return secp256k1_ec_commit_verify(ctx, &pubnonce, original_nonce, data32, 32);
5353
}
5454

5555
int secp256k1_schnorrsig_anti_nonce_sidechan_host_commit(secp256k1_context *ctx, unsigned char *rand_commitment32, const unsigned char *rand32) {
@@ -74,7 +74,7 @@ int secp256k1_schnorrsig_anti_nonce_sidechan_client_commit(secp256k1_context *ct
7474
ARG_CHECK(seckey32 != NULL);
7575
ARG_CHECK(rand_commitment32 != NULL);
7676

77-
memcpy(s2c_ctx->data_commitment, rand_commitment32, 32);
77+
memcpy(s2c_ctx->data_hash, rand_commitment32, 32);
7878
return secp256k1_nonce_function_bipschnorr_no_s2c(ctx, nonce32, msg32, seckey32, NULL, s2c_ctx, 0);
7979
}
8080

@@ -89,7 +89,7 @@ int secp256k1_schnorrsig_anti_nonce_sidechan_client_setrand(secp256k1_context *c
8989
secp256k1_sha256_initialize(&sha);
9090
secp256k1_sha256_write(&sha, rand32, 32);
9191
secp256k1_sha256_finalize(&sha, rand_hash);
92-
if (memcmp(rand_hash, s2c_ctx->data_commitment, 32) != 0) {
92+
if (memcmp(rand_hash, s2c_ctx->data_hash, 32) != 0) {
9393
return 0;
9494
}
9595
memcpy(s2c_ctx->data, rand32, 32);

src/modules/schnorrsig/tests_impl.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ void test_schnorrsig_anti_nonce_sidechannel(void) {
710710
unsigned char rand32[32];
711711
unsigned char rand_commitment32[32];
712712
secp256k1_s2c_commit_context s2c_ctx;
713-
secp256k1_pubkey s2c_opening;
713+
secp256k1_pubkey s2c_original_nonce;
714714
secp256k1_schnorrsig sig;
715715
int negated_nonce;
716716

@@ -724,15 +724,15 @@ void test_schnorrsig_anti_nonce_sidechannel(void) {
724724
/* Host sends rand_commitment32 to client. */
725725
CHECK(secp256k1_schnorrsig_anti_nonce_sidechan_client_commit(ctx, &s2c_ctx, msg32, key32, rand_commitment32) == 1);
726726

727-
/* Client sends s2c opening. Host replies with rand32. */
727+
/* Client sends s2c original nonce. Host replies with rand32. */
728728
CHECK(secp256k1_schnorrsig_anti_nonce_sidechan_client_setrand(ctx, &s2c_ctx, rand32) == 1);
729729
/* Providing wrong data results in an error. */
730730
CHECK(secp256k1_schnorrsig_anti_nonce_sidechan_client_setrand(ctx, &s2c_ctx, rand_commitment32) == 0);
731-
CHECK(secp256k1_s2c_commit_get_opening(ctx, &s2c_opening, &s2c_ctx) == 1);
731+
CHECK(secp256k1_s2c_commit_get_original_nonce(ctx, &s2c_original_nonce, &s2c_ctx) == 1);
732732
CHECK(secp256k1_schnorrsig_sign(ctx, &sig, &negated_nonce, msg32, key32, NULL, &s2c_ctx) == 1);
733733

734734
/* Client sends signature to host. */
735-
CHECK(secp256k1_schnorrsig_verify_s2c_commit(ctx, &sig, rand32, &s2c_opening, negated_nonce) == 1);
735+
CHECK(secp256k1_schnorrsig_verify_s2c_commit(ctx, &sig, rand32, &s2c_original_nonce, negated_nonce) == 1);
736736
}
737737

738738
void run_schnorrsig_tests(void) {

src/secp256k1.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ int secp256k1_ec_commit(const secp256k1_context* ctx, secp256k1_pubkey *commitme
629629
}
630630

631631
/* Compute the seckey of an ec commitment from the original secret key of the pubkey as seckey +
632-
* hash(pubkey, data)*G. */
632+
* hash(pubkey, data). */
633633
int secp256k1_ec_commit_seckey(const secp256k1_context* ctx, unsigned char *seckey, const secp256k1_pubkey *pubkey, const unsigned char *data, size_t n) {
634634
unsigned char tweak[32];
635635
secp256k1_pubkey pubkey_tmp;
@@ -696,16 +696,16 @@ int secp256k1_s2c_commit_context_create(secp256k1_context *ctx, secp256k1_s2c_co
696696
memcpy(s2c_ctx->data, data32, 32);
697697
secp256k1_sha256_initialize(&sha);
698698
secp256k1_sha256_write(&sha, data32, 32);
699-
secp256k1_sha256_finalize(&sha, s2c_ctx->data_commitment);
699+
secp256k1_sha256_finalize(&sha, s2c_ctx->data_hash);
700700
return 1;
701701
}
702702

703-
int secp256k1_s2c_commit_get_opening(secp256k1_context *ctx, secp256k1_pubkey *opening, const secp256k1_s2c_commit_context *s2c_ctx) {
703+
int secp256k1_s2c_commit_get_original_nonce(secp256k1_context *ctx, secp256k1_pubkey *original_nonce, const secp256k1_s2c_commit_context *s2c_ctx) {
704704
VERIFY_CHECK(ctx != NULL);
705-
ARG_CHECK(opening != NULL);
705+
ARG_CHECK(original_nonce != NULL);
706706
ARG_CHECK(s2c_ctx != NULL);
707707

708-
memcpy(opening, &s2c_ctx->original_pubnonce, sizeof(secp256k1_pubkey));
708+
memcpy(original_nonce, &s2c_ctx->original_pubnonce, sizeof(secp256k1_pubkey));
709709
return 1;
710710
}
711711

@@ -729,7 +729,7 @@ static int secp256k1_nonce_function_bipschnorr_no_s2c(const secp256k1_context *c
729729
} else {
730730
/* Do a sign-to-contract commitment if data is provided */
731731
secp256k1_s2c_commit_context *s2c_ctx = (secp256k1_s2c_commit_context *)data;
732-
secp256k1_sha256_write(&sha, s2c_ctx->data_commitment, 32);
732+
secp256k1_sha256_write(&sha, s2c_ctx->data_hash, 32);
733733
secp256k1_sha256_finalize(&sha, nonce32);
734734

735735
if (!secp256k1_ec_pubkey_create(ctx, &s2c_ctx->original_pubnonce, nonce32)) {

src/tests.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4062,7 +4062,7 @@ void test_nonce_function_bipschnorr_s2c(void) {
40624062
unsigned char data32[32];
40634063
secp256k1_s2c_commit_context s2c_ctx;
40644064
secp256k1_pubkey pubnonce;
4065-
secp256k1_pubkey opening;
4065+
secp256k1_pubkey original_nonce;
40664066

40674067
secp256k1_rand256(msg32);
40684068
secp256k1_rand256(key32);
@@ -4071,9 +4071,9 @@ void test_nonce_function_bipschnorr_s2c(void) {
40714071

40724072
CHECK(secp256k1_s2c_commit_context_create(ctx, &s2c_ctx, data32) == 1);
40734073
CHECK(secp256k1_nonce_function_bipschnorr(ctx, nonce32, msg32, key32, NULL, &s2c_ctx, 0) == 1);
4074-
CHECK(secp256k1_s2c_commit_get_opening(ctx, &opening, &s2c_ctx) == 1);
4074+
CHECK(secp256k1_s2c_commit_get_original_nonce(ctx, &original_nonce, &s2c_ctx) == 1);
40754075
CHECK(secp256k1_ec_pubkey_create(ctx, &pubnonce, nonce32) == 1);
4076-
CHECK(secp256k1_ec_commit_verify(ctx, &pubnonce, &opening, data32, 32) == 1);
4076+
CHECK(secp256k1_ec_commit_verify(ctx, &pubnonce, &original_nonce, data32, 32) == 1);
40774077
}
40784078

40794079
void run_nonce_function_bipschnorr_tests(void) {

0 commit comments

Comments
 (0)