I have following simple function
uint128_t crypto_aes_prf( ECB_Mode< AES >::Encryption& e, int message)
{
// Encrypt the input using AES
unsigned char messageBytes[16]= {0};
unsigned char ciphertext[16] = {0};
std::memcpy(messageBytes, &message, sizeof(message));
e.ProcessData(ciphertext, messageBytes, sizeof(messageBytes));
uint128_t result = 0;
for (size_t i = 0; i < sizeof(ciphertext); ++i)
{
result = (result << 8) | static_cast<uint8_t>(ciphertext[i]);
}
return result;
}
Here the encryptor is initialized as follows:
std::string key = "0123456789abcdef";
CryptoPP::SecByteBlock aesKey(reinterpret_cast<const unsigned char*>(&key), 16);
CryptoPP::SecByteBlock iv(CryptoPP::AES::BLOCKSIZE);
// // Setup AES encryption
ECB_Mode< AES >::Encryption e;
e.SetKey(aesKey, CryptoPP::AES::DEFAULT_KEYLENGTH);
and then I call is using
auto c3= crypto_aes_prf(e, 65654);
Issue is that the performance is very slow, it is around 2 microseconds, more strangely when I call the function again using same encryptor then it takes only 150 nanoseconds.
I am not sure why this change in the performance based on how many times it is run?