Add bytes_to_g1 to the interface

This commit is contained in:
Ramana Kumar 2022-10-05 19:33:27 +01:00
parent b3d550d1a3
commit f0f72d3fd1
No known key found for this signature in database
GPG Key ID: ED471C788B900433
2 changed files with 9 additions and 3 deletions

View File

@ -757,6 +757,12 @@ void bytes_from_g1(uint8_t out[48], const g1_t *in) {
blst_p1_compress(out, in); blst_p1_compress(out, in);
} }
void bytes_to_g1(g1_t* out, const uint8_t bytes[48]) {
blst_p1_affine tmp;
blst_p1_uncompress(&tmp, bytes);
blst_p1_from_affine(out, &tmp);
}
void uint64s_from_BLSFieldElement(uint64_t out[4], const BLSFieldElement *in) { void uint64s_from_BLSFieldElement(uint64_t out[4], const BLSFieldElement *in) {
blst_uint64_from_fr(out, in); blst_uint64_from_fr(out, in);
} }
@ -765,7 +771,6 @@ void uint64s_from_BLSFieldElement(uint64_t out[4], const BLSFieldElement *in) {
C_KZG_RET load_trusted_setup(KZGSettings *out, FILE *in) { C_KZG_RET load_trusted_setup(KZGSettings *out, FILE *in) {
uint64_t n2, i; uint64_t n2, i;
int j; uint8_t c[96]; int j; uint8_t c[96];
blst_p1_affine g1_affine;
blst_p2_affine g2_affine; blst_p2_affine g2_affine;
g1_t *g1_projective; g1_t *g1_projective;
@ -781,8 +786,7 @@ C_KZG_RET load_trusted_setup(KZGSettings *out, FILE *in) {
for (j = 0; j < 48; j++) { for (j = 0; j < 48; j++) {
fscanf(in, "%2hhx", &c[j]); fscanf(in, "%2hhx", &c[j]);
} }
blst_p1_uncompress(&g1_affine, c); bytes_to_g1(&g1_projective[i], c);
blst_p1_from_affine(&g1_projective[i], &g1_affine);
} }
for (i = 0; i < n2; i++) { for (i = 0; i < n2; i++) {

View File

@ -41,11 +41,13 @@ typedef fr_t BLSFieldElement;
* KZGCommitment and KZGProof can be recovered as 48 bytes * KZGCommitment and KZGProof can be recovered as 48 bytes
*/ */
void bytes_from_g1(uint8_t out[48], const g1_t*); void bytes_from_g1(uint8_t out[48], const g1_t*);
void bytes_to_g1(g1_t* out, const uint8_t[48]);
/** /**
* BLSFieldElements are communicated directly to/from clients, * BLSFieldElements are communicated directly to/from clients,
* so we need to expose the functions for translating between this * so we need to expose the functions for translating between this
* type and uint256. BLST represents uint256 as uint64[4]. * type and uint256. BLST represents uint256 as uint64[4].
* TODO: we should perhaps just used bytes[32] for this too.
* For conversion to BLSFieldElement use bytes_to_bls_field. * For conversion to BLSFieldElement use bytes_to_bls_field.
*/ */
void uint64s_from_BLSFieldElement(uint64_t out[4], const BLSFieldElement*); void uint64s_from_BLSFieldElement(uint64_t out[4], const BLSFieldElement*);