Cryptography Reference
In-Depth Information
memset( nonce + 12, '\0', sizeof( unsigned int ) );
nonce[ 15 ] = 0x01;
if ( !decrypt )
{
gf_multiply( input_block, H, output );
// Now encrypt the MAC block and output it
aes_block_encrypt( nonce, input_block, key, 16 );
xor( output, input_block, AES_BLOCK_SIZE );
}
else
{
gf_multiply( input_block, H, mac_block );
// Now decrypt the final (MAC) block and compare it
aes_block_encrypt( nonce, input_block, key, 16 );
xor( input_block, input, AES_BLOCK_SIZE );
if ( memcmp( mac_block, input_block, AES_BLOCK_SIZE ) )
{
return 1;
}
}
return 0;
}
int aes_gcm_encrypt( const unsigned char *input,
int input_len,
unsigned char *output,
void *iv,
const unsigned char *key )
{
return aes_gcm_process( input, input_len, output, iv, key, 0 );
}
int aes_gcm_decrypt( const unsigned char *input,
int input_len,
unsigned char *output,
void *iv,
const unsigned char *key )
{
return aes_gcm_process( input, input_len, output, iv, key, 1 );
}
AES-CCM and AES-GCM are fairly simple to understand, but not necessarily
simple to implement, due to the required precision surrounding their associ-
ated MACs. Fortunately, once you get the details all worked out, you can treat
Search WWH ::




Custom Search