Crypt-Eksblowfish-0.009000755001750001750 011556073712 15043 5ustar00zeframzefram000000000000Crypt-Eksblowfish-0.009/META.yml000444001750001750 246711556073702 16461 0ustar00zeframzefram000000000000--- abstract: 'the Eksblowfish block cipher' author: - 'Solar Designer (solar at openwall.com)' - 'Andrew Main (Zefram) ' build_requires: ExtUtils::CBuilder: 0.15 Module::Build: 0 Test::More: 0 perl: 5.006 strict: 0 warnings: 0 configure_requires: Module::Build: 0 perl: 5.006 strict: 0 warnings: 0 dynamic_config: 0 generated_by: 'Module::Build version 0.38, CPAN::Meta::Converter version 2.110580' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 name: Crypt-Eksblowfish provides: Crypt::Eksblowfish: file: lib/Crypt/Eksblowfish.pm version: 0.009 Crypt::Eksblowfish::Bcrypt: file: lib/Crypt/Eksblowfish/Bcrypt.pm version: 0.009 Crypt::Eksblowfish::Blowfish: file: lib/Crypt/Eksblowfish/Blowfish.pm version: 0.009 Crypt::Eksblowfish::Family: file: lib/Crypt/Eksblowfish/Family.pm version: 0.009 Crypt::Eksblowfish::Subkeyed: file: lib/Crypt/Eksblowfish/Subkeyed.pm version: 0.009 Crypt::Eksblowfish::Uklblowfish: file: lib/Crypt/Eksblowfish/Uklblowfish.pm version: 0.009 requires: Carp: 0 Class::Mix: 0.001 Exporter: 0 MIME::Base64: 2.21 XSLoader: 0 parent: 0 perl: 5.006 strict: 0 warnings: 0 resources: license: http://dev.perl.org/licenses/ version: 0.009 Crypt-Eksblowfish-0.009/SIGNATURE000644001750001750 466111556073712 16475 0ustar00zeframzefram000000000000This file contains message digests of all files listed in MANIFEST, signed via the Module::Signature module, version 0.66. To verify the content in this distribution, first make sure you have Module::Signature installed, then type: % cpansign -v It will check each file's integrity, as well as the signature's validity. If "==> Signature verified OK! <==" is not displayed, the distribution may already have been compromised, and you should not run its Makefile.PL or Build.PL. -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 SHA1 1056e548e8fc802cf9e547d3a1ac86708c90f132 .cvsignore SHA1 e655960831df6355f525b51095559d95045da7b2 Build.PL SHA1 55c49c1b1043d82dd7784a8cdb0b2ee08d5068b4 Changes SHA1 7aed7cddf47ea2ad0d3f355851344a231d1f8c01 MANIFEST SHA1 7e2d0343f5cc744c28e988bbcde680b5a419afb4 META.json SHA1 7cf6de35cd0ee6241aa0a1b4a18df50859703f68 META.yml SHA1 a4df8e97ccd390a42212af5a9f4d0986c85e7a5f Makefile.PL SHA1 5cfbb041c39258e6515e4df053f0e0e697cbd9bb README SHA1 1008eae74fc0ed04ffe262cf934bbe7ef3b56c18 lib/Crypt/.cvsignore SHA1 816c7b280b5756b9e4a91b53542218d90ae7bc4a lib/Crypt/Eksblowfish.pm SHA1 30385869643dbf1ae13cca68d242bbb26e507f7b lib/Crypt/Eksblowfish.xs SHA1 1e472a5263e35591c63e4924a1cd89782d6b24ce lib/Crypt/Eksblowfish/Bcrypt.pm SHA1 42896ef4a196e01a58b27bd7e0fc6b00bbe3218f lib/Crypt/Eksblowfish/Blowfish.pm SHA1 e5dc5f1779ab8852a9132d38d07ee047d9d68ef7 lib/Crypt/Eksblowfish/Family.pm SHA1 8ce83e9805152c826e23e00f0221728c68642948 lib/Crypt/Eksblowfish/Subkeyed.pm SHA1 37ea8bbe887befa6b2682fa88bf15a2dea6252b6 lib/Crypt/Eksblowfish/Uklblowfish.pm SHA1 fc61296b16be35687dfe8dc25868927ecbda5186 t/base64.t SHA1 2982289d98db3f0328f31e3a5e1ad49d3344fbff t/bcrypt.t SHA1 965c1c785b1e5c3ce0fa0d54cd65af72813e396d t/bcrypt_hash.t SHA1 85e1ac18310b6a0fa01b5d78dd4ead89c765fbf0 t/blowfish.t SHA1 a23c99f053c821c932513c8c9ef97da4cec4df28 t/eksblowfish.t SHA1 23077a7069fcb22dee7a8bde5f7de29bfa86e839 t/family.t SHA1 904d9a4f76525e2303e4b0c168c68230f223c8de t/pod_cvg.t SHA1 65c75abdef6f01a5d1588a307f2ddfe2333dc961 t/pod_syn.t SHA1 e609e4d8ea71964f400a8db6e3a02e9792c73677 t/subkey.t SHA1 e761a97727f8bf7238e5d8553f78575f8cc6d364 t/uklblowfish.t SHA1 7b673ca24bf62de6e7550aa7b19ed92e96dc0a78 t/utf8.t SHA1 7ad478ba2f46a8291fd098976ea1cebc39db5971 typemap -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) iEYEARECAAYFAk24d8IACgkQOV9mt2VyAVFYHQCdEsi0g7BAoO0rXXz93sZL2qfy Vo4AnjrlDqWl1g4QL40L+7tM/aPHe7sY =mEj6 -----END PGP SIGNATURE----- Crypt-Eksblowfish-0.009/MANIFEST000444001750001750 76611556073702 16321 0ustar00zeframzefram000000000000.cvsignore Build.PL Changes MANIFEST META.json META.yml Makefile.PL README lib/Crypt/.cvsignore lib/Crypt/Eksblowfish.pm lib/Crypt/Eksblowfish.xs lib/Crypt/Eksblowfish/Bcrypt.pm lib/Crypt/Eksblowfish/Blowfish.pm lib/Crypt/Eksblowfish/Family.pm lib/Crypt/Eksblowfish/Subkeyed.pm lib/Crypt/Eksblowfish/Uklblowfish.pm t/base64.t t/bcrypt.t t/bcrypt_hash.t t/blowfish.t t/eksblowfish.t t/family.t t/pod_cvg.t t/pod_syn.t t/subkey.t t/uklblowfish.t t/utf8.t typemap SIGNATURE Added here by Module::Build Crypt-Eksblowfish-0.009/Changes000444001750001750 734611556073702 16504 0ustar00zeframzefram000000000000version 0.009; 2011-04-28 * in XS, use PERL_NO_GET_CONTEXT for efficiency * in XS, declare "PROTOTYPES: DISABLE" to prevent automatic generation of unintended prototypes * jump through hoops to avoid compiler warnings * use full stricture in test suite * in Build.PL, complete declaration of configure-time requirements * slightly reformat some Perl and C code to avoid exceeding 80 columns * include META.json in distribution * add MYMETA.json and MYMETA.yml to .cvsignore version 0.008; 2010-03-11 * bugfix: avoid memory leak when returning block to Perl space * check for required Perl version at runtime * in XS, avoid using "class" as a variable name, for compatibility with C++ compilers * in Build.PL, explicitly declare configure-time requirements * remove bogus "exit 0" from Build.PL version 0.007; 2009-04-22 * in XS code, use the correct "PREINIT:" instead of "INIT:" to introduce variable declarations * test Uklblowfish with long keys version 0.006; 2009-04-21 * in C::E::Family, new method "as_class" to work around Crypt::CBC brain damage * use simpler "parent" pragma in place of "base" * in documentation, use the term "truth value" instead of the less precise "boolean" * drop prototypes from method subs (where the prototypes have no effect) * in C::E::Family, abandon use of the "fields" module * add casts for pointer target signedness to avoid compiler warnings * use full stricture in Build.PL version 0.005; 2008-04-06 * bugfix: when UTF8-decoding salt, don't attempt to read freed copy * don't rely on typemap handling of AV* arguments, because it's broken on perl 5.6 * add backward-compatibility definition of bytes_from_utf8() function * avoid calling XSLoader::load() redundantly, which was causing redefinition warnings on older versions of XSLoader version 0.004; 2008-04-02 * add backward-compatibility definition of Newx() macro * in tests, avoid unreliable "\S" regexp element version 0.003; 2007-09-26 * bugfix: in Crypt::Eksblowfish::{Bcrypt,Family}, ensure that the Crypt::Eksblowfish that is loaded is recent enough to have the UTF8 bugfix * bugfix: avoid memory leaks when croaking * new class Crypt::Eksblowfish::Subkeyed, with constructors "new_from_subkeys" and "new_initial" and subkey access methods "p_array" and "s_boxes", which is now a superclass of Crypt::Eksblowfish * new method "is_weak" (in superclass Crypt::Eksblowfish::Subkeyed) to check for weak keys * new class Crypt::Eksblowfish::Blowfish, which implements the original Blowfish cipher * new class Crypt::Eksblowfish::Uklblowfish, which implements Blowfish with key length limits removed * for efficiency, change objects to point to C key schedule structure instead of storing that structure as a Perl string * wrap up block argument marshalling code in typemap * use "fields" module to structure Crypt::Eksblowfish::Family object * in documentation and all source, use precise term "octet" instead of "byte" * document class methods in a separate section from instance methods * tests for key length restrictions version 0.002; 2007-09-17 * bugfix: correctly handle UTF8-encoded scalars * don't use ppport.h, because it wasn't doing anything for perl v5.6+ * test POD syntax and coverage * build with Module::Build instead of ExtUtils::MakeMaker * rearrange source tree to fit Module::Build convention * complete dependency list * include signature in distribution * in documentation, separate "license" section from "copyright" section version 0.001; 2006-08-12 * obfuscate Solar Designer's email address, at eir request version 0.000; 2006-08-06 * initial released version Crypt-Eksblowfish-0.009/README000444001750001750 301011556073702 16051 0ustar00zeframzefram000000000000NAME Crypt::Eksblowfish - the Eksblowfish block cipher DESCRIPTION Eksblowfish is a variant of the Blowfish cipher, modified to make the key setup very expensive. ("Eks" stands for "expensive key schedule".) This doesn't make it significantly cryptographically stronger, but is intended to hinder brute-force attacks. It also makes it unsuitable for any application requiring key agility. It was designed by Niels Provos and David Mazieres for password hashing in OpenBSD. Eksblowfish is a parameterised (family-keyed) cipher. It takes a cost parameter that controls how expensive the key scheduling is. It also takes a family key, known as the "salt". Cost and salt parameters together define a cipher family. Within each family, a key determines an encryption function in the usual way. This distribution also includes an implementation of "bcrypt", the Unix crypt() password hashing algorithm based on Eksblowfish. INSTALLATION perl Build.PL ./Build ./Build test ./Build install AUTHOR Eksblowfish guts originally by Solar Designer (solar at openwall.com). Modifications and Perl interface by Andrew Main (Zefram) . COPYRIGHT Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Andrew Main (Zefram) The original Eksblowfish code (in the form of crypt()) from which this module is derived is in the public domain. It may be found at . LICENSE This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Crypt-Eksblowfish-0.009/typemap000444001750001750 122511556073702 16601 0ustar00zeframzefram000000000000TYPEMAP Crypt::Eksblowfish::Subkeyed T_PTROBJ Crypt::Eksblowfish T_PTROBJ Crypt::Eksblowfish::Blowfish T_PTROBJ Crypt::Eksblowfish::Uklblowfish T_PTROBJ BF_block T_BF_BLOCK INPUT T_BF_BLOCK { STRLEN bfb_len; U8 *bfb_octets; bool bfb_tofree; sv_to_octets(&bfb_octets, &bfb_len, &bfb_tofree, $arg); if(bfb_len != 8) { if(bfb_tofree) Safefree(bfb_octets); croak(\"block must be exactly eight octets long\"); } $var = import_block(bfb_octets); if(bfb_tofree) Safefree(bfb_octets); } OUTPUT T_BF_BLOCK { U8 bfb_octets[8]; export_block($var, (unsigned char *)bfb_octets); sv_setpvn($arg, (char*)bfb_octets, 8); SvUTF8_off($arg); } Crypt-Eksblowfish-0.009/Makefile.PL000444001750001750 230211556073702 17146 0ustar00zeframzefram000000000000# Note: this file was auto-generated by Module::Build::Compat version 0.3800 require 5.006; unless (eval "use Module::Build::Compat 0.02; 1" ) { print "This module requires Module::Build to install itself.\n"; require ExtUtils::MakeMaker; my $yn = ExtUtils::MakeMaker::prompt (' Install Module::Build now from CPAN?', 'y'); unless ($yn =~ /^y/i) { die " *** Cannot install without Module::Build. Exiting ...\n"; } require Cwd; require File::Spec; require CPAN; # Save this 'cause CPAN will chdir all over the place. my $cwd = Cwd::cwd(); CPAN::Shell->install('Module::Build::Compat'); CPAN::Shell->expand("Module", "Module::Build::Compat")->uptodate or die "Couldn't install Module::Build, giving up.\n"; chdir $cwd or die "Cannot chdir() back to $cwd: $!"; } eval "use Module::Build::Compat 0.02; 1" or die $@; Module::Build::Compat->run_build_pl(args => \@ARGV); my $build_script = 'Build'; $build_script .= '.com' if $^O eq 'VMS'; exit(0) unless(-e $build_script); # cpantesters convention require Module::Build; Module::Build::Compat->write_makefile(build_class => 'Module::Build'); Crypt-Eksblowfish-0.009/.cvsignore000444001750001750 15711556073702 17162 0ustar00zeframzefram000000000000Build Makefile _build blib META.json META.yml MYMETA.json MYMETA.yml Makefile.PL SIGNATURE Crypt-Eksblowfish-* Crypt-Eksblowfish-0.009/META.json000444001750001750 423311556073702 16622 0ustar00zeframzefram000000000000{ "abstract" : "the Eksblowfish block cipher", "author" : [ "Solar Designer (solar at openwall.com)", "Andrew Main (Zefram) " ], "dynamic_config" : 0, "generated_by" : "Module::Build version 0.38, CPAN::Meta::Converter version 2.110580", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "Crypt-Eksblowfish", "prereqs" : { "build" : { "requires" : { "ExtUtils::CBuilder" : "0.15", "Module::Build" : 0, "Test::More" : 0, "perl" : "5.006", "strict" : 0, "warnings" : 0 } }, "configure" : { "requires" : { "Module::Build" : 0, "perl" : "5.006", "strict" : 0, "warnings" : 0 } }, "runtime" : { "requires" : { "Carp" : 0, "Class::Mix" : "0.001", "Exporter" : 0, "MIME::Base64" : "2.21", "XSLoader" : 0, "parent" : 0, "perl" : "5.006", "strict" : 0, "warnings" : 0 } } }, "provides" : { "Crypt::Eksblowfish" : { "file" : "lib/Crypt/Eksblowfish.pm", "version" : "0.009" }, "Crypt::Eksblowfish::Bcrypt" : { "file" : "lib/Crypt/Eksblowfish/Bcrypt.pm", "version" : "0.009" }, "Crypt::Eksblowfish::Blowfish" : { "file" : "lib/Crypt/Eksblowfish/Blowfish.pm", "version" : "0.009" }, "Crypt::Eksblowfish::Family" : { "file" : "lib/Crypt/Eksblowfish/Family.pm", "version" : "0.009" }, "Crypt::Eksblowfish::Subkeyed" : { "file" : "lib/Crypt/Eksblowfish/Subkeyed.pm", "version" : "0.009" }, "Crypt::Eksblowfish::Uklblowfish" : { "file" : "lib/Crypt/Eksblowfish/Uklblowfish.pm", "version" : "0.009" } }, "release_status" : "stable", "resources" : { "license" : [ "http://dev.perl.org/licenses/" ] }, "version" : "0.009" } Crypt-Eksblowfish-0.009/Build.PL000444001750001750 154711556073702 16502 0ustar00zeframzefram000000000000{ use 5.006; } use warnings; use strict; use Module::Build; Module::Build->new( module_name => "Crypt::Eksblowfish", license => "perl", dist_author => [ "Solar Designer (solar at openwall.com)", "Andrew Main (Zefram) ", ], configure_requires => { "Module::Build" => 0, "perl" => "5.006", "strict" => 0, "warnings" => 0, }, build_requires => { "ExtUtils::CBuilder" => "0.15", "Module::Build" => 0, "Test::More" => 0, "perl" => "5.006", "strict" => 0, "warnings" => 0, }, requires => { "Carp" => 0, "Class::Mix" => "0.001", "Exporter" => 0, "MIME::Base64" => "2.21", "XSLoader" => 0, "parent" => 0, "perl" => "5.006", "strict" => 0, "warnings" => 0, }, dynamic_config => 0, meta_add => { distribution_type => "module" }, create_makefile_pl => "passthrough", sign => 1, )->create_build_script; 1; Crypt-Eksblowfish-0.009/lib000755001750001750 011556073702 15610 5ustar00zeframzefram000000000000Crypt-Eksblowfish-0.009/lib/Crypt000755001750001750 011556073702 16711 5ustar00zeframzefram000000000000Crypt-Eksblowfish-0.009/lib/Crypt/Eksblowfish.pm000444001750001750 1072511556073702 21711 0ustar00zeframzefram000000000000=head1 NAME Crypt::Eksblowfish - the Eksblowfish block cipher =head1 SYNOPSIS use Crypt::Eksblowfish; $block_size = Crypt::Eksblowfish->blocksize; $cipher = Crypt::Eksblowfish->new(8, $salt, $key); $block_size = $cipher->blocksize; $ciphertext = $cipher->encrypt($plaintext); $plaintext = $cipher->decrypt($ciphertext); $p_array = $cipher->p_array; $s_boxes = $cipher->s_boxes; if($cipher->is_weak) { ... =head1 DESCRIPTION An object of this type encapsulates a keyed instance of the Eksblowfish block cipher, ready to encrypt and decrypt. Eksblowfish is a variant of the Blowfish cipher, modified to make the key setup very expensive. ("Eks" stands for "expensive key schedule".) This doesn't make it significantly cryptographically stronger, but is intended to hinder brute-force attacks. It also makes it unsuitable for any application requiring key agility. It was designed by Niels Provos and David Mazieres for password hashing in OpenBSD. See L for the hash algorithm. See L for the unmodified Blowfish cipher. Eksblowfish is a parameterised (family-keyed) cipher. It takes a cost parameter that controls how expensive the key scheduling is. It also takes a family key, known as the "salt". Cost and salt parameters together define a cipher family. Within each family, a key determines an encryption function in the usual way. See L for a way to encapsulate an Eksblowfish cipher family. =cut package Crypt::Eksblowfish; { use 5.006; } use warnings; use strict; our $VERSION = "0.009"; use parent "Crypt::Eksblowfish::Subkeyed"; die "mismatched versions of Crypt::Eksblowfish modules" unless $Crypt::Eksblowfish::Subkeyed::VERSION eq $VERSION; =head1 CLASS METHODS =over =item Crypt::Eksblowfish->blocksize Returns 8, indicating the Eksblowfish block size of 8 octets. This method may be called on either the class or an instance. =back =head1 CONSTRUCTOR =over =item Crypt::Eksblowfish->new(COST, SALT, KEY) Performs key setup on a new instance of the Eksblowfish algorithm, returning the keyed state. The KEY may be any length from 1 octet to 72 octets inclusive. The SALT is a family key, and must be exactly 16 octets. COST is an integer parameter controlling the expense of keying: the number of operations in key setup is proportional to 2^COST. All three parameters influence all the subkeys; changing any of them produces a different encryption function. Due to the mandatory family-keying parameters (COST and SALT), this constructor does not match the interface expected by C and similar crypto plumbing modules. To use Eksblowfish with them it is necessary to have an object that encapsulates a cipher family and provides a constructor that takes only a key argument. That facility is supplied by C. =back =head1 METHODS =over =item $cipher->blocksize Returns 8, indicating the Eksblowfish block size of 8 octets. This method may be called on either the class or an instance. =item $cipher->encrypt(PLAINTEXT) PLAINTEXT must be exactly eight octets. The block is encrypted, and the ciphertext is returned. =item $cipher->decrypt(CIPHERTEXT) CIPHERTEXT must be exactly eight octets. The block is decrypted, and the plaintext is returned. =item $cipher->p_array =item $cipher->s_boxes These methods extract the subkeys from the keyed cipher. This is not required in ordinary operation. See the superclass L for details. =item $cipher->is_weak This method checks whether the cipher has been keyed with a weak key. It may be desired to avoid using weak keys. See the superclass L for details. =back =head1 SEE ALSO L, L, L, L, L =head1 AUTHOR Eksblowfish guts originally by Solar Designer (solar at openwall.com). Modifications and Perl interface by Andrew Main (Zefram) . =head1 COPYRIGHT Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Andrew Main (Zefram) The original Eksblowfish code (in the form of crypt()) from which this module is derived is in the public domain. It may be found at L. =head1 LICENSE This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut 1; Crypt-Eksblowfish-0.009/lib/Crypt/.cvsignore000444001750001750 1611556073702 21003 0ustar00zeframzefram000000000000Eksblowfish.c Crypt-Eksblowfish-0.009/lib/Crypt/Eksblowfish.xs000444001750001750 6311711556073702 21732 0ustar00zeframzefram000000000000#define PERL_NO_GET_CONTEXT 1 #include "EXTERN.h" #include "perl.h" #include "XSUB.h" #ifndef Newx # define Newx(v,n,t) New(0,v,n,t) #endif /* !Newx */ #ifndef bytes_from_utf8 /* 5.6.0 has UTF-8 scalars, but lacks the utility bytes_from_utf8() */ static U8 * bytes_from_utf8(U8 *orig, STRLEN *len_p, bool *is_utf8_p) { STRLEN orig_len = *len_p; U8 *orig_end = orig + orig_len; STRLEN new_len = orig_len; U8 *new; U8 *p, *q; if(!*is_utf8_p) return orig; for(p = orig; p != orig_end; ) { U8 fb = *p++, sb; if(fb <= 0x7f) continue; if(p == orig_end || !(fb >= 0xc2 && fb <= 0xc3)) return orig; sb = *p++; if(!(sb >= 0x80 && sb <= 0xbf)) return orig; new_len--; } if(new_len == orig_len) { *is_utf8_p = 0; return orig; } Newx(new, new_len+1, U8); for(p = orig, q = new; p != orig_end; ) { U8 fb = *p++; *q++ = fb <= 0x7f ? fb : ((fb & 0x03) << 6) | (*p++ & 0x3f); } *q = 0; *len_p = new_len; *is_utf8_p = 0; return new; } #endif /* !bytes_from_utf8 */ /* * This Blowfish code is derived from the Blowfish crypt() code written * by Solar Designer (solar at openwall.com) in 1998-2002 and placed in * the public domain. Original at . * Extensively modified by Andrew Main (Zefram) . */ #include typedef unsigned int BF_word; /* Number of Blowfish rounds, this is also hardcoded into a few places */ #define BF_N 16 typedef struct { BF_word L, R; } BF_block; typedef BF_word BF_round_key_set[BF_N + 2]; typedef struct { BF_round_key_set P; BF_word S[4][0x100]; } BF_key_schedule; /* * P-box and S-box tables initialized with digits of Pi. */ static const BF_key_schedule BF_init_state = { { 0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344, 0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89, 0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c, 0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917, 0x9216d5d9, 0x8979fb1b }, { { 0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7, 0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99, 0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16, 0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e, 0x0d95748f, 0x728eb658, 0x718bcd58, 0x82154aee, 0x7b54a41d, 0xc25a59b5, 0x9c30d539, 0x2af26013, 0xc5d1b023, 0x286085f0, 0xca417918, 0xb8db38ef, 0x8e79dcb0, 0x603a180e, 0x6c9e0e8b, 0xb01e8a3e, 0xd71577c1, 0xbd314b27, 0x78af2fda, 0x55605c60, 0xe65525f3, 0xaa55ab94, 0x57489862, 0x63e81440, 0x55ca396a, 0x2aab10b6, 0xb4cc5c34, 0x1141e8ce, 0xa15486af, 0x7c72e993, 0xb3ee1411, 0x636fbc2a, 0x2ba9c55d, 0x741831f6, 0xce5c3e16, 0x9b87931e, 0xafd6ba33, 0x6c24cf5c, 0x7a325381, 0x28958677, 0x3b8f4898, 0x6b4bb9af, 0xc4bfe81b, 0x66282193, 0x61d809cc, 0xfb21a991, 0x487cac60, 0x5dec8032, 0xef845d5d, 0xe98575b1, 0xdc262302, 0xeb651b88, 0x23893e81, 0xd396acc5, 0x0f6d6ff3, 0x83f44239, 0x2e0b4482, 0xa4842004, 0x69c8f04a, 0x9e1f9b5e, 0x21c66842, 0xf6e96c9a, 0x670c9c61, 0xabd388f0, 0x6a51a0d2, 0xd8542f68, 0x960fa728, 0xab5133a3, 0x6eef0b6c, 0x137a3be4, 0xba3bf050, 0x7efb2a98, 0xa1f1651d, 0x39af0176, 0x66ca593e, 0x82430e88, 0x8cee8619, 0x456f9fb4, 0x7d84a5c3, 0x3b8b5ebe, 0xe06f75d8, 0x85c12073, 0x401a449f, 0x56c16aa6, 0x4ed3aa62, 0x363f7706, 0x1bfedf72, 0x429b023d, 0x37d0d724, 0xd00a1248, 0xdb0fead3, 0x49f1c09b, 0x075372c9, 0x80991b7b, 0x25d479d8, 0xf6e8def7, 0xe3fe501a, 0xb6794c3b, 0x976ce0bd, 0x04c006ba, 0xc1a94fb6, 0x409f60c4, 0x5e5c9ec2, 0x196a2463, 0x68fb6faf, 0x3e6c53b5, 0x1339b2eb, 0x3b52ec6f, 0x6dfc511f, 0x9b30952c, 0xcc814544, 0xaf5ebd09, 0xbee3d004, 0xde334afd, 0x660f2807, 0x192e4bb3, 0xc0cba857, 0x45c8740f, 0xd20b5f39, 0xb9d3fbdb, 0x5579c0bd, 0x1a60320a, 0xd6a100c6, 0x402c7279, 0x679f25fe, 0xfb1fa3cc, 0x8ea5e9f8, 0xdb3222f8, 0x3c7516df, 0xfd616b15, 0x2f501ec8, 0xad0552ab, 0x323db5fa, 0xfd238760, 0x53317b48, 0x3e00df82, 0x9e5c57bb, 0xca6f8ca0, 0x1a87562e, 0xdf1769db, 0xd542a8f6, 0x287effc3, 0xac6732c6, 0x8c4f5573, 0x695b27b0, 0xbbca58c8, 0xe1ffa35d, 0xb8f011a0, 0x10fa3d98, 0xfd2183b8, 0x4afcb56c, 0x2dd1d35b, 0x9a53e479, 0xb6f84565, 0xd28e49bc, 0x4bfb9790, 0xe1ddf2da, 0xa4cb7e33, 0x62fb1341, 0xcee4c6e8, 0xef20cada, 0x36774c01, 0xd07e9efe, 0x2bf11fb4, 0x95dbda4d, 0xae909198, 0xeaad8e71, 0x6b93d5a0, 0xd08ed1d0, 0xafc725e0, 0x8e3c5b2f, 0x8e7594b7, 0x8ff6e2fb, 0xf2122b64, 0x8888b812, 0x900df01c, 0x4fad5ea0, 0x688fc31c, 0xd1cff191, 0xb3a8c1ad, 0x2f2f2218, 0xbe0e1777, 0xea752dfe, 0x8b021fa1, 0xe5a0cc0f, 0xb56f74e8, 0x18acf3d6, 0xce89e299, 0xb4a84fe0, 0xfd13e0b7, 0x7cc43b81, 0xd2ada8d9, 0x165fa266, 0x80957705, 0x93cc7314, 0x211a1477, 0xe6ad2065, 0x77b5fa86, 0xc75442f5, 0xfb9d35cf, 0xebcdaf0c, 0x7b3e89a0, 0xd6411bd3, 0xae1e7e49, 0x00250e2d, 0x2071b35e, 0x226800bb, 0x57b8e0af, 0x2464369b, 0xf009b91e, 0x5563911d, 0x59dfa6aa, 0x78c14389, 0xd95a537f, 0x207d5ba2, 0x02e5b9c5, 0x83260376, 0x6295cfa9, 0x11c81968, 0x4e734a41, 0xb3472dca, 0x7b14a94a, 0x1b510052, 0x9a532915, 0xd60f573f, 0xbc9bc6e4, 0x2b60a476, 0x81e67400, 0x08ba6fb5, 0x571be91f, 0xf296ec6b, 0x2a0dd915, 0xb6636521, 0xe7b9f9b6, 0xff34052e, 0xc5855664, 0x53b02d5d, 0xa99f8fa1, 0x08ba4799, 0x6e85076a }, { 0x4b7a70e9, 0xb5b32944, 0xdb75092e, 0xc4192623, 0xad6ea6b0, 0x49a7df7d, 0x9cee60b8, 0x8fedb266, 0xecaa8c71, 0x699a17ff, 0x5664526c, 0xc2b19ee1, 0x193602a5, 0x75094c29, 0xa0591340, 0xe4183a3e, 0x3f54989a, 0x5b429d65, 0x6b8fe4d6, 0x99f73fd6, 0xa1d29c07, 0xefe830f5, 0x4d2d38e6, 0xf0255dc1, 0x4cdd2086, 0x8470eb26, 0x6382e9c6, 0x021ecc5e, 0x09686b3f, 0x3ebaefc9, 0x3c971814, 0x6b6a70a1, 0x687f3584, 0x52a0e286, 0xb79c5305, 0xaa500737, 0x3e07841c, 0x7fdeae5c, 0x8e7d44ec, 0x5716f2b8, 0xb03ada37, 0xf0500c0d, 0xf01c1f04, 0x0200b3ff, 0xae0cf51a, 0x3cb574b2, 0x25837a58, 0xdc0921bd, 0xd19113f9, 0x7ca92ff6, 0x94324773, 0x22f54701, 0x3ae5e581, 0x37c2dadc, 0xc8b57634, 0x9af3dda7, 0xa9446146, 0x0fd0030e, 0xecc8c73e, 0xa4751e41, 0xe238cd99, 0x3bea0e2f, 0x3280bba1, 0x183eb331, 0x4e548b38, 0x4f6db908, 0x6f420d03, 0xf60a04bf, 0x2cb81290, 0x24977c79, 0x5679b072, 0xbcaf89af, 0xde9a771f, 0xd9930810, 0xb38bae12, 0xdccf3f2e, 0x5512721f, 0x2e6b7124, 0x501adde6, 0x9f84cd87, 0x7a584718, 0x7408da17, 0xbc9f9abc, 0xe94b7d8c, 0xec7aec3a, 0xdb851dfa, 0x63094366, 0xc464c3d2, 0xef1c1847, 0x3215d908, 0xdd433b37, 0x24c2ba16, 0x12a14d43, 0x2a65c451, 0x50940002, 0x133ae4dd, 0x71dff89e, 0x10314e55, 0x81ac77d6, 0x5f11199b, 0x043556f1, 0xd7a3c76b, 0x3c11183b, 0x5924a509, 0xf28fe6ed, 0x97f1fbfa, 0x9ebabf2c, 0x1e153c6e, 0x86e34570, 0xeae96fb1, 0x860e5e0a, 0x5a3e2ab3, 0x771fe71c, 0x4e3d06fa, 0x2965dcb9, 0x99e71d0f, 0x803e89d6, 0x5266c825, 0x2e4cc978, 0x9c10b36a, 0xc6150eba, 0x94e2ea78, 0xa5fc3c53, 0x1e0a2df4, 0xf2f74ea7, 0x361d2b3d, 0x1939260f, 0x19c27960, 0x5223a708, 0xf71312b6, 0xebadfe6e, 0xeac31f66, 0xe3bc4595, 0xa67bc883, 0xb17f37d1, 0x018cff28, 0xc332ddef, 0xbe6c5aa5, 0x65582185, 0x68ab9802, 0xeecea50f, 0xdb2f953b, 0x2aef7dad, 0x5b6e2f84, 0x1521b628, 0x29076170, 0xecdd4775, 0x619f1510, 0x13cca830, 0xeb61bd96, 0x0334fe1e, 0xaa0363cf, 0xb5735c90, 0x4c70a239, 0xd59e9e0b, 0xcbaade14, 0xeecc86bc, 0x60622ca7, 0x9cab5cab, 0xb2f3846e, 0x648b1eaf, 0x19bdf0ca, 0xa02369b9, 0x655abb50, 0x40685a32, 0x3c2ab4b3, 0x319ee9d5, 0xc021b8f7, 0x9b540b19, 0x875fa099, 0x95f7997e, 0x623d7da8, 0xf837889a, 0x97e32d77, 0x11ed935f, 0x16681281, 0x0e358829, 0xc7e61fd6, 0x96dedfa1, 0x7858ba99, 0x57f584a5, 0x1b227263, 0x9b83c3ff, 0x1ac24696, 0xcdb30aeb, 0x532e3054, 0x8fd948e4, 0x6dbc3128, 0x58ebf2ef, 0x34c6ffea, 0xfe28ed61, 0xee7c3c73, 0x5d4a14d9, 0xe864b7e3, 0x42105d14, 0x203e13e0, 0x45eee2b6, 0xa3aaabea, 0xdb6c4f15, 0xfacb4fd0, 0xc742f442, 0xef6abbb5, 0x654f3b1d, 0x41cd2105, 0xd81e799e, 0x86854dc7, 0xe44b476a, 0x3d816250, 0xcf62a1f2, 0x5b8d2646, 0xfc8883a0, 0xc1c7b6a3, 0x7f1524c3, 0x69cb7492, 0x47848a0b, 0x5692b285, 0x095bbf00, 0xad19489d, 0x1462b174, 0x23820e00, 0x58428d2a, 0x0c55f5ea, 0x1dadf43e, 0x233f7061, 0x3372f092, 0x8d937e41, 0xd65fecf1, 0x6c223bdb, 0x7cde3759, 0xcbee7460, 0x4085f2a7, 0xce77326e, 0xa6078084, 0x19f8509e, 0xe8efd855, 0x61d99735, 0xa969a7aa, 0xc50c06c2, 0x5a04abfc, 0x800bcadc, 0x9e447a2e, 0xc3453484, 0xfdd56705, 0x0e1e9ec9, 0xdb73dbd3, 0x105588cd, 0x675fda79, 0xe3674340, 0xc5c43465, 0x713e38d8, 0x3d28f89e, 0xf16dff20, 0x153e21e7, 0x8fb03d4a, 0xe6e39f2b, 0xdb83adf7 }, { 0xe93d5a68, 0x948140f7, 0xf64c261c, 0x94692934, 0x411520f7, 0x7602d4f7, 0xbcf46b2e, 0xd4a20068, 0xd4082471, 0x3320f46a, 0x43b7d4b7, 0x500061af, 0x1e39f62e, 0x97244546, 0x14214f74, 0xbf8b8840, 0x4d95fc1d, 0x96b591af, 0x70f4ddd3, 0x66a02f45, 0xbfbc09ec, 0x03bd9785, 0x7fac6dd0, 0x31cb8504, 0x96eb27b3, 0x55fd3941, 0xda2547e6, 0xabca0a9a, 0x28507825, 0x530429f4, 0x0a2c86da, 0xe9b66dfb, 0x68dc1462, 0xd7486900, 0x680ec0a4, 0x27a18dee, 0x4f3ffea2, 0xe887ad8c, 0xb58ce006, 0x7af4d6b6, 0xaace1e7c, 0xd3375fec, 0xce78a399, 0x406b2a42, 0x20fe9e35, 0xd9f385b9, 0xee39d7ab, 0x3b124e8b, 0x1dc9faf7, 0x4b6d1856, 0x26a36631, 0xeae397b2, 0x3a6efa74, 0xdd5b4332, 0x6841e7f7, 0xca7820fb, 0xfb0af54e, 0xd8feb397, 0x454056ac, 0xba489527, 0x55533a3a, 0x20838d87, 0xfe6ba9b7, 0xd096954b, 0x55a867bc, 0xa1159a58, 0xcca92963, 0x99e1db33, 0xa62a4a56, 0x3f3125f9, 0x5ef47e1c, 0x9029317c, 0xfdf8e802, 0x04272f70, 0x80bb155c, 0x05282ce3, 0x95c11548, 0xe4c66d22, 0x48c1133f, 0xc70f86dc, 0x07f9c9ee, 0x41041f0f, 0x404779a4, 0x5d886e17, 0x325f51eb, 0xd59bc0d1, 0xf2bcc18f, 0x41113564, 0x257b7834, 0x602a9c60, 0xdff8e8a3, 0x1f636c1b, 0x0e12b4c2, 0x02e1329e, 0xaf664fd1, 0xcad18115, 0x6b2395e0, 0x333e92e1, 0x3b240b62, 0xeebeb922, 0x85b2a20e, 0xe6ba0d99, 0xde720c8c, 0x2da2f728, 0xd0127845, 0x95b794fd, 0x647d0862, 0xe7ccf5f0, 0x5449a36f, 0x877d48fa, 0xc39dfd27, 0xf33e8d1e, 0x0a476341, 0x992eff74, 0x3a6f6eab, 0xf4f8fd37, 0xa812dc60, 0xa1ebddf8, 0x991be14c, 0xdb6e6b0d, 0xc67b5510, 0x6d672c37, 0x2765d43b, 0xdcd0e804, 0xf1290dc7, 0xcc00ffa3, 0xb5390f92, 0x690fed0b, 0x667b9ffb, 0xcedb7d9c, 0xa091cf0b, 0xd9155ea3, 0xbb132f88, 0x515bad24, 0x7b9479bf, 0x763bd6eb, 0x37392eb3, 0xcc115979, 0x8026e297, 0xf42e312d, 0x6842ada7, 0xc66a2b3b, 0x12754ccc, 0x782ef11c, 0x6a124237, 0xb79251e7, 0x06a1bbe6, 0x4bfb6350, 0x1a6b1018, 0x11caedfa, 0x3d25bdd8, 0xe2e1c3c9, 0x44421659, 0x0a121386, 0xd90cec6e, 0xd5abea2a, 0x64af674e, 0xda86a85f, 0xbebfe988, 0x64e4c3fe, 0x9dbc8057, 0xf0f7c086, 0x60787bf8, 0x6003604d, 0xd1fd8346, 0xf6381fb0, 0x7745ae04, 0xd736fccc, 0x83426b33, 0xf01eab71, 0xb0804187, 0x3c005e5f, 0x77a057be, 0xbde8ae24, 0x55464299, 0xbf582e61, 0x4e58f48f, 0xf2ddfda2, 0xf474ef38, 0x8789bdc2, 0x5366f9c3, 0xc8b38e74, 0xb475f255, 0x46fcd9b9, 0x7aeb2661, 0x8b1ddf84, 0x846a0e79, 0x915f95e2, 0x466e598e, 0x20b45770, 0x8cd55591, 0xc902de4c, 0xb90bace1, 0xbb8205d0, 0x11a86248, 0x7574a99e, 0xb77f19b6, 0xe0a9dc09, 0x662d09a1, 0xc4324633, 0xe85a1f02, 0x09f0be8c, 0x4a99a025, 0x1d6efe10, 0x1ab93d1d, 0x0ba5a4df, 0xa186f20f, 0x2868f169, 0xdcb7da83, 0x573906fe, 0xa1e2ce9b, 0x4fcd7f52, 0x50115e01, 0xa70683fa, 0xa002b5c4, 0x0de6d027, 0x9af88c27, 0x773f8641, 0xc3604c06, 0x61a806b5, 0xf0177a28, 0xc0f586e0, 0x006058aa, 0x30dc7d62, 0x11e69ed7, 0x2338ea63, 0x53c2dd94, 0xc2c21634, 0xbbcbee56, 0x90bcb6de, 0xebfc7da1, 0xce591d76, 0x6f05e409, 0x4b7c0188, 0x39720a3d, 0x7c927c24, 0x86e3725f, 0x724d9db9, 0x1ac15bb4, 0xd39eb8fc, 0xed545578, 0x08fca5b5, 0xd83d7cd3, 0x4dad0fc4, 0x1e50ef5e, 0xb161e6f8, 0xa28514d9, 0x6c51133c, 0x6fd5c7e7, 0x56e14ec4, 0x362abfce, 0xddc6c837, 0xd79a3234, 0x92638212, 0x670efa8e, 0x406000e0 }, { 0x3a39ce37, 0xd3faf5cf, 0xabc27737, 0x5ac52d1b, 0x5cb0679e, 0x4fa33742, 0xd3822740, 0x99bc9bbe, 0xd5118e9d, 0xbf0f7315, 0xd62d1c7e, 0xc700c47b, 0xb78c1b6b, 0x21a19045, 0xb26eb1be, 0x6a366eb4, 0x5748ab2f, 0xbc946e79, 0xc6a376d2, 0x6549c2c8, 0x530ff8ee, 0x468dde7d, 0xd5730a1d, 0x4cd04dc6, 0x2939bbdb, 0xa9ba4650, 0xac9526e8, 0xbe5ee304, 0xa1fad5f0, 0x6a2d519a, 0x63ef8ce2, 0x9a86ee22, 0xc089c2b8, 0x43242ef6, 0xa51e03aa, 0x9cf2d0a4, 0x83c061ba, 0x9be96a4d, 0x8fe51550, 0xba645bd6, 0x2826a2f9, 0xa73a3ae1, 0x4ba99586, 0xef5562e9, 0xc72fefd3, 0xf752f7da, 0x3f046f69, 0x77fa0a59, 0x80e4a915, 0x87b08601, 0x9b09e6ad, 0x3b3ee593, 0xe990fd5a, 0x9e34d797, 0x2cf0b7d9, 0x022b8b51, 0x96d5ac3a, 0x017da67d, 0xd1cf3ed6, 0x7c7d2d28, 0x1f9f25cf, 0xadf2b89b, 0x5ad6b472, 0x5a88f54c, 0xe029ac71, 0xe019a5e6, 0x47b0acfd, 0xed93fa9b, 0xe8d3c48d, 0x283b57cc, 0xf8d56629, 0x79132e28, 0x785f0191, 0xed756055, 0xf7960e44, 0xe3d35e8c, 0x15056dd4, 0x88f46dba, 0x03a16125, 0x0564f0bd, 0xc3eb9e15, 0x3c9057a2, 0x97271aec, 0xa93a072a, 0x1b3f6d9b, 0x1e6321f5, 0xf59c66fb, 0x26dcf319, 0x7533d928, 0xb155fdf5, 0x03563482, 0x8aba3cbb, 0x28517711, 0xc20ad9f8, 0xabcc5167, 0xccad925f, 0x4de81751, 0x3830dc8e, 0x379d5862, 0x9320f991, 0xea7a90c2, 0xfb3e7bce, 0x5121ce64, 0x774fbe32, 0xa8b6e37e, 0xc3293d46, 0x48de5369, 0x6413e680, 0xa2ae0810, 0xdd6db224, 0x69852dfd, 0x09072166, 0xb39a460a, 0x6445c0dd, 0x586cdecf, 0x1c20c8ae, 0x5bbef7dd, 0x1b588d40, 0xccd2017f, 0x6bb4e3bb, 0xdda26a7e, 0x3a59ff45, 0x3e350a44, 0xbcb4cdd5, 0x72eacea8, 0xfa6484bb, 0x8d6612ae, 0xbf3c6f47, 0xd29be463, 0x542f5d9e, 0xaec2771b, 0xf64e6370, 0x740e0d8d, 0xe75b1357, 0xf8721671, 0xaf537d5d, 0x4040cb08, 0x4eb4e2cc, 0x34d2466a, 0x0115af84, 0xe1b00428, 0x95983a1d, 0x06b89fb4, 0xce6ea048, 0x6f3f3b82, 0x3520ab82, 0x011a1d4b, 0x277227f8, 0x611560b1, 0xe7933fdc, 0xbb3a792b, 0x344525bd, 0xa08839e1, 0x51ce794b, 0x2f32c9b7, 0xa01fbac9, 0xe01cc87e, 0xbcc7d1f6, 0xcf0111c3, 0xa1e8aac7, 0x1a908749, 0xd44fbd9a, 0xd0dadecb, 0xd50ada38, 0x0339c32a, 0xc6913667, 0x8df9317c, 0xe0b12b4f, 0xf79e59b7, 0x43f5bb3a, 0xf2d519ff, 0x27d9459c, 0xbf97222c, 0x15e6fc2a, 0x0f91fc71, 0x9b941525, 0xfae59361, 0xceb69ceb, 0xc2a86459, 0x12baa8d1, 0xb6c1075e, 0xe3056a0c, 0x10d25065, 0xcb03a442, 0xe0ec6e0e, 0x1698db3b, 0x4c98a0be, 0x3278e964, 0x9f1f9532, 0xe0d392df, 0xd3a0342b, 0x8971f21e, 0x1b0a7441, 0x4ba3348c, 0xc5be7120, 0xc37632d8, 0xdf359f8d, 0x9b992f2e, 0xe60b6f47, 0x0fe3f11d, 0xe54cda54, 0x1edad891, 0xce6279cf, 0xcd3e7e6f, 0x1618b166, 0xfd2c1d05, 0x848fd2c5, 0xf6fb2299, 0xf523f357, 0xa6327623, 0x93a83531, 0x56cccd02, 0xacf08162, 0x5a75ebb5, 0x6e163697, 0x88d273cc, 0xde966292, 0x81b949d0, 0x4c50901b, 0x71c65614, 0xe6c6c7bd, 0x327a140a, 0x45e1d006, 0xc3f27b9a, 0xc9aa53fd, 0x62a80f00, 0xbb25bfe2, 0x35bdd2f6, 0x71126905, 0xb2040222, 0xb6cbcf7c, 0xcd769c2b, 0x53113ec0, 0x1640e3d3, 0x38abbd60, 0x2547adf0, 0xba38209c, 0xf746ce76, 0x77afa1c5, 0x20756060, 0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e, 0x1948c25c, 0x02fb8a8c, 0x01c36ae4, 0xd6ebe1f9, 0x90d4f869, 0xa65cdea0, 0x3f09252d, 0xc208e69f, 0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6 } } }; #if defined(__i386__) || defined(__x86_64__) || defined(__alpha__) || \ defined(__hppa__) /* Architectures which can shift addresses left by 2 bits with no extra cost */ #define BF_ROUND(L, R, N) \ tmp1 = L & 0xFF; \ tmp2 = L >> 8; \ tmp2 &= 0xFF; \ tmp3 = L >> 16; \ tmp3 &= 0xFF; \ tmp4 = L >> 24; \ tmp1 = ks->S[3][tmp1]; \ tmp2 = ks->S[2][tmp2]; \ tmp3 = ks->S[1][tmp3]; \ tmp3 += ks->S[0][tmp4]; \ tmp3 ^= tmp2; \ R ^= ks->P[N + 1]; \ tmp3 += tmp1; \ R ^= tmp3; #else /* Architectures with no complicated addressing modes supported */ #define BF_INDEX(S, i) \ (*((BF_word *)(((unsigned char *)S) + (i)))) #define BF_ROUND(L, R, N) \ tmp1 = L & 0xFF; \ tmp1 <<= 2; \ tmp2 = L >> 6; \ tmp2 &= 0x3FC; \ tmp3 = L >> 14; \ tmp3 &= 0x3FC; \ tmp4 = L >> 22; \ tmp4 &= 0x3FC; \ tmp1 = BF_INDEX(ks->S[3], tmp1); \ tmp2 = BF_INDEX(ks->S[2], tmp2); \ tmp3 = BF_INDEX(ks->S[1], tmp3); \ tmp3 += BF_INDEX(ks->S[0], tmp4); \ tmp3 ^= tmp2; \ R ^= ks->P[N + 1]; \ tmp3 += tmp1; \ R ^= tmp3; #endif /* * Encrypt one block, BF_N is hardcoded here. */ static BF_block encrypt_block(const BF_key_schedule *ks, BF_block blk) { BF_word tmp1, tmp2, tmp3, tmp4, t; blk.L ^= ks->P[0]; BF_ROUND(blk.L, blk.R, 0); BF_ROUND(blk.R, blk.L, 1); BF_ROUND(blk.L, blk.R, 2); BF_ROUND(blk.R, blk.L, 3); BF_ROUND(blk.L, blk.R, 4); BF_ROUND(blk.R, blk.L, 5); BF_ROUND(blk.L, blk.R, 6); BF_ROUND(blk.R, blk.L, 7); BF_ROUND(blk.L, blk.R, 8); BF_ROUND(blk.R, blk.L, 9); BF_ROUND(blk.L, blk.R, 10); BF_ROUND(blk.R, blk.L, 11); BF_ROUND(blk.L, blk.R, 12); BF_ROUND(blk.R, blk.L, 13); BF_ROUND(blk.L, blk.R, 14); BF_ROUND(blk.R, blk.L, 15); t = blk.R; blk.R = blk.L; blk.L = t ^ ks->P[BF_N + 1]; return blk; } /* * Decrypt one block, BF_N is hardcoded here. */ static BF_block decrypt_block(const BF_key_schedule *ks, BF_block blk) { BF_word tmp1, tmp2, tmp3, tmp4, t; t = blk.L ^ ks->P[BF_N + 1]; blk.L = blk.R; blk.R = t; BF_ROUND(blk.R, blk.L, 15); BF_ROUND(blk.L, blk.R, 14); BF_ROUND(blk.R, blk.L, 13); BF_ROUND(blk.L, blk.R, 12); BF_ROUND(blk.R, blk.L, 11); BF_ROUND(blk.L, blk.R, 10); BF_ROUND(blk.R, blk.L, 9); BF_ROUND(blk.L, blk.R, 8); BF_ROUND(blk.R, blk.L, 7); BF_ROUND(blk.L, blk.R, 6); BF_ROUND(blk.R, blk.L, 5); BF_ROUND(blk.L, blk.R, 4); BF_ROUND(blk.R, blk.L, 3); BF_ROUND(blk.L, blk.R, 2); BF_ROUND(blk.R, blk.L, 1); BF_ROUND(blk.L, blk.R, 0); blk.L ^= ks->P[0]; return blk; } static BF_block import_block(const unsigned char octets[8]) { BF_block blk; blk.L = (((BF_word)octets[0]) << 24) | (((BF_word)octets[1]) << 16) | (((BF_word)octets[2]) << 8) | ((BF_word)octets[3]); blk.R = (((BF_word)octets[4]) << 24) | (((BF_word)octets[5]) << 16) | (((BF_word)octets[6]) << 8) | ((BF_word)octets[7]); return blk; } static void export_block(BF_block blk, unsigned char octets[8]) { octets[0] = (blk.L >> 24) & 0xff; octets[1] = (blk.L >> 16) & 0xff; octets[2] = (blk.L >> 8) & 0xff; octets[3] = (blk.L ) & 0xff; octets[4] = (blk.R >> 24) & 0xff; octets[5] = (blk.R >> 16) & 0xff; octets[6] = (blk.R >> 8) & 0xff; octets[7] = (blk.R ) & 0xff; } static void expand_key(const unsigned char *key, size_t keylen, BF_round_key_set expkey) { const unsigned char *kend = key + keylen; const unsigned char *kptr; int i; for (kptr = key, i = 0; i != BF_N + 2; i++) { BF_word tmp = 0; int j; for (j = 0; j != 4; j++) { tmp = (tmp << 8) | *kptr++; if (kptr == kend) kptr = key; } expkey[i] = tmp; } } static void merge_key(const BF_round_key_set expkey, BF_key_schedule *ks) { int i; for(i = BF_N + 2; i--; ) { ks->P[i] ^= expkey[i]; } } static void munge_subkeys(BF_key_schedule *ks) { BF_block blk = { 0, 0 }; BF_word *subkey_ptr; for(subkey_ptr = ks->P; subkey_ptr != ks[1].P; ) { blk = encrypt_block(ks, blk); *subkey_ptr++ = blk.L; *subkey_ptr++ = blk.R; } } static void setup_eksblowfish_ks(int cost, const unsigned char *salt, const unsigned char *key, size_t keylen, BF_key_schedule *ks) { BF_round_key_set expanded_key; BF_round_key_set expanded_salt; BF_block blk; BF_word *subkey_ptr; unsigned int count; int i, j; expand_key(key, keylen, expanded_key); for(i = 0; i != 4; i += 2) { BF_block sblk; sblk = import_block(salt + i*4); expanded_salt[i] = sblk.L; expanded_salt[i+1] = sblk.R; } for(; i != BF_N + 2; i++) { expanded_salt[i] = expanded_salt[i & 3]; } memcpy(ks, &BF_init_state, sizeof(*ks)); merge_key(expanded_key, ks); blk.L = blk.R = 0; for(subkey_ptr = ks->P, j = 0; subkey_ptr != ks[1].P; j ^= 2) { blk.L ^= expanded_salt[j]; blk.R ^= expanded_salt[j + 1]; blk = encrypt_block(ks, blk); *subkey_ptr++ = blk.L; *subkey_ptr++ = blk.R; } for(count = 1U << cost; count--; ) { for(j = 0; j != 2; j++) { merge_key(j == 0 ? expanded_key : expanded_salt, ks); munge_subkeys(ks); } } } static void setup_blowfish_ks(const unsigned char *key, size_t keylen, BF_key_schedule *ks) { BF_round_key_set expanded_key; expand_key(key, keylen, expanded_key); memcpy(ks, &BF_init_state, sizeof(*ks)); merge_key(expanded_key, ks); munge_subkeys(ks); } #define sv_to_octets(octets_p, len_p, must_free_p, sv) \ THX_sv_to_octets(aTHX_ octets_p, len_p, must_free_p, sv) static void THX_sv_to_octets(pTHX_ U8 **octets_p, STRLEN *len_p, bool *must_free_p, SV *sv) { U8 *in_str = (U8*)SvPV(sv, *len_p); bool is_utf8 = !!SvUTF8(sv); *octets_p = bytes_from_utf8(in_str, len_p, &is_utf8); if(is_utf8) croak("input must contain only octets"); *must_free_p = *octets_p != in_str; } typedef BF_key_schedule *Crypt__Eksblowfish__Subkeyed; typedef BF_key_schedule *Crypt__Eksblowfish; typedef BF_key_schedule *Crypt__Eksblowfish__Blowfish; typedef BF_key_schedule *Crypt__Eksblowfish__Uklblowfish; MODULE = Crypt::Eksblowfish PACKAGE = Crypt::Eksblowfish::Subkeyed PROTOTYPES: DISABLE int blocksize(SV *invocant) CODE: PERL_UNUSED_VAR(invocant); RETVAL = 8; OUTPUT: RETVAL BF_block encrypt(Crypt::Eksblowfish::Subkeyed ks, BF_block pt_block) CODE: RETVAL = encrypt_block(ks, pt_block); OUTPUT: RETVAL BF_block decrypt(Crypt::Eksblowfish::Subkeyed ks, BF_block ct_block) CODE: RETVAL = decrypt_block(ks, ct_block); OUTPUT: RETVAL SV * p_array(Crypt::Eksblowfish::Subkeyed ks) PREINIT: AV *rka; int i; CODE: rka = newAV(); av_fill(rka, BF_N+2 - 1); for(i = 0; i != BF_N+2; i++) { av_store(rka, i, newSVuv(ks->P[i])); } RETVAL = newRV_noinc((SV *)rka); OUTPUT: RETVAL SV * s_boxes(Crypt::Eksblowfish::Subkeyed ks) PREINIT: AV *aa, *ab; int i, j; CODE: ab = newAV(); av_fill(ab, 4 - 1); for(j = 0; j != 4; j++) { aa = newAV(); av_fill(aa, 256 - 1); for(i = 0; i != 256; i++) { av_store(aa, i, newSVuv(ks->S[j][i])); } av_store(ab, j, newRV_noinc((SV *)aa)); } RETVAL = newRV_noinc((SV *)ab); OUTPUT: RETVAL bool is_weak(Crypt::Eksblowfish::Subkeyed ks) PREINIT: int s, i, j; CODE: RETVAL = 0; for(s = 4; s--; ) { for(i = 256; --i; ) { BF_word si = ks->S[s][i]; for(j = i; j--; ) { if(ks->S[s][j] == si) { RETVAL = 1; goto done; } } } } done: ; OUTPUT: RETVAL void DESTROY(Crypt::Eksblowfish::Subkeyed ks) CODE: Safefree(ks); Crypt::Eksblowfish::Subkeyed new_from_subkeys(SV *classname, SV *parray_sv, SV *sboxes_sv) PREINIT: AV *parray, *sboxes; int i, j; CODE: PERL_UNUSED_VAR(classname); if(!SvROK(parray_sv)) croak("P-array argument must be reference"); parray = (AV *)SvRV(parray_sv); if(SvTYPE((SV *)parray) != SVt_PVAV) croak("P-array argument must be reference to array"); if(!SvROK(sboxes_sv)) croak("S-boxes argument must be reference"); sboxes = (AV *)SvRV(sboxes_sv); if(SvTYPE((SV *)sboxes) != SVt_PVAV) croak("S-boxes argument must be reference to array"); Newx(RETVAL, 1, BF_key_schedule); if(av_len(parray) != BF_N+2 - 1) { Safefree(RETVAL); croak("need exactly %d round keys", BF_N+2); } for(i = 0; i != BF_N+2; i++) { SV **item_p = av_fetch(parray, i, 0); RETVAL->P[i] = SvUV(item_p ? *item_p : &PL_sv_undef); } if(av_len(sboxes) != 4 - 1) { Safefree(RETVAL); croak("need exactly four S-boxes"); } for(j = 0; j != 4; j++) { SV **item_p = av_fetch(sboxes, j, 0); SV *sbox_sv = item_p ? *item_p : &PL_sv_undef; AV *sbox; if(!SvROK(sbox_sv)) { Safefree(RETVAL); croak("S-box sub-argument must be reference"); } sbox = (AV *)SvRV(sbox_sv); if(SvTYPE((SV *)sbox) != SVt_PVAV) { Safefree(RETVAL); croak("S-box sub-argument must be reference to array"); } if(av_len(sbox) != 256 - 1) { Safefree(RETVAL); croak("need exactly 256 entries per S-box"); } for(i = 0; i != 256; i++) { SV **item_p = av_fetch(sbox, i, 0); RETVAL->S[j][i] = SvUV(item_p ? *item_p : &PL_sv_undef); } } OUTPUT: RETVAL Crypt::Eksblowfish::Subkeyed new_initial(SV *classname) CODE: PERL_UNUSED_VAR(classname); Newx(RETVAL, 1, BF_key_schedule); memcpy(RETVAL, &BF_init_state, sizeof(BF_init_state)); OUTPUT: RETVAL MODULE = Crypt::Eksblowfish PACKAGE = Crypt::Eksblowfish Crypt::Eksblowfish new(SV *classname, unsigned cost, SV *salt_sv, SV *key_sv) PREINIT: STRLEN salt_len, key_len; U8 *salt_octets, *key_octets; bool salt_tofree, key_tofree; U8 salt[16]; CODE: PERL_UNUSED_VAR(classname); if(cost > 31) croak("cost parameters greater than 31 are not supported yet"); sv_to_octets(&salt_octets, &salt_len, &salt_tofree, salt_sv); if(salt_len != 16) { if(salt_tofree) Safefree(salt_octets); croak("salt must be exactly sixteen octets long"); } memcpy(salt, salt_octets, 16); if(salt_tofree) Safefree(salt_octets); sv_to_octets(&key_octets, &key_len, &key_tofree, key_sv); if(key_len < 1 || key_len > (BF_N + 2) * 4) { if(key_tofree) Safefree(key_octets); croak("key must be between 1 and %d octets long", (BF_N+2)*4); } Newx(RETVAL, 1, BF_key_schedule); setup_eksblowfish_ks(cost, (unsigned char *)salt, (unsigned char *)key_octets, key_len, RETVAL); if(key_tofree) Safefree(key_octets); OUTPUT: RETVAL MODULE = Crypt::Eksblowfish PACKAGE = Crypt::Eksblowfish::Blowfish Crypt::Eksblowfish::Blowfish new(SV *classname, SV *key_sv) PREINIT: STRLEN key_len; U8 *key_octets; bool key_tofree; CODE: PERL_UNUSED_VAR(classname); sv_to_octets(&key_octets, &key_len, &key_tofree, key_sv); if(key_len < 4 || key_len > 56) { if(key_tofree) Safefree(key_octets); croak("key must be between 4 and 56 octets long"); } Newx(RETVAL, 1, BF_key_schedule); setup_blowfish_ks((unsigned char *)key_octets, key_len, RETVAL); if(key_tofree) Safefree(key_octets); OUTPUT: RETVAL MODULE = Crypt::Eksblowfish PACKAGE = Crypt::Eksblowfish::Uklblowfish Crypt::Eksblowfish::Uklblowfish new(SV *classname, SV *key_sv) PREINIT: STRLEN key_len; U8 *key_octets; bool key_tofree; CODE: PERL_UNUSED_VAR(classname); sv_to_octets(&key_octets, &key_len, &key_tofree, key_sv); if(key_len < 1 || key_len > (BF_N + 2) * 4) { if(key_tofree) Safefree(key_octets); croak("key must be between 1 and %d octets long", (BF_N+2)*4); } Newx(RETVAL, 1, BF_key_schedule); setup_blowfish_ks((unsigned char *)key_octets, key_len, RETVAL); if(key_tofree) Safefree(key_octets); OUTPUT: RETVAL Crypt-Eksblowfish-0.009/lib/Crypt/Eksblowfish000755001750001750 011556073702 21171 5ustar00zeframzefram000000000000Crypt-Eksblowfish-0.009/lib/Crypt/Eksblowfish/Family.pm000444001750001750 1441211556073702 23127 0ustar00zeframzefram000000000000=head1 NAME Crypt::Eksblowfish::Family - Eksblowfish cipher family =head1 SYNOPSIS use Crypt::Eksblowfish::Family; $family = Crypt::Eksblowfish::Family->new_family(8, $salt); $cost = $family->cost; $salt = $family->salt; $block_size = $family->blocksize; $key_size = $family->keysize; $cipher = $family->new($key); =head1 DESCRIPTION An object of this class represents an Eksblowfish cipher family. It contains the family parameters (cost and salt), and if combined with a key it yields an encryption function. See L for discussion of the Eksblowfish algorithm. It is intended that an object of this class can be used in situations such as the "-cipher" parameter to C. Normally that parameter is the name of a class, such as "Crypt::Rijndael", where the class implements a block cipher algorithm. The class provides a C constructor that accepts a key. In the case of Eksblowfish, the key alone is not sufficient. An Eksblowfish family fills the role of block cipher algorithm. Therefore a family object is used in place of a class name, and it is the family object the provides the C constructor. =head2 Crypt::CBC C itself has a problem, with the result that this class can no longer be used with it in the manner originally intended. When this class was originally designed, it worked with C as described above: an object of this class would be accepted by C as a cipher algorithm, and C would happily supply it with a key and encrypt using the resulting cipher object. C didn't realise it was dealing with a family object, however, and there was some risk that a future version might accidentally squash the object into a string, which would be no use. In the course of discussion about regularising the use of cipher family objects, the author of C got hold of the wrong end of the stick, and ended up changing C in a way that totally breaks this usage, rather than putting it on a secure footing. The present behaviour of C is that if an object (rather than a class name) is supplied as the "-cipher" parameter then it has a completely different meaning from usual. In this case, the object supplied is used as the keyed cipher, rather than as a cipher algorithm which must be given a key. This bypasses all of C's usual keying logic, which can hash and salt a passphrase to generate the key. It is arguably a useful feature, but it's a gross abuse of the "-cipher" parameter and a severe impediment to the use of family-keyed cipher algorithms. This class now provides a workaround. For the benefit of C, and any other crypto plumbing that requires a keyable cipher algorithm to look like a Perl class (rather than an object), a family object of this class can in fact be reified as a class of its own. See the method L. =cut package Crypt::Eksblowfish::Family; { use 5.006; } use warnings; use strict; use Carp qw(croak); use Crypt::Eksblowfish 0.005; use Class::Mix 0.001 qw(genpkg); our $VERSION = "0.009"; =head1 CONSTRUCTOR =over =item Crypt::Eksblowfish::Family->new_family(COST, SALT) Creates and returns an object representing the Eksblowfish cipher family specified by the parameters. The SALT is a family key, and must be exactly 16 octets. COST is an integer parameter controlling the expense of keying: the number of operations in key setup is proportional to 2^COST. =cut sub new_family { my($class, $cost, $salt) = @_; return bless({ cost => $cost, salt => $salt }, $class); } =back =head1 METHODS =over =item $family->cost Extracts and returns the cost parameter. =cut sub cost { $_[0]->{cost} } =item $family->salt Extracts and returns the salt parameter. =cut sub salt { $_[0]->{salt} } =item $family->blocksize Returns 8, indicating the Eksblowfish block size of 8 octets. =cut sub blocksize { 8 } =item $family->keysize Returns 0, indicating that the key size is variable. This situation is handled specially by C. =cut sub keysize { 0 } =item $family->new(KEY) Performs key setup on a new instance of the Eksblowfish algorithm, returning the keyed state. The KEY may be any length from 1 octet to 72 octets inclusive. The object returned is of class C; see L for the encryption and decryption methods. Note that this method is called on a family object, not on the class C. =cut sub new { my($self, $key) = @_; croak "Crypt::Eksblowfish::Family::new is not a class method ". "(perhaps you want new_family instead)" if ref($self) eq ""; return Crypt::Eksblowfish->new($self->{cost}, $self->{salt}, $key); } =item $family->encrypt This method nominally exists, to satisfy C. It can't really be used: it doesn't make any sense. =cut sub encrypt { croak "Crypt::Eksblowfish::Family::encrypt called" } =item $family->as_class Generates and returns (the name of) a Perl class that behaves as a keyable cipher algorithm identical to this Eksblowfish cipher family. The same methods that can be called as instance methods on $family can be called as class methods on the generated class. You should prefer to use the family object directly wherever you can. Aside from being a silly indirection, the classes generated by this method cannot be garbage-collected. This method exists only to cater to C, which requires a keyable cipher algorithm to look like a Perl class, and won't operate correctly on one that looks like an object. =cut sub as_class { my($self) = @_; return $self->{as_class} ||= do { my $pkg = genpkg(__PACKAGE__."::"); no strict "refs"; @{"${pkg}::ISA"} = (ref($self)); *{"${pkg}::new_family"} = sub { croak $_[0]."->new_family called" }; *{"${pkg}::cost"} = sub { $self->cost }; *{"${pkg}::salt"} = sub { $self->salt }; *{"${pkg}::new"} = sub { shift; $self->new(@_) }; *{"${pkg}::as_class"} = sub { $pkg }; $pkg; }; } =back =head1 SEE ALSO L, L =head1 AUTHOR Andrew Main (Zefram) =head1 COPYRIGHT Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Andrew Main (Zefram) =head1 LICENSE This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut 1; Crypt-Eksblowfish-0.009/lib/Crypt/Eksblowfish/Bcrypt.pm000444001750001750 1162511556073702 23154 0ustar00zeframzefram000000000000=head1 NAME Crypt::Eksblowfish::Bcrypt - Blowfish-based Unix crypt() password hash =head1 SYNOPSIS use Crypt::Eksblowfish::Bcrypt qw(bcrypt_hash); $hash = bcrypt_hash({ key_nul => 1, cost => 8, salt => $salt, }, $password); use Crypt::Eksblowfish::Bcrypt qw(en_base64 de_base64); $text = en_base64($octets); $octets = de_base64($text); use Crypt::Eksblowfish::Bcrypt qw(bcrypt); $hashed_password = bcrypt($password, $settings); =head1 DESCRIPTION This module implements the Blowfish-based Unix crypt() password hashing algorithm, known as "bcrypt". This hash uses a variant of Blowfish, known as "Eksblowfish", modified to have particularly expensive key scheduling. Eksblowfish and bcrypt were devised by Niels Provos and David Mazieres for OpenBSD. The design is described in a paper at L. =cut package Crypt::Eksblowfish::Bcrypt; { use 5.006; } use warnings; use strict; use Carp qw(croak); use Crypt::Eksblowfish 0.005; use MIME::Base64 2.21 qw(encode_base64 decode_base64); our $VERSION = "0.009"; use parent "Exporter"; our @EXPORT_OK = qw(bcrypt_hash en_base64 de_base64 bcrypt); =head1 FUNCTIONS =over =item bcrypt_hash(SETTINGS, PASSWORD) Hashes PASSWORD according to the supplied SETTINGS, and returns the 23-octet hash. SETTINGS must be a reference to a hash, with these keys: =over =item B Truth value: whether to append a NUL to the password before using it as a key. The algorithm as originally devised does not do this, but it was later modified to do it. The version that does append NUL is to be preferred; not doing so is supported only for backward compatibility. =item B Non-negative integer controlling the cost of the hash function. The number of operations is proportional to 2^cost. =item B Exactly sixteen octets of salt. =back =cut sub bcrypt_hash($$) { my($settings, $password) = @_; $password .= "\0" if $settings->{key_nul} || $password eq ""; my $cipher = Crypt::Eksblowfish->new($settings->{cost}, $settings->{salt}, substr($password, 0, 72)); my $hash = join("", map { my $blk = $_; for(my $i = 64; $i--; ) { $blk = $cipher->encrypt($blk); } $blk; } qw(OrpheanB eholderS cryDoubt)); chop $hash; return $hash; } =item en_base64(BYTES) Encodes the octet string textually using the form of base 64 that is conventionally used with bcrypt. =cut sub en_base64($) { my($octets) = @_; my $text = encode_base64($octets, ""); $text =~ tr#A-Za-z0-9+/=#./A-Za-z0-9#d; return $text; } =item de_base64(TEXT) Decodes an octet string that was textually encoded using the form of base 64 that is conventionally used with bcrypt. =cut sub de_base64($) { my($text) = @_; croak "bad base64 encoding" unless $text =~ m#\A(?>(?:[./A-Za-z0-9]{4})*) (?:|[./A-Za-z0-9]{2}[.CGKOSWaeimquy26]| [./A-Za-z0-9][.Oeu])\z#x; $text =~ tr#./A-Za-z0-9#A-Za-z0-9+/#; $text .= "=" x (3 - (length($text) + 3) % 4); return decode_base64($text); } =item bcrypt(PASSWORD, SETTINGS) This is a version of C (see L) that implements the bcrypt algorithm. It does not implement any other hashing algorithms, so if others are desired then it necessary to examine the algorithm prefix in SETTINGS and dispatch between more than one version of C. SETTINGS must be a string which encodes the algorithm parameters, including salt. It must begin with "$2", optional "a", "$", two digits, "$", and 22 base 64 digits. The rest of the string is ignored. The presence of the optional "a" means that a NUL is to be appended to the password before it is used as a key. The two digits set the cost parameter. The 22 base 64 digits encode the salt. The function will C if SETTINGS does not have this format. The PASSWORD is hashed according to the SETTINGS. The value returned is a string which encodes the algorithm parameters and the hash: the parameters are in the same format required in SETTINGS, and the hash is appended in the form of 31 base 64 digits. This result is suitable to be used as a SETTINGS string for input to this function: the hash part of the string is ignored on input. =cut sub bcrypt($$) { my($password, $settings) = @_; croak "bad bcrypt settings" unless $settings =~ m#\A\$2(a?)\$([0-9]{2})\$ ([./A-Za-z0-9]{22})#x; my($key_nul, $cost, $salt_base64) = ($1, $2, $3); my $hash = bcrypt_hash({ key_nul => $key_nul, cost => $cost, salt => de_base64($salt_base64), }, $password); return "\$2${key_nul}\$${cost}\$${salt_base64}".en_base64($hash); } =back =head1 SEE ALSO L, L =head1 AUTHOR Andrew Main (Zefram) =head1 COPYRIGHT Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Andrew Main (Zefram) =head1 LICENSE This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut 1; Crypt-Eksblowfish-0.009/lib/Crypt/Eksblowfish/Uklblowfish.pm000444001750001750 1314111556073702 24175 0ustar00zeframzefram000000000000=head1 NAME Crypt::Eksblowfish::Uklblowfish - Blowfish cipher with unrestricted key length =head1 SYNOPSIS use Crypt::Eksblowfish::Uklblowfish; $block_size = Crypt::Eksblowfish::Uklblowfish->blocksize; $key_size = Crypt::Eksblowfish::Uklblowfish->keysize; $cipher = Crypt::Eksblowfish::Uklblowfish->new($key); $block_size = $cipher->blocksize; $ciphertext = $cipher->encrypt($plaintext); $plaintext = $cipher->decrypt($ciphertext); $p_array = $cipher->p_array; $s_boxes = $cipher->s_boxes; if($cipher->is_weak) { ... =head1 DESCRIPTION An object of this type encapsulates a keyed instance of the Blowfish block cipher, ready to encrypt and decrypt. However, if you're looking for an implementation of Blowfish you most likely want L. This class differs from the standard Blowfish in that it accepts some keys that Blowfish officially does not permit. Blowfish is a symmetric cipher algorithm designed by Bruce Schneier in 1993. It operates on 64-bit blocks, and takes a variable-length key. Officially the key can vary from 32 bits (4 octets) to 448 bits (56 octets) in increments of 8 bits (1 octet). In fact the algorithm can easily operate on a key of any number of octets from 1 (8 bits) to 72 (576 bits). Some implementations don't enforce the official key length limits, and so for compatibility it is sometimes necessary to handle a Blowfish key of a prohibited length. That is what this class is for. The "Ukl" in the name stands for "unrestricted key length". Using a very short key is generally a bad idea because there aren't very many keys of that length and so it's easy for an attacker to try them all. The official 32-bit minimum for Blowfish was already far too short for serious security at the time that Blowfish was designed. (A machine to crack 56-bit DES keys by brute force in a few days each was publicly built only five years later.) Do not base your security on the secrecy of a short key. Using overlong keys has more interesting effects, which depend on internal features of Blowfish. When the key exceeds 64 octets (512 bits), varying key bits past that length results in subkeys which have predictable relationships. There is also some possibility of equivalent keys when the keys exceed 64 octets and differ only in the first 8 octets (64 bits). These phenomena have not been extensively studied in the open literature, so it is difficult to judge the degree of cryptographic weakness that results from them. It is clear that beyond some length Blowfish keys do not have as much strength as their length would suggest, and it is possible that overlong keys have specific weaknesses that render them weaker than shorter keys. If choosing a key for security, it is advised to stay within the official length limit of 56 octets. In summary: using Blowfish keys of officially-unsupported lengths causes security problems. If you are using Blowfish for security, and have the choice, use a key of an officially-supported length (and a standard implementation such as L). Use out-of-range key lengths (and this class) only for compatibility or cryptanalytic reasons. =cut package Crypt::Eksblowfish::Uklblowfish; { use 5.006; } use warnings; use strict; our $VERSION = "0.009"; use parent "Crypt::Eksblowfish::Subkeyed"; die "mismatched versions of Crypt::Eksblowfish modules" unless $Crypt::Eksblowfish::Subkeyed::VERSION eq $VERSION; =head1 CLASS METHODS =over =item Crypt::Eksblowfish::Uklblowfish->blocksize Returns 8, indicating the Blowfish block size of 8 octets. This method may be called on either the class or an instance. =item Crypt::Eksblowfish::Uklblowfish->keysize Returns 0, indicating that the key size is variable. This situation is handled specially by C. =back =cut sub keysize { 0 } =head1 CONSTRUCTOR =over =item Crypt::Eksblowfish::Uklblowfish->new(KEY) Performs key setup on a new instance of the Blowfish algorithm, returning the keyed state. The KEY may be any length from 1 octet to 72 octets inclusive. =back =head1 METHODS =over =item $cipher->blocksize Returns 8, indicating the Blowfish block size of 8 octets. This method may be called on either the class or an instance. =item $cipher->encrypt(PLAINTEXT) PLAINTEXT must be exactly eight octets. The block is encrypted, and the ciphertext is returned. =item $cipher->decrypt(CIPHERTEXT) CIPHERTEXT must be exactly eight octets. The block is decrypted, and the plaintext is returned. =item $cipher->p_array =item $cipher->s_boxes These methods extract the subkeys from the keyed cipher. This is not required in ordinary operation. See the superclass L for details. =item $cipher->is_weak This method checks whether the cipher has been keyed with a weak key. It may be desired to avoid using weak keys. See the superclass L for details. This method does not detect any cryptographic weaknesses that might result from the related-key properties and other features of overlong keys. =back =head1 SEE ALSO L =head1 AUTHOR Eksblowfish guts originally by Solar Designer (solar at openwall.com). Modifications and Perl interface by Andrew Main (Zefram) . =head1 COPYRIGHT Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Andrew Main (Zefram) The original Eksblowfish code (in the form of crypt()) from which this module is derived is in the public domain. It may be found at L. =head1 LICENSE This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut 1; Crypt-Eksblowfish-0.009/lib/Crypt/Eksblowfish/Blowfish.pm000444001750001750 773511556073702 23455 0ustar00zeframzefram000000000000=head1 NAME Crypt::Eksblowfish::Blowfish - Blowfish block cipher via Eksblowfish engine =head1 SYNOPSIS use Crypt::Eksblowfish::Blowfish; $block_size = Crypt::Eksblowfish::Blowfish->blocksize; $key_size = Crypt::Eksblowfish::Blowfish->keysize; $cipher = Crypt::Eksblowfish::Blowfish->new($key); $block_size = $cipher->blocksize; $ciphertext = $cipher->encrypt($plaintext); $plaintext = $cipher->decrypt($ciphertext); $p_array = $cipher->p_array; $s_boxes = $cipher->s_boxes; if($cipher->is_weak) { ... =head1 DESCRIPTION An object of this type encapsulates a keyed instance of the Blowfish block cipher, ready to encrypt and decrypt. Blowfish is a symmetric cipher algorithm designed by Bruce Schneier in 1993. It operates on 64-bit blocks, and takes a variable-length key from 32 bits (4 octets) to 448 bits (56 octets) in increments of 8 bits (1 octet). This implementation of Blowfish uses an encryption engine that was originally implemented in order to support Eksblowfish, which is a variant of Blowfish modified to make keying particularly expensive. See L for that variant; this class implements the original Blowfish. =cut package Crypt::Eksblowfish::Blowfish; { use 5.006; } use warnings; use strict; our $VERSION = "0.009"; use parent "Crypt::Eksblowfish::Subkeyed"; die "mismatched versions of Crypt::Eksblowfish modules" unless $Crypt::Eksblowfish::Subkeyed::VERSION eq $VERSION; =head1 CLASS METHODS =over =item Crypt::Eksblowfish::Blowfish->blocksize Returns 8, indicating the Blowfish block size of 8 octets. This method may be called on either the class or an instance. =item Crypt::Eksblowfish::Blowfish->keysize Returns 0, indicating that the key size is variable. This situation is handled specially by C. =back =cut sub keysize { 0 } =head1 CONSTRUCTOR =over =item Crypt::Eksblowfish::Blowfish->new(KEY) Performs key setup on a new instance of the Blowfish algorithm, returning the keyed state. The KEY may be any length from 4 octets to 56 octets inclusive. You may occasionally come across an alleged Blowfish key that is outside this length range, and so is rejected by this constructor. Blowfish can internally process a key of any octet length up to 72 octets, and some implementations don't enforce the official length restrictions. If it is necessary for compatibility, a key of out-of-range length can be processed by L. =back =head1 METHODS =over =item $cipher->blocksize Returns 8, indicating the Blowfish block size of 8 octets. This method may be called on either the class or an instance. =item $cipher->encrypt(PLAINTEXT) PLAINTEXT must be exactly eight octets. The block is encrypted, and the ciphertext is returned. =item $cipher->decrypt(CIPHERTEXT) CIPHERTEXT must be exactly eight octets. The block is decrypted, and the plaintext is returned. =item $cipher->p_array =item $cipher->s_boxes These methods extract the subkeys from the keyed cipher. This is not required in ordinary operation. See the superclass L for details. =item $cipher->is_weak This method checks whether the cipher has been keyed with a weak key. It may be desired to avoid using weak keys. See the superclass L for details. =back =head1 SEE ALSO L, L, L, L =head1 AUTHOR Eksblowfish guts originally by Solar Designer (solar at openwall.com). Modifications and Perl interface by Andrew Main (Zefram) . =head1 COPYRIGHT Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Andrew Main (Zefram) The original Eksblowfish code (in the form of crypt()) from which this module is derived is in the public domain. It may be found at L. =head1 LICENSE This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut 1; Crypt-Eksblowfish-0.009/lib/Crypt/Eksblowfish/Subkeyed.pm000444001750001750 1542711556073702 23470 0ustar00zeframzefram000000000000=head1 NAME Crypt::Eksblowfish::Subkeyed - Blowfish/Eksblowfish with access to subkeys =head1 SYNOPSIS use Crypt::Eksblowfish::Subkeyed; $block_size = Crypt::Eksblowfish::Subkeyed->blocksize; $cipher = Crypt::Eksblowfish::Subkeyed ->new_from_subkeys(\@p_array, \@s_boxes); $cipher = Crypt::Eksblowfish::Subkeyed->new_initial; $block_size = $cipher->blocksize; $ciphertext = $cipher->encrypt($plaintext); $plaintext = $cipher->decrypt($ciphertext); $p_array = $cipher->p_array; $s_boxes = $cipher->s_boxes; if($cipher->is_weak) { ... =head1 DESCRIPTION An object of this class encapsulates a keyed instance of the Blowfish or Eksblowfish block cipher, ready to encrypt and decrypt. Normally this class will not be used directly, but through subclasses such as L. Eksblowfish is a variant of the Blowfish cipher with a modified key setup algorithm. This class doesn't implement either form of key setup, but only provides the actual encryption and decryption parts of the ciphers. This part is shared between Blowfish and Eksblowfish, and also any other cipher that uses the core of Blowfish but supplies its own key setup. This class has "Eksblowfish" in its name rather than "Blowfish" merely due to the historical accident that it is derived from the encryption engine that was used to implement Eksblowfish. The key setup phase of a block cipher, also known as the "key schedule", produces a set of "subkeys", which are somewhat like ordinary cryptographic keys (which are the input to the key setup algorithm) but are much larger. In some block ciphers the subkeys also have special interrelationships. In Blowfish the subkeys consist of a "P-array" of 18 32-bit entries (one per encryption round plus two more) and four "S-boxes" ("S" is for "substitution") each of which consists of 256 32-bit entries. There is no special relationship between the values of the subkeys. Methods in this class allow a cipher object to be constructed from a full set of subkeys, and for the subkeys to be extracted from a cipher object. Normal users don't need to do either of these things. It's mainly useful when devising a new key schedule to stick onto the Blowfish core, or when performing cryptanalysis of the cipher algorithm. Generating subkeys directly by a strong random process, rather than by expansion of a smaller random key, is an expensive and slightly bizarre way to get greater cryptographic strength from a cipher algorithm. It eliminates attacks on the key schedule, and yields the full strength of the core algorithm. However, this is always a lot less strength than the amount of subkey material, whereas a normal key schedule is designed to yield strength equal to the length of the (much shorter) key. Also, any non-randomness in the source of the subkey material is likely to lead to a cryptographic weakness, whereas a key schedule conceals any non-randomness in the choice of the key. =cut package Crypt::Eksblowfish::Subkeyed; { use 5.006; } use warnings; use strict; use XSLoader; our $VERSION = "0.009"; XSLoader::load("Crypt::Eksblowfish", $VERSION); =head1 CLASS METHODS =over =item Crypt::Eksblowfish::Subkeyed->blocksize Returns 8, indicating the Eksblowfish block size of 8 octets. This method may be called on either the class or an instance. =back =head1 CONSTRUCTOR =over =item Crypt::Eksblowfish::Subkeyed->new_from_subkeys(ROUND_KEYS, SBOXES) Creates a new Blowfish cipher object encapsulating the supplied subkeys. ROUND_KEYS must be a reference to an array of 18 32-bit integers. SBOXES must be a reference to an array of four references to 256-element arrays of 32-bit integers. These subkeys are used in the standard order for Blowfish. =item Crypt::Eksblowfish::Subkeyed->new_initial The standard Blowfish key schedule is an iterative process, which uses the cipher algorithm to progressively replace subkeys, thus mutating the cipher for subsequent iterations of keying. The Eksblowfish key schedule works similarly, but with a lot more iterations. In both cases, the key setup algorithm begins with a standard set of subkeys, consisting of the initial bits of the fractional part of pi. This constructor creates and returns a Blowfish block cipher object with that standard initial set of subkeys. This is probably useful only to designers of novel key schedules. =back =head1 METHODS =over =item $cipher->blocksize Returns 8, indicating the Eksblowfish block size of 8 octets. This method may be called on either the class or an instance. =item $cipher->encrypt(PLAINTEXT) PLAINTEXT must be exactly eight octets. The block is encrypted, and the ciphertext is returned. =item $cipher->decrypt(CIPHERTEXT) CIPHERTEXT must be exactly eight octets. The block is decrypted, and the plaintext is returned. =item $cipher->p_array Returns a reference to an 18-element array containing the 32-bit round keys used in this cipher object. =item $cipher->s_boxes Returns a reference to a 4-element array containing the S-boxes used in this cipher object. Each S-box is a 256-element array of 32-bit entries. =item $cipher->is_weak Returns a truth value indicating whether this is a weak key. A key is considered weak if any S-box contains a pair of identical entries (in any positions). When Blowfish is used with such an S-box, certain cryptographic attacks are possible that are not possible against most keys. The current (as of 2007) cryptanalytic results on Blowfish do not include an actual break of the algorithm when weak keys are used, but if a break is ever developed then it is likely to be achieved for weak keys before it is achieved for the general case. About one key in every 2^15 is weak (if the keys are randomly selected). Because of the complicated key schedule in standard Blowfish it is not possible to predict which keys will be weak without first performing the full key setup, which is why this is a method on the keyed cipher object. In some uses of Blowfish it may be desired to avoid weak keys; if so, check using this method and generate a new random key when a weak key is detected. Bruce Schneier, the designer of Blowfish, says it is probably not worth avoiding weak keys. =back =head1 SEE ALSO L, L, L =head1 AUTHOR Eksblowfish guts originally by Solar Designer (solar at openwall.com). Modifications and Perl interface by Andrew Main (Zefram) . =head1 COPYRIGHT Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Andrew Main (Zefram) The original Eksblowfish code (in the form of crypt()) from which this module is derived is in the public domain. It may be found at L. =head1 LICENSE This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut 1; Crypt-Eksblowfish-0.009/t000755001750001750 011556073702 15305 5ustar00zeframzefram000000000000Crypt-Eksblowfish-0.009/t/bcrypt_hash.t000444001750001750 73311556073702 20120 0ustar00zeframzefram000000000000use warnings; use strict; use Test::More tests => 3; BEGIN { use_ok "Crypt::Eksblowfish::Bcrypt", qw(bcrypt_hash); } is bcrypt_hash({ key_nul => 0, cost => 5, salt => "abcdefghijklmnop" }, "supercalifragilisticexpialidocious"), pack("H*", "1e514c325869b8c311f852ffe630bac51519a66409ed77"); is bcrypt_hash({ key_nul => 1, cost => 6, salt => "ABCDEFGHIJKLMNOP" }, "Libelar! Timmah!"), pack("H*", "2b7453cbc43bc27cb59c1a1a2ce520d79557f7a1a17b9b"); 1; Crypt-Eksblowfish-0.009/t/bcrypt.t000444001750001750 310311556073702 17127 0ustar00zeframzefram000000000000use warnings; use strict; use Test::More tests => 69; BEGIN { use_ok "Crypt::Eksblowfish::Bcrypt", qw(bcrypt); } my @wrong_passwords = qw(foo quux supercalifragilisticexpialidocious); while() { chomp; s/([^ ]+) ([^ ]+) *//; my($settings, $hash) = ($1, $2); is bcrypt($_, $settings), $settings.$hash; isnt bcrypt($_, $settings), $settings.$hash foreach (@wrong_passwords); } 1; __DATA__ $2$05$CCCCCCCCCCCCCCCCCCCCC. 7uG0VCzI2bS7j6ymqJi9CdcdxiRTWNy $2$07$aba.............kC2SI. cbHK1ODT5F77pYUqRNV63bd/IDxsTXq 0 $2$07$abcdee..........kC2SI. HiVB5Ax/RkxnDF2P5lQk06NBgbF/xYO 0 $2$07$abcdefghijklmnopkC2SI. 7Q0nVrcMF4umRv5Pk5vDi0GlDI.lLE. 0 $2$07$abcdefghijklmnopqrstuu AgtOGDu2Z1DC3oOn6HzhbBE811IGUYu 0 $2$07$abcdefghijklmnopkC2SI. SY5XUDcstCvd.D7IsnwxqkBQmKD548W password $2$04$abcdefghijklmnopkC2SI. q7Yf61ne/f5tu69iU.SIM68gT3LAaYy password $2$10$abcdefghijklmnopkC2SI. /wsXFeTOFgHVzDjpY2cn9yyF85o0khS password $2$04$...................... Ns4TWVMFumL/LG8wa/FMbZnvNs.EDBi password $2$05$...................... bvpG2UfzdyW/S0ny/4YyEZrmczoJfVm password $2$06$...................... h9TvqYVBoV1csDZEfDS/qeQHryfT7dm password $2$07$...................... A.nYdZ8J7ihz9grv6aPNwWdqpEgHssm password $2a$05$CCCCCCCCCCCCCCCCCCCCC. E5YPO9kmyuRGyh0XouQYb4YMJKvyOeW U*U $2a$05$CCCCCCCCCCCCCCCCCCCCC. VGOzA784oUp/Z0DY336zx7pLYAy0lwK U*U* $2a$05$XXXXXXXXXXXXXXXXXXXXXO AcXxm9kjPGEMsLznoKqmqw7tc8WCx4a U*U*U $2a$05$CCCCCCCCCCCCCCCCCCCCC. 7uG0VCzI2bS7j6ymqJi9CdcdxiRTWNy $2a$05$abcdefghijklmnopqrstuu 5s2v8.iXieOjg/.AySBTTZIIVFJeBui 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 Crypt-Eksblowfish-0.009/t/eksblowfish.t000444001750001750 402511556073702 20150 0ustar00zeframzefram000000000000use warnings; use strict; use Test::More tests => 12 + 6*11; BEGIN { use_ok "Crypt::Eksblowfish"; } is(Crypt::Eksblowfish->blocksize, 8); eval { Crypt::Eksblowfish->new(-1, "a" x 16, "abcd") }; isnt $@, ""; eval { Crypt::Eksblowfish->new(0, "a" x 15, "abcd") }; isnt $@, ""; eval { Crypt::Eksblowfish->new(0, "a" x 17, "abcd") }; isnt $@, ""; eval { Crypt::Eksblowfish->new(0, "a" x 16, "") }; isnt $@, ""; eval { Crypt::Eksblowfish->new(0, "a" x 16, "a") }; is $@, ""; eval { Crypt::Eksblowfish->new(0, "a" x 16, "a" x 72) }; is $@, ""; eval { Crypt::Eksblowfish->new(0, "a" x 16, "a" x 73) }; isnt $@, ""; my $cipher = Crypt::Eksblowfish->new(0, "a" x 16, "abcd"); ok $cipher; is $cipher->p_array->[2], 0x7653a00a; is $cipher->s_boxes->[2]->[222], 0xee8053dc; while() { my($cost, @data) = split; my($salt, $pt, $ct, $key) = map { pack("H*", $_) } @data; my $cipher = Crypt::Eksblowfish->new($cost, $salt, $key); ok $cipher; is ref($cipher), "Crypt::Eksblowfish"; is $cipher->blocksize, 8; is $cipher->encrypt($pt), $ct; is $cipher->decrypt($ct), $pt; is !!$cipher->is_weak, $key eq pack("H*", "67df71d0acdcbef5"); } 1; __DATA__ 0 77b5a8e66bf437f3d03cc6b4cdc7d429 5bb0131eefeb17f7 3f6fdaddcd605c01 13ffc413d7ed649a8551 1 cfd2fe88ead6a5a8dca9523889081f39 ea936213788e916d 0999967ad37fcca1 af5d 2 31188a1d6e1d65b3f71b86bce55a67f4 90ee362f71522361 8217921bcf1deaa3 c8931a6e0efb32937b68 3 d2f0d334b90b356d592c3019ec8eca71 071147d03942894d 2343bba87456e218 0e8c8f04c67af0b2c348 4 9727d95b6d12343ef1411edc0a6ebf1d 59d4a5de34d29cb6 427895b5c7743cf8 e1278612 5 171125170554d7bd6e712fdcc549c00d cb78660a68b67ab9 dfd346f724ddb9c7 0527bb76250e8e606129 6 4b3916adb70a841658aaf4ec7ebb51e8 7ba6a4ca4d6bcc29 325ac35c6b7eb748 7bda 7 d05f3e37e0abb779485cb0c42d4898b2 9fade3ceb8780bdb 38b574199128a028 0365bd0af501 8 e1aedf7b96277f44bf7ee57abe2ad0c4 099845e9998a5d66 ccbdfdd5dd8243eb 3c2dae71 9 0bc4788fa499faac1e54e6c8d3c492d8 bffb573ea1a50827 b663a0daeaf7db86 32711230b5b1ce 0 632883779720f1b6a8cb65f9526e638f e1b46bade19d63d5 597cde1ed988cc79 67df71d0acdcbef5 Crypt-Eksblowfish-0.009/t/family.t000444001750001750 414411556073702 17113 0ustar00zeframzefram000000000000use warnings; use strict; use Test::More tests => 2 + 26*10; BEGIN { use_ok "Crypt::Eksblowfish::Family"; } eval { "Crypt::Eksblowfish::Family"->new("a"x16) }; like $@, qr/Crypt::Eksblowfish::Family::new is not a class method/; while() { my($cost, @data) = split; my($salt, $pt, $ct, $key) = map { pack("H*", $_) } @data; my $family = Crypt::Eksblowfish::Family->new_family($cost, $salt); ok $family; ok $family->can("keysize"); ok $family->can("encrypt"); is $family->cost, $cost; is $family->salt, $salt; is $family->blocksize, 8; is $family->keysize, 0; eval { $family->encrypt($pt) }; like $@, qr/\ACrypt::Eksblowfish::Family::encrypt called/; my $cipher = $family->new($key); ok $cipher; is $cipher->blocksize, 8; is $cipher->encrypt($pt), $ct; is $cipher->decrypt($ct), $pt; my $pkg = $family->as_class; like $pkg, qr/\ACrypt::Eksblowfish::Family::/; is $pkg, $family->as_class; eval { $pkg->new_family($cost, $salt) }; like $@, qr/\A${pkg}->new_family called/; ok $pkg->can("keysize"); ok $pkg->can("encrypt"); is $pkg->cost, $cost; is $pkg->salt, $salt; is $pkg->blocksize, 8; is $pkg->keysize, 0; $cipher = $pkg->new($key); ok $cipher; is $cipher->blocksize, 8; is $cipher->encrypt($pt), $ct; is $cipher->decrypt($ct), $pt; is $pkg->as_class, $pkg; } 1; __DATA__ 0 77b5a8e66bf437f3d03cc6b4cdc7d429 5bb0131eefeb17f7 3f6fdaddcd605c01 13ffc413d7ed649a8551 1 cfd2fe88ead6a5a8dca9523889081f39 ea936213788e916d 0999967ad37fcca1 af5d 2 31188a1d6e1d65b3f71b86bce55a67f4 90ee362f71522361 8217921bcf1deaa3 c8931a6e0efb32937b68 3 d2f0d334b90b356d592c3019ec8eca71 071147d03942894d 2343bba87456e218 0e8c8f04c67af0b2c348 4 9727d95b6d12343ef1411edc0a6ebf1d 59d4a5de34d29cb6 427895b5c7743cf8 e1278612 5 171125170554d7bd6e712fdcc549c00d cb78660a68b67ab9 dfd346f724ddb9c7 0527bb76250e8e606129 6 4b3916adb70a841658aaf4ec7ebb51e8 7ba6a4ca4d6bcc29 325ac35c6b7eb748 7bda 7 d05f3e37e0abb779485cb0c42d4898b2 9fade3ceb8780bdb 38b574199128a028 0365bd0af501 8 e1aedf7b96277f44bf7ee57abe2ad0c4 099845e9998a5d66 ccbdfdd5dd8243eb 3c2dae71 9 0bc4788fa499faac1e54e6c8d3c492d8 bffb573ea1a50827 b663a0daeaf7db86 32711230b5b1ce Crypt-Eksblowfish-0.009/t/base64.t000444001750001750 245111556073702 16715 0ustar00zeframzefram000000000000use warnings; use strict; use Test::More tests => 49; BEGIN { use_ok "Crypt::Eksblowfish::Bcrypt", qw(en_base64 de_base64); } is en_base64(""), ""; is de_base64(""), ""; while() { my($hex, $base64) = (/([^ \n]+) ([^ \n]+)/); my $bytes = pack("H*", $hex); is en_base64($bytes), $base64; is de_base64($base64), $bytes; } 1; __DATA__ 25 HO 6b11 YvC 54e019 TM.X b7f42420 r9OiG. ee98fbf36c 5nh560u fc4f0a3d7822 9C6INVeg 724b0d7bd5aeda aiqLc7Us0e e4580effb833ab56 3DeM95exozW 67f8868799d147cb86 X9gEf3lPP6sE 695e827fb15247956d57 YT4Ad5DQP3TrTu a3339ba92b27fd07c286c9 mxMZoQql9OdAfqi ae1fa7c6e2907627516dfc8e pf8lvsIObgbPZdwM aaab0dcc66982daa236e7dacae ooqLxEYWJYmhZl0qpe 71c57d5a841b24dd8caae0c6e3d1 aaT7UmOZHL0KosBE27C b96da52272a5b5a4fd1b55ac943cc1 sU0jGlIjrYR7EzUqjBx/ 21c4142be6baddf2b47bee16ae7bf273 GaOSI8Y41dIyc82Upltwau 003ff4216a5843f59e7345bde105881b94 .B9yGUnWO9UcayU72OUGE3O 89c4461e18e325d61acc842cb11191132d61 gaPEFfhhHbWYxGOqqPEPCwzf 2b3794afc652601592033f366434a6f0c96dfa IxcSp6XQW/UQ.x60XBQk6Kjr8e 4e22dc36a3d66f141b56b626723b23a13f6f2faa RgJaLoNUZvOZTpWkahqhmR7tJ4m 18426b5e6bff02889c7fcbb5b70e9cdb5a26792a6d ECHpVkt9.mgad6szru4a0zmkcQnr 4c3c8d04abf2b19cbcb533e124f30a696cccecf5d421 RBwL/ItwqXw6rRNfHNKIYUxK5NVSGO e12a5202eb8a40855fbadb131e949bb95554e99c879cbf 2QnQ.ssIOGTdsrqRFnQZsTTS4XwFlJ6 Crypt-Eksblowfish-0.009/t/pod_cvg.t000444001750001750 27311556073702 17232 0ustar00zeframzefram000000000000use warnings; use strict; use Test::More; plan skip_all => "Test::Pod::Coverage not available" unless eval "use Test::Pod::Coverage; 1"; Test::Pod::Coverage::all_pod_coverage_ok(); 1; Crypt-Eksblowfish-0.009/t/uklblowfish.t000444001750001750 1074611556073702 20210 0ustar00zeframzefram000000000000use warnings; use strict; use Test::More tests => 10 + 6*61; BEGIN { use_ok "Crypt::Eksblowfish::Uklblowfish"; } is(Crypt::Eksblowfish::Uklblowfish->blocksize, 8); is(Crypt::Eksblowfish::Uklblowfish->keysize, 0); eval { Crypt::Eksblowfish::Uklblowfish->new("") }; isnt $@, ""; eval { Crypt::Eksblowfish::Uklblowfish->new("a") }; is $@, ""; eval { Crypt::Eksblowfish::Uklblowfish->new("a" x 72) }; is $@, ""; eval { Crypt::Eksblowfish::Uklblowfish->new("a" x 73) }; isnt $@, ""; my $cipher = Crypt::Eksblowfish::Uklblowfish->new("abcd"); ok $cipher; is $cipher->p_array->[2], 0x5802cc0b; is $cipher->s_boxes->[2]->[222], 0xbcd61854; while() { my($pt, $ct, $key) = map { pack("H*", $_) } split; my $cipher = Crypt::Eksblowfish::Uklblowfish->new($key); ok $cipher; is ref($cipher), "Crypt::Eksblowfish::Uklblowfish"; is $cipher->blocksize, 8; is $cipher->encrypt($pt), $ct; is $cipher->decrypt($ct), $pt; is !!$cipher->is_weak, $key eq pack("H*", "88b824049795f021"); } 1; __DATA__ 0000000000000000 4ef997456198dd78 0000000000000000 ffffffffffffffff 51866fd5b85ecb8a ffffffffffffffff 1000000000000001 7d856f9a613063f2 3000000000000000 1111111111111111 2466dd878b963c9d 1111111111111111 1111111111111111 61f9c3802281b096 0123456789abcdef 0123456789abcdef 7d0cc630afda1ec7 1111111111111111 0000000000000000 4ef997456198dd78 0000000000000000 0123456789abcdef 0aceab0fc6a0a28d fedcba9876543210 01a1d6d039776742 59c68245eb05282b 7ca110454a1a6e57 5cd54ca83def57da b1b8cc0b250f09a0 0131d9619dc1376e 0248d43806f67172 1730e5778bea1da4 07a1133e4a0b2686 51454b582ddf440a a25e7856cf2651eb 3849674c2602319e 42fd443059577fa2 353882b109ce8f1a 04b915ba43feb5b6 059b5e0851cf143a 48f4d0884c379918 0113b970fd34f2ce 0756d8e0774761d2 432193b78951fc98 0170f175468fb5e6 762514b829bf486a 13f04154d69d1ae5 43297fad38e373fe 3bdd119049372802 2eedda93ffd39c79 07a7137045da2a16 26955f6835af609a d887e0393c2da6e3 04689104c2fd3b2f 164d5e404f275232 5f99d04f5b163969 37d06bb516cb7546 6b056e18759f5cca 4a057a3b24d3977b 1f08260d1ac2465e 004bd6ef09176062 452031c1e4fada8e 584023641aba6176 480d39006ee762f2 7555ae39f59b87bd 025816164629b007 437540c8698f3cfa 53c55f9cb49fc019 49793ebc79b3258f 072d43a077075292 7a8e7bfa937e89a3 4fb05e1515ab73a7 02fe55778117f12a cf9c5d7a4986adb5 49e95d6d4ca229bf 1d9d5c5018f728c2 d1abb290658bc778 018310dc409b26d6 305532286d6f295a 55cb3774d13ef201 1c587f1c13924fef 0123456789abcdef fa34ec4847b268b2 0101010101010101 0123456789abcdef a790795108ea3cae 1f1f1f1f0e0e0e0e 0123456789abcdef c39e072d9fac631d e0fee0fef1fef1fe ffffffffffffffff 014933e0cdaff6e4 0000000000000000 0000000000000000 f21e9a77b71c49bc ffffffffffffffff 0000000000000000 245946885754369a 0123456789abcdef ffffffffffffffff 6b5c5a9c5d9e0a5a fedcba9876543210 fedcba9876543210 f9ad597c49db005e f0 fedcba9876543210 e91d21c1d961a6d6 f0e1 fedcba9876543210 e9c2b70a1bc65cf3 f0e1d2 fedcba9876543210 be1e639408640f05 f0e1d2c3 fedcba9876543210 b39e44481bdb1e6e f0e1d2c3b4 fedcba9876543210 9457aa83b1928c0d f0e1d2c3b4a5 fedcba9876543210 8bb77032f960629d f0e1d2c3b4a596 fedcba9876543210 e87a244e2cc85e82 f0e1d2c3b4a59687 fedcba9876543210 15750e7a4f4ec577 f0e1d2c3b4a5968778 fedcba9876543210 122ba70b3ab64ae0 f0e1d2c3b4a596877869 fedcba9876543210 3a833c9affc537f6 f0e1d2c3b4a5968778695a fedcba9876543210 9409da87a90f6bf2 f0e1d2c3b4a5968778695a4b fedcba9876543210 884f80625060b8b4 f0e1d2c3b4a5968778695a4b3c fedcba9876543210 1f85031c19e11968 f0e1d2c3b4a5968778695a4b3c2d fedcba9876543210 79d9373a714ca34f f0e1d2c3b4a5968778695a4b3c2d1e fedcba9876543210 93142887ee3be15c f0e1d2c3b4a5968778695a4b3c2d1e0f fedcba9876543210 03429e838ce2d14b f0e1d2c3b4a5968778695a4b3c2d1e0f00 fedcba9876543210 a4299e27469ff67b f0e1d2c3b4a5968778695a4b3c2d1e0f0011 fedcba9876543210 afd5aed1c1bc96a8 f0e1d2c3b4a5968778695a4b3c2d1e0f001122 fedcba9876543210 10851c0e3858da9f f0e1d2c3b4a5968778695a4b3c2d1e0f00112233 fedcba9876543210 e6f51ed79b9db21f f0e1d2c3b4a5968778695a4b3c2d1e0f0011223344 fedcba9876543210 64a6e14afd36b46f f0e1d2c3b4a5968778695a4b3c2d1e0f001122334455 fedcba9876543210 80c7d7d45a5479ad f0e1d2c3b4a5968778695a4b3c2d1e0f00112233445566 fedcba9876543210 05044b62fa52d080 f0e1d2c3b4a5968778695a4b3c2d1e0f0011223344556677 fedcba9876543210 0fad02a8076bf102 f0e1d2c3b4a5968778695a4b3c2d1e0f00112233445566778899aabbccddeeff000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20212223242526 fedcba9876543210 082da95ef6e4b2f7 f0e1d2c3b4a5968778695a4b3c2d1e0f00112233445566778899aabbccddeeff000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f2021222324252627 ad9e7ebf6cdd5bce 681617e03bca6fe2 88b824049795f021 Crypt-Eksblowfish-0.009/t/subkey.t000444001750001750 527111556073702 17136 0ustar00zeframzefram000000000000use warnings; use strict; use Test::More tests => 42 + 6*10; BEGIN { use_ok "Crypt::Eksblowfish::Subkeyed"; } is(Crypt::Eksblowfish::Subkeyed->blocksize, 8); my $init = Crypt::Eksblowfish::Subkeyed->new_initial; ok $init; is ref($init), "Crypt::Eksblowfish::Subkeyed"; is $init->blocksize, 8; my $pa = $init->p_array; is ref($pa), "ARRAY"; is scalar(@$pa), 18; is $pa->[0], 0x243f6a88; is $pa->[17], 0x8979fb1b; my $sb = $init->s_boxes; is ref($sb), "ARRAY"; is scalar(@$sb), 4; for(my $i = 4; $i--; ) { is ref($sb->[$i]), "ARRAY"; is scalar(@{$sb->[$i]}), 256; } is $sb->[0]->[0], 0xd1310ba6; is $sb->[3]->[255], 0x3ac372e6; ok !$init->is_weak; eval { Crypt::Eksblowfish::Subkeyed->new_from_subkeys(3, $sb); }; isnt $@, ""; eval { Crypt::Eksblowfish::Subkeyed->new_from_subkeys([], $sb); }; isnt $@, ""; eval { Crypt::Eksblowfish::Subkeyed->new_from_subkeys($pa, []); }; isnt $@, ""; eval { Crypt::Eksblowfish::Subkeyed->new_from_subkeys($pa, [@{$sb}[0..2],3]); }; isnt $@, ""; eval { Crypt::Eksblowfish::Subkeyed->new_from_subkeys($pa, [@{$sb}[0..2],[]]); }; isnt $@, ""; my $cinit = Crypt::Eksblowfish::Subkeyed->new_from_subkeys($pa, $sb); ok $cinit; is ref($cinit), "Crypt::Eksblowfish::Subkeyed"; is $cinit->blocksize, 8; is_deeply $cinit->p_array, $pa; is_deeply $cinit->s_boxes, $sb; ok !$cinit->is_weak; $pa = [ reverse(@$pa) ]; $sb = [ map { [ reverse(@$_) ] } @$sb ]; my $tcipher = Crypt::Eksblowfish::Subkeyed->new_from_subkeys($pa, $sb); ok $tcipher; is ref($tcipher), "Crypt::Eksblowfish::Subkeyed"; is $tcipher->blocksize, 8; is_deeply $tcipher->p_array, $pa; is_deeply $tcipher->s_boxes, $sb; ok !$tcipher->is_weak; ok !Crypt::Eksblowfish::Subkeyed->new_from_subkeys([ @{$pa}[0..5,9,7..17] ], $sb)->is_weak; ok !Crypt::Eksblowfish::Subkeyed->new_from_subkeys($pa, [ @{$sb}[0,0,0,0] ])->is_weak; ok !!Crypt::Eksblowfish::Subkeyed->new_from_subkeys($pa, [ $sb->[0], [ @{$sb->[1]}[0..5,9,7..255] ], @{$sb}[1,2] ])->is_weak; while() { my($pt, $ict, $tct) = map { pack("H*", $_) } split; is $init->encrypt($pt), $ict; is $init->decrypt($ict), $pt; is $cinit->encrypt($pt), $ict; is $cinit->decrypt($ict), $pt; is $tcipher->encrypt($pt), $tct; is $tcipher->decrypt($tct), $pt; } 1; __DATA__ c2e05cec152b7f84 e7ae62039464d1a3 95360a60c9d8ae55 8f2a4b8beb786d34 b268b3c6cd763b9b 1cbfcb33912e6aad 08953ae2bc9b6fac 85f97065bb2cfb95 fde450df89601c8f e146d6f4593bb6d4 4bb9b1a1cd6d3519 08ee35abde632849 ea95a8d87f8b3707 b81b2bc161d4858f eed42049b4473cd3 754f65df7612b623 be6858951aaa5b8e 667e2ef6e618fa09 189b7138fbe47050 599861bf55e807d7 e5245a3ad5f1927e c4d8aa6c8f89d566 eaedc699152cb8bd ce615d5dde70b9db 17360076b8aa87d8 fcc844ffa2cb9a39 cac0835a83c7dcc6 837397193cd28b9f f6ac385258e1d151 e08588070546c327 Crypt-Eksblowfish-0.009/t/utf8.t000444001750001750 243711556073702 16523 0ustar00zeframzefram000000000000use warnings; use strict; use Test::More tests => 8; BEGIN { use_ok "Crypt::Eksblowfish"; } my $tstr = "abcdefgh\xaa1234567"; my $ustr; eval { require Encode; $ustr = Encode::encode_utf8($tstr); Encode::_utf8_on($ustr); }; $ustr = undef unless $@ eq ""; my $bstr = "abcdefgh\x{100}1234567"; eval { Crypt::Eksblowfish->new(1, $bstr, $tstr); }; like $@, qr/\Ainput must contain only octets\b/; eval { Crypt::Eksblowfish->new(1, $tstr, $bstr); }; like $@, qr/\Ainput must contain only octets\b/; SKIP: { skip "Encode not available", 1 unless defined $ustr; my $ca = Crypt::Eksblowfish->new(1, $tstr, $tstr); my $cb = Crypt::Eksblowfish->new(1, $ustr, $ustr); is $ca->encrypt("ABCDEFGH"), $cb->encrypt("ABCDEFGH"); } my $tblk = "foo\xaabar!"; my $ublk; eval { require Encode; $ublk = Encode::encode_utf8($tblk); Encode::_utf8_on($ublk); }; $ublk = undef unless $@ eq ""; my $bblk = "foo\x{100}bar!"; my $cipher = Crypt::Eksblowfish->new(1, $tstr, $tstr); eval { $cipher->encrypt($bblk); }; like $@, qr/\Ainput must contain only octets\b/; eval { $cipher->decrypt($bblk); }; like $@, qr/\Ainput must contain only octets\b/; SKIP: { skip "Encode not available", 2 unless defined $ustr; is $cipher->encrypt($tblk), $cipher->encrypt($ublk); is $cipher->decrypt($tblk), $cipher->decrypt($ublk); } 1; Crypt-Eksblowfish-0.009/t/pod_syn.t000444001750001750 23611556073702 17263 0ustar00zeframzefram000000000000use warnings; use strict; use Test::More; plan skip_all => "Test::Pod not available" unless eval "use Test::Pod 1.00; 1"; Test::Pod::all_pod_files_ok(); 1; Crypt-Eksblowfish-0.009/t/blowfish.t000444001750001750 1046411556073702 17471 0ustar00zeframzefram000000000000use warnings; use strict; use Test::More tests => 13 + 6*59; BEGIN { use_ok "Crypt::Eksblowfish::Blowfish"; } is(Crypt::Eksblowfish::Blowfish->blocksize, 8); is(Crypt::Eksblowfish::Blowfish->keysize, 0); eval { Crypt::Eksblowfish::Blowfish->new("") }; isnt $@, ""; eval { Crypt::Eksblowfish::Blowfish->new("a") }; isnt $@, ""; eval { Crypt::Eksblowfish::Blowfish->new("ab") }; isnt $@, ""; eval { Crypt::Eksblowfish::Blowfish->new("abc") }; isnt $@, ""; eval { Crypt::Eksblowfish::Blowfish->new("abcd") }; is $@, ""; eval { Crypt::Eksblowfish::Blowfish->new("a" x 56) }; is $@, ""; eval { Crypt::Eksblowfish::Blowfish->new("a" x 57) }; isnt $@, ""; my $cipher = Crypt::Eksblowfish::Blowfish->new("abcd"); ok $cipher; is $cipher->p_array->[2], 0x5802cc0b; is $cipher->s_boxes->[2]->[222], 0xbcd61854; while() { my($pt, $ct, $key) = map { pack("H*", $_) } split; my $cipher = Crypt::Eksblowfish::Blowfish->new($key); ok $cipher; is ref($cipher), "Crypt::Eksblowfish::Blowfish"; is $cipher->blocksize, 8; is $cipher->encrypt($pt), $ct; is $cipher->decrypt($ct), $pt; is !!$cipher->is_weak, $key eq pack("H*", "88b824049795f021"); } 1; __DATA__ 0000000000000000 4ef997456198dd78 0000000000000000 ffffffffffffffff 51866fd5b85ecb8a ffffffffffffffff 1000000000000001 7d856f9a613063f2 3000000000000000 1111111111111111 2466dd878b963c9d 1111111111111111 1111111111111111 61f9c3802281b096 0123456789abcdef 0123456789abcdef 7d0cc630afda1ec7 1111111111111111 0000000000000000 4ef997456198dd78 0000000000000000 0123456789abcdef 0aceab0fc6a0a28d fedcba9876543210 01a1d6d039776742 59c68245eb05282b 7ca110454a1a6e57 5cd54ca83def57da b1b8cc0b250f09a0 0131d9619dc1376e 0248d43806f67172 1730e5778bea1da4 07a1133e4a0b2686 51454b582ddf440a a25e7856cf2651eb 3849674c2602319e 42fd443059577fa2 353882b109ce8f1a 04b915ba43feb5b6 059b5e0851cf143a 48f4d0884c379918 0113b970fd34f2ce 0756d8e0774761d2 432193b78951fc98 0170f175468fb5e6 762514b829bf486a 13f04154d69d1ae5 43297fad38e373fe 3bdd119049372802 2eedda93ffd39c79 07a7137045da2a16 26955f6835af609a d887e0393c2da6e3 04689104c2fd3b2f 164d5e404f275232 5f99d04f5b163969 37d06bb516cb7546 6b056e18759f5cca 4a057a3b24d3977b 1f08260d1ac2465e 004bd6ef09176062 452031c1e4fada8e 584023641aba6176 480d39006ee762f2 7555ae39f59b87bd 025816164629b007 437540c8698f3cfa 53c55f9cb49fc019 49793ebc79b3258f 072d43a077075292 7a8e7bfa937e89a3 4fb05e1515ab73a7 02fe55778117f12a cf9c5d7a4986adb5 49e95d6d4ca229bf 1d9d5c5018f728c2 d1abb290658bc778 018310dc409b26d6 305532286d6f295a 55cb3774d13ef201 1c587f1c13924fef 0123456789abcdef fa34ec4847b268b2 0101010101010101 0123456789abcdef a790795108ea3cae 1f1f1f1f0e0e0e0e 0123456789abcdef c39e072d9fac631d e0fee0fef1fef1fe ffffffffffffffff 014933e0cdaff6e4 0000000000000000 0000000000000000 f21e9a77b71c49bc ffffffffffffffff 0000000000000000 245946885754369a 0123456789abcdef ffffffffffffffff 6b5c5a9c5d9e0a5a fedcba9876543210 fedcba9876543210 f9ad597c49db005e f0f0f0f0 fedcba9876543210 e91d21c1d961a6d6 f0e1f0e1 fedcba9876543210 e9c2b70a1bc65cf3 f0e1d2f0e1d2 fedcba9876543210 be1e639408640f05 f0e1d2c3 fedcba9876543210 b39e44481bdb1e6e f0e1d2c3b4 fedcba9876543210 9457aa83b1928c0d f0e1d2c3b4a5 fedcba9876543210 8bb77032f960629d f0e1d2c3b4a596 fedcba9876543210 e87a244e2cc85e82 f0e1d2c3b4a59687 fedcba9876543210 15750e7a4f4ec577 f0e1d2c3b4a5968778 fedcba9876543210 122ba70b3ab64ae0 f0e1d2c3b4a596877869 fedcba9876543210 3a833c9affc537f6 f0e1d2c3b4a5968778695a fedcba9876543210 9409da87a90f6bf2 f0e1d2c3b4a5968778695a4b fedcba9876543210 884f80625060b8b4 f0e1d2c3b4a5968778695a4b3c fedcba9876543210 1f85031c19e11968 f0e1d2c3b4a5968778695a4b3c2d fedcba9876543210 79d9373a714ca34f f0e1d2c3b4a5968778695a4b3c2d1e fedcba9876543210 93142887ee3be15c f0e1d2c3b4a5968778695a4b3c2d1e0f fedcba9876543210 03429e838ce2d14b f0e1d2c3b4a5968778695a4b3c2d1e0f00 fedcba9876543210 a4299e27469ff67b f0e1d2c3b4a5968778695a4b3c2d1e0f0011 fedcba9876543210 afd5aed1c1bc96a8 f0e1d2c3b4a5968778695a4b3c2d1e0f001122 fedcba9876543210 10851c0e3858da9f f0e1d2c3b4a5968778695a4b3c2d1e0f00112233 fedcba9876543210 e6f51ed79b9db21f f0e1d2c3b4a5968778695a4b3c2d1e0f0011223344 fedcba9876543210 64a6e14afd36b46f f0e1d2c3b4a5968778695a4b3c2d1e0f001122334455 fedcba9876543210 80c7d7d45a5479ad f0e1d2c3b4a5968778695a4b3c2d1e0f00112233445566 fedcba9876543210 05044b62fa52d080 f0e1d2c3b4a5968778695a4b3c2d1e0f0011223344556677 ad9e7ebf6cdd5bce 681617e03bca6fe2 88b824049795f021