|
cryptnox-sdk-esp32 1.0.0
ESP32 SDK for Cryptnox Hardware Wallet
|
CW_CryptoProvider backed by mbedTLS and the ESP32 hardware TRNG. More...
#include <esp32_crypto_provider.h>
Public Member Functions | |
| bool | sha256 (const uint8_t *data, size_t len, uint8_t *out) override |
| Compute SHA-256 over a contiguous buffer. | |
| bool | sha512 (const uint8_t *data, size_t len, uint8_t *out) override |
| Compute SHA-512 over a contiguous buffer. | |
| uint16_t | aesCbcEncrypt (const uint8_t *in, uint16_t len, uint8_t *out, const uint8_t *key, uint8_t keyLen, uint8_t *iv, bool bitPadding) override |
| Encrypt a buffer with AES-CBC. | |
| uint16_t | aesCbcDecrypt (uint8_t *in, uint16_t len, uint8_t *out, const uint8_t *key, uint8_t keyLen, uint8_t *iv, bool bitPadding) override |
| Decrypt a buffer with AES-CBC. | |
| bool | ecdh (const uint8_t *pubKey, const uint8_t *privKey, uint8_t *secret, CW_Curve curve) override |
| Compute an ECDH shared secret. | |
| bool | makeKey (uint8_t *pubKey, uint8_t *privKey, CW_Curve curve) override |
| Generate an ephemeral EC key pair. | |
| bool | random (uint8_t *dest, unsigned size) override |
| Fill a buffer with cryptographically random bytes. | |
| bool | ecdsaVerify (const uint8_t *pubKey64, const uint8_t *hash, size_t hashLen, const uint8_t *sig, CW_Curve curve) override |
| Verify an ECDSA signature. | |
| ~ESP32CryptoProvider () override | |
| Default destructor. | |
CW_CryptoProvider backed by mbedTLS and the ESP32 hardware TRNG.
All operations are stateless; a single instance may be shared across multiple CryptnoxWallet objects (though concurrent use from different RTOS tasks is not thread-safe without external locking).
Definition at line 62 of file esp32_crypto_provider.h.
|
inlineoverride |
Default destructor.
Definition at line 213 of file esp32_crypto_provider.h.
|
override |
Decrypt a buffer with AES-CBC.
AES-CBC decrypt with optional ISO/IEC 9797-1 Method 2 bit-padding removal.
Uses mbedTLS AES-CBC and optionally strips ISO/IEC 7816-4 bit-padding after decryption. The IV is updated in-place.
| [in,out] | in | Ciphertext input buffer; may be modified in-place (must not be NULL). |
| [in] | len | Length of in in bytes (must be a multiple of 16). |
| [out] | out | Plaintext output buffer (must not be NULL). |
| [in] | key | AES key bytes (must not be NULL). |
| [in] | keyLen | Key length in bytes (16 / 24 / 32). |
| [in,out] | iv | 16-byte IV; updated in-place after the call. |
| [in] | bitPadding | When true, strips ISO/IEC 7816-4 bit padding from the decrypted output. |
out, or 0 on failure. Definition at line 147 of file esp32_crypto_provider.cpp.
References AES_BLOCK_SIZE_BYTES, AES_KEY_BITS_PER_BYTE, BIT_PADDING_MARKER, MBEDTLS_OK, and PADDING_ZERO_FILL.
|
override |
Encrypt a buffer with AES-CBC.
AES-CBC encrypt with optional ISO/IEC 9797-1 Method 2 bit padding.
Uses mbedTLS AES-CBC with optional ISO/IEC 7816-4 bit-padding. The IV is updated in-place after each block so that the caller can chain calls for streaming encryption.
| [in] | in | Plaintext input buffer (must not be NULL). |
| [in] | len | Length of in in bytes. |
| [out] | out | Ciphertext output buffer; must be at least len + 16 bytes to accommodate padding. |
| [in] | key | AES key bytes (must not be NULL). |
| [in] | keyLen | Key length in bytes (16 for AES-128, 24 for AES-192, 32 for AES-256). |
| [in,out] | iv | 16-byte IV; updated in-place after the call. |
| [in] | bitPadding | When true, applies ISO/IEC 7816-4 bit padding before encrypting. |
out, or 0 on failure. Definition at line 89 of file esp32_crypto_provider.cpp.
References AES_BLOCK_SIZE_BYTES, AES_KEY_BITS_PER_BYTE, AES_PAD_BUF_SIZE, BIT_PADDING_MARKER, MBEDTLS_OK, and PADDING_ZERO_FILL.
|
override |
Compute an ECDH shared secret.
Compute ECDH shared secret: X-coordinate of privKey * pubKey point.
Performs the standard Diffie-Hellman point multiplication secret = privKey × pubKey on the specified curve via the uECC shim.
| [in] | pubKey | Uncompressed peer public key (64 bytes, X||Y; no 0x04 prefix; must not be NULL). |
| [in] | privKey | 32-byte private scalar (must not be NULL). |
| [out] | secret | 32-byte shared-secret output buffer (must not be NULL). |
| [in] | curve | Elliptic curve selector (CW_CURVE_SECP256R1 or CW_CURVE_SECP256K1). |
true on success, false if point multiplication fails or a pointer argument is NULL. Definition at line 211 of file esp32_crypto_provider.cpp.
References toCurve(), uECC_shared_secret(), and UECC_SUCCESS.
|
override |
Verify an ECDSA signature.
Verify an ECDSA signature (raw r||s) against a hash on the specified curve.
Checks that sig is a valid low-S DER-encoded ECDSA signature over hash produced by the private key corresponding to pubKey64.
| [in] | pubKey64 | 64-byte uncompressed public key (X||Y, no 0x04 prefix; must not be NULL). |
| [in] | hash | Message digest to verify against (must not be NULL). |
| [in] | hashLen | Length of hash in bytes. |
| [in] | sig | DER-encoded signature bytes (must not be NULL). |
| [in] | curve | Elliptic curve selector (CW_CURVE_SECP256R1 or CW_CURVE_SECP256K1). |
true if the signature is valid, false otherwise (including on NULL arguments or malformed DER). Definition at line 250 of file esp32_crypto_provider.cpp.
References toCurve(), UECC_SUCCESS, and uECC_verify().
|
override |
Generate an ephemeral EC key pair.
Generate an ECC key pair via mbedTLS and the ESP32 hardware RNG.
Uses the hardware TRNG (via random) as the entropy source for the private scalar.
| [out] | pubKey | 64-byte uncompressed public key output (X||Y, no 0x04 prefix; must not be NULL). |
| [out] | privKey | 32-byte private key output (must not be NULL). |
| [in] | curve | Elliptic curve selector (CW_CURVE_SECP256R1 or CW_CURVE_SECP256K1). |
true on success, false on RNG or key-generation failure.Definition at line 223 of file esp32_crypto_provider.cpp.
References toCurve(), uECC_make_key(), and UECC_SUCCESS.
|
override |
Fill a buffer with cryptographically random bytes.
Fill dest with size cryptographically random bytes from the ESP32 hardware RNG.
Calls esp_fill_random() which reads from the ESP32 hardware TRNG. Full entropy requires Wi-Fi or Bluetooth to be active; without a live radio the TRNG operates in reduced-entropy mode (thermal noise and ring-oscillator jitter only — see SEC-001).
| [out] | dest | Buffer to fill (must not be NULL). |
| [in] | size | Number of random bytes to generate. |
true on success, false if dest is NULL or size is 0.Definition at line 239 of file esp32_crypto_provider.cpp.
|
override |
Compute SHA-256 over a contiguous buffer.
Compute SHA-256 over the input buffer, writing 32 bytes to out.
Uses the mbedTLS mbedtls_sha256 API, which is hardware-accelerated on ESP32-S3.
| [in] | data | Pointer to the input data (must not be NULL). |
| [in] | len | Length of data in bytes. |
| [out] | out | 32-byte output buffer for the digest (must not be NULL). |
true on success, false if data or out is NULL or if the mbedTLS call fails. Definition at line 73 of file esp32_crypto_provider.cpp.
References MBEDTLS_OK, and MBEDTLS_SHA256_MODE.
|
override |
Compute SHA-512 over a contiguous buffer.
Compute SHA-512 over the input buffer, writing 64 bytes to out.
Uses the mbedTLS mbedtls_sha512 API, which is hardware-accelerated on ESP32-S3.
| [in] | data | Pointer to the input data (must not be NULL). |
| [in] | len | Length of data in bytes. |
| [out] | out | 64-byte output buffer for the digest (must not be NULL). |
true on success, false if data or out is NULL or if the mbedTLS call fails. Definition at line 79 of file esp32_crypto_provider.cpp.
References MBEDTLS_OK, and MBEDTLS_SHA512_MODE.