Crypt-DES-2.09/0000755000175000017500000000000015236451445011333 5ustar timtimCrypt-DES-2.09/test.pl0000644000175000017500000004036315236447467012666 0ustar timtimBEGIN { push @INC, qw(. .. ../lib ../../lib ../../../lib) } # # Extended testing is Copyright (C) 2000 W3Works, LLC # All rights reserved. # # # Copyright (C) 1995, 1996 Systemics Ltd (http://www.systemics.com/) # All rights reserved. # package Crypt::DES; require Exporter; require DynaLoader; use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); @ISA = (Exporter, DynaLoader); # Items to export into callers namespace by default @EXPORT = qw(); # Other items we are prepared to export if requested @EXPORT_OK = qw(); $VERSION = '2.09'; bootstrap Crypt::DES; use strict; use Carp; sub usage { my ($package, $filename, $line, $subr) = caller(1); $Carp::CarpLevel = 2; croak "Usage: $subr(@_)"; } sub blocksize { 8; } sub keysize { 8; } sub new { usage("new DES key") unless @_ == 2; my($type,$key) = @_; my $self = {}; bless $self, $type; $self->{'ks'} = Crypt::DES::expand_key($key); return $self; } sub encrypt { usage("encrypt data[8 bytes]") unless @_ == 2; my ($self,$data) = @_; return Crypt::DES::crypt($data, $data, $self->{'ks'}, 1); } sub decrypt { usage("decrypt data[8 bytes]") unless @_ == 2; my ($self,$data) = @_; return Crypt::DES::crypt($data, $data, $self->{'ks'}, 0); } package main; use Data::Dumper; use Benchmark; # # Adding the above tests into this program is # left as an exercise for the reader # # # Some test values... # # KEY PLAINTEXT CIPHERTEXT my $testval = [ ['0101010101010101', '95f8a5e5dd31d900', '8000000000000000'], ['0101010101010101', 'dd7f121ca5015619', '4000000000000000'], ['0101010101010101', '2e8653104f3834ea', '2000000000000000'], ['0101010101010101', '4bd388ff6cd81d4f', '1000000000000000'], ['0101010101010101', '20b9e767b2fb1456', '0800000000000000'], ['0101010101010101', '55579380d77138ef', '0400000000000000'], ['0101010101010101', '6cc5defaaf04512f', '0200000000000000'], ['0101010101010101', '0d9f279ba5d87260', '0100000000000000'], ['0101010101010101', 'd9031b0271bd5a0a', '0080000000000000'], ['0101010101010101', '424250b37c3dd951', '0040000000000000'], ['0101010101010101', 'b8061b7ecd9a21e5', '0020000000000000'], ['0101010101010101', 'f15d0f286b65bd28', '0010000000000000'], ['0101010101010101', 'add0cc8d6e5deba1', '0008000000000000'], ['0101010101010101', 'e6d5f82752ad63d1', '0004000000000000'], ['0101010101010101', 'ecbfe3bd3f591a5e', '0002000000000000'], ['0101010101010101', 'f356834379d165cd', '0001000000000000'], ['0101010101010101', '2b9f982f20037fa9', '0000800000000000'], ['0101010101010101', '889de068a16f0be6', '0000400000000000'], ['0101010101010101', 'e19e275d846a1298', '0000200000000000'], ['0101010101010101', '329a8ed523d71aec', '0000100000000000'], ['0101010101010101', 'e7fce22557d23c97', '0000080000000000'], ['0101010101010101', '12a9f5817ff2d65d', '0000040000000000'], ['0101010101010101', 'a484c3ad38dc9c19', '0000020000000000'], ['0101010101010101', 'fbe00a8a1ef8ad72', '0000010000000000'], ['0101010101010101', '750d079407521363', '0000008000000000'], ['0101010101010101', '64feed9c724c2faf', '0000004000000000'], ['0101010101010101', 'f02b263b328e2b60', '0000002000000000'], ['0101010101010101', '9d64555a9a10b852', '0000001000000000'], ['0101010101010101', 'd106ff0bed5255d7', '0000000800000000'], ['0101010101010101', 'e1652c6b138c64a5', '0000000400000000'], ['0101010101010101', 'e428581186ec8f46', '0000000200000000'], ['0101010101010101', 'aeb5f5ede22d1a36', '0000000100000000'], ['0101010101010101', 'e943d7568aec0c5c', '0000000080000000'], ['0101010101010101', 'df98c8276f54b04b', '0000000040000000'], ['0101010101010101', 'b160e4680f6c696f', '0000000020000000'], ['0101010101010101', 'fa0752b07d9c4ab8', '0000000010000000'], ['0101010101010101', 'ca3a2b036dbc8502', '0000000008000000'], ['0101010101010101', '5e0905517bb59bcf', '0000000004000000'], ['0101010101010101', '814eeb3b91d90726', '0000000002000000'], ['0101010101010101', '4d49db1532919c9f', '0000000001000000'], ['0101010101010101', '25eb5fc3f8cf0621', '0000000000800000'], ['0101010101010101', 'ab6a20c0620d1c6f', '0000000000400000'], ['0101010101010101', '79e90dbc98f92cca', '0000000000200000'], ['0101010101010101', '866ecedd8072bb0e', '0000000000100000'], ['0101010101010101', '8b54536f2f3e64a8', '0000000000080000'], ['0101010101010101', 'ea51d3975595b86b', '0000000000040000'], ['0101010101010101', 'caffc6ac4542de31', '0000000000020000'], ['0101010101010101', '8dd45a2ddf90796c', '0000000000010000'], ['0101010101010101', '1029d55e880ec2d0', '0000000000008000'], ['0101010101010101', '5d86cb23639dbea9', '0000000000004000'], ['0101010101010101', '1d1ca853ae7c0c5f', '0000000000002000'], ['0101010101010101', 'ce332329248f3228', '0000000000001000'], ['0101010101010101', '8405d1abe24fb942', '0000000000000800'], ['0101010101010101', 'e643d78090ca4207', '0000000000000400'], ['0101010101010101', '48221b9937748a23', '0000000000000200'], ['0101010101010101', 'dd7c0bbd61fafd54', '0000000000000100'], ['0101010101010101', '2fbc291a570db5c4', '0000000000000080'], ['0101010101010101', 'e07c30d7e4e26e12', '0000000000000040'], ['0101010101010101', '0953e2258e8e90a1', '0000000000000020'], ['0101010101010101', '5b711bc4ceebf2ee', '0000000000000010'], ['0101010101010101', 'cc083f1e6d9e85f6', '0000000000000008'], ['0101010101010101', 'd2fd8867d50d2dfe', '0000000000000004'], ['0101010101010101', '06e7ea22ce92708f', '0000000000000002'], ['0101010101010101', '166b40b44aba4bd6', '0000000000000001'], ['8001010101010101', '0000000000000000', '95a8d72813daa94d'], ['4001010101010101', '0000000000000000', '0eec1487dd8c26d5'], ['2001010101010101', '0000000000000000', '7ad16ffb79c45926'], ['1001010101010101', '0000000000000000', 'd3746294ca6a6cf3'], ['0801010101010101', '0000000000000000', '809f5f873c1fd761'], ['0401010101010101', '0000000000000000', 'c02faffec989d1fc'], ['0201010101010101', '0000000000000000', '4615aa1d33e72f10'], ['0180010101010101', '0000000000000000', '2055123350c00858'], ['0140010101010101', '0000000000000000', 'df3b99d6577397c8'], ['0120010101010101', '0000000000000000', '31fe17369b5288c9'], ['0110010101010101', '0000000000000000', 'dfdd3cc64dae1642'], ['0108010101010101', '0000000000000000', '178c83ce2b399d94'], ['0104010101010101', '0000000000000000', '50f636324a9b7f80'], ['0102010101010101', '0000000000000000', 'a8468ee3bc18f06d'], ['0101800101010101', '0000000000000000', 'a2dc9e92fd3cde92'], ['0101400101010101', '0000000000000000', 'cac09f797d031287'], ['0101200101010101', '0000000000000000', '90ba680b22aeb525'], ['0101100101010101', '0000000000000000', 'ce7a24f350e280b6'], ['0101080101010101', '0000000000000000', '882bff0aa01a0b87'], ['0101040101010101', '0000000000000000', '25610288924511c2'], ['0101020101010101', '0000000000000000', 'c71516c29c75d170'], ['0101018001010101', '0000000000000000', '5199c29a52c9f059'], ['0101014001010101', '0000000000000000', 'c22f0a294a71f29f'], ['0101012001010101', '0000000000000000', 'ee371483714c02ea'], ['0101011001010101', '0000000000000000', 'a81fbd448f9e522f'], ['0101010801010101', '0000000000000000', '4f644c92e192dfed'], ['0101010401010101', '0000000000000000', '1afa9a66a6df92ae'], ['0101010201010101', '0000000000000000', 'b3c1cc715cb879d8'], ['0101010180010101', '0000000000000000', '19d032e64ab0bd8b'], ['0101010140010101', '0000000000000000', '3cfaa7a7dc8720dc'], ['0101010120010101', '0000000000000000', 'b7265f7f447ac6f3'], ['0101010110010101', '0000000000000000', '9db73b3c0d163f54'], ['0101010108010101', '0000000000000000', '8181b65babf4a975'], ['0101010104010101', '0000000000000000', '93c9b64042eaa240'], ['0101010102010101', '0000000000000000', '5570530829705592'], ['0101010101800101', '0000000000000000', '8638809e878787a0'], ['0101010101400101', '0000000000000000', '41b9a79af79ac208'], ['0101010101200101', '0000000000000000', '7a9be42f2009a892'], ['0101010101100101', '0000000000000000', '29038d56ba6d2745'], ['0101010101080101', '0000000000000000', '5495c6abf1e5df51'], ['0101010101040101', '0000000000000000', 'ae13dbd561488933'], ['0101010101020101', '0000000000000000', '024d1ffa8904e389'], ['0101010101018001', '0000000000000000', 'd1399712f99bf02e'], ['0101010101014001', '0000000000000000', '14c1d7c1cffec79e'], ['0101010101012001', '0000000000000000', '1de5279dae3bed6f'], ['0101010101011001', '0000000000000000', 'e941a33f85501303'], ['0101010101010801', '0000000000000000', 'da99dbbc9a03f379'], ['0101010101010401', '0000000000000000', 'b7fc92f91d8e92e9'], ['0101010101010201', '0000000000000000', 'ae8e5caa3ca04e85'], ['0101010101010180', '0000000000000000', '9cc62df43b6eed74'], ['0101010101010140', '0000000000000000', 'd863dbb5c59a91a0'], ['0101010101010120', '0000000000000000', 'a1ab2190545b91d7'], ['0101010101010110', '0000000000000000', '0875041e64c570f7'], ['0101010101010108', '0000000000000000', '5a594528bebef1cc'], ['0101010101010104', '0000000000000000', 'fcdb3291de21f0c0'], ['0101010101010102', '0000000000000000', '869efd7f9f265a09'], ['1046913489980131', '0000000000000000', '88d55e54f54c97b4'], ['1007103489988020', '0000000000000000', '0c0cc00c83ea48fd'], ['10071034c8980120', '0000000000000000', '83bc8ef3a6570183'], ['1046103489988020', '0000000000000000', 'df725dcad94ea2e9'], ['1086911519190101', '0000000000000000', 'e652b53b550be8b0'], ['1086911519580101', '0000000000000000', 'af527120c485cbb0'], ['5107b01519580101', '0000000000000000', '0f04ce393db926d5'], ['1007b01519190101', '0000000000000000', 'c9f00ffc74079067'], ['3107915498080101', '0000000000000000', '7cfd82a593252b4e'], ['3107919498080101', '0000000000000000', 'cb49a2f9e91363e3'], ['10079115b9080140', '0000000000000000', '00b588be70d23f56'], ['3107911598090140', '0000000000000000', '406a9a6ab43399ae'], ['1007d01589980101', '0000000000000000', '6cb773611dca9ada'], ['9107911589980101', '0000000000000000', '67fd21c17dbb5d70'], ['9107d01589190101', '0000000000000000', '9592cb4110430787'], ['1007d01598980120', '0000000000000000', 'a6b7ff68a318ddd3'], ['1007940498190101', '0000000000000000', '4d102196c914ca16'], ['0107910491190401', '0000000000000000', '2dfa9f4573594965'], ['0107910491190101', '0000000000000000', 'b46604816c0e0774'], ['0107940491190401', '0000000000000000', '6e7e6221a4f34e87'], ['19079210981a0101', '0000000000000000', 'aa85e74643233199'], ['1007911998190801', '0000000000000000', '2e5a19db4d1962d6'], ['10079119981a0801', '0000000000000000', '23a866a809d30894'], ['1007921098190101', '0000000000000000', 'd812d961f017d320'], ['100791159819010b', '0000000000000000', '055605816e58608f'], ['1004801598190101', '0000000000000000', 'abd88e8b1b7716f1'], ['1004801598190102', '0000000000000000', '537ac95be69da1e1'], ['1004801598190108', '0000000000000000', 'aed0f6ae3c25cdd8'], ['1002911598100104', '0000000000000000', 'b3e35a5ee53e7b8d'], ['1002911598190104', '0000000000000000', '61c79c71921a2ef8'], ['1002911598100201', '0000000000000000', 'e2f5728f0995013c'], ['1002911698100101', '0000000000000000', '1aeac39a61f0a464'], ['7ca110454a1a6e57', '01a1d6d039776742', '690f5b0d9a26939b'], ['0131d9619dc1376e', '5cd54ca83def57da', '7a389d10354bd271'], ['07a1133e4a0b2686', '0248d43806f67172', '868ebb51cab4599a'], ['3849674c2602319e', '51454b582ddf440a', '7178876e01f19b2a'], ['04b915ba43feb5b6', '42fd443059577fa2', 'af37fb421f8c4095'], ['0113b970fd34f2ce', '059b5e0851cf143a', '86a560f10ec6d85b'], ['0170f175468fb5e6', '0756d8e0774761d2', '0cd3da020021dc09'], ['43297fad38e373fe', '762514b829bf486a', 'ea676b2cb7db2b7a'], ['07a7137045da2a16', '3bdd119049372802', 'dfd64a815caf1a0f'], ['04689104c2fd3b2f', '26955f6835af609a', '5c513c9c4886c088'], ['37d06bb516cb7546', '164d5e404f275232', '0a2aeeae3ff4ab77'], ['1f08260d1ac2465e', '6b056e18759f5cca', 'ef1bf03e5dfa575a'], ['584023641aba6176', '004bd6ef09176062', '88bf0db6d70dee56'], ['025816164629b007', '480d39006ee762f2', 'a1f9915541020b56'], ['49793ebc79b3258f', '437540c8698f3cfa', '6fbf1cafcffd0556'], ['4fb05e1515ab73a7', '072d43a077075292', '2f22e49bab7ca1ac'], ['49e95d6d4ca229bf', '02fe55778117f12a', '5a6b612cc26cce4a'], ['018310dc409b26d6', '1d9d5c5018f728c2', '5f4c038ed12b2e41'], ['1c587f1c13924fef', '305532286d6f295a', '63fac0d034d9f793'], ]; my $i = 1; my $fail = 0; my $tt = (scalar(@{$testval}) *2); print "1..$tt\n"; my $t0 = Benchmark->new(); foreach my $tst (@{$testval}) { my ($anot,$bnot) = (0,0); foreach(@{$tst}) { $_ = pack("H*",$_) } my $cipher = Crypt::DES->new($tst->[0]); $anot = 1 unless ($cipher->encrypt($tst->[1]) eq $tst->[2]); if($anot) { #print "not "; $fail++; } $i++; $bnot = 1 unless ($cipher->decrypt($tst->[2]) eq $tst->[1]); if($bnot) { #print "not "; $fail++; } ; $i++; } my $t1 = Benchmark->new(); my $suc = $tt - $fail; my $fp = sprintf("%0.2f",(($tt / $suc) * 100)) unless $suc == 0; if($suc == 0) { $fp = '0.00' } my $td0 = timediff($t1,$t0); my $ts0 = timestr($td0); print "$tt basic tests ran in $ts0\n"; print "$suc of $tt tests passed ($fp\%)\n"; if($fail > 0) { print "Not all tests successful. Please attempt to rebuild the package\n"; } else { print "\nRunning speed tests...\n"; print "\nnon-cached cipher speed test. 5000 encrypt iterations\n"; my $t2 = Benchmark->new(); for(1..5000) { my $cipher = Crypt::DES->new(pack("H*",'1c587f1c13924fef')); $cipher->encrypt(pack("H*",'305532286d6f295a')); } my $t3 = Benchmark->new(); my $td1 = timediff($t3,$t2); my $ts1 = timestr($td1); print "$ts1\nok 343\n"; print "\nnon-cached cipher speed test. 5000 decrypt iterations\n"; my $t4 = Benchmark->new(); for(1..5000) { my $cipher = Crypt::DES->new(pack("H*",'1c587f1c13924fef')); $cipher->decrypt(pack("H*",'63fac0d034d9f793')); } my $t5 = Benchmark->new(); my $td2 = timediff($t5,$t4); my $ts2 = timestr($td2); print "$ts2\nok 344\n"; print "\ncached cipher speed test. 10000 encrypt iterations\n"; { my $t6 = Benchmark->new(); my $cipher = Crypt::DES->new(pack("H*",'1c587f1c13924fef')); for(1..10000) { $cipher->encrypt(pack("H*",'305532286d6f295a')); } my $t7 = Benchmark->new(); my $td3 = timediff($t7,$t6); my $ts3 = timestr($td3); print "$ts3\nok 345\n"; } print "\ncached cipher speed test. 10000 decrypt iterations\n"; { my $t8 = Benchmark->new(); my $cipher = Crypt::DES->new(pack("H*",'1c587f1c13924fef')); for(1..10000) { $cipher->decrypt(pack("H*",'63fac0d034d9f793')); } my $t9 = Benchmark->new(); my $td4 = timediff($t9,$t8); my $ts4 = timestr($td4); print "$ts4\nok 346\n"; } } print "\nTesting Cipher Block Chaining..\n"; eval 'use Crypt::CBC'; if(!$@) { if($Crypt::CBC::VERSION < 1.22) { $@ = "CBC mode requires Crypt::CBC version 1.22 or higher."; } else { my $cipher = Crypt::CBC->new(pack("H*","0123456789ABCDEF"),"DES"); my $ciphertext = $cipher->encrypt(pack("H*","37363534333231204E6F77206973207468652074696D6520666F722000")); my $plaintext = $cipher->decrypt($ciphertext); if($plaintext ne "7654321 Now is the time for \0") { print "not "; } print "ok 347 - CBC Mode\n"; } } # end no errors if($@) { print "Error (probably harmless):\n$@\n"; } print "\nFinished with tests\n\n"; Crypt-DES-2.09/_des.c0000644000175000017500000005414615235703352012417 0ustar timtim/* * cross-platform and mod_ssl-safe code modifications are Copyright (C) * 2000 W3Works, LLC. All rights reserved. */ /* * The modifications found herein are Copyright (C) W3Works, LLC. # All rights reserved. */ /* * NB - This file is a modified version of one by Eric Young. * It was modifed by Systemics Ltd (http://www.systemics.com/) */ /* Copyright (C) 1995 Eric Young (eay@mincom.oz.au) * All rights reserved. * * This file is part of an SSL implementation written * by Eric Young (eay@mincom.oz.au). * The implementation was written so as to conform with Netscapes SSL * specification. This library and applications are * FREE FOR COMMERCIAL AND NON-COMMERCIAL USE * as long as the following conditions are aheared to. * * Copyright remains Eric Young's, and as such any Copyright notices in * the code are not to be removed. If this code is used in a product, * Eric Young should be given attribution as the author of the parts used. * This can be in the form of a textual message at program startup or * in documentation (online or textual) provided with the package. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by Eric Young (eay@mincom.oz.au) * * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * The licence and distribution terms for any publically available version or * derivative of this code cannot be changed. i.e. this code cannot simply be * copied and put under another distribution licence * [including the GNU Public Licence.] */ #include "_des.h" #define c2l(c,l) (l =((unsigned long)(*((c)++))), \ l|=((unsigned long)(*((c)++)))<< 8, \ l|=((unsigned long)(*((c)++)))<<16, \ l|=((unsigned long)(*((c)++)))<<24) #define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \ *((c)++)=(unsigned char)(((l)>> 8)&0xff), \ *((c)++)=(unsigned char)(((l)>>16)&0xff), \ *((c)++)=(unsigned char)(((l)>>24)&0xff)) #define ITERATIONS 16 #define HPERM_OP(a,t,n,m) ((t)=((((a)<<(16-(n)))^(a))&(m)),\ (a)=(a)^(t)^(t>>(16-(n)))) unsigned long des_SPtrans_x[8][64]={ /* nibble 0 */ 0x00820200, 0x00020000, 0x80800000, 0x80820200, 0x00800000, 0x80020200, 0x80020000, 0x80800000, 0x80020200, 0x00820200, 0x00820000, 0x80000200, 0x80800200, 0x00800000, 0x00000000, 0x80020000, 0x00020000, 0x80000000, 0x00800200, 0x00020200, 0x80820200, 0x00820000, 0x80000200, 0x00800200, 0x80000000, 0x00000200, 0x00020200, 0x80820000, 0x00000200, 0x80800200, 0x80820000, 0x00000000, 0x00000000, 0x80820200, 0x00800200, 0x80020000, 0x00820200, 0x00020000, 0x80000200, 0x00800200, 0x80820000, 0x00000200, 0x00020200, 0x80800000, 0x80020200, 0x80000000, 0x80800000, 0x00820000, 0x80820200, 0x00020200, 0x00820000, 0x80800200, 0x00800000, 0x80000200, 0x80020000, 0x00000000, 0x00020000, 0x00800000, 0x80800200, 0x00820200, 0x80000000, 0x80820000, 0x00000200, 0x80020200, /* nibble 1 */ 0x10042004, 0x00000000, 0x00042000, 0x10040000, 0x10000004, 0x00002004, 0x10002000, 0x00042000, 0x00002000, 0x10040004, 0x00000004, 0x10002000, 0x00040004, 0x10042000, 0x10040000, 0x00000004, 0x00040000, 0x10002004, 0x10040004, 0x00002000, 0x00042004, 0x10000000, 0x00000000, 0x00040004, 0x10002004, 0x00042004, 0x10042000, 0x10000004, 0x10000000, 0x00040000, 0x00002004, 0x10042004, 0x00040004, 0x10042000, 0x10002000, 0x00042004, 0x10042004, 0x00040004, 0x10000004, 0x00000000, 0x10000000, 0x00002004, 0x00040000, 0x10040004, 0x00002000, 0x10000000, 0x00042004, 0x10002004, 0x10042000, 0x00002000, 0x00000000, 0x10000004, 0x00000004, 0x10042004, 0x00042000, 0x10040000, 0x10040004, 0x00040000, 0x00002004, 0x10002000, 0x10002004, 0x00000004, 0x10040000, 0x00042000, /* nibble 2 */ 0x41000000, 0x01010040, 0x00000040, 0x41000040, 0x40010000, 0x01000000, 0x41000040, 0x00010040, 0x01000040, 0x00010000, 0x01010000, 0x40000000, 0x41010040, 0x40000040, 0x40000000, 0x41010000, 0x00000000, 0x40010000, 0x01010040, 0x00000040, 0x40000040, 0x41010040, 0x00010000, 0x41000000, 0x41010000, 0x01000040, 0x40010040, 0x01010000, 0x00010040, 0x00000000, 0x01000000, 0x40010040, 0x01010040, 0x00000040, 0x40000000, 0x00010000, 0x40000040, 0x40010000, 0x01010000, 0x41000040, 0x00000000, 0x01010040, 0x00010040, 0x41010000, 0x40010000, 0x01000000, 0x41010040, 0x40000000, 0x40010040, 0x41000000, 0x01000000, 0x41010040, 0x00010000, 0x01000040, 0x41000040, 0x00010040, 0x01000040, 0x00000000, 0x41010000, 0x40000040, 0x41000000, 0x40010040, 0x00000040, 0x01010000, /* nibble 3 */ 0x00100402, 0x04000400, 0x00000002, 0x04100402, 0x00000000, 0x04100000, 0x04000402, 0x00100002, 0x04100400, 0x04000002, 0x04000000, 0x00000402, 0x04000002, 0x00100402, 0x00100000, 0x04000000, 0x04100002, 0x00100400, 0x00000400, 0x00000002, 0x00100400, 0x04000402, 0x04100000, 0x00000400, 0x00000402, 0x00000000, 0x00100002, 0x04100400, 0x04000400, 0x04100002, 0x04100402, 0x00100000, 0x04100002, 0x00000402, 0x00100000, 0x04000002, 0x00100400, 0x04000400, 0x00000002, 0x04100000, 0x04000402, 0x00000000, 0x00000400, 0x00100002, 0x00000000, 0x04100002, 0x04100400, 0x00000400, 0x04000000, 0x04100402, 0x00100402, 0x00100000, 0x04100402, 0x00000002, 0x04000400, 0x00100402, 0x00100002, 0x00100400, 0x04100000, 0x04000402, 0x00000402, 0x04000000, 0x04000002, 0x04100400, /* nibble 4 */ 0x02000000, 0x00004000, 0x00000100, 0x02004108, 0x02004008, 0x02000100, 0x00004108, 0x02004000, 0x00004000, 0x00000008, 0x02000008, 0x00004100, 0x02000108, 0x02004008, 0x02004100, 0x00000000, 0x00004100, 0x02000000, 0x00004008, 0x00000108, 0x02000100, 0x00004108, 0x00000000, 0x02000008, 0x00000008, 0x02000108, 0x02004108, 0x00004008, 0x02004000, 0x00000100, 0x00000108, 0x02004100, 0x02004100, 0x02000108, 0x00004008, 0x02004000, 0x00004000, 0x00000008, 0x02000008, 0x02000100, 0x02000000, 0x00004100, 0x02004108, 0x00000000, 0x00004108, 0x02000000, 0x00000100, 0x00004008, 0x02000108, 0x00000100, 0x00000000, 0x02004108, 0x02004008, 0x02004100, 0x00000108, 0x00004000, 0x00004100, 0x02004008, 0x02000100, 0x00000108, 0x00000008, 0x00004108, 0x02004000, 0x02000008, /* nibble 5 */ 0x20000010, 0x00080010, 0x00000000, 0x20080800, 0x00080010, 0x00000800, 0x20000810, 0x00080000, 0x00000810, 0x20080810, 0x00080800, 0x20000000, 0x20000800, 0x20000010, 0x20080000, 0x00080810, 0x00080000, 0x20000810, 0x20080010, 0x00000000, 0x00000800, 0x00000010, 0x20080800, 0x20080010, 0x20080810, 0x20080000, 0x20000000, 0x00000810, 0x00000010, 0x00080800, 0x00080810, 0x20000800, 0x00000810, 0x20000000, 0x20000800, 0x00080810, 0x20080800, 0x00080010, 0x00000000, 0x20000800, 0x20000000, 0x00000800, 0x20080010, 0x00080000, 0x00080010, 0x20080810, 0x00080800, 0x00000010, 0x20080810, 0x00080800, 0x00080000, 0x20000810, 0x20000010, 0x20080000, 0x00080810, 0x00000000, 0x00000800, 0x20000010, 0x20000810, 0x20080800, 0x20080000, 0x00000810, 0x00000010, 0x20080010, /* nibble 6 */ 0x00001000, 0x00000080, 0x00400080, 0x00400001, 0x00401081, 0x00001001, 0x00001080, 0x00000000, 0x00400000, 0x00400081, 0x00000081, 0x00401000, 0x00000001, 0x00401080, 0x00401000, 0x00000081, 0x00400081, 0x00001000, 0x00001001, 0x00401081, 0x00000000, 0x00400080, 0x00400001, 0x00001080, 0x00401001, 0x00001081, 0x00401080, 0x00000001, 0x00001081, 0x00401001, 0x00000080, 0x00400000, 0x00001081, 0x00401000, 0x00401001, 0x00000081, 0x00001000, 0x00000080, 0x00400000, 0x00401001, 0x00400081, 0x00001081, 0x00001080, 0x00000000, 0x00000080, 0x00400001, 0x00000001, 0x00400080, 0x00000000, 0x00400081, 0x00400080, 0x00001080, 0x00000081, 0x00001000, 0x00401081, 0x00400000, 0x00401080, 0x00000001, 0x00001001, 0x00401081, 0x00400001, 0x00401080, 0x00401000, 0x00001001, /* nibble 7 */ 0x08200020, 0x08208000, 0x00008020, 0x00000000, 0x08008000, 0x00200020, 0x08200000, 0x08208020, 0x00000020, 0x08000000, 0x00208000, 0x00008020, 0x00208020, 0x08008020, 0x08000020, 0x08200000, 0x00008000, 0x00208020, 0x00200020, 0x08008000, 0x08208020, 0x08000020, 0x00000000, 0x00208000, 0x08000000, 0x00200000, 0x08008020, 0x08200020, 0x00200000, 0x00008000, 0x08208000, 0x00000020, 0x00200000, 0x00008000, 0x08000020, 0x08208020, 0x00008020, 0x08000000, 0x00000000, 0x00208000, 0x08200020, 0x08008020, 0x08008000, 0x00200020, 0x08208000, 0x00000020, 0x00200020, 0x08008000, 0x08208020, 0x00200000, 0x08200000, 0x08000020, 0x00208000, 0x00008020, 0x08008020, 0x08200000, 0x00000020, 0x08208000, 0x00208020, 0x00000000, 0x08000000, 0x08200020, 0x00008000, 0x00208020}; unsigned long des_skb[8][64]={ /* for C bits (numbered as per FIPS 46) 1 2 3 4 5 6 */ 0x00000000,0x00000010,0x20000000,0x20000010, 0x00010000,0x00010010,0x20010000,0x20010010, 0x00000800,0x00000810,0x20000800,0x20000810, 0x00010800,0x00010810,0x20010800,0x20010810, 0x00000020,0x00000030,0x20000020,0x20000030, 0x00010020,0x00010030,0x20010020,0x20010030, 0x00000820,0x00000830,0x20000820,0x20000830, 0x00010820,0x00010830,0x20010820,0x20010830, 0x00080000,0x00080010,0x20080000,0x20080010, 0x00090000,0x00090010,0x20090000,0x20090010, 0x00080800,0x00080810,0x20080800,0x20080810, 0x00090800,0x00090810,0x20090800,0x20090810, 0x00080020,0x00080030,0x20080020,0x20080030, 0x00090020,0x00090030,0x20090020,0x20090030, 0x00080820,0x00080830,0x20080820,0x20080830, 0x00090820,0x00090830,0x20090820,0x20090830, /* for C bits (numbered as per FIPS 46) 7 8 10 11 12 13 */ 0x00000000,0x02000000,0x00002000,0x02002000, 0x00200000,0x02200000,0x00202000,0x02202000, 0x00000004,0x02000004,0x00002004,0x02002004, 0x00200004,0x02200004,0x00202004,0x02202004, 0x00000400,0x02000400,0x00002400,0x02002400, 0x00200400,0x02200400,0x00202400,0x02202400, 0x00000404,0x02000404,0x00002404,0x02002404, 0x00200404,0x02200404,0x00202404,0x02202404, 0x10000000,0x12000000,0x10002000,0x12002000, 0x10200000,0x12200000,0x10202000,0x12202000, 0x10000004,0x12000004,0x10002004,0x12002004, 0x10200004,0x12200004,0x10202004,0x12202004, 0x10000400,0x12000400,0x10002400,0x12002400, 0x10200400,0x12200400,0x10202400,0x12202400, 0x10000404,0x12000404,0x10002404,0x12002404, 0x10200404,0x12200404,0x10202404,0x12202404, /* for C bits (numbered as per FIPS 46) 14 15 16 17 19 20 */ 0x00000000,0x00000001,0x00040000,0x00040001, 0x01000000,0x01000001,0x01040000,0x01040001, 0x00000002,0x00000003,0x00040002,0x00040003, 0x01000002,0x01000003,0x01040002,0x01040003, 0x00000200,0x00000201,0x00040200,0x00040201, 0x01000200,0x01000201,0x01040200,0x01040201, 0x00000202,0x00000203,0x00040202,0x00040203, 0x01000202,0x01000203,0x01040202,0x01040203, 0x08000000,0x08000001,0x08040000,0x08040001, 0x09000000,0x09000001,0x09040000,0x09040001, 0x08000002,0x08000003,0x08040002,0x08040003, 0x09000002,0x09000003,0x09040002,0x09040003, 0x08000200,0x08000201,0x08040200,0x08040201, 0x09000200,0x09000201,0x09040200,0x09040201, 0x08000202,0x08000203,0x08040202,0x08040203, 0x09000202,0x09000203,0x09040202,0x09040203, /* for C bits (numbered as per FIPS 46) 21 23 24 26 27 28 */ 0x00000000,0x00100000,0x00000100,0x00100100, 0x00000008,0x00100008,0x00000108,0x00100108, 0x00001000,0x00101000,0x00001100,0x00101100, 0x00001008,0x00101008,0x00001108,0x00101108, 0x04000000,0x04100000,0x04000100,0x04100100, 0x04000008,0x04100008,0x04000108,0x04100108, 0x04001000,0x04101000,0x04001100,0x04101100, 0x04001008,0x04101008,0x04001108,0x04101108, 0x00020000,0x00120000,0x00020100,0x00120100, 0x00020008,0x00120008,0x00020108,0x00120108, 0x00021000,0x00121000,0x00021100,0x00121100, 0x00021008,0x00121008,0x00021108,0x00121108, 0x04020000,0x04120000,0x04020100,0x04120100, 0x04020008,0x04120008,0x04020108,0x04120108, 0x04021000,0x04121000,0x04021100,0x04121100, 0x04021008,0x04121008,0x04021108,0x04121108, /* for D bits (numbered as per FIPS 46) 1 2 3 4 5 6 */ 0x00000000,0x10000000,0x00010000,0x10010000, 0x00000004,0x10000004,0x00010004,0x10010004, 0x20000000,0x30000000,0x20010000,0x30010000, 0x20000004,0x30000004,0x20010004,0x30010004, 0x00100000,0x10100000,0x00110000,0x10110000, 0x00100004,0x10100004,0x00110004,0x10110004, 0x20100000,0x30100000,0x20110000,0x30110000, 0x20100004,0x30100004,0x20110004,0x30110004, 0x00001000,0x10001000,0x00011000,0x10011000, 0x00001004,0x10001004,0x00011004,0x10011004, 0x20001000,0x30001000,0x20011000,0x30011000, 0x20001004,0x30001004,0x20011004,0x30011004, 0x00101000,0x10101000,0x00111000,0x10111000, 0x00101004,0x10101004,0x00111004,0x10111004, 0x20101000,0x30101000,0x20111000,0x30111000, 0x20101004,0x30101004,0x20111004,0x30111004, /* for D bits (numbered as per FIPS 46) 8 9 11 12 13 14 */ 0x00000000,0x08000000,0x00000008,0x08000008, 0x00000400,0x08000400,0x00000408,0x08000408, 0x00020000,0x08020000,0x00020008,0x08020008, 0x00020400,0x08020400,0x00020408,0x08020408, 0x00000001,0x08000001,0x00000009,0x08000009, 0x00000401,0x08000401,0x00000409,0x08000409, 0x00020001,0x08020001,0x00020009,0x08020009, 0x00020401,0x08020401,0x00020409,0x08020409, 0x02000000,0x0A000000,0x02000008,0x0A000008, 0x02000400,0x0A000400,0x02000408,0x0A000408, 0x02020000,0x0A020000,0x02020008,0x0A020008, 0x02020400,0x0A020400,0x02020408,0x0A020408, 0x02000001,0x0A000001,0x02000009,0x0A000009, 0x02000401,0x0A000401,0x02000409,0x0A000409, 0x02020001,0x0A020001,0x02020009,0x0A020009, 0x02020401,0x0A020401,0x02020409,0x0A020409, /* for D bits (numbered as per FIPS 46) 16 17 18 19 20 21 */ 0x00000000,0x00000100,0x00080000,0x00080100, 0x01000000,0x01000100,0x01080000,0x01080100, 0x00000010,0x00000110,0x00080010,0x00080110, 0x01000010,0x01000110,0x01080010,0x01080110, 0x00200000,0x00200100,0x00280000,0x00280100, 0x01200000,0x01200100,0x01280000,0x01280100, 0x00200010,0x00200110,0x00280010,0x00280110, 0x01200010,0x01200110,0x01280010,0x01280110, 0x00000200,0x00000300,0x00080200,0x00080300, 0x01000200,0x01000300,0x01080200,0x01080300, 0x00000210,0x00000310,0x00080210,0x00080310, 0x01000210,0x01000310,0x01080210,0x01080310, 0x00200200,0x00200300,0x00280200,0x00280300, 0x01200200,0x01200300,0x01280200,0x01280300, 0x00200210,0x00200310,0x00280210,0x00280310, 0x01200210,0x01200310,0x01280210,0x01280310, /* for D bits (numbered as per FIPS 46) 22 23 24 25 27 28 */ 0x00000000,0x04000000,0x00040000,0x04040000, 0x00000002,0x04000002,0x00040002,0x04040002, 0x00002000,0x04002000,0x00042000,0x04042000, 0x00002002,0x04002002,0x00042002,0x04042002, 0x00000020,0x04000020,0x00040020,0x04040020, 0x00000022,0x04000022,0x00040022,0x04040022, 0x00002020,0x04002020,0x00042020,0x04042020, 0x00002022,0x04002022,0x00042022,0x04042022, 0x00000800,0x04000800,0x00040800,0x04040800, 0x00000802,0x04000802,0x00040802,0x04040802, 0x00002800,0x04002800,0x00042800,0x04042800, 0x00002802,0x04002802,0x00042802,0x04042802, 0x00000820,0x04000820,0x00040820,0x04040820, 0x00000822,0x04000822,0x00040822,0x04040822, 0x00002820,0x04002820,0x00042820,0x04042820, 0x00002822,0x04002822,0x00042822,0x04042822, }; /* The changes to this macro may help or hinder, depending on the * compiler and the achitecture. gcc2 always seems to do well :-). * Inspired by Dana How * DO NOT use the alternative version on machines with 8 byte longs. */ #ifdef ALT_ECB #define D_ENCRYPT(L,R,S) \ u=((R^s[S ])<<2); \ t= R^s[S+1]; \ t=((t>>2)+(t<<30)); \ L^= \ *(unsigned long *)(des_SP+0x0100+((t )&0xfc))+ \ *(unsigned long *)(des_SP+0x0300+((t>> 8)&0xfc))+ \ *(unsigned long *)(des_SP+0x0500+((t>>16)&0xfc))+ \ *(unsigned long *)(des_SP+0x0700+((t>>24)&0xfc))+ \ *(unsigned long *)(des_SP+ ((u )&0xfc))+ \ *(unsigned long *)(des_SP+0x0200+((u>> 8)&0xfc))+ \ *(unsigned long *)(des_SP+0x0400+((u>>16)&0xfc))+ \ *(unsigned long *)(des_SP+0x0600+((u>>24)&0xfc)); #else /* original version */ #define D_ENCRYPT(L,R,S) \ u=(R^s[S ]); \ t=R^s[S+1]; \ t=((t>>4)+(t<<28)); \ L^= des_SPtrans_x[1][(t )&0x3f]| \ des_SPtrans_x[3][(t>> 8)&0x3f]| \ des_SPtrans_x[5][(t>>16)&0x3f]| \ des_SPtrans_x[7][(t>>24)&0x3f]| \ des_SPtrans_x[0][(u )&0x3f]| \ des_SPtrans_x[2][(u>> 8)&0x3f]| \ des_SPtrans_x[4][(u>>16)&0x3f]| \ des_SPtrans_x[6][(u>>24)&0x3f]; #endif /* IP and FP * The problem is more of a geometric problem that random bit fiddling. 0 1 2 3 4 5 6 7 62 54 46 38 30 22 14 6 8 9 10 11 12 13 14 15 60 52 44 36 28 20 12 4 16 17 18 19 20 21 22 23 58 50 42 34 26 18 10 2 24 25 26 27 28 29 30 31 to 56 48 40 32 24 16 8 0 32 33 34 35 36 37 38 39 63 55 47 39 31 23 15 7 40 41 42 43 44 45 46 47 61 53 45 37 29 21 13 5 48 49 50 51 52 53 54 55 59 51 43 35 27 19 11 3 56 57 58 59 60 61 62 63 57 49 41 33 25 17 9 1 The output has been subject to swaps of the form 0 1 -> 3 1 but the odd and even bits have been put into 2 3 2 0 different words. The main trick is to remember that t=((l>>size)^r)&(mask); r^=t; l^=(t<>(n))^(b))&(m)),\ (b)^=(t),\ (a)^=((t)<<(n))) void perl_des_crypt( des_cblock input, des_cblock output, des_ks ks, int encrypt ) { unsigned long l,r,t,u; #ifdef ALT_ECB unsigned char *des_SP=(unsigned char *)des_SPtrans_x; #endif static int i; static unsigned long * s; unsigned char * ptr; c2l( input, l ); /* get endian free long from input block */ c2l( input, r ); /* get endian free long from input block */ /* do IP */ PERM_OP(r,l,t, 4,0x0f0f0f0f); PERM_OP(l,r,t,16,0x0000ffff); PERM_OP(r,l,t, 2,0x33333333); PERM_OP(l,r,t, 8,0x00ff00ff); PERM_OP(r,l,t, 1,0x55555555); /* r and l are reversed - remember that :-) - fix * it in the next step */ /* Things have been modified so that the initial rotate is * done outside the loop. This required the * des_SPtrans_x values in sp.h to be rotated 1 bit to the right. * One perl script later and things have a 5% speed up on a sparc2. * Thanks to Richard Outerbridge <71755.204@CompuServe.COM> * for pointing this out. */ t=(r<<1)|(r>>31); r=(l<<1)|(l>>31); l=t; /* clear the top bits on machines with 8byte longs */ l&=0xffffffff; r&=0xffffffff; s=(unsigned long *)ks; /* I don't know if it is worth the effort of loop unrolling the * inner loop */ if (encrypt) { for (i=0; i<32; i+=4) { D_ENCRYPT(l,r,i+0); /* 1 */ D_ENCRYPT(r,l,i+2); /* 2 */ } } else { for (i=30; i>0; i-=4) { D_ENCRYPT(l,r,i-0); /* 16 */ D_ENCRYPT(r,l,i-2); /* 15 */ } } l=(l>>1)|(l<<31); r=(r>>1)|(r<<31); /* clear the top bits on machines with 8byte longs */ l&=0xffffffff; r&=0xffffffff; /* swap l and r * we will not do the swap so just remember they are * reversed for the rest of the subroutine * luckily FP fixes this problem :-) */ PERM_OP(r,l,t, 1,0x55555555); PERM_OP(l,r,t, 8,0x00ff00ff); PERM_OP(r,l,t, 2,0x33333333); PERM_OP(l,r,t,16,0x0000ffff); PERM_OP(r,l,t, 4,0x0f0f0f0f); l2c( l, output ); /* get endian free long from input block */ l2c( r, output ); /* get endian free long from input block */ } void perl_des_expand_key(des_user_key userKey, des_ks ks) { unsigned long c,d,t,s; unsigned char * in; unsigned long * k; int i; static unsigned char shifts2[16]={0,0,1,1,1,1,1,1,0,1,1,1,1,1,1,0}; k=(unsigned long *)ks; in=(unsigned char *)userKey; c2l(in,c); c2l(in,d); /* do PC1 in 60 simple operations */ /* PERM_OP(d,c,t,4,0x0f0f0f0f); HPERM_OP(c,t,-2, 0xcccc0000); HPERM_OP(c,t,-1, 0xaaaa0000); HPERM_OP(c,t, 8, 0x00ff0000); HPERM_OP(c,t,-1, 0xaaaa0000); HPERM_OP(d,t,-8, 0xff000000); HPERM_OP(d,t, 8, 0x00ff0000); HPERM_OP(d,t, 2, 0x33330000); d=((d&0x00aa00aa)<<7)|((d&0x55005500)>>7)|(d&0xaa55aa55); d=(d>>8)|((c&0xf0000000)>>4); c&=0x0fffffff; */ /* I now do it in 47 simple operations :-) * Thanks to John Fletcher (john_fletcher@lccmail.ocf.llnl.gov) * for the inspiration. :-) */ PERM_OP (d,c,t,4,0x0f0f0f0f); HPERM_OP(c,t,-2,0xcccc0000); HPERM_OP(d,t,-2,0xcccc0000); PERM_OP (d,c,t,1,0x55555555); PERM_OP (c,d,t,8,0x00ff00ff); PERM_OP (d,c,t,1,0x55555555); d= (((d&0x000000ff)<<16)| (d&0x0000ff00) | ((d&0x00ff0000)>>16)|((c&0xf0000000)>>4)); c&=0x0fffffff; for (i=0; i>2)|(c<<26)); d=((d>>2)|(d<<26)); } else { c=((c>>1)|(c<<27)); d=((d>>1)|(d<<27)); } c&=0x0fffffff; d&=0x0fffffff; /* could be a few less shifts but I am to lazy at this * point in time to investigate */ s=des_skb[0][ (c )&0x3f ]| des_skb[1][((c>> 6)&0x03)|((c>> 7)&0x3c)]| des_skb[2][((c>>13)&0x0f)|((c>>14)&0x30)]| des_skb[3][((c>>20)&0x01)|((c>>21)&0x06) | ((c>>22)&0x38)]; t=des_skb[4][ (d )&0x3f ]| des_skb[5][((d>> 7)&0x03)|((d>> 8)&0x3c)]| des_skb[6][ (d>>15)&0x3f ]| des_skb[7][((d>>21)&0x0f)|((d>>22)&0x30)]; /* table contained 0213 4657 */ *(k++)=((t<<16)|(s&0x0000ffff))&0xffffffff; s= ((s>>16)|(t&0xffff0000)); s=(s<<4)|(s>>28); *(k++)=s&0xffffffff; } } Crypt-DES-2.09/DES.pm0000644000175000017500000001023415236450646012306 0ustar timtim# # Copyright (C) 1995, 1996 Systemics Ltd (http://www.systemics.com/) # All rights reserved. # # Modifications are Copyright (c) 2000, W3Works, LLC # All Rights Reserved. package Crypt::DES; require Exporter; require DynaLoader; use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); @ISA = qw(Exporter DynaLoader); # Items to export into callers namespace by default @EXPORT = qw(); # Other items we are prepared to export if requested @EXPORT_OK = qw(); $VERSION = '2.09'; bootstrap Crypt::DES $VERSION; use strict; use Carp; sub usage { my ($package, $filename, $line, $subr) = caller(1); $Carp::CarpLevel = 2; croak "Usage: $subr(@_)"; } sub blocksize { 8; } sub keysize { 8; } sub new { usage("new DES key") unless @_ == 2; my $type = shift; my $self = {}; bless $self, $type; $self->{'ks'} = Crypt::DES::expand_key(shift); return $self; } sub encrypt { usage("encrypt data[8 bytes]") unless @_ == 2; my ($self,$data) = @_; return Crypt::DES::crypt($data, $data, $self->{'ks'}, 1); } sub decrypt { usage("decrypt data[8 bytes]") unless @_ == 2; my ($self,$data) = @_; return Crypt::DES::crypt($data, $data, $self->{'ks'}, 0); } 1; __END__ =head1 NAME Crypt::DES - Perl DES encryption module =head1 SYNOPSIS use Crypt::DES; my $key = pack("H16", "0123456789ABCDEF"); my $cipher = Crypt::DES->new($key); my $ciphertext = $cipher->encrypt($plaintext); my $plaintext = $cipher->decrypt($ciphertext); =head1 DESCRIPTION The module implements the Crypt::CBC interface, which has the following methods =over 4 =item blocksize =item keysize =item encrypt =item decrypt =back =head1 FUNCTIONS =over 4 =item blocksize Returns the size (in bytes) of the block cipher. =item keysize Returns the size (in bytes) of the key. Optimal size is 8 bytes. =item new my $cipher = Crypt::DES->new($key); This creates a new Crypt::DES BlockCipher object, using $key, where $key is a key of C bytes. =item encrypt my $cipher = Crypt::DES->new($key); my $ciphertext = $cipher->encrypt($plaintext); This function encrypts $plaintext and returns the $ciphertext where $plaintext and $ciphertext should be of C bytes. =item decrypt my $cipher = Crypt::DES->new($key); my $plaintext = $cipher->decrypt($ciphertext); This function decrypts $ciphertext and returns the $plaintext where $plaintext and $ciphertext should be of C bytes. =back =head1 Security Considerations This module is not deprecated as there may still be a reason to encrypt and decrypt using DES. However, DES is known to be weak. In 2026 a standard laptop can brute-force a DES key in a few days. B. =head1 EXAMPLE my $key = pack("H16", "0123456789ABCDEF"); my $cipher = Crypt::DES->new($key); my $ciphertext = $cipher->encrypt("plaintex"); # NB - 8 bytes print unpack("H16", $ciphertext), "\n"; my $plaintext = $cipher->decrypt($ciphertext); print $plaintext, "\n"; =head1 NOTES Do note that DES only uses 8 byte keys and only works on 8 byte data blocks. If you're intending to encrypt larger blocks or entire files, please use Crypt::CBC in conjunction with this module. See the Crypt::CBC documentation for proper syntax and use. Also note that the DES algorithm is, by today's standard, weak encryption. CryptX (Crypt::Cipher::AES) is recommended if you want to replace Crypt::DES in a Crypt::CBC use case. Otherwise, replacing it with something like Crypt::AuthEnc::GCM would be recommended. =head1 SEE ALSO Crypt::AuthEnc::GCM Crypt::Blowfish Crypt::IDEA Bruce Schneier, I, 1995, Second Edition, published by John Wiley & Sons, Inc. =head1 COPYRIGHT The implementation of the DES algorithm was developed by, and is copyright of, Eric Young (eay@mincom.oz.au). Other parts of the perl extension and module are copyright of Systemics Ltd ( http://www.systemics.com/ ). Cross-platform work and packaging for single algorithm distribution is copyright of W3Works, LLC. =head1 MAINTAINER This single-algorithm package and cross-platform code is maintained by Dave Paris . Timothy Legge started maintaining this module as of version 2.08. =cut Crypt-DES-2.09/MANIFEST0000644000175000017500000000031615235742060012457 0ustar timtim_des.c _des.h Changes COPYRIGHT DES.pm DES.xs Makefile.PL MANIFEST META.json Module JSON meta-data (added by MakeMaker) META.yml Module meta-data (added by MakeMaker) README SECURITY.md test.pl typemap Crypt-DES-2.09/Makefile.PL0000555000175000017500000000145715235741617013317 0ustar timtim#! /usr/local/bin/perl use ExtUtils::MakeMaker; # See lib/ExtUtils/MakeMaker.pm for details of how to influence # the contents of the Makefile being created. require 5.004; WriteMakefile( 'NAME' => 'Crypt::DES', 'DISTNAME' => 'Crypt-DES', 'VERSION_FROM' => 'DES.pm',, 'OBJECT' => 'DES.o _des.o', 'dist' => {COMPRESS=>'gzip', SUFFIX=>'gz'}, META_MERGE => { 'meta-spec' => { version => 2 }, 'resources' => { 'repository' => { 'type' => 'git', 'url' => 'git://github.com/timlegge/perl-Crypt-DES.git', 'web' => 'https://github.com/timlegge/perl-Crypt-DES', }, 'bugtracker' => { 'web' => 'https://github.com/timlegge/perl-Crypt-DES/issues', }, }, }, ); Crypt-DES-2.09/README0000644000175000017500000000626015236446616012223 0ustar timtimCrypt::DES - an XS-based DES implimentation for Perl. The 2.XX tree represents a major improvement over the 1.XX tree. This package builds on big-endian machines and many more x86 platforms than before. (with a few rare exceptions, like gcc on DUX against 5.004). mod_ssl conflicts have also been resolved. Thank you to Jan 'Kozo' Vajda for pointing out the des_SPtrans overlap between these two packages. In release 2.04, des.h was renamed to _des.h in an attempt to solve the build-on-Solaris problem. Reports would be appreciated. In release 2.05, all references to des_ were changed to _des_ since the 2.04 release didn't seem to fix the problem on Solaris. In release 2.06, SvUPGRADE was changed to a statement. In release 2.07, a minor bug in META.yml was fixed. See Changes introduced in 2.08 for release information. Prerequisites ------------- For the full test suite to run, Crypt::CBC, version 1.22 or higher is required (recommended is 1.25 or higher), however this module is not mandatory for standalone DES use, and all other tests will run to completion. Installing Crypt::DES --------------------- nothing unusual: 1. perl Makefile.PL 2. make 3. make test 4. make install Notes ----- The following is a list of known good platforms: FreeBSD 3.5-RELEASE / x86 / 5.005 OpenBSD 2.7 / x86 / 5.6 Linux / x86 / 5.005 & 5.6 Linux / PPC / 5.005 & 5.6 Solaris7 / SPARC / 5.005 Solaris / x86 / 5.005 DUX / Alpha / 5.005 (using DEC cc) Win32 / x86 / 5.005 (using VC++5) OS/2 / x86 / 5.6 Reports of builds against 5.004 have been equally positive. Building on Win32 with VC++6 may prove problematic. Complaints about build problems on Win32 will be sent to /dev/null. Please report any other successful OS/Platform combinations to amused@pobox.com. Thank you. What you can expect in the way of speed: Linux/x86 dual PII400 non-cached cipher speed test. 5000 encrypt iterations 0 wallclock secs ( 0.52 usr + 0.01 sys = 0.53 CPU) non-cached cipher speed test. 5000 decrypt iterations 1 wallclock secs ( 0.52 usr + 0.01 sys = 0.53 CPU) cached cipher speed test. 10000 encrypt iterations 0 wallclock secs ( 0.20 usr + 0.00 sys = 0.20 CPU) cached cipher speed test. 10000 decrypt iterations 0 wallclock secs ( 0.22 usr + 0.00 sys = 0.22 CPU) Windows NT4(SP6)/x86 dual PPro 200 non-cached cipher speed test. 5000 encrypt iterations 1 wallclock secs ( 1.25 usr + 0.00 sys = 1.25 CPU) non-cached cipher speed test. 5000 decrypt iterations 2 wallclock secs ( 1.22 usr + 0.00 sys = 1.22 CPU) cached cipher speed test. 10000 encrypt iterations 0 wallclock secs ( 0.58 usr + 0.00 sys = 0.58 CPU) cached cipher speed test. 10000 decrypt iterations 1 wallclock secs ( 0.59 usr + 0.00 sys = 0.59 CPU) Solaris7/SPARC UltraSPARCIIi 277Mhz non-cached cipher speed test. 5000 encrypt iterations 1 wallclock secs ( 1.08 usr + 0.20 sys = 1.28 CPU) non-cached cipher speed test. 5000 decrypt iterations 2 wallclock secs ( 1.14 usr + 0.12 sys = 1.26 CPU) cached cipher speed test. 10000 encrypt iterations 0 wallclock secs ( 0.52 usr + 0.00 sys = 0.52 CPU) cached cipher speed test. 10000 decrypt iterations 1 wallclock secs ( 0.50 usr + 0.00 sys = 0.50 CPU) Crypt-DES-2.09/_des.h0000644000175000017500000000037515235703331012414 0ustar timtimtypedef unsigned char des_user_key[8]; typedef unsigned char des_cblock[8]; typedef unsigned long des_ks[32]; void perl_des_crypt( des_cblock in, des_cblock out, des_ks key, int encrypt ); void perl_des_expand_key( des_user_key userKey, des_ks key ); Crypt-DES-2.09/COPYRIGHT0000644000175000017500000000516715235727657012651 0ustar timtimThis perl extension includes software developed by Eric Young (eay@mincom.oz.au) Modifications, including cross-platform fixups, and single-algorithm distribution packaging are Copyright (C) 2000 W3Works, LLC. All Rights Reserved. Mail questions and comments to Dave Paris . Original distribution license (below) applies. Other parts of the library are covered by the following licence: Copyright (C) 1995, 1996 Systemics Ltd (http://www.systemics.com/) All rights reserved. This library and applications are FREE FOR COMMERCIAL AND NON-COMMERCIAL USE as long as the following conditions are adhered to. Copyright remains with Systemics Ltd, and as such any Copyright notices in the code are not to be removed. If this code is used in a product, Systemics should be given attribution as the author of the parts used. This can be in the form of a textual message at program startup or in documentation (online or textual) provided with the package. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. All advertising materials mentioning features or use of this software must display the following acknowledgement: This product includes software developed by Systemics Ltd (http://www.systemics.com/) THIS SOFTWARE IS PROVIDED BY SYSTEMICS LTD ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. The licence and distribution terms for any publically available version or derivative of this code cannot be changed. i.e. this code cannot simply be copied and put under another distribution licence [including the GNU Public Licence.] Crypt-DES-2.09/typemap0000644000175000017500000000001007157231055012720 0ustar timtimTYPEMAP Crypt-DES-2.09/META.yml0000664000175000017500000000114415236451445012606 0ustar timtim--- abstract: unknown author: - unknown build_requires: ExtUtils::MakeMaker: '0' configure_requires: ExtUtils::MakeMaker: '0' dynamic_config: 1 generated_by: 'ExtUtils::MakeMaker version 7.78, CPAN::Meta::Converter version 2.150013' license: unknown meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Crypt-DES no_index: directory: - t - inc resources: bugtracker: https://github.com/timlegge/perl-Crypt-DES/issues repository: git://github.com/timlegge/perl-Crypt-DES.git version: '2.09' x_serialization_backend: 'CPAN::Meta::YAML version 0.020' Crypt-DES-2.09/SECURITY.md0000644000175000017500000000727215235725612013133 0ustar timtim# Security Policy for the Crypt-DES distribution. Report security issues by email to Timothy Legge . This is the Security Policy for Crypt-DES. This text is based on the CPAN Security Group's Guidelines for Adding a Security Policy to Perl Distributions (version 1.3.0) https://security.metacpan.org/docs/guides/security-policy-for-authors.html # How to Report a Security Vulnerability Security vulnerabilities can be reported to the current Crypt-DES maintainers by email to Timothy Legge . Please include as many details as possible, including code samples or test cases, so that we can reproduce the issue. Check that your report does not expose any sensitive data, such as passwords, tokens, or personal information. If you would like any help with triaging the issue, or if the issue is being actively exploited, please copy the report to the CPAN Security Group (CPANSec) at . Please *do not* use the public issue reporting system on RT or GitHub issues for reporting security vulnerabilities. Please do not disclose the security vulnerability in public forums until past any proposed date for public disclosure, or it has been made public by the maintainers or CPANSec. That includes patches or pull requests. For more information, see [Report a Security Issue](https://security.metacpan.org/docs/report.html) on the CPANSec website. ## Response to Reports The maintainer(s) aim to acknowledge your security report as soon as possible. However, this project is maintained by a single person in their spare time, and they cannot guarantee a rapid response. If you have not received a response from them within 2 weeks, then please send a reminder to them and copy the report to CPANSec at . Please note that the initial response to your report will be an acknowledgement, with a possible query for more information. It will not necessarily include any fixes for the issue. The project maintainer(s) may forward this issue to the security contacts for other projects where we believe it is relevant. This may include embedded libraries, system libraries, prerequisite modules or downstream software that uses this software. They may also forward this issue to CPANSec. # Which Software This Policy Applies To Any security vulnerabilities in Crypt-DES are covered by this policy. Security vulnerabilities in versions of any libraries that are included in Crypt-DES are also covered by this policy. Security vulnerabilities are considered anything that allows users to execute unauthorised code, access unauthorised resources, or to have an adverse impact on accessibility or performance of a system. Security vulnerabilities in upstream software (prerequisite modules or system libraries, or in Perl), are not covered by this policy unless they affect Crypt-DES, or Crypt-DES can be used to exploit vulnerabilities in them. Security vulnerabilities in downstream software (any software that uses Crypt-DES, or plugins to it that are not included with the Crypt-DES distribution) are not covered by this policy. ## Supported Versions of Crypt-DES The maintainer(s) will only commit to releasing security fixes for the latest version of Crypt-DES. # Installation and Usage Issues The distribution metadata specifies minimum versions of prerequisites that are required for Crypt-DES to work. However, some of these prerequisites may have security vulnerabilities, and you should ensure that you are using up-to-date versions of these prerequisites. Where security vulnerabilities are known, the metadata may indicate newer versions as recommended. ## Usage Please see the software documentation for further information. Crypt-DES-2.09/DES.xs0000644000175000017500000000277615235703240012326 0ustar timtim/* * cross-platform and mod_ssl-safe code modifications are Copyright (C) * 2000 W3Works, LLC. All rights reserved. */ /* * Copyright (C) 1995, 1996 Systemics Ltd (http://www.systemics.com/) * All rights reserved. */ #include "EXTERN.h" #include "perl.h" #include "XSUB.h" typedef unsigned char i8; typedef unsigned long i32; #include "_des.h" #ifndef sv_undef #define sv_undef PL_sv_undef #endif MODULE = Crypt::DES PACKAGE = Crypt::DES PREFIX = _des_ PROTOTYPES: DISABLE char * _des_expand_key(key) char * key = NO_INIT STRLEN key_len = NO_INIT CODE: { des_ks ks; key = (char *) SvPV(ST(0), key_len); if (key_len != sizeof(des_user_key)) croak("Invalid key"); perl_des_expand_key((i8 *)key, ks); ST(0) = sv_2mortal(newSVpv((char *)ks, sizeof(ks))); } void _des_crypt(input, output, ks, enc_flag) char * input = NO_INIT SV * output char * ks = NO_INIT int enc_flag STRLEN input_len = NO_INIT STRLEN output_len = NO_INIT STRLEN ks_len = NO_INIT CODE: { input = (char *) SvPV(ST(0), input_len); if (input_len != 8) croak("input must be 8 bytes long"); ks = (char *) SvPV(ST(2), ks_len); if (ks_len != sizeof(des_ks)) croak("Invalid key schedule"); if (output == &sv_undef) output = sv_newmortal(); output_len = 8; (SvUPGRADE(output, SVt_PV)); perl_des_crypt(input, SvGROW(output, output_len), (i32 *)ks, enc_flag); SvCUR_set(output, output_len); *SvEND(output) = '\0'; (void) SvPOK_only(output); SvTAINT(output); ST(0) = output; } Crypt-DES-2.09/Changes0000644000175000017500000000760415236451414012631 0ustar timtimRevision history for Crypt-DES 2.09 2026-08-10 [Significant Changes since 2.08] - Essentially 2.08-TRIAL with minor documentation and test updates - Add a Security Considerations section to the pod - Clarify module recommendations - Move new Module::Whatever to Module::Whatever->new() in pod and tests [Detailed Changes] - 6d8a719 Increment the version for a release - 8aa5583 Update .gitignore - e4255e8 Update README - bfc70b5 Add a Security Considerations section and clarifiy recommendations - 6f3c622 Modernize module new() in tests - 061b73a Fix over item back pod with blank lines - cefb17d Modernize new() calling and fix missing SYNOPSIS - 40eb31b Add a Changes file 2.08 2026-08-08 [Significant Changes since 2.07] - New Maintainer (TIMLEGGE) - Fixes failure to build on newer GCC with implicit-function-declaration - Add Security Policy (DES is insecure) - Minor packaging updates [Detailed Changes] - 76a27cd Update/reformat MANIFEST Changes, META.json and SECURITY.md added - 6cc5f6a Add .gitignore file - 9578c62 Regenerate META.yml - 35fb123 Add links for github code repo and issues - 1b3a375 Increment version number - c8d74aa Add a Security Policy - 19dd1d0 Fix RT#133363 and RT#133412 fails to build with implicit-function-declaration - 9cba1a9 Import Crypt-DES-2.07 from CPAN Note: The change details below were generated with the assistance of AI. In most cases the wording is direct from the updates in various parts of the code, README or pod. While I have attempted to ensure its accuracy by reviewing the diffs between the versions myself, it should be considered informational only and may have inaccuracies. Should you be concerned about the history of this module prior to 2.08 you will need to review the diffs between released versions manually. 2.07 2013-07-23 - Fixed malformed META.yml. - test.pl $VERSION resynced with DES.pm (was left at 2.05). 2.06 2013-07-23 - Fixed use of SvUPGRADE as an rvalue, which broke the build under Perl 5.18; now called as a statement. - Regenerated META.yml; 2.05 2005-12-08 - Renamed the XS entry points from des_* to _des_* (XS PREFIX and _des.h prototypes), the 2.04 header rename having failed to fix the Solaris symbol clash. 2.04 2005-12-08 - Renamed des.h to _des.h to avoid clashing with the system DES header on Solaris. - Added META.yml. 2.03 2000-12-05 - Restored "require DynaLoader", missing since 2.00 although DynaLoader was still listed in @ISA. - Dropped the stray "package DES;" so blocksize/keysize/new/ encrypt/decrypt are defined in Crypt::DES itself. - bootstrap now version-checks against $VERSION. - Declared globals with "use vars". - Documentation: describe the interface as Crypt::CBC's rather than Crypt::BlockCipher's. (2.02 was never released to CPAN.) 2.01 2000-09-11 - Removed a stray #include from _des.c. - Comment and dead-code cleanup in DES.pm and test.pl. 2.00 2000-09-11 - Maintenance taken over by Dave Paris / W3Works, LLC. - Portability rewrite: builds on big-endian machines and on many more x86 platforms; local i8/i32 typedefs replace the u_int*_t types, and PL_sv_undef is handled for newer perls. - Renamed the internal DES routines to perl_des_* and des.c to _des.c, resolving the des_SPtrans symbol clash with mod_ssl (reported by Jan 'Kozo' Vajda). - POD folded from DES.pod into DES.pm; README added. - Makefile.PL requires Perl 5.004 and takes VERSION_FROM DES.pm. - Expanded tests 1.01 1999-06-07 - Include instead of . - Adjusted library paths so installation via "perl -MCPAN" works. 1.0 1996-05-22 - First release, by Gary Howland; DES implementation by Eric Young, Perl extension by Systemics Ltd. Crypt-DES-2.09/META.json0000664000175000017500000000211015236451445012750 0ustar timtim{ "abstract" : "unknown", "author" : [ "unknown" ], "dynamic_config" : 1, "generated_by" : "ExtUtils::MakeMaker version 7.78, CPAN::Meta::Converter version 2.150013", "license" : [ "unknown" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "Crypt-DES", "no_index" : { "directory" : [ "t", "inc" ] }, "prereqs" : { "build" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://github.com/timlegge/perl-Crypt-DES/issues" }, "repository" : { "type" : "git", "url" : "git://github.com/timlegge/perl-Crypt-DES.git", "web" : "https://github.com/timlegge/perl-Crypt-DES" } }, "version" : "2.09", "x_serialization_backend" : "JSON::PP version 4.16" }