Skip to content

Commit 7067ee5

Browse files
committed
tests: add tests for secp256k1_{read,write}_be64
This can be reviewed with `--ignore-all-space` (or `-w`), to ignore already existing code that was only indented.
1 parent 740528c commit 7067ee5

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

src/tests.c

+23-8
Original file line numberDiff line numberDiff line change
@@ -7516,16 +7516,31 @@ static void run_secp256k1_memczero_test(void) {
75167516
}
75177517

75187518
static void run_secp256k1_byteorder_tests(void) {
7519-
const uint32_t x = 0xFF03AB45;
7520-
const unsigned char x_be[4] = {0xFF, 0x03, 0xAB, 0x45};
7521-
unsigned char buf[4];
7522-
uint32_t x_;
7519+
{
7520+
const uint32_t x = 0xFF03AB45;
7521+
const unsigned char x_be[4] = {0xFF, 0x03, 0xAB, 0x45};
7522+
unsigned char buf[4];
7523+
uint32_t x_;
7524+
7525+
secp256k1_write_be32(buf, x);
7526+
CHECK(secp256k1_memcmp_var(buf, x_be, sizeof(buf)) == 0);
75237527

7524-
secp256k1_write_be32(buf, x);
7525-
CHECK(secp256k1_memcmp_var(buf, x_be, sizeof(buf)) == 0);
7528+
x_ = secp256k1_read_be32(buf);
7529+
CHECK(x == x_);
7530+
}
75267531

7527-
x_ = secp256k1_read_be32(buf);
7528-
CHECK(x == x_);
7532+
{
7533+
const uint64_t x = 0xCAFE0123BEEF4567;
7534+
const unsigned char x_be[8] = {0xCA, 0xFE, 0x01, 0x23, 0xBE, 0xEF, 0x45, 0x67};
7535+
unsigned char buf[8];
7536+
uint64_t x_;
7537+
7538+
secp256k1_write_be64(buf, x);
7539+
CHECK(secp256k1_memcmp_var(buf, x_be, sizeof(buf)) == 0);
7540+
7541+
x_ = secp256k1_read_be64(buf);
7542+
CHECK(x == x_);
7543+
}
75297544
}
75307545

75317546
static void int_cmov_test(void) {

0 commit comments

Comments
 (0)