AES-CMAC python interface

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
Post Reply
gradoj
Posts: 27
Joined: Mon Aug 11, 2014 5:47 pm

AES-CMAC python interface

Post by gradoj » Tue Sep 10, 2019 5:22 am

Hello. I would like to use AES-CMAC which is used for message verification/authentication in micropython. It appears the ucryptolib AES code comes from mbed tls which also includes CMAC code. Anyone know if cmac has been stripped out for micropython or do I need to just build a python interface on top of it?

Should I just copy the AES ucryptolib.c to add support for CMAC or any other suggestions to get me started?

Is anyone working on or any intentions of adding a python interface for cmac? Regular python has it implemented like this:

>>> from Crypto.Hash import CMAC
>>> from Crypto.Cipher import AES
>>>
>>> secret = b'Sixteen byte key'
>>> cobj = CMAC.new(secret, ciphermod=AES)
>>> cobj.update(msg)
>>> try:
>>> cobj.verify(mac)
>>> print "The message '%s' is authentic" % msg
>>> except ValueError:
>>> print "The message or the key is wrong"

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

Re: AES-CMAC python interface

Post by jimmo » Tue Sep 10, 2019 2:56 pm

Yes I would imagine it just wasn't included because of space constraints. Adding a Python interface in ucryptolib.c should be fairly straightforward.

It might be difficult to get a PR merged though because of the size cost... maybe if you made it disabled by default with a #define. If you're going to do it for your own purposes, no harm in sending a PR I guess!

Post Reply