News for hackers. Stuff that matters.
Re:Hell Is Overconfident Developers Writing Encryption Code by loeg on Saturday February 01, 2025 @05:49PM (#42903289)
I want to roll my own variant of AES (I know, I know!) CTR mode for appendable (append-only) files that does not require a key change or reencrypting any full AES block. Big caveat, this design doesn't have a MAC, with all the associated problems (it's competing against alternatives like AES-XTS, not authenticated modes).

Partial blocks are represented by stealing 4 bits of counter space to represent the length mod block size. This restricts us to 2^28 blocks or about 4GB, but that's an ok limitation for this use.

So say you initially write a file of 33 bytes: two full blocks A and B, and a partial block C. A and B get counter values 0 (len) || 0 (ctr) and 0 (len) || 1 (ctr). C is encrypted by XORing the plaintext with AES(k, IV || 1 (len) || 2 (ctr)).

You can append a byte to get a length of 34 bytes. Encrypted A/B don't change. C_2 is encrypted by XORing plaintext_2 with AES(k, IV || 2 (len) || 2 (ctr)). Since the output of AES on different inputs is essentially a PRF, this seems... ok?

Finally if you append enough bytes to fill C, it gets to len=0 mod 16. So the long and short if it is: no partial or full block will ever reuse the same k+iv+len+ctr, even rewriting it for an append.

Re:Hell Is Overconfident Developers Writing Encryption Code by some_furry on Saturday February 01, 2025 @06:00PM (#42903386)
> I want to roll my own variant of AES (I know, I know!) CTR mode for appendable (append-only) files that does not require a key change or reencrypting any full AES block.

https://xyproblem.info

Why, exactly, do you want to do that at all?

Re:Hell Is Overconfident Developers Writing Encryption Code by loeg on Saturday February 01, 2025 @06:02PM (#42903414)
I want the contents to be unreadable to an attacker who is able to steal a disk. I want to be able to append to files but not overwrite them in place, and do partial reads without decrypting the entire file.

(Google's AES-XCTR / HCTR2 seems somewhat similar.)

Re:Hell Is Overconfident Developers Writing Encryption Code by some_furry on Saturday February 01, 2025 @06:28PM (#42903660)
Hmm, are you familiar with NIST's workshops on accordion cipher modes?

I would talk to the people involved in that effort rather than wholesaling a design from scratch.

Re:Hell Is Overconfident Developers Writing Encryption Code by loeg on Saturday February 01, 2025 @09:51PM (#42905231)
Interesting!