From 567bc2d6ce18f55e7a1d2c8e023ead44f5c2cc45 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sun, 7 Jan 2018 15:13:56 +0200 Subject: extmod/moducryptolib: Add ucryptolib module with crypto functions. The API follows guidelines of https://www.python.org/dev/peps/pep-0272/, but is optimized for code size, with the idea that full PEP 0272 compatibility can be added with a simple Python wrapper mode. The naming of the module follows (u)hashlib pattern. At the bare minimum, this module is expected to provide: * AES128, ECB (i.e. "null") mode, encrypt only Implementation in this commit is based on axTLS routines, and implements following: * AES 128 and 256 * ECB and CBC modes * encrypt and decrypt --- py/builtin.h | 1 + py/mpconfig.h | 4 ++++ py/objmodule.c | 3 +++ py/py.mk | 1 + 4 files changed, 9 insertions(+) (limited to 'py') diff --git a/py/builtin.h b/py/builtin.h index 84b99a8a4..6f8964a25 100644 --- a/py/builtin.h +++ b/py/builtin.h @@ -106,6 +106,7 @@ extern const mp_obj_module_t mp_module_ujson; extern const mp_obj_module_t mp_module_ure; extern const mp_obj_module_t mp_module_uheapq; extern const mp_obj_module_t mp_module_uhashlib; +extern const mp_obj_module_t mp_module_ucryptolib; extern const mp_obj_module_t mp_module_ubinascii; extern const mp_obj_module_t mp_module_urandom; extern const mp_obj_module_t mp_module_uselect; diff --git a/py/mpconfig.h b/py/mpconfig.h index 08d100549..2fe3bdb5a 100644 --- a/py/mpconfig.h +++ b/py/mpconfig.h @@ -1163,6 +1163,10 @@ typedef double mp_float_t; #define MICROPY_PY_UHASHLIB_SHA256 (1) #endif +#ifndef MICROPY_PY_UCRYPTOLIB +#define MICROPY_PY_UCRYPTOLIB (0) +#endif + #ifndef MICROPY_PY_UBINASCII #define MICROPY_PY_UBINASCII (0) #endif diff --git a/py/objmodule.c b/py/objmodule.c index c4aba3a7b..7ec66adf3 100644 --- a/py/objmodule.c +++ b/py/objmodule.c @@ -193,6 +193,9 @@ STATIC const mp_rom_map_elem_t mp_builtin_module_table[] = { #if MICROPY_PY_UHASHLIB { MP_ROM_QSTR(MP_QSTR_uhashlib), MP_ROM_PTR(&mp_module_uhashlib) }, #endif +#if MICROPY_PY_UCRYPTOLIB + { MP_ROM_QSTR(MP_QSTR_ucryptolib), MP_ROM_PTR(&mp_module_ucryptolib) }, +#endif #if MICROPY_PY_UBINASCII { MP_ROM_QSTR(MP_QSTR_ubinascii), MP_ROM_PTR(&mp_module_ubinascii) }, #endif diff --git a/py/py.mk b/py/py.mk index 0027fbb88..19ce55a47 100644 --- a/py/py.mk +++ b/py/py.mk @@ -227,6 +227,7 @@ PY_EXTMOD_O_BASENAME = \ extmod/moduheapq.o \ extmod/modutimeq.o \ extmod/moduhashlib.o \ + extmod/moducryptolib.o \ extmod/modubinascii.o \ extmod/virtpin.o \ extmod/machine_mem.o \ -- cgit v1.2.3