cryptnox-sdk-esp32 1.0.0
ESP32 SDK for Cryptnox Hardware Wallet
Loading...
Searching...
No Matches
uECC.h
Go to the documentation of this file.
1/*
2 * SPDX-License-Identifier: LGPL-3.0-or-later
3 * Copyright (c) 2026 Cryptnox SA
4 */
5
6#ifndef UECC_H
7#define UECC_H
8
9/*
10 * uECC compatibility shim for ESP32.
11 * Exposes the micro-ecc API surface required by cryptnox-sdk-cpp,
12 * implemented internally via mbedTLS and the ESP32 hardware RNG.
13 */
14
15#ifdef __cplusplus
16extern "C" {
17#endif
18
19#include <stdint.h>
20
21/* Opaque curve descriptor — definition lives in uECC_esp32.cpp. */
23
24/* Return curve descriptors for the two Cryptnox curves. */
25const uECC_Curve_t* uECC_secp256r1(void);
26const uECC_Curve_t* uECC_secp256k1(void);
27
28/*
29 * RNG callback type (micro-ecc compatible).
30 * Returns 1 on success, 0 on failure.
31 */
32typedef int (*uECC_RNG_Function)(uint8_t *dest, unsigned size);
33
34/*
35 * Register an external RNG callback.
36 * On ESP32 this is a no-op — the hardware RNG is used via mbedTLS directly.
37 */
38void uECC_set_rng(uECC_RNG_Function rng_function);
39
40/*
41 * Generate an EC key pair.
42 * public_key [out] 64 bytes: X || Y (uncompressed, no 0x04 prefix).
43 * private_key [out] 32 bytes.
44 * Returns 1 on success, 0 on failure.
45 */
46int uECC_make_key(uint8_t *public_key, uint8_t *private_key,
47 const uECC_Curve_t *curve);
48
49/*
50 * Compute an ECDH shared secret.
51 * public_key [in] 64-byte remote public key (X || Y, no 0x04 prefix).
52 * private_key [in] 32-byte local private key.
53 * secret [out] 32-byte shared secret (X coordinate of d*Q).
54 * Returns 1 on success, 0 on failure.
55 */
56int uECC_shared_secret(const uint8_t *public_key, const uint8_t *private_key,
57 uint8_t *secret, const uECC_Curve_t *curve);
58
59/*
60 * Verify an ECDSA signature.
61 * public_key [in] 64-byte public key (X || Y, no 0x04 prefix).
62 * hash [in] Message hash bytes.
63 * hash_size [in] Hash length in bytes (32 for SHA-256).
64 * signature [in] 64-byte raw signature: r[32] || s[32].
65 * Returns 1 if valid, 0 if invalid.
66 */
67int uECC_verify(const uint8_t *public_key, const uint8_t *hash, unsigned hash_size,
68 const uint8_t *signature, const uECC_Curve_t *curve);
69
70#ifdef __cplusplus
71}
72#endif
73
74#endif /* UECC_H */
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_RNG_Function)(uint8_t *dest, unsigned size)
Definition uECC.h:32
const uECC_Curve_t * uECC_secp256k1(void)
Return the static secp256k1 curve descriptor.
const uECC_Curve_t * uECC_secp256r1(void)
Return the static secp256r1 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_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.