Crypt-ARIA

 view release on metacpan or  search on metacpan

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


    my $data = "";

    my $i = 0;
    while ( $i < $len ) {
        my $cipbuf = substr( $cipher, $i, BLOCKSIZE );
        my $buf = $self->decrypt( $cipbuf );
        $data .= $buf;
        $i += BLOCKSIZE;
    }

    return $data;
}

1;

=pod

=encoding UTF-8

=head1 NAME

Crypt::ARIA - Perl extension for ARIA encryption/decryption algorithm.

=head1 VERSION

version 0.004

=head1 SYNOPSIS

  use Crypt::ARIA;

  # create an object
  my $aria = Crypt::ARIA->new();
  # or,
  my $key = pack 'H*', '00112233445566778899aabbccddeeff';
  my $aria = Crypt::ARIA->new( $key );


  # set master key
  $aria->set_key( pack 'H*', '00112233445566778899aabbccddeeff' );
  # or
  # (whitespace allowed)
  $aria->set_key_hexstring( '00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff' );


  # one block encryption/decryption
  # $plaintext and $ciphertext should be of "blocksize()" bytes.
  my $cipher = $aria->encrypt( $plain );
  my $plain  = $aria->decrypt( $cipher );

  
  # 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

Crypt::ARIA provides an interface between Perl and ARIA implementation
in C.

ARIA is a block cipher algorithm designed in South Korea.
For more information about ARIA, visit links in L</SEE ALSO> section.

The C portion of this module is made by researchers of ARIA and is
available from the ARIA website. I had asked them and they've made sure
that the code is free to use.

=head1 METHODS

=over

=item new

C<new()> method creates an object.

  my $aria = Crypt::ARIA->new();

You can give a master key as argument. The master key in ARIA should be of 16, 24, or 32 bytes.

  my $key = pack 'H*', '00112233445566778899aabbccddeeff';
  my $aria = Crypt::ARIA->new( $key );

=item set_key

C<set_key()> sets a master key. This method returns the object itself.

  $aria->set_key( pack 'H*', '00112233445566778899aabbccddeeff' );

=item set_key_hexstring

C<set_key_hexstring()> sets a master key. You can give a hexstring as
argument. The hexstring can include whitespaces.
This method returns the object itself.

  $aria->set_key_hexstring( '00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff' );

=item unset_key

This method removes the master key from object and return the object itsetf.

  $aria->unset_key();

=item has_key

This method returns true if a master key is set, false otherwise.

=item encrypt

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

C<decrypt()> decrypts a block of ciphertext.

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

$cipher should be of exactly 16 bytes.
Again, you have to use another module to decrypt multi-block
message.

=item encrypt_ecb

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

Geunyoung Park <gypark@gmail.com>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2013 by Geunyoung Park.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.

=cut

__END__
# Below is stub documentation for your module. You'd better edit it!




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