ciphertext question

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
KJM
Posts: 158
Joined: Sun Nov 18, 2018 10:53 pm
Location: Sydney AU

ciphertext question

Post by KJM » Sun Aug 14, 2022 3:23 am

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?
Last edited by KJM on Sun Aug 14, 2022 7:12 am, edited 2 times in total.

TheSilverBullet
Posts: 50
Joined: Thu Jul 07, 2022 7:40 am

Re: ciphertext question

Post by TheSilverBullet » Sun Aug 14, 2022 5:26 am

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.

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: ciphertext question

Post by jimmo » Wed Aug 17, 2022 3:12 am

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.

Post Reply