cryptnox-sdk-arduino 1.0.0
Arduino library for Cryptnox Hardware Wallet
Loading...
Searching...
No Matches
ArduinoCryptoProvider.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
20
21#ifndef ARDUINOCRYPTOPROVIDER_H
22#define ARDUINOCRYPTOPROVIDER_H
23
24#include <Arduino.h>
25#include <uECC.h>
27#include "AESLib.h"
28
64public:
69
72
75
89 bool sha256(const uint8_t* data, size_t len, uint8_t* out) override;
90
102 bool sha512(const uint8_t* data, size_t len, uint8_t* out) override;
103
117 uint16_t aesCbcEncrypt(const uint8_t* in, uint16_t len, uint8_t* out,
118 const uint8_t* key, uint8_t keyLen,
119 uint8_t* iv, bool bitPadding) override;
120
133 uint16_t aesCbcDecrypt(uint8_t* in, uint16_t len, uint8_t* out,
134 const uint8_t* key, uint8_t keyLen,
135 uint8_t* iv, bool bitPadding) override;
136
152 bool ecdh(const uint8_t* pubKey, const uint8_t* privKey,
153 uint8_t* secret, CW_Curve curve) override;
154
170 bool makeKey(uint8_t* pubKey, uint8_t* privKey,
171 CW_Curve curve) override;
172
183 bool random(uint8_t* dest, unsigned size) override;
184
199 bool ecdsaVerify(const uint8_t* pubKey64,
200 const uint8_t* hash, size_t hashLen,
201 const uint8_t* sig, CW_Curve curve) override;
203
204private:
205 AESLib _aes;
206
213 static const uECC_Curve_t* toUEccCurve(CW_Curve curve);
214
222 static uint8_t trngByte();
223
231 static int trngCallback(uint8_t* dest, unsigned size);
232};
233
234#endif // ARDUINOCRYPTOPROVIDER_H
Abstract cryptographic primitives interface.
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
AES-CBC decrypt (selectable bit / null padding).
static uint8_t trngByte()
Generate one random byte from the RA4M1 hardware TRNG.
ArduinoCryptoProvider & operator=(const ArduinoCryptoProvider &)=delete
bool makeKey(uint8_t *pubKey, uint8_t *privKey, CW_Curve curve) override
Generate a fresh EC keypair via micro-ecc.
static const uECC_Curve_t * toUEccCurve(CW_Curve curve)
Translate a portable CW_Curve to the matching micro-ecc descriptor.
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
AES-CBC encrypt (selectable bit / null padding).
bool sha512(const uint8_t *data, size_t len, uint8_t *out) override
Compute SHA-512 over a contiguous buffer.
bool ecdsaVerify(const uint8_t *pubKey64, const uint8_t *hash, size_t hashLen, const uint8_t *sig, CW_Curve curve) override
Verify a raw r||s ECDSA signature against a message hash.
AESLib _aes
AESLib engine instance reused across all aesCbc* calls.
bool sha256(const uint8_t *data, size_t len, uint8_t *out) override
Compute SHA-256 over a contiguous buffer.
ArduinoCryptoProvider(const ArduinoCryptoProvider &)=delete
static int trngCallback(uint8_t *dest, unsigned size)
Static RNG callback registered with uECC_set_rng().
ArduinoCryptoProvider()
Construct the provider and install the RA4M1 TRNG into micro-ecc.
bool random(uint8_t *dest, unsigned size) override
Fill a buffer with random bytes from the RA4M1 hardware TRNG.
bool ecdh(const uint8_t *pubKey, const uint8_t *privKey, uint8_t *secret, CW_Curve curve) override
Compute the ECDH shared secret on a portable curve identifier.
Abstract interface for cryptographic operations used by CW_SecureChannel.
CW_Curve
Portable curve identifier used throughout the SDK.
Definition CW_Defs.h:151