Nashatyrev feature/add g2 add dbl (#16)

* Add g2_add_or_dbl() function

* Add unit test

Co-authored-by: Anton Nashatyrev <anton.nashatyrev@gmail.com>
This commit is contained in:
Ben Edgington 2021-08-11 10:06:32 +01:00 committed by GitHub
parent 80f984cecd
commit 950d53c325
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 0 deletions

View File

@ -356,6 +356,19 @@ void g2_mul(g2_t *out, const g2_t *a, const fr_t *b) {
blst_p2_mult(out, a, s.b, 8 * sizeof(blst_scalar));
}
/**
* Add or double G2 points.
*
* This is safe if the two points are the same.
*
* @param[out] out @p a plus @p b in the group
* @param[in] a G2 group point
* @param[in] b G2 group point
*/
void g2_add_or_dbl(g2_t *out, const g2_t *a, const g2_t *b) {
blst_p2_add_or_double(out, a, b);
}
/**
* Subtraction of G2 group elements.
*
@ -608,6 +621,15 @@ void p1_sub_works(void) {
TEST_CHECK(g1_equal(&tmp, &res));
}
void p2_add_or_dbl_works(void) {
g2_t expected, actual;
g2_dbl(&expected, &g2_generator);
g2_add_or_dbl(&actual, &g2_generator, &g2_generator);
TEST_CHECK(g2_equal(&expected, &actual));
}
void p2_mul_works(void) {
fr_t minus1;
g2_t res;
@ -714,6 +736,7 @@ TEST_LIST = {
{"fr_uint64s_roundtrip", fr_uint64s_roundtrip},
{"p1_mul_works", p1_mul_works},
{"p1_sub_works", p1_sub_works},
{"p2_add_or_dbl_works", p2_add_or_dbl_works},
{"p2_mul_works", p2_mul_works},
{"p2_sub_works", p2_sub_works},
{"g1_identity_is_infinity", g1_identity_is_infinity},

View File

@ -126,6 +126,7 @@ void g1_mul(g1_t *out, const g1_t *a, const fr_t *b);
void g1_sub(g1_t *out, const g1_t *a, const g1_t *b);
bool g2_equal(const g2_t *a, const g2_t *b);
void g2_mul(g2_t *out, const g2_t *a, const fr_t *b);
void g2_add_or_dbl(g2_t *out, const g2_t *a, const g2_t *b);
void g2_sub(g2_t *out, const g2_t *a, const g2_t *b);
void g2_dbl(g2_t *out, const g2_t *a);
void g1_linear_combination(g1_t *out, const g1_t *p, const fr_t *coeffs, const uint64_t len);