~sircmpwn/hare-dev

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
2 2

[PATCH hare] crypto::cipher::ctr: finish underlying block on close

Details
Message ID
<20220510144902.10974-1-apreiml@strohwolke.at>
DKIM signature
pass
Download raw message
Patch: +10 -5
Signed-off-by: Armin Preiml <apreiml@strohwolke.at>
---
 crypto/aes/ctr+test.ha | 11 +++++++----
 crypto/cipher/ctr.ha   |  4 +++-
 2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/crypto/aes/ctr+test.ha b/crypto/aes/ctr+test.ha
index c6831f94..c8c9631b 100644
--- a/crypto/aes/ctr+test.ha
+++ b/crypto/aes/ctr+test.ha
@@ -34,7 +34,6 @@ use io;

	let b = ct64();
	ct64_init(&b, key);
	defer cipher::finish(&b);

	let ctr = cipher::ctr(&resultbuf, &b, iv[..], buf[..]);

@@ -47,6 +46,9 @@ use io;
	const bsz = cipher::blocksz(&b);
	assert(bytes::equal(ctr.xorbuf, zero[bsz..]));

	let b = ct64();
	ct64_init(&b, key);

	result = [0...];
	buf = [0...];
	let cipherbuf = bufio::fixed(cipher, io::mode::READ);
@@ -85,7 +87,6 @@ use io;

	let b = ct64();
	ct64_init(&b, key);
	defer cipher::finish(&b);

	let ctr = cipher::ctr(&resultbuf, &b, iv[..], buf[..]);
	defer io::close(&ctr)!;
@@ -137,7 +138,6 @@ use io;

	let b = ct64();
	ct64_init(&b, key);
	defer cipher::finish(&b);

	let ctr = cipher::ctr(&resultbuf, &b, iv[..], buf[..]);
	const n = io::writeall(&ctr, plain)!;
@@ -145,11 +145,15 @@ use io;
	assert(bytes::equal(cipher, result));
	io::close(&ctr)!;

	let b = ct64();
	ct64_init(&b, key);

	let cipherbuf = bufio::fixed(cipher, io::mode::READ);
	let ctr = cipher::ctr(&cipherbuf, &b, iv[..], buf[..]);
	const n = io::readall(&ctr, result)!;
	assert(n as size == len(plain));
	assert(bytes::equal(plain, result));
	io::close(&ctr)!;
};

@test fn ctr_test_multiple_calls() void = {
@@ -195,7 +199,6 @@ use io;

	let b = ct64();
	ct64_init(&b, key);
	defer cipher::finish(&b);

	let ctr = cipher::ctr(&resultbuf, &b, iv[..], buf[..]);
	defer io::close(&ctr)!;
diff --git a/crypto/cipher/ctr.ha b/crypto/cipher/ctr.ha
index c12c4ceb..7f5720bc 100644
--- a/crypto/cipher/ctr.ha
+++ b/crypto/cipher/ctr.ha
@@ -26,7 +26,8 @@ export type ctr_stream = struct {
// of these buffers for static allocation.
//
// The user must call [[io::close]] when they are done using the stream to
// securely erase secret information stored in the stream state.
// securely erase secret information stored in the stream state. This will also
// finish the underlying [[block]] cipher.
export fn ctr(h: io::handle, b: *block, iv: []u8, buf: []u8) ctr_stream = {
	assert(len(iv) == blocksz(b), "iv is of invalid block size");
	assert(len(buf) >= blocksz(b) * 2, "buf must be at least 2 * blocksize");
@@ -109,4 +110,5 @@ fn ctr_advance(s: *xorstream, n: size) void = {
fn ctr_finish(s: *xorstream) void = {
	let ctr = s: *ctr_stream;
	bytes::zero(ctr.xorbuf);
	finish(ctr.b);
};
-- 
2.36.1

[hare/patches] build success

builds.sr.ht <builds@sr.ht>
Details
Message ID
<CJW5Z93XNO4Z.5QFGGIM7L6SK@cirno>
In-Reply-To
<20220510144902.10974-1-apreiml@strohwolke.at> (view parent)
DKIM signature
missing
Download raw message
hare/patches: SUCCESS in 1m32s

[crypto::cipher::ctr: finish underlying block on close][0] from [Armin Preiml][1]

[0]: https://lists.sr.ht/~sircmpwn/hare-dev/patches/32160
[1]: apreiml@strohwolke.at

✓ #755282 SUCCESS hare/patches/freebsd.yml https://builds.sr.ht/~sircmpwn/job/755282
✓ #755281 SUCCESS hare/patches/alpine.yml  https://builds.sr.ht/~sircmpwn/job/755281
Details
Message ID
<CJYO1MCJ692N.2A9X4QFK9N2TB@taiga>
In-Reply-To
<20220510144902.10974-1-apreiml@strohwolke.at> (view parent)
DKIM signature
fail
Download raw message
DKIM signature: fail
Thanks!

To git@git.sr.ht:~sircmpwn/hare
   7b323f92..ac7517aa  master -> master
Reply to thread Export thread (mbox)