Make sure that bppp_log2 isn't called with value 0

Author:    Jonas Nick <jonasd.nick@gmail.com>
Date:      Thu Feb 9 21:31:43 2023 +0000
This commit is contained in:
Jonas Nick
2023-02-09 21:31:43 +00:00
committed by sanket1729
parent e5a01d12c6
commit d7fb25c8ca
3 changed files with 37 additions and 7 deletions

View File

@@ -45,9 +45,10 @@ static int secp256k1_is_power_of_two(size_t n) {
return n > 0 && (n & (n - 1)) == 0;
}
/* Compute the log2 of n. If n is not a power of two, it returns the largest
* `k` such that 2^k <= n. Assumes n < 2^64. In Bulletproofs, this is bounded
* by len of input vectors which can be safely assumed to be less than 2^64.
/* Compute the log2 of n. n must NOT be 0. If n is not a power of two, it
* returns the largest `k` such that 2^k <= n. Assumes 0 < n < 2^64. In
* Bulletproofs, this is bounded by len of input vectors which can be safely
* assumed to be less than 2^64.
*/
static size_t secp256k1_bppp_log2(size_t n) {
return 64 - 1 - secp256k1_clz64_var((uint64_t)n);