bwrega / crypto-js

Automatically exported from code.google.com/p/crypto-js
0 stars 0 forks source link

AES or any cipher gives bad results if CBC 256bit mode is used (when iv is defined with 32bytes). #118

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
When 256bit block mode is used with CBC  that means wkey,wIv is of size 32byte 
(256bit mode). (Se example below: yes they are WordArrays. The blocksize is 
incorrect and the algorithm gives bad results. 

cipher.cfg.blockSize is 8 but 
cipher.blockSize is standard value 4.  <-- Incorrect. 

This gives incorrect results. 

Example: 

CryptoJS.AES.decrypt({
    ciphertext: wTarget,
    salt: ""},wKey, { iv: wIv, blockSize: 8, padding: CryptoJS.pad.NoPadding}); 

gives incorrect result. (tested with Firefox 27.0.1) 

Suggestion:  line 330 in cipher-core.js or appropiate need to change.  (see 
below) 

         processBlock: function (words, offset) {
                // Shortcuts
                var cipher = this._cipher;
                var blockSize = cipher.blockSize; // <-- 

                // Remember this block to use with next block
                var thisBlock = words.slice(offset, offset + blockSize);

                // Decrypt and XOR
                cipher.decryptBlock(words, offset);
                xorBlock.call(this, words, offset, blockSize);

                // This block becomes the previous block
                this._prevBlock = thisBlock;
            }

Original issue reported on code.google.com by AminGhol...@gmail.com on 13 Mar 2014 at 3:41

GoogleCodeExporter commented 8 years ago
Per the spec, AES supports a 256-bit *key*, but the block size is always fixed 
at 128 bits.

Original comment by Jeff.Mott.OR on 13 Mar 2014 at 4:06

GoogleCodeExporter commented 8 years ago

Original comment by Jeff.Mott.OR on 14 Mar 2014 at 2:07