From 6630354ffe9f33d2af8154fbac003cb4db0cc348 Mon Sep 17 00:00:00 2001 From: Yonatan Goldschmidt Date: Sat, 9 Jun 2018 02:48:29 +0300 Subject: [PATCH] extmod/moduhashlib: Allow to disable the sha256 class. Via the config value MICROPY_PY_UHASHLIB_SHA256. Default to enabled to keep backwards compatibility. Also add default value for the sha1 class, to at least document its existence. --- extmod/moduhashlib.c | 8 ++++++++ py/mpconfig.h | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/extmod/moduhashlib.c b/extmod/moduhashlib.c index 2eb90ed739..e47bae0a02 100644 --- a/extmod/moduhashlib.c +++ b/extmod/moduhashlib.c @@ -31,7 +31,9 @@ #if MICROPY_PY_UHASHLIB +#if MICROPY_PY_UHASHLIB_SHA256 #include "crypto-algorithms/sha256.h" +#endif #if MICROPY_PY_UHASHLIB_SHA1 @@ -50,6 +52,7 @@ typedef struct _mp_obj_hash_t { char state[0]; } mp_obj_hash_t; +#if MICROPY_PY_UHASHLIB_SHA256 STATIC mp_obj_t uhashlib_sha256_update(mp_obj_t self_in, mp_obj_t arg); STATIC mp_obj_t uhashlib_sha256_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { @@ -94,6 +97,7 @@ STATIC const mp_obj_type_t uhashlib_sha256_type = { .make_new = uhashlib_sha256_make_new, .locals_dict = (void*)&uhashlib_sha256_locals_dict, }; +#endif #if MICROPY_PY_UHASHLIB_SHA1 STATIC mp_obj_t uhashlib_sha1_update(mp_obj_t self_in, mp_obj_t arg); @@ -177,7 +181,9 @@ STATIC const mp_obj_type_t uhashlib_sha1_type = { STATIC const mp_rom_map_elem_t mp_module_uhashlib_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_uhashlib) }, + #if MICROPY_PY_UHASHLIB_SHA256 { MP_ROM_QSTR(MP_QSTR_sha256), MP_ROM_PTR(&uhashlib_sha256_type) }, + #endif #if MICROPY_PY_UHASHLIB_SHA1 { MP_ROM_QSTR(MP_QSTR_sha1), MP_ROM_PTR(&uhashlib_sha1_type) }, #endif @@ -190,6 +196,8 @@ const mp_obj_module_t mp_module_uhashlib = { .globals = (mp_obj_dict_t*)&mp_module_uhashlib_globals, }; +#if MICROPY_PY_UHASHLIB_SHA256 #include "crypto-algorithms/sha256.c" +#endif #endif //MICROPY_PY_UHASHLIB diff --git a/py/mpconfig.h b/py/mpconfig.h index a85b22128e..08d1005491 100644 --- a/py/mpconfig.h +++ b/py/mpconfig.h @@ -1155,6 +1155,14 @@ typedef double mp_float_t; #define MICROPY_PY_UHASHLIB (0) #endif +#ifndef MICROPY_PY_UHASHLIB_SHA1 +#define MICROPY_PY_UHASHLIB_SHA1 (0) +#endif + +#ifndef MICROPY_PY_UHASHLIB_SHA256 +#define MICROPY_PY_UHASHLIB_SHA256 (1) +#endif + #ifndef MICROPY_PY_UBINASCII #define MICROPY_PY_UBINASCII (0) #endif