Crypt::CCM - CCM Mode for symmetric key block ciphers
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);
The module implements the CCM Mode for Authentication and Confidentiality.
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)
$cipher->set_cipher(Crypt::Rijndael->new($key));
$cipher->set_nonce($nonce);
This allows you to change the 'nonce'. allow 7,8,9,10,11,12,13 byte string.
This allows you to change the MAC length. allow 4,6,8,10,12,14,16 byte string.
my $cipher_text = $cipher->encrypt($plain_text);
my $plain_text = $cipher->decrypt($cipher_text);
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;
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;
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
Hiroyuki OYAMA, <oyama@module.jp<gt>
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.
To install Crypt::CCM, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Crypt::CCM
CPAN shell
perl -MCPAN -e shell install Crypt::CCM
For more information on module installation, please visit the detailed CPAN module installation guide.