Crypt-ARIA

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

Release history for Crypt::ARIA

0.004     2013-11-28 12:11:15 Asia/Seoul
          add Crypt::CBC >= 2.31 condition to test.

0.003     2013-11-26 22:13:46 Asia/Seoul
          Fix POD.

0.002     2013-11-26 15:16:44 Asia/Seoul
          Fix POD. Fix testing Crypt::CBC

0.001     2013-11-26 12:26:09 Asia/Seoul
          First release

META.yml  view on Meta::CPAN

---
abstract: 'Perl extension for ARIA encryption/decryption algorithm.'
author:
  - 'Geunyoung Park <gypark@gmail.com>'
build_requires:
  Crypt::CBC: 2.31
  Test::More: 0
configure_requires:
  ExtUtils::MakeMaker: 6.30
dynamic_config: 0
generated_by: 'Dist::Zilla version 5.005, CPAN::Meta::Converter version 2.120921'
license: perl
meta-spec:
  url: http://module-build.sourceforge.net/META-spec-v1.4.html
  version: 1.4
name: Crypt-ARIA

Makefile.PL  view on Meta::CPAN

  "NAME" => "Crypt::ARIA",
  "PREREQ_PM" => {
    "Carp" => 0,
    "Exporter" => 0,
    "XSLoader" => 0,
    "constant" => 0,
    "strict" => 0,
    "warnings" => 0
  },
  "TEST_REQUIRES" => {
    "Crypt::CBC" => "2.31",
    "Test::More" => 0
  },
  "VERSION" => "0.004",
  "test" => {
    "TESTS" => "t/*.t"
  }
);


