Fix deprecated warnings

This commit is contained in:
Charles-Edouard de la Vergne
2024-03-18 08:58:05 +01:00
parent 6e872b45cc
commit 36ae183a1c
36 changed files with 361 additions and 473 deletions

View File

@@ -44,6 +44,7 @@
#define APDU_RESPONSE_INVALID_P1_P2 0x6b00
#define APDU_RESPONSE_CONDITION_NOT_SATISFIED 0x6985
#define APDU_RESPONSE_REF_DATA_NOT_FOUND 0x6a88
#define APDU_RESPONSE_UNKNOWN 0x6f00
enum { OFFSET_CLA = 0, OFFSET_INS, OFFSET_P1, OFFSET_P2, OFFSET_LC, OFFSET_CDATA };

View File

@@ -36,7 +36,7 @@ void initTx(txContext_t *context,
context->customProcessor = customProcessor;
context->extra = extra;
context->currentField = RLP_NONE + 1;
cx_keccak_init(context->sha3, 256);
CX_ASSERT(cx_keccak_init_no_throw(context->sha3, 256));
}
uint8_t readTxByte(txContext_t *context) {
@@ -52,7 +52,7 @@ uint8_t readTxByte(txContext_t *context) {
context->currentFieldPos++;
}
if (!(context->processingField && context->fieldSingleByte)) {
cx_hash((cx_hash_t *) context->sha3, 0, &data, 1, NULL, 0);
CX_ASSERT(cx_hash_no_throw((cx_hash_t *) context->sha3, 0, &data, 1, NULL, 0));
}
return data;
}
@@ -66,7 +66,8 @@ void copyTxData(txContext_t *context, uint8_t *out, uint32_t length) {
memmove(out, context->workBuffer, length);
}
if (!(context->processingField && context->fieldSingleByte)) {
cx_hash((cx_hash_t *) context->sha3, 0, context->workBuffer, length, NULL, 0);
CX_ASSERT(
cx_hash_no_throw((cx_hash_t *) context->sha3, 0, context->workBuffer, length, NULL, 0));
}
context->workBuffer += length;
context->commandLength -= length;

View File

