|
cryptnox-pos 1.0.0
Standalone USDC payment terminal firmware (ESP32 + Cryptnox smart card)
|
Hex Ethereum-address parsing — a pure, dependency-free unit so it can be unit-tested and fuzzed on the host (see fuzz/fuzz_parse_address.cpp). More...
#include <stdint.h>#include <stddef.h>#include <stdbool.h>Go to the source code of this file.
Macros | |
| #define | ETH_ADDR_LEN 20U |
| Length of a raw (binary) Ethereum address, in bytes. | |
| #define | ETH_ADDR_HEX_LEN ((size_t)ETH_ADDR_LEN * 2U) |
Length of the same address in hex characters (no 0x prefix). | |
Functions | |
| bool | eth_addr_parse (const char *hex, uint8_t out[ETH_ADDR_LEN]) |
| Parse a 20-byte Ethereum address from a hex string. | |
| bool | eth_addr_format (const uint8_t addr[ETH_ADDR_LEN], char *out, size_t n) |
| Render a 20-byte address as an EIP-55 mixed-case "0x..." string. | |
Hex Ethereum-address parsing — a pure, dependency-free unit so it can be unit-tested and fuzzed on the host (see fuzz/fuzz_parse_address.cpp).
Definition in file eth_addr.h.
| #define ETH_ADDR_HEX_LEN ((size_t)ETH_ADDR_LEN * 2U) |
Length of the same address in hex characters (no 0x prefix).
Two hex chars per byte. The multiply is performed in size_t because every use site is a size_t context (strlen result, array bound, loop bound): multiplying in unsigned int and widening at the use site trips bugprone-implicit-widening-of-multiplication-result on a 64-bit host.
Definition at line 34 of file eth_addr.h.
Referenced by eth_addr_format(), and eth_addr_parse().
| #define ETH_ADDR_LEN 20U |
Length of a raw (binary) Ethereum address, in bytes.
Definition at line 25 of file eth_addr.h.
Referenced by addr_plausible(), address_consistent(), build_usdc_calldata(), eth_addr_format(), eth_addr_parse(), pos_boot(), sign_and_broadcast(), sign_and_broadcast_tron(), token_decimals_ok(), and token_parse().
| bool eth_addr_format | ( | const uint8_t | addr[ETH_ADDR_LEN], |
| char * | out, | ||
| size_t | n ) |
Render a 20-byte address as an EIP-55 mixed-case "0x..." string.
The inverse of eth_addr_parse, and it produces the checksummed form on purpose: an address derived on the device (from a card's public key, say) is then displayed exactly as the operator's own wallet displays it, which is the whole point of showing it to them. It also means the value that goes into storage carries a checksum, so the boot-time parse is a real check on it rather than the no-op it is for an all-lowercase string.
| [in] | addr | 20-byte address. |
| [out] | out | Buffer for "0x" + 40 hex + NUL. |
| [in] | n | Capacity of out; needs at least 43 bytes. |
out is too small (and then left empty). Definition at line 109 of file eth_addr.cpp.
References ETH_ADDR_HEX_LEN, ETH_ADDR_LEN, and keccak256().
Referenced by card_read_payouts(), and sign_and_broadcast().
| bool eth_addr_parse | ( | const char * | hex, |
| uint8_t | out[ETH_ADDR_LEN] ) |
Parse a 20-byte Ethereum address from a hex string.
Accepts an optional 0x / 0X prefix, then requires exactly 40 hex characters and rejects any non-hex input instead of silently decoding garbage. A mixed-case input is treated as EIP-55 checksummed and its checksum is verified (keccak256 recomputed, rejected on case mismatch); an all-lower/all-upper input is accepted as un-checksummed.
| [in] | hex | Address string (with or without 0x prefix). |
| [out] | out | 20-byte decoded address; zeroed then left partially written on failure — must not be used unless true is returned. |
Definition at line 34 of file eth_addr.cpp.
References ETH_ADDR_HEX_LEN, ETH_ADDR_LEN, hex_nibble_val(), and keccak256().
Referenced by addr_plausible(), resolve_evm_payout(), and token_parse().