1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-29 10:58:21 +00:00

Update trezor-crypto

This commit is contained in:
Saleem Rashid 2017-12-09 18:02:13 +00:00 committed by Pavol Rusnak
parent dc781725c6
commit 268e7de109
5 changed files with 16 additions and 16 deletions

View File

@ -63,7 +63,7 @@ bool coinExtractAddressType(const CoinInfo *coin, const char *addr, uint32_t *ad
{ {
if (!addr) return false; if (!addr) return false;
uint8_t addr_raw[MAX_ADDR_RAW_SIZE]; uint8_t addr_raw[MAX_ADDR_RAW_SIZE];
int len = base58_decode_check(addr, addr_raw, MAX_ADDR_RAW_SIZE); int len = base58_decode_check(addr, coin->hasher_type, addr_raw, MAX_ADDR_RAW_SIZE);
if (len >= 21) { if (len >= 21) {
return coinExtractAddressTypeRaw(coin, addr_raw, address_type); return coinExtractAddressTypeRaw(coin, addr_raw, address_type);
} }

View File

@ -178,8 +178,8 @@ int cryptoMessageVerify(const CoinInfo *coin, const uint8_t *message, size_t mes
// p2pkh // p2pkh
if (signature[0] >= 27 && signature[0] <= 34) { if (signature[0] >= 27 && signature[0] <= 34) {
size_t len = base58_decode_check(address, addr_raw, MAX_ADDR_RAW_SIZE); size_t len = base58_decode_check(address, coin->hasher_type, addr_raw, MAX_ADDR_RAW_SIZE);
ecdsa_get_address_raw(pubkey, coin->address_type, recovered_raw); ecdsa_get_address_raw(pubkey, coin->address_type, coin->hasher_type, recovered_raw);
if (memcmp(recovered_raw, addr_raw, len) != 0 if (memcmp(recovered_raw, addr_raw, len) != 0
|| len != address_prefix_bytes_len(coin->address_type) + 20) { || len != address_prefix_bytes_len(coin->address_type) + 20) {
return 2; return 2;
@ -187,8 +187,8 @@ int cryptoMessageVerify(const CoinInfo *coin, const uint8_t *message, size_t mes
} else } else
// segwit-in-p2sh // segwit-in-p2sh
if (signature[0] >= 35 && signature[0] <= 38) { if (signature[0] >= 35 && signature[0] <= 38) {
size_t len = base58_decode_check(address, addr_raw, MAX_ADDR_RAW_SIZE); size_t len = base58_decode_check(address, coin->hasher_type, addr_raw, MAX_ADDR_RAW_SIZE);
ecdsa_get_address_segwit_p2sh_raw(pubkey, coin->address_type_p2sh, recovered_raw); ecdsa_get_address_segwit_p2sh_raw(pubkey, coin->address_type_p2sh, coin->hasher_type, recovered_raw);
if (memcmp(recovered_raw, addr_raw, len) != 0 if (memcmp(recovered_raw, addr_raw, len) != 0
|| len != address_prefix_bytes_len(coin->address_type_p2sh) + 20) { || len != address_prefix_bytes_len(coin->address_type_p2sh) + 20) {
return 2; return 2;
@ -202,7 +202,7 @@ int cryptoMessageVerify(const CoinInfo *coin, const uint8_t *message, size_t mes
|| !segwit_addr_decode(&witver, recovered_raw, &len, coin->bech32_prefix, address)) { || !segwit_addr_decode(&witver, recovered_raw, &len, coin->bech32_prefix, address)) {
return 4; return 4;
} }
ecdsa_get_pubkeyhash(pubkey, addr_raw); ecdsa_get_pubkeyhash(pubkey, coin->hasher_type, addr_raw);
if (memcmp(recovered_raw, addr_raw, len) != 0 if (memcmp(recovered_raw, addr_raw, len) != 0
|| witver != 0 || len != 20) { || witver != 0 || len != 20) {
return 2; return 2;

View File

@ -424,7 +424,7 @@ bool compile_input_script_sig(TxInputType *tinput)
tinput->script_sig.size = compile_script_multisig(&(tinput->multisig), tinput->script_sig.bytes); tinput->script_sig.size = compile_script_multisig(&(tinput->multisig), tinput->script_sig.bytes);
} else { // SPENDADDRESS } else { // SPENDADDRESS
uint8_t hash[20]; uint8_t hash[20];
ecdsa_get_pubkeyhash(node.public_key, hash); ecdsa_get_pubkeyhash(node.public_key, coin->hasher_type, hash);
tinput->script_sig.size = compile_script_sig(coin->address_type, hash, tinput->script_sig.bytes); tinput->script_sig.size = compile_script_sig(coin->address_type, hash, tinput->script_sig.bytes);
} }
return tinput->script_sig.size > 0; return tinput->script_sig.size > 0;

View File

@ -123,7 +123,7 @@ bool compute_address(const CoinInfo *coin,
prelen = address_prefix_bytes_len(coin->address_type_p2sh); prelen = address_prefix_bytes_len(coin->address_type_p2sh);
address_write_prefix_bytes(coin->address_type_p2sh, raw); address_write_prefix_bytes(coin->address_type_p2sh, raw);
ripemd160(digest, 32, raw + prelen); ripemd160(digest, 32, raw + prelen);
if (!base58_encode_check(raw, prelen + 20, address, MAX_ADDR_SIZE)) { if (!base58_encode_check(raw, prelen + 20, coin->hasher_type, address, MAX_ADDR_SIZE)) {
return 0; return 0;
} }
} else { } else {
@ -131,7 +131,7 @@ bool compute_address(const CoinInfo *coin,
prelen = address_prefix_bytes_len(coin->address_type_p2sh); prelen = address_prefix_bytes_len(coin->address_type_p2sh);
address_write_prefix_bytes(coin->address_type_p2sh, raw); address_write_prefix_bytes(coin->address_type_p2sh, raw);
ripemd160(digest, 32, raw + prelen); ripemd160(digest, 32, raw + prelen);
if (!base58_encode_check(raw, prelen + 20, address, MAX_ADDR_SIZE)) { if (!base58_encode_check(raw, prelen + 20, coin->hasher_type, address, MAX_ADDR_SIZE)) {
return 0; return 0;
} }
} }
@ -140,7 +140,7 @@ bool compute_address(const CoinInfo *coin,
if (!coin->has_segwit || !coin->bech32_prefix) { if (!coin->has_segwit || !coin->bech32_prefix) {
return 0; return 0;
} }
ecdsa_get_pubkeyhash(node->public_key, digest); ecdsa_get_pubkeyhash(node->public_key, coin->hasher_type, digest);
if (!segwit_addr_encode(address, coin->bech32_prefix, SEGWIT_VERSION_0, digest, 20)) { if (!segwit_addr_encode(address, coin->bech32_prefix, SEGWIT_VERSION_0, digest, 20)) {
return 0; return 0;
} }
@ -152,9 +152,9 @@ bool compute_address(const CoinInfo *coin,
if (!coin->has_address_type_p2sh) { if (!coin->has_address_type_p2sh) {
return 0; return 0;
} }
ecdsa_get_address_segwit_p2sh(node->public_key, coin->address_type_p2sh, address, MAX_ADDR_SIZE); ecdsa_get_address_segwit_p2sh(node->public_key, coin->address_type_p2sh, coin->hasher_type, address, MAX_ADDR_SIZE);
} else { } else {
ecdsa_get_address(node->public_key, coin->address_type, address, MAX_ADDR_SIZE); ecdsa_get_address(node->public_key, coin->address_type, coin->hasher_type, address, MAX_ADDR_SIZE);
} }
return 1; return 1;
} }
@ -219,7 +219,7 @@ int compile_output(const CoinInfo *coin, const HDNode *root, TxOutputType *in, T
return 0; // failed to compile output return 0; // failed to compile output
} }
addr_raw_len = base58_decode_check(in->address, addr_raw, MAX_ADDR_RAW_SIZE); addr_raw_len = base58_decode_check(in->address, coin->hasher_type, addr_raw, MAX_ADDR_RAW_SIZE);
size_t prefix_len; size_t prefix_len;
if (coin->has_address_type // p2pkh if (coin->has_address_type // p2pkh
&& address_check_prefix(addr_raw, coin->address_type) && address_check_prefix(addr_raw, coin->address_type)
@ -639,7 +639,7 @@ uint32_t tx_output_weight(const CoinInfo *coin, const TxOutputType *txoutput) {
&& segwit_addr_decode(&witver, addr_raw, &addr_raw_len, coin->bech32_prefix, txoutput->address)) { && segwit_addr_decode(&witver, addr_raw, &addr_raw_len, coin->bech32_prefix, txoutput->address)) {
output_script_size = 2 + addr_raw_len; output_script_size = 2 + addr_raw_len;
} else { } else {
addr_raw_len = base58_decode_check(txoutput->address, addr_raw, MAX_ADDR_RAW_SIZE); addr_raw_len = base58_decode_check(txoutput->address, coin->hasher_type, addr_raw, MAX_ADDR_RAW_SIZE);
if (coin->has_address_type if (coin->has_address_type
&& address_check_prefix(addr_raw, coin->address_type)) { && address_check_prefix(addr_raw, coin->address_type)) {
output_script_size = TXSIZE_P2PKHASH; output_script_size = TXSIZE_P2PKHASH;

View File

@ -613,7 +613,7 @@ void u2f_register(const APDU *a)
memcpy(sig_base.chal, req->chal, U2F_CHAL_SIZE); memcpy(sig_base.chal, req->chal, U2F_CHAL_SIZE);
memcpy(sig_base.keyHandle, &resp->keyHandleCertSig, KEY_HANDLE_LEN); memcpy(sig_base.keyHandle, &resp->keyHandleCertSig, KEY_HANDLE_LEN);
memcpy(sig_base.pubKey, &resp->pubKey, U2F_PUBKEY_LEN); memcpy(sig_base.pubKey, &resp->pubKey, U2F_PUBKEY_LEN);
if (ecdsa_sign(&nist256p1, U2F_ATT_PRIV_KEY, (uint8_t *)&sig_base, sizeof(sig_base), sig, NULL, NULL) != 0) { if (ecdsa_sign(&nist256p1, HASHER_SHA2, U2F_ATT_PRIV_KEY, (uint8_t *)&sig_base, sizeof(sig_base), sig, NULL, NULL) != 0) {
send_u2f_error(U2F_SW_WRONG_DATA); send_u2f_error(U2F_SW_WRONG_DATA);
return; return;
} }
@ -735,7 +735,7 @@ void u2f_authenticate(const APDU *a)
sig_base.flags = resp->flags; sig_base.flags = resp->flags;
memcpy(sig_base.ctr, resp->ctr, 4); memcpy(sig_base.ctr, resp->ctr, 4);
memcpy(sig_base.chal, req->chal, U2F_CHAL_SIZE); memcpy(sig_base.chal, req->chal, U2F_CHAL_SIZE);
if (ecdsa_sign(&nist256p1, node->private_key, (uint8_t *)&sig_base, sizeof(sig_base), sig, NULL, NULL) != 0) { if (ecdsa_sign(&nist256p1, HASHER_SHA2, node->private_key, (uint8_t *)&sig_base, sizeof(sig_base), sig, NULL, NULL) != 0) {
send_u2f_error(U2F_SW_WRONG_DATA); send_u2f_error(U2F_SW_WRONG_DATA);
return; return;
} }