Page 1 of 1

ciphertext question

Posted: Sun Aug 14, 2022 3:23 am
by KJM
The crypto lib in pycom's flavour of micropython allows creating a cipher for less than 16 bytes

Code: Select all

import crypto
from crypto import AES
msg='shortxt'
iv=b'sixteen chatr iv'
cipher=AES(key, AES.MODE_CFB, iv)
The ucrytolib in regular micropython however seems to only work with 16 bytes, so that shorter messages have to be padded to 16 bytes

Code: Select all

import cryptolib
msg='shortxt'+'89abcdef0'
iv=b'sixteen chatr iv'
cipher=cryptolib.aes(key, 2, iv)
Just wondering if there is anyone on the forum familiar with both libs who knows why crypto can handle the shorter messages without prompting the

Code: Select all

ValueError: blksize % 16
error?

Re: ciphertext question

Posted: Sun Aug 14, 2022 5:26 am
by TheSilverBullet
KJM wrote:
Sun Aug 14, 2022 3:23 am
The crypto lib in pycom's flavour of micropython allows aes encrytption of less than 16 bytes & the encrypted message is the same length as the unencrypted message
I wonder how an encryption standard with a minimum block size of 128 bits (16bytes) could work with less than 16 bytes and still call itself AES.

Re: ciphertext question

Posted: Wed Aug 17, 2022 3:12 am
by jimmo
KJM wrote:
Sun Aug 14, 2022 3:23 am
Just wondering if there is anyone on the forum familiar with both libs who knows why crypto can handle the shorter messages without prompting the
Your first (pycom) example is in CFB mode. The second (micropython) is in CBC mode.

We only support non-multiple-of-16 blocks in CTR mode. We also don't support CFB mode.
TheSilverBullet wrote:
Sun Aug 14, 2022 5:26 am
I wonder how an encryption standard with a minimum block size of 128 bits (16bytes) could work with less than 16 bytes and still call itself AES.
As above, it depends which mode you're in.