diff --git a/README.md b/README.md index 7376e8d..1587881 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ This is a copy of C-KZG stripped down to support the [Polynomial Commitments](ht We also provide `load_trusted_setup` and `free_trusted_setup` to load the trusted setup data from a file into an object that can be passed to the API -functions. +functions, and functions for converting commitments/proofs/points to/from bytes. The only dependency is [blst](https://github.com/supranational/blst). Ensure `blst.h` is provided in `inc` and `libblst.a` in `lib`. diff --git a/src/c_kzg_4844.c b/src/c_kzg_4844.c index cd01e5f..da96fef 100644 --- a/src/c_kzg_4844.c +++ b/src/c_kzg_4844.c @@ -752,11 +752,11 @@ static bool pairings_verify(const g1_t *a1, const g2_t *a2, const g1_t *b1, cons } -static void bytes_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); } -static C_KZG_RET bytes_to_g1(g1_t* out, const uint8_t bytes[48]) { +C_KZG_RET bytes_to_g1(g1_t* out, const uint8_t bytes[48]) { blst_p1_affine tmp; if (blst_p1_uncompress(&tmp, bytes) != BLST_SUCCESS) return C_KZG_BADARGS; @@ -829,7 +829,7 @@ static void compute_powers(fr_t out[], uint64_t n) { while (++i < n) fr_mul(&out[i], &out[i-1], &out[1]); } -static void bytes_to_bls_field(BLSFieldElement *out, const uint8_t bytes[32]) { +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/src/c_kzg_4844.h b/src/c_kzg_4844.h index b77b559..752a451 100644 --- a/src/c_kzg_4844.h +++ b/src/c_kzg_4844.h @@ -31,7 +31,7 @@ #define FIELD_ELEMENTS_PER_BLOB 4096 #define BYTES_PER_FIELD_ELEMENT 32 -const uint8_t FIAT_SHAMIR_PROTOCOL_DOMAIN[] = {70, 83, 66, 76, 79, 66, 86, 69, 82, 73, 70, 89, 95, 86, 49, 95}; // "FSBLOBVERIFY_V1_" +static const uint8_t FIAT_SHAMIR_PROTOCOL_DOMAIN[] = {70, 83, 66, 76, 79, 66, 86, 69, 82, 73, 70, 89, 95, 86, 49, 95}; // "FSBLOBVERIFY_V1_" typedef blst_p1 g1_t; /**< Internal G1 group element type */ typedef blst_p2 g2_t; /**< Internal G2 group element type */ @@ -80,6 +80,11 @@ typedef struct { * Interface functions */ +C_KZG_RET bytes_to_g1(g1_t* out, const uint8_t in[48]); +void bytes_from_g1(uint8_t out[48], const g1_t *in); + +void bytes_to_bls_field(BLSFieldElement *out, const uint8_t in[BYTES_PER_FIELD_ELEMENT]); + C_KZG_RET load_trusted_setup(KZGSettings *out, FILE *in);