The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Crypt::CCM - CCM Mode for symmetric key block ciphers

SYNOPSIS

  use Crypt::CCM;
  use strict;
  
  my $ccm = Crypt::CCM->new(-key => $key);
  $ccm->set_nonce($random_nonce);
  $ccm->set_aad($assoc_data);
  my $cipher_text = $ccm->encrypt($plain_text);

DESCRIPTION

The module implements the CCM Mode for Authentication and Confidentiality.

API

new(ARGS)

  my $cipher = Crypt::CCM->new(
      -key        => $secret_key,
      -cipher     => 'Crypt::Rijndael',
      -nonce      => $nonce,
      -aad        => $associated_data,
      -tag_length => 128/8,
  );

The new() method creates an new Crypt::CCM object. it accepts a list of -artument => value pairs selected form the following list:

  Argument    Description
  --------    -----------
  -key        The encryption/decryption key
  -cipher     The cipher algorithm module name
  -nonce      The nonce. 
  -aad        The associated data (default '')
  -tag_length The bytes length of the MAC (default 128/8)

set_cipher($cipher)

  $cipher->set_cipher(Crypt::Rijndael->new($key));

set_nonce($nonce)

  $cipher->set_nonce($nonce);

This allows you to change the 'nonce'. allow 7,8,9,10,11,12,13 byte string.

set_aad($associated_data)

set_tag_length($length)

This allows you to change the MAC length. allow 4,6,8,10,12,14,16 byte string.

encrypt($plain_text);

  my $cipher_text = $cipher->encrypt($plain_text);

decrypt($cipher_text)

  my $plain_text = $cipher->decrypt($cipher_text);

EXAMPLE

Encrypt

  use Crypt::CCM;
  use strict;
  
  my $key             = pack 'H*', '00000000000000000000000000000000'; 
  my $nonce           = pack 'H*', '0000000000000000';
  my $associated_data = 'this is associated data';
  my $plain_text      = 'Hello World!';
  my $c = Crypt::CCM->new(
      -key    => $key,
      -cipher => 'Crypt::Rijndael'
  );
  $c->set_nonce($nonce);
  $c->set_aad($associated_data);
  my $cipher_text = $c->encrypt($plain_text);
  printf qq{encrypt: %s (hex)\n}, unpack 'H*', $cipher_text;

Decrypt

  use Crypt::CCM;
  use strict;
  
  my $key             = pack 'H*', '00000000000000000000000000000000'; 
  my $nonce           = pack 'H*', '0000000000000000';
  my $associated_data = 'this is associated data';
  my $cipher_text     = pack 'H*', '08da066234def1e5c7481a5a40b6aa4319332731a184426ac77f47de';
  
  my $c = Crypt::CCM->new(
      -key => $key,
      -cipher => 'Crypt::Rijndael'
  );
  $c->set_nonce($nonce);
  $c->set_aad($associated_data);
  my $plain_text = $c->decrypt($cipher_text);
  printf qq{decrypt: %s\n}, $plain_text;

SEE ALSO

NIST Special Publication 800-38C - Recommendation for Block Cipher Modes of Operation: The CCM Mode for Authentication and Confidentiality.

http://csrc.nist.gov/CryptoToolkit/modes/800-38_Series_Publications/SP800-38C.pdf

RFC 3610 - Counter with CBC-MAC (CCM)

http://tools.ietf.org/html/rfc3610

AUTHOR

Hiroyuki OYAMA, <oyama@module.jp<gt>

COPYRIGHT AND LICENSE

Copyright (C) 2006 by Hiroyuki OYAMA

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.6 or, at your option, any later version of Perl 5 you may have available.