Skip to content

Commit 71c993e

Browse files
committed
Merge commit '33cfc37946c9be4e60d46479ade607bbec231c10' into secp256k1-zkp-update
2 parents 12b11e3 + 33cfc37 commit 71c993e

11 files changed

+16
-343
lines changed

src/secp256k1/.cirrus.yml

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ env:
1414
WITH_VALGRIND: yes
1515
EXTRAFLAGS:
1616
### secp256k1 modules
17+
EXPERIMENTAL: no
1718
ECDH: no
1819
RECOVERY: no
1920
SCHNORRSIG: no

src/secp256k1/contrib/musig2-vectors.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
22

33
import sys
44
import json

src/secp256k1/contrib/sync-upstream.sh

+3-4
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,13 @@ case $1 in
7979
shift
8080
setup
8181
range "$@"
82-
REPRODUCE_COMMAND="$0 range -b $LOCAL_BRANCH $RANGEEND_COMMIT"
82+
REPRODUCE_COMMAND="$0 -b $LOCAL_BRANCH range $RANGEEND_COMMIT"
8383
;;
8484
select)
8585
shift
8686
setup
8787
COMMITS=$*
88-
REPRODUCE_COMMAND="$0 select -b $LOCAL_BRANCH $@"
88+
REPRODUCE_COMMAND="$0 -b $LOCAL_BRANCH select $@"
8989
;;
9090
help)
9191
help
@@ -104,8 +104,7 @@ do
104104
done
105105
# Remove trailing ","
106106
TITLE=${TITLE%?}
107-
108-
BODY=$(printf "%s\n\n%s" "$BODY" "This PR can be recreated with \`$REPRODUCE_COMMAND\`.")
107+
BODY=$(printf "%s\n\n%s\n%s" "$BODY" "This PR can be recreated with \`$REPRODUCE_COMMAND\`." "Tip: Use \`git show --remerge-diff\` to show the changes manually added to the merge commit.")
109108

110109
echo "-----------------------------------"
111110
echo "$TITLE"

src/secp256k1/src/modules/bppp/tests_impl.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,11 @@ void test_serialize_two_points(void) {
257257
random_group_element_test(&X);
258258
random_group_element_test(&R);
259259
secp256k1_bppp_serialize_points(buf, &X, &R);
260-
buf[0] |= 4 + (unsigned char)secp256k1_testrandi64(4, 255);
260+
261+
buf[0] = 4 + (unsigned char)secp256k1_testrandi64(0, 253);
262+
/* Assert that buf[0] is actually invalid. */
263+
CHECK(buf[0] != 0x02 && buf[0] != 0x03);
264+
261265
CHECK(!secp256k1_bppp_parse_one_of_points(&X_tmp, buf, 0));
262266
CHECK(!secp256k1_bppp_parse_one_of_points(&R_tmp, buf, 0));
263267
}

src/secp256k1/src/modules/rangeproof/borromean_impl.h

+6-12
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,18 @@
2020
#include <limits.h>
2121
#include <string.h>
2222

23-
#if defined(SECP256K1_BIG_ENDIAN)
24-
#define BE32(x) (x)
25-
#elif defined(SECP256K1_LITTLE_ENDIAN)
26-
#define BE32(p) ((((p) & 0xFF) << 24) | (((p) & 0xFF00) << 8) | (((p) & 0xFF0000) >> 8) | (((p) & 0xFF000000) >> 24))
27-
#endif
28-
2923
SECP256K1_INLINE static void secp256k1_borromean_hash(unsigned char *hash, const unsigned char *m, size_t mlen, const unsigned char *e, size_t elen,
3024
size_t ridx, size_t eidx) {
31-
uint32_t ring;
32-
uint32_t epos;
25+
unsigned char ring[4];
26+
unsigned char epos[4];
3327
secp256k1_sha256 sha256_en;
3428
secp256k1_sha256_initialize(&sha256_en);
35-
ring = BE32((uint32_t)ridx);
36-
epos = BE32((uint32_t)eidx);
29+
secp256k1_write_be32(ring, (uint32_t)ridx);
30+
secp256k1_write_be32(epos, (uint32_t)eidx);
3731
secp256k1_sha256_write(&sha256_en, e, elen);
3832
secp256k1_sha256_write(&sha256_en, m, mlen);
39-
secp256k1_sha256_write(&sha256_en, (unsigned char*)&ring, 4);
40-
secp256k1_sha256_write(&sha256_en, (unsigned char*)&epos, 4);
33+
secp256k1_sha256_write(&sha256_en, ring, 4);
34+
secp256k1_sha256_write(&sha256_en, epos, 4);
4135
secp256k1_sha256_finalize(&sha256_en, hash);
4236
}
4337

