horcrux/test/crypto-test.cpp
Michele Rodolfi db5dfcaa85 Initial commit
Base project structure
2020-12-11 12:38:02 +01:00

44 lines
1.6 KiB
C++

#include <string>
#include "gtest/gtest.h"
#include "utils.h"
#include "crypto.h"
typedef std::basic_string<unsigned char> ustring;
std::vector<std::byte> string_to_bytes(const std::string& str){
std::vector<std::byte> out;
transform(str.begin(), str.end(), std::back_inserter(out), [](auto c){return static_cast<std::byte>(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<unsigned char> 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<unsigned char> input(test1_str.begin(), test1_str.end());
size_t output_len = input.size() + 16;
std::vector<unsigned char> output(output_len);
const std::vector<unsigned char> key(test1_key.begin(), test1_key.end());
const std::vector<unsigned char> iv(test1_iv.begin(), test1_iv.end());
AES256 a;
a.encrypt(key, iv, input, input.size(), output, output_len);
EXPECT_EQ(test1_enc, output);
}