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

Finalization and key setup figures for hash/auth algorithms

This commit is contained in:
Rhys Weatherley
2015-04-02 16:33:47 +10:00
parent d50a7fed2d
commit 47ab405e7f
10 changed files with 392 additions and 19 deletions

View File

@@ -224,6 +224,28 @@ void testHMAC(Hash *hash, size_t keyLen)
Serial.println("Failed");
}
void perfFinalize(Hash *hash)
{
unsigned long start;
unsigned long elapsed;
int count;
Serial.print("Finalizing ... ");
hash->reset();
hash->update("abc", 3);
start = micros();
for (count = 0; count < 1000; ++count) {
hash->finalize(buffer, hash->hashSize());
}
elapsed = micros() - start;
Serial.print(elapsed / 1000.0);
Serial.print("us per op, ");
Serial.print((1000.0 * 1000000.0) / elapsed);
Serial.println(" ops per second");
}
void setup()
{
Serial.begin(9600);
@@ -250,6 +272,7 @@ void setup()
Serial.println("Performance Tests:");
perfHash(&blake2b);
perfFinalize(&blake2b);
}
void loop()

View File

@@ -208,6 +208,66 @@ void testHMAC(Hash *hash, size_t keyLen)
Serial.println("Failed");
}
void perfFinalize(Hash *hash)
{
unsigned long start;
unsigned long elapsed;
int count;
Serial.print("Finalizing ... ");
hash->reset();
hash->update("abc", 3);
start = micros();
for (count = 0; count < 1000; ++count) {
hash->finalize(buffer, hash->hashSize());
}
elapsed = micros() - start;
Serial.print(elapsed / 1000.0);
Serial.print("us per op, ");
Serial.print((1000.0 * 1000000.0) / elapsed);
Serial.println(" ops per second");
}
void perfHMAC(Hash *hash)
{
unsigned long start;
unsigned long elapsed;
int count;
Serial.print("HMAC Reset ... ");
for (size_t posn = 0; posn < sizeof(buffer); ++posn)
buffer[posn] = (uint8_t)posn;
start = micros();
for (count = 0; count < 1000; ++count) {
hash->resetHMAC(buffer, hash->hashSize());
}
elapsed = micros() - start;
Serial.print(elapsed / 1000.0);
Serial.print("us per op, ");
Serial.print((1000.0 * 1000000.0) / elapsed);
Serial.println(" ops per second");
Serial.print("HMAC Finalize ... ");
hash->resetHMAC(buffer, hash->hashSize());
hash->update("abc", 3);
start = micros();
for (count = 0; count < 1000; ++count) {
hash->finalizeHMAC(buffer, hash->hashSize(), buffer, hash->hashSize());
}
elapsed = micros() - start;
Serial.print(elapsed / 1000.0);
Serial.print("us per op, ");
Serial.print((1000.0 * 1000000.0) / elapsed);
Serial.println(" ops per second");
}
void setup()
{
Serial.begin(9600);
@@ -234,6 +294,8 @@ void setup()
Serial.println("Performance Tests:");
perfHash(&blake2s);
perfFinalize(&blake2s);
perfHMAC(&blake2s);
}
void loop()

View File

@@ -174,6 +174,48 @@ void perfGHASH(GHASH *hash)
Serial.println(" bytes per second");
}
void perfGHASHSetKey(GHASH *hash)
{
unsigned long start;
unsigned long elapsed;
int count;
Serial.print("Set Key ... ");
start = micros();
for (count = 0; count < 1000; ++count) {
hash->reset(testVectorGHASH_1.key);
}
elapsed = micros() - start;
Serial.print(elapsed / 1000.0);
Serial.print("us per op, ");
Serial.print((1000.0 * 1000000.0) / elapsed);
Serial.println(" ops per second");
}
void perfGHASHFinalize(GHASH *hash)
{
unsigned long start;
unsigned long elapsed;
int count;
Serial.print("Finalize ... ");
hash->reset(testVectorGHASH_1.key);
hash->update("abc", 3);
start = micros();
for (count = 0; count < 1000; ++count) {
hash->finalize(buffer, 16);
}
elapsed = micros() - start;
Serial.print(elapsed / 1000.0);
Serial.print("us per op, ");
Serial.print((1000.0 * 1000000.0) / elapsed);
Serial.println(" ops per second");
}
void setup()
{
Serial.begin(9600);
@@ -194,6 +236,8 @@ void setup()
Serial.println("Performance Tests:");
perfGHASH(&ghash);
perfGHASHSetKey(&ghash);
perfGHASHFinalize(&ghash);
}
void loop()