unless ( eval { ExtUtils::MakeMaker->VERSION(6.63_03) } ) {

lib/Crypt/ARIA.pm  view on Meta::CPAN


  
  # multi block encryption/decryption
  # simple ECB mode
  my $cipher    = $aria->encrypt_ecb( $plain );
  my $decrypted = $aria->decrypt_ecb( $cipher );
  # note that $decrypt may not be same as $plain, because it is appended
  # null bytes to.


  # CBC mode
  use Crypt::CBC;
  my $cbc = Crypt::CBC->new(
        -cipher => Crypt::ARIA->new()->set_key( $key ),
        -iv     => $initial_vector,
        -header => 'none';
        -padding => 'none';
    );
  my $cipher = $cbc->encrypt( $plain );
  my $plain  = $cbc->decrypt( $cipher );

=head1 DESCRIPTION

lib/Crypt/ARIA.pm  view on Meta::CPAN

C<encrypt()> encrypts a block of plaintext.

  my $cipher = $aria->encrypt( $plain );

$plain should be of exactly 16 bytes.
It returns a ciphertext of 16 bytes.
If you want to encrypt a text of different length,
you have to choose the operation mode and the padding method.
You may implement them by yourself or use another module for them.

C<Crypt::ARIA> is designed to be compatible with L<Crypt::CBC>.
Therefore, you can use C<Crypt::CBC> to use CBC mode with several
padding methods.

  use Crypt::CBC;
  my $cbc = Crypt::CBC->new(
        -cipher => Crypt::ARIA->new()->set_key( $key ),
        -iv     => $initial_vector,
        -header => 'none';
        -padding => 'none';
    );
  my $cipher = $cbc->encrypt( $plain );
  my $plain  = $cbc->decrypt( $cipher );

=item decrypt

lib/Crypt/ARIA.pm  view on Meta::CPAN

This method encrypts a plaintext of arbitrary length.

  my $cipher  = $aria->encrypt_ecb( $plain );

It returns the ciphertext whose length is multiple of 16 bytes.

NOTE: If the length of $plain is not n-times of 16 exactly,
C<encrypt_ecb()> appends null bytes to fill it. If the length
is n-times of 16 exactly, $plain would be untouched. This means
you should have to deliver the original length of $plain to the
receiver. You had better use other module like L<Crypt::CBC> that
provides advanced operation mode and padding method.
This method is just for test purpose.

=item decrypt_ecb

This method decrypts a multi-block ciphertext.

  my $decrypted = $aria->decrypt_ecb( $cipher );

As described in L</encrypt_ecb>, $decrypted may contain a sequence
of null bytes in its end. You should remove them yourself.

=back

=head1 SEE ALSO

L<Crypt::CBC>, L<Crypt::SEED>

L<http://en.wikipedia.org/wiki/ARIA_%28cipher%29>

L<http://210.104.33.10/ARIA/index-e.html>

IETF RFC 5794 : A Description of the ARIA Encryption Algorithm
L<http://tools.ietf.org/html/rfc5794>

=head1 AUTHOR

t/04-using_crypt_cbc.t  view on Meta::CPAN


use strict;
use warnings;

use Test::More;
use Crypt::ARIA;

#########################

SKIP: {
	eval { require Crypt::CBC; Crypt::CBC->VERSION(2.31); 1 };

	skip "Crypt::CBC >= 2.31 not installed", 8 if $@;

# CBC
{

	my $key = '00112233445566778899aabbccddeeff';
	my $iv  = '0f1e2d3c4b5a69788796a5b4c3d2e1f0';

	my $plain = <<'END';
11 11 11 11 aa aa aa aa 11 11 11 11 bb bb bb bb
11 11 11 11 cc cc cc cc 11 11 11 11 dd dd dd dd
22 22 22 22 aa aa aa aa 22 22 22 22 bb bb bb bb
22 22 22 22 cc cc cc cc 22 22 22 22 dd dd dd dd

t/04-using_crypt_cbc.t  view on Meta::CPAN

cd 46 e4 5f 85 ea a7 07 24 37 dd 9f a6 79 3d 6f
8d 4c ce fc 4e b1 ac 64 1a c1 bd 30 b1 8c 6d 64
c4 9b ca 13 7e b2 1c 2e 04 da 62 71 2c a2 b4 f5
40 c5 71 12 c3 87 91 85 2c fa c7 a5 d1 9e d8 3a
END
	$expected =~ s/\s+//g;

	my $plain_pack = pack 'H*', $plain;
	my $obj = Crypt::ARIA->new()->set_key_hexstring( $key );

	my $cbc = Crypt::CBC->new(-cipher => $obj,
							  -iv => pack('H*', $iv),
							  -header => 'none',
							  -padding => 'none',
						     );

	my $cipher_pack = $cbc->encrypt( $plain_pack );
	my $cipher = unpack 'H*', $cipher_pack;
	is ( $cipher, $expected, 'encryption with CBC mode. keysize 128' );

	my $decrypt_pack = $cbc->decrypt( $cipher_pack );
	my $decrypt = unpack 'H*', $decrypt_pack;
	cmp_ok( $decrypt, 'eq', $plain, 'recover plaintext with CBC mode. keysize 128' );
}

{
	my $key = '00112233445566778899aabbccddeeff0011223344556677';
	my $iv  = '0f1e2d3c4b5a69788796a5b4c3d2e1f0';

	my $plain = <<'END';
11 11 11 11 aa aa aa aa 11 11 11 11 bb bb bb bb
11 11 11 11 cc cc cc cc 11 11 11 11 dd dd dd dd
22 22 22 22 aa aa aa aa 22 22 22 22 bb bb bb bb

t/04-using_crypt_cbc.t  view on Meta::CPAN

63 19 98 d5 48 11 0d 66 6b 3d 54 c2 a0 91 95 5c
6f 05 be b4 f6 23 09 36 86 96 c9 79 1f c4 c5 51
56 4a 26 37 f1 94 34 6e c4 5f bc a6 c7 2a 5b 46
12 e2 08 d5 31 d6 c3 4c c5 c6 4e ac 6b d0 cf 8c
END
	$expected =~ s/\s+//g;

	my $plain_pack = pack 'H*', $plain;
	my $obj = Crypt::ARIA->new()->set_key_hexstring( $key );

	my $cbc = Crypt::CBC->new(-cipher => $obj,
							  -iv => pack('H*', $iv),
							  -header => 'none',
							  -padding => 'none',
						     );

	my $cipher_pack = $cbc->encrypt( $plain_pack );
	my $cipher = unpack 'H*', $cipher_pack;
	is ( $cipher, $expected, 'encryption with CBC mode. keysize 192' );

	my $decrypt_pack = $cbc->decrypt( $cipher_pack );
	my $decrypt = unpack 'H*', $decrypt_pack;
	cmp_ok( $decrypt, 'eq', $plain, 'recover plaintext with CBC mode. keysize 192' );
}

{
	my $key = '00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff';
	my $iv  = '0f1e2d3c4b5a69788796a5b4c3d2e1f0';

	my $plain = <<'END';
11 11 11 11 aa aa aa aa 11 11 11 11 bb bb bb bb
11 11 11 11 cc cc cc cc 11 11 11 11 dd dd dd dd
22 22 22 22 aa aa aa aa 22 22 22 22 bb bb bb bb

t/04-using_crypt_cbc.t  view on Meta::CPAN

a5 d6 20 99 46 68 ca 22 f5 99 79 1d 29 2d d6 27
3b 29 59 08 2a af b7 a9 96 16 7c ce 1e ec 5f 0c
fd 15 f6 10 d8 7e 2d da 9b a6 8c e1 26 0c a5 4b
22 24 91 41 83 74 29 4e 79 09 b1 e8 55 1c d8 de
END
	$expected =~ s/\s+//g;

	my $plain_pack = pack 'H*', $plain;
	my $obj = Crypt::ARIA->new()->set_key_hexstring( $key );

	my $cbc = Crypt::CBC->new(-cipher => $obj,
							  -iv => pack('H*', $iv),
							  -header => 'none',
							  -padding => 'none',
						     );

	my $cipher_pack = $cbc->encrypt( $plain_pack );
	my $cipher = unpack 'H*', $cipher_pack;
	is ( $cipher, $expected, 'encryption with CBC mode. keysize 256' );

	my $decrypt_pack = $cbc->decrypt( $cipher_pack );
	my $decrypt = unpack 'H*', $decrypt_pack;
	cmp_ok( $decrypt, 'eq', $plain, 'recover plaintext with CBC mode. keysize 256' );
}

# arbitrary string
{
	my $key = '00112233445566778899aabbccddeeff';
	my $iv  = '0f1e2d3c4b5a69788796a5b4c3d2e1f0';

	my $plain = "short";

	my $obj = Crypt::ARIA->new()->set_key_hexstring( $key );
	my $cbc = Crypt::CBC->new(-cipher => $obj,
							  -iv => pack('H*', $iv),
							  -header => 'none',
							  -padding => 'standard',
						     );

	my $cipher_pack = $cbc->encrypt( $plain );
	my $decrypt = $cbc->decrypt( $cipher_pack );

	cmp_ok( $decrypt, 'eq', $plain, 'encrypt and recover short string' );
}

t/04-using_crypt_cbc.t  view on Meta::CPAN

The interface is the same as AES: 128-bit block size with key size of 128, 192, or 256 bits.
The number of rounds is 12, 14, or 16, depending on the key size.
ARIA uses two 8×8-bit S-boxes and their inverses in alternate rounds; one of these
is the Rijndael S-box.

The key schedule processes the key using a 3-round 256-bit Feistel cipher, with
the binary expansion of 1/Ï€ as a source of "nothing up my sleeve numbers".
END

	my $obj = Crypt::ARIA->new()->set_key_hexstring( $key );
	my $cbc = Crypt::CBC->new(-cipher => $obj,
							  -iv => pack('H*', $iv),
							  -header => 'none',
							  -padding => 'standard',
						     );

	my $cipher_pack = $cbc->encrypt( $plain );
	my $decrypt = $cbc->decrypt( $cipher_pack );

	cmp_ok( $decrypt, 'eq', $plain, 'encrypt and recover long string' );
}



( run in 1.250 second using v1.01-cache-2.11-cpan-e1769b4cff6 )