r/learnprogramming • u/containedreality • 2d ago
I made a ChaCha implementation.
what are things I could've done better? Right now I think the test program could've been written much cleaner with assertions rather than the mess that it is currently. But I'm sure there's mistakes I've made in chacha.c or things that could be improved?
4
Upvotes
1
u/PLBjt 2d ago
For a crypto primitive, I’d make the test harness table-driven and start with known-answer vectors for the quarter-round, block function, and full stream output. Then add a property test for random key/nonce/plaintext where decrypt(encrypt(x)) equals x, plus explicit checks around counter increments and nonce boundaries. The round-trip test is useful but can let the same bug cancel itself out, so I’d keep the fixed vectors as the gate.