Add tests to all implementations

This commit is contained in:
Manuel Thalmann 2023-12-19 18:11:26 +01:00
parent 626c68b9e2
commit 528944434d
4 changed files with 47 additions and 1 deletions

View file

@ -1,4 +1,4 @@
CPPFLAGS ?= -Ofast
CPPFLAGS ?= -g
BUILD_DIR = bin

View file

@ -1,5 +1,6 @@
#include <chrono>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <stdint.h>
#include <stdlib.h>
@ -190,6 +191,7 @@ int main(int argc, char* argv[])
uint32_t cycles = 1000000;
uint8_t key[16] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff };
uint8_t in[16] = { 0xab, 0xcd, 0xef, 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x01, 0x23, 0x45, 0x67, 0x89};
uint8_t expected[16] = { 0x1d, 0x07, 0x34, 0x40, 0xeb, 0xbe, 0x24, 0xc5, 0x02, 0x8b, 0xd8, 0x02, 0x65, 0xc8, 0xfb, 0x1d };
if (argc > 2) {
std::cerr << "Invalid number of arguments\n";
@ -210,5 +212,19 @@ int main(int argc, char* argv[])
std::cout << "AES (" << cycles << " runs)\nElapsed time: ";
std::cout << milliseconds << "ms\n"; // Before C++20
if (cycles == 1000000) {
for (int i = 0; i < 16; i++) {
if (in[i] != expected[i]) {
std::cout << "Mismatch at out[" << i << "]!\n";
exit(EXIT_FAILURE);
}
}
std::cout << "Validation successful!\n";
} else {
std::cout << "No results for " << cycles << " cycles precomputed. No validation.";
}
exit(in[0]);
}

View file

@ -105,6 +105,7 @@ int main(int argc, char* argv[])
uint32_t cycles = 1000000;
__m128i key = _mm_setr_epi8(0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff);
__m128i value = _mm_setr_epi8(0xab, 0xcd, 0xef, 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x01, 0x23, 0x45, 0x67, 0x89);
uint8_t expected[16] = { 0x1d, 0x07, 0x34, 0x40, 0xeb, 0xbe, 0x24, 0xc5, 0x02, 0x8b, 0xd8, 0x02, 0x65, 0xc8, 0xfb, 0x1d };
if (argc > 2) {
std::cerr << "Invalid number of arguments\n";
@ -125,5 +126,19 @@ int main(int argc, char* argv[])
std::cout << "AES (" << cycles << " runs)\nElapsed time: ";
std::cout << milliseconds << "ms\n"; // Before C++20
if (cycles == 1000000) {
for (int i = 0; i < 16; i++) {
if (((uint8_t *)&value)[i] != expected[i]) {
std::cout << "Mismatch at out[" << i << "]!\n";
exit(EXIT_FAILURE);
}
}
std::cout << "Validation successful!\n";
} else {
std::cout << "No results for " << cycles << " cycles precomputed. No validation.";
}
exit(value[0]);
}

View file

@ -184,6 +184,7 @@ int main(int argc, char* argv[])
uint32_t cycles = 1000000;
uint8_t key[16] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff };
uint8_t in[16] = { 0xab, 0xcd, 0xef, 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x01, 0x23, 0x45, 0x67, 0x89};
uint8_t expected[16] = { 0x1d, 0x07, 0x34, 0x40, 0xeb, 0xbe, 0x24, 0xc5, 0x02, 0x8b, 0xd8, 0x02, 0x65, 0xc8, 0xfb, 0x1d };
if (argc > 2) {
std::cerr << "Invalid number of arguments\n";
@ -214,5 +215,19 @@ int main(int argc, char* argv[])
std::cout << "AES (" << cycles << " runs)\nElapsed time: ";
std::cout << milliseconds << "ms\n"; // Before C++20
if (cycles == 1000000) {
for (int i = 0; i < 16; i++) {
if (in[i] != expected[i]) {
std::cout << "Mismatch at out[" << i << "]!\n";
exit(EXIT_FAILURE);
}
}
std::cout << "Validation successful!\n";
} else {
std::cout << "No results for " << cycles << " cycles precomputed. No validation.";
}
exit(in[0]);
}