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

simplify cryptoMessageVerify call

This commit is contained in:
Pavol Rusnak 2016-10-10 00:18:57 +02:00
parent 6bfe487f19
commit 3a42032c63
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
3 changed files with 6 additions and 8 deletions

View File

@ -141,7 +141,7 @@ int cryptoMessageSign(const CoinType *coin, HDNode *node, const uint8_t *message
return result;
}
int cryptoMessageVerify(const CoinType *coin, const uint8_t *message, size_t message_len, uint32_t address_type, const uint8_t *address_raw, const uint8_t *signature)
int cryptoMessageVerify(const CoinType *coin, const uint8_t *message, size_t message_len, const uint8_t *address_raw, const uint8_t *signature)
{
SHA256_CTX ctx;
uint8_t pubkey[65], addr_raw[MAX_ADDR_RAW_SIZE], hash[32];
@ -172,8 +172,8 @@ int cryptoMessageVerify(const CoinType *coin, const uint8_t *message, size_t mes
pubkey[0] = 0x02 | (pubkey[64] & 1);
}
// check if the address is correct
ecdsa_get_address_raw(pubkey, address_type, addr_raw);
if (memcmp(addr_raw, address_raw, prefixBytesByAddressType(address_type) + 20) != 0) {
ecdsa_get_address_raw(pubkey, coin->address_type, addr_raw);
if (memcmp(addr_raw, address_raw, prefixBytesByAddressType(coin->address_type) + 20) != 0) {
return 2;
}
return 0;

View File

@ -39,10 +39,9 @@ int gpgMessageSign(HDNode *node, const uint8_t *message, size_t message_len, uin
int cryptoGetECDHSessionKey(const HDNode *node, const uint8_t *peer_public_key, uint8_t *session_key);
int cryptoMessageSign(const CoinType *coin, HDNode *node, const uint8_t *message, size_t message_len, uint8_t *signature);
int cryptoMessageVerify(const CoinType *coin, const uint8_t *message, size_t message_len, uint32_t address_type, const uint8_t *address_raw, const uint8_t *signature);
int cryptoMessageVerify(const CoinType *coin, const uint8_t *message, size_t message_len, const uint8_t *address_raw, const uint8_t *signature);
/* ECIES disabled
int cryptoMessageEncrypt(curve_point *pubkey, const uint8_t *msg, size_t msg_size, bool display_only, uint8_t *nonce, size_t *nonce_len, uint8_t *payload, size_t *payload_len, uint8_t *hmac, size_t *hmac_len, const uint8_t *privkey, const uint8_t *address_raw);

View File

@ -756,12 +756,11 @@ void fsm_msgVerifyMessage(VerifyMessage *msg)
if (!coin) return;
layoutProgressSwipe("Verifying", 0);
uint8_t addr_raw[MAX_ADDR_RAW_SIZE];
uint32_t address_type;
if (!getAddressType(coin, (const uint8_t *) msg->address, &address_type) || !ecdsa_address_decode(msg->address, address_type, addr_raw)) {
if (!ecdsa_address_decode(msg->address, coin->address_type, addr_raw)) {
fsm_sendFailure(FailureType_Failure_InvalidSignature, "Invalid address");
return;
}
if (msg->signature.size == 65 && cryptoMessageVerify(coin, msg->message.bytes, msg->message.size, address_type, addr_raw, msg->signature.bytes) == 0) {
if (msg->signature.size == 65 && cryptoMessageVerify(coin, msg->message.bytes, msg->message.size, addr_raw, msg->signature.bytes) == 0) {
layoutVerifyAddress(msg->address);
if (!protectButton(ButtonRequestType_ButtonRequest_Other, false)) {
fsm_sendFailure(FailureType_Failure_ActionCancelled, "Message verification cancelled");