#include #include "gtest/gtest.h" #include "utils.h" #include "crypto.h" typedef std::basic_string ustring; std::vector string_to_bytes(const std::string& str){ std::vector out; transform(str.begin(), str.end(), std::back_inserter(out), [](auto c){return static_cast(c);}); return out; } /* test command: echo "ditemi perche' se la mucca fa mu il merlo non fa me" | scripts/aes256.sh -k 0123456789ABCDEF0123456789ABCDEF -i 0123456789ABCDEF | xxd -i */ const std::string test1_str = "ditemi perche' se la mucca fa mu il merlo non fa me"; const std::string test1_key = "0123456789ABCDEF0123456789ABCDEF"; const std::string test1_iv = "0123456789ABCDEF"; const std::vector test1_enc { 0x4c, 0x17, 0x6e, 0x6d, 0xd2, 0x83, 0x51, 0x52, 0xfc, 0x5d, 0xbe, 0x0f, 0x1b, 0xcf, 0x86, 0xef, 0x73, 0x91, 0x58, 0xc4, 0xdd, 0x1b, 0x09, 0x3d, 0x77, 0xe0, 0x78, 0x5d, 0x21, 0xfe, 0x59, 0x9c, 0xb2, 0x12, 0xa6, 0x81, 0x12, 0x96, 0x50, 0xd6, 0x5c, 0xe2, 0xc1, 0x99, 0xe3, 0x38, 0x39, 0x8e, 0x55, 0xd2, 0x04, 0x73, 0x16, 0x39, 0xc7, 0x6a, 0xd3, 0x61, 0x2c, 0x22, 0x59, 0x25, 0xa6, 0x20 }; TEST(encryptTest, test1){ const std::vector input(test1_str.begin(), test1_str.end()); size_t output_len = input.size() + 16; std::vector output(output_len); const std::vector key(test1_key.begin(), test1_key.end()); const std::vector iv(test1_iv.begin(), test1_iv.end()); AES256 a; a.encrypt(key, iv, input, input.size(), output, output_len); EXPECT_EQ(test1_enc, output); }