Script 'mail_helper' called by obssrc Hello community, here is the log from the commit of package perl-Crypt-Rijndael for openSUSE:Factory checked in at 2021-04-15 16:56:58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/perl-Crypt-Rijndael (Old) and /work/SRC/openSUSE:Factory/.perl-Crypt-Rijndael.new.12324 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "perl-Crypt-Rijndael" Thu Apr 15 16:56:58 2021 rev:17 rq:884587 version:1.16 Changes: -------- --- /work/SRC/openSUSE:Factory/perl-Crypt-Rijndael/perl-Crypt-Rijndael.changes 2020-10-15 13:46:43.921207617 +0200 +++ /work/SRC/openSUSE:Factory/.perl-Crypt-Rijndael.new.12324/perl-Crypt-Rijndael.changes 2021-04-15 16:57:09.574649830 +0200 @@ -1,0 +2,10 @@ +Fri Apr 2 03:06:16 UTC 2021 - Tina M??ller <timueller+p...@suse.de> + +- updated to 1.16 + see /usr/share/doc/packages/perl-Crypt-Rijndael/Changes + + 1.16 - 2021-04-01 + * Add non-blocksized encoding support to streaming modes + * Explicitly use downgraded strings + +------------------------------------------------------------------- Old: ---- Crypt-Rijndael-1.15.tar.gz New: ---- Crypt-Rijndael-1.16.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ perl-Crypt-Rijndael.spec ++++++ --- /var/tmp/diff_new_pack.wSwHiw/_old 2021-04-15 16:57:09.994650494 +0200 +++ /var/tmp/diff_new_pack.wSwHiw/_new 2021-04-15 16:57:09.998650501 +0200 @@ -1,7 +1,7 @@ # # spec file for package perl-Crypt-Rijndael # -# Copyright (c) 2020 SUSE LLC +# Copyright (c) 2021 SUSE LLC # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -16,18 +16,16 @@ # +%define cpan_name Crypt-Rijndael Name: perl-Crypt-Rijndael -Version: 1.15 +Version: 1.16 Release: 0 #Upstream: SUSE-Public-Domain -%define cpan_name Crypt-Rijndael Summary: Crypt::CBC compliant Rijndael encryption module License: LGPL-3.0-only -Group: Development/Libraries/Perl URL: https://metacpan.org/release/%{cpan_name} Source0: https://cpan.metacpan.org/authors/id/L/LE/LEONT/%{cpan_name}-%{version}.tar.gz Source1: cpanspec.yml -BuildRoot: %{_tmppath}/%{name}-%{version}-build BuildRequires: perl BuildRequires: perl-macros %{perl_requires} @@ -76,11 +74,11 @@ Decrypts '$data'. %prep -%setup -q -n %{cpan_name}-%{version} +%autosetup -n %{cpan_name}-%{version} %build perl Makefile.PL INSTALLDIRS=vendor OPTIMIZE="%{optflags}" -make %{?_smp_mflags} +%make_build %check make test @@ -91,7 +89,6 @@ %perl_gen_filelist %files -f %{name}.files -%defattr(-,root,root,755) %doc Changes NEWS README %license COPYING LICENSE ++++++ Crypt-Rijndael-1.15.tar.gz -> Crypt-Rijndael-1.16.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Crypt-Rijndael-1.15/Changes new/Crypt-Rijndael-1.16/Changes --- old/Crypt-Rijndael-1.15/Changes 2020-10-10 21:27:33.000000000 +0200 +++ new/Crypt-Rijndael-1.16/Changes 2021-04-01 23:32:23.000000000 +0200 @@ -1,5 +1,9 @@ Revision history for Perl module Crypt::Rijndael +1.16 - 2021-04-01 + * Add non-blocksized encoding support to streaming modes + * Explicitly use downgraded strings + 1.15 - 2020-10-10 * Use standard uint8_t and uint32_t from stdint.h diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Crypt-Rijndael-1.15/MANIFEST new/Crypt-Rijndael-1.16/MANIFEST --- old/Crypt-Rijndael-1.15/MANIFEST 2015-05-28 01:57:38.000000000 +0200 +++ new/Crypt-Rijndael-1.16/MANIFEST 2021-04-01 23:34:04.000000000 +0200 @@ -5,11 +5,8 @@ Makefile.PL MANIFEST This list of files MANIFEST.SKIP -META.json Module JSON meta-data (added by MakeMaker) -META.yml Module YAML meta-data (added by MakeMaker) NEWS ppport.h -README rijndael.h Rijndael.pm Rijndael.xs @@ -17,3 +14,5 @@ t/modes.t t/rt/27632.t typemap +META.yml Module YAML meta-data (added by MakeMaker) +META.json Module JSON meta-data (added by MakeMaker) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Crypt-Rijndael-1.15/META.json new/Crypt-Rijndael-1.16/META.json --- old/Crypt-Rijndael-1.15/META.json 2020-10-10 21:30:20.000000000 +0200 +++ new/Crypt-Rijndael-1.16/META.json 2021-04-01 23:34:04.000000000 +0200 @@ -55,6 +55,6 @@ "web" : "https://github.com/leont/crypt-rijndael" } }, - "version" : "1.15", + "version" : "1.16", "x_serialization_backend" : "JSON::PP version 4.04" } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Crypt-Rijndael-1.15/META.yml new/Crypt-Rijndael-1.16/META.yml --- old/Crypt-Rijndael-1.15/META.yml 2020-10-10 21:30:20.000000000 +0200 +++ new/Crypt-Rijndael-1.16/META.yml 2021-04-01 23:34:03.000000000 +0200 @@ -26,5 +26,5 @@ bugtracker: https://github.com/leont/crypt-rijndael/issues homepage: https://github.com/leont/crypt-rijndael repository: https://github.com/leont/crypt-rijndael.git -version: '1.15' +version: '1.16' x_serialization_backend: 'CPAN::Meta::YAML version 0.018' diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Crypt-Rijndael-1.15/README new/Crypt-Rijndael-1.16/README --- old/Crypt-Rijndael-1.15/README 2020-10-10 21:30:20.000000000 +0200 +++ new/Crypt-Rijndael-1.16/README 2021-04-01 23:34:04.000000000 +0200 @@ -2,7 +2,7 @@ Crypt::Rijndael - Crypt::CBC compliant Rijndael encryption module VERSION - Version 1.14 + Version 1.16 SYNOPSIS use Crypt::Rijndael; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Crypt-Rijndael-1.15/Rijndael.pm new/Crypt-Rijndael-1.16/Rijndael.pm --- old/Crypt-Rijndael-1.15/Rijndael.pm 2020-10-10 21:28:31.000000000 +0200 +++ new/Crypt-Rijndael-1.16/Rijndael.pm 2021-04-01 23:32:52.000000000 +0200 @@ -3,7 +3,7 @@ use strict; use warnings; -our $VERSION = '1.15'; +our $VERSION = '1.16'; use XSLoader; @@ -19,7 +19,7 @@ =head1 VERSION -Version 1.14 +Version 1.16 =head1 SYNOPSIS diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Crypt-Rijndael-1.15/Rijndael.xs new/Crypt-Rijndael-1.16/Rijndael.xs --- old/Crypt-Rijndael-1.15/Rijndael.xs 2020-10-10 21:27:06.000000000 +0200 +++ new/Crypt-Rijndael-1.16/Rijndael.xs 2021-04-01 23:31:51.000000000 +0200 @@ -32,9 +32,10 @@ typedef struct cryptstate { RIJNDAEL_context ctx; uint8_t iv[RIJNDAEL_BLOCKSIZE]; - int mode; } *Crypt__Rijndael; +typedef const char* IVEC; + MODULE = Crypt::Rijndael PACKAGE = Crypt::Rijndael PROTOTYPES: DISABLE @@ -58,49 +59,40 @@ SV * class SV * key int mode - CODE: - { + PREINIT: STRLEN keysize; - - if (!SvPOK (key)) - Perl_croak(aTHX_ "key must be an untainted string scalar"); + CODE: + if (!SvPOK(key)) + Perl_croak(aTHX_ "Key must be an string scalar"); + if (SvTAINTED(key)) + Perl_croak(aTHX_ "Key must be untainted"); keysize = SvCUR(key); if (keysize != 16 && keysize != 24 && keysize != 32) - Perl_croak(aTHX_ "wrong key length: key must be 128, 192 or 256 bits long"); + Perl_croak(aTHX_ "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) - Perl_croak(aTHX_ "illegal mode, see documentation for valid modes"); + Perl_croak(aTHX_ "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 */ - Zero(RETVAL->iv, RIJNDAEL_BLOCKSIZE, char); - rijndael_setup(&RETVAL->ctx, keysize, (uint8_t *) SvPV_nolen(key)); - } + Newxz(RETVAL, 1, struct cryptstate); + RETVAL->ctx.mode = mode; + rijndael_setup(&RETVAL->ctx, keysize, (uint8_t *) SvPVbyte_nolen(key)); OUTPUT: RETVAL SV * set_iv(self, data) Crypt::Rijndael self - SV * data - + IVEC data CODE: - { - SV *res; - STRLEN size; - void *rawbytes = SvPV(data,size); + Copy(data, self->iv, RIJNDAEL_BLOCKSIZE, char); - if( size != RIJNDAEL_BLOCKSIZE ) - Perl_croak(aTHX_ "set_iv: initial value must be the blocksize (%d bytes), but was %d bytes", RIJNDAEL_BLOCKSIZE, size); - Copy(rawbytes, self->iv, RIJNDAEL_BLOCKSIZE, char); - } SV * -encrypt(self, data) +encrypt(self, data, iv = self->iv) Crypt::Rijndael self SV * data + IVEC iv ALIAS: decrypt = 1 @@ -108,20 +100,20 @@ { SV *res; STRLEN size; - void *rawbytes = SvPV(data,size); + void *rawbytes = SvPVbyte(data,size); if (size) { uint8_t* buffer; - if (size % RIJNDAEL_BLOCKSIZE) + if ((self->ctx.mode == MODE_ECB || self->ctx.mode == MODE_CBC) && size % RIJNDAEL_BLOCKSIZE) Perl_croak(aTHX_ "encrypt: datasize not multiple of blocksize (%d bytes)", RIJNDAEL_BLOCKSIZE); RETVAL = newSV(size); SvPOK_only(RETVAL); SvCUR_set(RETVAL, size); - buffer = (uint8_t *)SvPV_nolen(RETVAL); + buffer = (uint8_t *)SvPVbyte_nolen(RETVAL); (ix ? block_decrypt : block_encrypt) - (&self->ctx, rawbytes, size, buffer, self->iv); + (&self->ctx, rawbytes, size, buffer, iv); buffer[size] = '\0'; } else diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Crypt-Rijndael-1.15/_rijndael.c new/Crypt-Rijndael-1.16/_rijndael.c --- old/Crypt-Rijndael-1.15/_rijndael.c 2020-10-10 21:27:06.000000000 +0200 +++ new/Crypt-Rijndael-1.16/_rijndael.c 2021-04-01 23:31:51.000000000 +0200 @@ -41,7 +41,7 @@ that we can perform a round's encryption or by means of four table lookups and four XOR's per column of state. They were generated by the makertbls.pl script. */ -uint32_t dtbl[] = { +static const uint32_t dtbl[] = { 0xa56363c6, 0x847c7cf8, 0x997777ee, 0x8d7b7bf6, 0x0df2f2ff, 0xbd6b6bd6, 0xb16f6fde, 0x54c5c591, 0x50303060, 0x03010102, 0xa96767ce, 0x7d2b2b56, @@ -108,7 +108,7 @@ 0xcbb0b07b, 0xfc5454a8, 0xd6bbbb6d, 0x3a16162c, }; -uint32_t itbl[] = { +static const uint32_t itbl[] = { 0x50a7f451, 0x5365417e, 0xc3a4171a, 0x965e273a, 0xcb6bab3b, 0xf1459d1f, 0xab58faac, 0x9303e34b, 0x55fa3020, 0xf66d76ad, 0x9176cc88, 0x254c02f5, @@ -177,7 +177,7 @@ /* Needed only for the key schedule and for final rounds */ -uint8_t sbox[256] = { +static const uint8_t sbox[256] = { 99, 124, 119, 123, 242, 107, 111, 197, 48, 1, 103, 43, 254, 215, 171, 118, 202, 130, 201, 125, 250, 89, 71, 240, 173, 212, 162, 175, 156, 164, 114, 192, 183, 253, 147, 38, 54, 63, 247, 204, 52, 165, 229, 241, 113, @@ -198,7 +198,7 @@ 22, }; -uint8_t isbox[256] = { +static const uint8_t isbox[256] = { 82, 9, 106, 213, 48, 54, 165, 56, 191, 64, 163, 158, 129, 243, 215, 251, 124, 227, 57, 130, 155, 47, 255, 135, 52, 142, 67, 68, 196, 222, 233, 203, 84, 123, 148, 50, 166, 194, 35, 61, 238, 76, 149, 11, 66, @@ -220,7 +220,7 @@ }; /* Used only by the key schedule */ -uint8_t Logtable[256] = { +static const uint8_t Logtable[256] = { 0, 0, 25, 1, 50, 2, 26, 198, 75, 199, 27, 104, 51, 238, 223, 3, 100, 4, 224, 14, 52, 141, 129, 239, 76, 113, 8, 200, 248, 105, 28, 193, 125, 194, 29, 181, 249, 185, 39, 106, 77, 228, 166, 114, 154, 201, @@ -240,7 +240,7 @@ 74, 237, 222, 197, 49, 254, 24, 13, 99, 140, 128, 192, 247, 112, 7, }; -uint8_t Alogtable[256] = { +static const uint8_t Alogtable[256] = { 1, 3, 5, 15, 17, 51, 85, 255, 26, 46, 114, 150, 161, 248, 19, 53, 95, 225, 56, 72, 216, 115, 149, 164, 247, 2, 6, 10, 30, 34, 102, 170, 229, 52, 92, 228, 55, 89, 235, 38, 106, 190, 217, 112, 144, @@ -267,9 +267,7 @@ ((box)[(((x) >> 16) & 0xff)] << 16) | \ ((box)[(((x) >> 24) & 0xff)] << 24)) -static uint8_t -xtime(uint8_t a) -{ +static uint8_t xtime(uint8_t a) { uint8_t b; b = (a & 0x80) ? 0x1b : 0; @@ -278,16 +276,12 @@ return(a); } -static uint8_t -mul(uint8_t a, uint8_t b) -{ +static uint8_t mul(uint8_t a, uint8_t b) { if (a && b) return Alogtable[(Logtable[a] + Logtable[b])%255]; else return 0; } -static void -inv_mix_column(uint32_t *a, uint32_t *b) -{ +static void inv_mix_column(const uint32_t *a, uint32_t *b) { uint8_t c[4][4]; int i, j; @@ -306,9 +300,7 @@ } } -void -rijndael_setup(RIJNDAEL_context *ctx, size_t keysize, const uint8_t *key) -{ +void rijndael_setup(RIJNDAEL_context *ctx, size_t keysize, const uint8_t *key) { int nk, nr, i, lastkey; uint32_t temp, rcon; @@ -352,9 +344,7 @@ } /* Key addition that also packs every byte in the key to a word rep. */ -static void -key_addition_8to32(const uint8_t *txt, uint32_t *keys, uint32_t *out) -{ +static void key_addition_8to32(const uint8_t *txt, const uint32_t *keys, uint32_t *out) { const uint8_t *ptr; int i, j; uint32_t val; @@ -368,18 +358,14 @@ } } -static void -key_addition32(const uint32_t *txt, uint32_t *keys, uint32_t *out) -{ +static void key_addition32(const uint32_t *txt, const uint32_t *keys, uint32_t *out) { int i; for (i=0; i<4; i++) out[i] = keys[i] ^ txt[i]; } -static void -key_addition32to8(const uint32_t *txt, uint32_t *keys, uint8_t *out) -{ +static void key_addition32to8(const uint32_t *txt, const uint32_t *keys, uint8_t *out) { uint8_t *ptr; int i, j; uint32_t val; @@ -398,11 +384,19 @@ { 2, 3, 0, 1 }, { 3, 0, 1, 2 } }; -void -rijndael_encrypt(RIJNDAEL_context *ctx, - const uint8_t *plaintext, - uint8_t *ciphertext) -{ +/* + * 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. + */ + +static void rijndael_encrypt(const RIJNDAEL_context *ctx, const uint8_t *plaintext, uint8_t *ciphertext) { int r, j; uint32_t wtxt[4], t[4]; /* working ciphertext */ uint32_t e; @@ -437,11 +431,20 @@ { 2, 3, 0, 1 }, { 1, 2, 3, 0 } }; -void -rijndael_decrypt(RIJNDAEL_context *ctx, - const uint8_t *ciphertext, - uint8_t *plaintext) -{ +/* + * 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. + */ + +static void rijndael_decrypt(const RIJNDAEL_context *ctx, const uint8_t *ciphertext, uint8_t *plaintext) { int r, j; uint32_t wtxt[4], t[4]; /* working ciphertext */ uint32_t e; @@ -470,145 +473,181 @@ key_addition32to8(t, &(ctx->ikeys[0]), plaintext); } -void -block_encrypt(RIJNDAEL_context *ctx, uint8_t *input, int inputlen, - uint8_t *output, uint8_t *iv) -{ - int i, j, nblocks, carry_flg; - uint8_t block[RIJNDAEL_BLOCKSIZE], block2[RIJNDAEL_BLOCKSIZE], oldptxt; +static void xor_block_with(const uint8_t* input, uint8_t* output) { + int j; + for (j=0; j<RIJNDAEL_BLOCKSIZE; j++) + output[j] ^= input[j]; +} + +static void xor_block_to(const uint8_t* block, const uint8_t* input, uint8_t* output) { + int j; + for (j=0; j<RIJNDAEL_BLOCKSIZE; j++) + output[j] = block[j] ^ input[j]; +} + +static void xor_bytes_to(const uint8_t* block, const uint8_t* input, size_t inputlen, uint8_t* output) { + int j; + for (j=0; j<inputlen; j++) + output[j] = block[j] ^ input[j]; +} + +#define xor_bytes_with(input, output, length) xor_bytes_to(input, output, length, output) +#define block_no(ptr, index) ((ptr) + (index)*RIJNDAEL_BLOCKSIZE) +#define copy_block(from, to) memcpy(to, from, RIJNDAEL_BLOCKSIZE) + +static void ecb_encrypt(const RIJNDAEL_context *ctx, const uint8_t *input, int inputlen, uint8_t *output) { + int i, nblocks = inputlen / RIJNDAEL_BLOCKSIZE; + for (i = 0; i<nblocks; i++) { + rijndael_encrypt(ctx, block_no(input, i), block_no(output, i)); + } +} + +static void cbc_encrypt(const RIJNDAEL_context *ctx, const uint8_t *input, int inputlen, uint8_t *output, const uint8_t *iv) { + uint8_t block[RIJNDAEL_BLOCKSIZE]; + int i, nblocks = inputlen / RIJNDAEL_BLOCKSIZE; + + //* set initial value + copy_block(iv, block); + for (i=0; i< nblocks; i++) { + xor_block_with(block_no(input, i), block); + rijndael_encrypt(ctx, block, block); + copy_block(block, block_no(output, i)); + } +} + +static void cfb_encrypt(const RIJNDAEL_context *ctx, const uint8_t *input, int inputlen, uint8_t *output, const uint8_t *iv) { + uint8_t block[RIJNDAEL_BLOCKSIZE]; + int i, nblocks = inputlen / RIJNDAEL_BLOCKSIZE, leftover = inputlen % RIJNDAEL_BLOCKSIZE; + + copy_block(iv, block); + for (i=0; i<nblocks; i++) { + rijndael_encrypt(ctx, block, block); + xor_block_with(block_no(input, i), block); + copy_block(block, block_no(output, i)); + } + if (leftover) { + rijndael_encrypt(ctx, block, block); + xor_bytes_with(block_no(input, nblocks), block, leftover); + memcpy(block_no(output, nblocks), block, leftover); + } +} + +static void ofb_encrypt(const RIJNDAEL_context *ctx, const uint8_t *input, int inputlen, uint8_t *output, const uint8_t *iv) { + uint8_t block[RIJNDAEL_BLOCKSIZE]; + int i, nblocks = inputlen / RIJNDAEL_BLOCKSIZE, leftover = inputlen % RIJNDAEL_BLOCKSIZE; + + copy_block(iv, block); + for (i=0; i<nblocks; i++) { + rijndael_encrypt(ctx, block, block); + xor_block_to(block_no(input, i), block, block_no(output, i)); + } + if (leftover) { + rijndael_encrypt(ctx, block, block); + xor_bytes_to(block_no(input, nblocks), block, leftover, block_no(output, nblocks)); + } +} + +static void increment_counter(uint8_t* counter) { + int i = RIJNDAEL_BLOCKSIZE-1, carry_flg = 1; + + while (carry_flg && i >= 0) + carry_flg = !++counter[i--]; +} - nblocks = inputlen / RIJNDAEL_BLOCKSIZE; +static void ctr_encrypt(const RIJNDAEL_context *ctx, const uint8_t *input, int inputlen, uint8_t *output, const uint8_t *iv) { + uint8_t block[RIJNDAEL_BLOCKSIZE], counter[RIJNDAEL_BLOCKSIZE]; + int i, carry_flg, nblocks = inputlen / RIJNDAEL_BLOCKSIZE, leftover = inputlen % RIJNDAEL_BLOCKSIZE; + + copy_block(iv, counter); + for (i=0; i<nblocks; i++) { + rijndael_encrypt(ctx, counter, block); + xor_block_to(block, block_no(input, i), block_no(output, i)); + increment_counter(counter); + } + if (leftover) { + rijndael_encrypt(ctx, counter, block); + xor_bytes_to(block, block_no(input, nblocks), leftover, block_no(output, nblocks)); +/* increment_counter(counter); */ + } +} +void block_encrypt(const RIJNDAEL_context *ctx, const uint8_t *input, int inputlen, uint8_t *output, const uint8_t *iv) { 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]); - } + ecb_encrypt(ctx, input, inputlen, output); 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); - } + cbc_encrypt(ctx, input, inputlen, output, iv); break; case MODE_CFB: /* 128-bit cipher feedback */ - memcpy(block, iv, RIJNDAEL_BLOCKSIZE); - for (i=0; i<nblocks; i++) { - rijndael_encrypt(ctx, block, block); - for (j=0; j<RIJNDAEL_BLOCKSIZE; j++) - block[j] ^= input[i*RIJNDAEL_BLOCKSIZE + j]; - memcpy(&output[RIJNDAEL_BLOCKSIZE*i], block, RIJNDAEL_BLOCKSIZE); - } + cfb_encrypt(ctx, input, inputlen, output, iv); break; case MODE_OFB: /* 128-bit output feedback */ - memcpy(block, iv, RIJNDAEL_BLOCKSIZE); - for (i=0; i<nblocks; i++) { - rijndael_encrypt(ctx, block, block); - for (j=0; j<RIJNDAEL_BLOCKSIZE; j++) { - output[RIJNDAEL_BLOCKSIZE*i + j] = block[j] ^ - input[RIJNDAEL_BLOCKSIZE*i + j]; - } - } + ofb_encrypt(ctx, input, inputlen, output, iv); break; case MODE_CTR: /* counter */ - memcpy(block, iv, RIJNDAEL_BLOCKSIZE); - for (i=0; i<nblocks; i++) { - rijndael_encrypt(ctx, block, block2); - for (j=0; j<RIJNDAEL_BLOCKSIZE; j++) { - output[RIJNDAEL_BLOCKSIZE*i + j] = block2[j] ^ - input[RIJNDAEL_BLOCKSIZE*i + j]; - } - block[RIJNDAEL_BLOCKSIZE-1]++; - carry_flg = block[RIJNDAEL_BLOCKSIZE-1] != 0 ? 0 : 1; - for (j=RIJNDAEL_BLOCKSIZE-2; j>=0; j--) { - if (carry_flg) { - block[j]++; - carry_flg = block[j] != 0 ? 0 : 1; - } else - break; - } - } + ctr_encrypt(ctx, input, inputlen, output, iv); break; default: break; } } -void -block_decrypt(RIJNDAEL_context *ctx, uint8_t *input, int inputlen, - uint8_t *output, uint8_t *iv) -{ - int i, j, nblocks, carry_flg; - uint8_t block[RIJNDAEL_BLOCKSIZE], block2[RIJNDAEL_BLOCKSIZE]; +static void ecb_decrypt(const RIJNDAEL_context *ctx, const uint8_t *input, int inputlen, uint8_t *output) { + int i, nblocks = inputlen / RIJNDAEL_BLOCKSIZE; + for (i = 0; i<nblocks; i++) { + rijndael_decrypt(ctx, block_no(input, i), block_no(output, i)); + } +} - nblocks = inputlen / RIJNDAEL_BLOCKSIZE; +static void cbc_decrypt(const RIJNDAEL_context *ctx, const uint8_t *input, int inputlen, uint8_t *output, const uint8_t *iv) { + uint8_t block[RIJNDAEL_BLOCKSIZE]; + int i, nblocks = inputlen / RIJNDAEL_BLOCKSIZE; + + /* first block */ + rijndael_decrypt(ctx, input, block); + /* XOR the block with the IV to get the output */ + xor_block_to(block, iv, output); + for (i=1; i<nblocks; i++) { + rijndael_decrypt(ctx, block_no(input, i), block); + xor_block_to(block, block_no(input, i-1), block_no(output, i)); + } +} + +static void cfb_decrypt(const RIJNDAEL_context *ctx, const uint8_t *input, int inputlen, uint8_t *output, const uint8_t *iv) { + uint8_t block[RIJNDAEL_BLOCKSIZE]; + int i, nblocks = inputlen / RIJNDAEL_BLOCKSIZE, leftover = inputlen % RIJNDAEL_BLOCKSIZE; + + copy_block(iv, block); + for (i=0; i<nblocks; i++) { + rijndael_encrypt(ctx, block, block); /* ENCRYPT is right! */ + xor_block_to(block, block_no(input, i), block_no(output, i)); + copy_block(block_no(input, i), block); + } + if (leftover) { + rijndael_encrypt(ctx, block, block); /* ENCRYPT is right! */ + xor_bytes_to(block, block_no(input, i), leftover, block_no(output, i)); + memcpy(block, block_no(input, i), leftover); + } +} + +void block_decrypt(const RIJNDAEL_context *ctx, const uint8_t *input, int inputlen, uint8_t *output, const uint8_t *iv) { switch (ctx->mode) { case MODE_ECB: - for (i = 0; i<nblocks; i++) { - rijndael_decrypt(ctx, &input[RIJNDAEL_BLOCKSIZE*i], - &output[RIJNDAEL_BLOCKSIZE*i]); - } + ecb_decrypt(ctx, input, inputlen, output); 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]; - } - } + cbc_decrypt(ctx, input, inputlen, output, iv); break; case MODE_CFB: /* 128-bit cipher feedback */ - memcpy(block, iv, RIJNDAEL_BLOCKSIZE); - for (i=0; i<nblocks; i++) { - rijndael_encrypt(ctx, block, block); /* ENCRYPT is right! */ - for (j=0; j<RIJNDAEL_BLOCKSIZE; j++) { - output[RIJNDAEL_BLOCKSIZE*i + j] = block[j] ^ - input[RIJNDAEL_BLOCKSIZE*i + j]; - } - memcpy(block, &input[RIJNDAEL_BLOCKSIZE*i], RIJNDAEL_BLOCKSIZE); - } + cfb_decrypt(ctx, input, inputlen, output, iv); break; case MODE_OFB: /* 128-bit output feedback */ - /* this is exactly the same as encryption in OFB...in fact you can use - the encryption in OFB mode to decrypt! */ - memcpy(block, iv, RIJNDAEL_BLOCKSIZE); - for (i=0; i<nblocks; i++) { - rijndael_encrypt(ctx, block, block); - for (j=0; j<RIJNDAEL_BLOCKSIZE; j++) { - output[RIJNDAEL_BLOCKSIZE*i + j] = block[j] ^ - input[RIJNDAEL_BLOCKSIZE*i + j]; - } - } + ofb_encrypt(ctx, input, inputlen, output, iv); break; case MODE_CTR: /* counter */ - memcpy(block, iv, RIJNDAEL_BLOCKSIZE); - for (i=0; i<nblocks; i++) { - rijndael_encrypt(ctx, block, block2); - for (j=0; j<RIJNDAEL_BLOCKSIZE; j++) { - output[RIJNDAEL_BLOCKSIZE*i + j] = block2[j] ^ - input[RIJNDAEL_BLOCKSIZE*i + j]; - } - block[RIJNDAEL_BLOCKSIZE-1]++; - carry_flg = block[RIJNDAEL_BLOCKSIZE-1] != 0 ? 0 : 1; - for (j=RIJNDAEL_BLOCKSIZE-2; j>=0; j--) { - if (carry_flg) { - block[j]++; - carry_flg = block[j] != 0 ? 0 : 1; - } else - break; - } - } + ctr_encrypt(ctx, input, inputlen, output, iv); break; default: break; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Crypt-Rijndael-1.15/rijndael.h new/Crypt-Rijndael-1.16/rijndael.h --- old/Crypt-Rijndael-1.15/rijndael.h 2020-10-10 21:27:06.000000000 +0200 +++ new/Crypt-Rijndael-1.16/rijndael.h 2021-04-01 23:31:51.000000000 +0200 @@ -64,53 +64,13 @@ * 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_t *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_t *plaintext, - uint8_t *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_t *ciphertext, - uint8_t *plaintext); +void rijndael_setup(RIJNDAEL_context *ctx, size_t keysize, const uint8_t *key); /* Encrypt a block of plaintext in a mode specified in the context */ -void -block_encrypt(RIJNDAEL_context *ctx, uint8_t *input, int inputlen, - uint8_t *output, uint8_t *iv); +void block_encrypt(const RIJNDAEL_context *ctx, const uint8_t *input, int inputlen, uint8_t *output, const uint8_t *iv); /* Decrypt a block of plaintext in a mode specified in the context */ -void -block_decrypt(RIJNDAEL_context *ctx, uint8_t *input, int inputlen, - uint8_t *output, uint8_t *iv); +void block_decrypt(const RIJNDAEL_context *ctx, const uint8_t *input, int inputlen, uint8_t *output, const uint8_t *iv); #endif /* RIJNDAEL_H */ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Crypt-Rijndael-1.15/t/modes.t new/Crypt-Rijndael-1.16/t/modes.t --- old/Crypt-Rijndael-1.15/t/modes.t 2015-12-04 01:05:15.000000000 +0100 +++ new/Crypt-Rijndael-1.16/t/modes.t 2021-04-01 23:31:51.000000000 +0200 @@ -1,6 +1,6 @@ #!/usr/bin/perl -use Test::More tests => 68; +use Test::More tests => 90; use Crypt::Rijndael; @@ -18,6 +18,11 @@ } foreach my $a ( 0 .. 10 ) { + my ($plain, $data) = crypt_decrypt_partial(Crypt::Rijndael::MODE_CFB); + is($plain, $data, "Decrypted text matches plain text for cfb-$a-partial"); +} + +foreach my $a ( 0 .. 10 ) { my $hash = crypt_decrypt(Crypt::Rijndael::MODE_CTR); is($hash->{plain}, $hash->{data}, "Decrypted text matches plain text for ctr-$a"); } @@ -32,6 +37,11 @@ is($hash->{plain}, $hash->{data}, "Decrypted text matches plain text for ofb-$a"); } +foreach my $a ( 0 .. 10 ) { + my ($plain, $data) = crypt_decrypt_partial(Crypt::Rijndael::MODE_OFB); + is($plain, $data, "Decrypted text matches plain text for ofb-$a-partial"); +} + TODO: { todo_skip "PCBC is not a legal mode (yet)", 11; @@ -48,9 +58,10 @@ my $key = make_string(32); my $c = Crypt::Rijndael->new($key, $mode); my $data = make_string(32 * int rand(16) + 1); + my $iv = make_string(16); - my $cipher = $c->encrypt($data); - my $plain = $c->decrypt($cipher); + my $cipher = $c->encrypt($data, $iv); + my $plain = $c->decrypt($cipher, $iv); return { data => $data, @@ -59,6 +70,20 @@ }; } +sub crypt_decrypt_partial { + my $mode = shift; + + my $key = make_string(16); + my $c = Crypt::Rijndael->new($key, $mode); + my $data = make_string(32 * int(2 + 1) + 8); + my $iv = make_string(16); + + my $cipher = $c->encrypt($data, $iv); + my $plain = $c->decrypt($cipher, $iv); + + return ($plain, $data); +} + sub make_string { my $size = shift; return pack 'C*', map { rand 256 } 1 .. $size; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Crypt-Rijndael-1.15/typemap new/Crypt-Rijndael-1.16/typemap --- old/Crypt-Rijndael-1.15/typemap 2015-12-04 01:05:15.000000000 +0100 +++ new/Crypt-Rijndael-1.16/typemap 2021-04-01 23:31:51.000000000 +0200 @@ -1 +1,12 @@ Crypt::Rijndael T_PTROBJ +IVEC T_IVEC + +INPUT +T_IVEC + { + const char* ret; + STRLEN size; + $var = ($type)SvPVbyte($arg, size); + if (size != RIJNDAEL_BLOCKSIZE) + Perl_croak(aTHX_ \"set_iv: initial value must be the blocksize (%d bytes), but was %d bytes\", RIJNDAEL_BLOCKSIZE, size); + }