Page 1 of 1

AES-CMAC python interface

Posted: Tue Sep 10, 2019 5:22 am
by gradoj
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"

Re: AES-CMAC python interface

Posted: Tue Sep 10, 2019 2:56 pm
by jimmo
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!