One function

_encrypt in wbond/oscrypto

The author described this change as Fix aes_cbc_no_padding_encrypt() with OpenSSL, add tests. It counts as a record because the check below fails on the code as it stood at 63abadd04 and passes on 67d001795, with nothing else changed between the two runs.

Fix saved2019-07-23
Sharing licenceMIT · LICENSE
Change size+19 1

What the code was meant to do, written into the code itself as a docstring

Encrypts plaintext :param cipher: A unicode string of "aes128", "aes192", "aes256", "des", "tripledes_2key", "tripledes_3key", "rc2", "rc4" :param key: The encryption key - a byte string 5-32 bytes long :param data: The plaintext - a byte string :param iv: The initialization vector - a byte string - unused for RC4 :param padding: Boolean, if padding should be used - unused for RC4 :raises: ValueError - when any of the parameters contain an invalid value TypeError - when any of the parameters are of the wrong type OSError - when an error is returned by OpenSSL :return: A byte string of the ciphertext

The change

5252 ))
5353
5454 if cipher != 'rc4' and not padding:
55- raise ValueError('padding must be specified')
55+ # AES in CBC mode can be allowed with no padding if
56+ # the data is an exact multiple of the key size
57+ aes128_no_padding = (
58+ cipher == 'aes128' and
59+ padding is False and
60+ len(data) % 16 == 0
61+ )
62+ aes192_no_padding = (
63+ cipher == 'aes192' and
64+ padding is False and
65+ len(data) % 24 == 0
66+ )
67+ aes256_no_padding = (
68+ cipher == 'aes256' and
69+ padding is False and
70+ len(data) % 32 == 0
71+ )
72+ if aes128_no_padding is False and aes192_no_padding is False and aes256_no_padding is False:
73+ raise ValueError('padding must be specified')
5674
5775 evp_cipher_ctx = None
5876

The check that tells the two apart

failpass·tests/test_symmetric.py::SymmetricTests::test_aes_cbc_no_padding_encrypt_decrypt

Check file tests/test_symmetric.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.

Origin and history

The code before it63abadd04116eaf43db83fccdde64edb591c9c8f
Broken version dated2019-07-19
Moduleoscrypto._openssl.symmetric
Units changed_encrypt
Fingerprintf3ba63724ae04710
Checked2026-08-18 by goldset/0.1

Every field above is generated by our program. None of it is written by hand.

Other bugs found in wbond/oscrypto