1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-01-22 05:10:56 +00:00

fix pbkdf2.key() method

This commit is contained in:
Pavol Rusnak 2016-10-07 13:41:25 +02:00
parent 446ea33dc1
commit 2bba78bf87
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D

View File

@ -87,12 +87,18 @@ STATIC mp_obj_t mod_TrezorCrypto_Pbkdf2_key(mp_obj_t self) {
mp_obj_Pbkdf2_t *o = MP_OBJ_TO_PTR(self);
vstr_t vstr;
if (o->prf == 256) {
PBKDF2_HMAC_SHA256_CTX ctx;
memcpy(&ctx, &(o->ctx256), sizeof(PBKDF2_HMAC_SHA256_CTX));
vstr_init_len(&vstr, SHA256_DIGEST_LENGTH);
memcpy(vstr.buf, o->ctx256.f, SHA256_DIGEST_LENGTH);
pbkdf2_hmac_sha256_Final(&ctx, (uint8_t *)vstr.buf);
memset(&ctx, 0, sizeof(PBKDF2_HMAC_SHA256_CTX));
}
if (o->prf == 512) {
PBKDF2_HMAC_SHA512_CTX ctx;
memcpy(&ctx, &(o->ctx512), sizeof(PBKDF2_HMAC_SHA512_CTX));
vstr_init_len(&vstr, SHA512_DIGEST_LENGTH);
memcpy(vstr.buf, o->ctx512.f, SHA512_DIGEST_LENGTH);
pbkdf2_hmac_sha512_Final(&ctx, (uint8_t *)vstr.buf);
memset(&ctx, 0, sizeof(PBKDF2_HMAC_SHA512_CTX));
}
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
}