Filter-Rijndael
view release on metacpan or search on metacpan
Rijndael.xs view on Meta::CPAN
for( i = 0; i < shadsize(state); i++ )
if( checksum[i] != ( result[i] & 0x000000FF ) )
croak( (unsigned char *)unknown_file_type );
shaclose(state);
/* set back file position */
PerlIO_seek( PL_rsfp, current_location, 0 );
/* initialize Rijndael */
ctx.mode = MODE_CBC;
memset( iv, 0, BLOCKSIZE );
rijndael_setup( &ctx, KEYSIZE, KEY );
}
static void
postDecrypt()
{
}
static I32
_rijndael.c view on Meta::CPAN
nblocks = inputlen / RIJNDAEL_BLOCKSIZE;
switch (ctx->mode) {
case MODE_ECB: /* electronic code book */
for (i = 0; i<nblocks; i++) {
rijndael_encrypt(ctx, &input[RIJNDAEL_BLOCKSIZE*i],
&output[RIJNDAEL_BLOCKSIZE*i]);
}
break;
case MODE_CBC: /* Cipher block chaining */
/* set initial value */
memcpy(block, iv, RIJNDAEL_BLOCKSIZE);
for (i=0; i< nblocks; i++) {
for (j=0; j<RIJNDAEL_BLOCKSIZE; j++)
block[j] ^= input[i*RIJNDAEL_BLOCKSIZE + j] & 0xff;
rijndael_encrypt(ctx, block, block);
memcpy(&output[RIJNDAEL_BLOCKSIZE*i], block, RIJNDAEL_BLOCKSIZE);
}
break;
case MODE_CFB: /* 128-bit cipher feedback */
_rijndael.c view on Meta::CPAN
UINT8 block[RIJNDAEL_BLOCKSIZE], block2[RIJNDAEL_BLOCKSIZE];
nblocks = inputlen / RIJNDAEL_BLOCKSIZE;
switch (ctx->mode) {
case MODE_ECB:
for (i = 0; i<nblocks; i++) {
rijndael_decrypt(ctx, &input[RIJNDAEL_BLOCKSIZE*i],
&output[RIJNDAEL_BLOCKSIZE*i]);
}
break;
case MODE_CBC:
/* first block */
rijndael_decrypt(ctx, input, block);
/* XOR the block with the IV to get the output */
for (i=0; i<RIJNDAEL_BLOCKSIZE; i++)
output[i] = block[i] ^ iv[i];
for (i=1; i<nblocks; i++) {
rijndael_decrypt(ctx, &input[i*RIJNDAEL_BLOCKSIZE], block);
for (j=0; j<RIJNDAEL_BLOCKSIZE; j++) {
output[i*RIJNDAEL_BLOCKSIZE + j] = block[j] ^
input[(i-1)*RIJNDAEL_BLOCKSIZE + j];
_rijndael.h view on Meta::CPAN
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 */
bin/encrypt.pl view on Meta::CPAN
use Crypt::Rijndael;
use Digest::SHA qw( sha1_hex );
my $blocksize = 16;
my $headersize = 6;
my $fingerprint = pack( 'C*', 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 );
my $cipher = Crypt::Rijndael->new(
pack( 'C*', 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ),
Crypt::Rijndael::MODE_CBC()
);
my $module_name = 'Filter::Rijndael';
die sprintf( "Usage: $0 <file>\n" ) if( ! scalar( @ARGV ) );
my $infile = $ARGV[0];
my $outfile = $ARGV[1] // sprintf( '%s.pe', $infile );
if ( ! -T $infile ) {
print "Skipping directory $infile\n" if( -d $infile );
( run in 0.601 second using v1.01-cache-2.11-cpan-df04353d9ac )