From 8f6bc22b2f9e41da835911069af1eb3191749d41 Mon Sep 17 00:00:00 2001 From: Ramana Kumar Date: Sat, 1 Oct 2022 12:42:44 +0100 Subject: [PATCH] Avoid exposing blst scalar --- min-bindings/c_kzg_4844.swg | 1 - min-src/c_kzg_4844.c | 8 +++++--- min-src/c_kzg_4844.h | 5 ++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/min-bindings/c_kzg_4844.swg b/min-bindings/c_kzg_4844.swg index 25a3e71..f435dc2 100644 --- a/min-bindings/c_kzg_4844.swg +++ b/min-bindings/c_kzg_4844.swg @@ -70,7 +70,6 @@ } #endif -%array_class(scalar_t, scalars) %array_class(uint8_t, bytes) %array_class(BLSFieldElement, BLSFieldElements) %pointer_class(PolynomialEvalForm, PolynomialEvalFormPtr) diff --git a/min-src/c_kzg_4844.c b/min-src/c_kzg_4844.c index 4af0cc6..5c40cd5 100644 --- a/min-src/c_kzg_4844.c +++ b/min-src/c_kzg_4844.c @@ -753,7 +753,7 @@ static bool pairings_verify(const g1_t *a1, const g2_t *a2, const g1_t *b1, cons } -void Bytes48_from_G1(uint8_t out[48], const g1_t *in) { +void bytes_from_G1(uint8_t out[48], const g1_t *in) { blst_p1_compress(out, in); } @@ -824,8 +824,10 @@ void compute_powers(fr_t out[], const fr_t *x, uint64_t n) { while (++i < n) fr_mul(&out[i], &out[i-1], x); } -void bytes_to_bls_field(BLSFieldElement *out, const scalar_t *bytes) { - blst_fr_from_scalar(out, bytes); +void bytes_to_bls_field(BLSFieldElement *out, const uint8_t bytes[32]) { + blst_scalar tmp; + blst_scalar_from_lendian(&tmp, bytes); + blst_fr_from_scalar(out, &tmp); } /** diff --git a/min-src/c_kzg_4844.h b/min-src/c_kzg_4844.h index 23162fa..9b4b369 100644 --- a/min-src/c_kzg_4844.h +++ b/min-src/c_kzg_4844.h @@ -32,7 +32,6 @@ typedef blst_p1 g1_t; /**< Internal G1 group element type */ typedef blst_p2 g2_t; /**< Internal G2 group element type */ typedef blst_fr fr_t; /**< Internal Fr field element type */ -typedef blst_scalar scalar_t; /**< Internal scalar type */ typedef g1_t KZGCommitment; typedef g1_t KZGProof; @@ -41,7 +40,7 @@ typedef fr_t BLSFieldElement; /** * KZGCommitment and KZGProof can be recovered as 48 bytes */ -void Bytes48_from_G1(uint8_t out[48], const g1_t*); +void bytes_from_G1(uint8_t out[48], const g1_t*); /** * BLSFieldElements are communicated directly to/from clients, @@ -105,7 +104,7 @@ C_KZG_RET load_trusted_setup(KZGSettings *out, FILE *in); void free_trusted_setup(KZGSettings *s); -void bytes_to_bls_field(BLSFieldElement *out, const scalar_t *bytes); +void bytes_to_bls_field(BLSFieldElement *out, const uint8_t bytes[32]); void vector_lincomb(BLSFieldElement out[], const BLSFieldElement *vectors, const BLSFieldElement *scalars, uint64_t num_vectors, uint64_t vector_len);