Crypt-Misty1

 view release on metacpan or  search on metacpan

Misty1.pm  view on Meta::CPAN

XSLoader::load('Crypt::Misty1', $VERSION);

# Preloaded methods go here.

1;

__END__

=head1 NAME

Crypt::Misty1 - Crypt::CBC-compliant block cipher

=head1 ABSTRACT

Misty1 is a 128-bit key, 64-bit block cipher. Designed by Mitsuru
Matsui, the inventor of linear cryptanalysis, Misty1 is the first
cipher that is provably secure against linear and differential
cryptanalysis.

=head1 SYNOPSIS

Misty1.pm  view on Meta::CPAN

=head1 DESCRIPTION

Misty1 is a 64-bit symmetric block cipher with a 128-bit key. It was
developed by Mitsuru Matsui, and is described in the paper B<New Block
Encryption Algorithm MISTY> and in B<RFC2994>. 

In January of 2000, the 3GPP consortium selected a variant of Misty1,
dubbed as KASUMI (the Japanese word for ``misty''), as the mandatory
cipher in W-CDMA.

This module supports the Crypt::CBC interface, with the following
functions.

=head2 Functions

=over

=item B<blocksize>

Returns the size (in bytes) of the block (8, in this case).

Misty1.pm  view on Meta::CPAN


    print "Decryption OK\n" if ($plaintext1 eq $plaintext2);

=head1 EXAMPLE 2

    #!/usr/local/bin/perl

    use diagnostics;
    use strict;
    use warnings;
    use Crypt::CBC;  # CBC automatically loads Misty1 for us

    # when using Crypt::CBC, key may be of ANY length
    my $key = "0123456789abcdef";

    # IV must be exactly 8 bytes long
    my $IV = pack "H16", 0;

    my $cipher = Crypt::CBC->new({'key' => $key,
                                  'cipher' => 'Misty1',
                                  'iv' => $IV,
                                  'regenerate_key' => 1,
                                  'padding' => 'standard',
                                  'prepend_iv' => 0
                                });

    # when using Crypt::CBC, plaintext may be of ANY length
    my $plaintext1 = "This is a test";

    my $ciphertext = $cipher->encrypt($plaintext1);
    my $plaintext2 = $cipher->decrypt($ciphertext);

    print "Decryption OK\n" if ($plaintext1 eq $plaintext2);

=head1 MORE EXAMPLES

See B<Crypt::CBC> for more examples using CBC mode. See also the
"examples" and "t" directories for some more examples.

=head1 COPYRIGHT AND LICENSE

Copyright 2003 by Julius C. Duque <jcduque (AT) lycos (DOT) com>

This library is free software; you can redistribute it and/or modify
it under the same terms as the GNU General Public License.

=cut

examples/cbc-mode  view on Meta::CPAN

#!/usr/local/bin/perl

use diagnostics;
use strict;
use warnings;
use Crypt::CBC;    # CBC automatically loads Misty1 for us

my $key = pack "H32", "00112233445566778899aabbccddeeff";
my $IV = pack "H16", "0102030405060708";

my $cipher = Crypt::CBC->new({'key' => $key,
                              'cipher' => 'Misty1',
                              'iv' => $IV,
                              'regenerate_key' => 0,
                              'padding' => 'standard',
                              'prepend_iv' => 0
                            });

my $plaintext1 = pack "H32", "0123456789abcdeffedcba9876543210";
print "plaintext1  : ", unpack("H*", $plaintext1), "\n";

my $ciphertext1 = $cipher->encrypt($plaintext1);
print "ciphertext1 : ", unpack("H*", $ciphertext1), "\n";

my $plaintext2 = $cipher->decrypt($ciphertext1);
print "plaintext2  : ", unpack("H*", $plaintext2), "\n";

# Note that 'regenerate_key' was set to 0 just so that this example
# confirms the CBC result given in RFC 2994. However, it is highly
# recommended that 'regenerate_key' be set to 1 for maximum security.

examples/fileenc  view on Meta::CPAN

#!/usr/local/bin/perl

use diagnostics;
use strict;
use warnings;
use Getopt::Long;
use Crypt::CBC;    # CBC automatically loads Misty1 for us

my ($encrypt, $decrypt, $help);
GetOptions("encrypt" => \$encrypt, "decrypt" => \$decrypt,
    "help" => \$help);

