|
cryptnox-sdk-arduino 1.0.0
Arduino library for Cryptnox Hardware Wallet
|
#include <stdint.h>#include <stddef.h>Go to the source code of this file.
Functions | |
| uint32_t | RlpEncodeWholeHeader (uint8_t *header_output, size_t header_cap, uint32_t total_len) |
| Encodes the total length into an RLP list header. | |
| uint32_t | RlpEncodeItem (uint8_t *output, size_t output_cap, const uint8_t *input, uint32_t input_len) |
| Encodes a single item in RLP format. | |
| uint32_t | ConvertNumberToUintArray (uint8_t *str, uint64_t val) |
| Converts an unsigned integer to a big-endian byte array. | |
| size_t | trimLeadingZeros (uint8_t *out, size_t out_cap, const uint8_t *in, size_t in_len) |
| Removes leading zeros from a byte array. | |
| int | fromHex (char c) |
| Convert a hexadecimal character to a byte value. | |
| bool | hexToBytes (const char *hex, uint8_t *out, size_t len) |
| Convert a hex string to a byte array. | |
| uint32_t ConvertNumberToUintArray | ( | uint8_t * | str, |
| uint64_t | val ) |
Converts an unsigned integer to a big-endian byte array.
NEW-5: widened from uint32_t to uint64_t so that 64-bit Ethereum fields (nonce, gasLimit, value, maxFeePerGas, maxPriorityFeePerGas) are not silently truncated. Returns up to 8 bytes; str must be >= 8 bytes.
| [out] | str | Pointer to output buffer (at least 8 bytes). |
| [in] | val | Unsigned 64-bit integer to convert. |
Converts an unsigned integer to a big-endian byte array.
NEW-5: widened to uint64_t. Previously truncated Tx2 uint64 fields (nonce/fees/gasLimit/value) at 4 bytes, producing wrong-amount tx.
| [out] | str | Output buffer (at least 8 bytes). |
| [in] | val | Unsigned 64-bit integer to convert. |
Definition at line 190 of file util.cpp.
Referenced by rlpEncodeTxBody().
| int fromHex | ( | char | c | ) |
Convert a hexadecimal character to a byte value.
Returns -1 on any non-hex character so callers can distinguish a true '0' from a parse error. Previously this returned 0 on invalid input, causing silent data corruption (security audit M-07).
| c | Hex character. |
M-07: returns -1 on any non-hex character so callers can distinguish a true '0' from a parse error.
Definition at line 15 of file util.cpp.
Referenced by fetchNonce(), and hexToBytes().
| bool hexToBytes | ( | const char * | hex, |
| uint8_t * | out, | ||
| size_t | len ) |
Convert a hex string to a byte array.
Validates that hex contains at least 2*len characters before any read, to prevent out-of-bounds reads on malformed / truncated RPC responses (security audit H-03).
| hex | Input hex string (must be NUL-terminated). |
| out | Output byte array (caller-allocated, at least len bytes). |
| len | Number of bytes to write to out. |
hex is too short or NULL.H-03: validate input length before any read. Without this guard a truncated or malicious RPC response shorter than 2*len would cause out-of-bounds reads past the NUL terminator.
Definition at line 32 of file util.cpp.
References fromHex().
Referenced by encodeERC20Transfer(), and rlpEncodeTxBody().
| uint32_t RlpEncodeItem | ( | uint8_t * | output, |
| size_t | output_cap, | ||
| const uint8_t * | input, | ||
| uint32_t | input_len ) |
Encodes a single item in RLP format.
Bounds-checked: returns 0 (and does not write) if the encoded item would not fit in output_cap bytes.
| [out] | output | Pointer to buffer to store the RLP-encoded item. |
| [in] | output_cap | Capacity of output in bytes. |
| [in] | input | Pointer to the data to encode. |
| [in] | input_len | Length of the input data in bytes. |
Encodes a single item in RLP format.
| [out] | output | Buffer where the encoded RLP item will be written. |
| [in] | input | Input data to encode. |
| [in] | input_len | Length of input data. |
Definition at line 123 of file util.cpp.
Referenced by rlpEncodeSignedTx().
| uint32_t RlpEncodeWholeHeader | ( | uint8_t * | header_output, |
| size_t | header_cap, | ||
| uint32_t | total_len ) |
Encodes the total length into an RLP list header.
Bounds-checked: returns 0 (and does not write) if the encoded header would not fit in header_cap bytes.
| [out] | header_output | Pointer to buffer to store the RLP header. |
| [in] | header_cap | Capacity of header_output in bytes. |
| [in] | total_len | Total length of the RLP list content. |
Encodes the total length into an RLP list header.
This function generates the RLP "whole header" for a list payload of length total_len, according to Ethereum RLP specification.
RLP encoding rules:
Example: total_len = 10 → header = C0 + 0x0A → C0 0A total_len = 100 → total_len = 0x64 (1 byte) → F8 64 total_len = 1024 → total_len = 0x0400 (2 bytes) → F9 04 00
This header is intended to be placed immediately before the concatenated items in an RLP list. For EIP-1559 typed transactions, it must appear after the type byte (0x02).
| [out] | header_output | Pointer where the encoded header will be written. |
| [in] | total_len | Length in bytes of all list items concatenated. |
Definition at line 76 of file util.cpp.
Referenced by rlpFinalize().
| size_t trimLeadingZeros | ( | uint8_t * | out, |
| size_t | out_cap, | ||
| const uint8_t * | in, | ||
| size_t | in_len ) |
Removes leading zeros from a byte array.
Bounds-checked: returns 0 if out_cap is smaller than the trimmed length. (Trimmed length is always <= in_len.)
| [out] | out | Pointer to buffer to store trimmed result. |
| [in] | out_cap | Capacity of out in bytes. |
| [in] | in | Pointer to input byte array. |
| [in] | in_len | Length of input array. |
Removes leading zeros from a byte array.
| [out] | out | Output buffer. |
| [in] | in | Input buffer. |
| [in] | in_len | Length of input buffer. |
Definition at line 220 of file util.cpp.
Referenced by rlpEncodeSignedTx().