Make lint happier

This commit is contained in:
BTChip github
2022-03-22 08:40:36 +01:00
parent d04ed9aef1
commit 52738e6bf5
5 changed files with 40 additions and 39 deletions

View File

@@ -116,11 +116,11 @@ void handleSetPlugin(uint8_t p1,
unsigned int *tx);
void handlePerformPrivacyOperation(uint8_t p1,
uint8_t p2,
uint8_t *workBuffer,
uint16_t dataLength,
unsigned int *flags,
unsigned int *tx);
uint8_t p2,
uint8_t *workBuffer,
uint16_t dataLength,
unsigned int *flags,
unsigned int *tx);
#ifdef HAVE_ETH2

View File

@@ -542,11 +542,11 @@ void handleApdu(unsigned int *flags, unsigned int *tx) {
case INS_PERFORM_PRIVACY_OPERATION:
handlePerformPrivacyOperation(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);
G_io_apdu_buffer[OFFSET_P2],
G_io_apdu_buffer + OFFSET_CDATA,
G_io_apdu_buffer[OFFSET_LC],
flags,
tx);
break;
case INS_SIGN:

View File

@@ -5,11 +5,11 @@
#include "feature_performPrivacyOperation.h"
#define P2_PUBLIC_ENCRYPTION_KEY 0x00
#define P2_SHARED_SECRET 0x01
#define P2_SHARED_SECRET 0x01
void decodeScalar(const uint8_t *scalarIn, uint8_t *scalarOut) {
for (uint8_t i=0; i<32; i++) {
switch(i) {
for (uint8_t i = 0; i < 32; i++) {
switch (i) {
case 0:
scalarOut[0] = (scalarIn[31] & 0x7f) | 0x40;
break;
@@ -18,16 +18,16 @@ void decodeScalar(const uint8_t *scalarIn, uint8_t *scalarOut) {
break;
default:
scalarOut[i] = scalarIn[31 - i];
}
}
}
}
void handlePerformPrivacyOperation(uint8_t p1,
uint8_t p2,
uint8_t *dataBuffer,
uint16_t dataLength,
unsigned int *flags,
unsigned int *tx) {
uint8_t p2,
uint8_t *dataBuffer,
uint16_t dataLength,
unsigned int *flags,
unsigned int *tx) {
UNUSED(dataLength);
uint8_t privateKeyData[INT256_LENGTH];
uint8_t privateKeyDataSwapped[INT256_LENGTH];
@@ -38,14 +38,11 @@ void handlePerformPrivacyOperation(uint8_t p1,
if (dataLength < 1 + 4 * bip32PathLength) {
THROW(0x6700);
}
}
else
if (p2 == P2_SHARED_SECRET) {
} else if (p2 == P2_SHARED_SECRET) {
if (dataLength < 1 + 4 * bip32PathLength + 32) {
THROW(0x6700);
}
}
else {
}
} else {
THROW(0x6B00);
}
cx_ecfp_private_key_t privateKey;
@@ -59,7 +56,7 @@ void handlePerformPrivacyOperation(uint8_t p1,
for (uint8_t i = 0; i < bip32PathLength; i++) {
bip32Path[i] = U4BE(dataBuffer, 0);
dataBuffer += 4;
}
}
os_perso_derive_node_bip32(
CX_CURVE_256K1,
bip32Path,
@@ -71,19 +68,21 @@ void handlePerformPrivacyOperation(uint8_t p1,
getEthAddressStringFromKey(&tmpCtx.publicKeyContext.publicKey,
tmpCtx.publicKeyContext.address,
&global_sha3,
chainConfig->chainId);
chainConfig->chainId);
if (p2 == P2_PUBLIC_ENCRYPTION_KEY) {
decodeScalar(privateKeyData, privateKeyDataSwapped);
cx_ecfp_init_private_key(CX_CURVE_Curve25519, privateKeyDataSwapped, 32, &privateKey);
cx_ecfp_generate_pair(CX_CURVE_Curve25519, &tmpCtx.publicKeyContext.publicKey, &privateKey, 1);
cx_ecfp_generate_pair(CX_CURVE_Curve25519,
&tmpCtx.publicKeyContext.publicKey,
&privateKey,
1);
explicit_bzero(privateKeyDataSwapped, sizeof(privateKeyDataSwapped));
}
else {
} else {
memmove(tmpCtx.publicKeyContext.publicKey.W + 1, dataBuffer, 32);
status = cx_x25519(tmpCtx.publicKeyContext.publicKey.W + 1, privateKeyData, 32);
}
explicit_bzero(&privateKey, sizeof(privateKey));
explicit_bzero(privateKeyData, sizeof(privateKeyData));
explicit_bzero(privateKeyData, sizeof(privateKeyData));
if (status != CX_OK) {
THROW(0x6A80);
@@ -97,24 +96,27 @@ void handlePerformPrivacyOperation(uint8_t p1,
THROW(0x9000);
}
#ifndef NO_CONSENT
else {
else {
snprintf(strings.common.fullAddress,
sizeof(strings.common.fullAddress),
"0x%.*s",
40,
tmpCtx.publicKeyContext.address);
for (uint8_t i=0; i<32; i++) {
for (uint8_t i = 0; i < 32; i++) {
privateKeyData[i] = tmpCtx.publicKeyContext.publicKey.W[32 - i];
}
snprintf(strings.common.fullAmount, sizeof(strings.common.fullAmount) - 1, "%.*H", 32, privateKeyData);
snprintf(strings.common.fullAmount,
sizeof(strings.common.fullAmount) - 1,
"%.*H",
32,
privateKeyData);
if (p2 == P2_PUBLIC_ENCRYPTION_KEY) {
ux_flow_init(0, ux_display_privacy_public_key_flow, NULL);
}
else {
} else {
ux_flow_init(0, ux_display_privacy_shared_secret_flow, NULL);
}
*flags |= IO_ASYNCH_REPLY;
*flags |= IO_ASYNCH_REPLY;
}
#endif // NO_CONSENT
}

View File

@@ -1,7 +1,7 @@
#include "shared_context.h"
uint32_t set_result_perform_privacy_operation() {
for (uint8_t i=0; i<32; i++) {
for (uint8_t i = 0; i < 32; i++) {
G_io_apdu_buffer[i] = tmpCtx.publicKeyContext.publicKey.W[32 - i];
}
return 32;

View File

@@ -24,4 +24,3 @@ unsigned int io_seproxyhal_touch_privacy_cancel(__attribute__((unused)) const ba
ui_idle();
return 0; // do not redraw the widget
}