From aab3df643b14ce82adfeea2be55533e77c558f8d Mon Sep 17 00:00:00 2001 From: Ramana Kumar Date: Sun, 2 Oct 2022 12:09:01 +0100 Subject: [PATCH] Use pointers for scalars too --- min-src/c_kzg_4844.c | 4 ++-- min-src/c_kzg_4844.h | 2 +- src/c_kzg.h | 2 +- src/kzg_proofs.c | 16 ++++++++-------- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/min-src/c_kzg_4844.c b/min-src/c_kzg_4844.c index 8453fcc..9f7a1f9 100644 --- a/min-src/c_kzg_4844.c +++ b/min-src/c_kzg_4844.c @@ -833,14 +833,14 @@ void bytes_to_bls_field(BLSFieldElement *out, const uint8_t bytes[32]) { /** * Compute linear combinations of a sequence of vectors with some scalars */ -void vector_lincomb(fr_t out[], const fr_t *vectors[], const fr_t *scalars, uint64_t n, uint64_t m) { +void vector_lincomb(fr_t out[], const fr_t* vectors[], const fr_t* scalars[], uint64_t n, uint64_t m) { fr_t tmp; uint64_t i, j; for (j = 0; j < m; j++) out[j] = fr_zero; for (i = 0; i < n; i++) { for (j = 0; j < m; j++) { - fr_mul(&tmp, &scalars[i], vectors[i * m + j]); + fr_mul(&tmp, scalars[i], vectors[i * m + j]); fr_add(&out[j], &out[j], &tmp); } } diff --git a/min-src/c_kzg_4844.h b/min-src/c_kzg_4844.h index 3158aa1..d53e988 100644 --- a/min-src/c_kzg_4844.h +++ b/min-src/c_kzg_4844.h @@ -106,7 +106,7 @@ void free_trusted_setup(KZGSettings *s); 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); +void vector_lincomb(BLSFieldElement out[], const BLSFieldElement* vectors[], const BLSFieldElement* scalars[], uint64_t num_vectors, uint64_t vector_len); void g1_lincomb(KZGCommitment *out, const KZGCommitment points[], const BLSFieldElement scalars[], uint64_t num_points); diff --git a/src/c_kzg.h b/src/c_kzg.h index 157113e..7810544 100644 --- a/src/c_kzg.h +++ b/src/c_kzg.h @@ -108,7 +108,7 @@ void free_poly_l(poly_l *p); // kzg_proofs.c // -void fr_vector_lincomb(fr_t out[], const fr_t *vectors[], const fr_t *scalars, uint64_t n, uint64_t m); +void fr_vector_lincomb(fr_t out[], const fr_t* vectors[], const fr_t* scalars[], uint64_t n, uint64_t m); /** * Stores the setup and parameters needed for computing KZG proofs. diff --git a/src/kzg_proofs.c b/src/kzg_proofs.c index 9cb00a4..a086b4e 100644 --- a/src/kzg_proofs.c +++ b/src/kzg_proofs.c @@ -31,14 +31,14 @@ /** * Compute linear combinations of a sequence of vectors with some scalars */ -void fr_vector_lincomb(fr_t out[], const fr_t *vectors[], const fr_t *scalars, uint64_t n, uint64_t m) { +void fr_vector_lincomb(fr_t out[], const fr_t* vectors[], const fr_t* scalars[], uint64_t n, uint64_t m) { fr_t tmp; uint64_t i, j; for (j = 0; j < m; j++) out[j] = fr_zero; for (i = 0; i < n; i++) { for (j = 0; j < m; j++) { - fr_mul(&tmp, &scalars[i], vectors[i * m + j]); + fr_mul(&tmp, scalars[i], vectors[i * m + j]); fr_add(&out[j], &out[j], &tmp); } } @@ -748,20 +748,20 @@ void fr_vector_lincomb_simple_test(void) { const fr_t* vectors[] = { &v1[0], &v1[1], &v1[2], &v2[0], &v2[1], &v2[2] }; - fr_t scalars[2] = { fr_zero, fr_one }; - fr_vector_lincomb(out, (const fr_t**)vectors, (fr_t*)scalars, n, m); + const fr_t* scalars[2] = { &fr_zero, &fr_one }; + fr_vector_lincomb(out, (const fr_t**)vectors, (const fr_t**)scalars, n, m); for (i = 0; i < m; i++) { TEST_CHECK(fr_equal(&out[i], &v2[i])); } - scalars[0] = fr_one; scalars[1] = fr_zero; - fr_vector_lincomb(out, (const fr_t**)vectors, (fr_t*)scalars, n, m); + scalars[0] = &fr_one; scalars[1] = &fr_zero; + fr_vector_lincomb(out, (const fr_t**)vectors, (const fr_t**)scalars, n, m); for (i = 0; i < m; i++) { TEST_CHECK(fr_equal(&out[i], &v1[i])); } - scalars[1] = fr_one; - fr_vector_lincomb(out, (const fr_t**)vectors, (fr_t*)scalars, n, m); + scalars[1] = &fr_one; + fr_vector_lincomb(out, (const fr_t**)vectors, (const fr_t**)scalars, n, m); for (i = 0; i < m; i++) { fr_add(&tmp, &v1[i], &v2[i]); TEST_CHECK(fr_equal(&out[i], &tmp));