src/secp256k1/src/scalar.h

-3
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,4 @@ static void secp256k1_scalar_mul_shift_var(secp256k1_scalar *r, const secp256k1_
108108
/** If flag is true, set *r equal to *a; otherwise leave it. Constant-time. Both *r and *a must be initialized.*/
109109
static void secp256k1_scalar_cmov(secp256k1_scalar *r, const secp256k1_scalar *a, int flag);
110110

111-
/** Generate two scalars from a 32-byte seed and an integer using the chacha20 stream cipher */
112-
static void secp256k1_scalar_chacha20(secp256k1_scalar *r1, secp256k1_scalar *r2, const unsigned char *seed, uint64_t idx);
113-
114111
#endif /* SECP256K1_SCALAR_H */

src/secp256k1/src/scalar_4x64_impl.h

-87
Original file line numberDiff line numberDiff line change
@@ -970,93 +970,6 @@ static SECP256K1_INLINE void secp256k1_scalar_cmov(secp256k1_scalar *r, const se
970970
r->d[3] = (r->d[3] & mask0) | (a->d[3] & mask1);
971971
}
972972

973-
#define ROTL32(x,n) ((x) << (n) | (x) >> (32-(n)))
974-
#define QUARTERROUND(a,b,c,d) \
975-
a += b; d = ROTL32(d ^ a, 16); \
976-
c += d; b = ROTL32(b ^ c, 12); \
977-
a += b; d = ROTL32(d ^ a, 8); \
978-
c += d; b = ROTL32(b ^ c, 7);
979-
980-
#if defined(SECP256K1_BIG_ENDIAN)
981-
#define LE32(p) ((((p) & 0xFF) << 24) | (((p) & 0xFF00) << 8) | (((p) & 0xFF0000) >> 8) | (((p) & 0xFF000000) >> 24))
982-
#elif defined(SECP256K1_LITTLE_ENDIAN)
983-
#define LE32(p) (p)
984-
#endif
985-
986-
static void secp256k1_scalar_chacha20(secp256k1_scalar *r1, secp256k1_scalar *r2, const unsigned char *seed, uint64_t idx) {
987-
size_t n;
988-
size_t over_count = 0;
989-
uint32_t seed32[8];
990-
uint32_t x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15;
991-
int over1, over2;
992-
993-
memcpy((void *) seed32, (const void *) seed, 32);
994-
do {
995-
x0 = 0x61707865;
996-
x1 = 0x3320646e;
997-
x2 = 0x79622d32;
998-
x3 = 0x6b206574;
999-
x4 = LE32(seed32[0]);
1000-
x5 = LE32(seed32[1]);
1001-
x6 = LE32(seed32[2]);
1002-
x7 = LE32(seed32[3]);
1003-
x8 = LE32(seed32[4]);
1004-
x9 = LE32(seed32[5]);
1005-
x10 = LE32(seed32[6]);
1006-
x11 = LE32(seed32[7]);
1007-
x12 = idx;
1008-
x13 = idx >> 32;
1009-
x14 = 0;
1010-
x15 = over_count;
1011-
1012-
n = 10;
1013-
while (n--) {
1014-
QUARTERROUND(x0, x4, x8,x12)
1015-
QUARTERROUND(x1, x5, x9,x13)
1016-
QUARTERROUND(x2, x6,x10,x14)
1017-
QUARTERROUND(x3, x7,x11,x15)
1018-
QUARTERROUND(x0, x5,x10,x15)
1019-
QUARTERROUND(x1, x6,x11,x12)
1020-
QUARTERROUND(x2, x7, x8,x13)
1021-
QUARTERROUND(x3, x4, x9,x14)
1022-
}
1023-
1024-
x0 += 0x61707865;
1025-
x1 += 0x3320646e;
1026-
x2 += 0x79622d32;
1027-
x3 += 0x6b206574;
1028-
x4 += LE32(seed32[0]);
1029-
x5 += LE32(seed32[1]);
1030-
x6 += LE32(seed32[2]);
1031-
x7 += LE32(seed32[3]);
1032-
x8 += LE32(seed32[4]);
1033-
x9 += LE32(seed32[5]);
1034-
x10 += LE32(seed32[6]);
1035-
x11 += LE32(seed32[7]);
1036-
x12 += idx;
1037-
x13 += idx >> 32;
1038-
x14 += 0;
1039-
x15 += over_count;
1040-
1041-
r1->d[3] = (((uint64_t) x0) << 32) | x1;
1042-
r1->d[2] = (((uint64_t) x2) << 32) | x3;
1043-
r1->d[1] = (((uint64_t) x4) << 32) | x5;
1044-
r1->d[0] = (((uint64_t) x6) << 32) | x7;
1045-
r2->d[3] = (((uint64_t) x8) << 32) | x9;
1046-
r2->d[2] = (((uint64_t) x10) << 32) | x11;
1047-
r2->d[1] = (((uint64_t) x12) << 32) | x13;
1048-
r2->d[0] = (((uint64_t) x14) << 32) | x15;
1049-
1050-
over1 = secp256k1_scalar_check_overflow(r1);
1051-
over2 = secp256k1_scalar_check_overflow(r2);
1052-
over_count++;
1053-
} while (over1 | over2);
1054-
}
1055-
1056-
#undef ROTL32
1057-
#undef QUARTERROUND
1058-
#undef LE32
1059-
1060973
static void secp256k1_scalar_from_signed62(secp256k1_scalar *r, const secp256k1_modinv64_signed62 *a) {
1061974
const uint64_t a0 = a->v[0], a1 = a->v[1], a2 = a->v[2], a3 = a->v[3], a4 = a->v[4];
1062975

src/secp256k1/src/scalar_8x32_impl.h

-95
Original file line numberDiff line numberDiff line change
@@ -749,101 +749,6 @@ static SECP256K1_INLINE void secp256k1_scalar_cmov(secp256k1_scalar *r, const se
749749
r->d[7] = (r->d[7] & mask0) | (a->d[7] & mask1);
750750
}
751751

752-
#define ROTL32(x,n) ((x) << (n) | (x) >> (32-(n)))
753-
#define QUARTERROUND(a,b,c,d) \
754-
a += b; d = ROTL32(d ^ a, 16); \
755-
c += d; b = ROTL32(b ^ c, 12); \
756-
a += b; d = ROTL32(d ^ a, 8); \
757-
c += d; b = ROTL32(b ^ c, 7);
758-
759-
#if defined(SECP256K1_BIG_ENDIAN)
760-
#define LE32(p) ((((p) & 0xFF) << 24) | (((p) & 0xFF00) << 8) | (((p) & 0xFF0000) >> 8) | (((p) & 0xFF000000) >> 24))
761-
#elif defined(SECP256K1_LITTLE_ENDIAN)
762-
#define LE32(p) (p)
763-
#endif
764-
765-
static void secp256k1_scalar_chacha20(secp256k1_scalar *r1, secp256k1_scalar *r2, const unsigned char *seed, uint64_t idx) {
766-
size_t n;
767-
size_t over_count = 0;
768-
uint32_t seed32[8];
769-
uint32_t x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15;
770-
int over1, over2;
771-
772-
memcpy((void *) seed32, (const void *) seed, 32);
773-
do {
774-
x0 = 0x61707865;
775-
x1 = 0x3320646e;
776-
x2 = 0x79622d32;
777-
x3 = 0x6b206574;
778-
x4 = LE32(seed32[0]);
779-
x5 = LE32(seed32[1]);
780-
x6 = LE32(seed32[2]);
781-
x7 = LE32(seed32[3]);
782-
x8 = LE32(seed32[4]);
783-
x9 = LE32(seed32[5]);
784-
x10 = LE32(seed32[6]);
785-
x11 = LE32(seed32[7]);
786-
x12 = idx;
787-
x13 = idx >> 32;
788-
x14 = 0;
789-
x15 = over_count;
790-
791-
n = 10;
792-
while (n--) {
793-
QUARTERROUND(x0, x4, x8,x12)
794-
QUARTERROUND(x1, x5, x9,x13)
795-
QUARTERROUND(x2, x6,x10,x14)
796-
QUARTERROUND(x3, x7,x11,x15)
797-
QUARTERROUND(x0, x5,x10,x15)
798-
QUARTERROUND(x1, x6,x11,x12)
799-
QUARTERROUND(x2, x7, x8,x13)
800-
QUARTERROUND(x3, x4, x9,x14)
801-
}
802-
803-
x0 += 0x61707865;
804-
x1 += 0x3320646e;
805-
x2 += 0x79622d32;
806-
x3 += 0x6b206574;
807-
x4 += LE32(seed32[0]);
808-
x5 += LE32(seed32[1]);
809-
x6 += LE32(seed32[2]);
810-
x7 += LE32(seed32[3]);
811-
x8 += LE32(seed32[4]);
812-
x9 += LE32(seed32[5]);
813-
x10 += LE32(seed32[6]);
814-
x11 += LE32(seed32[7]);
815-
x12 += idx;
816-
x13 += idx >> 32;
817-
x14 += 0;
818-
x15 += over_count;
819-
820-
r1->d[7] = x0;
821-
r1->d[6] = x1;
822-
r1->d[5] = x2;
823-
r1->d[4] = x3;
824-
r1->d[3] = x4;
825-
r1->d[2] = x5;
826-
r1->d[1] = x6;
827-
r1->d[0] = x7;
828-
r2->d[7] = x8;
829-
r2->d[6] = x9;
830-
r2->d[5] = x10;
831-
r2->d[4] = x11;
832-
r2->d[3] = x12;
833-
r2->d[2] = x13;
834-
r2->d[1] = x14;
835-
r2->d[0] = x15;
836-
837-
over1 = secp256k1_scalar_check_overflow(r1);
838-
over2 = secp256k1_scalar_check_overflow(r2);
839-
over_count++;
840-
} while (over1 | over2);
841-
}
842-
843-
#undef ROTL32
844-
#undef QUARTERROUND
845-
#undef LE32
846-
847752
static void secp256k1_scalar_from_signed30(secp256k1_scalar *r, const secp256k1_modinv32_signed30 *a) {
848753
const uint32_t a0 = a->v[0], a1 = a->v[1], a2 = a->v[2], a3 = a->v[3], a4 = a->v[4],
849754
a5 = a->v[5], a6 = a->v[6], a7 = a->v[7], a8 = a->v[8];

src/secp256k1/src/scalar_low_impl.h

-5
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,6 @@ static SECP256K1_INLINE void secp256k1_scalar_cmov(secp256k1_scalar *r, const se
127127
*r = (*r & mask0) | (*a & mask1);
128128
}
129129

130-
SECP256K1_INLINE static void secp256k1_scalar_chacha20(secp256k1_scalar *r1, secp256k1_scalar *r2, const unsigned char *seed, uint64_t n) {
131-
*r1 = (seed[0] + n) % EXHAUSTIVE_TEST_ORDER;
132-
*r2 = (seed[1] + n) % EXHAUSTIVE_TEST_ORDER;
133-
}
134-
135130
static void secp256k1_scalar_inverse(secp256k1_scalar *r, const secp256k1_scalar *x) {
136131
int i;
137132
*r = 0;

0 commit comments

Comments
 (0)