wireguard-lwip icon indicating copy to clipboard operation
wireguard-lwip copied to clipboard

Chacha20poly1305 enc/dec function not symmetrical

Open sacca97 opened this issue 1 year ago • 0 comments

Not sure you intended this, but the encryption and decryption function are not symmetrical. (i.e. the ct length is not encoded in the padding)

Basic code sample follows.

` uint8_t msg[7] = "Simola"; size_t pad = (sizeof(msg) + 15) & 0xFFFFFFF0; uint8_t enc[16 + pad]; aead_encrypt(enc, msg, 7, NULL, 0, 0, key_bytes); uint8_t dec[16]; int rc = aead_decrypt(dec, enc, sizeof(enc), NULL, 0, 0, key_bytes);

assert(crypto_equal(msg, dec, 7) && rc == 1);`

The assertion fails, but If I call the decryption function with srclen = 16+7 then the decryption is successfull.

sacca97 avatar Sep 05 '23 14:09 sacca97