mirror of
https://github.com/taigrr/arduinolibs
synced 2025-01-18 04:33:12 -08:00
Overview documentation for the Crypto library
This commit is contained in:
@@ -291,6 +291,39 @@ void testCipher(ChaCha *cipher, const struct TestVector *test)
|
||||
Serial.println("Failed");
|
||||
}
|
||||
|
||||
// The data space of this sketch is too big if we try to test the
|
||||
// performance of all of setKey(), encrypt(), and decrypt().
|
||||
// Since decryption is almost identical to encryption, only test
|
||||
// that if the PERF_DECRYPT option is enabled, suppressing setKey().
|
||||
//#define PERF_DECRYPT 1
|
||||
|
||||
#if !defined(PERF_DECRYPT)
|
||||
|
||||
void perfCipherSetKey(ChaCha *cipher, const struct TestVector *test)
|
||||
{
|
||||
unsigned long start;
|
||||
unsigned long elapsed;
|
||||
int count;
|
||||
|
||||
Serial.print(test->name);
|
||||
Serial.print(" SetKey ... ");
|
||||
|
||||
cipher->setNumRounds(test->rounds);
|
||||
start = micros();
|
||||
for (count = 0; count < 1000; ++count) {
|
||||
cipher->setKey(test->key, test->keySize);
|
||||
cipher->setIV(test->iv, 8);
|
||||
}
|
||||
elapsed = micros() - start;
|
||||
|
||||
Serial.print(elapsed / 1000.0);
|
||||
Serial.print("us per operation, ");
|
||||
Serial.print((1000.0 * 1000000.0) / elapsed);
|
||||
Serial.println(" per second");
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void perfCipherEncrypt(ChaCha *cipher, const struct TestVector *test)
|
||||
{
|
||||
unsigned long start;
|
||||
@@ -315,6 +348,8 @@ void perfCipherEncrypt(ChaCha *cipher, const struct TestVector *test)
|
||||
Serial.println(" bytes per second");
|
||||
}
|
||||
|
||||
#if defined(PERF_DECRYPT)
|
||||
|
||||
void perfCipherDecrypt(ChaCha *cipher, const struct TestVector *test)
|
||||
{
|
||||
unsigned long start;
|
||||
@@ -339,10 +374,17 @@ void perfCipherDecrypt(ChaCha *cipher, const struct TestVector *test)
|
||||
Serial.println(" bytes per second");
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void perfCipher(ChaCha *cipher, const struct TestVector *test)
|
||||
{
|
||||
#if !defined(PERF_DECRYPT)
|
||||
perfCipherSetKey(cipher, test);
|
||||
perfCipherEncrypt(cipher, test);
|
||||
#else
|
||||
perfCipherEncrypt(cipher, test);
|
||||
perfCipherDecrypt(cipher, test);
|
||||
#endif
|
||||
}
|
||||
|
||||
void setup()
|
||||
|
||||
Reference in New Issue
Block a user