From fa851f1b2c43974daec85fb94e22dce5ab87b7ee Mon Sep 17 00:00:00 2001 From: Gottfried Herold Date: Thu, 9 Mar 2023 17:24:49 +0100 Subject: [PATCH] fr_batch_inv() now fails if output and input pointers alias (#185) instead of giving wrong result with no error Co-authored-by: George Kadianakis --- src/c_kzg_4844.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/c_kzg_4844.c b/src/c_kzg_4844.c index 2ef6374..9689d5d 100644 --- a/src/c_kzg_4844.c +++ b/src/c_kzg_4844.c @@ -301,6 +301,9 @@ static void fr_from_uint64(fr_t *out, uint64_t n) { /** * Montgomery batch inversion in finite field. * + * @remark This function does not support in-place computation (i.e. `a` MUST + * NOT point to the same place as `out`) + * * @param[out] out The inverses of @p a, length @p len * @param[in] a A vector of field elements, length @p len * @param[in] len The number of field elements @@ -311,6 +314,8 @@ static C_KZG_RET fr_batch_inv(fr_t *out, const fr_t *a, size_t len) { fr_t inv; size_t i; + assert(a != out); + ret = new_fr_array(&prod, len); if (ret != C_KZG_OK) goto out;