diff --git a/.github/workflows/aes-ci.yml b/.github/workflows/aes-ci.yml index af9855a..1613969 100644 --- a/.github/workflows/aes-ci.yml +++ b/.github/workflows/aes-ci.yml @@ -22,13 +22,19 @@ jobs: sudo make sudo cp lib/*.a /usr/lib - - name: Build + - name: Build test run: | - mkdir bin - make workflow_build + make workflow_build_test - - name: Test + - name: Run test run: ./bin/test + - name: Build speed test + run: | + make workflow_build_speed_test + + - name: Run speed test + run: ./bin/speedtest + diff --git a/Makefile b/Makefile index 67c1334..a97f965 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ FLAGS = -Wall -Wextra -build_all: clean build_test build_debug build_profile build_release +build_all: clean build_test build_debug build_profile build_release build_speed_test build_test: docker-compose exec aes g++ $(FLAGS) -g -pthread ./src/AES.cpp ./tests/tests.cpp /usr/lib/libgtest.a -o bin/test @@ -11,9 +11,14 @@ build_debug: build_profile: docker-compose exec aes g++ $(FLAGS) -pg ./src/AES.cpp ./dev/main.cpp -o bin/profile +build_speed_test: + docker-compose exec aes g++ $(FLAGS) -O2 ./src/AES.cpp ./speedtest/main.cpp -o bin/speedtest + build_release: docker-compose exec aes g++ $(FLAGS) -O2 ./src/AES.cpp ./dev/main.cpp -o bin/release + + test: docker-compose exec aes bin/test @@ -26,11 +31,16 @@ profile: release: docker-compose exec aes bin/release +speed_test: + docker-compose exec aes bin/speedtest + clean: - docker-compose exec aes rm -rf bin - docker-compose exec aes mkdir bin -p + docker-compose exec aes rm -rf bin/* + +workflow_build_test: + g++ $(FLAGS) -g -pthread ./src/AES.cpp ./tests/tests.cpp /usr/lib/libgtest.a -o bin/test -workflow_build: - g++ $(FLAGS) -g -pthread ./src/AES.cpp ./tests/tests.cpp /usr/lib/libgtest.a -o bin/test +workflow_build_speed_test: + g++ $(FLAGS) -O2 ./src/AES.cpp ./speedtest/main.cpp -o bin/speedtest diff --git a/README.md b/README.md index 26b753c..6c3fe77 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,7 @@ There are four executables in `bin` folder: * `test` - run tests * `debug` - version for debugging (main code will be taken from dev/main.cpp) * `profile` - version for profiling with gprof (main code will be taken from dev/main.cpp) +* `speedtest` - performance speed test (main code will be taken from speedtest/main.cpp) * `release` - version with optimization (main code will be taken from dev/main.cpp) @@ -58,9 +59,11 @@ Build commands: * `make build_test` - build `test` target * `make build_debug` - build `debug` target * `make build_profile` - build `profile` target +* `make build_speed_test` - build `speedtest` target * `make build_release` - build `release` target * `make test` - run tests * `make debug` - run debug version * `make profile` - run profile version +* `make speedtest` - run performance speed test * `make release` - run `release` version * `make clean` - clean `bin` directory diff --git a/bin/.gitkeep b/bin/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/dev/main.cpp b/dev/main.cpp index dda8ca2..4ba3904 100644 --- a/dev/main.cpp +++ b/dev/main.cpp @@ -1,9 +1,8 @@ #include #include "../src/AES.h" -using namespace std; int main() { - cout << "Aes dev" << endl; + std::cout << "Aes dev" << std::endl; return 0; } diff --git a/speedtest/main.cpp b/speedtest/main.cpp new file mode 100644 index 0000000..c8ba62f --- /dev/null +++ b/speedtest/main.cpp @@ -0,0 +1,52 @@ +#include +#include +#include +#include "../src/AES.h" + +const unsigned int MICROSECONDS = 1000000; +unsigned long getMicroseconds() +{ + struct timeval tv; + gettimeofday(&tv,NULL); + return MICROSECONDS * tv.tv_sec + tv.tv_usec; +} + +unsigned char * getRandomPlain(unsigned int length) +{ + unsigned char *plain = new unsigned char[length]; + for (unsigned int i = 0; i < length; i++) { + plain[i] = rand() % 256; + } + + return plain; + +} + +int main() +{ + const unsigned int MEGABYTE = 1024 * 1024 * sizeof(unsigned char); + + unsigned int len = 0; + unsigned int megabytesCount = 10; + unsigned int plainLength = megabytesCount * MEGABYTE; + unsigned char key[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }; + + std::cout << "Start speedtest" << std::endl; + srand(std::time(nullptr)); + + unsigned char *plain = getRandomPlain(plainLength); + + AES aes(AESKeyLength::AES_256); + unsigned long start = getMicroseconds(); + unsigned char *out = aes.EncryptECB(plain, plainLength, key, len); + unsigned long delta = getMicroseconds() - start; + + double speed = (double)megabytesCount / delta * MICROSECONDS; + + printf("%.2f Mb/s\n", speed); + + delete[] plain; + delete[] out; + + return 0; +} \ No newline at end of file diff --git a/src/AES.cpp b/src/AES.cpp index 353b82b..af30a58 100644 --- a/src/AES.cpp +++ b/src/AES.cpp @@ -486,73 +486,73 @@ void AES::printHexArray (unsigned char a[], unsigned int n) } } -void AES::printHexVector (vector a) +void AES::printHexVector (std::vector a) { for (unsigned int i = 0; i < a.size(); i++) { printf("%02x ", a[i]); } } -vector AES::ArrayToVector(unsigned char *a, unsigned char len) +std::vector AES::ArrayToVector(unsigned char *a, unsigned char len) { - vector v(a, a + len * sizeof(unsigned char)); + std::vector v(a, a + len * sizeof(unsigned char)); return v; } -unsigned char *AES::VectorToArray(vector a) +unsigned char *AES::VectorToArray(std::vector a) { return a.data(); } -vector AES::EncryptECB(vector in, vector key) +std::vector AES::EncryptECB(std::vector in, std::vector key) { unsigned int outLen = 0;; unsigned char *out = EncryptECB(VectorToArray(in), (unsigned int)in.size(), VectorToArray(key), outLen); - vector v = ArrayToVector(out, outLen); + std::vector v = ArrayToVector(out, outLen); delete []out; return v; } -vector AES::DecryptECB(vector in, vector key) +std::vector AES::DecryptECB(std::vector in, std::vector key) { unsigned char *out = DecryptECB(VectorToArray(in), (unsigned int)in.size(), VectorToArray(key)); - vector v = ArrayToVector(out, (unsigned int)in.size()); + std::vector v = ArrayToVector(out, (unsigned int)in.size()); delete []out; return v; } -vector AES::EncryptCBC(vector in, vector key, vector iv) +std::vector AES::EncryptCBC(std::vector in, std::vector key, std::vector iv) { unsigned int outLen = 0; unsigned char *out = EncryptCBC(VectorToArray(in), (unsigned int)in.size(), VectorToArray(key), VectorToArray(iv), outLen); - vector v = ArrayToVector(out, outLen); + std::vector v = ArrayToVector(out, outLen); delete [] out; return v; } -vector AES::DecryptCBC(vector in, vector key, vector iv) +std::vector AES::DecryptCBC(std::vector in, std::vector key, std::vector iv) { unsigned char *out = DecryptCBC(VectorToArray(in), (unsigned int)in.size(), VectorToArray(key), VectorToArray(iv)); - vector v = ArrayToVector(out, (unsigned int)in.size()); + std::vector v = ArrayToVector(out, (unsigned int)in.size()); delete [] out; return v; } - vector AES::EncryptCFB(vector in, vector key, vector iv) +std::vector AES::EncryptCFB(std::vector in, std::vector key, std::vector iv) { unsigned int outLen = 0; unsigned char *out = EncryptCFB(VectorToArray(in), (unsigned int)in.size(), VectorToArray(key), VectorToArray(iv), outLen); - vector v = ArrayToVector(out, outLen); + std::vector v = ArrayToVector(out, outLen); delete [] out; return v; } -vector AES::DecryptCFB(vector in, vector key, vector iv) +std::vector AES::DecryptCFB(std::vector in, std::vector key, std::vector iv) { unsigned char *out = DecryptCFB(VectorToArray(in), (unsigned int)in.size(), VectorToArray(key), VectorToArray(iv)); - vector v = ArrayToVector(out, (unsigned int)in.size()); + std::vector v = ArrayToVector(out, (unsigned int)in.size()); delete [] out; return v; diff --git a/src/AES.h b/src/AES.h index fe0aff7..c5a59d7 100644 --- a/src/AES.h +++ b/src/AES.h @@ -6,8 +6,6 @@ #include #include -using namespace std; - enum class AESKeyLength { AES_128, AES_192, @@ -61,9 +59,9 @@ class AES void XorBlocks(unsigned char *a, unsigned char * b, unsigned char *c, unsigned int len); - vector ArrayToVector(unsigned char *a, unsigned char len); + std::vector ArrayToVector(unsigned char *a, unsigned char len); - unsigned char *VectorToArray(vector a); + unsigned char *VectorToArray(std::vector a); public: explicit AES(AESKeyLength keyLength = AESKeyLength::AES_256); @@ -82,22 +80,22 @@ class AES - vector EncryptECB(vector in, vector key); + std::vector EncryptECB(std::vector in, std::vector key); - vector DecryptECB(vector in, vector key); + std::vector DecryptECB(std::vector in, std::vector key); - vector EncryptCBC(vector in, vector key, vector iv); + std::vector EncryptCBC(std::vector in, std::vector key, std::vector iv); - vector DecryptCBC(vector in, vector key, vector iv); + std::vector DecryptCBC(std::vector in, std::vector key, std::vector iv); - vector EncryptCFB(vector in, vector key, vector iv); + std::vector EncryptCFB(std::vector in, std::vector key, std::vector iv); - vector DecryptCFB(vector in, vector key, vector iv); + std::vector DecryptCFB(std::vector in, std::vector key, std::vector iv); void printHexArray(unsigned char a[], unsigned int n); - void printHexVector(vector a); + void printHexVector(std::vector a); }; const unsigned char sbox[16][16] = { diff --git a/tests/tests.cpp b/tests/tests.cpp index 72a1e9c..18a8cf3 100644 --- a/tests/tests.cpp +++ b/tests/tests.cpp @@ -70,13 +70,13 @@ TEST(ECB, EncryptDecrypt) TEST(ECB, EncryptDecryptVector) { AES aes(AESKeyLength::AES_256); - vector plain = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff }; + std::vector plain = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff }; - vector key = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, + std::vector key = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f }; - vector out = aes.EncryptECB(plain, key); - vector innew = aes.DecryptECB(out, key); + std::vector out = aes.EncryptECB(plain, key); + std::vector innew = aes.DecryptECB(out, key); ASSERT_EQ(innew, plain); } @@ -97,10 +97,10 @@ TEST(ECB, OneBlockEncrypt) TEST(ECB, OneBlockEncryptVector) { AES aes(AESKeyLength::AES_128); - vector plain = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff}; - vector key = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }; - vector right = { 0x69, 0xc4, 0xe0, 0xd8, 0x6a, 0x7b, 0x04, 0x30, 0xd8, 0xcd, 0xb7, 0x80, 0x70, 0xb4, 0xc5, 0x5a}; - vector out = aes.EncryptECB(plain, key); + std::vector plain = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff}; + std::vector key = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }; + std::vector right = { 0x69, 0xc4, 0xe0, 0xd8, 0x6a, 0x7b, 0x04, 0x30, 0xd8, 0xcd, 0xb7, 0x80, 0x70, 0xb4, 0xc5, 0x5a}; + std::vector out = aes.EncryptECB(plain, key); ASSERT_EQ(BLOCK_BYTES_LENGTH, out.size()); @@ -177,10 +177,10 @@ TEST(ECB, OneBlockDecrypt) TEST(ECB, OneBlockDecryptVector) { AES aes(AESKeyLength::AES_128); - vector encrypted = { 0x69, 0xc4, 0xe0, 0xd8, 0x6a, 0x7b, 0x04, 0x30, 0xd8, 0xcd, 0xb7, 0x80, 0x70, 0xb4, 0xc5, 0x5a }; - vector key = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }; - vector right = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff}; - vector out = aes.DecryptECB(encrypted, key); + std::vector encrypted = { 0x69, 0xc4, 0xe0, 0xd8, 0x6a, 0x7b, 0x04, 0x30, 0xd8, 0xcd, 0xb7, 0x80, 0x70, 0xb4, 0xc5, 0x5a }; + std::vector key = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }; + std::vector right = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff}; + std::vector out = aes.DecryptECB(encrypted, key); ASSERT_EQ(right, out); } @@ -224,13 +224,13 @@ TEST(CBC, EncryptDecrypt) TEST(CBC, EncryptDecryptVector) { AES aes(AESKeyLength::AES_256); - vector plain = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff }; - vector iv = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; - vector key = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, + std::vector plain = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff }; + std::vector iv = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; + std::vector key = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f }; - vector out = aes.EncryptCBC(plain, key, iv); - vector innew = aes.DecryptCBC(out, key, iv); + std::vector out = aes.EncryptCBC(plain, key, iv); + std::vector innew = aes.DecryptCBC(out, key, iv); ASSERT_EQ(innew, plain); } @@ -254,14 +254,14 @@ TEST(CBC, TwoBlocksEncrypt) TEST(CBC, TwoBlocksEncryptVector) { AES aes(AESKeyLength::AES_128); - vector plain = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, + std::vector plain = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff }; - vector iv = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; - vector key = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}; - vector right = {0x1b, 0x87, 0x23, 0x78, 0x79, 0x5f, 0x4f, 0xfd, 0x77, 0x28, 0x55, 0xfc, 0x87, 0xca, 0x96, 0x4d, + std::vector iv = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; + std::vector key = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}; + std::vector right = {0x1b, 0x87, 0x23, 0x78, 0x79, 0x5f, 0x4f, 0xfd, 0x77, 0x28, 0x55, 0xfc, 0x87, 0xca, 0x96, 0x4d, 0x4c, 0x5b, 0xca, 0x1c, 0x48, 0xcd, 0x88, 0x00, 0x3a, 0x10, 0x52, 0x11, 0x88, 0x12, 0x5e, 0x00}; - vector out = aes.EncryptCBC(plain, key, iv); + std::vector out = aes.EncryptCBC(plain, key, iv); ASSERT_EQ(out, right); } @@ -287,16 +287,16 @@ TEST(CBC, TwoBlocksDecrypt) TEST(CBC, TwoBlocksDecryptVector) { AES aes(AESKeyLength::AES_128); - vectorencrypted = {0x1b, 0x87, 0x23, 0x78, 0x79, 0x5f, 0x4f, 0xfd, 0x77, 0x28, 0x55, 0xfc, 0x87, 0xca, 0x96, 0x4d, + std::vectorencrypted = {0x1b, 0x87, 0x23, 0x78, 0x79, 0x5f, 0x4f, 0xfd, 0x77, 0x28, 0x55, 0xfc, 0x87, 0xca, 0x96, 0x4d, 0x4c, 0x5b, 0xca, 0x1c, 0x48, 0xcd, 0x88, 0x00, 0x3a, 0x10, 0x52, 0x11, 0x88, 0x12, 0x5e, 0x00}; - vector iv = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; - vector key = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}; - vector right = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, + std::vector iv = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; + std::vector key = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}; + std::vector right = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff }; - vector out = aes.DecryptCBC(encrypted, key, iv); + std::vector out = aes.DecryptCBC(encrypted, key, iv); ASSERT_EQ(out, right); } @@ -322,13 +322,13 @@ TEST(CFB, EncryptDecrypt) TEST(CFB, EncryptDecryptVector) { AES aes(AESKeyLength::AES_256); - vector plain = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff }; - vector iv = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; - vector key = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, + std::vector plain = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff }; + std::vector iv = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; + std::vector key = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f }; - vector out = aes.EncryptCFB(plain, key, iv); - vector innew = aes.DecryptCFB(out, key, iv); + std::vector out = aes.EncryptCFB(plain, key, iv); + std::vector innew = aes.DecryptCFB(out, key, iv); ASSERT_EQ(innew, plain); } @@ -352,14 +352,14 @@ TEST(CFB, EncryptTwoBlocks) TEST(CFB, EncryptTwoBlocksVector) { AES aes(AESKeyLength::AES_128); - vector plain = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, + std::vector plain = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff }; - vector iv = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; - vector key = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}; - vector right = {0x3c, 0x55, 0x3d, 0x01, 0x8a, 0x52, 0xe4, 0x54, 0xec, 0x4e, 0x08, 0x22, 0xc2, 0x8d, 0x55, 0xec, + std::vector iv = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; + std::vector key = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}; + std::vector right = {0x3c, 0x55, 0x3d, 0x01, 0x8a, 0x52, 0xe4, 0x54, 0xec, 0x4e, 0x08, 0x22, 0xc2, 0x8d, 0x55, 0xec, 0xe3, 0x5a, 0x40, 0xab, 0x30, 0x29, 0xf3, 0x0c, 0xe1, 0xdb, 0x30, 0x6c, 0xa1, 0x05, 0xcb, 0xa9}; - vector out = aes.EncryptCFB(plain, key, iv); + std::vector out = aes.EncryptCFB(plain, key, iv); ASSERT_EQ(right, out); } @@ -367,14 +367,14 @@ TEST(CFB, EncryptTwoBlocksVector) TEST(CFB, DecryptTwoBlocks) { AES aes(AESKeyLength::AES_128); - vector encrypted = {0x3c, 0x55, 0x3d, 0x01, 0x8a, 0x52, 0xe4, 0x54, 0xec, 0x4e, 0x08, 0x22, 0xc2, 0x8d, 0x55, 0xec, + std::vector encrypted = {0x3c, 0x55, 0x3d, 0x01, 0x8a, 0x52, 0xe4, 0x54, 0xec, 0x4e, 0x08, 0x22, 0xc2, 0x8d, 0x55, 0xec, 0xe3, 0x5a, 0x40, 0xab, 0x30, 0x29, 0xf3, 0x0c, 0xe1, 0xdb, 0x30, 0x6c, 0xa1, 0x05, 0xcb, 0xa9}; - vector iv = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; - vector key = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}; - vector right = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, + std::vector iv = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; + std::vector key = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}; + std::vector right = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff }; - vector out = aes.DecryptCFB(encrypted, key, iv); + std::vector out = aes.DecryptCFB(encrypted, key, iv); ASSERT_EQ(right, out); }