hare

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

commit ef178728dbe0fe9c7187073e4fd7178aa46befd2
parent dd5d3948328cd6ed1272a93b198242a839fb026c
Author: Armin Preiml <apreiml@strohwolke.at>
Date:   Sun, 16 Jan 2022 21:29:44 +0100

crypto: limit slices to equal length on slice copy

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

Diffstat:
Mcrypto/blake2b/blake2b.ha | 2+-
Mcrypto/poly1305/poly1305.ha | 2+-
Mcrypto/sha1/sha1.ha | 4++--
Mcrypto/sha256/sha256.ha | 4++--
Mcrypto/sha512/sha512.ha | 4++--
5 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/crypto/blake2b/blake2b.ha b/crypto/blake2b/blake2b.ha @@ -79,7 +79,7 @@ fn write(st: *io::stream, buf: const []u8) (size | io::error) = { for (h.blocklen + len(buf) > BSIZE) { const n = BSIZE - h.blocklen; - h.block[h.blocklen..] = buf[..n]; + h.block[h.blocklen..h.blocklen + n] = buf[..n]; buf = buf[n..]; h.tlow += BSIZE; diff --git a/crypto/poly1305/poly1305.ha b/crypto/poly1305/poly1305.ha @@ -68,7 +68,7 @@ fn write(st: *io::stream, bbuf: const []u8) (size | io::error) = { yield BLOCKSIZE - p.cidx; }; - p.c[p.cidx..] = buf[..n]; + p.c[p.cidx..p.cidx + n] = buf[..n]; p.cidx += n; buf = buf[n..]; diff --git a/crypto/sha1/sha1.ha b/crypto/sha1/sha1.ha @@ -50,7 +50,7 @@ fn write(st: *io::stream, buf: const []u8) (size | io::error) = { // Compute how many bytes can be copied into h.x let r = len(h.x) - h.nx; let n = if (nn > r) r else nn; - h.x[h.nx..] = b[..n]; + h.x[h.nx..h.nx + n] = b[..n]; h.nx += n; if (h.nx == chunk) { block(h, h.x[..]); @@ -65,7 +65,7 @@ fn write(st: *io::stream, buf: const []u8) (size | io::error) = { }; if (len(b) > 0) { let n = len(b); - h.x[..n] = b[..]; + h.x[..n] = b[..n]; h.nx = n; }; return nn; diff --git a/crypto/sha256/sha256.ha b/crypto/sha256/sha256.ha @@ -76,7 +76,7 @@ fn write(st: *io::stream, buf: const []u8) (size | io::error) = { let n = if (len(b) > len(h.x) - h.nx) { yield len(h.x) - h.nx; } else len(b); - h.x[h.nx..] = b[..n]; + h.x[h.nx..h.nx + n] = b[..n]; h.nx += n; if (h.nx == chunk) { block(h, h.x[..]); @@ -91,7 +91,7 @@ fn write(st: *io::stream, buf: const []u8) (size | io::error) = { }; if (len(b) > 0) { let n = len(b); - h.x[..n] = b[..]; + h.x[..n] = b[..n]; h.nx = n; }; return n; diff --git a/crypto/sha512/sha512.ha b/crypto/sha512/sha512.ha @@ -103,7 +103,7 @@ fn write(st: *io::stream, buf: const []u8) (size | io::error) = { // Compute how many bytes can be copied into h.x let r = len(h.x) - h.nx; let n = if (nn > r) r else nn; - h.x[h.nx..] = b[..n]; + h.x[h.nx..h.nx + n] = b[..n]; h.nx += n; if (h.nx == chunk) { block(h, h.x[..]); @@ -162,7 +162,7 @@ fn sum(h: *hash::hash, buf: []u8) void = { // We only copy the necessary bytes from fixed-size array into the // returned slice. The size is already found in the inner hash struct. - buf[..] = dig[..d.sz]; + buf[..d.sz] = dig[..d.sz]; }; fn reset(h: *hash::hash) void = {