diff --git a/ChaCha20-Poly1305.cpp b/ChaCha20-Poly1305.cpp index ef5c5c3..f48a6bc 100644 --- a/ChaCha20-Poly1305.cpp +++ b/ChaCha20-Poly1305.cpp @@ -6,38 +6,38 @@ #include "extended-precision-integers/include/epi/epi.hpp" #ifdef _MAKE_LIB -#include "ChaCha20-Poly1305.hpp" + #include "ChaCha20-Poly1305.hpp" #endif #define DEVMODE #ifdef DEVMODE -#include "ChaCha20-Poly1305.hpp" + #include "ChaCha20-Poly1305.hpp" #endif -namespace chacha20 -{ +namespace chacha20 { inline unsigned int bit_left_roll(unsigned int num, size_t n) { unsigned int msb = (num << n); - unsigned int lsb = (num >> (32-n)); + unsigned int lsb = (num >> (32 - n)); return msb | lsb; } void QUARTERROUND(unsigned int *state, size_t x, size_t y, size_t z, size_t w) { - - state[x] += state[y]; state[w] ^= state[x]; state[w] = bit_left_roll(state[w],16); - state[z] += state[w]; state[y] ^= state[z]; state[y] = bit_left_roll(state[y],12); - state[x] += state[y]; state[w] ^= state[x]; state[w] = bit_left_roll(state[w],8); - state[z] += state[w]; state[y] ^= state[z]; state[y] = bit_left_roll(state[y],7); + + state[x] += state[y]; state[w] ^= state[x]; state[w] = bit_left_roll(state[w], 16); + state[z] += state[w]; state[y] ^= state[z]; state[y] = bit_left_roll(state[y], 12); + state[x] += state[y]; state[w] ^= state[x]; state[w] = bit_left_roll(state[w], 8); + state[z] += state[w]; state[y] ^= state[z]; state[y] = bit_left_roll(state[y], 7); } void init_state( // function parameters - unsigned int *output, - const unsigned int *key, - unsigned int counter, - const unsigned int *nonce) { // function body - + unsigned int *output, + const unsigned int *key, + unsigned int counter, + const unsigned int *nonce + ) { // function body + // indecies 0-3 : constants output[0] = 0x61707865; output[1] = 0x3320646e; @@ -64,13 +64,13 @@ namespace chacha20 } void apply_20rounds(unsigned int *output, const unsigned int *input) { - + // copy initial state to state - for(size_t i=0; i(lorem.data()),lorem.size(), - AAD,sizeof(AAD),reinterpret_cast(key.data()),iv,constant + cipher_text, encrypt_mac, reinterpret_cast(lorem.data()), lorem.size(), AAD, sizeof(AAD), + reinterpret_cast(key.data()), iv, constant ); // decryption (with C style casting on parameters). unsigned char *recover_text = new unsigned char[lorem.size()]; - unsigned char *decrypt_mac = new unsigned char[POLY1305_MAC_BYTES]; + unsigned char *decrypt_mac = new unsigned char[POLY1305_MAC_BYTES]; ChaCha20_Poly1305::aead_decrypt( - recover_text,decrypt_mac, - cipher_text,lorem.size(), - AAD,sizeof(AAD),(const unsigned char*)key.data(),iv,constant + recover_text, decrypt_mac, cipher_text, lorem.size(), AAD, sizeof(AAD), (const unsigned char *) key.data(), iv, + constant ); // you can use whatever cast you want C or C++. - + // compare plain text and recovered text bool correct = true; - for(size_t i=0; i(lorem.data()),lorem.size(), - AAD,sizeof(AAD),reinterpret_cast(key.data()),iv,constant + cipher_text, encrypt_mac, reinterpret_cast(lorem.data()), lorem.size(), AAD, sizeof(AAD), + reinterpret_cast(key.data()), iv, constant ); // decryption (with C style casting on parameters). unsigned char *recover_text = new unsigned char[lorem.size()]; - unsigned char *decrypt_mac = new unsigned char[POLY1305_MAC_BYTES]; + unsigned char *decrypt_mac = new unsigned char[POLY1305_MAC_BYTES]; ChaCha20_Poly1305::aead_decrypt( - recover_text,decrypt_mac, - cipher_text,lorem.size(), - AAD,sizeof(AAD),(const unsigned char*)key.data(),iv,constant + recover_text, decrypt_mac, cipher_text, lorem.size(), AAD, sizeof(AAD), (const unsigned char *) key.data(), iv, + constant ); // you can use whatever cast you want C or C++. - + // compare plain text and recovered text bool correct = true; - for(size_t i=0; i #ifndef _MAKE_LIB -#include "../Header-Mode-ChaCha20-Poly1305.hpp" + #include "../Header-Mode-ChaCha20-Poly1305.hpp" #else -#include + #include #endif // ChaCha State Comparison -bool CompareState(unsigned int *A, unsigned int *B){ - for(size_t i=0; i<16; ++i) - if(A[i] != B[i]) +bool CompareState(unsigned int *A, unsigned int *B) { + for (size_t i = 0; i < 16; ++i) + if (A[i] != B[i]) return false; return true; } -int main() -{ - unsigned char key[32] = { - 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 - }; +int main() { + unsigned char key[32] = {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}; - unsigned char nonce[12] = { - 0x00,0x00,0x00,0x09,0x00,0x00, - 0x00,0x4a,0x00,0x00,0x00,0x00 - }; + unsigned char nonce[12] = {0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x4a, 0x00, 0x00, 0x00, 0x00}; - unsigned int correct_output_state[16] = { - 0xe4e7f110, 0x15593bd1, 0x1fdd0f50, 0xc47120a3, - 0xc7f4d1c7, 0x0368c033, 0x9aaa2204, 0x4e6cd4c3, - 0x466482d2, 0x09aa9f07, 0x05d7c214, 0xa2028bd9, - 0xd19c12b5, 0xb94e16de, 0xe883d0cb, 0x4e3c50a2 - }; + unsigned int correct_output_state[16] = {0xe4e7f110, 0x15593bd1, 0x1fdd0f50, 0xc47120a3, 0xc7f4d1c7, 0x0368c033, + 0x9aaa2204, 0x4e6cd4c3, 0x466482d2, 0x09aa9f07, 0x05d7c214, 0xa2028bd9, + 0xd19c12b5, 0xb94e16de, 0xe883d0cb, 0x4e3c50a2}; - unsigned char correct_serial[64] = { - 0x10, 0xf1, 0xe7, 0xe4, 0xd1, 0x3b, 0x59, 0x15, 0x50, 0x0f, 0xdd, 0x1f, 0xa3, 0x20, 0x71, 0xc4, - 0xc7, 0xd1, 0xf4, 0xc7, 0x33, 0xc0, 0x68, 0x03, 0x04, 0x22, 0xaa, 0x9a, 0xc3, 0xd4, 0x6c, 0x4e, - 0xd2, 0x82, 0x64, 0x46, 0x07, 0x9f, 0xaa, 0x09, 0x14, 0xc2, 0xd7, 0x05, 0xd9, 0x8b, 0x02, 0xa2, - 0xb5, 0x12, 0x9c, 0xd1, 0xde, 0x16, 0x4e, 0xb9, 0xcb, 0xd0, 0x83, 0xe8, 0xa2, 0x50, 0x3c, 0x4e - }; + unsigned char correct_serial[64] = {0x10, 0xf1, 0xe7, 0xe4, 0xd1, 0x3b, 0x59, 0x15, 0x50, 0x0f, 0xdd, 0x1f, 0xa3, + 0x20, 0x71, 0xc4, 0xc7, 0xd1, 0xf4, 0xc7, 0x33, 0xc0, 0x68, 0x03, 0x04, 0x22, + 0xaa, 0x9a, 0xc3, 0xd4, 0x6c, 0x4e, 0xd2, 0x82, 0x64, 0x46, 0x07, 0x9f, 0xaa, + 0x09, 0x14, 0xc2, 0xd7, 0x05, 0xd9, 0x8b, 0x02, 0xa2, 0xb5, 0x12, 0x9c, 0xd1, + 0xde, 0x16, 0x4e, 0xb9, 0xcb, 0xd0, 0x83, 0xe8, 0xa2, 0x50, 0x3c, 0x4e}; unsigned int *initial_state = new unsigned int[CHACHA20_STATE_DWORDS]; - unsigned int* output_state = new unsigned int[CHACHA20_BLK_FUNC_OUTPUT_DWORDS]; + unsigned int *output_state = new unsigned int[CHACHA20_BLK_FUNC_OUTPUT_DWORDS]; - chacha20::init_state(initial_state,(unsigned int*)key,1,(unsigned int*)nonce); - chacha20::apply_20rounds(output_state,initial_state); - - unsigned char* serialize = (unsigned char*) output_state; + chacha20::init_state(initial_state, (unsigned int *) key, 1, (unsigned int *) nonce); + chacha20::apply_20rounds(output_state, initial_state); + + unsigned char *serialize = (unsigned char *) output_state; bool serial_passed = true; - for(size_t i=0; i #ifndef _MAKE_LIB -#include "../Header-Mode-ChaCha20-Poly1305.hpp" + #include "../Header-Mode-ChaCha20-Poly1305.hpp" #else -#include + #include #endif // #define PRINT_FAILED_OUTPUTS -std::vector TEST_RESULTS; +std::vector TEST_RESULTS; const static std::string TEST_NAME = "Block Function Additional Test 1 "; -void ASSERT_UINT512(const epi::uint320_t& A, const epi::uint320_t& B, const std::string& TEST_MESSAGE); +void ASSERT_UINT512(const epi::uint320_t &A, const epi::uint320_t &B, const std::string &TEST_MESSAGE); -template -void ASSERT_ARRAY(T* A, T* B, size_t length, std::string TEST_MESSAGE, std::vector& RESULTS); +template +void ASSERT_ARRAY(T *A, T *B, size_t length, std::string TEST_MESSAGE, std::vector &RESULTS); -void printBytes(unsigned char* bytearray, size_t len) { - for(size_t i=0; i(output_state,correct_output_state,16,"output state",TEST_RESULTS); - ASSERT_ARRAY(serialize,correct_serial,64,"serialized ",TEST_RESULTS); - - delete [] initial_state; - delete [] output_state; - + unsigned int *output_state = new unsigned int[CHACHA20_BLK_FUNC_OUTPUT_DWORDS]; + + chacha20::init_state(initial_state, (unsigned int *) key, counter, (unsigned int *) nonce); + chacha20::apply_20rounds(output_state, initial_state); + + unsigned char *serialize = (unsigned char *) output_state; + + // TESTING ANSWER + + ASSERT_ARRAY(output_state, correct_output_state, 16, "output state", TEST_RESULTS); + ASSERT_ARRAY(serialize, correct_serial, 64, "serialized ", TEST_RESULTS); + + delete[] initial_state; + delete[] output_state; + // SUMMARY OF RESULTS size_t failed_cnt = 0; - for(auto e : TEST_RESULTS) { - if(!e) failed_cnt++; + for (auto e: TEST_RESULTS) { + if (!e) + failed_cnt++; } std::cout << "---------------------------------\n"; - std::cout << TEST_NAME << " RESULT:" << "\n"; - if(!failed_cnt) { + std::cout << TEST_NAME << " RESULT:" + << "\n"; + if (!failed_cnt) { std::cout << "\tALL test PASSED\n"; std::cout << "---------------------------------\n"; return 0; - } - else { + } else { std::cout << "\tSOME test FAILED\n"; std::cout << "---------------------------------\n"; return 1; - } + } } - -void ASSERT_UINT512(const epi::uint320_t& A, const epi::uint320_t& B, const std::string& TEST_MESSAGE) { +void ASSERT_UINT512(const epi::uint320_t &A, const epi::uint320_t &B, const std::string &TEST_MESSAGE) { std::cout << TEST_NAME << ":" << TEST_MESSAGE << " : "; - if(A!=B) { + if (A != B) { std::cout << "FAILED\n"; TEST_RESULTS.push_back(false); - } - else { + } else { std::cout << "PASSED\n"; TEST_RESULTS.push_back(true); } } -template -void ASSERT_ARRAY(T* A, T* B, size_t length, std::string TEST_MESSAGE, std::vector& RESULTS) { +template +void ASSERT_ARRAY(T *A, T *B, size_t length, std::string TEST_MESSAGE, std::vector &RESULTS) { std::cout << ":" << TEST_MESSAGE << " : "; bool result_passed = true; - for(size_t i=0; i #ifndef _MAKE_LIB -#include "../Header-Mode-ChaCha20-Poly1305.hpp" + #include "../Header-Mode-ChaCha20-Poly1305.hpp" #else -#include + #include #endif // #define PRINT_FAILED_OUTPUTS -std::vector TEST_RESULTS; +std::vector TEST_RESULTS; const static std::string TEST_NAME = "Block Function Additional Test 2 "; -void ASSERT_UINT512(const epi::uint320_t& A, const epi::uint320_t& B, const std::string& TEST_MESSAGE); +void ASSERT_UINT512(const epi::uint320_t &A, const epi::uint320_t &B, const std::string &TEST_MESSAGE); -template -void ASSERT_ARRAY(T* A, T* B, size_t length, std::string TEST_MESSAGE, std::vector& RESULTS); +template +void ASSERT_ARRAY(T *A, T *B, size_t length, std::string TEST_MESSAGE, std::vector &RESULTS); -void printBytes(unsigned char* bytearray, size_t len) { - for(size_t i=0; i(output_state,correct_output_state,16,"output state",TEST_RESULTS); - ASSERT_ARRAY(serialize,correct_serial,64,"serialized ",TEST_RESULTS); - - delete [] initial_state; - delete [] output_state; - + unsigned int *output_state = new unsigned int[CHACHA20_BLK_FUNC_OUTPUT_DWORDS]; + + chacha20::init_state(initial_state, (unsigned int *) key, counter, (unsigned int *) nonce); + chacha20::apply_20rounds(output_state, initial_state); + + unsigned char *serialize = (unsigned char *) output_state; + + // TESTING ANSWER + + ASSERT_ARRAY(output_state, correct_output_state, 16, "output state", TEST_RESULTS); + ASSERT_ARRAY(serialize, correct_serial, 64, "serialized ", TEST_RESULTS); + + delete[] initial_state; + delete[] output_state; + // SUMMARY OF RESULTS size_t failed_cnt = 0; - for(auto e : TEST_RESULTS) { - if(!e) failed_cnt++; + for (auto e: TEST_RESULTS) { + if (!e) + failed_cnt++; } std::cout << "---------------------------------\n"; - std::cout << TEST_NAME << " RESULT:" << "\n"; - if(!failed_cnt) { + std::cout << TEST_NAME << " RESULT:" + << "\n"; + if (!failed_cnt) { std::cout << "\tALL test PASSED\n"; std::cout << "---------------------------------\n"; return 0; - } - else { + } else { std::cout << "\tSOME test FAILED\n"; std::cout << "---------------------------------\n"; return 1; - } + } } - -void ASSERT_UINT512(const epi::uint320_t& A, const epi::uint320_t& B, const std::string& TEST_MESSAGE) { +void ASSERT_UINT512(const epi::uint320_t &A, const epi::uint320_t &B, const std::string &TEST_MESSAGE) { std::cout << TEST_NAME << ":" << TEST_MESSAGE << " : "; - if(A!=B) { + if (A != B) { std::cout << "FAILED\n"; TEST_RESULTS.push_back(false); - } - else { + } else { std::cout << "PASSED\n"; TEST_RESULTS.push_back(true); } } -template -void ASSERT_ARRAY(T* A, T* B, size_t length, std::string TEST_MESSAGE, std::vector& RESULTS) { +template +void ASSERT_ARRAY(T *A, T *B, size_t length, std::string TEST_MESSAGE, std::vector &RESULTS) { std::cout << ":" << TEST_MESSAGE << " : "; bool result_passed = true; - for(size_t i=0; i #ifndef _MAKE_LIB -#include "../Header-Mode-ChaCha20-Poly1305.hpp" + #include "../Header-Mode-ChaCha20-Poly1305.hpp" #else -#include + #include #endif // #define PRINT_FAILED_OUTPUTS -std::vector TEST_RESULTS; +std::vector TEST_RESULTS; const static std::string TEST_NAME = "Block Function Additional Test 3 "; -void ASSERT_UINT512(const epi::uint320_t& A, const epi::uint320_t& B, const std::string& TEST_MESSAGE); +void ASSERT_UINT512(const epi::uint320_t &A, const epi::uint320_t &B, const std::string &TEST_MESSAGE); -template -void ASSERT_ARRAY(T* A, T* B, size_t length, std::string TEST_MESSAGE, std::vector& RESULTS); +template +void ASSERT_ARRAY(T *A, T *B, size_t length, std::string TEST_MESSAGE, std::vector &RESULTS); -void printBytes(unsigned char* bytearray, size_t len) { - for(size_t i=0; i(output_state, correct_output_state, 16, "output state", TEST_RESULTS); + ASSERT_ARRAY(serialize, correct_serial, 64, "serialized ", TEST_RESULTS); + + delete[] initial_state; + delete[] output_state; - ASSERT_ARRAY(output_state,correct_output_state,16,"output state",TEST_RESULTS); - ASSERT_ARRAY(serialize,correct_serial,64,"serialized ",TEST_RESULTS); - - delete [] initial_state; - delete [] output_state; - // SUMMARY OF RESULTS size_t failed_cnt = 0; - for(auto e : TEST_RESULTS) { - if(!e) failed_cnt++; + for (auto e: TEST_RESULTS) { + if (!e) + failed_cnt++; } std::cout << "---------------------------------\n"; - std::cout << TEST_NAME << " RESULT:" << "\n"; - if(!failed_cnt) { + std::cout << TEST_NAME << " RESULT:" + << "\n"; + if (!failed_cnt) { std::cout << "\tALL test PASSED\n"; std::cout << "---------------------------------\n"; return 0; - } - else { + } else { std::cout << "\tSOME test FAILED\n"; std::cout << "---------------------------------\n"; return 1; - } + } } - -void ASSERT_UINT512(const epi::uint320_t& A, const epi::uint320_t& B, const std::string& TEST_MESSAGE) { +void ASSERT_UINT512(const epi::uint320_t &A, const epi::uint320_t &B, const std::string &TEST_MESSAGE) { std::cout << TEST_NAME << ":" << TEST_MESSAGE << " : "; - if(A!=B) { + if (A != B) { std::cout << "FAILED\n"; TEST_RESULTS.push_back(false); - } - else { + } else { std::cout << "PASSED\n"; TEST_RESULTS.push_back(true); } } -template -void ASSERT_ARRAY(T* A, T* B, size_t length, std::string TEST_MESSAGE, std::vector& RESULTS) { +template +void ASSERT_ARRAY(T *A, T *B, size_t length, std::string TEST_MESSAGE, std::vector &RESULTS) { std::cout << ":" << TEST_MESSAGE << " : "; bool result_passed = true; - for(size_t i=0; i #ifndef _MAKE_LIB -#include "../Header-Mode-ChaCha20-Poly1305.hpp" + #include "../Header-Mode-ChaCha20-Poly1305.hpp" #else -#include + #include #endif // #define PRINT_FAILED_OUTPUTS -std::vector TEST_RESULTS; +std::vector TEST_RESULTS; const static std::string TEST_NAME = "Block Function Additional Test 4 "; -void ASSERT_UINT512(const epi::uint320_t& A, const epi::uint320_t& B, const std::string& TEST_MESSAGE); +void ASSERT_UINT512(const epi::uint320_t &A, const epi::uint320_t &B, const std::string &TEST_MESSAGE); -template -void ASSERT_ARRAY(T* A, T* B, size_t length, std::string TEST_MESSAGE, std::vector& RESULTS); +template +void ASSERT_ARRAY(T *A, T *B, size_t length, std::string TEST_MESSAGE, std::vector &RESULTS); -void printBytes(unsigned char* bytearray, size_t len) { - for(size_t i=0; i(output_state, correct_output_state, 16, "output state", TEST_RESULTS); + ASSERT_ARRAY(serialize, correct_serial, 64, "serialized ", TEST_RESULTS); + + delete[] initial_state; + delete[] output_state; - ASSERT_ARRAY(output_state,correct_output_state,16,"output state",TEST_RESULTS); - ASSERT_ARRAY(serialize,correct_serial,64,"serialized ",TEST_RESULTS); - - delete [] initial_state; - delete [] output_state; - // SUMMARY OF RESULTS size_t failed_cnt = 0; - for(auto e : TEST_RESULTS) { - if(!e) failed_cnt++; + for (auto e: TEST_RESULTS) { + if (!e) + failed_cnt++; } std::cout << "---------------------------------\n"; - std::cout << TEST_NAME << " RESULT:" << "\n"; - if(!failed_cnt) { + std::cout << TEST_NAME << " RESULT:" + << "\n"; + if (!failed_cnt) { std::cout << "\tALL test PASSED\n"; std::cout << "---------------------------------\n"; return 0; - } - else { + } else { std::cout << "\tSOME test FAILED\n"; std::cout << "---------------------------------\n"; return 1; - } + } } - -void ASSERT_UINT512(const epi::uint320_t& A, const epi::uint320_t& B, const std::string& TEST_MESSAGE) { +void ASSERT_UINT512(const epi::uint320_t &A, const epi::uint320_t &B, const std::string &TEST_MESSAGE) { std::cout << TEST_NAME << ":" << TEST_MESSAGE << " : "; - if(A!=B) { + if (A != B) { std::cout << "FAILED\n"; TEST_RESULTS.push_back(false); - } - else { + } else { std::cout << "PASSED\n"; TEST_RESULTS.push_back(true); } } -template -void ASSERT_ARRAY(T* A, T* B, size_t length, std::string TEST_MESSAGE, std::vector& RESULTS) { +template +void ASSERT_ARRAY(T *A, T *B, size_t length, std::string TEST_MESSAGE, std::vector &RESULTS) { std::cout << ":" << TEST_MESSAGE << " : "; bool result_passed = true; - for(size_t i=0; i #ifndef _MAKE_LIB -#include "../Header-Mode-ChaCha20-Poly1305.hpp" + #include "../Header-Mode-ChaCha20-Poly1305.hpp" #else -#include + #include #endif // #define PRINT_FAILED_OUTPUTS -std::vector TEST_RESULTS; +std::vector TEST_RESULTS; const static std::string TEST_NAME = "Block Function Additional Test 5 "; -void ASSERT_UINT512(const epi::uint320_t& A, const epi::uint320_t& B, const std::string& TEST_MESSAGE); +void ASSERT_UINT512(const epi::uint320_t &A, const epi::uint320_t &B, const std::string &TEST_MESSAGE); -template -void ASSERT_ARRAY(T* A, T* B, size_t length, std::string TEST_MESSAGE, std::vector& RESULTS); +template +void ASSERT_ARRAY(T *A, T *B, size_t length, std::string TEST_MESSAGE, std::vector &RESULTS); -void printBytes(unsigned char* bytearray, size_t len) { - for(size_t i=0; i(output_state, correct_output_state, 16, "output state", TEST_RESULTS); + ASSERT_ARRAY(serialize, correct_serial, 64, "serialized ", TEST_RESULTS); + + delete[] initial_state; + delete[] output_state; - ASSERT_ARRAY(output_state,correct_output_state,16,"output state",TEST_RESULTS); - ASSERT_ARRAY(serialize,correct_serial,64,"serialized ",TEST_RESULTS); - - delete [] initial_state; - delete [] output_state; - // SUMMARY OF RESULTS size_t failed_cnt = 0; - for(auto e : TEST_RESULTS) { - if(!e) failed_cnt++; + for (auto e: TEST_RESULTS) { + if (!e) + failed_cnt++; } std::cout << "---------------------------------\n"; - std::cout << TEST_NAME << " RESULT:" << "\n"; - if(!failed_cnt) { + std::cout << TEST_NAME << " RESULT:" + << "\n"; + if (!failed_cnt) { std::cout << "\tALL test PASSED\n"; std::cout << "---------------------------------\n"; return 0; - } - else { + } else { std::cout << "\tSOME test FAILED\n"; std::cout << "---------------------------------\n"; return 1; - } + } } - -void ASSERT_UINT512(const epi::uint320_t& A, const epi::uint320_t& B, const std::string& TEST_MESSAGE) { +void ASSERT_UINT512(const epi::uint320_t &A, const epi::uint320_t &B, const std::string &TEST_MESSAGE) { std::cout << TEST_NAME << ":" << TEST_MESSAGE << " : "; - if(A!=B) { + if (A != B) { std::cout << "FAILED\n"; TEST_RESULTS.push_back(false); - } - else { + } else { std::cout << "PASSED\n"; TEST_RESULTS.push_back(true); } } -template -void ASSERT_ARRAY(T* A, T* B, size_t length, std::string TEST_MESSAGE, std::vector& RESULTS) { +template +void ASSERT_ARRAY(T *A, T *B, size_t length, std::string TEST_MESSAGE, std::vector &RESULTS) { std::cout << ":" << TEST_MESSAGE << " : "; bool result_passed = true; - for(size_t i=0; i #ifndef _MAKE_LIB -#include "../Header-Mode-ChaCha20-Poly1305.hpp" + #include "../Header-Mode-ChaCha20-Poly1305.hpp" #else -#include + #include #endif // #define PRINT_FAILED_OUTPUTS -std::vector TEST_RESULTS; +std::vector TEST_RESULTS; const static std::string TEST_NAME = "ChaCha20 Encryption Test 1 "; -void ASSERT_UINT512(const epi::uint320_t& A, const epi::uint320_t& B, const std::string& TEST_MESSAGE); +void ASSERT_UINT512(const epi::uint320_t &A, const epi::uint320_t &B, const std::string &TEST_MESSAGE); -template -void ASSERT_ARRAY(T* A, T* B, size_t length, std::string TEST_MESSAGE, std::vector& RESULTS); +template +void ASSERT_ARRAY(T *A, T *B, size_t length, std::string TEST_MESSAGE, std::vector &RESULTS); -void printBytes(unsigned char* bytearray, size_t len) { - for(size_t i=0; i(cipher_out,cipher_text,sizeof(cipher_text),"ChaCha20 encryption ",TEST_RESULTS); - - delete [] cipher_out; - + ASSERT_ARRAY(cipher_out, cipher_text, sizeof(cipher_text), "ChaCha20 encryption ", TEST_RESULTS); + + delete[] cipher_out; + // SUMMARY OF RESULTS size_t failed_cnt = 0; - for(auto e : TEST_RESULTS) { - if(!e) failed_cnt++; + for (auto e: TEST_RESULTS) { + if (!e) + failed_cnt++; } std::cout << "---------------------------------\n"; - std::cout << TEST_NAME << " RESULT:" << "\n"; - if(!failed_cnt) { + std::cout << TEST_NAME << " RESULT:" + << "\n"; + if (!failed_cnt) { std::cout << "\tALL test PASSED\n"; std::cout << "---------------------------------\n"; return 0; - } - else { + } else { std::cout << "\tSOME test FAILED\n"; std::cout << "---------------------------------\n"; return 1; - } + } } - -void ASSERT_UINT512(const epi::uint320_t& A, const epi::uint320_t& B, const std::string& TEST_MESSAGE) { +void ASSERT_UINT512(const epi::uint320_t &A, const epi::uint320_t &B, const std::string &TEST_MESSAGE) { std::cout << TEST_NAME << ":" << TEST_MESSAGE << " : "; - if(A!=B) { + if (A != B) { std::cout << "FAILED\n"; TEST_RESULTS.push_back(false); - } - else { + } else { std::cout << "PASSED\n"; TEST_RESULTS.push_back(true); } } -template -void ASSERT_ARRAY(T* A, T* B, size_t length, std::string TEST_MESSAGE, std::vector& RESULTS) { +template +void ASSERT_ARRAY(T *A, T *B, size_t length, std::string TEST_MESSAGE, std::vector &RESULTS) { std::cout << ":" << TEST_MESSAGE << " : "; bool result_passed = true; - for(size_t i=0; i #ifndef _MAKE_LIB -#include "../Header-Mode-ChaCha20-Poly1305.hpp" + #include "../Header-Mode-ChaCha20-Poly1305.hpp" #else -#include + #include #endif // #define PRINT_FAILED_OUTPUTS -std::vector TEST_RESULTS; +std::vector TEST_RESULTS; const static std::string TEST_NAME = "ChaCha20 Encryption Test 2 "; -void ASSERT_UINT512(const epi::uint320_t& A, const epi::uint320_t& B, const std::string& TEST_MESSAGE); +void ASSERT_UINT512(const epi::uint320_t &A, const epi::uint320_t &B, const std::string &TEST_MESSAGE); -template -void ASSERT_ARRAY(T* A, T* B, size_t length, std::string TEST_MESSAGE, std::vector& RESULTS); +template +void ASSERT_ARRAY(T *A, T *B, size_t length, std::string TEST_MESSAGE, std::vector &RESULTS); -void printBytes(unsigned char* bytearray, size_t len) { - for(size_t i=0; i(cipher_out,cipher_text,sizeof(cipher_text),"ChaCha20 encryption ",TEST_RESULTS); + ASSERT_ARRAY(cipher_out, cipher_text, sizeof(cipher_text), "ChaCha20 encryption ", TEST_RESULTS); - delete [] cipher_out; - + delete[] cipher_out; // SUMMARY OF RESULTS size_t failed_cnt = 0; - for(auto e : TEST_RESULTS) { - if(!e) failed_cnt++; + for (auto e: TEST_RESULTS) { + if (!e) + failed_cnt++; } std::cout << "---------------------------------\n"; - std::cout << TEST_NAME << " RESULT:" << "\n"; - if(!failed_cnt) { + std::cout << TEST_NAME << " RESULT:" + << "\n"; + if (!failed_cnt) { std::cout << "\tALL test PASSED\n"; std::cout << "---------------------------------\n"; return 0; - } - else { + } else { std::cout << "\tSOME test FAILED\n"; std::cout << "---------------------------------\n"; return 1; - } + } } - -void ASSERT_UINT512(const epi::uint320_t& A, const epi::uint320_t& B, const std::string& TEST_MESSAGE) { +void ASSERT_UINT512(const epi::uint320_t &A, const epi::uint320_t &B, const std::string &TEST_MESSAGE) { std::cout << TEST_NAME << ":" << TEST_MESSAGE << " : "; - if(A!=B) { + if (A != B) { std::cout << "FAILED\n"; TEST_RESULTS.push_back(false); - } - else { + } else { std::cout << "PASSED\n"; TEST_RESULTS.push_back(true); } } -template -void ASSERT_ARRAY(T* A, T* B, size_t length, std::string TEST_MESSAGE, std::vector& RESULTS) { +template +void ASSERT_ARRAY(T *A, T *B, size_t length, std::string TEST_MESSAGE, std::vector &RESULTS) { std::cout << ":" << TEST_MESSAGE << " : "; bool result_passed = true; - for(size_t i=0; i #ifndef _MAKE_LIB -#include "../Header-Mode-ChaCha20-Poly1305.hpp" + #include "../Header-Mode-ChaCha20-Poly1305.hpp" #else -#include + #include #endif // #define PRINT_FAILED_OUTPUTS -std::vector TEST_RESULTS; +std::vector TEST_RESULTS; const static std::string TEST_NAME = "ChaCha20 Encryption Test 3 "; -void ASSERT_UINT512(const epi::uint320_t& A, const epi::uint320_t& B, const std::string& TEST_MESSAGE); +void ASSERT_UINT512(const epi::uint320_t &A, const epi::uint320_t &B, const std::string &TEST_MESSAGE); -template -void ASSERT_ARRAY(T* A, T* B, size_t length, std::string TEST_MESSAGE, std::vector& RESULTS); +template +void ASSERT_ARRAY(T *A, T *B, size_t length, std::string TEST_MESSAGE, std::vector &RESULTS); -void printBytes(unsigned char* bytearray, size_t len) { - for(size_t i=0; i(cipher_out, cipher_text, sizeof(cipher_text), "ChaCha20 encryption ", TEST_RESULTS); + + delete[] cipher_out; - // TESTING ANSWER - ASSERT_ARRAY(cipher_out,cipher_text,sizeof(cipher_text),"ChaCha20 encryption ",TEST_RESULTS); - - delete [] cipher_out; - // SUMMARY OF RESULTS size_t failed_cnt = 0; - for(auto e : TEST_RESULTS) { - if(!e) failed_cnt++; + for (auto e: TEST_RESULTS) { + if (!e) + failed_cnt++; } std::cout << "---------------------------------\n"; - std::cout << TEST_NAME << " RESULT:" << "\n"; - if(!failed_cnt) { + std::cout << TEST_NAME << " RESULT:" + << "\n"; + if (!failed_cnt) { std::cout << "\tALL test PASSED\n"; std::cout << "---------------------------------\n"; return 0; - } - else { + } else { std::cout << "\tSOME test FAILED\n"; std::cout << "---------------------------------\n"; return 1; - } + } } - -void ASSERT_UINT512(const epi::uint320_t& A, const epi::uint320_t& B, const std::string& TEST_MESSAGE) { +void ASSERT_UINT512(const epi::uint320_t &A, const epi::uint320_t &B, const std::string &TEST_MESSAGE) { std::cout << TEST_NAME << ":" << TEST_MESSAGE << " : "; - if(A!=B) { + if (A != B) { std::cout << "FAILED\n"; TEST_RESULTS.push_back(false); - } - else { + } else { std::cout << "PASSED\n"; TEST_RESULTS.push_back(true); } } -template -void ASSERT_ARRAY(T* A, T* B, size_t length, std::string TEST_MESSAGE, std::vector& RESULTS) { +template +void ASSERT_ARRAY(T *A, T *B, size_t length, std::string TEST_MESSAGE, std::vector &RESULTS) { std::cout << ":" << TEST_MESSAGE << " : "; bool result_passed = true; - for(size_t i=0; i #ifndef _MAKE_LIB -#include "../Header-Mode-ChaCha20-Poly1305.hpp" + #include "../Header-Mode-ChaCha20-Poly1305.hpp" #else -#include + #include #endif // #define PRINT_FAILED_OUTPUTS -std::vector TEST_RESULTS; +std::vector TEST_RESULTS; const static std::string TEST_NAME = "ChaCha20-Poly1305 decrypt, authenticate "; -void ASSERT_UINT512(const epi::uint320_t& A, const epi::uint320_t& B, const std::string& TEST_MESSAGE); +void ASSERT_UINT512(const epi::uint320_t &A, const epi::uint320_t &B, const std::string &TEST_MESSAGE); -template -void ASSERT_ARRAY(T* A, T* B, size_t length, std::string TEST_MESSAGE, std::vector& RESULTS); +template +void ASSERT_ARRAY(T *A, T *B, size_t length, std::string TEST_MESSAGE, std::vector &RESULTS); -void printBytes(unsigned char* bytearray, size_t len) { - for(size_t i=0; i(recover_tag,receiveTag,sizeof(receiveTag), "Poly1305 mac/tag ",TEST_RESULTS); - ASSERT_ARRAY(recovered_text,plainText,sizeof(plainText),"ChaCha20 decrypt ",TEST_RESULTS); + ASSERT_ARRAY(recover_tag, receiveTag, sizeof(receiveTag), "Poly1305 mac/tag ", TEST_RESULTS); + ASSERT_ARRAY(recovered_text, plainText, sizeof(plainText), "ChaCha20 decrypt ", TEST_RESULTS); + + delete[] recover_tag; + delete[] recovered_text; - delete [] recover_tag; - delete [] recovered_text; - // SUMMARY OF RESULTS size_t failed_cnt = 0; - for(auto e : TEST_RESULTS) { - if(!e) failed_cnt++; + for (auto e: TEST_RESULTS) { + if (!e) + failed_cnt++; } std::cout << "---------------------------------\n"; - std::cout << TEST_NAME << " RESULT:" << "\n"; - if(!failed_cnt) { + std::cout << TEST_NAME << " RESULT:" + << "\n"; + if (!failed_cnt) { std::cout << "\tALL test PASSED\n"; std::cout << "---------------------------------\n"; return 0; - } - else { + } else { std::cout << "\tSOME test FAILED\n"; std::cout << "---------------------------------\n"; return 1; - } + } } -void ASSERT_UINT512(const epi::uint320_t& A, const epi::uint320_t& B, const std::string& TEST_MESSAGE) { +void ASSERT_UINT512(const epi::uint320_t &A, const epi::uint320_t &B, const std::string &TEST_MESSAGE) { std::cout << TEST_NAME << ":" << TEST_MESSAGE << " : "; - if(A!=B) { + if (A != B) { std::cout << "FAILED\n"; TEST_RESULTS.push_back(false); - } - else { + } else { std::cout << "PASSED\n"; TEST_RESULTS.push_back(true); } } -template -void ASSERT_ARRAY(T* A, T* B, size_t length, std::string TEST_MESSAGE, std::vector& RESULTS) { +template +void ASSERT_ARRAY(T *A, T *B, size_t length, std::string TEST_MESSAGE, std::vector &RESULTS) { std::cout << ":" << TEST_MESSAGE << " : "; bool result_passed = true; - for(size_t i=0; i #ifndef _MAKE_LIB -#include "../Header-Mode-ChaCha20-Poly1305.hpp" + #include "../Header-Mode-ChaCha20-Poly1305.hpp" #else -#include + #include #endif // #define PRINT_FAILED_OUTPUTS -std::vector TEST_RESULTS; +std::vector TEST_RESULTS; const static std::string TEST_NAME = "ChaCha20-Poly1305 nonce version decrypt, authenticate "; -void ASSERT_UINT512(const epi::uint320_t& A, const epi::uint320_t& B, const std::string& TEST_MESSAGE); +void ASSERT_UINT512(const epi::uint320_t &A, const epi::uint320_t &B, const std::string &TEST_MESSAGE); -template -void ASSERT_ARRAY(T* A, T* B, size_t length, std::string TEST_MESSAGE, std::vector& RESULTS); +template +void ASSERT_ARRAY(T *A, T *B, size_t length, std::string TEST_MESSAGE, std::vector &RESULTS); -void printBytes(unsigned char* bytearray, size_t len) { - for(size_t i=0; i(recover_tag,receiveTag,sizeof(receiveTag), "Poly1305 mac/tag ",TEST_RESULTS); - ASSERT_ARRAY(recovered_text,plainText,sizeof(plainText),"ChaCha20 decrypt ",TEST_RESULTS); + ASSERT_ARRAY(recover_tag, receiveTag, sizeof(receiveTag), "Poly1305 mac/tag ", TEST_RESULTS); + ASSERT_ARRAY(recovered_text, plainText, sizeof(plainText), "ChaCha20 decrypt ", TEST_RESULTS); + + delete[] recover_tag; + delete[] recovered_text; - delete [] recover_tag; - delete [] recovered_text; - // SUMMARY OF RESULTS size_t failed_cnt = 0; - for(auto e : TEST_RESULTS) { - if(!e) failed_cnt++; + for (auto e: TEST_RESULTS) { + if (!e) + failed_cnt++; } std::cout << "---------------------------------\n"; - std::cout << TEST_NAME << " RESULT:" << "\n"; - if(!failed_cnt) { + std::cout << TEST_NAME << " RESULT:" + << "\n"; + if (!failed_cnt) { std::cout << "\tALL test PASSED\n"; std::cout << "---------------------------------\n"; return 0; - } - else { + } else { std::cout << "\tSOME test FAILED\n"; std::cout << "---------------------------------\n"; return 1; - } + } } -void ASSERT_UINT512(const epi::uint320_t& A, const epi::uint320_t& B, const std::string& TEST_MESSAGE) { +void ASSERT_UINT512(const epi::uint320_t &A, const epi::uint320_t &B, const std::string &TEST_MESSAGE) { std::cout << TEST_NAME << ":" << TEST_MESSAGE << " : "; - if(A!=B) { + if (A != B) { std::cout << "FAILED\n"; TEST_RESULTS.push_back(false); - } - else { + } else { std::cout << "PASSED\n"; TEST_RESULTS.push_back(true); } } -template -void ASSERT_ARRAY(T* A, T* B, size_t length, std::string TEST_MESSAGE, std::vector& RESULTS) { +template +void ASSERT_ARRAY(T *A, T *B, size_t length, std::string TEST_MESSAGE, std::vector &RESULTS) { std::cout << ":" << TEST_MESSAGE << " : "; bool result_passed = true; - for(size_t i=0; i #ifndef _MAKE_LIB -#include "../Header-Mode-ChaCha20-Poly1305.hpp" + #include "../Header-Mode-ChaCha20-Poly1305.hpp" #else -#include + #include #endif -void printBytes(unsigned char* bytearray, size_t len) { - for(size_t i=0; i #ifndef _MAKE_LIB -#include "../Header-Mode-ChaCha20-Poly1305.hpp" + #include "../Header-Mode-ChaCha20-Poly1305.hpp" #else -#include + #include #endif // #define PRINT_FAILED_OUTPUTS -std::vector TEST_RESULTS; +std::vector TEST_RESULTS; const static std::string TEST_NAME = "Poly1305 keygen using ChaCha20 test 1 "; -void ASSERT_UINT512(const epi::uint320_t& A, const epi::uint320_t& B, const std::string& TEST_MESSAGE); +void ASSERT_UINT512(const epi::uint320_t &A, const epi::uint320_t &B, const std::string &TEST_MESSAGE); -template -void ASSERT_ARRAY(T* A, T* B, size_t length, std::string TEST_MESSAGE, std::vector& RESULTS); +template +void ASSERT_ARRAY(T *A, T *B, size_t length, std::string TEST_MESSAGE, std::vector &RESULTS); -void printBytes(unsigned char* bytearray, size_t len) { - for(size_t i=0; i(genkey, polykey, sizeof(polykey), "Poly1305 key generation test ", TEST_RESULTS); + + delete[] genkey; - // TESTING ANSWER - ASSERT_ARRAY(genkey,polykey,sizeof(polykey),"Poly1305 key generation test ",TEST_RESULTS); - - delete [] genkey; - // SUMMARY OF RESULTS size_t failed_cnt = 0; - for(auto e : TEST_RESULTS) { - if(!e) failed_cnt++; + for (auto e: TEST_RESULTS) { + if (!e) + failed_cnt++; } std::cout << "---------------------------------\n"; - std::cout << TEST_NAME << " RESULT:" << "\n"; - if(!failed_cnt) { + std::cout << TEST_NAME << " RESULT:" + << "\n"; + if (!failed_cnt) { std::cout << "\tALL test PASSED\n"; std::cout << "---------------------------------\n"; return 0; - } - else { + } else { std::cout << "\tSOME test FAILED\n"; std::cout << "---------------------------------\n"; return 1; - } + } } - -void ASSERT_UINT512(const epi::uint320_t& A, const epi::uint320_t& B, const std::string& TEST_MESSAGE) { +void ASSERT_UINT512(const epi::uint320_t &A, const epi::uint320_t &B, const std::string &TEST_MESSAGE) { std::cout << TEST_NAME << ":" << TEST_MESSAGE << " : "; - if(A!=B) { + if (A != B) { std::cout << "FAILED\n"; TEST_RESULTS.push_back(false); - } - else { + } else { std::cout << "PASSED\n"; TEST_RESULTS.push_back(true); } } -template -void ASSERT_ARRAY(T* A, T* B, size_t length, std::string TEST_MESSAGE, std::vector& RESULTS) { +template +void ASSERT_ARRAY(T *A, T *B, size_t length, std::string TEST_MESSAGE, std::vector &RESULTS) { std::cout << ":" << TEST_MESSAGE << " : "; bool result_passed = true; - for(size_t i=0; i #ifndef _MAKE_LIB -#include "../Header-Mode-ChaCha20-Poly1305.hpp" + #include "../Header-Mode-ChaCha20-Poly1305.hpp" #else -#include + #include #endif // #define PRINT_FAILED_OUTPUTS -std::vector TEST_RESULTS; +std::vector TEST_RESULTS; const static std::string TEST_NAME = "Poly1305 keygen using ChaCha20 test 2 "; -void ASSERT_UINT512(const epi::uint320_t& A, const epi::uint320_t& B, const std::string& TEST_MESSAGE); +void ASSERT_UINT512(const epi::uint320_t &A, const epi::uint320_t &B, const std::string &TEST_MESSAGE); -template -void ASSERT_ARRAY(T* A, T* B, size_t length, std::string TEST_MESSAGE, std::vector& RESULTS); +template +void ASSERT_ARRAY(T *A, T *B, size_t length, std::string TEST_MESSAGE, std::vector &RESULTS); -void printBytes(unsigned char* bytearray, size_t len) { - for(size_t i=0; i(genkey, polykey, sizeof(polykey), "Poly1305 key generation test ", TEST_RESULTS); + + delete[] genkey; - // TESTING ANSWER - ASSERT_ARRAY(genkey,polykey,sizeof(polykey),"Poly1305 key generation test ",TEST_RESULTS); - - delete [] genkey; - // SUMMARY OF RESULTS size_t failed_cnt = 0; - for(auto e : TEST_RESULTS) { - if(!e) failed_cnt++; + for (auto e: TEST_RESULTS) { + if (!e) + failed_cnt++; } std::cout << "---------------------------------\n"; - std::cout << TEST_NAME << " RESULT:" << "\n"; - if(!failed_cnt) { + std::cout << TEST_NAME << " RESULT:" + << "\n"; + if (!failed_cnt) { std::cout << "\tALL test PASSED\n"; std::cout << "---------------------------------\n"; return 0; - } - else { + } else { std::cout << "\tSOME test FAILED\n"; std::cout << "---------------------------------\n"; return 1; - } + } } - -void ASSERT_UINT512(const epi::uint320_t& A, const epi::uint320_t& B, const std::string& TEST_MESSAGE) { +void ASSERT_UINT512(const epi::uint320_t &A, const epi::uint320_t &B, const std::string &TEST_MESSAGE) { std::cout << TEST_NAME << ":" << TEST_MESSAGE << " : "; - if(A!=B) { + if (A != B) { std::cout << "FAILED\n"; TEST_RESULTS.push_back(false); - } - else { + } else { std::cout << "PASSED\n"; TEST_RESULTS.push_back(true); } } -template -void ASSERT_ARRAY(T* A, T* B, size_t length, std::string TEST_MESSAGE, std::vector& RESULTS) { +template +void ASSERT_ARRAY(T *A, T *B, size_t length, std::string TEST_MESSAGE, std::vector &RESULTS) { std::cout << ":" << TEST_MESSAGE << " : "; bool result_passed = true; - for(size_t i=0; i #ifndef _MAKE_LIB -#include "../Header-Mode-ChaCha20-Poly1305.hpp" + #include "../Header-Mode-ChaCha20-Poly1305.hpp" #else -#include + #include #endif // #define PRINT_FAILED_OUTPUTS -std::vector TEST_RESULTS; +std::vector TEST_RESULTS; const static std::string TEST_NAME = "Poly1305 keygen using ChaCha20 test 3 "; -void ASSERT_UINT512(const epi::uint320_t& A, const epi::uint320_t& B, const std::string& TEST_MESSAGE); +void ASSERT_UINT512(const epi::uint320_t &A, const epi::uint320_t &B, const std::string &TEST_MESSAGE); -template -void ASSERT_ARRAY(T* A, T* B, size_t length, std::string TEST_MESSAGE, std::vector& RESULTS); +template +void ASSERT_ARRAY(T *A, T *B, size_t length, std::string TEST_MESSAGE, std::vector &RESULTS); -void printBytes(unsigned char* bytearray, size_t len) { - for(size_t i=0; i(genkey, polykey, sizeof(polykey), "Poly1305 key generation test ", TEST_RESULTS); + + delete[] genkey; - // TESTING ANSWER - ASSERT_ARRAY(genkey,polykey,sizeof(polykey),"Poly1305 key generation test ",TEST_RESULTS); - - delete [] genkey; - // SUMMARY OF RESULTS size_t failed_cnt = 0; - for(auto e : TEST_RESULTS) { - if(!e) failed_cnt++; + for (auto e: TEST_RESULTS) { + if (!e) + failed_cnt++; } std::cout << "---------------------------------\n"; - std::cout << TEST_NAME << " RESULT:" << "\n"; - if(!failed_cnt) { + std::cout << TEST_NAME << " RESULT:" + << "\n"; + if (!failed_cnt) { std::cout << "\tALL test PASSED\n"; std::cout << "---------------------------------\n"; return 0; - } - else { + } else { std::cout << "\tSOME test FAILED\n"; std::cout << "---------------------------------\n"; return 1; - } + } } - -void ASSERT_UINT512(const epi::uint320_t& A, const epi::uint320_t& B, const std::string& TEST_MESSAGE) { +void ASSERT_UINT512(const epi::uint320_t &A, const epi::uint320_t &B, const std::string &TEST_MESSAGE) { std::cout << TEST_NAME << ":" << TEST_MESSAGE << " : "; - if(A!=B) { + if (A != B) { std::cout << "FAILED\n"; TEST_RESULTS.push_back(false); - } - else { + } else { std::cout << "PASSED\n"; TEST_RESULTS.push_back(true); } } -template -void ASSERT_ARRAY(T* A, T* B, size_t length, std::string TEST_MESSAGE, std::vector& RESULTS) { +template +void ASSERT_ARRAY(T *A, T *B, size_t length, std::string TEST_MESSAGE, std::vector &RESULTS) { std::cout << ":" << TEST_MESSAGE << " : "; bool result_passed = true; - for(size_t i=0; i #ifndef _MAKE_LIB -#include "../Header-Mode-ChaCha20-Poly1305.hpp" + #include "../Header-Mode-ChaCha20-Poly1305.hpp" #else -#include + #include #endif // #define PRINT_FAILED_OUTPUTS -std::vector TEST_RESULTS; +std::vector TEST_RESULTS; const static std::string TEST_NAME = "Poly1305 mac test 1 "; -void ASSERT_UINT512(const epi::uint320_t& A, const epi::uint320_t& B, const std::string& TEST_MESSAGE); +void ASSERT_UINT512(const epi::uint320_t &A, const epi::uint320_t &B, const std::string &TEST_MESSAGE); -template -void ASSERT_ARRAY(T* A, T* B, size_t length, std::string TEST_MESSAGE, std::vector& RESULTS); +template +void ASSERT_ARRAY(T *A, T *B, size_t length, std::string TEST_MESSAGE, std::vector &RESULTS); -void printBytes(unsigned char* bytearray, size_t len) { - for(size_t i=0; i(out_tag, tag, 16, "Poly1305 tag/mac test ", TEST_RESULTS); + + delete[] out_tag; - // TESTING ANSWER - ASSERT_ARRAY(out_tag,tag,16,"Poly1305 tag/mac test ",TEST_RESULTS); - - delete [] out_tag; - // SUMMARY OF RESULTS size_t failed_cnt = 0; - for(auto e : TEST_RESULTS) { - if(!e) failed_cnt++; + for (auto e: TEST_RESULTS) { + if (!e) + failed_cnt++; } std::cout << "---------------------------------\n"; - std::cout << TEST_NAME << " RESULT:" << "\n"; - if(!failed_cnt) { + std::cout << TEST_NAME << " RESULT:" + << "\n"; + if (!failed_cnt) { std::cout << "\tALL test PASSED\n"; std::cout << "---------------------------------\n"; return 0; - } - else { + } else { std::cout << "\tSOME test FAILED\n"; std::cout << "---------------------------------\n"; return 1; - } + } } - -void ASSERT_UINT512(const epi::uint320_t& A, const epi::uint320_t& B, const std::string& TEST_MESSAGE) { +void ASSERT_UINT512(const epi::uint320_t &A, const epi::uint320_t &B, const std::string &TEST_MESSAGE) { std::cout << TEST_NAME << ":" << TEST_MESSAGE << " : "; - if(A!=B) { + if (A != B) { std::cout << "FAILED\n"; TEST_RESULTS.push_back(false); - } - else { + } else { std::cout << "PASSED\n"; TEST_RESULTS.push_back(true); } } -template -void ASSERT_ARRAY(T* A, T* B, size_t length, std::string TEST_MESSAGE, std::vector& RESULTS) { +template +void ASSERT_ARRAY(T *A, T *B, size_t length, std::string TEST_MESSAGE, std::vector &RESULTS) { std::cout << ":" << TEST_MESSAGE << " : "; bool result_passed = true; - for(size_t i=0; i #ifndef _MAKE_LIB -#include "../Header-Mode-ChaCha20-Poly1305.hpp" + #include "../Header-Mode-ChaCha20-Poly1305.hpp" #else -#include + #include #endif // #define PRINT_FAILED_OUTPUTS -std::vector TEST_RESULTS; +std::vector TEST_RESULTS; const static std::string TEST_NAME = "Poly1305 mac test 10 "; -void ASSERT_UINT512(const epi::uint320_t& A, const epi::uint320_t& B, const std::string& TEST_MESSAGE); +void ASSERT_UINT512(const epi::uint320_t &A, const epi::uint320_t &B, const std::string &TEST_MESSAGE); -template -void ASSERT_ARRAY(T* A, T* B, size_t length, std::string TEST_MESSAGE, std::vector& RESULTS); +template +void ASSERT_ARRAY(T *A, T *B, size_t length, std::string TEST_MESSAGE, std::vector &RESULTS); -void printBytes(unsigned char* bytearray, size_t len) { - for(size_t i=0; i(out_tag, tag, 16, "Poly1305 tag/mac test ", TEST_RESULTS); + + delete[] out_tag; - // TESTING ANSWER - ASSERT_ARRAY(out_tag,tag,16,"Poly1305 tag/mac test ",TEST_RESULTS); - - delete [] out_tag; - // SUMMARY OF RESULTS size_t failed_cnt = 0; - for(auto e : TEST_RESULTS) { - if(!e) failed_cnt++; + for (auto e: TEST_RESULTS) { + if (!e) + failed_cnt++; } std::cout << "---------------------------------\n"; - std::cout << TEST_NAME << " RESULT:" << "\n"; - if(!failed_cnt) { + std::cout << TEST_NAME << " RESULT:" + << "\n"; + if (!failed_cnt) { std::cout << "\tALL test PASSED\n"; std::cout << "---------------------------------\n"; return 0; - } - else { + } else { std::cout << "\tSOME test FAILED\n"; std::cout << "---------------------------------\n"; return 1; - } + } } - -void ASSERT_UINT512(const epi::uint320_t& A, const epi::uint320_t& B, const std::string& TEST_MESSAGE) { +void ASSERT_UINT512(const epi::uint320_t &A, const epi::uint320_t &B, const std::string &TEST_MESSAGE) { std::cout << TEST_NAME << ":" << TEST_MESSAGE << " : "; - if(A!=B) { + if (A != B) { std::cout << "FAILED\n"; TEST_RESULTS.push_back(false); - } - else { + } else { std::cout << "PASSED\n"; TEST_RESULTS.push_back(true); } } -template -void ASSERT_ARRAY(T* A, T* B, size_t length, std::string TEST_MESSAGE, std::vector& RESULTS) { +template +void ASSERT_ARRAY(T *A, T *B, size_t length, std::string TEST_MESSAGE, std::vector &RESULTS) { std::cout << ":" << TEST_MESSAGE << " : "; bool result_passed = true; - for(size_t i=0; i #ifndef _MAKE_LIB -#include "../Header-Mode-ChaCha20-Poly1305.hpp" + #include "../Header-Mode-ChaCha20-Poly1305.hpp" #else -#include + #include #endif // #define PRINT_FAILED_OUTPUTS -std::vector TEST_RESULTS; +std::vector TEST_RESULTS; const static std::string TEST_NAME = "Poly1305 mac test 11 "; -void ASSERT_UINT512(const epi::uint320_t& A, const epi::uint320_t& B, const std::string& TEST_MESSAGE); +void ASSERT_UINT512(const epi::uint320_t &A, const epi::uint320_t &B, const std::string &TEST_MESSAGE); -template -void ASSERT_ARRAY(T* A, T* B, size_t length, std::string TEST_MESSAGE, std::vector& RESULTS); +template +void ASSERT_ARRAY(T *A, T *B, size_t length, std::string TEST_MESSAGE, std::vector &RESULTS); -void printBytes(unsigned char* bytearray, size_t len) { - for(size_t i=0; i(out_tag, tag, 16, "Poly1305 tag/mac test ", TEST_RESULTS); + + delete[] out_tag; - // TESTING ANSWER - ASSERT_ARRAY(out_tag,tag,16,"Poly1305 tag/mac test ",TEST_RESULTS); - - delete [] out_tag; - // SUMMARY OF RESULTS size_t failed_cnt = 0; - for(auto e : TEST_RESULTS) { - if(!e) failed_cnt++; + for (auto e: TEST_RESULTS) { + if (!e) + failed_cnt++; } std::cout << "---------------------------------\n"; - std::cout << TEST_NAME << " RESULT:" << "\n"; - if(!failed_cnt) { + std::cout << TEST_NAME << " RESULT:" + << "\n"; + if (!failed_cnt) { std::cout << "\tALL test PASSED\n"; std::cout << "---------------------------------\n"; return 0; - } - else { + } else { std::cout << "\tSOME test FAILED\n"; std::cout << "---------------------------------\n"; return 1; - } + } } - -void ASSERT_UINT512(const epi::uint320_t& A, const epi::uint320_t& B, const std::string& TEST_MESSAGE) { +void ASSERT_UINT512(const epi::uint320_t &A, const epi::uint320_t &B, const std::string &TEST_MESSAGE) { std::cout << TEST_NAME << ":" << TEST_MESSAGE << " : "; - if(A!=B) { + if (A != B) { std::cout << "FAILED\n"; TEST_RESULTS.push_back(false); - } - else { + } else { std::cout << "PASSED\n"; TEST_RESULTS.push_back(true); } } -template -void ASSERT_ARRAY(T* A, T* B, size_t length, std::string TEST_MESSAGE, std::vector& RESULTS) { +template +void ASSERT_ARRAY(T *A, T *B, size_t length, std::string TEST_MESSAGE, std::vector &RESULTS) { std::cout << ":" << TEST_MESSAGE << " : "; bool result_passed = true; - for(size_t i=0; i #ifndef _MAKE_LIB -#include "../Header-Mode-ChaCha20-Poly1305.hpp" + #include "../Header-Mode-ChaCha20-Poly1305.hpp" #else -#include + #include #endif // #define PRINT_FAILED_OUTPUTS -std::vector TEST_RESULTS; +std::vector TEST_RESULTS; const static std::string TEST_NAME = "Poly1305 mac test 2 "; -void ASSERT_UINT512(const epi::uint320_t& A, const epi::uint320_t& B, const std::string& TEST_MESSAGE); +void ASSERT_UINT512(const epi::uint320_t &A, const epi::uint320_t &B, const std::string &TEST_MESSAGE); -template -void ASSERT_ARRAY(T* A, T* B, size_t length, std::string TEST_MESSAGE, std::vector& RESULTS); +template +void ASSERT_ARRAY(T *A, T *B, size_t length, std::string TEST_MESSAGE, std::vector &RESULTS); -void printBytes(unsigned char* bytearray, size_t len) { - for(size_t i=0; i(out_tag, tag, 16, "Poly1305 tag/mac test ", TEST_RESULTS); + + delete[] out_tag; - // TESTING ANSWER - ASSERT_ARRAY(out_tag,tag,16,"Poly1305 tag/mac test ",TEST_RESULTS); - - delete [] out_tag; - // SUMMARY OF RESULTS size_t failed_cnt = 0; - for(auto e : TEST_RESULTS) { - if(!e) failed_cnt++; + for (auto e: TEST_RESULTS) { + if (!e) + failed_cnt++; } std::cout << "---------------------------------\n"; - std::cout << TEST_NAME << " RESULT:" << "\n"; - if(!failed_cnt) { + std::cout << TEST_NAME << " RESULT:" + << "\n"; + if (!failed_cnt) { std::cout << "\tALL test PASSED\n"; std::cout << "---------------------------------\n"; return 0; - } - else { + } else { std::cout << "\tSOME test FAILED\n"; std::cout << "---------------------------------\n"; return 1; - } + } } - -void ASSERT_UINT512(const epi::uint320_t& A, const epi::uint320_t& B, const std::string& TEST_MESSAGE) { +void ASSERT_UINT512(const epi::uint320_t &A, const epi::uint320_t &B, const std::string &TEST_MESSAGE) { std::cout << TEST_NAME << ":" << TEST_MESSAGE << " : "; - if(A!=B) { + if (A != B) { std::cout << "FAILED\n"; TEST_RESULTS.push_back(false); - } - else { + } else { std::cout << "PASSED\n"; TEST_RESULTS.push_back(true); } } -template -void ASSERT_ARRAY(T* A, T* B, size_t length, std::string TEST_MESSAGE, std::vector& RESULTS) { +template +void ASSERT_ARRAY(T *A, T *B, size_t length, std::string TEST_MESSAGE, std::vector &RESULTS) { std::cout << ":" << TEST_MESSAGE << " : "; bool result_passed = true; - for(size_t i=0; i #ifndef _MAKE_LIB -#include "../Header-Mode-ChaCha20-Poly1305.hpp" + #include "../Header-Mode-ChaCha20-Poly1305.hpp" #else -#include + #include #endif // #define PRINT_FAILED_OUTPUTS -std::vector TEST_RESULTS; +std::vector TEST_RESULTS; const static std::string TEST_NAME = "Poly1305 mac test 3 "; -void ASSERT_UINT512(const epi::uint320_t& A, const epi::uint320_t& B, const std::string& TEST_MESSAGE); +void ASSERT_UINT512(const epi::uint320_t &A, const epi::uint320_t &B, const std::string &TEST_MESSAGE); -template -void ASSERT_ARRAY(T* A, T* B, size_t length, std::string TEST_MESSAGE, std::vector& RESULTS); +template +void ASSERT_ARRAY(T *A, T *B, size_t length, std::string TEST_MESSAGE, std::vector &RESULTS); -void printBytes(unsigned char* bytearray, size_t len) { - for(size_t i=0; i(out_tag, tag, 16, "Poly1305 tag/mac test ", TEST_RESULTS); + + delete[] out_tag; - // TESTING ANSWER - ASSERT_ARRAY(out_tag,tag,16,"Poly1305 tag/mac test ",TEST_RESULTS); - - delete [] out_tag; - // SUMMARY OF RESULTS size_t failed_cnt = 0; - for(auto e : TEST_RESULTS) { - if(!e) failed_cnt++; + for (auto e: TEST_RESULTS) { + if (!e) + failed_cnt++; } std::cout << "---------------------------------\n"; - std::cout << TEST_NAME << " RESULT:" << "\n"; - if(!failed_cnt) { + std::cout << TEST_NAME << " RESULT:" + << "\n"; + if (!failed_cnt) { std::cout << "\tALL test PASSED\n"; std::cout << "---------------------------------\n"; return 0; - } - else { + } else { std::cout << "\tSOME test FAILED\n"; std::cout << "---------------------------------\n"; return 1; - } + } } - -void ASSERT_UINT512(const epi::uint320_t& A, const epi::uint320_t& B, const std::string& TEST_MESSAGE) { +void ASSERT_UINT512(const epi::uint320_t &A, const epi::uint320_t &B, const std::string &TEST_MESSAGE) { std::cout << TEST_NAME << ":" << TEST_MESSAGE << " : "; - if(A!=B) { + if (A != B) { std::cout << "FAILED\n"; TEST_RESULTS.push_back(false); - } - else { + } else { std::cout << "PASSED\n"; TEST_RESULTS.push_back(true); } } -template -void ASSERT_ARRAY(T* A, T* B, size_t length, std::string TEST_MESSAGE, std::vector& RESULTS) { +template +void ASSERT_ARRAY(T *A, T *B, size_t length, std::string TEST_MESSAGE, std::vector &RESULTS) { std::cout << ":" << TEST_MESSAGE << " : "; bool result_passed = true; - for(size_t i=0; i #ifndef _MAKE_LIB -#include "../Header-Mode-ChaCha20-Poly1305.hpp" + #include "../Header-Mode-ChaCha20-Poly1305.hpp" #else -#include + #include #endif // #define PRINT_FAILED_OUTPUTS -std::vector TEST_RESULTS; +std::vector TEST_RESULTS; const static std::string TEST_NAME = "Poly1305 mac test 4 "; -void ASSERT_UINT512(const epi::uint320_t& A, const epi::uint320_t& B, const std::string& TEST_MESSAGE); +void ASSERT_UINT512(const epi::uint320_t &A, const epi::uint320_t &B, const std::string &TEST_MESSAGE); -template -void ASSERT_ARRAY(T* A, T* B, size_t length, std::string TEST_MESSAGE, std::vector& RESULTS); +template +void ASSERT_ARRAY(T *A, T *B, size_t length, std::string TEST_MESSAGE, std::vector &RESULTS); -void printBytes(unsigned char* bytearray, size_t len) { - for(size_t i=0; i(out_tag, tag, 16, "Poly1305 tag/mac test ", TEST_RESULTS); + + delete[] out_tag; - // TESTING ANSWER - ASSERT_ARRAY(out_tag,tag,16,"Poly1305 tag/mac test ",TEST_RESULTS); - - delete [] out_tag; - // SUMMARY OF RESULTS size_t failed_cnt = 0; - for(auto e : TEST_RESULTS) { - if(!e) failed_cnt++; + for (auto e: TEST_RESULTS) { + if (!e) + failed_cnt++; } std::cout << "---------------------------------\n"; - std::cout << TEST_NAME << " RESULT:" << "\n"; - if(!failed_cnt) { + std::cout << TEST_NAME << " RESULT:" + << "\n"; + if (!failed_cnt) { std::cout << "\tALL test PASSED\n"; std::cout << "---------------------------------\n"; return 0; - } - else { + } else { std::cout << "\tSOME test FAILED\n"; std::cout << "---------------------------------\n"; return 1; - } + } } - -void ASSERT_UINT512(const epi::uint320_t& A, const epi::uint320_t& B, const std::string& TEST_MESSAGE) { +void ASSERT_UINT512(const epi::uint320_t &A, const epi::uint320_t &B, const std::string &TEST_MESSAGE) { std::cout << TEST_NAME << ":" << TEST_MESSAGE << " : "; - if(A!=B) { + if (A != B) { std::cout << "FAILED\n"; TEST_RESULTS.push_back(false); - } - else { + } else { std::cout << "PASSED\n"; TEST_RESULTS.push_back(true); } } -template -void ASSERT_ARRAY(T* A, T* B, size_t length, std::string TEST_MESSAGE, std::vector& RESULTS) { +template +void ASSERT_ARRAY(T *A, T *B, size_t length, std::string TEST_MESSAGE, std::vector &RESULTS) { std::cout << ":" << TEST_MESSAGE << " : "; bool result_passed = true; - for(size_t i=0; i #ifndef _MAKE_LIB -#include "../Header-Mode-ChaCha20-Poly1305.hpp" + #include "../Header-Mode-ChaCha20-Poly1305.hpp" #else -#include + #include #endif // #define PRINT_FAILED_OUTPUTS -std::vector TEST_RESULTS; +std::vector TEST_RESULTS; const static std::string TEST_NAME = "Poly1305 mac test 5 "; -void ASSERT_UINT512(const epi::uint320_t& A, const epi::uint320_t& B, const std::string& TEST_MESSAGE); +void ASSERT_UINT512(const epi::uint320_t &A, const epi::uint320_t &B, const std::string &TEST_MESSAGE); -template -void ASSERT_ARRAY(T* A, T* B, size_t length, std::string TEST_MESSAGE, std::vector& RESULTS); +template +void ASSERT_ARRAY(T *A, T *B, size_t length, std::string TEST_MESSAGE, std::vector &RESULTS); -void printBytes(unsigned char* bytearray, size_t len) { - for(size_t i=0; i(out_tag, tag, 16, "Poly1305 tag/mac test ", TEST_RESULTS); + + delete[] out_tag; - // TESTING ANSWER - ASSERT_ARRAY(out_tag,tag,16,"Poly1305 tag/mac test ",TEST_RESULTS); - - delete [] out_tag; - // SUMMARY OF RESULTS size_t failed_cnt = 0; - for(auto e : TEST_RESULTS) { - if(!e) failed_cnt++; + for (auto e: TEST_RESULTS) { + if (!e) + failed_cnt++; } std::cout << "---------------------------------\n"; - std::cout << TEST_NAME << " RESULT:" << "\n"; - if(!failed_cnt) { + std::cout << TEST_NAME << " RESULT:" + << "\n"; + if (!failed_cnt) { std::cout << "\tALL test PASSED\n"; std::cout << "---------------------------------\n"; return 0; - } - else { + } else { std::cout << "\tSOME test FAILED\n"; std::cout << "---------------------------------\n"; return 1; - } + } } - -void ASSERT_UINT512(const epi::uint320_t& A, const epi::uint320_t& B, const std::string& TEST_MESSAGE) { +void ASSERT_UINT512(const epi::uint320_t &A, const epi::uint320_t &B, const std::string &TEST_MESSAGE) { std::cout << TEST_NAME << ":" << TEST_MESSAGE << " : "; - if(A!=B) { + if (A != B) { std::cout << "FAILED\n"; TEST_RESULTS.push_back(false); - } - else { + } else { std::cout << "PASSED\n"; TEST_RESULTS.push_back(true); } } -template -void ASSERT_ARRAY(T* A, T* B, size_t length, std::string TEST_MESSAGE, std::vector& RESULTS) { +template +void ASSERT_ARRAY(T *A, T *B, size_t length, std::string TEST_MESSAGE, std::vector &RESULTS) { std::cout << ":" << TEST_MESSAGE << " : "; bool result_passed = true; - for(size_t i=0; i #ifndef _MAKE_LIB -#include "../Header-Mode-ChaCha20-Poly1305.hpp" + #include "../Header-Mode-ChaCha20-Poly1305.hpp" #else -#include + #include #endif // #define PRINT_FAILED_OUTPUTS -std::vector TEST_RESULTS; +std::vector TEST_RESULTS; const static std::string TEST_NAME = "Poly1305 mac test 6 "; -void ASSERT_UINT512(const epi::uint320_t& A, const epi::uint320_t& B, const std::string& TEST_MESSAGE); +void ASSERT_UINT512(const epi::uint320_t &A, const epi::uint320_t &B, const std::string &TEST_MESSAGE); -template -void ASSERT_ARRAY(T* A, T* B, size_t length, std::string TEST_MESSAGE, std::vector& RESULTS); +template +void ASSERT_ARRAY(T *A, T *B, size_t length, std::string TEST_MESSAGE, std::vector &RESULTS); -void printBytes(unsigned char* bytearray, size_t len) { - for(size_t i=0; i(out_tag, tag, 16, "Poly1305 tag/mac test ", TEST_RESULTS); + + delete[] out_tag; - // TESTING ANSWER - ASSERT_ARRAY(out_tag,tag,16,"Poly1305 tag/mac test ",TEST_RESULTS); - - delete [] out_tag; - // SUMMARY OF RESULTS size_t failed_cnt = 0; - for(auto e : TEST_RESULTS) { - if(!e) failed_cnt++; + for (auto e: TEST_RESULTS) { + if (!e) + failed_cnt++; } std::cout << "---------------------------------\n"; - std::cout << TEST_NAME << " RESULT:" << "\n"; - if(!failed_cnt) { + std::cout << TEST_NAME << " RESULT:" + << "\n"; + if (!failed_cnt) { std::cout << "\tALL test PASSED\n"; std::cout << "---------------------------------\n"; return 0; - } - else { + } else { std::cout << "\tSOME test FAILED\n"; std::cout << "---------------------------------\n"; return 1; - } + } } - -void ASSERT_UINT512(const epi::uint320_t& A, const epi::uint320_t& B, const std::string& TEST_MESSAGE) { +void ASSERT_UINT512(const epi::uint320_t &A, const epi::uint320_t &B, const std::string &TEST_MESSAGE) { std::cout << TEST_NAME << ":" << TEST_MESSAGE << " : "; - if(A!=B) { + if (A != B) { std::cout << "FAILED\n"; TEST_RESULTS.push_back(false); - } - else { + } else { std::cout << "PASSED\n"; TEST_RESULTS.push_back(true); } } -template -void ASSERT_ARRAY(T* A, T* B, size_t length, std::string TEST_MESSAGE, std::vector& RESULTS) { +template +void ASSERT_ARRAY(T *A, T *B, size_t length, std::string TEST_MESSAGE, std::vector &RESULTS) { std::cout << ":" << TEST_MESSAGE << " : "; bool result_passed = true; - for(size_t i=0; i #ifndef _MAKE_LIB -#include "../Header-Mode-ChaCha20-Poly1305.hpp" + #include "../Header-Mode-ChaCha20-Poly1305.hpp" #else -#include + #include #endif // #define PRINT_FAILED_OUTPUTS -std::vector TEST_RESULTS; +std::vector TEST_RESULTS; const static std::string TEST_NAME = "Poly1305 mac test 7 "; -void ASSERT_UINT512(const epi::uint320_t& A, const epi::uint320_t& B, const std::string& TEST_MESSAGE); +void ASSERT_UINT512(const epi::uint320_t &A, const epi::uint320_t &B, const std::string &TEST_MESSAGE); -template -void ASSERT_ARRAY(T* A, T* B, size_t length, std::string TEST_MESSAGE, std::vector& RESULTS); +template +void ASSERT_ARRAY(T *A, T *B, size_t length, std::string TEST_MESSAGE, std::vector &RESULTS); -void printBytes(unsigned char* bytearray, size_t len) { - for(size_t i=0; i(out_tag, tag, 16, "Poly1305 tag/mac test ", TEST_RESULTS); + + delete[] out_tag; - // TESTING ANSWER - ASSERT_ARRAY(out_tag,tag,16,"Poly1305 tag/mac test ",TEST_RESULTS); - - delete [] out_tag; - // SUMMARY OF RESULTS size_t failed_cnt = 0; - for(auto e : TEST_RESULTS) { - if(!e) failed_cnt++; + for (auto e: TEST_RESULTS) { + if (!e) + failed_cnt++; } std::cout << "---------------------------------\n"; - std::cout << TEST_NAME << " RESULT:" << "\n"; - if(!failed_cnt) { + std::cout << TEST_NAME << " RESULT:" + << "\n"; + if (!failed_cnt) { std::cout << "\tALL test PASSED\n"; std::cout << "---------------------------------\n"; return 0; - } - else { + } else { std::cout << "\tSOME test FAILED\n"; std::cout << "---------------------------------\n"; return 1; - } + } } - -void ASSERT_UINT512(const epi::uint320_t& A, const epi::uint320_t& B, const std::string& TEST_MESSAGE) { +void ASSERT_UINT512(const epi::uint320_t &A, const epi::uint320_t &B, const std::string &TEST_MESSAGE) { std::cout << TEST_NAME << ":" << TEST_MESSAGE << " : "; - if(A!=B) { + if (A != B) { std::cout << "FAILED\n"; TEST_RESULTS.push_back(false); - } - else { + } else { std::cout << "PASSED\n"; TEST_RESULTS.push_back(true); } } -template -void ASSERT_ARRAY(T* A, T* B, size_t length, std::string TEST_MESSAGE, std::vector& RESULTS) { +template +void ASSERT_ARRAY(T *A, T *B, size_t length, std::string TEST_MESSAGE, std::vector &RESULTS) { std::cout << ":" << TEST_MESSAGE << " : "; bool result_passed = true; - for(size_t i=0; i #ifndef _MAKE_LIB -#include "../Header-Mode-ChaCha20-Poly1305.hpp" + #include "../Header-Mode-ChaCha20-Poly1305.hpp" #else -#include + #include #endif // #define PRINT_FAILED_OUTPUTS -std::vector TEST_RESULTS; +std::vector TEST_RESULTS; const static std::string TEST_NAME = "Poly1305 mac test 8 "; -void ASSERT_UINT512(const epi::uint320_t& A, const epi::uint320_t& B, const std::string& TEST_MESSAGE); +void ASSERT_UINT512(const epi::uint320_t &A, const epi::uint320_t &B, const std::string &TEST_MESSAGE); -template -void ASSERT_ARRAY(T* A, T* B, size_t length, std::string TEST_MESSAGE, std::vector& RESULTS); +template +void ASSERT_ARRAY(T *A, T *B, size_t length, std::string TEST_MESSAGE, std::vector &RESULTS); -void printBytes(unsigned char* bytearray, size_t len) { - for(size_t i=0; i(out_tag, tag, 16, "Poly1305 tag/mac test ", TEST_RESULTS); + + delete[] out_tag; - // TESTING ANSWER - ASSERT_ARRAY(out_tag,tag,16,"Poly1305 tag/mac test ",TEST_RESULTS); - - delete [] out_tag; - // SUMMARY OF RESULTS size_t failed_cnt = 0; - for(auto e : TEST_RESULTS) { - if(!e) failed_cnt++; + for (auto e: TEST_RESULTS) { + if (!e) + failed_cnt++; } std::cout << "---------------------------------\n"; - std::cout << TEST_NAME << " RESULT:" << "\n"; - if(!failed_cnt) { + std::cout << TEST_NAME << " RESULT:" + << "\n"; + if (!failed_cnt) { std::cout << "\tALL test PASSED\n"; std::cout << "---------------------------------\n"; return 0; - } - else { + } else { std::cout << "\tSOME test FAILED\n"; std::cout << "---------------------------------\n"; return 1; - } + } } - -void ASSERT_UINT512(const epi::uint320_t& A, const epi::uint320_t& B, const std::string& TEST_MESSAGE) { +void ASSERT_UINT512(const epi::uint320_t &A, const epi::uint320_t &B, const std::string &TEST_MESSAGE) { std::cout << TEST_NAME << ":" << TEST_MESSAGE << " : "; - if(A!=B) { + if (A != B) { std::cout << "FAILED\n"; TEST_RESULTS.push_back(false); - } - else { + } else { std::cout << "PASSED\n"; TEST_RESULTS.push_back(true); } } -template -void ASSERT_ARRAY(T* A, T* B, size_t length, std::string TEST_MESSAGE, std::vector& RESULTS) { +template +void ASSERT_ARRAY(T *A, T *B, size_t length, std::string TEST_MESSAGE, std::vector &RESULTS) { std::cout << ":" << TEST_MESSAGE << " : "; bool result_passed = true; - for(size_t i=0; i #ifndef _MAKE_LIB -#include "../Header-Mode-ChaCha20-Poly1305.hpp" + #include "../Header-Mode-ChaCha20-Poly1305.hpp" #else -#include + #include #endif // #define PRINT_FAILED_OUTPUTS -std::vector TEST_RESULTS; +std::vector TEST_RESULTS; const static std::string TEST_NAME = "Poly1305 mac test 9 "; -void ASSERT_UINT512(const epi::uint320_t& A, const epi::uint320_t& B, const std::string& TEST_MESSAGE); +void ASSERT_UINT512(const epi::uint320_t &A, const epi::uint320_t &B, const std::string &TEST_MESSAGE); -template -void ASSERT_ARRAY(T* A, T* B, size_t length, std::string TEST_MESSAGE, std::vector& RESULTS); +template +void ASSERT_ARRAY(T *A, T *B, size_t length, std::string TEST_MESSAGE, std::vector &RESULTS); -void printBytes(unsigned char* bytearray, size_t len) { - for(size_t i=0; i(out_tag, tag, 16, "Poly1305 tag/mac test ", TEST_RESULTS); + + delete[] out_tag; - // TESTING ANSWER - ASSERT_ARRAY(out_tag,tag,16,"Poly1305 tag/mac test ",TEST_RESULTS); - - delete [] out_tag; - // SUMMARY OF RESULTS size_t failed_cnt = 0; - for(auto e : TEST_RESULTS) { - if(!e) failed_cnt++; + for (auto e: TEST_RESULTS) { + if (!e) + failed_cnt++; } std::cout << "---------------------------------\n"; - std::cout << TEST_NAME << " RESULT:" << "\n"; - if(!failed_cnt) { + std::cout << TEST_NAME << " RESULT:" + << "\n"; + if (!failed_cnt) { std::cout << "\tALL test PASSED\n"; std::cout << "---------------------------------\n"; return 0; - } - else { + } else { std::cout << "\tSOME test FAILED\n"; std::cout << "---------------------------------\n"; return 1; - } + } } - -void ASSERT_UINT512(const epi::uint320_t& A, const epi::uint320_t& B, const std::string& TEST_MESSAGE) { +void ASSERT_UINT512(const epi::uint320_t &A, const epi::uint320_t &B, const std::string &TEST_MESSAGE) { std::cout << TEST_NAME << ":" << TEST_MESSAGE << " : "; - if(A!=B) { + if (A != B) { std::cout << "FAILED\n"; TEST_RESULTS.push_back(false); - } - else { + } else { std::cout << "PASSED\n"; TEST_RESULTS.push_back(true); } } -template -void ASSERT_ARRAY(T* A, T* B, size_t length, std::string TEST_MESSAGE, std::vector& RESULTS) { +template +void ASSERT_ARRAY(T *A, T *B, size_t length, std::string TEST_MESSAGE, std::vector &RESULTS) { std::cout << ":" << TEST_MESSAGE << " : "; bool result_passed = true; - for(size_t i=0; i #ifndef _MAKE_LIB -#include "../Header-Mode-ChaCha20-Poly1305.hpp" + #include "../Header-Mode-ChaCha20-Poly1305.hpp" #else -#include + #include #endif using namespace std; // ChaCha State Comparison -bool CompareState(unsigned int *A, unsigned int *B){ - for(size_t i=0; i<16; ++i) - if(A[i] != B[i]) +bool CompareState(unsigned int *A, unsigned int *B) { + for (size_t i = 0; i < 16; ++i) + if (A[i] != B[i]) return false; return true; } -int main(){ +int main() { - unsigned int stack_state[4*4] = { - 0x879531e0, 0xc5ecf37d, 0x516461b1, 0xc9a62f8a, - 0x44c20ef3, 0x3390af7f, 0xd9fc690b, 0x2a5f714c, - 0x53372767, 0xb00a5631, 0x974c541a, 0x359e9963, - 0x5c971061, 0x3d631689, 0x2098d9d6, 0x91dbd320, + unsigned int stack_state[4 * 4] = { + 0x879531e0, 0xc5ecf37d, 0x516461b1, 0xc9a62f8a, 0x44c20ef3, 0x3390af7f, 0xd9fc690b, 0x2a5f714c, + 0x53372767, 0xb00a5631, 0x974c541a, 0x359e9963, 0x5c971061, 0x3d631689, 0x2098d9d6, 0x91dbd320, }; unsigned int *heap_state = new unsigned int[16]; - for(size_t i=0; i<(4*4); ++i) + for (size_t i = 0; i < (4 * 4); ++i) heap_state[i] = stack_state[i]; - unsigned int correct_state[4*4] = { - 0x879531e0, 0xc5ecf37d, 0xbdb886dc, 0xc9a62f8a, - 0x44c20ef3, 0x3390af7f, 0xd9fc690b, 0xcfacafd2, - 0xe46bea80, 0xb00a5631, 0x974c541a, 0x359e9963, - 0x5c971061, 0xccc07c79, 0x2098d9d6, 0x91dbd320 - }; + unsigned int correct_state[4 * 4] = {0x879531e0, 0xc5ecf37d, 0xbdb886dc, 0xc9a62f8a, 0x44c20ef3, 0x3390af7f, + 0xd9fc690b, 0xcfacafd2, 0xe46bea80, 0xb00a5631, 0x974c541a, 0x359e9963, + 0x5c971061, 0xccc07c79, 0x2098d9d6, 0x91dbd320}; chacha20::QUARTERROUND(stack_state, 2, 7, 8, 13); chacha20::QUARTERROUND(heap_state, 2, 7, 8, 13); - bool passed = CompareState(stack_state,correct_state) && CompareState(heap_state,correct_state); + bool passed = CompareState(stack_state, correct_state) && CompareState(heap_state, correct_state); - delete [] heap_state; + delete[] heap_state; - if(passed) { + if (passed) { std::cout << "ChaChaQuarterRoundTest : PASSED\n"; return 0; - } - else { + } else { std::cout << "ChaChaQuarterRoundTest : FAILED\n"; return 1; } diff --git a/tests/chacha20_aead_enc_dec.cpp b/tests/chacha20_aead_enc_dec.cpp index 8062c1a..79c0ad4 100644 --- a/tests/chacha20_aead_enc_dec.cpp +++ b/tests/chacha20_aead_enc_dec.cpp @@ -3,21 +3,21 @@ #include #ifndef _MAKE_LIB -#include "../Header-Mode-ChaCha20-Poly1305.hpp" + #include "../Header-Mode-ChaCha20-Poly1305.hpp" #else -#include + #include #endif // #define PRINT_FAILED_OUTPUTS -std::vector TEST_RESULTS; +std::vector TEST_RESULTS; const static std::string TEST_NAME = "Initial ChaCha20Poly1305 encrypt, decrypt, authenticate test "; -void ASSERT_UINT512(const epi::uint320_t& A, const epi::uint320_t& B, const std::string& TEST_MESSAGE); +void ASSERT_UINT512(const epi::uint320_t &A, const epi::uint320_t &B, const std::string &TEST_MESSAGE); -template -void ASSERT_ARRAY(T* A, T* B, size_t length, std::string TEST_MESSAGE, std::vector& RESULTS); +template +void ASSERT_ARRAY(T *A, T *B, size_t length, std::string TEST_MESSAGE, std::vector &RESULTS); -void printBytes(unsigned char* bytearray, size_t len) { - for(size_t i=0; i(ciphertext,correct_cipher,sizeof(plaintext),"ChaCha20 cipher text",TEST_RESULTS); - ASSERT_ARRAY(recovered,plaintext,sizeof(plaintext), "ChaCha20 recovered text",TEST_RESULTS); - ASSERT_ARRAY(tag,correct_tag,sizeof(correct_tag), "Poly1305 encryption tag",TEST_RESULTS); - ASSERT_ARRAY(tag,recovered_tag,sizeof(recovered_tag), "Poly1305 decryption tag",TEST_RESULTS); - bool constcomp = poly1305::verify(tag,recovered_tag); - if(constcomp) { + 0xd3, 0x1a, 0x8d, 0x34, 0x64, 0x8e, 0x60, 0xdb, 0x7b, 0x86, 0xaf, 0xbc, 0x53, 0xef, 0x7e, 0xc2, 0xa4, 0xad, 0xed, + 0x51, 0x29, 0x6e, 0x08, 0xfe, 0xa9, 0xe2, 0xb5, 0xa7, 0x36, 0xee, 0x62, 0xd6, 0x3d, 0xbe, 0xa4, 0x5e, 0x8c, 0xa9, + 0x67, 0x12, 0x82, 0xfa, 0xfb, 0x69, 0xda, 0x92, 0x72, 0x8b, 0x1a, 0x71, 0xde, 0x0a, 0x9e, 0x06, 0x0b, 0x29, 0x05, + 0xd6, 0xa5, 0xb6, 0x7e, 0xcd, 0x3b, 0x36, 0x92, 0xdd, 0xbd, 0x7f, 0x2d, 0x77, 0x8b, 0x8c, 0x98, 0x03, 0xae, 0xe3, + 0x28, 0x09, 0x1b, 0x58, 0xfa, 0xb3, 0x24, 0xe4, 0xfa, 0xd6, 0x75, 0x94, 0x55, 0x85, 0x80, 0x8b, 0x48, 0x31, 0xd7, + 0xbc, 0x3f, 0xf4, 0xde, 0xf0, 0x8e, 0x4b, 0x7a, 0x9d, 0xe5, 0x76, 0xd2, 0x65, 0x86, 0xce, 0xc6, 0x4b, 0x61, 0x16}; + + unsigned char correct_tag[16] = {0x1a, 0xe1, 0x0b, 0x59, 0x4f, 0x09, 0xe2, 0x6a, + 0x7e, 0x90, 0x2e, 0xcb, 0xd0, 0x60, 0x06, 0x91}; + + ASSERT_ARRAY(ciphertext, correct_cipher, sizeof(plaintext), "ChaCha20 cipher text", TEST_RESULTS); + ASSERT_ARRAY(recovered, plaintext, sizeof(plaintext), "ChaCha20 recovered text", TEST_RESULTS); + ASSERT_ARRAY(tag, correct_tag, sizeof(correct_tag), "Poly1305 encryption tag", TEST_RESULTS); + ASSERT_ARRAY(tag, recovered_tag, sizeof(recovered_tag), "Poly1305 decryption tag", TEST_RESULTS); + bool constcomp = poly1305::verify(tag, recovered_tag); + if (constcomp) { std::cout << "Poly1305 Constant Time Comparision : Passed\n"; - } - else { + } else { std::cout << "Poly1305 Constant Time Comparision : Failed\n"; } TEST_RESULTS.push_back(constcomp); // SUMMARY OF RESULTS size_t failed_cnt = 0; - for(auto e : TEST_RESULTS) { - if(!e) failed_cnt++; + for (auto e: TEST_RESULTS) { + if (!e) + failed_cnt++; } std::cout << "---------------------------------\n"; - std::cout << TEST_NAME << " RESULT:" << "\n"; - if(!failed_cnt) { + std::cout << TEST_NAME << " RESULT:" + << "\n"; + if (!failed_cnt) { std::cout << "\tALL test PASSED\n"; std::cout << "---------------------------------\n"; return 0; - } - else { + } else { std::cout << "\tSOME test FAILED\n"; std::cout << "---------------------------------\n"; return 1; - } + } } - -void ASSERT_UINT512(const epi::uint320_t& A, const epi::uint320_t& B, const std::string& TEST_MESSAGE) { +void ASSERT_UINT512(const epi::uint320_t &A, const epi::uint320_t &B, const std::string &TEST_MESSAGE) { std::cout << TEST_NAME << ":" << TEST_MESSAGE << " : "; - if(A!=B) { + if (A != B) { std::cout << "FAILED\n"; TEST_RESULTS.push_back(false); - } - else { + } else { std::cout << "PASSED\n"; TEST_RESULTS.push_back(true); } } -template -void ASSERT_ARRAY(T* A, T* B, size_t length, std::string TEST_MESSAGE, std::vector& RESULTS) { +template +void ASSERT_ARRAY(T *A, T *B, size_t length, std::string TEST_MESSAGE, std::vector &RESULTS) { std::cout << ":" << TEST_MESSAGE << " : "; bool result_passed = true; - for(size_t i=0; i #ifndef _MAKE_LIB -#include "../Header-Mode-ChaCha20-Poly1305.hpp" + #include "../Header-Mode-ChaCha20-Poly1305.hpp" #else -#include + #include #endif // #define PRINT_FAILED_OUTPUTS -std::vector TEST_RESULTS; +std::vector TEST_RESULTS; const static std::string TEST_NAME = "poly1305 keygen"; -template -void ASSERT_ARRAY(T* A, T* B, size_t length, std::string TEST_MESSAGE, std::vector& RESULTS); +template +void ASSERT_ARRAY(T *A, T *B, size_t length, std::string TEST_MESSAGE, std::vector &RESULTS); -void printBytes(unsigned char* bytearray, size_t len) { - for(size_t i=0; i(poly1305_key,poly1305_key_correct,32,"generated key matching",TEST_RESULTS); + ASSERT_ARRAY(poly1305_key, poly1305_key_correct, 32, "generated key matching", TEST_RESULTS); // SUMMARY OF RESULTS size_t failed_cnt = 0; - for(auto e : TEST_RESULTS) { - if(!e) failed_cnt++; + for (auto e: TEST_RESULTS) { + if (!e) + failed_cnt++; } std::cout << "---------------------------------\n"; - std::cout << TEST_NAME << " RESULT:" << "\n"; - if(!failed_cnt) { + std::cout << TEST_NAME << " RESULT:" + << "\n"; + if (!failed_cnt) { std::cout << "\tALL test PASSED\n"; std::cout << "---------------------------------\n"; return 0; - } - else { + } else { std::cout << "\tSOME test FAILED\n"; std::cout << "---------------------------------\n"; return 1; - } + } } -template -void ASSERT_ARRAY(T* A, T* B, size_t length, std::string TEST_MESSAGE, std::vector& RESULTS) { +template +void ASSERT_ARRAY(T *A, T *B, size_t length, std::string TEST_MESSAGE, std::vector &RESULTS) { std::cout << ":" << TEST_MESSAGE << " : "; bool result_passed = true; - for(size_t i=0; i #ifndef _MAKE_LIB -#include "../Header-Mode-ChaCha20-Poly1305.hpp" + #include "../Header-Mode-ChaCha20-Poly1305.hpp" #else -#include + #include #endif // #define PRINT_FAILED_OUTPUTS -std::vector TEST_RESULTS; +std::vector TEST_RESULTS; const static std::string TEST_NAME = "poly1305 mac"; -template -void ASSERT_ARRAY(T* A, T* B, size_t length, std::string TEST_MESSAGE, std::vector& RESULTS); +template +void ASSERT_ARRAY(T *A, T *B, size_t length, std::string TEST_MESSAGE, std::vector &RESULTS); -void print16bytes(unsigned char* bytearray16) { - for(size_t i=0; i<16; ++i) { +void print16bytes(unsigned char *bytearray16) { + for (size_t i = 0; i < 16; ++i) { printf("%02x ", bytearray16[i]); } std::cout << "\n"; } - int main() { std::cout << "\n---------------------------------\n"; std::cout << TEST_NAME << "\n=================================\n"; - // TEST VARIABLES - unsigned char key[32] = { - 0x85, 0xd6, 0xbe, 0x78, 0x57, 0x55, 0x6d, 0x33, 0x7f, 0x44, 0x52, 0xfe, 0x42, 0xd5, 0x06, 0xa8, - 0x01, 0x03, 0x80, 0x8a, 0xfb, 0x0d, 0xb2, 0xfd, 0x4a, 0xbf, 0xf6, 0xaf, 0x41, 0x49, 0xf5, 0x1b - }; + unsigned char key[32] = {0x85, 0xd6, 0xbe, 0x78, 0x57, 0x55, 0x6d, 0x33, 0x7f, 0x44, 0x52, + 0xfe, 0x42, 0xd5, 0x06, 0xa8, 0x01, 0x03, 0x80, 0x8a, 0xfb, 0x0d, + 0xb2, 0xfd, 0x4a, 0xbf, 0xf6, 0xaf, 0x41, 0x49, 0xf5, 0x1b}; unsigned char msg[34] = { - 0x43, 0x72, 0x79, 0x70, 0x74, 0x6f, 0x67, 0x72, 0x61, 0x70, 0x68, 0x69, 0x63, 0x20, 0x46, 0x6f, - 0x72, 0x75, 0x6d, 0x20, 0x52, 0x65, 0x73, 0x65, 0x61, 0x72, 0x63, 0x68, 0x20, 0x47, 0x72, 0x6f, - 0x75, 0x70, + 0x43, 0x72, 0x79, 0x70, 0x74, 0x6f, 0x67, 0x72, 0x61, 0x70, 0x68, 0x69, 0x63, 0x20, 0x46, 0x6f, 0x72, + 0x75, 0x6d, 0x20, 0x52, 0x65, 0x73, 0x65, 0x61, 0x72, 0x63, 0x68, 0x20, 0x47, 0x72, 0x6f, 0x75, 0x70, }; + // ANSWERS + unsigned char tag[16]; - // ANSWERS - unsigned char tag[16]; - - poly1305::mac(tag,key,msg,34); // + poly1305::mac(tag, key, msg, 34); // // TEST CORRECT ANSWER - unsigned char correct_tag[16] = { - 0xa8, 0x06, 0x1d, 0xc1, 0x30, 0x51, 0x36, 0xc6, 0xc2, 0x2b, 0x8b, 0xaf, 0x0c, 0x01, 0x27, 0xa9 - }; + unsigned char correct_tag[16] = {0xa8, 0x06, 0x1d, 0xc1, 0x30, 0x51, 0x36, 0xc6, + 0xc2, 0x2b, 0x8b, 0xaf, 0x0c, 0x01, 0x27, 0xa9}; - // TESTING ANSWER - ASSERT_ARRAY(tag,correct_tag,16,"output tag correctness 1",TEST_RESULTS); + // TESTING ANSWER + ASSERT_ARRAY(tag, correct_tag, 16, "output tag correctness 1", TEST_RESULTS); // SUMMARY OF RESULTS size_t failed_cnt = 0; - for(auto e : TEST_RESULTS) { - if(!e) failed_cnt++; + for (auto e: TEST_RESULTS) { + if (!e) + failed_cnt++; } std::cout << "---------------------------------\n"; - std::cout << TEST_NAME << " RESULT:" << "\n"; - if(!failed_cnt) { + std::cout << TEST_NAME << " RESULT:" + << "\n"; + if (!failed_cnt) { std::cout << "\tALL test PASSED\n"; std::cout << "---------------------------------\n"; return 0; - } - else { + } else { std::cout << "\tSOME test FAILED\n"; std::cout << "---------------------------------\n"; return 1; - } + } } -template -void ASSERT_ARRAY(T* A, T* B, size_t length, std::string TEST_MESSAGE, std::vector& RESULTS) { +template +void ASSERT_ARRAY(T *A, T *B, size_t length, std::string TEST_MESSAGE, std::vector &RESULTS) { std::cout << ":" << TEST_MESSAGE << " : "; bool result_passed = true; - for(size_t i=0; i