|
cryptnox-pos 1.0.0
Standalone USDC payment terminal firmware (ESP32 + Cryptnox smart card)
|
Implementation of the hex Ethereum-address parser, with EIP-55 checksum verification (HARDENING.md §7.1). More...
#include "eth_addr.h"#include <string.h>#include <stdbool.h>#include "keccak256.h"#include "CW_Utils.h"Go to the source code of this file.
Functions | |
| static int | hex_nibble_val (char c) |
| Decode a single ASCII hex digit. | |
| 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. | |
Implementation of the hex Ethereum-address parser, with EIP-55 checksum verification (HARDENING.md §7.1).
Definition in file eth_addr.cpp.
| 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().
|
static |
Decode a single ASCII hex digit.
| [in] | c | Character to decode. |
c is not in [0-9a-fA-F]. Definition at line 26 of file eth_addr.cpp.
Referenced by eth_addr_parse().