@@ -1,7 +1,9 @@
#include "handle_check_address.h"
#include "apdu_constants.h"
#include "os.h"
#include "shared_context.h"
#include "string.h"
#include "lib_standard_app/crypto_helpers.h"
#define ZERO(x) explicit_bzero(&x, sizeof(x))
@@ -17,18 +19,9 @@ void handle_check_address(check_address_parameters_t* params, chain_config_t* ch
const uint8_t* bip32_path_ptr = params->address_parameters;
uint8_t bip32PathLength = *(bip32_path_ptr++);
cx_sha3_t local_sha3;
// Common memory is used for locals that are not used concurrently
union group1 {
uint32_t bip32Path[MAX_BIP32_PATH];
cx_ecfp_private_key_t privateKey;
char address[51];
} locals_union1;
union group2 {
uint8_t privateKeyData[64];
cx_ecfp_public_key_t publicKey;
} locals_union2;
uint32_t bip32Path[MAX_BIP32_PATH];
char address[51];
uint8_t raw_pubkey[65];
if ((bip32PathLength < 0x01) || (bip32PathLength > MAX_BIP32_PATH) ||
(bip32PathLength * 4 != params->address_parameters_length - 1)) {
@@ -36,58 +29,30 @@ void handle_check_address(check_address_parameters_t* params, chain_config_t* ch
return;
}
for (uint8_t i = 0; i < bip32PathLength; i++) {
locals_union1.bip32Path[i] = U4BE(bip32_path_ptr, 0);
bip32Path[i] = U4BE(bip32_path_ptr, 0);
bip32_path_ptr += 4;
}
if (os_derive_bip32_no_throw(CX_CURVE_256K1,
locals_union1.bip32Path,
bip32PathLength,
locals_union2.privateKeyData,
NULL) != CX_OK) {
ZERO(locals_union1);
ZERO(locals_union2);
return;
if (bip32_derive_get_pubkey_256(CX_CURVE_256K1,
bip32Path,
bip32PathLength,
raw_pubkey,
NULL,
CX_SHA512) != CX_OK) {
THROW(APDU_RESPONSE_UNKNOWN);
}
ZERO(locals_union1);
if (cx_ecfp_init_private_key_no_throw(CX_CURVE_256K1,
locals_union2.privateKeyData,
32,
&locals_union1.privateKey) != CX_OK) {
ZERO(locals_union1);
ZERO(locals_union2);
return;
}
ZERO(locals_union2);
if (cx_ecfp_generate_pair_no_throw(CX_CURVE_256K1,
&locals_union2.publicKey,
&locals_union1.privateKey,
1) != CX_OK) {
ZERO(locals_union1);
ZERO(locals_union2);
return;
}
ZERO(locals_union1);
if (!getEthAddressStringFromKey(&locals_union2.publicKey,
locals_union1.address,
&local_sha3,
chain_config->chainId)) {
ZERO(locals_union1);
ZERO(locals_union2);
return;
}
ZERO(locals_union2);
getEthAddressStringFromRawKey((const uint8_t*) raw_pubkey, address, chain_config->chainId);
uint8_t offset_0x = 0;
if (memcmp(params->address_to_check, "0x", 2) == 0) {
offset_0x = 2;
}
if (strcmp(locals_union1.address, params->address_to_check + offset_0x) != 0) {
if (strcmp(address, params->address_to_check + offset_0x) != 0) {
PRINTF("Addresses don't match\n");
} else {
PRINTF("Addresses match\n");
params->result = 1;
}
ZERO(locals_union1);
}

View File

@@ -113,4 +113,6 @@ void __attribute__((noreturn)) handle_swap_sign_transaction(chain_config_t* conf
BLE_power(1, NULL);
#endif // HAVE_BLE
app_main();
// Failsafe
os_sched_exit(-1);
}

View File

@@ -8,7 +8,7 @@
* @param[in] hash_ctx pointer to the hashing context
*/
void hash_nbytes(const uint8_t *bytes_ptr, size_t n, cx_hash_t *hash_ctx) {
cx_hash(hash_ctx, 0, bytes_ptr, n, NULL, 0);
CX_ASSERT(cx_hash_no_throw(hash_ctx, 0, bytes_ptr, n, NULL, 0));
}
/**

View File

@@ -31,6 +31,7 @@
#include "commands_712.h"
#include "challenge.h"
#include "domain_name.h"
#include "lib_standard_app/crypto_helpers.h"
unsigned char G_io_seproxyhal_spi_buffer[IO_SEPROXYHAL_BUFFER_SIZE_B];
@@ -88,28 +89,6 @@ void io_seproxyhal_send_status(uint32_t sw) {
io_exchange(CHANNEL_APDU | IO_RETURN_AFTER_TX, 2);
}
void format_signature_out(const uint8_t *signature) {
memset(G_io_apdu_buffer + 1, 0x00, 64);
uint8_t offset = 1;
uint8_t xoffset = 4; // point to r value
// copy r
uint8_t xlength = signature[xoffset - 1];
if (xlength == 33) {
xlength = 32;
xoffset++;
}
memmove(G_io_apdu_buffer + offset + 32 - xlength, signature + xoffset, xlength);
offset += 32;
xoffset += xlength + 2; // move over rvalue and TagLEn
// copy s value
xlength = signature[xoffset - 1];
if (xlength == 33) {
xlength = 32;
xoffset++;
}
memmove(G_io_apdu_buffer + offset + 32 - xlength, signature + xoffset, xlength);
}
unsigned short io_exchange_al(unsigned char channel, unsigned short tx_len) {
switch (channel & ~(IO_FLAGS)) {
case CHANNEL_KEYBOARD:
@@ -162,11 +141,17 @@ void handleGetWalletId(volatile unsigned int *tx) {
unsigned char t[64];
cx_ecfp_256_private_key_t priv;
cx_ecfp_256_public_key_t pub;
// seed => priv key
os_perso_derive_node_bip32(CX_CURVE_256K1, U_os_perso_seed_cookie, 2, t, NULL);
// seed => pubkey
CX_ASSERT(bip32_derive_with_seed_init_privkey_256(HDW_NORMAL,
CX_CURVE_256K1,
U_os_perso_seed_cookie,
2,
&priv,
NULL,
NULL,
0));
// priv key => pubkey
cx_ecdsa_init_private_key(CX_CURVE_256K1, t, 32, &priv);
cx_ecfp_generate_pair(CX_CURVE_256K1, &pub, &priv, 1);
CX_ASSERT(cx_ecfp_generate_pair_no_throw(CX_CURVE_256K1, &pub, &priv, 1));
// pubkey -> sha512
cx_hash_sha512(pub.W, sizeof(pub.W), t, sizeof(t));
// ! cookie !
@@ -508,9 +493,6 @@ void app_main(void) {
}
END_TRY;
}
// return_to_dashboard:
return;
}
// override point, but nothing more to do

View File

@@ -53,7 +53,6 @@ bool parse_swap_config(const uint8_t *config,
if ((config_len - offset) >= sizeof(*chain_id)) {
PRINTF("Chain ID from the swap subconfig = 0x%.*h\n", sizeof(*chain_id), &config[offset]);
*chain_id = u64_from_BE(config + offset, sizeof(*chain_id));
offset += sizeof(*chain_id);
}
return true;
}

View File

@@ -25,7 +25,6 @@ unsigned int io_seproxyhal_touch_privacy_cancel(const bagl_element_t *e);
void ui_warning_contract_data(void);
void io_seproxyhal_send_status(uint32_t sw);
void format_signature_out(const uint8_t *signature);
void finalizeParsing(bool direct);
extraInfo_t *getKnownToken(uint8_t *contractAddress);

View File

@@ -175,7 +175,7 @@ void mul256(const uint256_t *const number1,
write_u64_be(num1 + i * sizeof(uint64_t), number1->elements[i / 2].elements[i % 2]);
write_u64_be(num2 + i * sizeof(uint64_t), number2->elements[i / 2].elements[i % 2]);
}
cx_math_mult(result, num1, num2, sizeof(num1));
CX_ASSERT(cx_math_mult_no_throw(result, num1, num2, sizeof(num1)));
for (uint8_t i = 0; i < 4; i++) {
read_u64_be(result + 32 + i * sizeof(uint64_t), &target->elements[i / 2].elements[i % 2]);
}