revocation: fix integer underflow infinite loop bug in sha chain
* `i := toDerive - 1` created an unsigned integer, the last loop iteration subtracted from zero causing this to underflow creating an infinite loop * Instead, initialized `i` as an int, and cast to uint as needed
This commit is contained in:
parent
d7fba0e89d
commit
06bad8ba42
@ -72,11 +72,11 @@ func derive(from, to uint64, startingHash [32]byte) [32]byte {
|
||||
|
||||
numBranches := from ^ to
|
||||
toDerive := uint64(math.Log2(float64(numBranches))) // uh.....
|
||||
for i := toDerive - 1; i >= 0; i-- {
|
||||
if (numBranches>>i)&1 == 1 {
|
||||
for i := int(toDerive - 1); i >= 0; i-- {
|
||||
if (numBranches>>uint(i))&1 == 1 {
|
||||
// Flip the ith bit, then hash the current state to
|
||||
// advance down the tree.
|
||||
nextHash[i/8] ^= (1 << (i % 8))
|
||||
nextHash[i/8] ^= (1 << (uint(i) % 8))
|
||||
nextHash = sha256.Sum256(nextHash[:])
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user