#include "tomcrypt.h"
#include <string>
int main() {
register_all_ciphers();
int idx, err;
idx = find_cipher("aes");
if (idx == -1) {
idx = find_cipher("rijndael");
if (idx == -1) {
return CRYPT_NOP;
}
}
unsigned char key[16] = {
0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c,
0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08 };
unsigned char AAD[20] = {
0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
0xab, 0xad, 0xda, 0xd2 };
std::string initVector = "My initiailization vector";
unsigned char encText[100];
unsigned long inputText_size;
{
unsigned char tag[16];
unsigned long tag_Size = 16;
std::string inputText = "QWERTYUIOPASDFGHJKLZXCVBNM?";
inputText_size = inputText.size();
err = gcm_memory(idx,
key, 16,
(unsigned char*)initVector.data(), initVector.size(),
AAD, 20,
(unsigned char*)inputText.data(), inputText_size,
encText, tag, &tag_Size, GCM_ENCRYPT
);
}
{
unsigned char tag[16];
unsigned long tag_Size = 16;
std::string outputText(inputText_size, 0);
err = gcm_memory(idx,
key, 16,
(unsigned char*)initVector.data(), initVector.size(),
AAD, 20,
(unsigned char*)outputText.data(), inputText_size,
encText, tag, &tag_Size, GCM_DECRYPT
);
}
}