| Crypt-AllOrNothing documentation | Contained in the Crypt-AllOrNothing distribution. |
Crypt::AllOrNothing - All-Or-Nothing Encryption
Version 0.10
use Crypt::AllOrNothing; my $AllOrNothing = Crypt::AllOrNothing->new(K_0=>$K_0); my $K_0 = $AllOrNothing->get_K_0(); my $K_0 = $AllOrNothing->set_K_0($K_0); my $size = $AllOrNothing->get_size(); my @AllOrNothing_text = $AllOrNothing->encrypt(text=>$plaintext); my $plaintext = $AllOrNothing->decrypt(text=>@AllOrNothing_text);
$SIZE = 128 bits;
Create AllOrNothing object. Good idea to provide K_0, which must be ascii encoded(characters) and of length given in size. If K_0 is not given, you must retrieve it later with $AllOrNothing->K_0() else you will not be able to decrypt the message.
get/set K_0. K_0 must be ascii encoded(characters) and length given in size.
get size.
encrypt plaintext with All Or Nothing transform to array of messages. Optionally pass padding which will be used internally
decrypt cryptotext array with All Or Nothing transform to plaintext
Timothy Zander, <timothy.zander at alum.rpi.edu>
The All Or Nothing Encryption and Package Transform algorithm was developed by Ronald Rivest
Please report any bugs or feature requests to
bug-crypt-aon at rt.cpan.org, or through the web interface at
http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Crypt-AllOrNothing.
I will be notified, and then you'll automatically be notified of progress on
your bug as I make changes.
You can find documentation for this module with the perldoc command.
perldoc Crypt::AllOrNothing
You can also look for information at:
Thanks to Prof. Bulent Yener at RPI for his assistance.
Copyright 2007 Timothy Zander, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| Crypt-AllOrNothing documentation | Contained in the Crypt-AllOrNothing distribution. |
package Crypt::AllOrNothing; use warnings; use strict; use Crypt::OpenSSL::AES; use Crypt::AllOrNothing::Util qw/:all/; use Carp; use Crypt::Random qw/makerandom/;
our $VERSION = '0.10';
my $SIZE = 128;
sub new { my $class = shift; my %params = @_; my $self; ######## #Check params ######## if (!exists $params{size}) { $self->{size} = $SIZE; } elsif ($params{size} =~ /^(128)$/) { $self->{size} = $params{size}; } else { croak "Given size($params{size}) is invalid, valid sizes are 128 256 512 1024"; } if (!exists $params{K_0}) { #carp 'No K_0 given. One will be automatically generated. You must manually get this value with $AllOrNothing->get_K_0() to decrypt.'; $self->{K_0}=randomValue(size=>$self->{size}, 'return'=>'ascii'); } elsif (length $params{K_0} == $self->{size}/8) { $self->{K_0}=$params{K_0}; } else { croak "Given K_0 was invalid, if given in new() it must be the correct length and characters(not int, hex, or base64)"; } bless $self, $class; }
sub K_0 { my $self = shift; if (@_) { my $tmp_K_0 = shift; if (length $tmp_K_0 != $self->{size}) { carp 'K_0 passed is not correct length(must be equal to $AllOrNothing->size()), K_0 will not be set'; } else { $self->{K_0} = $tmp_K_0; } } return $self->{K_0}; }
sub size { my $self = shift; return $self->{size}; }
sub encrypt { my $self = shift; my %params = @_; #break packets into length size packets my @message = breakString(string=>$params{plaintext}, size=>$self->{size}/8); #create K_Prime my $K_Prime = randomValue(size=>$self->{size}, 'return'=>'ascii'); my $cipher_K_Prime = Crypt::OpenSSL::AES->new($K_Prime) or croak "Could not create AES cipher with K_Prime"; #add length and padding to message addLength_andPad(array=>\@message, size=>$self->{size}/8, padding=>$params{padding}); #encrypt #m_Prime_sub_i = m_sub_i xor E(K_Prime, i) for i=1..s #i must be made to a character and padded to size 'size' bits my @messagePrime = (); for (my $i=0; $i<scalar @message; $i++) { push @messagePrime, $message[$i] ^ ($cipher_K_Prime->encrypt((sprintf("%c",0x00) x ($self->{size}/8-4)) . pack("L",$i))); } #m_Prime_sub_s_Prime = K_Prime xor h_1 xor h_2 xor ... h_s #h_i = E(K_sub_0, m_Prime_sub_i xor i) for i=1..s #i must be made to be 'size' bits #K_sub_0 is a fixed publicly known encryption key my $cipher_K_0 = Crypt::OpenSSL::AES->new($self->{K_0}) or croak "Could not create AES cipher with K_0"; my $m_Prime_sub_s = $K_Prime; for (my $i=0; $i<scalar @message; $i++) { $m_Prime_sub_s ^= $cipher_K_0->encrypt($messagePrime[$i]^((sprintf("%c",0x00) x ($self->{size}/8-4)) . pack("L",$i))); } push @messagePrime, $m_Prime_sub_s; return @messagePrime; }
sub decrypt { my $self = shift; my %params = @_; my $cipher_K_0 = Crypt::OpenSSL::AES->new($self->{K_0}) or croak "Could not create AES cipher with K_0"; #get K_Prime my $m_prime_sub_s_prime = $params{cryptotext}->[$#{$params{cryptotext}}]; my $add_tmp = ''; for (my $i=0;$i<$#{$params{cryptotext}};$i++) { $add_tmp ^= $cipher_K_0->encrypt($params{cryptotext}->[$i]^((sprintf("%c",0x00) x ($self->{size}/8-4)) . pack("L",$i))); } my $K_prime = $m_prime_sub_s_prime ^ $add_tmp; pop @{$params{cryptotext}}; my $cipher_K_prime = Crypt::OpenSSL::AES->new($K_prime) or die "did not work to create K_Prime AES cipher"; my @m=(); for (my $i=0;$i<scalar @{$params{cryptotext}};$i++) { push @m, $params{cryptotext}->[$i]^$cipher_K_prime->encrypt(((sprintf("%c",0x00) x 12) . pack("L",$i))); } remLength_andPad(array=>\@m); my $plaintext=''; for (@m) { $plaintext .= $_; } return $plaintext; }
1; # End of Crypt::AllOrNothing