3 ms·
Can anyone do a rough cryptoanalysis of the code? It uses AES block cipher in CBC mode with a random iv. Which attacks is this open to? First, I suspect it's l
by diminish 11y ago
Can anyone do a rough cryptoanalysis of the code? It uses AES block cipher in CBC mode with a random iv. Which attacks is this open to?
First, I suspect it's lacking a secure integrity check (MAC), so is weak against chosen ciphertext attacks.
def encrypt(self, plaintext):
plaintext = self.pad(plaintext)
iv = Random.new().read(AES.block_size)
cipher = AES.new(self.key, AES.MODE_CBC, iv)
return iv + cipher.encrypt(plaintext)
I'm also not sure about his padding of zeros to attain the AES block size - was there a more secure padding?
def pad(self, s):
return s + b"\0" * (AES.block_size - len(s) % AES.block_size)