44#if uECC_SUPPORTS_secp256k1
58 static bool initialized =
false;
73 if ((dest != NULL) && (size > 0U)) {
74 for (
unsigned i = 0U; i < size; i++) {
86 if (out == NULL) {
return false; }
88 if ((data == NULL) && (len > 0U)) {
return false; }
90 sha.update(data, len);
91 sha.finalize(out, 32U);
95 (void)data; (void)len; (void)out;
104 if (out == NULL) {
return false; }
105 if ((data == NULL) && (len > 0U)) {
return false; }
107 sha.update(data, len);
108 sha.finalize(out, 64U);
116 const uint8_t* key, uint8_t keyLen,
117 uint8_t* iv,
bool bitPadding) {
118 _aes.set_paddingmode(bitPadding ? paddingMode::Bit : paddingMode::Null);
119 return _aes.encrypt(
reinterpret_cast<const byte*
>(in), len, out,
120 reinterpret_cast<const byte*
>(key),
static_cast<int>(keyLen), iv);
127 const uint8_t* key, uint8_t keyLen,
128 uint8_t* iv,
bool bitPadding) {
129 _aes.set_paddingmode(bitPadding ? paddingMode::Bit : paddingMode::Null);
130 return _aes.decrypt(in, len, out,
131 reinterpret_cast<const byte*
>(key),
static_cast<int>(keyLen), iv);
140 if (uc == NULL) {
return false; }
141 return (uECC_shared_secret(pubKey, privKey, secret, uc) != 0);
150 if (uc == NULL) {
return false; }
151 return (uECC_make_key(pubKey, privKey, uc) != 0);
165 const uint8_t* hash,
size_t hashLen,
166 const uint8_t* sig,
CW_Curve curve) {
168 if (uc == NULL) {
return false; }
169 return (uECC_verify(pubKey64, hash,
static_cast<unsigned>(hashLen), sig, uc) != 0);
Concrete CW_CryptoProvider for the Arduino UNO R4 (RA4M1).
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.
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.
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.
CW_Curve
Portable curve identifier used throughout the SDK.