hare

The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit b98348c2d847b9c482aa6cb8429b0c1c109e54d8
parent 1547477390abaa30c45b71f0275d49aaab89bc1f
Author: Armin Preiml <apreiml@strohwolke.at>
Date:   Wed, 12 Jan 2022 13:31:20 +0100

crypto::math: fix cmpslice

Signed-off-by: Armin Preiml <apreiml@strohwolke.at>

Diffstat:
Mcrypto/math/bits.ha | 9++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/crypto/math/bits.ha b/crypto/math/bits.ha @@ -61,7 +61,7 @@ export fn cmpslice(x: []u8, y: []u8) int = { assert(len(x) == len(y), "slices must have the same length"); let v: u8 = 0; for (let i = 0z; i < len(x); i += 1) { - v = x[i] ^ y[i]; + v |= x[i] ^ y[i]; }; return cmpu8(v, 0); }; @@ -69,6 +69,13 @@ export fn cmpslice(x: []u8, y: []u8) int = { @test fn cmpslice() void = { assert(cmpslice([], []) == 1); assert(cmpslice([0], [0]) == 1); + assert(cmpslice([1], [0]) == 0); + assert(cmpslice([1, 0], [0, 0]) == 0); + assert(cmpslice([0, 0], [0, 0]) == 1); + + assert(cmpslice([0x12, 0xAB], [0x12, 0xAB]) == 1); + assert(cmpslice([0x12, 0xAB], [0x12, 0xAC]) == 0); + assert(cmpslice([0x12, 0xAB], [0x11, 0xAB]) == 0); }; // Compare two bytes in constant time. Returns 1 if the bytes are the same