As an experiment / as a bit of a gag, I tried using Claude 3.7 Sonnet with Cline to write some simple cryptography code in Rust - use ECDHE to establish an ephemeral symmetric key, and then use AES256-GCM (with a counter in the nonce) to encrypt packets from client->server and server->client, using off-the-shelf RustCrypto libraries.
It got the interface right, but it got some details really wrong:
- It stored way more information than it needed in the structure tracking state, some of it very sensitive.
- It repeatedly converted back and forth between byte arrays and the proper types unnecessarily - reducing type safety and making things slower.
- Instead of using type safe enums it defined integer constants for no good reason.
- It logged information about failures as variable length strings, creating a possible timing side channel attack.
- Despite having a 96 bit nonce to work with (-1 bit to identify client->server and server->client), it used a 32 bit integer to represent the sequence number.
- And it "helpfully" used
wrapping_add
to increment the 32 sequence number! For those who don't know much Rust and/or much cryptography: the golden rule of using ciphers like GCM is that you must never ever re-use the same nonce for the same key (otherwise you leak the XOR of the two messages).wrapping_add
explicitly means when you get up to the maximum number (and remember, it's only 32 bits, so there's only about 4.3 billion numbers) it silently wraps back to 0. The secure implementation would be to explicitly fail if you go past the maximum size for the integer before attempting to encrypt / decrypt - and the smart choice would be to use at least 64 bits. - It also rolled its own bespoke hash-based key extension function instead of using HKDF (which was available right there in the library, and callable with far less code than it generated).
To be fair, I didn't really expect it to work well. Some kind of security auditor agent that does a pass over all the output might be able to find some of the issues, and pass it back to another agent to correct - which could make vibe coding more secure (to be proven).
But right now, I'd not put "vibe coded" output into production without someone going over it manually with a fine-toothed comb looking for security and stability issues.