Implement interfaces for ESP32
This commit is contained in:
29
src/crypto/ESP32CryptoSource.cpp
Normal file
29
src/crypto/ESP32CryptoSource.cpp
Normal file
@ -0,0 +1,29 @@
|
||||
#include "interface/ESP32CryptoSource.h"
|
||||
|
||||
#include <Ed25519.h>
|
||||
#include <RNG.h>
|
||||
#include <NoiseSource.h>
|
||||
|
||||
ESP32CryptoSource::ESP32CryptoSource(const char* rngInitTag) {
|
||||
RNG.begin(rngInitTag);
|
||||
RNG.addNoiseSource(noise);
|
||||
}
|
||||
|
||||
bool ESP32CryptoSource::createPrivateKey(PrivateKey* key) {
|
||||
Ed25519::generatePrivateKey(key->bytes);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ESP32CryptoSource::createPublicKey(const PrivateKey* privateKey, PublicKey* publicKey) {
|
||||
Ed25519::derivePublicKey(publicKey->bytes, privateKey->bytes);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ESP32CryptoSource::sign(const uint8_t *message, uint16_t length, Signature* signature, const PrivateKey* privateKey, const PublicKey* publicKey) {
|
||||
Ed25519::sign(signature->bytes, privateKey->bytes, publicKey->bytes, message, length);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ESP32CryptoSource::verify(const Signature* signature, const PublicKey* publicKey, const void *message, uint16_t length) {
|
||||
return Ed25519::verify(signature->bytes, publicKey->bytes, message, length);
|
||||
}
|
18
src/crypto/ESP32NoiseSource.cpp
Normal file
18
src/crypto/ESP32NoiseSource.cpp
Normal file
@ -0,0 +1,18 @@
|
||||
#include "interface/ESP32NoiseSource.h"
|
||||
|
||||
#include <esp_random.h>
|
||||
#include <bootloader_random.h>
|
||||
|
||||
ESP32NoiseSource::ESP32NoiseSource() {
|
||||
// Ensure that there is randomness even if Bluetooth and WiFi are disabled
|
||||
bootloader_random_enable();
|
||||
}
|
||||
|
||||
bool ESP32NoiseSource::calibrating() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
void ESP32NoiseSource::stir() {
|
||||
esp_fill_random(data, randomNumberBatchSize);
|
||||
output(data, randomNumberBatchSize, randomNumberBatchSize * 8);
|
||||
}
|
28
src/crypto/ESP32StorageSource.cpp
Normal file
28
src/crypto/ESP32StorageSource.cpp
Normal file
@ -0,0 +1,28 @@
|
||||
#include "interface/ESP32StorageSource.h"
|
||||
#include <EEPROM.h>
|
||||
|
||||
bool ESP32StorageSource::writeByteAtIndex(uint8_t byte, uint16_t index) {
|
||||
// TODO: What does return value mean?
|
||||
EEPROM.writeByte((int) index, byte);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ESP32StorageSource::canProvideStorageWithSize(uint16_t size) {
|
||||
return EEPROM.begin(size);
|
||||
}
|
||||
|
||||
bool ESP32StorageSource::commitData() {
|
||||
return EEPROM.commit();
|
||||
}
|
||||
|
||||
uint8_t ESP32StorageSource::readByteAtIndex(uint16_t index) {
|
||||
return EEPROM.readByte((int) index);
|
||||
}
|
||||
|
||||
uint16_t ESP32StorageSource::readBytes(uint16_t startIndex, uint16_t count, uint8_t* output) {
|
||||
return EEPROM.readBytes(startIndex, output, count);
|
||||
}
|
||||
|
||||
uint16_t ESP32StorageSource::writeBytes(uint8_t* bytes, uint16_t count, uint16_t startIndex) {
|
||||
return EEPROM.writeBytes(startIndex, bytes, count);
|
||||
}
|
Reference in New Issue
Block a user