View File

@@ -167,6 +167,48 @@ void perfPoly1305(Poly1305 *hash)
Serial.println(" bytes per second");
}
void perfPoly1305SetKey(Poly1305 *hash)
{
unsigned long start;
unsigned long elapsed;
int count;
Serial.print("Set Key ... ");
start = micros();
for (count = 0; count < 1000; ++count) {
hash->reset(testVectorPoly1305_1.key);
}
elapsed = micros() - start;
Serial.print(elapsed / 1000.0);
Serial.print("us per op, ");
Serial.print((1000.0 * 1000000.0) / elapsed);
Serial.println(" ops per second");
}
void perfPoly1305Finalize(Poly1305 *hash)
{
unsigned long start;
unsigned long elapsed;
int count;
Serial.print("Finalize ... ");
hash->reset(testVectorPoly1305_1.key);
hash->update("abc", 3);
start = micros();
for (count = 0; count < 1000; ++count) {
hash->finalize(testVectorPoly1305_1.nonce, buffer, 16);
}
elapsed = micros() - start;
Serial.print(elapsed / 1000.0);
Serial.print("us per op, ");
Serial.print((1000.0 * 1000000.0) / elapsed);
Serial.println(" ops per second");
}
void setup()
{
Serial.begin(9600);
@@ -187,6 +229,8 @@ void setup()
Serial.println("Performance Tests:");
perfPoly1305(&poly1305);
perfPoly1305SetKey(&poly1305);
perfPoly1305Finalize(&poly1305);
}
void loop()

View File

@@ -224,6 +224,66 @@ void perfHash(Hash *hash)
Serial.println(" bytes per second");
}
void perfFinalize(Hash *hash)
{
unsigned long start;
unsigned long elapsed;
int count;
Serial.print("Finalizing ... ");
hash->reset();
hash->update("abc", 3);
start = micros();
for (count = 0; count < 1000; ++count) {
hash->finalize(buffer, hash->hashSize());
}
elapsed = micros() - start;
Serial.print(elapsed / 1000.0);
Serial.print("us per op, ");
Serial.print((1000.0 * 1000000.0) / elapsed);
Serial.println(" ops per second");
}
void perfHMAC(Hash *hash)
{
unsigned long start;
unsigned long elapsed;
int count;
Serial.print("HMAC Reset ... ");
for (size_t posn = 0; posn < sizeof(buffer); ++posn)
buffer[posn] = (uint8_t)posn;
start = micros();
for (count = 0; count < 1000; ++count) {
hash->resetHMAC(buffer, hash->hashSize());
}
elapsed = micros() - start;
Serial.print(elapsed / 1000.0);
Serial.print("us per op, ");
Serial.print((1000.0 * 1000000.0) / elapsed);
Serial.println(" ops per second");
Serial.print("HMAC Finalize ... ");
hash->resetHMAC(buffer, hash->hashSize());
hash->update("abc", 3);
start = micros();
for (count = 0; count < 1000; ++count) {
hash->finalizeHMAC(buffer, hash->hashSize(), buffer, hash->hashSize());
}
elapsed = micros() - start;
Serial.print(elapsed / 1000.0);
Serial.print("us per op, ");
Serial.print((1000.0 * 1000000.0) / elapsed);
Serial.println(" ops per second");
}
void setup()
{
Serial.begin(9600);
@@ -250,6 +310,8 @@ void setup()
Serial.println("Performance Tests:");
perfHash(&sha1);
perfFinalize(&sha1);
perfHMAC(&sha1);
}
void loop()

View File

