From a0eb5fc65604926d1c2eb7d9f1896334d5dd508e Mon Sep 17 00:00:00 2001 From: Earle Lowe Date: Wed, 7 Jun 2023 10:49:01 -0700 Subject: [PATCH 1/2] Add in fp12 deserialization --- bindings/blst_aux.h | 1 + src/fp12_tower.c | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/bindings/blst_aux.h b/bindings/blst_aux.h index 3de0850e..b687b984 100644 --- a/bindings/blst_aux.h +++ b/bindings/blst_aux.h @@ -86,6 +86,7 @@ void blst_pairing_raw_aggregate(blst_pairing *ctx, const blst_p2_affine *q, const blst_p1_affine *p); blst_fp12 *blst_pairing_as_fp12(blst_pairing *ctx); void blst_bendian_from_fp12(byte out[48*12], const blst_fp12 *a); +void blst_fp12_from_bendian(blst_fp12 *out, const byte in[48 * 12]); void blst_keygen_v3(blst_scalar *out_SK, const byte *IKM, size_t IKM_len, const byte *info DEFNULL, size_t info_len DEFNULL); diff --git a/src/fp12_tower.c b/src/fp12_tower.c index d6c0b124..76a13acc 100644 --- a/src/fp12_tower.c +++ b/src/fp12_tower.c @@ -785,5 +785,26 @@ void blst_bendian_from_fp12(unsigned char ret[48*12], const vec384fp12 a) } } +void blst_fp12_from_bendian(vec384fp12 out, const byte in[48 * 12]) +{ + size_t i, j; + const byte *in_ptr = in; + vec384 tmp_vec; + + for (i = 0; i < 3; i++) + { + for (j = 0; j < 2; j++) + { + limbs_from_be_bytes(tmp_vec, in_ptr, sizeof(vec384)); + mul_fp(out[j][i][0], tmp_vec, BLS12_381_RR); + in_ptr += 48; + + limbs_from_be_bytes(tmp_vec, in_ptr, sizeof(vec384)); + mul_fp(out[j][i][1], tmp_vec, BLS12_381_RR); + in_ptr += 48; + } + } +} + size_t blst_fp12_sizeof(void) { return sizeof(vec384fp12); } From b85747d7980ea61083364dd011f5274d0bd91a4e Mon Sep 17 00:00:00 2001 From: Earle Lowe Date: Wed, 7 Jun 2023 11:03:37 -0700 Subject: [PATCH 2/2] Add from_bendian to PT class --- bindings/blst.hpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bindings/blst.hpp b/bindings/blst.hpp index 9e500a82..d32de4f5 100644 --- a/bindings/blst.hpp +++ b/bindings/blst.hpp @@ -860,6 +860,10 @@ class PT { bool in_group() const { return blst_fp12_in_group(&value); } void to_bendian(byte out[48*12]) const { blst_bendian_from_fp12(out, &value); } + void from_bendian(const byte in[48 * 12]) const + { + blst_fp12_from_bendian(&value, in); + } static bool finalverify(const PT& gt1, const PT& gt2) { return blst_fp12_finalverify(gt1, gt2); }