Cleanup, adjust derivation API to API level 5, adjust linker script and NVRAM location, move to internal SHA3 API, fix address checksum
This commit is contained in:
@@ -21,7 +21,7 @@
|
||||
#define MAX_INT256 32
|
||||
#define MAX_ADDRESS 20
|
||||
|
||||
void initTx(txContext_t *context, app_cx_sha3_t *sha3, txContent_t *content,
|
||||
void initTx(txContext_t *context, cx_sha3_t *sha3, txContent_t *content,
|
||||
ustreamProcess_t customProcessor, void *extra) {
|
||||
os_memset(context, 0, sizeof(txContext_t));
|
||||
context->sha3 = sha3;
|
||||
@@ -29,7 +29,7 @@ void initTx(txContext_t *context, app_cx_sha3_t *sha3, txContent_t *content,
|
||||
context->customProcessor = customProcessor;
|
||||
context->extra = extra;
|
||||
context->currentField = TX_RLP_CONTENT;
|
||||
app_cx_sha3_init(context->sha3, 256);
|
||||
cx_keccak_init(context->sha3, 256);
|
||||
}
|
||||
|
||||
uint8_t readTxByte(txContext_t *context) {
|
||||
@@ -45,7 +45,7 @@ uint8_t readTxByte(txContext_t *context) {
|
||||
context->currentFieldPos++;
|
||||
}
|
||||
if (!(context->processingField && context->fieldSingleByte)) {
|
||||
app_cx_hash((cx_hash_t *)context->sha3, 0, &data, 1, NULL);
|
||||
cx_hash((cx_hash_t *)context->sha3, 0, &data, 1, NULL);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
@@ -59,8 +59,8 @@ void copyTxData(txContext_t *context, uint8_t *out, uint32_t length) {
|
||||
os_memmove(out, context->workBuffer, length);
|
||||
}
|
||||
if (!(context->processingField && context->fieldSingleByte)) {
|
||||
app_cx_hash((cx_hash_t *)context->sha3, 0, context->workBuffer, length,
|
||||
NULL);
|
||||
cx_hash((cx_hash_t *)context->sha3, 0, context->workBuffer, length,
|
||||
NULL);
|
||||
}
|
||||
context->workBuffer += length;
|
||||
context->commandLength -= length;
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
#include "os.h"
|
||||
#include "cx.h"
|
||||
#include <stdbool.h>
|
||||
#include "app_cx_sha3.h"
|
||||
|
||||
struct txContext_t;
|
||||
|
||||
@@ -56,7 +55,7 @@ typedef struct txContent_t {
|
||||
|
||||
typedef struct txContext_t {
|
||||
rlpTxField_e currentField;
|
||||
app_cx_sha3_t *sha3;
|
||||
cx_sha3_t *sha3;
|
||||
uint32_t currentFieldLength;
|
||||
uint32_t currentFieldPos;
|
||||
bool currentFieldIsList;
|
||||
@@ -72,7 +71,7 @@ typedef struct txContext_t {
|
||||
void *extra;
|
||||
} txContext_t;
|
||||
|
||||
void initTx(txContext_t *context, app_cx_sha3_t *sha3, txContent_t *content,
|
||||
void initTx(txContext_t *context, cx_sha3_t *sha3, txContent_t *content,
|
||||
ustreamProcess_t customProcessor, void *extra);
|
||||
parserStatus_e processTx(txContext_t *context, uint8_t *buffer,
|
||||
uint32_t length);
|
||||
|
||||
@@ -115,18 +115,18 @@ bool rlpDecodeLength(uint8_t *buffer, uint32_t bufferLength,
|
||||
}
|
||||
|
||||
void getEthAddressFromKey(cx_ecfp_public_key_t *publicKey, uint8_t *out,
|
||||
app_cx_sha3_t *sha3Context) {
|
||||
cx_sha3_t *sha3Context) {
|
||||
uint8_t hashAddress[32];
|
||||
app_cx_sha3_init(sha3Context, 256);
|
||||
app_cx_hash((cx_hash_t *)sha3Context, CX_LAST, publicKey->W + 1, 64,
|
||||
hashAddress);
|
||||
cx_keccak_init(sha3Context, 256);
|
||||
cx_hash((cx_hash_t *)sha3Context, CX_LAST, publicKey->W + 1, 64,
|
||||
hashAddress);
|
||||
os_memmove(out, hashAddress + 12, 20);
|
||||
}
|
||||
|
||||
static const uint8_t const HEXDIGITS[] = "0123456789ABCDEF";
|
||||
|
||||
#ifdef CHECKSUM_1
|
||||
|
||||
static const uint8_t const HEXDIGITS[] = "0123456789ABCDEF";
|
||||
|
||||
static const uint8_t const MASK[] = {0x80, 0x40, 0x20, 0x10,
|
||||
0x08, 0x04, 0x02, 0x01};
|
||||
|
||||
@@ -150,20 +150,20 @@ char convertDigit(uint8_t *address, uint8_t index, uint8_t *hash) {
|
||||
}
|
||||
|
||||
void getEthAddressStringFromKey(cx_ecfp_public_key_t *publicKey, uint8_t *out,
|
||||
app_cx_sha3_t *sha3Context) {
|
||||
cx_sha3_t *sha3Context) {
|
||||
uint8_t hashAddress[32];
|
||||
app_cx_sha3_init(sha3Context, 256);
|
||||
app_cx_hash((cx_hash_t *)sha3Context, CX_LAST, publicKey->W + 1, 64,
|
||||
hashAddress);
|
||||
cx_keccak_init(sha3Context, 256);
|
||||
cx_hash((cx_hash_t *)sha3Context, CX_LAST, publicKey->W + 1, 64,
|
||||
hashAddress);
|
||||
getEthAddressStringFromBinary(hashAddress + 12, out, sha3Context);
|
||||
}
|
||||
|
||||
void getEthAddressStringFromBinary(uint8_t *address, uint8_t *out,
|
||||
app_cx_sha3_t *sha3Context) {
|
||||
cx_sha3_t *sha3Context) {
|
||||
uint8_t hashChecksum[32];
|
||||
uint8_t i;
|
||||
app_cx_sha3_init(sha3Context, 256);
|
||||
app_cx_hash((cx_hash_t *)sha3Context, CX_LAST, address, 20, hashChecksum);
|
||||
cx_keccak_init(sha3Context, 256);
|
||||
cx_hash((cx_hash_t *)sha3Context, CX_LAST, address, 20, hashChecksum);
|
||||
for (i = 0; i < 40; i++) {
|
||||
out[i] = convertDigit(address, i, hashChecksum);
|
||||
}
|
||||
@@ -172,17 +172,19 @@ void getEthAddressStringFromBinary(uint8_t *address, uint8_t *out,
|
||||
|
||||
#else
|
||||
|
||||
static const uint8_t const HEXDIGITS[] = "0123456789abcdef";
|
||||
|
||||
void getEthAddressStringFromKey(cx_ecfp_public_key_t *publicKey, uint8_t *out,
|
||||
app_cx_sha3_t *sha3Context) {
|
||||
cx_sha3_t *sha3Context) {
|
||||
uint8_t hashAddress[32];
|
||||
app_cx_sha3_init(sha3Context, 256);
|
||||
app_cx_hash((cx_hash_t *)sha3Context, CX_LAST, publicKey->W + 1, 64,
|
||||
hashAddress);
|
||||
cx_keccak_init(sha3Context, 256);
|
||||
cx_hash((cx_hash_t *)sha3Context, CX_LAST, publicKey->W + 1, 64,
|
||||
hashAddress);
|
||||
getEthAddressStringFromBinary(hashAddress + 12, out, sha3Context);
|
||||
}
|
||||
|
||||
void getEthAddressStringFromBinary(uint8_t *address, uint8_t *out,
|
||||
app_cx_sha3_t *sha3Context) {
|
||||
cx_sha3_t *sha3Context) {
|
||||
uint8_t hashChecksum[32];
|
||||
uint8_t tmp[40];
|
||||
uint8_t i;
|
||||
@@ -191,8 +193,8 @@ void getEthAddressStringFromBinary(uint8_t *address, uint8_t *out,
|
||||
tmp[2 * i] = HEXDIGITS[(digit >> 4) & 0x0f];
|
||||
tmp[2 * i + 1] = HEXDIGITS[digit & 0x0f];
|
||||
}
|
||||
app_cx_sha3_init(sha3Context, 256);
|
||||
app_cx_hash((cx_hash_t *)sha3Context, CX_LAST, tmp, 40, hashChecksum);
|
||||
cx_keccak_init(sha3Context, 256);
|
||||
cx_hash((cx_hash_t *)sha3Context, CX_LAST, tmp, 40, hashChecksum);
|
||||
for (i = 0; i < 40; i++) {
|
||||
uint8_t hashDigit = hashChecksum[i / 2];
|
||||
if ((i % 2) == 0) {
|
||||
@@ -201,7 +203,7 @@ void getEthAddressStringFromBinary(uint8_t *address, uint8_t *out,
|
||||
hashDigit = hashDigit & 0x0f;
|
||||
}
|
||||
if ((hashDigit > 7) && (tmp[i] > '9')) {
|
||||
out[i] = tmp[i] /*- 'a' + 'A'*/;
|
||||
out[i] = tmp[i] - 'a' + 'A';
|
||||
} else {
|
||||
out[i] = tmp[i];
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
|
||||
#include "os.h"
|
||||
#include "cx.h"
|
||||
#include "app_cx_sha3.h"
|
||||
|
||||
/**
|
||||
* @brief Decode an RLP encoded field - see
|
||||
@@ -37,13 +36,13 @@ bool rlpDecodeLength(uint8_t *buffer, uint32_t bufferLength,
|
||||
bool rlpCanDecode(uint8_t *buffer, uint32_t bufferLength, bool *valid);
|
||||
|
||||
void getEthAddressFromKey(cx_ecfp_public_key_t *publicKey, uint8_t *out,
|
||||
app_cx_sha3_t *sha3Context);
|
||||
cx_sha3_t *sha3Context);
|
||||
|
||||
void getEthAddressStringFromKey(cx_ecfp_public_key_t *publicKey, uint8_t *out,
|
||||
app_cx_sha3_t *sha3Context);
|
||||
cx_sha3_t *sha3Context);
|
||||
|
||||
void getEthAddressStringFromBinary(uint8_t *address, uint8_t *out,
|
||||
app_cx_sha3_t *sha3Context);
|
||||
cx_sha3_t *sha3Context);
|
||||
|
||||
bool adjustDecimals(char *src, uint32_t srcLength, char *target,
|
||||
uint32_t targetLength, uint8_t decimals);
|
||||
|
||||
Reference in New Issue
Block a user