Minor tweaks and add a unit test
This commit is contained in:
parent
fc641a2197
commit
958dc1aee7
|
@ -104,7 +104,7 @@ void fr_from_scalar(fr_t *out, const scalar_t *a) {
|
|||
* @param out The field element equivalent of @p n
|
||||
* @param vals The array of 64-bit integers to be converted, little-endian ordering of the 64-bit words
|
||||
*/
|
||||
void fr_from_uint64s(fr_t *out, const uint64_t *vals) {
|
||||
void fr_from_uint64s(fr_t *out, const uint64_t vals[4]) {
|
||||
blst_fr_from_uint64(out, vals);
|
||||
}
|
||||
|
||||
|
@ -122,12 +122,12 @@ void fr_from_uint64(fr_t *out, uint64_t n) {
|
|||
}
|
||||
|
||||
/**
|
||||
* Convert the field element to an array of four 64-bit unsigned integers.
|
||||
* Convert a field element to an array of four 64-bit unsigned integers.
|
||||
*
|
||||
* @param out array for returned values, little-endian ordering of the 64-bit words
|
||||
* @param out Array for returned values, little-endian ordering of the 64-bit words
|
||||
* @param vals The field element equivalent of @p n
|
||||
*/
|
||||
void fr_to_uint64s(uint64_t out[4], const fr_t* fr) {
|
||||
void fr_to_uint64s(uint64_t out[4], const fr_t *fr) {
|
||||
blst_uint64_from_fr(out, fr);
|
||||
}
|
||||
|
||||
|
|
|
@ -110,6 +110,20 @@ void fr_div_by_zero(void) {
|
|||
TEST_CHECK(fr_is_zero(&tmp));
|
||||
}
|
||||
|
||||
void fr_uint64s_roundtrip(void) {
|
||||
fr_t fr;
|
||||
uint64_t expected[4] = {1, 2, 3, 4};
|
||||
uint64_t actual[4];
|
||||
|
||||
fr_from_uint64s(&fr, expected);
|
||||
fr_to_uint64s(actual, &fr);
|
||||
|
||||
TEST_CHECK(expected[0] == actual[0]);
|
||||
TEST_CHECK(expected[1] == actual[1]);
|
||||
TEST_CHECK(expected[2] == actual[2]);
|
||||
TEST_CHECK(expected[3] == actual[3]);
|
||||
}
|
||||
|
||||
void p1_mul_works(void) {
|
||||
fr_t minus1;
|
||||
g1_t res;
|
||||
|
@ -235,6 +249,7 @@ TEST_LIST = {
|
|||
{"fr_pow_works", fr_pow_works},
|
||||
{"fr_div_works", fr_div_works},
|
||||
{"fr_div_by_zero", fr_div_by_zero},
|
||||
{"fr_uint64s_roundtrip", fr_uint64s_roundtrip},
|
||||
{"p1_mul_works", p1_mul_works},
|
||||
{"p1_sub_works", p1_sub_works},
|
||||
{"p2_mul_works", p2_mul_works},
|
||||
|
|
Loading…
Reference in New Issue