Cryptography Reference
In-Depth Information
unsigned int next_nonce;
int process_len;
int block_size;
input_block[ 0 ] = 0x1F; // t = mac_length = 8 bytes, q = 8 bytes (so n = 7)
process_len = input_len - ( decrypt ? MAC_LENGTH : 0 );
header_length_declaration = htonl( process_len );
while ( process_len )
{
// Increment counter
memcpy( ( void * ) &next_nonce, ( void * ) ( nonce + 12 ),
sizeof( unsigned int ) );
block_size = ( process_len < AES_BLOCK_SIZE ) ?
process_len : AES_BLOCK_SIZE;
// update the CBC-MAC
memset( input_block, '\0', AES_BLOCK_SIZE );
memcpy( input_block, decrypt ? output : input , block_size );
xor( input_block, mac_block, AES_BLOCK_SIZE );
output += block_size;
process_len -= block_size;
}
if ( !decrypt )
{
xor( mac_block, input_block, MAC_LENGTH );
memcpy( output, mac_block, MAC_LENGTH );
return 1;
}
else
{
xor( input_block, input, MAC_LENGTH );
if ( memcmp( mac_block, input_block, MAC_LENGTH ) )
{
return 0;
}
return 1;
}
int aes_ccm_encrypt( const unsigned char *input,
int input_len,
unsigned char *output,
void *iv,
const unsigned char *key )
{
return aes_ccm_process( input, input_len, output, iv, key, 0 );
}
(Continued)
Search WWH ::




Custom Search