I've written some code to do AES-GCM authenticated encryption like:

static inline void aes256GcmEncrypt(const Aes256Key &key,const void 
*iv,unsigned int ivLength,const void *header,const unsigned int 
headerLength,const void *message,const unsigned int messageLength,void 
*mac,unsigned int macLength,void *messageCipherText)
{
CryptoPP::GCM<CryptoPP::AES>::Encryption enc;
enc.SetKeyWithIV(key.data(),key.size(),reinterpret_cast<const uint8_t 
*>(iv),ivLength);
enc.EncryptAndAuthenticate(
reinterpret_cast<uint8_t *>(messageCipherText),
reinterpret_cast<uint8_t *>(mac),
macLength,
reinterpret_cast<const uint8_t *>(iv),
ivLength,
reinterpret_cast<const uint8_t *>(header),
headerLength,
reinterpret_cast<const uint8_t *>(message),
messageLength);
}

static inline bool aes256GcmDecryptAndVerify(const Aes256Key &key,const 
void *iv,unsigned int ivLength,const void *header,const unsigned int 
headerLength,const void *messageCipherText,const unsigned int 
messageLength,const void *mac,unsigned int macLength,void *message)
{
CryptoPP::GCM<CryptoPP::AES>::Decryption dec;
dec.SetKeyWithIV(key.data(),key.size(),reinterpret_cast<const uint8_t 
*>(iv),ivLength);
return dec.DecryptAndVerify(
reinterpret_cast<uint8_t *>(message),
reinterpret_cast<const uint8_t *>(mac),
macLength,
reinterpret_cast<const uint8_t *>(iv),
ivLength,
reinterpret_cast<const uint8_t *>(header),
headerLength,
reinterpret_cast<const uint8_t *>(messageCipherText),
messageLength);
}

It's pretty straightforward but given AES's complex key schedule isn't it 
really slow to re-key AES every single time? I found classes and code for 
re-using a keyed AES instance with other cipher modes but I can't find 
anything about GCM and the same sorts of classes don't seem to exist.

Is there any way to re-use a keyed/initialized AES instance with GCM?

-- 
-- 
You received this message because you are subscribed to the "Crypto++ Users" 
Google Group.
To unsubscribe, send an email to [email protected].
More information about Crypto++ and this group is available at 
http://www.cryptopp.com.
--- 
You received this message because you are subscribed to the Google Groups 
"Crypto++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to