diff --git a/bignum.c b/bignum.c index d2ebd6350..a0364309b 100644 --- a/bignum.c +++ b/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) { diff --git a/bignum.h b/bignum.h index 65bea7ba7..fd040c8dc 100644 --- a/bignum.h +++ b/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); diff --git a/tests.c b/tests.c index f1e10ba2b..82d47ab8c 100644 --- a/tests.c +++ b/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");