Skip to content

Commit aa3edea

Browse files
scalar: Remove unused secp256k1_scalar_chacha20
Unused since a112503.
1 parent 167194b commit aa3edea

File tree

6 files changed

+0
-325
lines changed

6 files changed

+0
-325
lines changed

src/scalar.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,4 @@ static void secp256k1_scalar_mul_shift_var(secp256k1_scalar *r, const secp256k1_
105105
/** If flag is true, set *r equal to *a; otherwise leave it. Constant-time. Both *r and *a must be initialized.*/
106106
static void secp256k1_scalar_cmov(secp256k1_scalar *r, const secp256k1_scalar *a, int flag);
107107

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

src/scalar_4x64_impl.h

Lines changed: 0 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -999,93 +999,6 @@ static SECP256K1_INLINE void secp256k1_scalar_cmov(secp256k1_scalar *r, const se
999999
r->d[3] = (r->d[3] & mask0) | (a->d[3] & mask1);
10001000
}
10011001

1002-
#define ROTL32(x,n) ((x) << (n) | (x) >> (32-(n)))
1003-
#define QUARTERROUND(a,b,c,d) \
1004-
a += b; d = ROTL32(d ^ a, 16); \
1005-
c += d; b = ROTL32(b ^ c, 12); \
1006-
a += b; d = ROTL32(d ^ a, 8); \
1007-
c += d; b = ROTL32(b ^ c, 7);
1008-
1009-
#if defined(SECP256K1_BIG_ENDIAN)
1010-
#define LE32(p) ((((p) & 0xFF) << 24) | (((p) & 0xFF00) << 8) | (((p) & 0xFF0000) >> 8) | (((p) & 0xFF000000) >> 24))
1011-
#elif defined(SECP256K1_LITTLE_ENDIAN)
1012-
#define LE32(p) (p)
1013-
#endif
1014-
1015-
static void secp256k1_scalar_chacha20(secp256k1_scalar *r1, secp256k1_scalar *r2, const unsigned char *seed, uint64_t idx) {
1016-
size_t n;
1017-
size_t over_count = 0;
1018-
uint32_t seed32[8];
1019-
uint32_t x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15;
1020-
int over1, over2;
1021-
1022-
memcpy((void *) seed32, (const void *) seed, 32);
1023-
do {
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-
n = 10;
1042-
while (n--) {
1043-
QUARTERROUND(x0, x4, x8,x12)
1044-
QUARTERROUND(x1, x5, x9,x13)
1045-
QUARTERROUND(x2, x6,x10,x14)
1046-
QUARTERROUND(x3, x7,x11,x15)
1047-
QUARTERROUND(x0, x5,x10,x15)
1048-
QUARTERROUND(x1, x6,x11,x12)
1049-
QUARTERROUND(x2, x7, x8,x13)
1050-
QUARTERROUND(x3, x4, x9,x14)
1051-
}
1052-
1053-
x0 += 0x61707865;
1054-
x1 += 0x3320646e;
1055-
x2 += 0x79622d32;
1056-
x3 += 0x6b206574;
1057-
x4 += LE32(seed32[0]);
1058-
x5 += LE32(seed32[1]);
1059-
x6 += LE32(seed32[2]);
1060-
x7 += LE32(seed32[3]);
1061-
x8 += LE32(seed32[4]);
1062-
x9 += LE32(seed32[5]);
1063-
x10 += LE32(seed32[6]);
1064-
x11 += LE32(seed32[7]);
1065-
x12 += idx;
1066-
x13 += idx >> 32;
1067-
x14 += 0;
1068-
x15 += over_count;
1069-
1070-
r1->d[3] = (((uint64_t) x0) << 32) | x1;
1071-
r1->d[2] = (((uint64_t) x2) << 32) | x3;
1072-
r1->d[1] = (((uint64_t) x4) << 32) | x5;
1073-
r1->d[0] = (((uint64_t) x6) << 32) | x7;
1074-
r2->d[3] = (((uint64_t) x8) << 32) | x9;
1075-
r2->d[2] = (((uint64_t) x10) << 32) | x11;
1076-
r2->d[1] = (((uint64_t) x12) << 32) | x13;
1077-
r2->d[0] = (((uint64_t) x14) << 32) | x15;
1078-
1079-
over1 = secp256k1_scalar_check_overflow(r1);
1080-
over2 = secp256k1_scalar_check_overflow(r2);
1081-
over_count++;
1082-
} while (over1 | over2);
1083-
}
1084-
1085-
#undef ROTL32
1086-
#undef QUARTERROUND
1087-
#undef LE32
1088-
10891002
static void secp256k1_scalar_from_signed62(secp256k1_scalar *r, const secp256k1_modinv64_signed62 *a) {
10901003
const uint64_t a0 = a->v[0], a1 = a->v[1], a2 = a->v[2], a3 = a->v[3], a4 = a->v[4];
10911004

src/scalar_8x32_impl.h

Lines changed: 0 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -751,101 +751,6 @@ static SECP256K1_INLINE void secp256k1_scalar_cmov(secp256k1_scalar *r, const se
751751
r->d[7] = (r->d[7] & mask0) | (a->d[7] & mask1);
752752
}
753753

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

src/scalar_low_impl.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,6 @@ static SECP256K1_INLINE void secp256k1_scalar_cmov(secp256k1_scalar *r, const se
129129
*r = (*r & mask0) | (*a & mask1);
130130
}
131131

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

src/tests.c

Lines changed: 0 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -2368,114 +2368,6 @@ static void run_scalar_set_b32_seckey_tests(void) {
23682368
CHECK(secp256k1_scalar_set_b32_seckey(&s2, b32) == 0);
23692369
}
23702370

2371-
static void scalar_chacha_tests(void) {
2372-
/* Test vectors 1 to 4 from https://tools.ietf.org/html/rfc8439#appendix-A
2373-
* Note that scalar_set_b32 and scalar_get_b32 represent integers
2374-
* underlying the scalar in big-endian format. */
2375-
unsigned char expected1[64] = {
2376-
0xad, 0xe0, 0xb8, 0x76, 0x90, 0x3d, 0xf1, 0xa0,
2377-
0xe5, 0x6a, 0x5d, 0x40, 0x28, 0xbd, 0x86, 0x53,
2378-
0xb8, 0x19, 0xd2, 0xbd, 0x1a, 0xed, 0x8d, 0xa0,
2379-
0xcc, 0xef, 0x36, 0xa8, 0xc7, 0x0d, 0x77, 0x8b,
2380-
0x7c, 0x59, 0x41, 0xda, 0x8d, 0x48, 0x57, 0x51,
2381-
0x3f, 0xe0, 0x24, 0x77, 0x37, 0x4a, 0xd8, 0xb8,
2382-
0xf4, 0xb8, 0x43, 0x6a, 0x1c, 0xa1, 0x18, 0x15,
2383-
0x69, 0xb6, 0x87, 0xc3, 0x86, 0x65, 0xee, 0xb2
2384-
};
2385-
unsigned char expected2[64] = {
2386-
0xbe, 0xe7, 0x07, 0x9f, 0x7a, 0x38, 0x51, 0x55,
2387-
0x7c, 0x97, 0xba, 0x98, 0x0d, 0x08, 0x2d, 0x73,
2388-
0xa0, 0x29, 0x0f, 0xcb, 0x69, 0x65, 0xe3, 0x48,
2389-
0x3e, 0x53, 0xc6, 0x12, 0xed, 0x7a, 0xee, 0x32,
2390-
0x76, 0x21, 0xb7, 0x29, 0x43, 0x4e, 0xe6, 0x9c,
2391-
0xb0, 0x33, 0x71, 0xd5, 0xd5, 0x39, 0xd8, 0x74,
2392-
0x28, 0x1f, 0xed, 0x31, 0x45, 0xfb, 0x0a, 0x51,
2393-
0x1f, 0x0a, 0xe1, 0xac, 0x6f, 0x4d, 0x79, 0x4b
2394-
};
2395-
unsigned char seed3[32] = {
2396-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2397-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2398-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2399-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01
2400-
};
2401-
unsigned char expected3[64] = {
2402-
0x24, 0x52, 0xeb, 0x3a, 0x92, 0x49, 0xf8, 0xec,
2403-
0x8d, 0x82, 0x9d, 0x9b, 0xdd, 0xd4, 0xce, 0xb1,
2404-
0xe8, 0x25, 0x20, 0x83, 0x60, 0x81, 0x8b, 0x01,
2405-
0xf3, 0x84, 0x22, 0xb8, 0x5a, 0xaa, 0x49, 0xc9,
2406-
0xbb, 0x00, 0xca, 0x8e, 0xda, 0x3b, 0xa7, 0xb4,
2407-
0xc4, 0xb5, 0x92, 0xd1, 0xfd, 0xf2, 0x73, 0x2f,
2408-
0x44, 0x36, 0x27, 0x4e, 0x25, 0x61, 0xb3, 0xc8,
2409-
0xeb, 0xdd, 0x4a, 0xa6, 0xa0, 0x13, 0x6c, 0x00
2410-
};
2411-
unsigned char seed4[32] = {
2412-
0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2413-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2414-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2415-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
2416-
};
2417-
unsigned char expected4[64] = {
2418-
0xfb, 0x4d, 0xd5, 0x72, 0x4b, 0xc4, 0x2e, 0xf1,
2419-
0xdf, 0x92, 0x26, 0x36, 0x32, 0x7f, 0x13, 0x94,
2420-
0xa7, 0x8d, 0xea, 0x8f, 0x5e, 0x26, 0x90, 0x39,
2421-
0xa1, 0xbe, 0xbb, 0xc1, 0xca, 0xf0, 0x9a, 0xae,
2422-
0xa2, 0x5a, 0xb2, 0x13, 0x48, 0xa6, 0xb4, 0x6c,
2423-
0x1b, 0x9d, 0x9b, 0xcb, 0x09, 0x2c, 0x5b, 0xe6,
2424-
0x54, 0x6c, 0xa6, 0x24, 0x1b, 0xec, 0x45, 0xd5,
2425-
0x87, 0xf4, 0x74, 0x73, 0x96, 0xf0, 0x99, 0x2e
2426-
};
2427-
unsigned char seed5[32] = {
2428-
0x32, 0x56, 0x56, 0xf4, 0x29, 0x02, 0xc2, 0xf8,
2429-
0xa3, 0x4b, 0x96, 0xf5, 0xa7, 0xf7, 0xe3, 0x6c,
2430-
0x92, 0xad, 0xa5, 0x18, 0x1c, 0xe3, 0x41, 0xae,
2431-
0xc3, 0xf3, 0x18, 0xd0, 0xfa, 0x5b, 0x72, 0x53
2432-
};
2433-
unsigned char expected5[64] = {
2434-
0xe7, 0x56, 0xd3, 0x28, 0xe9, 0xc6, 0x19, 0x5c,
2435-
0x6f, 0x17, 0x8e, 0x21, 0x8c, 0x1e, 0x72, 0x11,
2436-
0xe7, 0xbd, 0x17, 0x0d, 0xac, 0x14, 0xad, 0xe9,
2437-
0x3d, 0x9f, 0xb6, 0x92, 0xd6, 0x09, 0x20, 0xfb,
2438-
0x43, 0x8e, 0x3b, 0x6d, 0xe3, 0x33, 0xdc, 0xc7,
2439-
0x6c, 0x07, 0x6f, 0xbb, 0x1f, 0xb4, 0xc8, 0xb5,
2440-
0xe3, 0x6c, 0xe5, 0x12, 0xd9, 0xd7, 0x64, 0x0c,
2441-
0xf5, 0xa7, 0x0d, 0xab, 0x79, 0x03, 0xf1, 0x81
2442-
};
2443-
2444-
secp256k1_scalar exp_r1, exp_r2;
2445-
secp256k1_scalar r1, r2;
2446-
unsigned char seed0[32] = { 0 };
2447-
2448-
secp256k1_scalar_chacha20(&r1, &r2, seed0, 0);
2449-
secp256k1_scalar_set_b32(&exp_r1, &expected1[0], NULL);
2450-
secp256k1_scalar_set_b32(&exp_r2, &expected1[32], NULL);
2451-
CHECK(secp256k1_scalar_eq(&exp_r1, &r1));
2452-
CHECK(secp256k1_scalar_eq(&exp_r2, &r2));
2453-
2454-
secp256k1_scalar_chacha20(&r1, &r2, seed0, 1);
2455-
secp256k1_scalar_set_b32(&exp_r1, &expected2[0], NULL);
2456-
secp256k1_scalar_set_b32(&exp_r2, &expected2[32], NULL);
2457-
CHECK(secp256k1_scalar_eq(&exp_r1, &r1));
2458-
CHECK(secp256k1_scalar_eq(&exp_r2, &r2));
2459-
2460-
secp256k1_scalar_chacha20(&r1, &r2, seed3, 1);
2461-
secp256k1_scalar_set_b32(&exp_r1, &expected3[0], NULL);
2462-
secp256k1_scalar_set_b32(&exp_r2, &expected3[32], NULL);
2463-
CHECK(secp256k1_scalar_eq(&exp_r1, &r1));
2464-
CHECK(secp256k1_scalar_eq(&exp_r2, &r2));
2465-
2466-
secp256k1_scalar_chacha20(&r1, &r2, seed4, 2);
2467-
secp256k1_scalar_set_b32(&exp_r1, &expected4[0], NULL);
2468-
secp256k1_scalar_set_b32(&exp_r2, &expected4[32], NULL);
2469-
CHECK(secp256k1_scalar_eq(&exp_r1, &r1));
2470-
CHECK(secp256k1_scalar_eq(&exp_r2, &r2));
2471-
2472-
secp256k1_scalar_chacha20(&r1, &r2, seed5, 0x6ff8602a7a78e2f2ULL);
2473-
secp256k1_scalar_set_b32(&exp_r1, &expected5[0], NULL);
2474-
secp256k1_scalar_set_b32(&exp_r2, &expected5[32], NULL);
2475-
CHECK(secp256k1_scalar_eq(&exp_r1, &r1));
2476-
CHECK(secp256k1_scalar_eq(&exp_r2, &r2));
2477-
}
2478-
24792371
static void run_scalar_tests(void) {
24802372
int i;
24812373
for (i = 0; i < 128 * COUNT; i++) {
@@ -2485,8 +2377,6 @@ static void run_scalar_tests(void) {
24852377
run_scalar_set_b32_seckey_tests();
24862378
}
24872379

2488-
scalar_chacha_tests();
2489-
24902380
{
24912381
/* Check that the scalar constants secp256k1_scalar_zero and
24922382
secp256k1_scalar_one contain the expected values. */

src/util.h

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -220,31 +220,6 @@ SECP256K1_INLINE static int secp256k1_clz64_var(uint64_t x) {
220220
# define SECP256K1_GNUC_EXT
221221
#endif
222222

223-
/* If SECP256K1_{LITTLE,BIG}_ENDIAN is not explicitly provided, infer from various other system macros. */
224-
#if !defined(SECP256K1_LITTLE_ENDIAN) && !defined(SECP256K1_BIG_ENDIAN)
225-
/* Inspired by https://github.com/rofl0r/endianness.h/blob/9853923246b065a3b52d2c43835f3819a62c7199/endianness.h#L52L73 */
226-
# if (defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) || \
227-
defined(_X86_) || defined(__x86_64__) || defined(__i386__) || \
228-
defined(__i486__) || defined(__i586__) || defined(__i686__) || \
229-
defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL) || \
230-
defined(__ARMEL__) || defined(__AARCH64EL__) || \
231-
(defined(__LITTLE_ENDIAN__) && __LITTLE_ENDIAN__ == 1) || \
232-
(defined(_LITTLE_ENDIAN) && _LITTLE_ENDIAN == 1) || \
233-
defined(_M_IX86) || defined(_M_AMD64) || defined(_M_ARM) /* MSVC */
234-
# define SECP256K1_LITTLE_ENDIAN
235-
# endif
236-
# if (defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) || \
237-
defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB) || \
238-
defined(__MICROBLAZEEB__) || defined(__ARMEB__) || defined(__AARCH64EB__) || \
239-
(defined(__BIG_ENDIAN__) && __BIG_ENDIAN__ == 1) || \
240-
(defined(_BIG_ENDIAN) && _BIG_ENDIAN == 1)
241-
# define SECP256K1_BIG_ENDIAN
242-
# endif
243-
#endif
244-
#if defined(SECP256K1_LITTLE_ENDIAN) == defined(SECP256K1_BIG_ENDIAN)
245-
# error Please make sure that either SECP256K1_LITTLE_ENDIAN or SECP256K1_BIG_ENDIAN is set, see src/util.h.
246-
#endif
247-
248223
/* Zero memory if flag == 1. Flag must be 0 or 1. Constant time. */
249224
static SECP256K1_INLINE void secp256k1_memczero(void *s, size_t len, int flag) {
250225
unsigned char *p = (unsigned char *)s;

0 commit comments

Comments
 (0)