1
0
mirror of https://github.com/taigrr/arduinolibs synced 2025-01-18 04:33:12 -08:00

Make the Crypto examples work for ESP8266

This commit is contained in:
Rhys Weatherley
2018-04-01 15:58:00 +10:00
parent 990ae0ea37
commit 511cd8f77c
15 changed files with 135 additions and 8 deletions

View File

@@ -36,4 +36,11 @@ inline void clean(T &var)
bool secure_compare(const void *data1, const void *data2, size_t len);
#if defined(ESP8266)
extern "C" void system_soft_wdt_feed(void);
#define crypto_feed_watchdog() system_soft_wdt_feed()
#else
#define crypto_feed_watchdog() do { ; } while (0)
#endif
#endif

View File

@@ -934,6 +934,7 @@ void Curve25519::mul(limb_t *result, const limb_t *x, const limb_t *y)
mulNoReduce(temp, x, y);
reduce(result, temp, NUM_LIMBS_256BIT);
strict_clean(temp);
crypto_feed_watchdog();
}
/**

View File

@@ -965,6 +965,7 @@ void P521::mul(limb_t *result, const limb_t *x, const limb_t *y)
mulNoReduce(temp, x, y);
reduce(result, temp);
strict_clean(temp);
crypto_feed_watchdog();
}
/**

View File

@@ -76,6 +76,7 @@ byte buffer[16];
void testCipher(BlockCipher *cipher, const struct TestVector *test)
{
crypto_feed_watchdog();
Serial.print(test->name);
Serial.print(" Encryption ... ");
cipher->setKey(test->key, cipher->keySize());
@@ -100,6 +101,8 @@ void perfCipher(BlockCipher *cipher, const struct TestVector *test)
unsigned long elapsed;
int count;
crypto_feed_watchdog();
Serial.print(test->name);
Serial.print(" Set Key ... ");
start = micros();

View File

@@ -27,7 +27,11 @@ This example runs tests on the BLAKE2b implementation to verify correct behaviou
#include <Crypto.h>
#include <BLAKE2b.h>
#include <string.h>
#if defined(ESP8266)
#include <pgmspace.h>
#else
#include <avr/pgmspace.h>
#endif
#define HASH_SIZE 64
#define BLOCK_SIZE 128

View File

@@ -27,7 +27,11 @@ This example runs tests on the BLAKE2s implementation to verify correct behaviou
#include <Crypto.h>
#include <BLAKE2s.h>
#include <string.h>
#if defined(ESP8266)
#include <pgmspace.h>
#else
#include <avr/pgmspace.h>
#endif
#define HASH_SIZE 32
#define BLOCK_SIZE 64

View File

@@ -27,7 +27,11 @@ This example runs tests on the ChaCha implementation to verify correct behaviour
#include <Crypto.h>
#include <ChaCha.h>
#include <string.h>
#if defined(ESP8266)
#include <pgmspace.h>
#else
#include <avr/pgmspace.h>
#endif
#define MAX_PLAINTEXT_SIZE 64
#define MAX_CIPHERTEXT_SIZE 64

View File

@@ -28,7 +28,11 @@ correct behaviour.
#include <Crypto.h>
#include <ChaChaPoly.h>
#include <string.h>
#if defined(ESP8266)
#include <pgmspace.h>
#else
#include <avr/pgmspace.h>
#endif
#define MAX_PLAINTEXT_LEN 265

View File

@@ -30,7 +30,11 @@ This example runs tests on the EAX implementation to verify correct behaviour.
#include <Speck.h>
#include <SpeckTiny.h>
#include <string.h>
#if defined(ESP8266)
#include <pgmspace.h>
#else
#include <avr/pgmspace.h>
#endif
#define MAX_PLAINTEXT_LEN 64
@@ -244,6 +248,8 @@ bool testCipher_N(AuthenticatedCipher *cipher, const struct TestVector *test, si
size_t posn, len;
uint8_t tag[16];
crypto_feed_watchdog();
cipher->clear();
if (!cipher->setKey(test->key, 16)) {
Serial.print("setKey ");
@@ -344,6 +350,8 @@ void perfCipherSetKey(AuthenticatedCipher *cipher, const struct TestVector *test
unsigned long elapsed;
int count;
crypto_feed_watchdog();
memcpy_P(&testVector, test, sizeof(TestVector));
test = &testVector;
@@ -371,6 +379,8 @@ void perfCipherEncrypt(AuthenticatedCipher *cipher, const struct TestVector *tes
unsigned long elapsed;
int count;
crypto_feed_watchdog();
memcpy_P(&testVector, test, sizeof(TestVector));
test = &testVector;
@@ -399,6 +409,8 @@ void perfCipherDecrypt(AuthenticatedCipher *cipher, const struct TestVector *tes
unsigned long elapsed;
int count;
crypto_feed_watchdog();
memcpy_P(&testVector, test, sizeof(TestVector));
test = &testVector;
@@ -427,6 +439,8 @@ void perfCipherAddAuthData(AuthenticatedCipher *cipher, const struct TestVector
unsigned long elapsed;
int count;
crypto_feed_watchdog();
memcpy_P(&testVector, test, sizeof(TestVector));
test = &testVector;
@@ -456,6 +470,8 @@ void perfCipherComputeTag(AuthenticatedCipher *cipher, const struct TestVector *
unsigned long elapsed;
int count;
crypto_feed_watchdog();
memcpy_P(&testVector, test, sizeof(TestVector));
test = &testVector;

View File

@@ -30,7 +30,11 @@ This example runs tests on the GCM implementation to verify correct behaviour.
#include <SpeckTiny.h>
#include <GCM.h>
#include <string.h>
#if defined(ESP8266)
#include <pgmspace.h>
#else
#include <avr/pgmspace.h>
#endif
// There isn't enough memory to test both AES and Speck on the Uno,
// so disable Speck testing on AVR platforms unless explicitly enabled.
@@ -270,6 +274,8 @@ bool testCipher_N(AuthenticatedCipher *cipher, const struct TestVector *test, si
size_t posn, len;
uint8_t tag[16];
crypto_feed_watchdog();
cipher->clear();
if (!cipher->setKey(test->key, cipher->keySize())) {
Serial.print("setKey ");
@@ -367,6 +373,8 @@ void perfCipherSetKey(AuthenticatedCipher *cipher, const struct TestVector *test
unsigned long elapsed;
int count;
crypto_feed_watchdog();
memcpy_P(&testVector, test, sizeof(TestVector));
test = &testVector;
@@ -392,6 +400,8 @@ void perfCipherEncrypt(AuthenticatedCipher *cipher, const struct TestVector *tes
unsigned long elapsed;
int count;
crypto_feed_watchdog();
memcpy_P(&testVector, test, sizeof(TestVector));
test = &testVector;
@@ -418,6 +428,8 @@ void perfCipherDecrypt(AuthenticatedCipher *cipher, const struct TestVector *tes
unsigned long elapsed;
int count;
crypto_feed_watchdog();
memcpy_P(&testVector, test, sizeof(TestVector));
test = &testVector;
@@ -444,6 +456,8 @@ void perfCipherAddAuthData(AuthenticatedCipher *cipher, const struct TestVector
unsigned long elapsed;
int count;
crypto_feed_watchdog();
memcpy_P(&testVector, test, sizeof(TestVector));
test = &testVector;
@@ -471,6 +485,8 @@ void perfCipherComputeTag(AuthenticatedCipher *cipher, const struct TestVector *
unsigned long elapsed;
int count;
crypto_feed_watchdog();
memcpy_P(&testVector, test, sizeof(TestVector));
test = &testVector;

View File

@@ -34,7 +34,11 @@ AVR platforms with 32K or less of flash memory.
#include <RNG.h>
#include <RNG.h>
#include <string.h>
#if defined(ESP8266)
#include <pgmspace.h>
#else
#include <avr/pgmspace.h>
#endif
void printNumber(const char *name, const uint8_t *x, size_t len)
{

View File

@@ -78,6 +78,8 @@ byte buffer[16];
void testCipher(BlockCipher *cipher, const struct TestVector *test, size_t keySize, bool decryption = true)
{
crypto_feed_watchdog();
Serial.print(test->name);
Serial.print(" Encryption ... ");
cipher->setKey(test->key, keySize);
@@ -105,6 +107,8 @@ void perfCipher(BlockCipher *cipher, const struct TestVector *test, size_t keySi
unsigned long elapsed;
int count;
crypto_feed_watchdog();
Serial.print(test->name);
Serial.print(" Set Key ... ");
start = micros();

View File

@@ -31,7 +31,11 @@ This example runs tests on the XTS implementation to verify correct behaviour.
#include <SpeckTiny.h>
#include <XTS.h>
#include <string.h>
#if defined(ESP8266)
#include <pgmspace.h>
#else
#include <avr/pgmspace.h>
#endif
#define MAX_SECTOR_SIZE 64
@@ -207,6 +211,8 @@ void _printProgMem(const char *str)
void testXTS(XTSCommon *cipher, const struct TestVector *test)
{
crypto_feed_watchdog();
memcpy_P(&testVector, test, sizeof(testVector));
Serial.print(testVector.name);
@@ -261,6 +267,8 @@ void perfEncrypt(const char *name, XTSCommon *cipher, const struct TestVector *t
unsigned long elapsed;
int count;
crypto_feed_watchdog();
memcpy_P(&testVector, test, sizeof(testVector));
Serial.print(name);
@@ -288,6 +296,8 @@ void perfDecrypt(const char *name, XTSCommon *cipher, const struct TestVector *t
unsigned long elapsed;
int count;
crypto_feed_watchdog();
memcpy_P(&testVector, test, sizeof(testVector));
Serial.print(name);
@@ -314,6 +324,8 @@ void perfSetKey(const char *name, XTSCommon *cipher, const struct TestVector *te
unsigned long elapsed;
int count;
crypto_feed_watchdog();
memcpy_P(&testVector, test, sizeof(testVector));
Serial.print(name);
@@ -337,6 +349,8 @@ void perfSetTweak(const char *name, XTSCommon *cipher, const struct TestVector *
unsigned long elapsed;
int count;
crypto_feed_watchdog();
memcpy_P(&testVector, test, sizeof(testVector));
Serial.print(name);