RFC: Crypt::Skip32 [try 3]
am 24.09.2007 06:51:19 von Eric HammondI'm planning to upload this new module for distribution on the CPAN.
Feedback welcomed.
NAME
Crypt::Skip32 - 32-bit block cipher based on Skipjack
SYNOPSIS
use Crypt::Skip32;
my $cipher = new Crypt::Skip32 $key;
my $ciphertext = $cipher->encrypt($plaintext);
my $plaintext = $cipher->decrypt($ciphertext);
DESCRIPTION
Skip32 is a 80-bit key, 32-bit block cipher based on
Skipjack. The Perl code for the algorithm is a direct
translation from C to Perl of skip32.c by Greg Rose found
here:
http://www.qualcomm.com.au/PublicationsDocs/skip32.c
This cipher can be handy for scrambling small (32-bit) values
when you would like to obscure them while keeping the
encrypted output size small (32 bits).
One example where Skip32 has been useful: You have numeric
database record ids which increment sequentially. You would
like to use them in URLs, but you don't want to make it
obvious how many X's you have in the database by putting the
ids directly in the URLs.
You can use Skip32 to scramble ids and put the resulting
32-bit value in URLs (perhaps as 8 hex digits or some other
shorter encoding). When a user requests a URL, you can
unscramble the id to retrieve the object from the database.
Warning: A 32-bit value can only go a little over 4 billion
(American). Plan ahead if what you need to encrypt might
eventually go over this limit.
FUNCTIONS
new
my $cipher = new Crypt::Skip32 $key;
Creates a new Crypt::Skip32 block cipher object, using
$key, where $key is a key of "keysize" (10) bytes.
encrypt
my $ciphertext = $cipher->encrypt($plaintext);
Encrypt $plaintext and return the $ciphertext. The
$plaintext must be of "blocksize" (4) bytes.
decrypt
my $plaintext = $cipher->decrypt($ciphertext);
Decrypt $ciphertext and return the $plaintext. The
$ciphertext must be of "blocksize" (4) bytes.
blocksize
my $blocksize = $cipher->blocksize;
my $blocksize = Crypt::Skip32->blocksize;
Returns the size (in bytes) of the block cipher. This is
always 4 bytes (for 32 bits).
keysize
my $keysize = $cipher->keysize;
my $keysize = Crypt::Skip32->keysize;
Returns the size (in bytes) of the key. This is always 10
bytes.
EXAMPLE
use Crypt::Skip32;
my $key = pack("H20", "112233445566778899AA");
my $cipher = new Crypt::Skip32 $key;
my $plaintext1 = pack("N", 3493209676);
my $ciphertext = $cipher->encrypt($plaintext1);
print "scrambled 3493209676 -> 0x",
unpack("H8", $ciphertext), "\n";
my $plaintext2 = $cipher->decrypt($ciphertext);
die "something went horribly wrong"
unless $plaintext2 eq $plaintext1;
print "blocksize: ", $cipher->blocksize, " bytes \n";
print "keysize: ", $cipher->keysize, " bytes \n";
CAVEATS
This initial alpha Perl implementation of SKIP32 has not been
extentively reviewed by cryptographic experts, nor has it
been tested extensively on many different platforms. It is
recommended that this code not be used for applications which
require a high level of security. Reviewers and testers
welcomed.
TODO
This version of Skip32 is implemented entirely in Perl. Since
there is a free C implementation of the algorithm, this
should probably be made available with XS or Inline::C so
that it can run a bit faster.
SEE ALSO
The original Skip32 implementation in C by Greg Rose:
http://www.qualcomm.com.au/PublicationsDocs/skip32.c
The 80-bit key, 64-bit block Skipjack cipher created by the
NSA (Perl code maintained by Julius C. Duque):
Crypt::Skipjack
AUTHOR
Perl code maintained by Eric Hammond
http://www.anvilon.com
Original Skip32 C code written 1999-04-27 by Greg Rose, based
on an implementation of the Skipjack algorithm written by
Panu Rissanen.
COPYRIGHT AND LICENSE
(C) Copyright 2007, Eric Hammond
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.8 or, at your option, any later version of Perl 5
you may have available.
The C version of Skip32 by Greg Rose (see below) is
explicitly "not copyright, no rights reserved". Even so,
permission was requested and granted to make a Perl version
available on the CPAN.
ORIGINAL C SOURCE
/* SKIP32 -- 32 bit block cipher based on SKIPJACK. Written
by Greg Rose, QUALCOMM Australia, 1999/04/27.
In common: F-table, G-permutation, key schedule.
Different: 24 round feistel structure.
Based on: Unoptimized test implementation of SKIPJACK
algorithm
Panu Rissanen
SKIPJACK and KEA Algorithm Specifications
Version 2.0
29 May 1998
Not copyright, no rights reserved.
*/
[...]