From 24212039b2d0cd0453b93f06bb31100fc35b6979 Mon Sep 17 00:00:00 2001 From: Ramana Kumar Date: Thu, 29 Sep 2022 19:32:23 +0100 Subject: [PATCH] Add conversions to/from uint64s to the interface --- min-src/c_kzg_4844.c | 9 +++++++++ min-src/c_kzg_4844.h | 8 ++++++++ 2 files changed, 17 insertions(+) diff --git a/min-src/c_kzg_4844.c b/min-src/c_kzg_4844.c index 1537316..cace77c 100644 --- a/min-src/c_kzg_4844.c +++ b/min-src/c_kzg_4844.c @@ -753,6 +753,15 @@ static bool pairings_verify(const g1_t *a1, const g2_t *a2, const g1_t *b1, cons } +void BLSFieldElement_from_uint64s(BLSFieldElement *out, const uint64_t in[4]) { + blst_fr_from_uint64(out, in); +} + +void uint64s_from_BLSFieldElement(uint64_t out[4], const BLSFieldElement *in) { + blst_uint64_from_fr(out, in); +} + + C_KZG_RET load_trusted_setup(KZGSettings *out, FILE *in) { uint64_t n2, i; diff --git a/min-src/c_kzg_4844.h b/min-src/c_kzg_4844.h index 699c38e..d0473fc 100644 --- a/min-src/c_kzg_4844.h +++ b/min-src/c_kzg_4844.h @@ -38,6 +38,14 @@ typedef g1_t KZGCommitment; typedef g1_t KZGProof; typedef fr_t BLSFieldElement; +/** + * BLSFieldElements are communicated directly to/from clients, + * so we need to expose the functions for translating between this + * type and uint256. BLST represents uint256 as uint64[4]. + */ +void BLSFieldElement_from_uint64s(BLSFieldElement *out, const uint64_t[4]); +void uint64s_from_BLSFieldElement(uint64_t out[4], const BLSFieldElement*); + /** * The common return type for all routines in which something can go wrong. *