2017-12-19 20:54:22 +00:00
|
|
|
/*
|
2018-02-26 13:06:10 +00:00
|
|
|
* This file is part of the TREZOR project, https://trezor.io/
|
2017-12-19 20:54:22 +00:00
|
|
|
*
|
2018-02-26 13:06:10 +00:00
|
|
|
* Copyright (c) SatoshiLabs
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2017-12-19 20:54:22 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "py/objstr.h"
|
2018-05-14 14:44:08 +00:00
|
|
|
|
|
|
|
#include "embed/extmod/trezorobj.h"
|
|
|
|
|
2017-12-19 20:54:22 +00:00
|
|
|
#include "crc.h"
|
|
|
|
|
|
|
|
mp_obj_t mod_trezorcrypto_crc_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);
|
2018-05-14 14:44:08 +00:00
|
|
|
uint32_t crc = (n_args > 1) ? trezor_obj_get_uint(args[1]) : 0;
|
2017-12-19 20:54:22 +00:00
|
|
|
crc = crc32(bufinfo.buf, bufinfo.len, crc ^ 0xffffffff);
|
|
|
|
return mp_obj_new_int_from_uint(crc ^ 0xffffffff);
|
|
|
|
}
|
2018-01-12 12:43:52 +00:00
|
|
|
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorcrypto_crc_crc32_obj, 1, 2, mod_trezorcrypto_crc_crc32);
|
2017-12-19 20:54:22 +00:00
|
|
|
|
|
|
|
STATIC const mp_rom_map_elem_t mod_trezorcrypto_crc_globals_table[] = {
|
|
|
|
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_crc) },
|
|
|
|
{ MP_ROM_QSTR(MP_QSTR_crc32), MP_ROM_PTR(&mod_trezorcrypto_crc_crc32_obj) },
|
|
|
|
};
|
|
|
|
STATIC MP_DEFINE_CONST_DICT(mod_trezorcrypto_crc_globals, mod_trezorcrypto_crc_globals_table);
|
|
|
|
|
|
|
|
STATIC const mp_obj_module_t mod_trezorcrypto_crc_module = {
|
|
|
|
.base = { &mp_type_module },
|
|
|
|
.globals = (mp_obj_dict_t*)&mod_trezorcrypto_crc_globals,
|
|
|
|
};
|