Update to U2F managed SDK - add forks
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user