Use INT256_LENGTH and ADDRESS_LENGTH define
This commit is contained in:
@@ -36,6 +36,8 @@ typedef enum customStatus_e {
|
||||
typedef customStatus_e (*ustreamProcess_t)(struct txContext_t *context);
|
||||
|
||||
#define TX_FLAG_TYPE 0x01
|
||||
#define ADDRESS_LENGTH 20
|
||||
#define INT256_LENGTH 32
|
||||
|
||||
// First variant of every Tx enum.
|
||||
#define RLP_NONE 0
|
||||
@@ -97,7 +99,7 @@ typedef enum parserStatus_e {
|
||||
} parserStatus_e;
|
||||
|
||||
typedef struct txInt256_t {
|
||||
uint8_t value[32];
|
||||
uint8_t value[INT256_LENGTH];
|
||||
uint8_t length;
|
||||
} txInt256_t;
|
||||
|
||||
@@ -107,7 +109,7 @@ typedef struct txContent_t {
|
||||
txInt256_t value;
|
||||
txInt256_t nonce;
|
||||
txInt256_t chainID;
|
||||
uint8_t destination[20];
|
||||
uint8_t destination[ADDRESS_LENGTH];
|
||||
uint8_t destinationLength;
|
||||
uint8_t v[4];
|
||||
uint8_t vLength;
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#include "cx.h"
|
||||
#include "ethUtils.h"
|
||||
#include "chainConfig.h"
|
||||
#include "ethUstream.h"
|
||||
|
||||
bool rlpCanDecode(uint8_t *buffer, uint32_t bufferLength, bool *valid) {
|
||||
if (*buffer <= 0x7f) {
|
||||
@@ -120,7 +121,7 @@ bool rlpDecodeLength(uint8_t *buffer,
|
||||
}
|
||||
|
||||
void getEthAddressFromKey(cx_ecfp_public_key_t *publicKey, uint8_t *out, cx_sha3_t *sha3Context) {
|
||||
uint8_t hashAddress[32];
|
||||
uint8_t hashAddress[INT256_LENGTH];
|
||||
cx_keccak_init(sha3Context, 256);
|
||||
cx_hash((cx_hash_t *) sha3Context, CX_LAST, publicKey->W + 1, 64, hashAddress, 32);
|
||||
memmove(out, hashAddress + 12, 20);
|
||||
@@ -155,7 +156,7 @@ void getEthAddressStringFromKey(cx_ecfp_public_key_t *publicKey,
|
||||
uint8_t *out,
|
||||
cx_sha3_t *sha3Context,
|
||||
chain_config_t *chain_config) {
|
||||
uint8_t hashAddress[32];
|
||||
uint8_t hashAddress[INT256_LENGTH];
|
||||
cx_keccak_init(sha3Context, 256);
|
||||
cx_hash((cx_hash_t *) sha3Context, CX_LAST, publicKey->W + 1, 64, hashAddress, 32);
|
||||
getEthAddressStringFromBinary(hashAddress + 12, out, sha3Context, chain_config);
|
||||
@@ -166,7 +167,7 @@ void getEthAddressStringFromBinary(uint8_t *address,
|
||||
cx_sha3_t *sha3Context,
|
||||
chain_config_t *chain_config) {
|
||||
UNUSED(chain_config);
|
||||
uint8_t hashChecksum[32];
|
||||
uint8_t hashChecksum[INT256_LENGTH];
|
||||
uint8_t i;
|
||||
cx_keccak_init(sha3Context, 256);
|
||||
cx_hash((cx_hash_t *) sha3Context, CX_LAST, address, 20, hashChecksum, 32);
|
||||
@@ -184,7 +185,7 @@ void getEthAddressStringFromKey(cx_ecfp_public_key_t *publicKey,
|
||||
uint8_t *out,
|
||||
cx_sha3_t *sha3Context,
|
||||
chain_config_t *chain_config) {
|
||||
uint8_t hashAddress[32];
|
||||
uint8_t hashAddress[INT256_LENGTH];
|
||||
cx_keccak_init(sha3Context, 256);
|
||||
cx_hash((cx_hash_t *) sha3Context, CX_LAST, publicKey->W + 1, 64, hashAddress, 32);
|
||||
getEthAddressStringFromBinary(hashAddress + 12, out, sha3Context, chain_config);
|
||||
@@ -196,7 +197,7 @@ void getEthAddressStringFromBinary(uint8_t *address,
|
||||
chain_config_t *chain_config) {
|
||||
// save some precious stack space
|
||||
union locals_union {
|
||||
uint8_t hashChecksum[32];
|
||||
uint8_t hashChecksum[INT256_LENGTH];
|
||||
uint8_t tmp[51];
|
||||
} locals_union;
|
||||
|
||||
|
||||
@@ -347,7 +347,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];
|
||||
uint8_t num1[INT256_LENGTH], num2[INT256_LENGTH], result[INT256_LENGTH * 2];
|
||||
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]);
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include <stdbool.h>
|
||||
#include "os.h"
|
||||
#include "cx.h"
|
||||
#include "ethUstream.h"
|
||||
|
||||
typedef struct uint128_t {
|
||||
uint64_t elements[2];
|
||||
|
||||
Reference in New Issue
Block a user