diff --git a/aes-performance/aes-32bit/Makefile b/aes-performance/aes-32bit/Makefile index 424cce8..be69bea 100644 --- a/aes-performance/aes-32bit/Makefile +++ b/aes-performance/aes-32bit/Makefile @@ -1,4 +1,4 @@ -CPPFLAGS ?= -Ofast +CPPFLAGS ?= -g BUILD_DIR = bin diff --git a/aes-performance/aes-32bit/aes.cpp b/aes-performance/aes-32bit/aes.cpp index 8451dd4..d1e7a44 100644 --- a/aes-performance/aes-32bit/aes.cpp +++ b/aes-performance/aes-32bit/aes.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -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]); } diff --git a/aes-performance/aes-intrinsic/aes.cpp b/aes-performance/aes-intrinsic/aes.cpp index ce8b2d3..134f1b3 100644 --- a/aes-performance/aes-intrinsic/aes.cpp +++ b/aes-performance/aes-intrinsic/aes.cpp @@ -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]); } diff --git a/aes-performance/aes-tboxes/aes.cpp b/aes-performance/aes-tboxes/aes.cpp index 484d4ff..49ea51c 100644 --- a/aes-performance/aes-tboxes/aes.cpp +++ b/aes-performance/aes-tboxes/aes.cpp @@ -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]); }