extmod/modubinascii: Make crc32() support configurable.

Disable by default, enable in unix port.
crypto-aes
Paul Sokolovsky 7 years ago
parent 39799f7564
commit c428367543

@ -204,6 +204,7 @@ mp_obj_t mod_binascii_b2a_base64(mp_obj_t data) {
}
MP_DEFINE_CONST_FUN_OBJ_1(mod_binascii_b2a_base64_obj, mod_binascii_b2a_base64);
#if MICROPY_PY_UBINASCII_CRC32
mp_obj_t mod_binascii_crc32(size_t n_args, const mp_obj_t *args) {
mp_buffer_info_t bufinfo;
mp_get_buffer_raise(args[0], &bufinfo, MP_BUFFER_READ);
@ -212,6 +213,7 @@ mp_obj_t mod_binascii_crc32(size_t n_args, const mp_obj_t *args) {
return MP_OBJ_NEW_SMALL_INT(crc ^ 0xffffffff);
}
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_binascii_crc32_obj, 1, 2, mod_binascii_crc32);
#endif
#if MICROPY_PY_UBINASCII
@ -221,7 +223,9 @@ STATIC const mp_rom_map_elem_t mp_module_binascii_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_unhexlify), MP_ROM_PTR(&mod_binascii_unhexlify_obj) },
{ MP_ROM_QSTR(MP_QSTR_a2b_base64), MP_ROM_PTR(&mod_binascii_a2b_base64_obj) },
{ MP_ROM_QSTR(MP_QSTR_b2a_base64), MP_ROM_PTR(&mod_binascii_b2a_base64_obj) },
#if MICROPY_PY_UBINASCII_CRC32
{ MP_ROM_QSTR(MP_QSTR_crc32), MP_ROM_PTR(&mod_binascii_crc32_obj) },
#endif
};
STATIC MP_DEFINE_CONST_DICT(mp_module_binascii_globals, mp_module_binascii_globals_table);

@ -887,6 +887,11 @@ typedef double mp_float_t;
#define MICROPY_PY_UBINASCII (0)
#endif
// Depends on MICROPY_PY_UZLIB
#ifndef MICROPY_PY_UBINASCII_CRC32
#define MICROPY_PY_UBINASCII_CRC32 (0)
#endif
#ifndef MICROPY_PY_URANDOM
#define MICROPY_PY_URANDOM (0)
#endif

@ -2,6 +2,12 @@ try:
import ubinascii as binascii
except ImportError:
import binascii
try:
binascii.crc32
except AttributeError:
print("SKIP")
import sys
sys.exit()
print(hex(binascii.crc32(b'The quick brown fox jumps over the lazy dog')))
print(hex(binascii.crc32(b'\x00' * 32)))

@ -117,6 +117,7 @@
#define MICROPY_PY_UHASHLIB_SHA1 (1)
#endif
#define MICROPY_PY_UBINASCII (1)
#define MICROPY_PY_UBINASCII_CRC32 (1)
#define MICROPY_PY_URANDOM (1)
#ifndef MICROPY_PY_USELECT
#define MICROPY_PY_USELECT (1)

Loading…
Cancel
Save