1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-03-06 02:06:08 +00:00

Use hmac for checking key integrity

This commit is contained in:
Jochen Hoenicke 2016-04-27 12:27:29 +02:00
parent 01ddb3ff66
commit b3bfc64d2f

View File

@ -31,6 +31,7 @@
#include "curves.h" #include "curves.h"
#include "nist256p1.h" #include "nist256p1.h"
#include "rng.h" #include "rng.h"
#include "hmac.h"
#include "u2f/u2f.h" #include "u2f/u2f.h"
#include "u2f/u2f_hid.h" #include "u2f/u2f_hid.h"
@ -467,11 +468,8 @@ const HDNode *generateKeyHandle(const uint8_t app_id[], uint8_t key_handle[])
// Signature of app_id and random data // Signature of app_id and random data
memcpy(&keybase[0], app_id, 32); memcpy(&keybase[0], app_id, 32);
memcpy(&keybase[32], key_handle, 32); memcpy(&keybase[32], key_handle, 32);
uint8_t sig[64]; hmac_sha256(node->private_key, sizeof(node->private_key),
hdnode_sign(node, (uint8_t *)&keybase, sizeof(keybase), sig, NULL); keybase, sizeof(keybase), &key_handle[32]);
// Copy 32 bytes of signature into keyhandle
memcpy(&key_handle[32], sig, 32);
// Done! // Done!
return node; return node;
@ -492,10 +490,11 @@ const HDNode *validateKeyHandle(const uint8_t app_id[], const uint8_t key_handle
memcpy(&keybase[32], key_handle, 32); memcpy(&keybase[32], key_handle, 32);
uint8_t sig[64]; uint8_t hmac[32];
hdnode_sign(node, (uint8_t *)&keybase, sizeof(keybase), sig, NULL); hmac_sha256(node->private_key, sizeof(node->private_key),
keybase, sizeof(keybase), hmac);
if (memcmp(&key_handle[32], sig, 32) !=0) if (memcmp(&key_handle[32], hmac, 32) != 0)
return NULL; return NULL;
// Done! // Done!