Add fr_negate() method
This commit is contained in:
parent
ab0b618cac
commit
a59ccc7ff7
|
@ -17,9 +17,9 @@
|
|||
#include "blst_util.h"
|
||||
#include "debug_util.h"
|
||||
|
||||
bool fr_is_one(const blst_fr *fr_p) {
|
||||
bool fr_is_one(const blst_fr *p) {
|
||||
uint64_t a[4];
|
||||
blst_uint64_from_fr(a, fr_p);
|
||||
blst_uint64_from_fr(a, p);
|
||||
return a[0] == 1 && a[1] == 0 && a[2] == 0 && a[3] == 0;
|
||||
}
|
||||
|
||||
|
@ -35,6 +35,10 @@ bool fr_equal(const blst_fr *aa, const blst_fr *bb) {
|
|||
return a[0] == b[0] && a[1] == b[1] && a[2] == b[2] && a[3] == b[3];
|
||||
}
|
||||
|
||||
void fr_negate(blst_fr *out, const blst_fr *in) {
|
||||
blst_fr_cneg(out, in, true);
|
||||
}
|
||||
|
||||
// TODO: Is there really no better way to do this?
|
||||
void p1_mul(blst_p1 *out, const blst_p1 *a, const blst_fr *b) {
|
||||
blst_scalar s;
|
||||
|
|
|
@ -23,9 +23,10 @@ static const blst_fr one =
|
|||
// The G1 identity/infinity in affine representation
|
||||
static const blst_p1_affine identity_g1_affine = {{0,0,0,0,0,0},{0,0,0,0,0,0}};
|
||||
|
||||
bool fr_is_one(const blst_fr *fr_p);
|
||||
bool fr_is_one(const blst_fr *p);
|
||||
void fr_from_uint64(blst_fr *a, const uint64_t n);
|
||||
bool fr_equal(const blst_fr *aa, const blst_fr *bb);
|
||||
void fr_negate(blst_fr *out, const blst_fr *in);
|
||||
void p1_mul(blst_p1 *out, const blst_p1 *a, const blst_fr *b);
|
||||
void p1_sub(blst_p1 *out, const blst_p1 *a, const blst_p1 *b);
|
||||
void linear_combination_g1(blst_p1 *out, const blst_p1 *p, const blst_fr *coeffs, const uint64_t len);
|
||||
|
|
|
@ -18,6 +18,9 @@
|
|||
#include "debug_util.h"
|
||||
#include "blst_util.h"
|
||||
|
||||
// This is -1 (the second root of unity)
|
||||
uint64_t m1[] = {0xffffffff00000000L, 0x53bda402fffe5bfeL, 0x3339d80809a1d805L, 0x73eda753299d7d48L};
|
||||
|
||||
void fr_is_one_works(void) {
|
||||
TEST_CHECK(true == fr_is_one(&one));
|
||||
}
|
||||
|
@ -39,9 +42,14 @@ void fr_equal_works(void) {
|
|||
TEST_CHECK(false == fr_equal(&a, &b));
|
||||
}
|
||||
|
||||
void fr_negate_works(void) {
|
||||
blst_fr minus1, res;
|
||||
blst_fr_from_uint64(&minus1, m1);
|
||||
fr_negate(&res, &minus1);
|
||||
TEST_CHECK(fr_is_one(&res));
|
||||
}
|
||||
|
||||
void p1_mul_works(void) {
|
||||
// This is -1 (the second root of unity)
|
||||
uint64_t m1[] = {0xffffffff00000000L, 0x53bda402fffe5bfeL, 0x3339d80809a1d805L, 0x73eda753299d7d48L};
|
||||
blst_fr minus1;
|
||||
blst_p1 g1_gen, g1_gen_neg, res;
|
||||
|
||||
|
@ -100,6 +108,7 @@ TEST_LIST =
|
|||
{"fr_is_one_works", fr_is_one_works },
|
||||
{"fr_from_uint64_works", fr_from_uint64_works},
|
||||
{"fr_equal_works", fr_equal_works},
|
||||
{"fr_negate_works", fr_negate_works},
|
||||
{"p1_mul_works", p1_mul_works},
|
||||
{"p1_sub_works", p1_sub_works},
|
||||
{"identity_g1_is_infinity", identity_g1_is_infinity},
|
||||
|
|
Loading…
Reference in New Issue