Cleanup os_mem* functions

This commit is contained in:
BTChip github
2020-11-24 10:23:45 +01:00
committed by TamtamHero
parent 374580431d
commit d43f7f6698
22 changed files with 55 additions and 55 deletions

View File

@@ -72,7 +72,7 @@ CONTRACT_STARKWARE_DEPOSIT_TOKEN
```C
if ((context->currentFieldLength == STARKWARE_DEPOSIT_TOKEN_DATA_SIZE) &&
(os_memcmp(context->workBuffer, STARKWARE_DEPOSIT_TOKEN_ID, 4) == 0) &&
(memcmp(context->workBuffer, STARKWARE_DEPOSIT_TOKEN_ID, 4) == 0) &&
quantumSet) {
contractProvisioned = CONTRACT_STARKWARE_DEPOSIT_TOKEN;
}

View File

@@ -4,7 +4,7 @@
#include "ethUtils.h"
#include "string.h"
#define ZERO(x) os_memset(x, 0, sizeof(x))
#define ZERO(x) memset(x, 0, sizeof(x))
void handle_check_address(check_address_parameters_t* params, chain_config_t* chain_config) {
PRINTF("Params on the address %d\n",(unsigned int)params);
@@ -60,10 +60,10 @@ void handle_check_address(check_address_parameters_t* params, chain_config_t* ch
}
if ((strlen(locals_union1.address) != strlen(params->address_to_check + offset_0x)) ||
os_memcmp(locals_union1.address, params->address_to_check + offset_0x, strlen(locals_union1.address)) != 0) {
memcmp(locals_union1.address, params->address_to_check + offset_0x, strlen(locals_union1.address)) != 0) {
PRINTF("Addresses doesn't match\n");
return;
}
PRINTF("Addresses match\n");
params->result = 1;
}
}

View File

@@ -10,7 +10,7 @@
void handle_get_printable_amount( get_printable_amount_parameters_t* params, chain_config_t *config) {
uint8_t decimals;
char ticker[MAX_TICKER_LEN];
os_memset(params->printable_amount, 0, sizeof(params->printable_amount));
memset(params->printable_amount, 0, sizeof(params->printable_amount));
if (params->amount_length > 32) {
PRINTF("Amount is too big, 32 bytes max but buffer has %u bytes", params->amount_length);
os_lib_end();
@@ -30,4 +30,4 @@ void handle_get_printable_amount( get_printable_amount_parameters_t* params, cha
}
amountToString(params->amount, params->amount_length, decimals, ticker, params->printable_amount, sizeof(params->printable_amount));
}
}

View File

@@ -69,7 +69,7 @@ chain_config_t *chainConfig;
void reset_app_context() {
//PRINTF("!!RESET_APP_CONTEXT\n");
appState = APP_STATE_IDLE;
os_memset(tmpCtx.transactionContext.tokenSet, 0, MAX_TOKEN);
memset(tmpCtx.transactionContext.tokenSet, 0, MAX_TOKEN);
called_from_swap = false;
#ifdef HAVE_STARKWARE
quantumSet = false;
@@ -77,8 +77,8 @@ void reset_app_context() {
#ifdef HAVE_ETH2
eth2WithdrawalIndex = 0;
#endif
os_memset((uint8_t*)&txContext, 0, sizeof(txContext));
os_memset((uint8_t*)&tmpContent, 0, sizeof(tmpContent));
memset((uint8_t*)&txContext, 0, sizeof(txContext));
memset((uint8_t*)&tmpContent, 0, sizeof(tmpContent));
}
void ui_idle(void) {
@@ -118,7 +118,7 @@ void io_seproxyhal_send_status(uint32_t sw) {
}
void format_signature_out(const uint8_t* signature) {
os_memset(G_io_apdu_buffer + 1, 0x00, 64);
memset(G_io_apdu_buffer + 1, 0x00, 64);
uint8_t offset = 1;
uint8_t xoffset = 4; //point to r value
//copy r
@@ -355,14 +355,14 @@ tokenDefinition_t* getKnownToken(uint8_t *contractAddress) {
currentToken = (tokenDefinition_t *)PIC(&TOKENS_THUNDERCORE[i]);
break
}
if (os_memcmp(currentToken->address, tmpContent.txContent.destination, 20) == 0) {
if (memcmp(currentToken->address, tmpContent.txContent.destination, 20) == 0) {
return currentToken;
}
}
#endif
for(size_t i=0; i<MAX_TOKEN; i++){
currentToken = &tmpCtx.transactionContext.tokens[i];
if (tmpCtx.transactionContext.tokenSet[i] && (os_memcmp(currentToken->address, contractAddress, 20) == 0)) {
if (tmpCtx.transactionContext.tokenSet[i] && (memcmp(currentToken->address, contractAddress, 20) == 0)) {
PRINTF("Token found at index %d\n", i);
return currentToken;
}
@@ -409,7 +409,7 @@ void handleApdu(unsigned int *flags, unsigned int *tx) {
switch (G_io_apdu_buffer[OFFSET_INS]) {
case INS_GET_PUBLIC_KEY:
os_memset(tmpCtx.transactionContext.tokenSet, 0, MAX_TOKEN);
memset(tmpCtx.transactionContext.tokenSet, 0, MAX_TOKEN);
handleGetPublicKey(G_io_apdu_buffer[OFFSET_P1], G_io_apdu_buffer[OFFSET_P2], G_io_apdu_buffer + OFFSET_CDATA, G_io_apdu_buffer[OFFSET_LC], flags, tx);
break;
@@ -426,19 +426,19 @@ void handleApdu(unsigned int *flags, unsigned int *tx) {
break;
case INS_SIGN_PERSONAL_MESSAGE:
os_memset(tmpCtx.transactionContext.tokenSet, 0, MAX_TOKEN);
memset(tmpCtx.transactionContext.tokenSet, 0, MAX_TOKEN);
handleSignPersonalMessage(G_io_apdu_buffer[OFFSET_P1], G_io_apdu_buffer[OFFSET_P2], G_io_apdu_buffer + OFFSET_CDATA, G_io_apdu_buffer[OFFSET_LC], flags, tx);
break;
case INS_SIGN_EIP_712_MESSAGE:
os_memset(tmpCtx.transactionContext.tokenSet, 0, MAX_TOKEN);
memset(tmpCtx.transactionContext.tokenSet, 0, MAX_TOKEN);
handleSignEIP712Message(G_io_apdu_buffer[OFFSET_P1], G_io_apdu_buffer[OFFSET_P2], G_io_apdu_buffer + OFFSET_CDATA, G_io_apdu_buffer[OFFSET_LC], flags, tx);
break;
#ifdef HAVE_ETH2
case INS_GET_ETH2_PUBLIC_KEY:
os_memset(tmpCtx.transactionContext.tokenSet, 0, MAX_TOKEN);
memset(tmpCtx.transactionContext.tokenSet, 0, MAX_TOKEN);
handleGetEth2PublicKey(G_io_apdu_buffer[OFFSET_P1], G_io_apdu_buffer[OFFSET_P2], G_io_apdu_buffer + OFFSET_CDATA, G_io_apdu_buffer[OFFSET_LC], flags, tx);
break;
@@ -678,7 +678,7 @@ void coin_main_with_config(chain_config_t *config) {
}
void init_coin_config(chain_config_t *coin_config) {
os_memset(coin_config, 0, sizeof(chain_config_t));
memset(coin_config, 0, sizeof(chain_config_t));
strcpy(coin_config->coinName, CHAINID_COINNAME " ");
coin_config->chainId = CHAIN_ID;
coin_config->kind = CHAIN_KIND;

View File

@@ -3,7 +3,7 @@
#include "poorstream.h"
void poorstream_init(poorstream_t *stream, uint8_t *buffer) {
os_memset((void*)stream, 0, sizeof(poorstream_t));
memset((void*)stream, 0, sizeof(poorstream_t));
stream->pointer = buffer;
}

View File

@@ -37,8 +37,8 @@ void array_hexstr(char *strbuf, const void *bin, unsigned int len) {
void convertUint256BE(uint8_t *data, uint32_t length, uint256_t *target) {
uint8_t tmp[32];
os_memset(tmp, 0, 32);
os_memmove(tmp + 32 - length, data, length);
memset(tmp, 0, 32);
memmove(tmp + 32 - length, data, length);
readu256BE(tmp, target);
}
@@ -113,4 +113,4 @@ bool parse_swap_config(uint8_t* config, uint8_t config_len, char* ticker, uint8_
}
*decimals = config[offset];
return true;
}
}

View File

@@ -26,7 +26,7 @@
void initTx(txContext_t *context, cx_sha3_t *sha3, txContent_t *content,
ustreamProcess_t customProcessor, void *extra) {
os_memset(context, 0, sizeof(txContext_t));
memset(context, 0, sizeof(txContext_t));
context->sha3 = sha3;
context->content = content;
context->customProcessor = customProcessor;
@@ -59,7 +59,7 @@ void copyTxData(txContext_t *context, uint8_t *out, uint32_t length) {
THROW(EXCEPTION);
}
if (out != NULL) {
os_memmove(out, context->workBuffer, length);
memmove(out, context->workBuffer, length);
}
if (!(context->processingField && context->fieldSingleByte)) {
cx_hash((cx_hash_t*)context->sha3, 0, context->workBuffer, length, NULL, 0);

View File

@@ -123,7 +123,7 @@ void getEthAddressFromKey(cx_ecfp_public_key_t *publicKey, uint8_t *out,
uint8_t hashAddress[32];
cx_keccak_init(sha3Context, 256);
cx_hash((cx_hash_t*)sha3Context, CX_LAST, publicKey->W + 1, 64, hashAddress, 32);
os_memmove(out, hashAddress + 12, 20);
memmove(out, hashAddress + 12, 20);
}

View File

@@ -350,7 +350,7 @@ void read_u64_be(uint8_t *in, uint64_t *out) {
void mul256(uint256_t *number1, uint256_t *number2, uint256_t *target) {
uint8_t num1[32], num2[32], result[64];
os_memset(&result, 0, sizeof(result));
memset(&result, 0, sizeof(result));
for(uint8_t i = 0; i<4; i++){
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]);

View File

@@ -4,7 +4,7 @@
uint32_t set_result_get_eth2_publicKey() {
uint32_t tx = 0;
os_memmove(G_io_apdu_buffer + tx, tmpCtx.publicKeyContext.publicKey.W, 48);
memmove(G_io_apdu_buffer + tx, tmpCtx.publicKeyContext.publicKey.W, 48);
tx += 48;
return tx;
}

View File

@@ -35,8 +35,8 @@ void handleGetPublicKey(uint8_t p1, uint8_t p2, uint8_t *dataBuffer, uint16_t da
cx_ecfp_init_private_key(CX_CURVE_256K1, privateKeyData, 32, &privateKey);
io_seproxyhal_io_heartbeat();
cx_ecfp_generate_pair(CX_CURVE_256K1, &tmpCtx.publicKeyContext.publicKey, &privateKey, 1);
os_memset(&privateKey, 0, sizeof(privateKey));
os_memset(privateKeyData, 0, sizeof(privateKeyData));
memset(&privateKey, 0, sizeof(privateKey));
memset(privateKeyData, 0, sizeof(privateKeyData));
io_seproxyhal_io_heartbeat();
getEthAddressStringFromKey(&tmpCtx.publicKeyContext.publicKey, tmpCtx.publicKeyContext.address, &global_sha3, chainConfig);
#ifndef NO_CONSENT

View File

@@ -3,13 +3,13 @@
uint32_t set_result_get_publicKey() {
uint32_t tx = 0;
G_io_apdu_buffer[tx++] = 65;
os_memmove(G_io_apdu_buffer + tx, tmpCtx.publicKeyContext.publicKey.W, 65);
memmove(G_io_apdu_buffer + tx, tmpCtx.publicKeyContext.publicKey.W, 65);
tx += 65;
G_io_apdu_buffer[tx++] = 40;
os_memmove(G_io_apdu_buffer + tx, tmpCtx.publicKeyContext.address, 40);
memmove(G_io_apdu_buffer + tx, tmpCtx.publicKeyContext.address, 40);
tx += 40;
if (tmpCtx.publicKeyContext.getChaincode) {
os_memmove(G_io_apdu_buffer + tx, tmpCtx.publicKeyContext.chainCode, 32);
memmove(G_io_apdu_buffer + tx, tmpCtx.publicKeyContext.chainCode, 32);
tx += 32;
}
return tx;

View File

@@ -47,7 +47,7 @@ void handleProvideErc20TokenInformation(uint8_t p1, uint8_t p2, uint8_t *workBuf
THROW(0x6A80);
}
cx_hash((cx_hash_t*)&sha256, 0, workBuffer + offset, tickerLength, NULL, 0);
os_memmove(token->ticker, workBuffer + offset, tickerLength);
memmove(token->ticker, workBuffer + offset, tickerLength);
token->ticker[tickerLength] = ' ';
token->ticker[tickerLength + 1] = '\0';
offset += tickerLength;
@@ -59,12 +59,12 @@ void handleProvideErc20TokenInformation(uint8_t p1, uint8_t p2, uint8_t *workBuf
THROW(0x6A80);
}
cx_hash((cx_hash_t*)&sha256, CX_LAST, workBuffer + offset, contractNameLength + 20 + 4 + 4, hash, 32);
os_memmove(token->contractName, workBuffer + offset, MIN(contractNameLength, sizeof(token->contractName)-1));
memmove(token->contractName, workBuffer + offset, MIN(contractNameLength, sizeof(token->contractName)-1));
token->contractName[MIN(contractNameLength, sizeof(token->contractName)-1)] = '\0';
offset += contractNameLength;
dataLength -= contractNameLength;
os_memmove(token->address, workBuffer + offset, 20);
memmove(token->address, workBuffer + offset, 20);
offset += 20;
dataLength -= 20;
token->decimals = U4BE(workBuffer, offset);
@@ -116,12 +116,12 @@ void handleProvideErc20TokenInformation(uint8_t p1, uint8_t p2, uint8_t *workBuf
THROW(0x6A80);
}
cx_hash_sha256(workBuffer + offset, tickerLength + 20 + 4 + 4, hash, 32);
os_memmove(token->ticker, workBuffer + offset, tickerLength);
memmove(token->ticker, workBuffer + offset, tickerLength);
token->ticker[tickerLength] = ' ';
token->ticker[tickerLength + 1] = '\0';
offset += tickerLength;
dataLength -= tickerLength;
os_memmove(token->address, workBuffer + offset, 20);
memmove(token->address, workBuffer + offset, 20);
offset += 20;
dataLength -= 20;
token->decimals = U4BE(workBuffer, offset);
@@ -140,7 +140,7 @@ void handleProvideErc20TokenInformation(uint8_t p1, uint8_t p2, uint8_t *workBuf
uint32_t index;
for (index=0; index < NUM_TOKENS_EXTRA; index++) {
currentToken = (tokenDefinition_t *)PIC(&TOKENS_EXTRA[index]);
if (os_memcmp(currentToken->address, token->address, 20) == 0) {
if (memcmp(currentToken->address, token->address, 20) == 0) {
strcpy((char*)token->ticker, (char*)currentToken->ticker);
token->decimals = currentToken->decimals;
break;

View File

@@ -13,14 +13,14 @@ unsigned int io_seproxyhal_touch_signMessage_ok(const bagl_element_t *e) {
tmpCtx.messageSigningContext.pathLength, privateKeyData, NULL);
io_seproxyhal_io_heartbeat();
cx_ecfp_init_private_key(CX_CURVE_256K1, privateKeyData, 32, &privateKey);
os_memset(privateKeyData, 0, sizeof(privateKeyData));
memset(privateKeyData, 0, sizeof(privateKeyData));
unsigned int info = 0;
io_seproxyhal_io_heartbeat();
signatureLength =
cx_ecdsa_sign(&privateKey, CX_RND_RFC6979 | CX_LAST, CX_SHA256,
tmpCtx.messageSigningContext.hash,
sizeof(tmpCtx.messageSigningContext.hash), signature, sizeof(signature), &info);
os_memset(&privateKey, 0, sizeof(privateKey));
memset(&privateKey, 0, sizeof(privateKey));
G_io_apdu_buffer[0] = 27;
if (info & CX_ECCINFO_PARITY_ODD) {
G_io_apdu_buffer[0]++;

View File

@@ -24,14 +24,14 @@ unsigned int io_seproxyhal_touch_signMessage712_v0_ok(const bagl_element_t *e) {
tmpCtx.messageSigningContext712.pathLength, privateKeyData, NULL);
io_seproxyhal_io_heartbeat();
cx_ecfp_init_private_key(CX_CURVE_256K1, privateKeyData, 32, &privateKey);
os_memset(privateKeyData, 0, sizeof(privateKeyData));
memset(privateKeyData, 0, sizeof(privateKeyData));
unsigned int info = 0;
io_seproxyhal_io_heartbeat();
signatureLength =
cx_ecdsa_sign(&privateKey, CX_RND_RFC6979 | CX_LAST, CX_SHA256,
hash,
sizeof(hash), signature, sizeof(signature), &info);
os_memset(&privateKey, 0, sizeof(privateKey));
memset(&privateKey, 0, sizeof(privateKey));
G_io_apdu_buffer[0] = 27;
if (info & CX_ECCINFO_PARITY_ODD) {
G_io_apdu_buffer[0]++;

View File

@@ -158,7 +158,7 @@ void compareOrCopy(char* preapproved_string, char* parsed_string, bool silent_mo
have some for checksum purpose, so let's get rid of these diffs */
to_uppercase(preapproved_string, strlen(preapproved_string));
to_uppercase(parsed_string, strlen(parsed_string));
if(os_memcmp(preapproved_string, parsed_string, strlen(preapproved_string))){
if(memcmp(preapproved_string, parsed_string, strlen(preapproved_string))){
THROW(ERR_SILENT_MODE_CHECK_FAILED);
}
}

View File

@@ -15,14 +15,14 @@ unsigned int io_seproxyhal_touch_tx_ok(const bagl_element_t *e) {
privateKeyData, NULL);
cx_ecfp_init_private_key(CX_CURVE_256K1, privateKeyData, 32,
&privateKey);
os_memset(privateKeyData, 0, sizeof(privateKeyData));
memset(privateKeyData, 0, sizeof(privateKeyData));
unsigned int info = 0;
io_seproxyhal_io_heartbeat();
signatureLength =
cx_ecdsa_sign(&privateKey, CX_RND_RFC6979 | CX_LAST, CX_SHA256,
tmpCtx.transactionContext.hash,
sizeof(tmpCtx.transactionContext.hash), signature, sizeof(signature), &info);
os_memset(&privateKey, 0, sizeof(privateKey));
memset(&privateKey, 0, sizeof(privateKey));
// Parity is present in the sequence tag in the legacy API
if (tmpContent.txContent.vLength == 0) {
// Legacy API

View File

@@ -34,8 +34,8 @@ void handleStarkwareGetPublicKey(uint8_t p1, uint8_t p2, uint8_t *dataBuffer, ui
cx_ecfp_init_private_key(CX_CURVE_Stark256, privateKeyData, 32, &privateKey);
io_seproxyhal_io_heartbeat();
cx_ecfp_generate_pair(CX_CURVE_Stark256, &tmpCtx.publicKeyContext.publicKey, &privateKey, 1);
os_memset(&privateKey, 0, sizeof(privateKey));
os_memset(privateKeyData, 0, sizeof(privateKeyData));
memset(&privateKey, 0, sizeof(privateKey));
memset(privateKeyData, 0, sizeof(privateKeyData));
io_seproxyhal_io_heartbeat();
#ifndef NO_CONSENT
if (p1 == P1_NON_CONFIRM)

View File

@@ -5,7 +5,7 @@
uint32_t set_result_get_stark_publicKey() {
uint32_t tx = 0;
os_memmove(G_io_apdu_buffer + tx, tmpCtx.publicKeyContext.publicKey.W, 65);
memmove(G_io_apdu_buffer + tx, tmpCtx.publicKeyContext.publicKey.W, 65);
tx += 65;
return tx;
}

View File

@@ -34,7 +34,7 @@ void handleStarkwareProvideQuantum(uint8_t p1, uint8_t p2, uint8_t *dataBuffer,
if ((p1 != STARK_QUANTUM_ETH) && !addressZero) {
for(i=0; i<MAX_TOKEN; i++){
currentToken = &tmpCtx.transactionContext.tokens[i];
if (tmpCtx.transactionContext.tokenSet[i] && (os_memcmp(currentToken->address, dataBuffer, 20) == 0)) {
if (tmpCtx.transactionContext.tokenSet[i] && (memcmp(currentToken->address, dataBuffer, 20) == 0)) {
break;
}
}

View File

@@ -72,7 +72,7 @@ void handleStarkwareSignMessage(uint8_t p1, uint8_t p2, uint8_t *dataBuffer, uin
offset += 4;
}
// Discard the path to use part of dataBuffer as a temporary buffer
os_memmove(dataBuffer, dataBuffer + offset, dataLength - offset);
memmove(dataBuffer, dataBuffer + offset, dataLength - offset);
dataContext.starkContext.conditional = (p1 == P1_STARK_CONDITIONAL_TRANSFER);
if (dataContext.starkContext.conditional) {
memmove(dataContext.starkContext.fact, dataBuffer + 20 + 32 + postOffset + 32 + 4 + 4 + 8 + 4 + 4, 32);
@@ -116,7 +116,7 @@ void handleStarkwareSignMessage(uint8_t p1, uint8_t p2, uint8_t *dataBuffer, uin
offset = 20 + 32 + postOffset + 20 + 32 + postOffset;
}
else {
os_memmove(dataContext.starkContext.w2, dataBuffer + 20 + 32 + postOffset, 32);
memmove(dataContext.starkContext.w2, dataBuffer + 20 + 32 + postOffset, 32);
offset = 20 + 32 + postOffset + 32;
}
@@ -176,10 +176,10 @@ void handleStarkwareSignMessage(uint8_t p1, uint8_t p2, uint8_t *dataBuffer, uin
cx_ecfp_init_private_key(CX_CURVE_Stark256, privateKeyData, 32, &privateKey);
io_seproxyhal_io_heartbeat();
cx_ecfp_generate_pair(CX_CURVE_Stark256, &publicKey, &privateKey, 1);
os_memset(&privateKey, 0, sizeof(privateKey));
os_memset(privateKeyData, 0, sizeof(privateKeyData));
memset(&privateKey, 0, sizeof(privateKey));
memset(privateKeyData, 0, sizeof(privateKeyData));
io_seproxyhal_io_heartbeat();
selfTransfer = (os_memcmp(publicKey.W + 1, dataBuffer + 20 + 32 + postOffset, 32) == 0);
selfTransfer = (memcmp(publicKey.W + 1, dataBuffer + 20 + 32 + postOffset, 32) == 0);
PRINTF("self transfer %d\n", selfTransfer);
io_seproxyhal_io_heartbeat();
// amount to transfer

View File

@@ -275,8 +275,8 @@ void starkware_get_source_address(char *destination) {
cx_ecfp_init_private_key(CX_CURVE_256K1, privateKeyData, 32, &privateKey);
io_seproxyhal_io_heartbeat();
cx_ecfp_generate_pair(CX_CURVE_256K1, &publicKey, &privateKey, 1);
os_memset(&privateKey, 0, sizeof(privateKey));
os_memset(privateKeyData, 0, sizeof(privateKeyData));
memset(&privateKey, 0, sizeof(privateKey));
memset(privateKeyData, 0, sizeof(privateKeyData));
io_seproxyhal_io_heartbeat();
destination[0] = '0';
destination[1] = 'x';