You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The g function in Implementation in blake.ts uses ~~(lo / 0x0100000000) to compute the carry from the lower 32 bits of a 64-bit word.
Since lo can be up to 0x2FFFFFFFC (i.e., approximately 3 times 0x0100000000), the carry can erroneously be 2 or 3.
Impact
Functional Integrity: Incorrect carry values can corrupt the internal state, leading to wrong hash outputs.
Security Risks: The integrity of the hash function is compromised, potentially allowing for hash collisions or predictable outputs, which undermines the cryptographic strength of Blake2-512.
Recommendation
Modify the carry calculation to ensure that only a single carry bit (0 or 1) is propagated. For example:
Alternatively, use BigInt for precise 64-bit arithmetic operations as in the original Blake implementation in the npm repo, which TypeScript supports, to handle carries correctly without manual intervention.
Incorrect Carry Handling in the
g
FunctionThe
g
function in Implementation inblake.ts
uses~~(lo / 0x0100000000)
to compute the carry from the lower 32 bits of a 64-bit word.Since
lo
can be up to0x2FFFFFFFC
(i.e., approximately 3 times0x0100000000
), the carry can erroneously be 2 or 3.Impact
Recommendation
P.S. Cross-posted from privacy-scaling-explorations/zk-kit#344 because it is the same implementation.
The text was updated successfully, but these errors were encountered: