Add error checking to bytes_to_g1

This commit is contained in:
Ramana Kumar 2022-10-05 20:04:04 +01:00
parent f0f72d3fd1
commit 989797c254
No known key found for this signature in database
GPG Key ID: ED471C788B900433
2 changed files with 19 additions and 17 deletions

View File

@ -757,10 +757,12 @@ void bytes_from_g1(uint8_t out[48], const g1_t *in) {
blst_p1_compress(out, in);
}
void 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;
blst_p1_uncompress(&tmp, bytes);
if (blst_p1_uncompress(&tmp, bytes) != BLST_SUCCESS)
return C_KZG_BADARGS;
blst_p1_from_affine(out, &tmp);
return C_KZG_OK;
}
void uint64s_from_BLSFieldElement(uint64_t out[4], const BLSFieldElement *in) {

View File

@ -37,21 +37,6 @@ typedef g1_t KZGCommitment;
typedef g1_t KZGProof;
typedef fr_t BLSFieldElement;
/**
* KZGCommitment and KZGProof can be recovered as 48 bytes
*/
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,
* so we need to expose the functions for translating between this
* 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.
*/
void uint64s_from_BLSFieldElement(uint64_t out[4], const BLSFieldElement*);
/**
* The common return type for all routines in which something can go wrong.
*
@ -66,6 +51,21 @@ typedef enum {
C_KZG_MALLOC, /**< Could not allocate memory */
} C_KZG_RET;
/**
* KZGCommitment and KZGProof can be recovered as 48 bytes
*/
void bytes_from_g1(uint8_t out[48], const g1_t*);
C_KZG_RET bytes_to_g1(g1_t* out, const uint8_t[48]);
/**
* 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].
* TODO: we should perhaps just used bytes[32] for this too.
* For conversion to BLSFieldElement use bytes_to_bls_field.
*/
void uint64s_from_BLSFieldElement(uint64_t out[4], const BLSFieldElement*);
/**
* Stores the setup and parameters needed for performing FFTs.
*/