1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-21 23:18:13 +00:00

introduce and use memzero instead of explicit_bzero

This commit is contained in:
Pavol Rusnak 2018-01-18 15:26:22 +01:00
parent 3098dc8447
commit e92440dfc8
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
18 changed files with 37 additions and 20 deletions

View File

@ -26,6 +26,7 @@ SOURCE_MOD += [
'vendor/trezor-crypto/ed25519-donna/ed25519-donna-32bit-tables.c',
'vendor/trezor-crypto/ed25519-donna/ed25519-donna-impl-base.c',
'vendor/trezor-crypto/ed25519-donna/modm-donna-32bit.c',
'vendor/trezor-crypto/memzero.c',
'vendor/trezor-crypto/sha2.c',
]

View File

@ -26,6 +26,7 @@ SOURCE_MOD += [
'vendor/trezor-crypto/ed25519-donna/ed25519-donna-32bit-tables.c',
'vendor/trezor-crypto/ed25519-donna/ed25519-donna-impl-base.c',
'vendor/trezor-crypto/ed25519-donna/modm-donna-32bit.c',
'vendor/trezor-crypto/memzero.c',
'vendor/trezor-crypto/sha2.c',
]

View File

@ -60,6 +60,7 @@ SOURCE_MOD += [
'vendor/trezor-crypto/ed25519-donna/modm-donna-32bit.c',
'vendor/trezor-crypto/hasher.c',
'vendor/trezor-crypto/hmac.c',
'vendor/trezor-crypto/memzero.c',
'vendor/trezor-crypto/nist256p1.c',
'vendor/trezor-crypto/pbkdf2.c',
'vendor/trezor-crypto/rand.c',

View File

@ -59,6 +59,7 @@ SOURCE_MOD += [
'vendor/trezor-crypto/ed25519-donna/modm-donna-32bit.c',
'vendor/trezor-crypto/hasher.c',
'vendor/trezor-crypto/hmac.c',
'vendor/trezor-crypto/memzero.c',
'vendor/trezor-crypto/nist256p1.c',
'vendor/trezor-crypto/pbkdf2.c',
'vendor/trezor-crypto/rand.c',

View File

@ -8,6 +8,7 @@
#include "py/objstr.h"
#include "aes/aes.h"
#include "memzero.h"
/// class AES:
/// '''
@ -145,8 +146,8 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_AES_update_obj, mod_trezorcryp
STATIC mp_obj_t mod_trezorcrypto_AES___del__(mp_obj_t self) {
mp_obj_AES_t *o = MP_OBJ_TO_PTR(self);
explicit_bzero(&(o->ctx), sizeof(aes_encrypt_ctx));
explicit_bzero(o->iv, AES_BLOCK_SIZE);
memzero(&(o->ctx), sizeof(aes_encrypt_ctx));
memzero(o->iv, AES_BLOCK_SIZE);
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_AES___del___obj, mod_trezorcrypto_AES___del__);

View File

@ -9,6 +9,7 @@
#include "bip32.h"
#include "curves.h"
#include "memzero.h"
/// class HDNode:
/// '''
@ -93,17 +94,17 @@ STATIC mp_obj_t mod_trezorcrypto_HDNode_make_new(const mp_obj_type_t *type, size
if (NULL != chain_code.buf && 32 == chain_code.len) {
memcpy(o->hdnode.chain_code, chain_code.buf, 32);
} else {
explicit_bzero(o->hdnode.chain_code, 32);
memzero(o->hdnode.chain_code, 32);
}
if (NULL != private_key.buf && 32 == private_key.len) {
memcpy(o->hdnode.private_key, private_key.buf, 32);
} else {
explicit_bzero(o->hdnode.private_key, 32);
memzero(o->hdnode.private_key, 32);
}
if (NULL != public_key.buf && 33 == public_key.len) {
memcpy(o->hdnode.public_key, public_key.buf, 33);
} else {
explicit_bzero(o->hdnode.public_key, 33);
memzero(o->hdnode.public_key, 33);
}
o->hdnode.curve = curve;
@ -120,7 +121,7 @@ STATIC mp_obj_t mod_trezorcrypto_HDNode_derive(mp_obj_t self, mp_obj_t index) {
uint32_t fp = hdnode_fingerprint(&o->hdnode);
if (!hdnode_private_ckd(&o->hdnode, i)) {
explicit_bzero(&o->hdnode, sizeof(o->hdnode));
memzero(&o->hdnode, sizeof(o->hdnode));
mp_raise_ValueError("Failed to derive");
}
o->fingerprint = fp;
@ -157,7 +158,7 @@ STATIC mp_obj_t mod_trezorcrypto_HDNode_derive_path(mp_obj_t self, mp_obj_t path
if (!hdnode_private_ckd_cached(&o->hdnode, pints, plen, &o->fingerprint)) {
// derivation failed, reset the state and raise
o->fingerprint = 0;
explicit_bzero(&o->hdnode, sizeof(o->hdnode));
memzero(&o->hdnode, sizeof(o->hdnode));
mp_raise_ValueError("Failed to derive path");
}

View File

@ -8,6 +8,7 @@
#include "py/objstr.h"
#include "blake256.h"
#include "memzero.h"
/// class Blake256:
/// '''
@ -68,7 +69,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Blake256_digest_obj, mod_trezo
STATIC mp_obj_t mod_trezorcrypto_Blake256___del__(mp_obj_t self) {
mp_obj_Blake256_t *o = MP_OBJ_TO_PTR(self);
explicit_bzero(&(o->ctx), sizeof(BLAKE256_CTX));
memzero(&(o->ctx), sizeof(BLAKE256_CTX));
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Blake256___del___obj, mod_trezorcrypto_Blake256___del__);

View File

@ -8,6 +8,7 @@
#include "py/objstr.h"
#include "blake2b.h"
#include "memzero.h"
/// class Blake2b:
/// '''
@ -75,7 +76,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Blake2b_digest_obj, mod_trezor
STATIC mp_obj_t mod_trezorcrypto_Blake2b___del__(mp_obj_t self) {
mp_obj_Blake2b_t *o = MP_OBJ_TO_PTR(self);
explicit_bzero(&(o->ctx), sizeof(BLAKE2B_CTX));
memzero(&(o->ctx), sizeof(BLAKE2B_CTX));
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Blake2b___del___obj, mod_trezorcrypto_Blake2b___del__);

View File

@ -8,6 +8,7 @@
#include "py/objstr.h"
#include "blake2s.h"
#include "memzero.h"
/// class Blake2s:
/// '''
@ -75,7 +76,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Blake2s_digest_obj, mod_trezor
STATIC mp_obj_t mod_trezorcrypto_Blake2s___del__(mp_obj_t self) {
mp_obj_Blake2s_t *o = MP_OBJ_TO_PTR(self);
explicit_bzero(&(o->ctx), sizeof(BLAKE2S_CTX));
memzero(&(o->ctx), sizeof(BLAKE2S_CTX));
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Blake2s___del___obj, mod_trezorcrypto_Blake2s___del__);

View File

@ -8,6 +8,7 @@
#include "py/objstr.h"
#include "chacha20poly1305/rfc7539.h"
#include "memzero.h"
/// class ChaCha20Poly1305:
/// '''
@ -105,7 +106,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_ChaCha20Poly1305_finish_obj, m
STATIC mp_obj_t mod_trezorcrypto_ChaCha20Poly1305___del__(mp_obj_t self) {
mp_obj_ChaCha20Poly1305_t *o = MP_OBJ_TO_PTR(self);
explicit_bzero(&(o->ctx), sizeof(chacha20poly1305_ctx));
memzero(&(o->ctx), sizeof(chacha20poly1305_ctx));
o->alen = 0;
o->plen = 0;
return mp_const_none;

View File

@ -8,6 +8,7 @@
#include "py/objstr.h"
#include "pbkdf2.h"
#include "memzero.h"
/// class Pbkdf2:
/// '''
@ -111,8 +112,8 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Pbkdf2_key_obj, mod_trezorcryp
STATIC mp_obj_t mod_trezorcrypto_Pbkdf2___del__(mp_obj_t self) {
mp_obj_Pbkdf2_t *o = MP_OBJ_TO_PTR(self);
explicit_bzero(&(o->ctx256), sizeof(PBKDF2_HMAC_SHA256_CTX));
explicit_bzero(&(o->ctx512), sizeof(PBKDF2_HMAC_SHA512_CTX));
memzero(&(o->ctx256), sizeof(PBKDF2_HMAC_SHA256_CTX));
memzero(&(o->ctx512), sizeof(PBKDF2_HMAC_SHA512_CTX));
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Pbkdf2___del___obj, mod_trezorcrypto_Pbkdf2___del__);

View File

@ -8,6 +8,7 @@
#include "py/objstr.h"
#include "ripemd160.h"
#include "memzero.h"
/// class Ripemd160:
/// '''
@ -68,7 +69,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Ripemd160_digest_obj, mod_trez
STATIC mp_obj_t mod_trezorcrypto_Ripemd160___del__(mp_obj_t self) {
mp_obj_Ripemd160_t *o = MP_OBJ_TO_PTR(self);
explicit_bzero(&(o->ctx), sizeof(RIPEMD160_CTX));
memzero(&(o->ctx), sizeof(RIPEMD160_CTX));
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Ripemd160___del___obj, mod_trezorcrypto_Ripemd160___del__);

View File

@ -8,6 +8,7 @@
#include "py/objstr.h"
#include "sha2.h"
#include "memzero.h"
/// class Sha1:
/// '''
@ -68,7 +69,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Sha1_digest_obj, mod_trezorcry
STATIC mp_obj_t mod_trezorcrypto_Sha1___del__(mp_obj_t self) {
mp_obj_Sha1_t *o = MP_OBJ_TO_PTR(self);
explicit_bzero(&(o->ctx), sizeof(SHA1_CTX));
memzero(&(o->ctx), sizeof(SHA1_CTX));
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Sha1___del___obj, mod_trezorcrypto_Sha1___del__);

View File

@ -8,6 +8,7 @@
#include "py/objstr.h"
#include "sha2.h"
#include "memzero.h"
/// class Sha256:
/// '''
@ -68,7 +69,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Sha256_digest_obj, mod_trezorc
STATIC mp_obj_t mod_trezorcrypto_Sha256___del__(mp_obj_t self) {
mp_obj_Sha256_t *o = MP_OBJ_TO_PTR(self);
explicit_bzero(&(o->ctx), sizeof(SHA256_CTX));
memzero(&(o->ctx), sizeof(SHA256_CTX));
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Sha256___del___obj, mod_trezorcrypto_Sha256___del__);

View File

@ -8,6 +8,7 @@
#include "py/objstr.h"
#include "sha3.h"
#include "memzero.h"
/// class Sha3_256:
/// '''
@ -72,7 +73,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorcrypto_Sha3_256_digest_obj,
STATIC mp_obj_t mod_trezorcrypto_Sha3_256___del__(mp_obj_t self) {
mp_obj_Sha3_256_t *o = MP_OBJ_TO_PTR(self);
explicit_bzero(&(o->ctx), sizeof(SHA3_CTX));
memzero(&(o->ctx), 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__);

View File

@ -8,6 +8,7 @@
#include "py/objstr.h"
#include "sha3.h"
#include "memzero.h"
/// class Sha3_512:
/// '''
@ -72,7 +73,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorcrypto_Sha3_512_digest_obj,
STATIC mp_obj_t mod_trezorcrypto_Sha3_512___del__(mp_obj_t self) {
mp_obj_Sha3_512_t *o = MP_OBJ_TO_PTR(self);
explicit_bzero(&(o->ctx), sizeof(SHA3_CTX));
memzero(&(o->ctx), 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__);

View File

@ -8,6 +8,7 @@
#include "py/objstr.h"
#include "sha2.h"
#include "memzero.h"
/// class Sha512:
/// '''
@ -67,7 +68,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Sha512_digest_obj, mod_trezorc
STATIC mp_obj_t mod_trezorcrypto_Sha512___del__(mp_obj_t self) {
mp_obj_Sha512_t *o = MP_OBJ_TO_PTR(self);
explicit_bzero(&(o->ctx), sizeof(SHA512_CTX));
memzero(&(o->ctx), sizeof(SHA512_CTX));
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorcrypto_Sha512___del___obj, mod_trezorcrypto_Sha512___del__);

@ -1 +1 @@
Subproject commit b7f73ee3ff78e09c266a30dbc31407558d471615
Subproject commit bb4c3d052561bd31856a03d975ca226571f6a893