Crypt-Rijndael-1.12/000755 000765 000024 00000000000 12261635543 014531 5ustar00brianstaff000000 000000 Crypt-Rijndael-1.12/_rijndael.c000644 000765 000024 00000054424 12261635541 016633 0ustar00brianstaff000000 000000 /* rijndael - An implementation of the Rijndael cipher. * Copyright (C) 2000, 2001 Rafael R. Sevilla * * Currently maintained by brian d foy, * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the Free * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "rijndael.h" #include #include #include #if 0 static void print_block(UINT8 *block) { int i; for (i=0; i> 8) | (((x) & 0xff) << 24)) #define ROTRBYTE(x) (((x) << 8) | (((x) >> 24) & 0xff)) #define SUBBYTE(x, box) (((box)[((x) & 0xff)]) | \ ((box)[(((x) >> 8) & 0xff)] << 8) | \ ((box)[(((x) >> 16) & 0xff)] << 16) | \ ((box)[(((x) >> 24) & 0xff)] << 24)) static UINT8 xtime(UINT8 a) { UINT8 b; b = (a & 0x80) ? 0x1b : 0; a<<=1; a^=b; return(a); } static UINT8 mul(UINT8 a, UINT8 b) { if (a && b) return Alogtable[(Logtable[a] + Logtable[b])%255]; else return 0; } static void inv_mix_column(UINT32 *a, UINT32 *b) { UINT8 c[4][4]; int i, j; for(j = 0; j < 4; j++) { for(i = 0; i < 4; i++) { c[j][i] = mul(0xe, (a[j] >> i*8) & 0xff) ^ mul(0xb, (a[j] >> ((i+1)%4)*8) & 0xff) ^ mul(0xd, (a[j] >> ((i+2)%4)*8) & 0xff) ^ mul(0x9, (a[j] >> ((i+3)%4)*8) & 0xff); } } for(i = 0; i < 4; i++) { b[i] = 0; for(j = 0; j < 4; j++) b[i] |= c[i][j] << (j*8); } } void rijndael_setup(RIJNDAEL_context *ctx, size_t keysize, const UINT8 *key) { int nk, nr, i, lastkey; UINT32 temp, rcon; /* Truncate keysizes to the valid key sizes provided by Rijndael */ if (keysize >= 32) { nk = 8; nr = 14; } else if (keysize >= 24) { nk = 6; nr = 12; } else { /* must be 16 or more */ nk = 4; nr = 10; } lastkey = (RIJNDAEL_BLOCKSIZE/4) * (nr + 1); ctx->nrounds = nr; rcon = 1; for (i=0; ikeys[i] = key[i*4] + (key[i*4+1]<<8) + (key[i*4+2]<<16) + (key[i*4+3]<<24); } for (i=nk; ikeys[i-1]; if (i % nk == 0) { temp = SUBBYTE(ROTBYTE(temp), sbox) ^ rcon; rcon = (UINT32)xtime((UINT8)rcon&0xff); } else if (nk > 6 && (i%nk) == 4) { temp = SUBBYTE(temp, sbox); } ctx->keys[i] = ctx->keys[i-nk] ^ temp; } /* Generate the inverse keys */ for (i=0; i<4; i++) { ctx->ikeys[i] = ctx->keys[i]; ctx->ikeys[lastkey-4 + i] = ctx->keys[lastkey-4 + i]; } for (i=4; ikeys[i]), &(ctx->ikeys[i])); } /* Key addition that also packs every byte in the key to a word rep. */ static void key_addition_8to32(const UINT8 *txt, UINT32 *keys, UINT32 *out) { const UINT8 *ptr; int i, j; UINT32 val; ptr = txt; for (i=0; i<4; i++) { val = 0; for (j=0; j<4; j++) val |= (*ptr++ << 8*j); out[i] = keys[i]^val; } } static void key_addition32(const UINT32 *txt, UINT32 *keys, UINT32 *out) { int i; for (i=0; i<4; i++) out[i] = keys[i] ^ txt[i]; } static void key_addition32to8(const UINT32 *txt, UINT32 *keys, UINT8 *out) { UINT8 *ptr; int i, j; UINT32 val; ptr = out; for (i=0; i<4; i++) { val = txt[i] ^ keys[i]; for (j=0; j<4; j++) *ptr++ = (val >> 8*j) & 0xff; } } static int idx[4][4] = { { 0, 1, 2, 3 }, { 1, 2, 3, 0 }, { 2, 3, 0, 1 }, { 3, 0, 1, 2 } }; void rijndael_encrypt(RIJNDAEL_context *ctx, const UINT8 *plaintext, UINT8 *ciphertext) { int r, j; UINT32 wtxt[4], t[4]; /* working ciphertext */ UINT32 e; key_addition_8to32(plaintext, &(ctx->keys[0]), wtxt); for (r=1; rnrounds; r++) { for (j=0; j<4; j++) { t[j] = dtbl[wtxt[j] & 0xff] ^ ROTRBYTE(dtbl[(wtxt[idx[1][j]] >> 8) & 0xff]^ ROTRBYTE(dtbl[(wtxt[idx[2][j]] >> 16) & 0xff] ^ ROTRBYTE(dtbl[(wtxt[idx[3][j]] >> 24) & 0xff]))); } key_addition32(t, &(ctx->keys[r*4]), wtxt); } /* last round is special: there is no mixcolumn, so we can't use the big tables. */ for (j=0; j<4; j++) { e = wtxt[j] & 0xff; e |= (wtxt[idx[1][j]]) & (0xff << 8 ); e |= (wtxt[idx[2][j]]) & (0xff << 16); e |= (wtxt[idx[3][j]]) & (0xffU << 24); t[j] = e; } for (j=0; j<4; j++) t[j] = SUBBYTE(t[j], sbox); key_addition32to8(t, &(ctx->keys[4*ctx->nrounds]), ciphertext); } static int iidx[4][4] = { { 0, 1, 2, 3 }, { 3, 0, 1, 2 }, { 2, 3, 0, 1 }, { 1, 2, 3, 0 } }; void rijndael_decrypt(RIJNDAEL_context *ctx, const UINT8 *ciphertext, UINT8 *plaintext) { int r, j; UINT32 wtxt[4], t[4]; /* working ciphertext */ UINT32 e; key_addition_8to32(ciphertext, &(ctx->ikeys[4*ctx->nrounds]), wtxt); for (r=ctx->nrounds-1; r> 0; r--) { for (j=0; j<4; j++) { t[j] = itbl[wtxt[j] & 0xff] ^ ROTRBYTE(itbl[(wtxt[iidx[1][j]] >> 8) & 0xff]^ ROTRBYTE(itbl[(wtxt[iidx[2][j]] >> 16) & 0xff] ^ ROTRBYTE(itbl[(wtxt[iidx[3][j]] >> 24) & 0xff]))); } key_addition32(t, &(ctx->ikeys[r*4]), wtxt); } /* last round is special: there is no mixcolumn, so we can't use the big tables. */ for (j=0; j<4; j++) { e = wtxt[j] & 0xff; e |= (wtxt[iidx[1][j]]) & (0xff << 8); e |= (wtxt[iidx[2][j]]) & (0xff << 16); e |= (wtxt[iidx[3][j]]) & (0xffU << 24); t[j] = e; } for (j=0; j<4; j++) t[j] = SUBBYTE(t[j], isbox); key_addition32to8(t, &(ctx->ikeys[0]), plaintext); } void block_encrypt(RIJNDAEL_context *ctx, UINT8 *input, int inputlen, UINT8 *output, UINT8 *iv) { int i, j, nblocks, carry_flg; UINT8 block[RIJNDAEL_BLOCKSIZE], block2[RIJNDAEL_BLOCKSIZE], oldptxt; nblocks = inputlen / RIJNDAEL_BLOCKSIZE; switch (ctx->mode) { case MODE_ECB: /* electronic code book */ for (i = 0; i=0; j--) { if (carry_flg) { block[j]++; carry_flg = block[j] != 0 ? 0 : 1; } else break; } } break; default: break; } } void block_decrypt(RIJNDAEL_context *ctx, UINT8 *input, int inputlen, UINT8 *output, UINT8 *iv) { int i, j, nblocks, carry_flg; UINT8 block[RIJNDAEL_BLOCKSIZE], block2[RIJNDAEL_BLOCKSIZE]; nblocks = inputlen / RIJNDAEL_BLOCKSIZE; switch (ctx->mode) { case MODE_ECB: for (i = 0; i=0; j--) { if (carry_flg) { block[j]++; carry_flg = block[j] != 0 ? 0 : 1; } else break; } } break; default: break; } } Crypt-Rijndael-1.12/Changes000644 000765 000024 00000011750 12261635541 016026 0ustar00brianstaff000000 000000 1.12 - Fri Jan 3 17:36:10 2014 * Get rid of MYMETA 1.11 - Sat Jul 28 16:09:37 2012 * Clarify the license as LGPL v3 (29 June 2007) (RT 78629) 1.10 - Wed Jul 11 19:25:12 2012 * Add MirBSD support. It's the same options as Sun stuff. 1.08 - Wed Dec 9 18:20:22 2009 * Promoting development release to full release. * This release mainly clarifies the licensing. 1.07_02 - Tue Nov 4 02:21:27 2008 * RT #40511: Give a better warning when you try to use tainted data as an initialization vector. If anyone wants to use tainted data, they can patch the code to accept it. 1.07_01 - Tue Oct 14 08:59:58 2008 * Clarify that these files are under the Lesser GNU Public License (also known as the Library GNU Public License). 1.07 - Fri Aug 15 16:53:36 2008 * Fixed the odd character problems in some of the files * No need to upgrade if you already have this installed 1.06_03 - Sun Jun 22 11:32:46 2008 * Trying the __sgi definition. If this doesn't make things blow up, this release will get bumped to 1.07. 1.06_02 - Thu Jun 19 11:55:21 2008 * Removed wide chars from the header file. Some compilers like to complain about things that are wrong. :( 1.06_01 - Wed Jun 18 09:37:34 2008 This is a test of a fix for Irix. 1.06_01 - Wed Jun 4 19:18:57 2008 * This is a test of a fix for Irix. 1.06 - Wed Apr 23 13:14:34 2008 * This release has a compiler-bug workaround for Sun C 5.9 identified by Andy Armstrong. No, really, it was a compiler bug: http://in.opensolaris.org/jive/thread.jspa?threadID=53641&tstart=0 * You don't need to upgrade if you already have 1.05. 1.05_02 - Sun Apr 20 15:26:21 2008 * This is a workaround for a Solaris compiler bug, but let's see what CPAN Testers does with it. 1.05_01 - Tue Nov 20 07:59:26 2007 * Updated rijndael.h to handle Mac OS X Panther, thanks to John Fong. * No need to upgrade if you already have this installed. 1.05 - Fri Nov 9 05:39:09 2007 * This version fixes the signed integer problems that Solaris had. * Now this module requires perl 5.6. * You don't need to upgrade if your system isn't Solaris. 1.04_03 - Mon Oct 15 14:27:00 2007 * Quashed warnings about overflows by casting numbers to unsigned ints. * This compiles warning-free and passes all tests on Solaris 10 with gcc 3.4.6, so it might take care of RT#27632 1.04_02 - Wed Sep 19 19:24:06 2007 * remove test files that shouldn't be there 1.04_01 - Wed Sep 12 15:34:24 2007 * This developer release explores the Solaris bug noted in RT#27632. Some Solaris installations may be encrypting or decrpyting incorrectly. 1.04 - Fri Feb 23 11:20:44 2007 * Todd Ross adjusted rijndael.h to use __sun to identify Solaris boxes. GCC uses __sun__ or __sun, but Solaris cc only uses __sun : http://blogs.sun.com/morganh/date/20060928 * If you've already compiled this module, you don't need to upgrade 1.03 - Thu Feb 22 15:42:04 2007 * Updated distro to include missing Pod tests * No code changes 1.02 - Thu Jan 25 14:48:51 2007 * Updated docs to show cipher modes. No need to upgrade if you already have this. 1.01 - Wed Jan 10 19:14:14 2007 * Bump to a release version. This is the same as 0.06_10. * This release should fix the problems with INT types on all platforms, including 64 bit platforms. 0.06_10 - Wed Jan 10 00:35:10 2007 * Let's try the int type for MinGW:wq 0.06_09 - Fri Dec 15 08:12:02 2006 * Updated header file to handle Solaris special case * I think this might be the release candidate for 0.07! :) 0.06_08 - Wed Nov 29 19:51:33 2006 * Adjusting WIN32 targets for typedefs. Some things look like both Unix and Windows, so I don't want compilers to choke if it tries to redefine types. 0.06_07 - Mon Nov 27 10:37:18 2006 * more header file fiddling to get everyone to define the right abstract types. This time check for _SYS_TYPES_H 0.06_06 - Fri Nov 17 14:56:19 2006 * Fooled with header file some more, and tested it myself on Cygwin. Instead of checking for WIN32, just check for __CYGWIN__ 0.06_05 - Fri Nov 17 11:13:25 2006 * The last two revisions seem to not define UINTxx and ends up with a parse error. Let's try this, as I go off to dig out my Windows box. 0.06_04 - Wed Nov 15 14:43:37 2006 * Try UINT patch from David Golden to get this to work on MinGW 0.06_03 - Wed Nov 15 11:07:08 2006 * Re-jiggered logic to define UINT32 and UINT8. First I'll try sys/types.h, then check if they are already defined elsewhere, and lastly hardcode the typedefs based on platform. The previous release (0.06_02) had some problems on Windows from conflicting typedefs (similar to the cygwin problems with libjpeg and X), so I guard my typedefs by checking for previous definitions. Let's hope those previous definitions are right :) 0.06_02 - Sun Nov 12 16:23:07 2006 * Let's try some hardcoded types for UINT(32|8) for Windows. 0.06_01 - Sun Nov 12 10:38:56 2006 * Adjust version number to match distro number (RT #4227) * Use instead of hard-coding (RT #22755, 9514, 18812, 1444, 503). * This module is now maintained by brian d foy (bdfoy@cpan.org) Crypt-Rijndael-1.12/COPYING000644 000765 000024 00000016743 12261635541 015575 0ustar00brianstaff000000 000000 GNU LESSER GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below. 0. Additional Definitions. As used herein, "this License" refers to version 3 of the GNU Lesser General Public License, and the "GNU GPL" refers to version 3 of the GNU General Public License. "The Library" refers to a covered work governed by this License, other than an Application or a Combined Work as defined below. An "Application" is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library. A "Combined Work" is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the "Linked Version". The "Minimal Corresponding Source" for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version. The "Corresponding Application Code" for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work. 1. Exception to Section 3 of the GNU GPL. You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL. 2. Conveying Modified Versions. If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version: a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy. 3. Object Code Incorporating Material from Library Header Files. The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following: a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the object code with a copy of the GNU GPL and this license document. 4. Combined Works. You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following: a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the Combined Work with a copy of the GNU GPL and this license document. c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document. d) Do one of the following: 0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source. 1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version. e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.) 5. Combined Libraries. You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License. b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 6. Revised Versions of the GNU Lesser General Public License. The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library as you received it specifies that a certain numbered version of the GNU Lesser General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation. If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the Library. Crypt-Rijndael-1.12/examples/000755 000765 000024 00000000000 12261635542 016346 5ustar00brianstaff000000 000000 Crypt-Rijndael-1.12/LICENSE000644 000765 000024 00000000037 12261635541 015534 0ustar00brianstaff000000 000000 See COPYING for license detailsCrypt-Rijndael-1.12/Makefile.PL000644 000765 000024 00000002037 12261635541 016503 0ustar00brianstaff000000 000000 require 5.006; use ExtUtils::MakeMaker 6.46; eval "use Test::Manifest 1.21"; WriteMakefile( 'NAME' => "Crypt::Rijndael", 'VERSION_FROM' => "Rijndael.pm", 'LICENSE' => 'lgpl', 'AUTHOR' => 'Rafael R. Sevilla (maintained by brian d foy )', 'ABSTRACT' => 'Crypt::CBC compliant Rijndael encryption module', 'PREREQ_PM' => { 'Test::More' => '0', 'Test::Manifest' => '1.14', }, 'MAN3PODS' => { 'Rijndael.pm' => '$(INST_MAN3DIR)/Crypt::Rijndael.3', }, 'META_MERGE' => { 'meta-spec' => { version => '2' }, 'resources' => { 'repository' => { type => 'git', web => 'https://github.com/briandfoy/crypt-rijndael', url => 'git@github.com:briandfoy/crypt-rijndael.git' }, }, }, clean => { FILES => q|*.bak *.old Crypt-*| }, dist => { PREOP => 'pod2text Rijndael.pm | tee README >$(DISTVNAME)/README; chmod -R u=rwX,go=rX . ;', COMPRESS => 'gzip -9v', SUFFIX => '.gz', }, OBJECT => q[_rijndael$(OBJ_EXT) Rijndael$(OBJ_EXT)], ); Crypt-Rijndael-1.12/MANIFEST000644 000765 000024 00000000705 12261635543 015664 0ustar00brianstaff000000 000000 _rijndael.c Changes COPYING examples/README LICENSE Makefile.PL MANIFEST MANIFEST.SKIP NEWS README rijndael.h Rijndael.pm Rijndael.xs t/00_load.t t/blocksize.t t/cbc.t t/cfb.t t/ctr.t t/ecb.t t/lib/mode.pl t/ofb.t t/pcbc.t t/pod.t t/pod_coverage.t t/rt/27632.t t/test_manifest typemap META.yml Module YAML meta-data (added by MakeMaker) META.json Module JSON meta-data (added by MakeMaker) Crypt-Rijndael-1.12/MANIFEST.SKIP000644 000765 000024 00000002115 12261635541 016424 0ustar00brianstaff000000 000000 #!start included /usr/local/perls/perl-5.18.1/lib/5.18.1/ExtUtils/MANIFEST.SKIP # Avoid version control files. \bRCS\b \bCVS\b \bSCCS\b ,v$ \B\.svn\b \B\.git\b \B\.gitignore\b \b_darcs\b \B\.cvsignore$ # Avoid VMS specific MakeMaker generated files \bDescrip.MMS$ \bDESCRIP.MMS$ \bdescrip.mms$ # Avoid Makemaker generated and utility files. \bMANIFEST\.bak \bMakefile$ \bblib/ \bMakeMaker-\d \bpm_to_blib\.ts$ \bpm_to_blib$ \bblibdirs\.ts$ # 6.18 through 6.25 generated this # Avoid Module::Build generated and utility files. \bBuild$ \b_build/ \bBuild.bat$ \bBuild.COM$ \bBUILD.COM$ \bbuild.com$ # Avoid temp and backup files. ~$ \.old$ \#$ \b\.# \.bak$ \.tmp$ \.# \.rej$ # Avoid OS-specific files/dirs # Mac OSX metadata \B\.DS_Store # Mac OSX SMB mount metadata files \B\._ # Avoid Devel::Cover and Devel::CoverX::Covered files. \bcover_db\b \bcovered\b # Avoid MYMETA files ^MYMETA\. #!end included /usr/local/perls/perl-5.18.1/lib/5.18.1/ExtUtils/MANIFEST.SKIP \.travis\.yml \.releaserc \.lwpcookies Crypt-.* Rijndael.c$ t/trailing_nulls.t ref/.* rijndael-vals .*\.o$ .*\.bs$ Crypt-Rijndael-1.12/META.json000644 000765 000024 00000001357 12261635543 016160 0ustar00brianstaff000000 000000 { "abstract" : "Crypt::CBC compliant Rijndael encryption module", "author" : [ "Rafael R. Sevilla (maintained by brian d foy )" ], "dynamic_config" : 1, "generated_by" : "ExtUtils::MakeMaker version 6.62, CPAN::Meta::Converter version 2.112150", "license" : [ "open_source" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "Crypt-Rijndael", "no_index" : { "directory" : [ "t", "inc" ] }, "release_status" : "stable", "resources" : { "repository" : { "type" : "git", "web" : "https://github.com/briandfoy/crypt-rijndael" } }, "version" : "1.12" } Crypt-Rijndael-1.12/META.yml000644 000765 000024 00000001012 12261635543 015774 0ustar00brianstaff000000 000000 --- abstract: 'Crypt::CBC compliant Rijndael encryption module' author: - 'Rafael R. Sevilla (maintained by brian d foy )' build_requires: {} dynamic_config: 1 generated_by: 'ExtUtils::MakeMaker version 6.62, CPAN::Meta::Converter version 2.112150' license: open_source meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 name: Crypt-Rijndael no_index: directory: - t - inc resources: repository: https://github.com/briandfoy/crypt-rijndael version: 1.12 Crypt-Rijndael-1.12/NEWS000644 000765 000024 00000000561 12261635541 015230 0ustar00brianstaff000000 000000 Changes from Version 0.04: All modes of operation recommended by NIST as of July 2001 (ECB, CBC, CFB-128, OFB, and CTR) are implemented, with the exception of n-bit CFB mode. I can't think of a way to do it without adding yet another incompatible method... An incompatible (to Crypt::CBC) method of changing the IV's for the modes which require it has been added. Crypt-Rijndael-1.12/README000644 000765 000024 00000005757 12261635543 015427 0ustar00brianstaff000000 000000 NAME Crypt::Rijndael - Crypt::CBC compliant Rijndael encryption module SYNOPSIS use Crypt::Rijndael; # keysize() is 32, but 24 and 16 are also possible # blocksize() is 16 $cipher = Crypt::Rijndael->new( "a" x 32, Crypt::Rijndael::MODE_CBC() ); $cipher->set_iv($iv); $crypted = $cipher->encrypt($plaintext); # - OR - $plaintext = $cipher->decrypt($crypted); DESCRIPTION This module implements the Rijndael cipher, which has just been selected as the Advanced Encryption Standard. keysize Returns the keysize, which is 32 (bytes). The Rijndael cipher actually supports keylengths of 16, 24 or 32 bytes, but there is no way to communicate this to `Crypt::CBC'. blocksize The blocksize for Rijndael is 16 bytes (128 bits), although the algorithm actually supports any blocksize that is any multiple of our bytes. 128 bits, is however, the AES- specified block size, so this is all we support. $cipher = Crypt::Rijndael->new( $key [, $mode] ) Create a new `Crypt::Rijndael' cipher object with the given key (which must be 128, 192 or 256 bits long). The additional `$mode' argument is the encryption mode, either `MODE_ECB' (electronic codebook mode, the default), `MODE_CBC' (cipher block chaining, the same that `Crypt::CBC' does), `MODE_CFB' (128-bit cipher feedback), `MODE_OFB' (128-bit output feedback), or `MODE_CTR' (counter mode). ECB mode is very insecure (read a book on cryptography if you don't know why!), so you should probably use CBC mode. $cipher->set_iv($iv) This allows you to change the initial value vector used by the chaining modes. It is not relevant for ECB mode. $cipher->encrypt($data) Encrypt data. The size of `$data' must be a multiple of `blocksize' (16 bytes), otherwise this function will croak. Apart from that, it can be of (almost) any length. $cipher->decrypt($data) Decrypts `$data'. Encryption modes Use these constants to select the cipher type: MODE_CBC - Cipher Block Chaining MODE_CFB - Cipher feedback MODE_CTR - Counter mode MODE_ECB - Electronic cookbook mode MODE_OFB - Output feedback MODE_PCBC - ignore this one for now :) SEE ALSO the Crypt::CBC manpage, http://www.csrc.nist.gov/encryption/aes/ BUGS Should EXPORT or EXPORT_OK the MODE constants. AUTHOR Currently maintained by brian d foy, `< >. Original code by Rafael R. Sevilla. The Rijndael Algorithm was developed by Vincent Rijmen and Joan Daemen, and has been selected as the US Government's Advanced Encryption Standard. SOURCE This code is in Github: git://github.com/briandfoy/crypt-rijndael.git =head1 LICENSE This software is licensed under the Lesser GNU Public License v3 (29 June 2007). See the included COPYING file for details. Crypt-Rijndael-1.12/rijndael.h000644 000765 000024 00000014213 12261635541 016471 0ustar00brianstaff000000 000000 /* rijndael - An implementation of the Rijndael cipher. * Copyright (C) 2000 Rafael R. Sevilla * * Currently maintained by brian d foy, * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the Free * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* * Rijndael is a 128/192/256-bit block cipher that accepts key sizes of * 128, 192, or 256 bits, designed by Joan Daemen and Vincent Rijmen. See * http://www.esat.kuleuven.ac.be/~rijmen/rijndael/ for details. */ #if !defined(RIJNDAEL_H) #define RIJNDAEL_H #include #include #ifdef _CRYPT_RIJNDAEL_H_TYPES #undef _CRYPT_RIJNDAEL_H_TYPES #endif /* Irix. We could include stdint.h and use uint8_t but that also * requires that we specifically drive the compiler in C99 mode. * Defining UINT8 as unsigned char is, ultimately, what stdint.h * would do anyway. */ #if defined(_SGIAPI) || defined( __sgi ) #define _CRYPT_RIJNDAEL_H_TYPES typedef __uint32_t UINT32; typedef unsigned char UINT8; #endif /* Solaris has sys/types.h, but doesn't act like everyone else * GCC defines __sun__ and __sun (report from Todd Ross) * Solaris cc defines __sun * MirBSD defines the same types as Solaris */ #if defined( __sun__ ) || defined( __sun ) || defined( __MirBSD__ ) #define _CRYPT_RIJNDAEL_H_TYPES typedef uint32_t UINT32; typedef uint8_t UINT8; #endif /* Mac OS X 10.3 defines things differently than most other systems */ #if defined( __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ ) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__-0 < 1140 #define _CRYPT_RIJNDAEL_H_TYPES typedef u_int32_t UINT32; typedef u_char UINT8; #endif /* Mac OS X 10.3 defines things differently than most other systems */ #if defined(__APPLE__) && ! defined(__DARWIN_UNIX03) #define _CRYPT_RIJNDAEL_H_TYPES typedef u_int32_t UINT32; typedef u_char UINT8; #endif /* I expect this to be the usual case */ #if ! defined(_CRYPT_RIJNDAEL_H_TYPES) && ( defined(_SYS_TYPES_H) || defined(_SYS_TYPES_H_) ) #define _CRYPT_RIJNDAEL_H_TYPES typedef __uint32_t UINT32; typedef __uint8_t UINT8; #endif #if defined(__CYGWIN__) && ! defined(_CRYPT_RIJNDAEL_H_TYPES) #define _CRYPT_RIJNDAEL_H_TYPES typedef unsigned int UINT32; typedef unsigned char UINT8; #endif #if defined(__MINGW32__) && ! defined(_CRYPT_RIJNDAEL_H_TYPES) #define _CRYPT_RIJNDAEL_H_TYPES typedef unsigned int UINT32; typedef unsigned char UINT8; #endif #if defined(WIN32) && ! defined(_CRYPT_RIJNDAEL_H_TYPES) #define _CRYPT_RIJNDAEL_H_TYPES typedef unsigned int UINT32; typedef unsigned char UINT8; #endif #if ! defined(_CRYPT_RIJNDAEL_H_TYPES) #define _CRYPT_RIJNDAEL_H_TYPES typedef unsigned int UINT32; typedef unsigned char UINT8; #endif /* Other block sizes and key lengths are possible, but in the context of * the ssh protocols, 256 bits is the default. */ #define RIJNDAEL_BLOCKSIZE 16 #define RIJNDAEL_KEYSIZE 32 #define MODE_ECB 1 /* Are we ciphering in ECB mode? */ #define MODE_CBC 2 /* Are we ciphering in CBC mode? */ #define MODE_CFB 3 /* Are we ciphering in 128-bit CFB mode? */ #define MODE_PCBC 4 /* Are we ciphering in PCBC mode? */ #define MODE_OFB 5 /* Are we ciphering in 128-bit OFB mode? */ #define MODE_CTR 6 /* Are we ciphering in counter mode? */ /* Allow keys of size 128 <= bits <= 256 */ #define RIJNDAEL_MIN_KEYSIZE 16 #define RIJNDAEL_MAX_KEYSIZE 32 typedef struct { UINT32 keys[60]; /* maximum size of key schedule */ UINT32 ikeys[60]; /* inverse key schedule */ int nrounds; /* number of rounds to use for our key size */ int mode; /* encryption mode */ } RIJNDAEL_context; /* This basically performs Rijndael's key scheduling algorithm, as it's the * only initialization required anyhow. The key size is specified in bytes, * but the only valid values are 16 (128 bits), 24 (192 bits), and 32 (256 * bits). If a value other than these three is specified, the key will be * truncated to the closest value less than the key size specified, e.g. * specifying 7 will use only the first 6 bytes of the key given. DO NOT * PASS A VALUE LESS THAN 16 TO KEYSIZE! */ void rijndael_setup(RIJNDAEL_context *ctx, size_t keysize, const UINT8 *key); /* * rijndael_encrypt() * * Encrypt 16 bytes of data with the Rijndael algorithm. Before this * function can be used, rijndael_setup must be used in order to initialize * Rijndael's key schedule. * * This function always encrypts 16 bytes of plaintext to 16 bytes of * ciphertext. The memory areas of the plaintext and the ciphertext can * overlap. */ void rijndael_encrypt(RIJNDAEL_context *context, const UINT8 *plaintext, UINT8 *ciphertext); /* * rijndael_decrypt() * * Decrypt 16 bytes of data with the Rijndael algorithm. * * Before this function can be used, rijndael_setup() must be used in order * to set up the key schedule required for the decryption algorithm. * * This function always decrypts 16 bytes of ciphertext to 16 bytes of * plaintext. The memory areas of the plaintext and the ciphertext can * overlap. */ void rijndael_decrypt(RIJNDAEL_context *context, const UINT8 *ciphertext, UINT8 *plaintext); /* Encrypt a block of plaintext in a mode specified in the context */ void block_encrypt(RIJNDAEL_context *ctx, UINT8 *input, int inputlen, UINT8 *output, UINT8 *iv); /* Decrypt a block of plaintext in a mode specified in the context */ void block_decrypt(RIJNDAEL_context *ctx, UINT8 *input, int inputlen, UINT8 *output, UINT8 *iv); #endif /* RIJNDAEL_H */ Crypt-Rijndael-1.12/Rijndael.pm000644 000765 000024 00000006027 12261635541 016622 0ustar00brianstaff000000 000000 =head1 NAME Crypt::Rijndael - Crypt::CBC compliant Rijndael encryption module =head1 SYNOPSIS use Crypt::Rijndael; # keysize() is 32, but 24 and 16 are also possible # blocksize() is 16 $cipher = Crypt::Rijndael->new( "a" x 32, Crypt::Rijndael::MODE_CBC() ); $cipher->set_iv($iv); $crypted = $cipher->encrypt($plaintext); # - OR - $plaintext = $cipher->decrypt($crypted); =head1 DESCRIPTION This module implements the Rijndael cipher, which has just been selected as the Advanced Encryption Standard. =over 4 =cut package Crypt::Rijndael; use strict; use vars qw( $VERSION @ISA ); use warnings; no warnings; require DynaLoader; $VERSION = '1.12'; @ISA = qw/DynaLoader/; bootstrap Crypt::Rijndael $VERSION; =item keysize Returns the keysize, which is 32 (bytes). The Rijndael cipher actually supports keylengths of 16, 24 or 32 bytes, but there is no way to communicate this to C. =item blocksize The blocksize for Rijndael is 16 bytes (128 bits), although the algorithm actually supports any blocksize that is any multiple of our bytes. 128 bits, is however, the AES-specified block size, so this is all we support. =item $cipher = Crypt::Rijndael->new( $key [, $mode] ) Create a new C cipher object with the given key (which must be 128, 192 or 256 bits long). The additional C<$mode> argument is the encryption mode, either C (electronic codebook mode, the default), C (cipher block chaining, the same that C does), C (128-bit cipher feedback), C (128-bit output feedback), or C (counter mode). ECB mode is very insecure (read a book on cryptography if you don't know why!), so you should probably use CBC mode. =item $cipher->set_iv($iv) This allows you to change the initial value vector used by the chaining modes. It is not relevant for ECB mode. =item $cipher->encrypt($data) Encrypt data. The size of C<$data> must be a multiple of C (16 bytes), otherwise this function will croak. Apart from that, it can be of (almost) any length. =item $cipher->decrypt($data) Decrypts C<$data>. =back =head2 Encryption modes Use these constants to select the cipher type: =over 4 =item MODE_CBC - Cipher Block Chaining =item MODE_CFB - Cipher feedback =item MODE_CTR - Counter mode =item MODE_ECB - Electronic cookbook mode =item MODE_OFB - Output feedback =item MODE_PCBC - ignore this one for now :) =back =head1 SEE ALSO L, http://www.csrc.nist.gov/encryption/aes/ =head1 BUGS Should EXPORT or EXPORT_OK the MODE constants. =head1 AUTHOR Currently maintained by brian d foy, C<< >>. Original code by Rafael R. Sevilla. The Rijndael Algorithm was developed by Vincent Rijmen and Joan Daemen, and has been selected as the US Government's Advanced Encryption Standard. =head1 SOURCE This code is in Github: git://github.com/briandfoy/crypt-rijndael.git =head1 LICENSE This software is licensed under the Lesser GNU Public License v3 (29 June 2007). See the included COPYING file for details. =cut 1; Crypt-Rijndael-1.12/Rijndael.xs000644 000765 000024 00000011252 12261635541 016634 0ustar00brianstaff000000 000000 /* rijndael - An implementation of the Rijndael cipher. * Copyright (C) 2000, 2001 Rafael R. Sevilla * * Currently maintained by brian d foy, * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the Free * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "EXTERN.h" #include "perl.h" #include "XSUB.h" /* try to be compatible with older perls */ /* SvPV_nolen() macro first defined in 5.005_55 */ /* this is slow, not threadsafe, but works */ #include "patchlevel.h" #if (PATCHLEVEL == 4) || ((PATCHLEVEL == 5) && (SUBVERSION < 55)) static STRLEN nolen_na; # define SvPV_nolen(sv) SvPV ((sv), nolen_na) #endif #include "rijndael.h" typedef struct cryptstate { RIJNDAEL_context ctx; UINT8 iv[RIJNDAEL_BLOCKSIZE]; int mode; } *Crypt__Rijndael; MODULE = Crypt::Rijndael PACKAGE = Crypt::Rijndael PROTOTYPES: ENABLE # newCONSTSUB is here as of 5.004_70 BOOT: { #if (PATCHLEVEL > 4) || ((PATCHLEVEL == 4) && (SUBVERSION >= 70)) HV *stash = gv_stashpv("Crypt::Rijndael", 0); newCONSTSUB (stash, "keysize", newSViv (32) ); newCONSTSUB (stash, "blocksize", newSViv (16) ); newCONSTSUB (stash, "MODE_ECB", newSViv (MODE_ECB) ); newCONSTSUB (stash, "MODE_CBC", newSViv (MODE_CBC) ); newCONSTSUB (stash, "MODE_CFB", newSViv (MODE_CFB) ); newCONSTSUB (stash, "MODE_PCBC", newSViv (MODE_PCBC) ); newCONSTSUB (stash, "MODE_OFB", newSViv (MODE_OFB) ); newCONSTSUB (stash, "MODE_CTR", newSViv (MODE_CTR) ); #endif } #if (PATCHLEVEL < 4) || ((PATCHLEVEL == 4) && (SUBVERSION < 70)) int keysize(...) CODE: RETVAL=32; OUTPUT: RETVAL int blocksize(...) CODE: RETVAL=16; OUTPUT: RETVAL int MODE_ECB(...) CODE: RETVAL=MODE_ECB; OUTPUT: RETVAL int MODE_CBC(...) CODE: RETVAL=MODE_CBC; OUTPUT: RETVAL int MODE_CFB(...) CODE: RETVAL=MODE_CFB; OUTPUT: RETVAL int MODE_PCBC(...) CODE: RETVAL=MODE_PCBC; OUTPUT: RETVAL int MODE_OFB(...) CODE: RETVAL=MODE_OFB; OUTPUT: RETVAL int MODE_CTR(...) CODE: RETVAL=MODE_CTR; OUTPUT: RETVAL #endif Crypt::Rijndael new(class, key, mode=MODE_ECB) SV * class SV * key int mode CODE: { STRLEN keysize; if (!SvPOK (key)) croak("key must be an untainted string scalar"); keysize = SvCUR(key); if (keysize != 16 && keysize != 24 && keysize != 32) croak ("wrong key length: key must be 128, 192 or 256 bits long"); if (mode != MODE_ECB && mode != MODE_CBC && mode != MODE_CFB && mode != MODE_OFB && mode != MODE_CTR) croak ("illegal mode, see documentation for valid modes"); Newz(0, RETVAL, 1, struct cryptstate); RETVAL->ctx.mode = RETVAL->mode = mode; /* set the IV to zero on initialization */ memset(RETVAL->iv, 0, RIJNDAEL_BLOCKSIZE); rijndael_setup(&RETVAL->ctx, keysize, (UINT8 *) SvPV_nolen(key)); } OUTPUT: RETVAL SV * set_iv(self, data) Crypt::Rijndael self SV * data CODE: { SV *res; STRLEN size; void *rawbytes = SvPV(data,size); if( size != RIJNDAEL_BLOCKSIZE ) croak( "set_iv: initial value must be the blocksize (%d bytes), but was %d bytes", RIJNDAEL_BLOCKSIZE, size ); memcpy(self->iv, rawbytes, RIJNDAEL_BLOCKSIZE); } SV * encrypt(self, data) Crypt::Rijndael self SV * data ALIAS: decrypt = 1 CODE: { SV *res; STRLEN size; void *rawbytes = SvPV(data,size); if (size) { if (size % RIJNDAEL_BLOCKSIZE) croak ("encrypt: datasize not multiple of blocksize (%d bytes)", RIJNDAEL_BLOCKSIZE); RETVAL = NEWSV (0, size); SvPOK_only (RETVAL); SvCUR_set (RETVAL, size); (ix ? block_decrypt : block_encrypt) (&self->ctx, rawbytes, size, (UINT8 *) SvPV_nolen(RETVAL), self->iv); } else RETVAL = newSVpv ("", 0); } OUTPUT: RETVAL void DESTROY(self) Crypt::Rijndael self CODE: Safefree(self); Crypt-Rijndael-1.12/t/000755 000765 000024 00000000000 12261635542 014773 5ustar00brianstaff000000 000000 Crypt-Rijndael-1.12/typemap000644 000765 000024 00000000034 12261635541 016126 0ustar00brianstaff000000 000000 Crypt::Rijndael T_PTROBJ Crypt-Rijndael-1.12/t/00_load.t000644 000765 000024 00000026204 12261635541 016401 0ustar00brianstaff000000 000000 BEGIN { $| = 1; print "1..41\n"; } END {print "not ok 1\n" unless $loaded;} use Crypt::Rijndael; $loaded = 1; print "ok 1\n"; $plaintext = chr(0) x 32; for ($i=0; $i<32; $i++) { substr($plaintext, $i, 1)=chr($i); } $key = chr(0) x 32; substr($key, 0, 1) = chr(1); $ecb = new Crypt::Rijndael $key; $crypted = $ecb->encrypt($plaintext); print unpack("H*", $crypted) eq "f2258e225d794572393a6484cfced7cf925d1aa18366bcd93c33d104294c8a6f" ? "" : "not ", "ok 2\n"; print $ecb->decrypt($crypted) eq $plaintext ? "" : "not ", "ok 3\n"; $cbc = new Crypt::Rijndael $key, Crypt::Rijndael::MODE_CBC; $crypted = $cbc->encrypt($plaintext); print unpack("H*", $crypted) eq "f2258e225d794572393a6484cfced7cfb487a41f6b6286c00c9c8d80cb3ee9f8" ? "" : "not ", "ok 4\n"; $cbc = new Crypt::Rijndael $key, Crypt::Rijndael::MODE_CBC; print $cbc->decrypt($crypted) eq $plaintext ? "" : "not ", "ok 5\n"; $plaintext = chr(0) x 16; $j = 0; for ($i=0x00; $i<=0xff; $i += 0x11) { substr($plaintext, $j, 1) = chr($i); $j++; } $key = chr(0) x 32; for ($i=0; $i<32; $i++) { substr($key, $i, 1) = chr($i); } # AES-256 $ecb = new Crypt::Rijndael $key; $crypted = $ecb->encrypt($plaintext); print unpack("H*", $crypted) eq "8ea2b7ca516745bfeafc49904b496089" ? "" : "not ", "ok 6\n"; print $ecb->decrypt($crypted) eq $plaintext ? "" : "not ", "ok 7\n"; # AES-192 $key = substr($key, 0, 24); $ecb = new Crypt::Rijndael $key; $crypted = $ecb->encrypt($plaintext); print unpack("H*", $crypted) eq "dda97ca4864cdfe06eaf70a0ec0d7191" ? "" : "not ", "ok 8\n"; print $ecb->decrypt($crypted) eq $plaintext ? "" : "not ", "ok 9\n"; # AES-128 $key = substr($key, 0, 16); $ecb = new Crypt::Rijndael $key; $crypted = $ecb->encrypt($plaintext); print unpack("H*", $crypted) eq "69c4e0d86a7b0430d8cdb78070b4c55a" ? "" : "not ", "ok 10\n"; print $ecb->decrypt($crypted) eq $plaintext ? "" : "not ", "ok 11\n"; # Modes of operation -- NIST paper tests # ECB-AES-128 $ecb = new Crypt::Rijndael pack("H*", "2b7e151628aed2a6abf7158809cf4f3c"); $plaintext = pack("H*", "6bc1bee22e409f96e93d7e117393172aae2d8a571e03ac9c9eb76fac45af8e5130c81c46a35ce411e5fbc1191a0a52eff69f2445df4f9b17ad2b417be66c3710"); $crypted = $ecb->encrypt($plaintext); print unpack("H*", $crypted) eq "3ad77bb40d7a3660a89ecaf32466ef97f5d3d58503b9699de785895a96fdbaaf43b1cd7f598ece23881b00e3ed0306887b0c785e27e8ad3f8223207104725dd4" ? "" : "not ", "ok 12\n"; print $ecb->decrypt($crypted) eq $plaintext ? "" : "not ", "ok 13\n"; # ECB-AES-192 $ecb = new Crypt::Rijndael pack("H*", "8e73b0f7da0e6452c810f32b809079e562f8ead2522c6b7b"); $plaintext = pack("H*", "6bc1bee22e409f96e93d7e117393172aae2d8a571e03ac9c9eb76fac45af8e5130c81c46a35ce411e5fbc1191a0a52eff69f2445df4f9b17ad2b417be66c3710"); $crypted = $ecb->encrypt($plaintext); print unpack("H*", $crypted) eq "bd334f1d6e45f25ff712a214571fa5cc974104846d0ad3ad7734ecb3ecee4eefef7afd2270e2e60adce0ba2face6444e9a4b41ba738d6c72fb16691603c18e0e" ? "" : "not ", "ok 14\n"; print $ecb->decrypt($crypted) eq $plaintext ? "" : "not ", "ok 15\n"; # ECB-AES-256 $ecb = new Crypt::Rijndael pack("H*", "603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4"); $plaintext = pack("H*", "6bc1bee22e409f96e93d7e117393172aae2d8a571e03ac9c9eb76fac45af8e5130c81c46a35ce411e5fbc1191a0a52eff69f2445df4f9b17ad2b417be66c3710"); $crypted = $ecb->encrypt($plaintext); print unpack("H*", $crypted) eq "f3eed1bdb5d2a03c064b5a7e3db181f8591ccb10d410ed26dc5ba74a31362870b6ed21b99ca6f4f9f153e7b1beafed1d23304b7a39f9f3ff067d8d8f9e24ecc7" ? "" : "not ", "ok 16\n"; print $ecb->decrypt($crypted) eq $plaintext ? "" : "not ", "ok 17\n"; # CBC-AES-128 $cbc = new Crypt::Rijndael pack("H*", "2b7e151628aed2a6abf7158809cf4f3c"), Crypt::Rijndael::MODE_CBC; $cbc->set_iv(pack("H*", "000102030405060708090a0b0c0d0e0f")); $plaintext = pack("H*", "6bc1bee22e409f96e93d7e117393172aae2d8a571e03ac9c9eb76fac45af8e5130c81c46a35ce411e5fbc1191a0a52eff69f2445df4f9b17ad2b417be66c3710"); $crypted = $cbc->encrypt($plaintext); print unpack("H*", $crypted) eq "7649abac8119b246cee98e9b12e9197d5086cb9b507219ee95db113a917678b273bed6b8e3c1743b7116e69e222295163ff1caa1681fac09120eca307586e1a7" ? "" : "not ", "ok 18\n"; print $cbc->decrypt($crypted) eq $plaintext ? "" : "not ", "ok 19\n"; # CBC-AES-192 $cbc = new Crypt::Rijndael pack("H*", "8e73b0f7da0e6452c810f32b809079e562f8ead2522c6b7b"), Crypt::Rijndael::MODE_CBC; $cbc->set_iv(pack("H*", "000102030405060708090a0b0c0d0e0f")); $plaintext = pack("H*", "6bc1bee22e409f96e93d7e117393172aae2d8a571e03ac9c9eb76fac45af8e5130c81c46a35ce411e5fbc1191a0a52eff69f2445df4f9b17ad2b417be66c3710"); $crypted = $cbc->encrypt($plaintext); print unpack("H*", $crypted) eq "4f021db243bc633d7178183a9fa071e8b4d9ada9ad7dedf4e5e738763f69145a571b242012fb7ae07fa9baac3df102e008b0e27988598881d920a9e64f5615cd" ? "" : "not ", "ok 20\n"; print $cbc->decrypt($crypted) eq $plaintext ? "" : "not ", "ok 21\n"; # CBC-AES-192 $cbc = new Crypt::Rijndael pack("H*", "603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4"), Crypt::Rijndael::MODE_CBC; $cbc->set_iv(pack("H*", "000102030405060708090a0b0c0d0e0f")); $plaintext = pack("H*", "6bc1bee22e409f96e93d7e117393172aae2d8a571e03ac9c9eb76fac45af8e5130c81c46a35ce411e5fbc1191a0a52eff69f2445df4f9b17ad2b417be66c3710"); $crypted = $cbc->encrypt($plaintext); print unpack("H*", $crypted) eq "f58c4c04d6e5f1ba779eabfb5f7bfbd69cfc4e967edb808d679f777bc6702c7d39f23369a9d9bacfa530e26304231461b2eb05e2c39be9fcda6c19078c6a9d1b" ? "" : "not ", "ok 22\n"; print $cbc->decrypt($crypted) eq $plaintext ? "" : "not ", "ok 23\n"; # CFB128-AES-128 $cfb = new Crypt::Rijndael pack("H*", "2b7e151628aed2a6abf7158809cf4f3c"), Crypt::Rijndael::MODE_CFB; $cfb->set_iv(pack("H*", "000102030405060708090a0b0c0d0e0f")); $plaintext = pack("H*", "6bc1bee22e409f96e93d7e117393172aae2d8a571e03ac9c9eb76fac45af8e5130c81c46a35ce411e5fbc1191a0a52eff69f2445df4f9b17ad2b417be66c3710"); $crypted = $cfb->encrypt($plaintext); print unpack("H*", $crypted) eq "3b3fd92eb72dad20333449f8e83cfb4ac8a64537a0b3a93fcde3cdad9f1ce58b26751f67a3cbb140b1808cf187a4f4dfc04b05357c5d1c0eeac4c66f9ff7f2e6" ? "" : "not ", "ok 24\n"; print $cfb->decrypt($crypted) eq $plaintext ? "" : "not ", "ok 25\n"; # CFB128-AES-192 $cfb = new Crypt::Rijndael pack("H*", "8e73b0f7da0e6452c810f32b809079e562f8ead2522c6b7b"), Crypt::Rijndael::MODE_CFB; $cfb->set_iv(pack("H*", "000102030405060708090a0b0c0d0e0f")); $plaintext = pack("H*", "6bc1bee22e409f96e93d7e117393172aae2d8a571e03ac9c9eb76fac45af8e5130c81c46a35ce411e5fbc1191a0a52eff69f2445df4f9b17ad2b417be66c3710"); $crypted = $cfb->encrypt($plaintext); print unpack("H*", $crypted) eq "cdc80d6fddf18cab34c25909c99a417467ce7f7f81173621961a2b70171d3d7a2e1e8a1dd59b88b1c8e60fed1efac4c9c05f9f9ca9834fa042ae8fba584b09ff" ? "" : "not ", "ok 26\n"; print $cfb->decrypt($crypted) eq $plaintext ? "" : "not ", "ok 27\n"; # CFB128-AES-256 $cfb = new Crypt::Rijndael pack("H*", "603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4"), Crypt::Rijndael::MODE_CFB; $cfb->set_iv(pack("H*", "000102030405060708090a0b0c0d0e0f")); $plaintext = pack("H*", "6bc1bee22e409f96e93d7e117393172aae2d8a571e03ac9c9eb76fac45af8e5130c81c46a35ce411e5fbc1191a0a52eff69f2445df4f9b17ad2b417be66c3710"); $crypted = $cfb->encrypt($plaintext); print unpack("H*", $crypted) eq "dc7e84bfda79164b7ecd8486985d386039ffed143b28b1c832113c6331e5407bdf10132415e54b92a13ed0a8267ae2f975a385741ab9cef82031623d55b1e471" ? "" : "not ", "ok 28\n"; print $cfb->decrypt($crypted) eq $plaintext ? "" : "not ", "ok 29\n"; # OFB-AES-128 $ofb = new Crypt::Rijndael pack("H*", "2b7e151628aed2a6abf7158809cf4f3c"), Crypt::Rijndael::MODE_OFB; $ofb->set_iv(pack("H*", "000102030405060708090a0b0c0d0e0f")); $plaintext = pack("H*", "6bc1bee22e409f96e93d7e117393172aae2d8a571e03ac9c9eb76fac45af8e5130c81c46a35ce411e5fbc1191a0a52eff69f2445df4f9b17ad2b417be66c3710"); $crypted = $ofb->encrypt($plaintext); print unpack("H*", $crypted) eq "3b3fd92eb72dad20333449f8e83cfb4a7789508d16918f03f53c52dac54ed8259740051e9c5fecf64344f7a82260edcc304c6528f659c77866a510d9c1d6ae5e" ? "" : "not ", "ok 30\n"; print $ofb->decrypt($crypted) eq $plaintext ? "" : "not ", "ok 31\n"; # OFB-AES-192 $ofb = new Crypt::Rijndael pack("H*", "8e73b0f7da0e6452c810f32b809079e562f8ead2522c6b7b"), Crypt::Rijndael::MODE_OFB; $ofb->set_iv(pack("H*", "000102030405060708090a0b0c0d0e0f")); $plaintext = pack("H*", "6bc1bee22e409f96e93d7e117393172aae2d8a571e03ac9c9eb76fac45af8e5130c81c46a35ce411e5fbc1191a0a52eff69f2445df4f9b17ad2b417be66c3710"); $crypted = $ofb->encrypt($plaintext); print unpack("H*", $crypted) eq "cdc80d6fddf18cab34c25909c99a4174fcc28b8d4c63837c09e81700c11004018d9a9aeac0f6596f559c6d4daf59a5f26d9f200857ca6c3e9cac524bd9acc92a" ? "" : "not ", "ok 32\n"; print $ofb->decrypt($crypted) eq $plaintext ? "" : "not ", "ok 33\n"; # OFB-AES-256 $ofb = new Crypt::Rijndael pack("H*", "603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4"), Crypt::Rijndael::MODE_OFB; $ofb->set_iv(pack("H*", "000102030405060708090a0b0c0d0e0f")); $plaintext = pack("H*", "6bc1bee22e409f96e93d7e117393172aae2d8a571e03ac9c9eb76fac45af8e5130c81c46a35ce411e5fbc1191a0a52eff69f2445df4f9b17ad2b417be66c3710"); $crypted = $ofb->encrypt($plaintext); print unpack("H*", $crypted) eq "dc7e84bfda79164b7ecd8486985d38604febdc6740d20b3ac88f6ad82a4fb08d71ab47a086e86eedf39d1c5bba97c4080126141d67f37be8538f5a8be740e484" ? "" : "not ", "ok 34\n"; print $ofb->decrypt($crypted) eq $plaintext ? "" : "not ", "ok 35\n"; # CTR-AES-128 $ctr = new Crypt::Rijndael pack("H*", "2b7e151628aed2a6abf7158809cf4f3c"), Crypt::Rijndael::MODE_CTR; $ctr->set_iv(pack("H*", "f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff")); $plaintext = pack("H*", "6bc1bee22e409f96e93d7e117393172aae2d8a571e03ac9c9eb76fac45af8e5130c81c46a35ce411e5fbc1191a0a52eff69f2445df4f9b17ad2b417be66c3710"); $crypted = $ctr->encrypt($plaintext); print unpack("H*", $crypted) eq "874d6191b620e3261bef6864990db6ce9806f66b7970fdff8617187bb9fffdff5ae4df3edbd5d35e5b4f09020db03eab1e031dda2fbe03d1792170a0f3009cee" ? "" : "not ", "ok 36\n"; print $ctr->decrypt($crypted) eq $plaintext ? "" : "not ", "ok 37\n"; # CTR-AES-192 $ctr = new Crypt::Rijndael pack("H*", "8e73b0f7da0e6452c810f32b809079e562f8ead2522c6b7b"), Crypt::Rijndael::MODE_CTR; $ctr->set_iv(pack("H*", "f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff")); $plaintext = pack("H*", "6bc1bee22e409f96e93d7e117393172aae2d8a571e03ac9c9eb76fac45af8e5130c81c46a35ce411e5fbc1191a0a52eff69f2445df4f9b17ad2b417be66c3710"); $crypted = $ctr->encrypt($plaintext); print unpack("H*", $crypted) eq "1abc932417521ca24f2b0459fe7e6e0b090339ec0aa6faefd5ccc2c6f4ce8e941e36b26bd1ebc670d1bd1d665620abf74f78a7f6d29809585a97daec58c6b050" ? "" : "not ", "ok 38\n"; print $ctr->decrypt($crypted) eq $plaintext ? "" : "not ", "ok 39\n"; # CTR-AES-256 $ctr = new Crypt::Rijndael pack("H*", "603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4"), Crypt::Rijndael::MODE_CTR; $ctr->set_iv(pack("H*", "f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff")); $plaintext = pack("H*", "6bc1bee22e409f96e93d7e117393172aae2d8a571e03ac9c9eb76fac45af8e5130c81c46a35ce411e5fbc1191a0a52eff69f2445df4f9b17ad2b417be66c3710"); $crypted = $ctr->encrypt($plaintext); print unpack("H*", $crypted) eq "601ec313775789a5b7a7f504bbf3d228f443e3ca4d62b59aca84e990cacaf5c52b0930daa23de94ce87017ba2d84988ddfc9c58db67aada613c2dd08457941a6" ? "" : "not ", "ok 40\n"; print $ctr->decrypt($crypted) eq $plaintext ? "" : "not ", "ok 41\n"; Crypt-Rijndael-1.12/t/blocksize.t000644 000765 000024 00000000233 12261635541 017142 0ustar00brianstaff000000 000000 #!/usr/bin/perl use Test::More 'no_plan'; use_ok( 'Crypt::Rijndael' ); ok( defined &Crypt::Rijndael::blocksize ); is( Crypt::Rijndael->blocksize, 16 );Crypt-Rijndael-1.12/t/cbc.t000644 000765 000024 00000000701 12261635541 015704 0ustar00brianstaff000000 000000 #!/usr/bin/perl use Cwd; use File::Spec; use Test::More 'no_plan'; require_ok( File::Spec->catfile( cwd(), qw( t lib mode.pl ) ) ); use_ok( 'Crypt::Rijndael' ); ok( defined &Crypt::Rijndael::MODE_CBC ); diag( "MODE_CBC is @{ [Crypt::Rijndael::MODE_CBC()] }" ) if $ENV{DEBUG}; foreach my $a ( 0 .. 10 ) { my $hash = crypt_decrypt( Crypt::Rijndael::MODE_CBC() ); is( $hash->{plain}, $hash->{data}, "Decrypted text matches plain text" ); }Crypt-Rijndael-1.12/t/cfb.t000644 000765 000024 00000000702 12261635541 015710 0ustar00brianstaff000000 000000 #!/usr/bin/perl use Cwd; use File::Spec; use Test::More 'no_plan'; require_ok( File::Spec->catfile( cwd(), qw( t lib mode.pl ) ) ); use_ok( 'Crypt::Rijndael' ); ok( defined &Crypt::Rijndael::MODE_CFB ); diag( "MODE_CBFB is @{ [Crypt::Rijndael::MODE_CFB()] }" ) if $ENV{DEBUG}; foreach my $a ( 0 .. 10 ) { my $hash = crypt_decrypt( Crypt::Rijndael::MODE_CFB() ); is( $hash->{plain}, $hash->{data}, "Decrypted text matches plain text" ); }Crypt-Rijndael-1.12/t/ctr.t000644 000765 000024 00000000701 12261635541 015745 0ustar00brianstaff000000 000000 #!/usr/bin/perl use Cwd; use File::Spec; use Test::More 'no_plan'; require_ok( File::Spec->catfile( cwd(), qw( t lib mode.pl ) ) ); use_ok( 'Crypt::Rijndael' ); ok( defined &Crypt::Rijndael::MODE_CTR ); diag( "MODE_CTR is @{ [Crypt::Rijndael::MODE_CTR()] }" ) if $ENV{DEBUG}; foreach my $a ( 0 .. 10 ) { my $hash = crypt_decrypt( Crypt::Rijndael::MODE_CTR() ); is( $hash->{plain}, $hash->{data}, "Decrypted text matches plain text" ); }Crypt-Rijndael-1.12/t/ecb.t000644 000765 000024 00000000701 12261635541 015706 0ustar00brianstaff000000 000000 #!/usr/bin/perl use Cwd; use File::Spec; use Test::More 'no_plan'; require_ok( File::Spec->catfile( cwd(), qw( t lib mode.pl ) ) ); use_ok( 'Crypt::Rijndael' ); ok( defined &Crypt::Rijndael::MODE_ECB ); diag( "MODE_ECB is @{ [Crypt::Rijndael::MODE_ECB()] }" ) if $ENV{DEBUG}; foreach my $a ( 0 .. 10 ) { my $hash = crypt_decrypt( Crypt::Rijndael::MODE_ECB() ); is( $hash->{plain}, $hash->{data}, "Decrypted text matches plain text" ); }Crypt-Rijndael-1.12/t/lib/000755 000765 000024 00000000000 12261635542 015541 5ustar00brianstaff000000 000000 Crypt-Rijndael-1.12/t/ofb.t000644 000765 000024 00000000701 12261635541 015723 0ustar00brianstaff000000 000000 #!/usr/bin/perl use Cwd; use File::Spec; use Test::More 'no_plan'; require_ok( File::Spec->catfile( cwd(), qw( t lib mode.pl ) ) ); use_ok( 'Crypt::Rijndael' ); ok( defined &Crypt::Rijndael::MODE_OFB ); diag( "MODE_OFB is @{ [Crypt::Rijndael::MODE_OFB()] }" ) if $ENV{DEBUG}; foreach my $a ( 0 .. 10 ) { my $hash = crypt_decrypt( Crypt::Rijndael::MODE_OFB() ); is( $hash->{plain}, $hash->{data}, "Decrypted text matches plain text" ); }Crypt-Rijndael-1.12/t/pcbc.t000644 000765 000024 00000001041 12261635541 016062 0ustar00brianstaff000000 000000 #!/usr/bin/perl use Cwd; use File::Spec; use Test::More 'no_plan'; require_ok( File::Spec->catfile( cwd(), qw( t lib mode.pl ) ) ); use_ok( 'Crypt::Rijndael' ); ok( defined &Crypt::Rijndael::MODE_PCBC ); diag( "MODE_PCBC is @{ [Crypt::Rijndael::MODE_PCBC()] }" ) if $ENV{DEBUG}; TODO: { local $TODO = "PCBC is not a legal mode (yet)"; my $value = eval { foreach my $a ( 0 .. 10 ) { my $hash = crypt_decrypt( Crypt::Rijndael::MODE_PCBC() ); is( $hash->{plain}, $hash->{data}, "Decrypted text matches plain text" ); } }; };Crypt-Rijndael-1.12/t/pod.t000644 000765 000024 00000000200 12261635541 015731 0ustar00brianstaff000000 000000 use Test::More; eval "use Test::Pod 1.00"; plan skip_all => "Test::Pod 1.00 required for testing POD" if $@; all_pod_files_ok();Crypt-Rijndael-1.12/t/pod_coverage.t000644 000765 000024 00000000240 12261635541 017610 0ustar00brianstaff000000 000000 use Test::More; eval "use Test::Pod::Coverage 1.00"; plan skip_all => "Test::Pod::Coverage 1.00 required for testing POD coverage" if $@; all_pod_coverage_ok();Crypt-Rijndael-1.12/t/rt/000755 000765 000024 00000000000 12261635542 015420 5ustar00brianstaff000000 000000 Crypt-Rijndael-1.12/t/test_manifest000644 000765 000024 00000000172 12261635541 017562 0ustar00brianstaff000000 000000 # $Id$ 00_load.t pod.t pod_coverage.t blocksize.t cbc.t cfb.t ctr.t ecb.t ofb.t pcbc.t #ref/cbc_d_m.t rt/27632.t #bad_iv.tCrypt-Rijndael-1.12/t/rt/27632.t000644 000765 000024 00000002020 12261635541 016261 0ustar00brianstaff000000 000000 #!/usr/bin/perl use strict; use Crypt::Rijndael; use Digest::MD5 qw(md5_hex); use Test::More 'no_plan'; my $class = 'Crypt::Rijndael'; my $key = 'abcdefghijklmnop'; my $in_plain = 'a' x 32; my $cipher = $class->new( $key, Crypt::Rijndael::MODE_CBC ); isa_ok( $cipher, $class ); $cipher->set_iv('a' x 16); # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # encrypt diag( "-" x 50 ) if $ENV{DEBUG}; my $crypt = $cipher->encrypt( $in_plain ); diag( "Plain text: [$in_plain]" ) if $ENV{DEBUG}; diag( "Crypt text: [$crypt]" ) if $ENV{DEBUG}; my $digest = md5_hex( $crypt ); diag( "MD5 digest of crypt: [$digest]" ) if $ENV{DEBUG}; # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # decrypt to see if we get back the same thing { diag( "-" x 50 ) if $ENV{DEBUG}; my $out_plain = $cipher->decrypt( $crypt ); diag( "Crypt text: [$crypt]" ) if $ENV{DEBUG}; diag( "Plain text: [$out_plain]" ) if $ENV{DEBUG}; is( $out_plain, $in_plain, "Text comes back correctly" ); }Crypt-Rijndael-1.12/t/lib/mode.pl000644 000765 000024 00000000750 12261635541 017023 0ustar00brianstaff000000 000000 use Crypt::Rijndael; sub crypt_decrypt { my( $mode ) = @_; my $key = make_string( 32 ); my $c = Crypt::Rijndael->new( $key, $mode ); my $data = make_string( 32 * int( rand(16) + 1 ) ); my $cipher = $c->encrypt( $data ); my $plain = $c->decrypt( $cipher ); return { data => $data, cipher => $cipher, plain => $plain, }; } sub make_string { my $size = shift; my $res; while( $size-- > 0 ) { $res .= pack 'C', rand 256; } $res; } 1;Crypt-Rijndael-1.12/examples/README000644 000765 000024 00000000105 12261635541 017221 0ustar00brianstaff000000 000000 See the tests in the t/ directory for examples until I add some more.