@@ -228,6 +228,66 @@ void perfHash(Hash *hash)
Serial.println(" bytes per second");
}
void perfFinalize(Hash *hash)
{
unsigned long start;
unsigned long elapsed;
int count;
Serial.print("Finalizing ... ");
hash->reset();
hash->update("abc", 3);
start = micros();
for (count = 0; count < 1000; ++count) {
hash->finalize(buffer, hash->hashSize());
}
elapsed = micros() - start;
Serial.print(elapsed / 1000.0);
Serial.print("us per op, ");
Serial.print((1000.0 * 1000000.0) / elapsed);
Serial.println(" ops per second");
}
void perfHMAC(Hash *hash)
{
unsigned long start;
unsigned long elapsed;
int count;
Serial.print("HMAC Reset ... ");
for (size_t posn = 0; posn < sizeof(buffer); ++posn)
buffer[posn] = (uint8_t)posn;
start = micros();
for (count = 0; count < 1000; ++count) {
hash->resetHMAC(buffer, hash->hashSize());
}
elapsed = micros() - start;
Serial.print(elapsed / 1000.0);
Serial.print("us per op, ");
Serial.print((1000.0 * 1000000.0) / elapsed);
Serial.println(" ops per second");
Serial.print("HMAC Finalize ... ");
hash->resetHMAC(buffer, hash->hashSize());
hash->update("abc", 3);
start = micros();
for (count = 0; count < 1000; ++count) {
hash->finalizeHMAC(buffer, hash->hashSize(), buffer, hash->hashSize());
}
elapsed = micros() - start;
Serial.print(elapsed / 1000.0);
Serial.print("us per op, ");
Serial.print((1000.0 * 1000000.0) / elapsed);
Serial.println(" ops per second");
}
void setup()
{
Serial.begin(9600);
@@ -254,6 +314,8 @@ void setup()
Serial.println("Performance Tests:");
perfHash(&sha256);
perfFinalize(&sha256);
perfHMAC(&sha256);
}
void loop()

View File

@@ -261,6 +261,32 @@ void testHMAC(Hash *hash, size_t keyLen)
Serial.println("Failed");
}
/*
void perfFinalize(Hash *hash)
{
unsigned long start;
unsigned long elapsed;
int count;
// Reuse one of the test vectors as a large temporary buffer.
uint8_t *buffer = (uint8_t *)&testVectorSHA3_256_5;
Serial.print("Finalizing ... ");
hash->reset();
hash->update("abc", 3);
start = micros();
for (count = 0; count < 1000; ++count) {
hash->finalize(buffer, hash->hashSize());
}
elapsed = micros() - start;
Serial.print(elapsed / 1000.0);
Serial.print("us per op, ");
Serial.print((1000.0 * 1000000.0) / elapsed);
Serial.println(" ops per second");
}
*/
void setup()
{
Serial.begin(9600);
@@ -288,6 +314,7 @@ void setup()
Serial.println("Performance Tests:");
perfHash(&sha3_256);
//perfFinalize(&sha3_256);
}
void loop()

View File

@@ -263,6 +263,30 @@ void testHMAC(Hash *hash, size_t keyLen)
Serial.println("Failed");
}
/*
void perfFinalize(Hash *hash)
{
unsigned long start;
unsigned long elapsed;
int count;
Serial.print("Finalizing ... ");
hash->reset();
hash->update("abc", 3);
start = micros();
for (count = 0; count < 1000; ++count) {
hash->finalize(buffer, hash->hashSize());
}
elapsed = micros() - start;
Serial.print(elapsed / 1000.0);
Serial.print("us per op, ");
Serial.print((1000.0 * 1000000.0) / elapsed);
Serial.println(" ops per second");
}
*/
void setup()
{
Serial.begin(9600);
@@ -290,6 +314,7 @@ void setup()
Serial.println("Performance Tests:");
perfHash(&sha3_512);
//perfFinalize(&sha3_512);
}
void loop()

View File

@@ -211,6 +211,28 @@ void testHMAC(Hash *hash, size_t keyLen)
Serial.println("Failed");
}
void perfFinalize(Hash *hash)
{
unsigned long start;
unsigned long elapsed;
int count;
Serial.print("Finalizing ... ");
hash->reset();
hash->update("abc", 3);
start = micros();
for (count = 0; count < 1000; ++count) {
hash->finalize(buffer, hash->hashSize());
}
elapsed = micros() - start;
Serial.print(elapsed / 1000.0);
Serial.print("us per op, ");
Serial.print((1000.0 * 1000000.0) / elapsed);
Serial.println(" ops per second");
}
void setup()
{
Serial.begin(9600);
@@ -236,6 +258,7 @@ void setup()
Serial.println("Performance Tests:");
perfHash(&sha512);
perfFinalize(&sha512);
}
void loop()