Update to U2F managed SDK - add forks
This commit is contained in:
@@ -46,7 +46,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);
|
||||
cx_hash((cx_hash_t*)context->sha3, 0, &data, 1, NULL);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
@@ -60,8 +60,7 @@ void copyTxData(txContext_t *context, uint8_t *out, uint32_t length) {
|
||||
os_memmove(out, context->workBuffer, length);
|
||||
}
|
||||
if (!(context->processingField && context->fieldSingleByte)) {
|
||||
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;
|
||||
@@ -81,6 +80,30 @@ static void processContent(txContext_t *context) {
|
||||
context->processingField = false;
|
||||
}
|
||||
|
||||
|
||||
static void processType(txContext_t *context) {
|
||||
if (context->currentFieldIsList) {
|
||||
PRINTF("Invalid type for RLP_TYPE\n");
|
||||
THROW(EXCEPTION);
|
||||
}
|
||||
if (context->currentFieldLength > MAX_INT256) {
|
||||
PRINTF("Invalid length for RLP_TYPE\n");
|
||||
THROW(EXCEPTION);
|
||||
}
|
||||
if (context->currentFieldPos < context->currentFieldLength) {
|
||||
uint32_t copySize =
|
||||
(context->commandLength <
|
||||
((context->currentFieldLength - context->currentFieldPos))
|
||||
? context->commandLength
|
||||
: context->currentFieldLength - context->currentFieldPos);
|
||||
copyTxData(context, NULL, copySize);
|
||||
}
|
||||
if (context->currentFieldPos == context->currentFieldLength) {
|
||||
context->currentField++;
|
||||
context->processingField = false;
|
||||
}
|
||||
}
|
||||
|
||||
static void processNonce(txContext_t *context) {
|
||||
if (context->currentFieldIsList) {
|
||||
PRINTF("Invalid type for RLP_NONCE\n");
|
||||
@@ -111,7 +134,7 @@ static void processStartGas(txContext_t *context) {
|
||||
}
|
||||
if (context->currentFieldLength > MAX_INT256) {
|
||||
PRINTF("Invalid length for RLP_STARTGAS %d\n",
|
||||
context->currentFieldLength);
|
||||
context->currentFieldLength);
|
||||
THROW(EXCEPTION);
|
||||
}
|
||||
if (context->currentFieldPos < context->currentFieldLength) {
|
||||
@@ -183,7 +206,7 @@ static void processValue(txContext_t *context) {
|
||||
}
|
||||
}
|
||||
|
||||
static void processTo(txContext_t *context) {
|
||||
static void processTo(txContext_t *context) {
|
||||
if (context->currentFieldIsList) {
|
||||
PRINTF("Invalid type for RLP_TO\n");
|
||||
THROW(EXCEPTION);
|
||||
@@ -191,7 +214,7 @@ static void processTo(txContext_t *context) {
|
||||
if (context->currentFieldLength > MAX_ADDRESS) {
|
||||
PRINTF("Invalid length for RLP_TO\n");
|
||||
THROW(EXCEPTION);
|
||||
}
|
||||
}
|
||||
if (context->currentFieldPos < context->currentFieldLength) {
|
||||
uint32_t copySize =
|
||||
(context->commandLength <
|
||||
@@ -209,7 +232,7 @@ static void processTo(txContext_t *context) {
|
||||
}
|
||||
}
|
||||
|
||||
static void processData(txContext_t *context) {
|
||||
static void processData(txContext_t *context) {
|
||||
if (context->currentFieldIsList) {
|
||||
PRINTF("Invalid type for RLP_DATA\n");
|
||||
THROW(EXCEPTION);
|
||||
@@ -228,7 +251,7 @@ static void processData(txContext_t *context) {
|
||||
}
|
||||
}
|
||||
|
||||
static void processV(txContext_t *context) {
|
||||
static void processV(txContext_t *context) {
|
||||
if (context->currentFieldIsList) {
|
||||
PRINTF("Invalid type for RLP_V\n");
|
||||
THROW(EXCEPTION);
|
||||
@@ -236,14 +259,15 @@ static void processV(txContext_t *context) {
|
||||
if (context->currentFieldLength > MAX_V) {
|
||||
PRINTF("Invalid length for RLP_V\n");
|
||||
THROW(EXCEPTION);
|
||||
}
|
||||
}
|
||||
if (context->currentFieldPos < context->currentFieldLength) {
|
||||
uint32_t copySize =
|
||||
(context->commandLength <
|
||||
((context->currentFieldLength - context->currentFieldPos))
|
||||
? context->commandLength
|
||||
: context->currentFieldLength - context->currentFieldPos);
|
||||
copyTxData(context, context->content->v + context->currentFieldPos,
|
||||
copyTxData(context,
|
||||
context->content->v + context->currentFieldPos,
|
||||
copySize);
|
||||
}
|
||||
if (context->currentFieldPos == context->currentFieldLength) {
|
||||
@@ -253,7 +277,8 @@ static void processV(txContext_t *context) {
|
||||
}
|
||||
}
|
||||
|
||||
static parserStatus_e processTxInternal(txContext_t *context) {
|
||||
|
||||
static parserStatus_e processTxInternal(txContext_t *context, uint32_t processingFlags) {
|
||||
for (;;) {
|
||||
bool processedCustom = false;
|
||||
// EIP 155 style transasction
|
||||
@@ -261,8 +286,7 @@ static parserStatus_e processTxInternal(txContext_t *context) {
|
||||
return USTREAM_FINISHED;
|
||||
}
|
||||
// Old style transaction
|
||||
if ((context->currentField == TX_RLP_V) &&
|
||||
(context->commandLength == 0)) {
|
||||
if ((context->currentField == TX_RLP_V) && (context->commandLength == 0)) {
|
||||
context->content->vLength = 0;
|
||||
return USTREAM_FINISHED;
|
||||
}
|
||||
@@ -323,6 +347,12 @@ static parserStatus_e processTxInternal(txContext_t *context) {
|
||||
switch (context->currentField) {
|
||||
case TX_RLP_CONTENT:
|
||||
processContent(context);
|
||||
if ((processingFlags & TX_FLAG_TYPE) == 0) {
|
||||
context->currentField++;
|
||||
}
|
||||
break;
|
||||
case TX_RLP_TYPE:
|
||||
processType(context);
|
||||
break;
|
||||
case TX_RLP_NONCE:
|
||||
processNonce(context);
|
||||
@@ -356,13 +386,13 @@ static parserStatus_e processTxInternal(txContext_t *context) {
|
||||
}
|
||||
|
||||
parserStatus_e processTx(txContext_t *context, uint8_t *buffer,
|
||||
uint32_t length) {
|
||||
uint32_t length, uint32_t processingFlags) {
|
||||
parserStatus_e result;
|
||||
BEGIN_TRY {
|
||||
TRY {
|
||||
context->workBuffer = buffer;
|
||||
context->commandLength = length;
|
||||
result = processTxInternal(context);
|
||||
result = processTxInternal(context, processingFlags);
|
||||
}
|
||||
CATCH_OTHER(e) {
|
||||
result = USTREAM_FAULT;
|
||||
|
||||
@@ -23,9 +23,12 @@ struct txContext_t;
|
||||
|
||||
typedef bool (*ustreamProcess_t)(struct txContext_t *context);
|
||||
|
||||
#define TX_FLAG_TYPE 0x01
|
||||
|
||||
typedef enum rlpTxField_e {
|
||||
TX_RLP_NONE = 0,
|
||||
TX_RLP_CONTENT,
|
||||
TX_RLP_TYPE,
|
||||
TX_RLP_NONCE,
|
||||
TX_RLP_GASPRICE,
|
||||
TX_RLP_STARTGAS,
|
||||
@@ -80,6 +83,6 @@ typedef struct txContext_t {
|
||||
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);
|
||||
uint32_t length, uint32_t processingFlags);
|
||||
void copyTxData(txContext_t *context, uint8_t *out, uint32_t length);
|
||||
uint8_t readTxByte(txContext_t *context);
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
#include "os.h"
|
||||
#include "cx.h"
|
||||
#include <stdbool.h>
|
||||
#include "ethUtils.h"
|
||||
#include "ethUtils.h"
|
||||
|
||||
bool rlpCanDecode(uint8_t *buffer, uint32_t bufferLength, bool *valid) {
|
||||
if (*buffer <= 0x7f) {
|
||||
@@ -115,14 +115,14 @@ bool rlpDecodeLength(uint8_t *buffer, uint32_t bufferLength,
|
||||
}
|
||||
|
||||
void getEthAddressFromKey(cx_ecfp_public_key_t *publicKey, uint8_t *out,
|
||||
cx_sha3_t *sha3Context) {
|
||||
cx_sha3_t *sha3Context) {
|
||||
uint8_t hashAddress[32];
|
||||
cx_keccak_init(sha3Context, 256);
|
||||
cx_hash((cx_hash_t *)sha3Context, CX_LAST, publicKey->W + 1, 64,
|
||||
hashAddress);
|
||||
cx_hash((cx_hash_t*)sha3Context, CX_LAST, publicKey->W + 1, 64, hashAddress);
|
||||
os_memmove(out, hashAddress + 12, 20);
|
||||
}
|
||||
|
||||
|
||||
#ifdef CHECKSUM_1
|
||||
|
||||
static const uint8_t const HEXDIGITS[] = "0123456789ABCDEF";
|
||||
@@ -153,8 +153,7 @@ void getEthAddressStringFromKey(cx_ecfp_public_key_t *publicKey, uint8_t *out,
|
||||
cx_sha3_t *sha3Context) {
|
||||
uint8_t hashAddress[32];
|
||||
cx_keccak_init(sha3Context, 256);
|
||||
cx_hash((cx_hash_t *)sha3Context, CX_LAST, publicKey->W + 1, 64,
|
||||
hashAddress);
|
||||
cx_hash((cx_hash_t*)sha3Context, CX_LAST, publicKey->W + 1, 64, hashAddress);
|
||||
getEthAddressStringFromBinary(hashAddress + 12, out, sha3Context);
|
||||
}
|
||||
|
||||
@@ -163,7 +162,7 @@ void getEthAddressStringFromBinary(uint8_t *address, uint8_t *out,
|
||||
uint8_t hashChecksum[32];
|
||||
uint8_t i;
|
||||
cx_keccak_init(sha3Context, 256);
|
||||
cx_hash((cx_hash_t *)sha3Context, CX_LAST, address, 20, hashChecksum);
|
||||
cx_hash((cx_hash_t*)sha3Context, CX_LAST, address, 20, hashChecksum);
|
||||
for (i = 0; i < 40; i++) {
|
||||
out[i] = convertDigit(address, i, hashChecksum);
|
||||
}
|
||||
@@ -178,8 +177,7 @@ void getEthAddressStringFromKey(cx_ecfp_public_key_t *publicKey, uint8_t *out,
|
||||
cx_sha3_t *sha3Context) {
|
||||
uint8_t hashAddress[32];
|
||||
cx_keccak_init(sha3Context, 256);
|
||||
cx_hash((cx_hash_t *)sha3Context, CX_LAST, publicKey->W + 1, 64,
|
||||
hashAddress);
|
||||
cx_hash((cx_hash_t*)sha3Context, CX_LAST, publicKey->W + 1, 64, hashAddress);
|
||||
getEthAddressStringFromBinary(hashAddress + 12, out, sha3Context);
|
||||
}
|
||||
|
||||
@@ -194,7 +192,7 @@ void getEthAddressStringFromBinary(uint8_t *address, uint8_t *out,
|
||||
tmp[2 * i + 1] = HEXDIGITS[digit & 0x0f];
|
||||
}
|
||||
cx_keccak_init(sha3Context, 256);
|
||||
cx_hash((cx_hash_t *)sha3Context, CX_LAST, tmp, 40, hashChecksum);
|
||||
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) {
|
||||
@@ -220,12 +218,12 @@ bool adjustDecimals(char *src, uint32_t srcLength, char *target,
|
||||
uint32_t offset = 0;
|
||||
if ((srcLength == 1) && (*src == '0')) {
|
||||
if (targetLength < 2) {
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
target[0] = '0';
|
||||
target[1] = '\0';
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (srcLength <= decimals) {
|
||||
uint32_t delta = decimals - srcLength;
|
||||
if (targetLength < srcLength + 1 + 2 + delta) {
|
||||
@@ -271,8 +269,8 @@ bool adjustDecimals(char *src, uint32_t srcLength, char *target,
|
||||
if (lastZeroOffset != 0) {
|
||||
target[lastZeroOffset] = '\0';
|
||||
if (target[lastZeroOffset - 1] == '.') {
|
||||
target[lastZeroOffset - 1] = '\0';
|
||||
}
|
||||
target[lastZeroOffset - 1] = '\0';
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ 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,
|
||||
cx_sha3_t *sha3Context);
|
||||
cx_sha3_t *sha3Context);
|
||||
|
||||
void getEthAddressStringFromKey(cx_ecfp_public_key_t *publicKey, uint8_t *out,
|
||||
cx_sha3_t *sha3Context);
|
||||
|
||||
Reference in New Issue
Block a user