|
|
@ -63,6 +63,38 @@ STATIC mp_obj_t uhashlib_sha256_make_new(const mp_obj_type_t *type, size_t n_arg |
|
|
|
return MP_OBJ_FROM_PTR(o); |
|
|
|
} |
|
|
|
|
|
|
|
STATIC mp_obj_t uhashlib_sha256_update(mp_obj_t self_in, mp_obj_t arg) { |
|
|
|
mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in); |
|
|
|
mp_buffer_info_t bufinfo; |
|
|
|
mp_get_buffer_raise(arg, &bufinfo, MP_BUFFER_READ); |
|
|
|
sha256_update((CRYAL_SHA256_CTX*)self->state, bufinfo.buf, bufinfo.len); |
|
|
|
return mp_const_none; |
|
|
|
} |
|
|
|
MP_DEFINE_CONST_FUN_OBJ_2(uhashlib_sha256_update_obj, uhashlib_sha256_update); |
|
|
|
|
|
|
|
STATIC mp_obj_t uhashlib_sha256_digest(mp_obj_t self_in) { |
|
|
|
mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in); |
|
|
|
vstr_t vstr; |
|
|
|
vstr_init_len(&vstr, SHA256_BLOCK_SIZE); |
|
|
|
sha256_final((CRYAL_SHA256_CTX*)self->state, (byte*)vstr.buf); |
|
|
|
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr); |
|
|
|
} |
|
|
|
MP_DEFINE_CONST_FUN_OBJ_1(uhashlib_sha256_digest_obj, uhashlib_sha256_digest); |
|
|
|
|
|
|
|
STATIC const mp_rom_map_elem_t uhashlib_sha256_locals_dict_table[] = { |
|
|
|
{ MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&uhashlib_sha256_update_obj) }, |
|
|
|
{ MP_ROM_QSTR(MP_QSTR_digest), MP_ROM_PTR(&uhashlib_sha256_digest_obj) }, |
|
|
|
}; |
|
|
|
|
|
|
|
STATIC MP_DEFINE_CONST_DICT(uhashlib_sha256_locals_dict, uhashlib_sha256_locals_dict_table); |
|
|
|
|
|
|
|
STATIC const mp_obj_type_t uhashlib_sha256_type = { |
|
|
|
{ &mp_type_type }, |
|
|
|
.name = MP_QSTR_sha256, |
|
|
|
.make_new = uhashlib_sha256_make_new, |
|
|
|
.locals_dict = (void*)&uhashlib_sha256_locals_dict, |
|
|
|
}; |
|
|
|
|
|
|
|
#if MICROPY_PY_UHASHLIB_SHA1 |
|
|
|
STATIC mp_obj_t uhashlib_sha1_update(mp_obj_t self_in, mp_obj_t arg); |
|
|
|
|
|
|
@ -77,6 +109,22 @@ STATIC mp_obj_t uhashlib_sha1_make_new(const mp_obj_type_t *type, size_t n_args, |
|
|
|
} |
|
|
|
return MP_OBJ_FROM_PTR(o); |
|
|
|
} |
|
|
|
|
|
|
|
STATIC mp_obj_t uhashlib_sha1_update(mp_obj_t self_in, mp_obj_t arg) { |
|
|
|
mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in); |
|
|
|
mp_buffer_info_t bufinfo; |
|
|
|
mp_get_buffer_raise(arg, &bufinfo, MP_BUFFER_READ); |
|
|
|
SHA1_Update((SHA1_CTX*)self->state, bufinfo.buf, bufinfo.len); |
|
|
|
return mp_const_none; |
|
|
|
} |
|
|
|
|
|
|
|
STATIC mp_obj_t uhashlib_sha1_digest(mp_obj_t self_in) { |
|
|
|
mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in); |
|
|
|
vstr_t vstr; |
|
|
|
vstr_init_len(&vstr, SHA1_SIZE); |
|
|
|
SHA1_Final((byte*)vstr.buf, (SHA1_CTX*)self->state); |
|
|
|
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr); |
|
|
|
} |
|
|
|
#endif |
|
|
|
|
|
|
|
#if MICROPY_SSL_MBEDTLS |
|
|
@ -91,32 +139,7 @@ STATIC mp_obj_t uhashlib_sha1_make_new(const mp_obj_type_t *type, size_t n_args, |
|
|
|
} |
|
|
|
return MP_OBJ_FROM_PTR(o); |
|
|
|
} |
|
|
|
#endif |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
STATIC mp_obj_t uhashlib_sha256_update(mp_obj_t self_in, mp_obj_t arg) { |
|
|
|
mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in); |
|
|
|
mp_buffer_info_t bufinfo; |
|
|
|
mp_get_buffer_raise(arg, &bufinfo, MP_BUFFER_READ); |
|
|
|
sha256_update((CRYAL_SHA256_CTX*)self->state, bufinfo.buf, bufinfo.len); |
|
|
|
return mp_const_none; |
|
|
|
} |
|
|
|
MP_DEFINE_CONST_FUN_OBJ_2(uhashlib_sha256_update_obj, uhashlib_sha256_update); |
|
|
|
|
|
|
|
#if MICROPY_PY_UHASHLIB_SHA1 |
|
|
|
|
|
|
|
#if MICROPY_SSL_AXTLS |
|
|
|
STATIC mp_obj_t uhashlib_sha1_update(mp_obj_t self_in, mp_obj_t arg) { |
|
|
|
mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in); |
|
|
|
mp_buffer_info_t bufinfo; |
|
|
|
mp_get_buffer_raise(arg, &bufinfo, MP_BUFFER_READ); |
|
|
|
SHA1_Update((SHA1_CTX*)self->state, bufinfo.buf, bufinfo.len); |
|
|
|
return mp_const_none; |
|
|
|
} |
|
|
|
#endif |
|
|
|
|
|
|
|
#if MICROPY_SSL_MBEDTLS |
|
|
|
STATIC mp_obj_t uhashlib_sha1_update(mp_obj_t self_in, mp_obj_t arg) { |
|
|
|
mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in); |
|
|
|
mp_buffer_info_t bufinfo; |
|
|
@ -124,33 +147,7 @@ STATIC mp_obj_t uhashlib_sha1_update(mp_obj_t self_in, mp_obj_t arg) { |
|
|
|
mbedtls_sha1_update((mbedtls_sha1_context*)self->state, bufinfo.buf, bufinfo.len); |
|
|
|
return mp_const_none; |
|
|
|
} |
|
|
|
#endif |
|
|
|
|
|
|
|
MP_DEFINE_CONST_FUN_OBJ_2(uhashlib_sha1_update_obj, uhashlib_sha1_update); |
|
|
|
#endif |
|
|
|
|
|
|
|
STATIC mp_obj_t uhashlib_sha256_digest(mp_obj_t self_in) { |
|
|
|
mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in); |
|
|
|
vstr_t vstr; |
|
|
|
vstr_init_len(&vstr, SHA256_BLOCK_SIZE); |
|
|
|
sha256_final((CRYAL_SHA256_CTX*)self->state, (byte*)vstr.buf); |
|
|
|
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr); |
|
|
|
} |
|
|
|
MP_DEFINE_CONST_FUN_OBJ_1(uhashlib_sha256_digest_obj, uhashlib_sha256_digest); |
|
|
|
|
|
|
|
#if MICROPY_PY_UHASHLIB_SHA1 |
|
|
|
|
|
|
|
#if MICROPY_SSL_AXTLS |
|
|
|
STATIC mp_obj_t uhashlib_sha1_digest(mp_obj_t self_in) { |
|
|
|
mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in); |
|
|
|
vstr_t vstr; |
|
|
|
vstr_init_len(&vstr, SHA1_SIZE); |
|
|
|
SHA1_Final((byte*)vstr.buf, (SHA1_CTX*)self->state); |
|
|
|
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr); |
|
|
|
} |
|
|
|
#endif |
|
|
|
|
|
|
|
#if MICROPY_SSL_MBEDTLS |
|
|
|
STATIC mp_obj_t uhashlib_sha1_digest(mp_obj_t self_in) { |
|
|
|
mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in); |
|
|
|
vstr_t vstr; |
|
|
@ -161,24 +158,9 @@ STATIC mp_obj_t uhashlib_sha1_digest(mp_obj_t self_in) { |
|
|
|
} |
|
|
|
#endif |
|
|
|
|
|
|
|
MP_DEFINE_CONST_FUN_OBJ_2(uhashlib_sha1_update_obj, uhashlib_sha1_update); |
|
|
|
MP_DEFINE_CONST_FUN_OBJ_1(uhashlib_sha1_digest_obj, uhashlib_sha1_digest); |
|
|
|
#endif |
|
|
|
|
|
|
|
STATIC const mp_rom_map_elem_t uhashlib_sha256_locals_dict_table[] = { |
|
|
|
{ MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&uhashlib_sha256_update_obj) }, |
|
|
|
{ MP_ROM_QSTR(MP_QSTR_digest), MP_ROM_PTR(&uhashlib_sha256_digest_obj) }, |
|
|
|
}; |
|
|
|
|
|
|
|
STATIC MP_DEFINE_CONST_DICT(uhashlib_sha256_locals_dict, uhashlib_sha256_locals_dict_table); |
|
|
|
|
|
|
|
STATIC const mp_obj_type_t uhashlib_sha256_type = { |
|
|
|
{ &mp_type_type }, |
|
|
|
.name = MP_QSTR_sha256, |
|
|
|
.make_new = uhashlib_sha256_make_new, |
|
|
|
.locals_dict = (void*)&uhashlib_sha256_locals_dict, |
|
|
|
}; |
|
|
|
|
|
|
|
#if MICROPY_PY_UHASHLIB_SHA1 |
|
|
|
STATIC const mp_rom_map_elem_t uhashlib_sha1_locals_dict_table[] = { |
|
|
|
{ MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&uhashlib_sha1_update_obj) }, |
|
|
|
{ MP_ROM_QSTR(MP_QSTR_digest), MP_ROM_PTR(&uhashlib_sha1_digest_obj) }, |
|
|
|