|
cryptnox-sdk-esp32 1.0.0
ESP32 SDK for Cryptnox Hardware Wallet
|
#include "uECC.h"#include "CW_Utils.h"#include "mbedtls/ecp.h"#include "mbedtls/ecdsa.h"#include "esp_log.h"#include <algorithm>Go to the source code of this file.
Classes | |
| struct | uECC_Curve_t |
Macros | |
| #define | COORD_SIZE_BYTES (32U) /* bytes per coordinate (256-bit curve) */ |
| #define | ECC_XY_KEY_SIZE (COORD_SIZE_BYTES * 2U) /* X[32] || Y[32] without 0x04 prefix */ |
| #define | UNCOMPRESSED_PUB_SIZE (65U) /* 0x04 || X[32] || Y[32] */ |
| #define | UNCOMPRESSED_PREFIX (0x04U) |
| #define | POINT_PREFIX_OFFSET (0U) /* byte offset of the 0x04 prefix */ |
| #define | COORD_X_OFFSET (1U) /* byte offset of X in 65-byte key */ |
| #define | RAW_SIG_R_OFFSET (0U) /* byte offset of r in 64-byte raw sig */ |
| #define | RAW_SIG_S_OFFSET (32U) /* byte offset of s in 64-byte raw sig */ |
| #define | UECC_SUCCESS (1) |
| #define | UECC_FAILURE (0) |
| #define | MBEDTLS_OK (0) |
| #define | RNG_ERROR (-1) /* returned by RNG callback on invalid arguments */ |
Functions | |
| static int | esp32_mbedtls_rng (void *ctx, unsigned char *output, size_t len) |
| const uECC_Curve_t * | uECC_secp256r1 (void) |
| Return the static secp256r1 curve descriptor. | |
| const uECC_Curve_t * | uECC_secp256k1 (void) |
| Return the static secp256k1 curve descriptor. | |
| void | uECC_set_rng (uECC_RNG_Function rng_function) |
| No-op: ESP32 hardware RNG is used internally; no external callback needed. | |
| int | uECC_make_key (uint8_t *public_key, uint8_t *private_key, const uECC_Curve_t *curve) |
| Generate an ECC key pair using mbedTLS and the ESP32 hardware RNG. | |
| int | uECC_shared_secret (const uint8_t *public_key, const uint8_t *private_key, uint8_t *secret, const uECC_Curve_t *curve) |
| Compute ECDH shared secret (X-coordinate of privKey * pubKey). | |
| int | uECC_verify (const uint8_t *public_key, const uint8_t *hash, unsigned hash_size, const uint8_t *signature, const uECC_Curve_t *curve) |
| Verify an ECDSA signature (raw 64-byte r||s) against a hash. | |
Variables | |
| static const char *const | UECC_LOG_TAG = "uECC_esp32" |
| static const uECC_Curve_t | s_secp256r1 = { MBEDTLS_ECP_DP_SECP256R1 } |
| static const uECC_Curve_t | s_secp256k1 = { MBEDTLS_ECP_DP_SECP256K1 } |
| #define COORD_SIZE_BYTES (32U) /* bytes per coordinate (256-bit curve) */ |
Definition at line 17 of file uECC_esp32.cpp.
Referenced by uECC_make_key(), uECC_shared_secret(), and uECC_verify().
| #define COORD_X_OFFSET (1U) /* byte offset of X in 65-byte key */ |
Definition at line 23 of file uECC_esp32.cpp.
Referenced by uECC_make_key(), uECC_shared_secret(), and uECC_verify().
| #define ECC_XY_KEY_SIZE (COORD_SIZE_BYTES * 2U) /* X[32] || Y[32] without 0x04 prefix */ |
Definition at line 19 of file uECC_esp32.cpp.
Referenced by uECC_make_key(), uECC_shared_secret(), and uECC_verify().
| #define MBEDTLS_OK (0) |
Definition at line 28 of file uECC_esp32.cpp.
| #define POINT_PREFIX_OFFSET (0U) /* byte offset of the 0x04 prefix */ |
Definition at line 22 of file uECC_esp32.cpp.
Referenced by uECC_shared_secret(), and uECC_verify().
| #define RAW_SIG_R_OFFSET (0U) /* byte offset of r in 64-byte raw sig */ |
Definition at line 24 of file uECC_esp32.cpp.
Referenced by uECC_verify().
| #define RAW_SIG_S_OFFSET (32U) /* byte offset of s in 64-byte raw sig */ |
Definition at line 25 of file uECC_esp32.cpp.
Referenced by uECC_verify().
| #define RNG_ERROR (-1) /* returned by RNG callback on invalid arguments */ |
Definition at line 29 of file uECC_esp32.cpp.
Referenced by esp32_mbedtls_rng().
| #define UECC_FAILURE (0) |
Definition at line 27 of file uECC_esp32.cpp.
Referenced by uECC_make_key(), uECC_shared_secret(), and uECC_verify().
| #define UECC_SUCCESS (1) |
Definition at line 26 of file uECC_esp32.cpp.
| #define UNCOMPRESSED_PREFIX (0x04U) |
Definition at line 21 of file uECC_esp32.cpp.
Referenced by uECC_shared_secret(), and uECC_verify().
| #define UNCOMPRESSED_PUB_SIZE (65U) /* 0x04 || X[32] || Y[32] */ |
Definition at line 20 of file uECC_esp32.cpp.
Referenced by uECC_make_key(), uECC_shared_secret(), and uECC_verify().
|
static |
Definition at line 50 of file uECC_esp32.cpp.
References MBEDTLS_OK, and RNG_ERROR.
Referenced by uECC_make_key(), and uECC_shared_secret().
| int uECC_make_key | ( | uint8_t * | public_key, |
| uint8_t * | private_key, | ||
| const uECC_Curve_t * | curve ) |
Generate an ECC key pair using mbedTLS and the ESP32 hardware RNG.
Definition at line 92 of file uECC_esp32.cpp.
References COORD_SIZE_BYTES, COORD_X_OFFSET, ECC_XY_KEY_SIZE, esp32_mbedtls_rng(), uECC_Curve_t::grp_id, MBEDTLS_OK, UECC_FAILURE, UECC_SUCCESS, and UNCOMPRESSED_PUB_SIZE.
Referenced by ESP32CryptoProvider::makeKey().
| const uECC_Curve_t * uECC_secp256k1 | ( | void | ) |
Return the static secp256k1 curve descriptor.
Definition at line 75 of file uECC_esp32.cpp.
References s_secp256k1.
Referenced by toCurve().
| const uECC_Curve_t * uECC_secp256r1 | ( | void | ) |
Return the static secp256r1 curve descriptor.
Definition at line 70 of file uECC_esp32.cpp.
References s_secp256r1.
Referenced by toCurve().
| void uECC_set_rng | ( | uECC_RNG_Function | rng_function | ) |
No-op: ESP32 hardware RNG is used internally; no external callback needed.
Definition at line 80 of file uECC_esp32.cpp.
References UECC_LOG_TAG.
| int uECC_shared_secret | ( | const uint8_t * | public_key, |
| const uint8_t * | private_key, | ||
| uint8_t * | secret, | ||
| const uECC_Curve_t * | curve ) |
Compute ECDH shared secret (X-coordinate of privKey * pubKey).
Definition at line 144 of file uECC_esp32.cpp.
References COORD_SIZE_BYTES, COORD_X_OFFSET, ECC_XY_KEY_SIZE, esp32_mbedtls_rng(), uECC_Curve_t::grp_id, MBEDTLS_OK, POINT_PREFIX_OFFSET, UECC_FAILURE, UECC_SUCCESS, UNCOMPRESSED_PREFIX, and UNCOMPRESSED_PUB_SIZE.
Referenced by ESP32CryptoProvider::ecdh().
| int uECC_verify | ( | const uint8_t * | public_key, |
| const uint8_t * | hash, | ||
| unsigned | hash_size, | ||
| const uint8_t * | signature, | ||
| const uECC_Curve_t * | curve ) |
Verify an ECDSA signature (raw 64-byte r||s) against a hash.
Definition at line 210 of file uECC_esp32.cpp.
References COORD_SIZE_BYTES, COORD_X_OFFSET, ECC_XY_KEY_SIZE, uECC_Curve_t::grp_id, MBEDTLS_OK, POINT_PREFIX_OFFSET, RAW_SIG_R_OFFSET, RAW_SIG_S_OFFSET, UECC_FAILURE, UECC_SUCCESS, UNCOMPRESSED_PREFIX, and UNCOMPRESSED_PUB_SIZE.
Referenced by ESP32CryptoProvider::ecdsaVerify().
|
static |
Definition at line 44 of file uECC_esp32.cpp.
Referenced by uECC_secp256k1().
|
static |
Definition at line 43 of file uECC_esp32.cpp.
Referenced by uECC_secp256r1().
|
static |
Definition at line 18 of file uECC_esp32.cpp.
Referenced by uECC_set_rng().