sub usage
{
    print "USAGE:\n";
    print "    $0 --encrypt file1 > outputfile\n";
    print "    $0 --decrypt file1 > outputfile\n\n";

examples/fileenc  view on Meta::CPAN

&usage() if (!$encrypt and !$decrypt);
&usage() if ($help);

my $key = &get_input("password");

# For better security, IV must be randomly
# generated AND must be used ONLY ONCE!
# So, this example is *very* weak!
my $IV = pack "H16", "0102030405060708";

my $cipher = Crypt::CBC->new({'key' => $key,
                              'cipher' => 'Misty1',
                              'iv' => $IV,
                              'regenerate_key' => 1,
                              'padding' => 'standard',
                              'prepend_iv' => 0
                            });

local $/ = undef;   # slurp whole file
chomp $ARGV[0];
open INFILE, $ARGV[0];

examples/pin-generator  view on Meta::CPAN

#!/usr/local/bin/perl

use diagnostics;
use strict;
use warnings;
use Crypt::CBC;
use MIME::Base64;

sub get_input
{
    my ($message) = @_;
    local $| = 1;
    local *TTY;
    open TTY,"/dev/tty";
    my ($tkey1, $tkey2);
    system "stty -echo </dev/tty";

examples/pin-generator  view on Meta::CPAN

    } until $tkey1 eq $tkey2;

    system "stty echo </dev/tty";
    close TTY;
    return $tkey1;
}

my $key = &get_input("username");

my $IV = pack "H16", "0102030405060708";
my $cipher = Crypt::CBC->new({'key' => $key,
                              'cipher' => 'Misty1',
                              'iv' => $IV,
                              'regenerate_key' => 1,
                              'padding' => 'standard',
                              'prepend_iv' => 0
                            });

my $ciphertext = $cipher->encrypt($key);
print "Your password is\n", encode_base64($ciphertext, ""), "\n";

rfc2994.txt  view on Meta::CPAN


   This document describes a secret-key cryptosystem MISTY1, which is
   block cipher with a 128-bit key, a 64-bit block and a variable number
   of rounds.  It is designed on the basis of the theory of provable
   security against differential and linear cryptanalysis, and moreover
   it realizes high-speed encryption on hardware platforms as well as on
   software environments.  As the result of weighing strength and speed,
   8-rounds of MISTY1 is recommended and used in most cases.

   Our implementation shows that MISTY1 with eight rounds can encrypt a
   data stream in CBC mode at a speed of 57Mbps and 40Mbps on Pentium
   II/266MHz and PA-7200/120MHz, respectively.  For its hardware
   performance, we have produced a prototype LSI by a process of 0.8-
   micron CMOS gate-array and confirmed a speed of 512Mbps.

2. Algorithm Description

   Algorithm [1] could be divided into two parts, namely "key scheduling
   part" and "data randomizing part".  Key scheduling part takes a 128-
   bit input key and produces a 128-bit expanded key.  Data randomizing

rfc2994.txt  view on Meta::CPAN

   D0 = FLINV(D0, 2);
   D1 = FLINV(D1, 3);
   D0 = D0 ^ FO(D1, 1);
   D1 = D1 ^ FO(D0, 0);
   D0 = FLINV(D0, 0);
   D1 = FLINV(D1, 1);
   P = (D0<<32) | D1;

3. Object Identifier

   The Object Identifier for MISTY1 in Cipher Block Chaining (CBC) mode
   is as follows:

   MISTY1-CBC OBJECT IDENTIFIER ::=
     {iso(1) member-body(2) jisc(392)
      mitsubishi-electric-corporation(200011) isl(61) security(1)
      algorithm(1) symmetric-encryption-algorithm(1) misty1-cbc(1)}

   MISTY1-CBC needs Initialization Vector (IV) as like as other
   algorithms, such as DES-CBC, DES-EDE3-CBC and so on.  To determine
   the value of IV, MISTY1-CBC takes parameter as:

   MISTY1-CBC Parameter ::= IV

   where IV ::= OCTET STRING -- 8 octets.

   When this Object Identifier is used, plaintext is padded before
   encrypt it.  At least 1 padding octet is appended at the end of the
   plaintext to make the length of the plaintext to the multiple of 8
   octets.  The value of these octets is as same as the number of
   appended octets.  (e.g., If 5 octets are needed to pad, the value is
   0x05.)

rfc2994.txt  view on Meta::CPAN

   Here is an example ciphertext of MISTY1 when the key and the
   plaintext are set as following value.

   Key:        00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff
   Plaintext:  01 23 45 67 89 ab cd ef fe dc ba 98 76 54 32 10
   Ciphertext: 8b 1d a5 f5 6a b3 d0 7c 04 b6 82 40 b1 3b e9 5d

   In the above example, because the plaintext has a length of 128-bit,
   MISTY1 is used two times to each 64-bit, namely ECB mode.

   Following example is ciphertext of MISTY1 in CBC mode.

   Key:        00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff
   IV:         01 02 03 04 05 06 07 08
   Plaintext:  01 23 45 67 89 ab cd ef fe dc ba 98 76 54 32 10
   Ciphertext: 46 1c 1e 87 9c 18 c2 7f b9 ad f2 d8 0c 89 03 1f







( run in 0.646 second using v1.01-cache-2.11-cpan-df04353d9ac )