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 <desnacked@riseup.net>
This commit is contained in:
Gottfried Herold 2023-03-09 17:24:49 +01:00 committed by GitHub
parent 2642595e39
commit fa851f1b2c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 0 deletions

View File

@ -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;