Add secp256k1_scalar_half for halving scalars (+ tests/benchmarks).

Co-authored-by: Jonas Nick <jonasd.nick@gmail.com>
Co-authored-by: Tim Ruffing <crypto@timruffing.de>
This commit is contained in:
Pieter Wuille
2022-12-29 11:48:06 -05:00
parent 1f1bb78b7f
commit 2140da9cd5
6 changed files with 153 additions and 0 deletions

View File

@@ -205,4 +205,12 @@ static void secp256k1_scalar_inverse_var(secp256k1_scalar *r, const secp256k1_sc
secp256k1_scalar_verify(r);
}
static void secp256k1_scalar_half(secp256k1_scalar *r, const secp256k1_scalar *a) {
secp256k1_scalar_verify(a);
*r = (*a + ((-(uint32_t)(*a & 1)) & EXHAUSTIVE_TEST_ORDER)) >> 1;
secp256k1_scalar_verify(r);
}
#endif /* SECP256K1_SCALAR_REPR_IMPL_H */