Whole file

wbond/oscrypto

The author described this change as Fix a bug with the OpenSSL backend and using AES192/256 and no padding. It counts as a record because the check below fails on the code as it stood at ab248e782 and passes on aa161858d, with nothing else changed between the two runs.

Fix saved2022-03-18
Sharing licenceMIT · LICENSE
Change size+4 18

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

Fix a bug with the OpenSSL backend and using AES192/256 and no padding

The change

622622
623623 if cipher != 'rc4' and not padding:
624624 # AES in CBC mode can be allowed with no padding if
625- # the data is an exact multiple of the key size
626- aes128_no_padding = (
627- cipher == 'aes128' and
628- padding is False and
629- len(data) % 16 == 0
630- )
631- aes192_no_padding = (
632- cipher == 'aes192' and
633- padding is False and
634- len(data) % 24 == 0
635- )
636- aes256_no_padding = (
637- cipher == 'aes256' and
638- padding is False and
639- len(data) % 32 == 0
640- )
641- if aes128_no_padding is False and aes192_no_padding is False and aes256_no_padding is False:
625+ # the data is an exact multiple of the block size
626+ is_aes = cipher in set(['aes128', 'aes192', 'aes256'])
627+ if not is_aes or (is_aes and (len(data) % 16) != 0):
642628 raise ValueError('padding must be specified')
643629
644630 evp_cipher_ctx = None
748734 type_name(iv)
749735 ))
750736
751- if cipher != 'rc4' and padding is None:
737+ if cipher not in set(['rc4', 'aes128', 'aes192', 'aes256']) and not padding:
752738 raise ValueError('padding must be specified')
753739
754740 evp_cipher_ctx = None

The check that tells the two apart

failpass·tests/test_symmetric.py::SymmetricTests::test_aes_192_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 itab248e782d73a958e52c6fce33b1cd1e57e6306c
Broken version dated2022-03-15
Moduleoscrypto._openssl.symmetric
Units changed_decrypt, _encrypt
Fingerprint5db0bbbb6985c67a
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