mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-22 22:38:08 +00:00
bignum: introduce copy
This commit is contained in:
parent
62a0db8c4e
commit
dd25a2ee5a
9
bignum.c
9
bignum.c
@ -156,6 +156,15 @@ void bn_write_le(const bignum256 *in_number, uint8_t *out_number)
|
||||
}
|
||||
}
|
||||
|
||||
// copies number a to b
|
||||
void bn_copy(bignum256 *a, bignum256 *b)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < 9; i++) {
|
||||
b->val[i] = a->val[i];
|
||||
}
|
||||
}
|
||||
|
||||
// sets a bignum to zero.
|
||||
void bn_zero(bignum256 *a)
|
||||
{
|
||||
|
2
bignum.h
2
bignum.h
@ -53,6 +53,8 @@ void bn_read_le(const uint8_t *in_number, bignum256 *out_number);
|
||||
|
||||
void bn_write_le(const bignum256 *in_number, uint8_t *out_number);
|
||||
|
||||
void bn_copy(bignum256 *a, bignum256 *b);
|
||||
|
||||
void bn_zero(bignum256 *a);
|
||||
|
||||
int bn_is_zero(const bignum256 *a);
|
||||
|
13
tests.c
13
tests.c
@ -153,6 +153,18 @@ START_TEST(test_bignum_write_le)
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST(test_bignum_copy)
|
||||
{
|
||||
bignum256 a;
|
||||
bignum256 b;
|
||||
|
||||
bn_read_be(fromhex("c55ece858b0ddd5263f96810fe14437cd3b5e1fbd7c6a2ec1e031f05e86d8bd5"), &a);
|
||||
bn_copy(&a, &b);
|
||||
|
||||
ck_assert_int_eq(bn_is_equal(&a, &b), 1);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
// from https://github.com/bitcoin/bitcoin/blob/master/src/test/data/base58_keys_valid.json
|
||||
START_TEST(test_base58)
|
||||
{
|
||||
@ -2403,6 +2415,7 @@ Suite *test_suite(void)
|
||||
tcase_add_test(tc, test_bignum_equal);
|
||||
tcase_add_test(tc, test_bignum_read_le);
|
||||
tcase_add_test(tc, test_bignum_write_le);
|
||||
tcase_add_test(tc, test_bignum_copy);
|
||||
suite_add_tcase(s, tc);
|
||||
|
||||
tc = tcase_create("base58");
|
||||
|
Loading…
Reference in New Issue
Block a user