hare

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

commit d8bd3c7d124ae7972e16b97ee721a96c1afe15bf
parent a70ea6eaaf104e4561abce965dd3dad9997642a7
Author: Armin Preiml <apreiml@strohwolke.at>
Date:   Sun, 14 Nov 2021 18:16:05 +0100

add crypto::math::xor

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

Diffstat:
Mcrypto/math/bits.ha | 10++++++++++
1 file changed, 10 insertions(+), 0 deletions(-)

diff --git a/crypto/math/bits.ha b/crypto/math/bits.ha @@ -43,3 +43,13 @@ export fn rotr64(x: u64, k: int) u64 = rotl64(x, -k); assert(rotl64(a, -2) == 0b0011110000111100001111000011110000111100001111000011110000111100u64); }; + +// Stores the xor of a and b into dest. +export fn xor(dest: []u8, a: []u8, b: []u8) void = { + assert(len(dest) == len(a) && len(dest) == len(b), + "dest, a and b must have the same length"); + + for (let i = 0z; i < len(dest); i += 1) { + dest[i] = a[i] ^ b[i]; + }; +};