Merge pull request #9 from benjaminion/Nashatyrev-feature/add-fr-to-uints

Add fr_to_uints() function
This commit is contained in:
Ben Edgington 2021-07-03 09:45:58 +01:00 committed by GitHub
commit 419e28b46b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 1 deletions

View File

@ -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);
}
@ -121,6 +121,16 @@ void fr_from_uint64(fr_t *out, uint64_t n) {
fr_from_uint64s(out, vals);
}
/**
* 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 vals The field element equivalent of @p n
*/
void fr_to_uint64s(uint64_t out[4], const fr_t *fr) {
blst_uint64_from_fr(out, fr);
}
/**
* Test whether two field elements are equal.
*

View File

@ -104,6 +104,7 @@ bool fr_is_null(const fr_t *p);
void fr_from_scalar(fr_t *out, const scalar_t *a);
void fr_from_uint64s(fr_t *out, const uint64_t *vals);
void fr_from_uint64(fr_t *out, uint64_t n);
void fr_to_uint64s(uint64_t out[4], const fr_t* fr);
bool fr_equal(const fr_t *aa, const fr_t *bb);
void fr_negate(fr_t *out, const fr_t *in);
void fr_add(fr_t *out, const fr_t *a, const fr_t *b);

View File

@ -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},