1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-30 03:18:20 +00:00

Remove the public_key hack.

It is no longer necessary to move the public key into a temporary buffer
since the node is specific for the curve and contains the right public
key.
This commit is contained in:
Jochen Hoenicke 2016-04-21 07:29:20 +02:00
parent 4a3a0b83dd
commit 6813ffb431
No known key found for this signature in database
GPG Key ID: EB17C6B5E51193F5
2 changed files with 6 additions and 12 deletions

View File

@ -97,7 +97,7 @@ const HDNode *fsm_getDerivedNode(const char *curve, uint32_t *address_n, size_t
{ {
static HDNode node; static HDNode node;
if (!storage_getRootNode(&node, curve)) { if (!storage_getRootNode(&node, curve)) {
fsm_sendFailure(FailureType_Failure_NotInitialized, "Device not initialized or passphrase request cancelled"); fsm_sendFailure(FailureType_Failure_NotInitialized, "Device not initialized or passphrase request cancelled or unsupported curve");
layoutHome(); layoutHome();
return 0; return 0;
} }
@ -299,11 +299,8 @@ void fsm_msgGetPublicKey(GetPublicKey *msg)
const HDNode *node = fsm_getDerivedNode(curve, msg->address_n, msg->address_n_count); const HDNode *node = fsm_getDerivedNode(curve, msg->address_n, msg->address_n_count);
if (!node) return; if (!node) return;
uint8_t public_key[33]; // copy public key to temporary buffer
memcpy(public_key, node->public_key, sizeof(public_key));
if (msg->has_show_display && msg->show_display) { if (msg->has_show_display && msg->show_display) {
layoutPublicKey(public_key); layoutPublicKey(node->public_key);
if (!protectButton(ButtonRequestType_ButtonRequest_PublicKey, true)) { if (!protectButton(ButtonRequestType_ButtonRequest_PublicKey, true)) {
fsm_sendFailure(FailureType_Failure_ActionCancelled, "Show public key cancelled"); fsm_sendFailure(FailureType_Failure_ActionCancelled, "Show public key cancelled");
layoutHome(); layoutHome();
@ -319,7 +316,7 @@ void fsm_msgGetPublicKey(GetPublicKey *msg)
resp->node.has_private_key = false; resp->node.has_private_key = false;
resp->node.has_public_key = true; resp->node.has_public_key = true;
resp->node.public_key.size = 33; resp->node.public_key.size = 33;
memcpy(resp->node.public_key.bytes, public_key, 33); memcpy(resp->node.public_key.bytes, node->public_key, 33);
resp->has_xpub = true; resp->has_xpub = true;
hdnode_serialize_public(node, resp->xpub, sizeof(resp->xpub)); hdnode_serialize_public(node, resp->xpub, sizeof(resp->xpub));
msg_write(MessageType_MessageType_PublicKey, resp); msg_write(MessageType_MessageType_PublicKey, resp);
@ -727,9 +724,6 @@ void fsm_msgSignIdentity(SignIdentity *msg)
const HDNode *node = fsm_getDerivedNode(curve, address_n, 5); const HDNode *node = fsm_getDerivedNode(curve, address_n, 5);
if (!node) return; if (!node) return;
uint8_t public_key[33]; // copy public key to temporary buffer
memcpy(public_key, node->public_key, sizeof(public_key));
bool sign_ssh = msg->identity.has_proto && (strcmp(msg->identity.proto, "ssh") == 0); bool sign_ssh = msg->identity.has_proto && (strcmp(msg->identity.proto, "ssh") == 0);
bool sign_gpg = msg->identity.has_proto && (strcmp(msg->identity.proto, "gpg") == 0); bool sign_gpg = msg->identity.has_proto && (strcmp(msg->identity.proto, "gpg") == 0);
@ -747,7 +741,7 @@ void fsm_msgSignIdentity(SignIdentity *msg)
} }
if (result == 0) { if (result == 0) {
if (curve != SECP256K1_NAME) { if (strcmp(curve, SECP256K1_NAME) != 0) {
resp->has_address = false; resp->has_address = false;
} else { } else {
resp->has_address = true; resp->has_address = true;
@ -757,7 +751,7 @@ void fsm_msgSignIdentity(SignIdentity *msg)
} }
resp->has_public_key = true; resp->has_public_key = true;
resp->public_key.size = 33; resp->public_key.size = 33;
memcpy(resp->public_key.bytes, public_key, 33); memcpy(resp->public_key.bytes, node->public_key, 33);
resp->has_signature = true; resp->has_signature = true;
resp->signature.size = 65; resp->signature.size = 65;
msg_write(MessageType_MessageType_SignedIdentity, resp); msg_write(MessageType_MessageType_SignedIdentity, resp);

@ -1 +1 @@
Subproject commit bf34b4269ccb9ab929625506a5370ea9c8382139 Subproject commit de30ffbf9a68bfd6f2fb3633f855998c8e375628