mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-16 03:18:09 +00:00
adapt to new trezor-crypto
This commit is contained in:
parent
dd93b1a0cf
commit
33f3566f61
@ -7,8 +7,7 @@
|
||||
|
||||
#include "py/objstr.h"
|
||||
|
||||
#include "mbedtls/pkcs5.h"
|
||||
#include "mbedtls/md_internal.h"
|
||||
#include "trezor-crypto/pbkdf2.h"
|
||||
|
||||
// def pbkdf2_hmac(hash_name: str, password: bytes, salt: bytes, iterations: int, dklen:int=None) -> bytes
|
||||
STATIC mp_obj_t mod_TrezorCrypto_pbkdf2_hmac(size_t n_args, const mp_obj_t *args) {
|
||||
@ -21,32 +20,27 @@ STATIC mp_obj_t mod_TrezorCrypto_pbkdf2_hmac(size_t n_args, const mp_obj_t *args
|
||||
mp_int_t iterations = mp_obj_get_int(args[3]);
|
||||
mp_int_t dklen = (n_args > 4) ? mp_obj_get_int(args[4]) : 0;
|
||||
|
||||
const mbedtls_md_info_t *info = 0;
|
||||
int digestsize = 0;
|
||||
if (hash_name.len == 6 && memcmp(hash_name.buf, "sha256", hash_name.len) == 0) {
|
||||
info = mbedtls_md_info_from_type(MBEDTLS_MD_SHA256);
|
||||
digestsize = 32;
|
||||
} else
|
||||
if (hash_name.len == 6 && memcmp(hash_name.buf, "sha512", hash_name.len) == 0) {
|
||||
info = mbedtls_md_info_from_type(MBEDTLS_MD_SHA512);
|
||||
digestsize = 64;
|
||||
}
|
||||
if (info == 0) {
|
||||
if (digestsize == 0) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Invalid hash_name"));
|
||||
}
|
||||
|
||||
if (dklen == 0) {
|
||||
dklen = info->size;
|
||||
dklen = digestsize;
|
||||
}
|
||||
mbedtls_md_context_t ctx;
|
||||
mbedtls_md_init(&ctx);
|
||||
if (mbedtls_md_setup(&ctx, info, 1) == 0) {
|
||||
vstr_t vstr;
|
||||
vstr_init_len(&vstr, dklen);
|
||||
mbedtls_pkcs5_pbkdf2_hmac(&ctx, password.buf, password.len, salt.buf, salt.len, iterations, dklen, (uint8_t *)vstr.buf);
|
||||
mbedtls_md_free(&ctx);
|
||||
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
|
||||
} else {
|
||||
mbedtls_md_free(&ctx);
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_RuntimeError, "mbedtls_md_setup failed"));
|
||||
vstr_t vstr;
|
||||
vstr_init_len(&vstr, dklen);
|
||||
if (digestsize == 32) {
|
||||
pbkdf2_hmac_sha256(password.buf, password.len, salt.buf, salt.len, iterations, (uint8_t *)vstr.buf, dklen, NULL);
|
||||
}
|
||||
return mp_const_none;
|
||||
if (digestsize == 64) {
|
||||
pbkdf2_hmac_sha512(password.buf, password.len, salt.buf, salt.len, iterations, (uint8_t *)vstr.buf, dklen, NULL);
|
||||
}
|
||||
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorCrypto_pbkdf2_hmac_obj, 4, 5, mod_TrezorCrypto_pbkdf2_hmac);
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
#include "py/objstr.h"
|
||||
|
||||
#include "mbedtls/ripemd160.h"
|
||||
#include "trezor-crypto/ripemd160.h"
|
||||
|
||||
#define HASH_RIPEMD160_BLOCK_SIZE 64
|
||||
#define HASH_RIPEMD160_DIGEST_SIZE 20
|
||||
@ -15,7 +15,7 @@
|
||||
// class Ripemd160(object):
|
||||
typedef struct _mp_obj_Ripemd160_t {
|
||||
mp_obj_base_t base;
|
||||
mbedtls_ripemd160_context ctx;
|
||||
RIPEMD160_CTX ctx;
|
||||
} mp_obj_Ripemd160_t;
|
||||
|
||||
STATIC mp_obj_t mod_TrezorCrypto_Ripemd160_update(mp_obj_t self, mp_obj_t data);
|
||||
@ -25,8 +25,7 @@ STATIC mp_obj_t mod_TrezorCrypto_Ripemd160_make_new(const mp_obj_type_t *type, s
|
||||
mp_arg_check_num(n_args, n_kw, 0, 1, false);
|
||||
mp_obj_Ripemd160_t *o = m_new_obj(mp_obj_Ripemd160_t);
|
||||
o->base.type = type;
|
||||
mbedtls_ripemd160_init(&(o->ctx));
|
||||
mbedtls_ripemd160_starts(&(o->ctx));
|
||||
ripemd160_Init(&(o->ctx));
|
||||
// constructor called with bytes/str as first parameter
|
||||
if (n_args == 1) {
|
||||
mod_TrezorCrypto_Ripemd160_update(MP_OBJ_FROM_PTR(o), args[0]);
|
||||
@ -39,7 +38,7 @@ STATIC mp_obj_t mod_TrezorCrypto_Ripemd160_update(mp_obj_t self, mp_obj_t data)
|
||||
mp_obj_Ripemd160_t *o = MP_OBJ_TO_PTR(self);
|
||||
mp_buffer_info_t databuf;
|
||||
mp_get_buffer_raise(data, &databuf, MP_BUFFER_READ);
|
||||
mbedtls_ripemd160_update(&(o->ctx), databuf.buf, databuf.len);
|
||||
ripemd160_Update(&(o->ctx), databuf.buf, databuf.len);
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_Ripemd160_update_obj, mod_TrezorCrypto_Ripemd160_update);
|
||||
@ -49,10 +48,10 @@ STATIC mp_obj_t mod_TrezorCrypto_Ripemd160_digest(mp_obj_t self) {
|
||||
mp_obj_Ripemd160_t *o = MP_OBJ_TO_PTR(self);
|
||||
vstr_t vstr;
|
||||
vstr_init_len(&vstr, HASH_RIPEMD160_DIGEST_SIZE);
|
||||
mbedtls_ripemd160_context ctx;
|
||||
mbedtls_ripemd160_clone(&ctx, &(o->ctx));
|
||||
mbedtls_ripemd160_finish(&ctx, (uint8_t *)vstr.buf);
|
||||
mbedtls_ripemd160_free(&ctx);
|
||||
RIPEMD160_CTX ctx;
|
||||
memcpy(&ctx, &(o->ctx), sizeof(RIPEMD160_CTX));
|
||||
ripemd160_Final(&ctx, (uint8_t *)vstr.buf);
|
||||
memset(&ctx, 0, sizeof(RIPEMD160_CTX));
|
||||
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_TrezorCrypto_Ripemd160_digest_obj, mod_TrezorCrypto_Ripemd160_digest);
|
||||
@ -60,7 +59,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_TrezorCrypto_Ripemd160_digest_obj, mod_Trez
|
||||
// def Ripemd160.__del__(self) -> None
|
||||
STATIC mp_obj_t mod_TrezorCrypto_Ripemd160___del__(mp_obj_t self) {
|
||||
mp_obj_Ripemd160_t *o = MP_OBJ_TO_PTR(self);
|
||||
mbedtls_ripemd160_free(&(o->ctx));
|
||||
memset(&(o->ctx), 0, sizeof(RIPEMD160_CTX));
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_TrezorCrypto_Ripemd160___del___obj, mod_TrezorCrypto_Ripemd160___del__);
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
#include "py/objstr.h"
|
||||
|
||||
#include "mbedtls/sha256.h"
|
||||
#include "trezor-crypto/sha2.h"
|
||||
|
||||
#define HASH_SHA256_BLOCK_SIZE 64
|
||||
#define HASH_SHA256_DIGEST_SIZE 32
|
||||
@ -15,7 +15,7 @@
|
||||
// class Sha256(object):
|
||||
typedef struct _mp_obj_Sha256_t {
|
||||
mp_obj_base_t base;
|
||||
mbedtls_sha256_context ctx;
|
||||
SHA256_CTX ctx;
|
||||
} mp_obj_Sha256_t;
|
||||
|
||||
STATIC mp_obj_t mod_TrezorCrypto_Sha256_update(mp_obj_t self, mp_obj_t data);
|
||||
@ -25,8 +25,7 @@ STATIC mp_obj_t mod_TrezorCrypto_Sha256_make_new(const mp_obj_type_t *type, size
|
||||
mp_arg_check_num(n_args, n_kw, 0, 1, false);
|
||||
mp_obj_Sha256_t *o = m_new_obj(mp_obj_Sha256_t);
|
||||
o->base.type = type;
|
||||
mbedtls_sha256_init(&(o->ctx));
|
||||
mbedtls_sha256_starts(&(o->ctx), 0);
|
||||
sha256_Init(&(o->ctx));
|
||||
// constructor called with bytes/str as first parameter
|
||||
if (n_args == 1) {
|
||||
mod_TrezorCrypto_Sha256_update(MP_OBJ_FROM_PTR(o), args[0]);
|
||||
@ -39,7 +38,7 @@ STATIC mp_obj_t mod_TrezorCrypto_Sha256_update(mp_obj_t self, mp_obj_t data) {
|
||||
mp_obj_Sha256_t *o = MP_OBJ_TO_PTR(self);
|
||||
mp_buffer_info_t databuf;
|
||||
mp_get_buffer_raise(data, &databuf, MP_BUFFER_READ);
|
||||
mbedtls_sha256_update(&(o->ctx), databuf.buf, databuf.len);
|
||||
sha256_Update(&(o->ctx), databuf.buf, databuf.len);
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_Sha256_update_obj, mod_TrezorCrypto_Sha256_update);
|
||||
@ -49,10 +48,10 @@ STATIC mp_obj_t mod_TrezorCrypto_Sha256_digest(mp_obj_t self) {
|
||||
mp_obj_Sha256_t *o = MP_OBJ_TO_PTR(self);
|
||||
vstr_t vstr;
|
||||
vstr_init_len(&vstr, HASH_SHA256_DIGEST_SIZE);
|
||||
mbedtls_sha256_context ctx;
|
||||
mbedtls_sha256_clone(&ctx, &(o->ctx));
|
||||
mbedtls_sha256_finish(&ctx, (uint8_t *)vstr.buf);
|
||||
mbedtls_sha256_free(&ctx);
|
||||
SHA256_CTX ctx;
|
||||
memcpy(&ctx, &(o->ctx), sizeof(SHA256_CTX));
|
||||
sha256_Final(&ctx, (uint8_t *)vstr.buf);
|
||||
memset(&ctx, 0, sizeof(SHA256_CTX));
|
||||
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_TrezorCrypto_Sha256_digest_obj, mod_TrezorCrypto_Sha256_digest);
|
||||
@ -60,7 +59,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_TrezorCrypto_Sha256_digest_obj, mod_TrezorC
|
||||
// def Sha256.__del__(self) -> None
|
||||
STATIC mp_obj_t mod_TrezorCrypto_Sha256___del__(mp_obj_t self) {
|
||||
mp_obj_Sha256_t *o = MP_OBJ_TO_PTR(self);
|
||||
mbedtls_sha256_free(&(o->ctx));
|
||||
memset(&(o->ctx), 0, sizeof(SHA256_CTX));
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_TrezorCrypto_Sha256___del___obj, mod_TrezorCrypto_Sha256___del__);
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
#include "py/objstr.h"
|
||||
|
||||
#include "sha3.h"
|
||||
#include "trezor-crypto/sha3.h"
|
||||
|
||||
#define HASH_SHA3_256_BLOCK_SIZE 64
|
||||
#define HASH_SHA3_256_DIGEST_SIZE 32
|
||||
@ -15,7 +15,7 @@
|
||||
// class Sha3_256(object):
|
||||
typedef struct _mp_obj_Sha3_256_t {
|
||||
mp_obj_base_t base;
|
||||
sha3_ctx ctx;
|
||||
SHA3_CTX ctx;
|
||||
} mp_obj_Sha3_256_t;
|
||||
|
||||
STATIC mp_obj_t mod_TrezorCrypto_Sha3_256_update(mp_obj_t self, mp_obj_t data);
|
||||
@ -25,7 +25,7 @@ STATIC mp_obj_t mod_TrezorCrypto_Sha3_256_make_new(const mp_obj_type_t *type, si
|
||||
mp_arg_check_num(n_args, n_kw, 0, 1, false);
|
||||
mp_obj_Sha3_256_t *o = m_new_obj(mp_obj_Sha3_256_t);
|
||||
o->base.type = type;
|
||||
rhash_sha3_256_init(&(o->ctx));
|
||||
sha3_256_Init(&(o->ctx));
|
||||
// constructor called with bytes/str as first parameter
|
||||
if (n_args == 1) {
|
||||
mod_TrezorCrypto_Sha3_256_update(MP_OBJ_FROM_PTR(o), args[0]);
|
||||
@ -38,7 +38,7 @@ STATIC mp_obj_t mod_TrezorCrypto_Sha3_256_update(mp_obj_t self, mp_obj_t data) {
|
||||
mp_obj_Sha3_256_t *o = MP_OBJ_TO_PTR(self);
|
||||
mp_buffer_info_t databuf;
|
||||
mp_get_buffer_raise(data, &databuf, MP_BUFFER_READ);
|
||||
rhash_sha3_update(&(o->ctx), databuf.buf, databuf.len);
|
||||
sha3_Update(&(o->ctx), databuf.buf, databuf.len);
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_Sha3_256_update_obj, mod_TrezorCrypto_Sha3_256_update);
|
||||
@ -48,10 +48,10 @@ STATIC mp_obj_t mod_TrezorCrypto_Sha3_256_digest(mp_obj_t self) {
|
||||
mp_obj_Sha3_256_t *o = MP_OBJ_TO_PTR(self);
|
||||
vstr_t vstr;
|
||||
vstr_init_len(&vstr, HASH_SHA3_256_DIGEST_SIZE);
|
||||
sha3_ctx ctx;
|
||||
memcpy(&ctx, &(o->ctx), sizeof(sha3_ctx));
|
||||
rhash_sha3_final(&ctx, (uint8_t *)vstr.buf);
|
||||
memset(&ctx, 0, sizeof(sha3_ctx));
|
||||
SHA3_CTX ctx;
|
||||
memcpy(&ctx, &(o->ctx), sizeof(SHA3_CTX));
|
||||
sha3_Final(&ctx, (uint8_t *)vstr.buf);
|
||||
memset(&ctx, 0, sizeof(SHA3_CTX));
|
||||
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_TrezorCrypto_Sha3_256_digest_obj, mod_TrezorCrypto_Sha3_256_digest);
|
||||
@ -59,7 +59,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_TrezorCrypto_Sha3_256_digest_obj, mod_Trezo
|
||||
// def Sha3_256.__del__(self) -> None
|
||||
STATIC mp_obj_t mod_TrezorCrypto_Sha3_256___del__(mp_obj_t self) {
|
||||
mp_obj_Sha3_256_t *o = MP_OBJ_TO_PTR(self);
|
||||
memset(&(o->ctx), 0, sizeof(sha3_ctx));
|
||||
memset(&(o->ctx), 0, sizeof(SHA3_CTX));
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_TrezorCrypto_Sha3_256___del___obj, mod_TrezorCrypto_Sha3_256___del__);
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
#include "py/objstr.h"
|
||||
|
||||
#include "sha3.h"
|
||||
#include "trezor-crypto/sha3.h"
|
||||
|
||||
#define HASH_SHA3_512_BLOCK_SIZE 128
|
||||
#define HASH_SHA3_512_DIGEST_SIZE 64
|
||||
@ -15,7 +15,7 @@
|
||||
// class Sha3_512(object):
|
||||
typedef struct _mp_obj_Sha3_512_t {
|
||||
mp_obj_base_t base;
|
||||
sha3_ctx ctx;
|
||||
SHA3_CTX ctx;
|
||||
} mp_obj_Sha3_512_t;
|
||||
|
||||
STATIC mp_obj_t mod_TrezorCrypto_Sha3_512_update(mp_obj_t self, mp_obj_t data);
|
||||
@ -25,7 +25,7 @@ STATIC mp_obj_t mod_TrezorCrypto_Sha3_512_make_new(const mp_obj_type_t *type, si
|
||||
mp_arg_check_num(n_args, n_kw, 0, 1, false);
|
||||
mp_obj_Sha3_512_t *o = m_new_obj(mp_obj_Sha3_512_t);
|
||||
o->base.type = type;
|
||||
rhash_sha3_512_init(&(o->ctx));
|
||||
sha3_512_Init(&(o->ctx));
|
||||
// constructor called with bytes/str as first parameter
|
||||
if (n_args == 1) {
|
||||
mod_TrezorCrypto_Sha3_512_update(MP_OBJ_FROM_PTR(o), args[0]);
|
||||
@ -38,7 +38,7 @@ STATIC mp_obj_t mod_TrezorCrypto_Sha3_512_update(mp_obj_t self, mp_obj_t data) {
|
||||
mp_obj_Sha3_512_t *o = MP_OBJ_TO_PTR(self);
|
||||
mp_buffer_info_t databuf;
|
||||
mp_get_buffer_raise(data, &databuf, MP_BUFFER_READ);
|
||||
rhash_sha3_update(&(o->ctx), databuf.buf, databuf.len);
|
||||
sha3_Update(&(o->ctx), databuf.buf, databuf.len);
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_Sha3_512_update_obj, mod_TrezorCrypto_Sha3_512_update);
|
||||
@ -48,10 +48,10 @@ STATIC mp_obj_t mod_TrezorCrypto_Sha3_512_digest(mp_obj_t self) {
|
||||
mp_obj_Sha3_512_t *o = MP_OBJ_TO_PTR(self);
|
||||
vstr_t vstr;
|
||||
vstr_init_len(&vstr, HASH_SHA3_512_DIGEST_SIZE);
|
||||
sha3_ctx ctx;
|
||||
memcpy(&ctx, &(o->ctx), sizeof(sha3_ctx));
|
||||
rhash_sha3_final(&ctx, (uint8_t *)vstr.buf);
|
||||
memset(&ctx, 0, sizeof(sha3_ctx));
|
||||
SHA3_CTX ctx;
|
||||
memcpy(&ctx, &(o->ctx), sizeof(SHA3_CTX));
|
||||
sha3_Final(&ctx, (uint8_t *)vstr.buf);
|
||||
memset(&ctx, 0, sizeof(SHA3_CTX));
|
||||
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_TrezorCrypto_Sha3_512_digest_obj, mod_TrezorCrypto_Sha3_512_digest);
|
||||
@ -59,7 +59,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_TrezorCrypto_Sha3_512_digest_obj, mod_Trezo
|
||||
// def Sha3_512.__del__(self) -> None
|
||||
STATIC mp_obj_t mod_TrezorCrypto_Sha3_512___del__(mp_obj_t self) {
|
||||
mp_obj_Sha3_512_t *o = MP_OBJ_TO_PTR(self);
|
||||
memset(&(o->ctx), 0, sizeof(sha3_ctx));
|
||||
memset(&(o->ctx), 0, sizeof(SHA3_CTX));
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_TrezorCrypto_Sha3_512___del___obj, mod_TrezorCrypto_Sha3_512___del__);
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
#include "py/objstr.h"
|
||||
|
||||
#include "mbedtls/sha512.h"
|
||||
#include "trezor-crypto/sha2.h"
|
||||
|
||||
#define HASH_SHA512_BLOCK_SIZE 128
|
||||
#define HASH_SHA512_DIGEST_SIZE 64
|
||||
@ -15,7 +15,7 @@
|
||||
// class Sha512(object):
|
||||
typedef struct _mp_obj_Sha512_t {
|
||||
mp_obj_base_t base;
|
||||
mbedtls_sha512_context ctx;
|
||||
SHA512_CTX ctx;
|
||||
} mp_obj_Sha512_t;
|
||||
|
||||
STATIC mp_obj_t mod_TrezorCrypto_Sha512_update(mp_obj_t self, mp_obj_t data);
|
||||
@ -25,8 +25,7 @@ STATIC mp_obj_t mod_TrezorCrypto_Sha512_make_new(const mp_obj_type_t *type, size
|
||||
mp_arg_check_num(n_args, n_kw, 0, 1, false);
|
||||
mp_obj_Sha512_t *o = m_new_obj(mp_obj_Sha512_t);
|
||||
o->base.type = type;
|
||||
mbedtls_sha512_init(&(o->ctx));
|
||||
mbedtls_sha512_starts(&(o->ctx), 0);
|
||||
sha512_Init(&(o->ctx));
|
||||
if (n_args == 1) {
|
||||
mod_TrezorCrypto_Sha512_update(MP_OBJ_FROM_PTR(o), args[0]);
|
||||
}
|
||||
@ -38,7 +37,7 @@ STATIC mp_obj_t mod_TrezorCrypto_Sha512_update(mp_obj_t self, mp_obj_t data) {
|
||||
mp_obj_Sha512_t *o = MP_OBJ_TO_PTR(self);
|
||||
mp_buffer_info_t databuf;
|
||||
mp_get_buffer_raise(data, &databuf, MP_BUFFER_READ);
|
||||
mbedtls_sha512_update(&(o->ctx), databuf.buf, databuf.len);
|
||||
sha512_Update(&(o->ctx), databuf.buf, databuf.len);
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorCrypto_Sha512_update_obj, mod_TrezorCrypto_Sha512_update);
|
||||
@ -48,10 +47,10 @@ STATIC mp_obj_t mod_TrezorCrypto_Sha512_digest(mp_obj_t self) {
|
||||
mp_obj_Sha512_t *o = MP_OBJ_TO_PTR(self);
|
||||
vstr_t vstr;
|
||||
vstr_init_len(&vstr, HASH_SHA512_DIGEST_SIZE);
|
||||
mbedtls_sha512_context ctx;
|
||||
mbedtls_sha512_clone(&ctx, &(o->ctx));
|
||||
mbedtls_sha512_finish(&ctx, (uint8_t *)vstr.buf);
|
||||
mbedtls_sha512_free(&ctx);
|
||||
SHA512_CTX ctx;
|
||||
memcpy(&ctx, &(o->ctx), sizeof(SHA512_CTX));
|
||||
sha512_Final(&ctx, (uint8_t *)vstr.buf);
|
||||
memset(&ctx, 0, sizeof(SHA512_CTX));
|
||||
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_TrezorCrypto_Sha512_digest_obj, mod_TrezorCrypto_Sha512_digest);
|
||||
@ -59,7 +58,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_TrezorCrypto_Sha512_digest_obj, mod_TrezorC
|
||||
// def Sha512.__del__(self) -> None
|
||||
STATIC mp_obj_t mod_TrezorCrypto_Sha512___del__(mp_obj_t self) {
|
||||
mp_obj_Sha512_t *o = MP_OBJ_TO_PTR(self);
|
||||
mbedtls_sha512_free(&(o->ctx));
|
||||
memset(&(o->ctx), 0, sizeof(SHA512_CTX));
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_TrezorCrypto_Sha512___del___obj, mod_TrezorCrypto_Sha512___del__);
|
||||
|
1
extmod/modtrezorcrypto/trezor-crypto
Symbolic link
1
extmod/modtrezorcrypto/trezor-crypto
Symbolic link
@ -0,0 +1 @@
|
||||
../../vendor/trezor-crypto
|
2
vendor/micropython
vendored
2
vendor/micropython
vendored
@ -1 +1 @@
|
||||
Subproject commit f0ffa8c044759ba10bd092b3ad0e1434fa1b6654
|
||||
Subproject commit 7a0980d51160a757bc509f7294460179e399a45a
|
2
vendor/trezor-crypto
vendored
2
vendor/trezor-crypto
vendored
@ -1 +1 @@
|
||||
Subproject commit c01be339f5c43d244aa545c444cd060f334f7fe2
|
||||
Subproject commit 08219ea77ad5651c7bd2641ca13956a90ba96ae6
|
Loading…
Reference in New Issue
Block a user