Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update modhashlib.c : adler32 checksum. #15322

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions extmod/modhashlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@

#endif

#if MICROPY_PY_DEFLATE
#include "lib/uzlib/uzlib.h"
#endif


typedef struct _mp_obj_hash_t {
mp_obj_base_t base;
bool final; // if set, update and digest raise an exception
Expand All @@ -81,6 +86,19 @@ static mp_obj_t hashlib_sha256_update(mp_obj_t self_in, mp_obj_t arg);
#define mbedtls_sha256_finish_ret mbedtls_sha256_finish
#endif


#if MICROPY_PY_DEFLATE
static mp_obj_t hashlib_adler32(mp_obj_t data, mp_obj_t seed) {
mp_buffer_info_t bufinfo;
uint32_t res;

mp_get_buffer_raise(data, &bufinfo, MP_BUFFER_READ);
res = uzlib_adler32(bufinfo.buf, bufinfo.len, mp_obj_get_int(seed));
return mp_obj_new_int_from_uint(res);
}
static MP_DEFINE_CONST_FUN_OBJ_2(hashlib_adler32_obj, hashlib_adler32);
#endif

static mp_obj_t hashlib_sha256_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
mp_arg_check_num(n_args, n_kw, 0, 1, false);
mp_obj_hash_t *o = mp_obj_malloc_var(mp_obj_hash_t, state, char, sizeof(mbedtls_sha256_context), type);
Expand Down Expand Up @@ -365,6 +383,9 @@ static const mp_rom_map_elem_t mp_module_hashlib_globals_table[] = {
#if MICROPY_PY_HASHLIB_MD5
{ MP_ROM_QSTR(MP_QSTR_md5), MP_ROM_PTR(&hashlib_md5_type) },
#endif
#if MICROPY_PY_DEFLATE
{ MP_ROM_QSTR(MP_QSTR_adler32), MP_ROM_PTR(&hashlib_adler32_obj) },
#endif
};

static MP_DEFINE_CONST_DICT(mp_module_hashlib_globals, mp_module_hashlib_globals_table);
Expand Down
Loading