1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- Crypto.mode.CBC = {
- encrypt: function (cipher, m, iv) {
- var blockSizeInBytes = cipher._blocksize * 4;
-
- m.push(0x80);
-
- for (var offset = 0; offset < m.length; offset += blockSizeInBytes) {
- if (offset == 0) {
-
- for (var i = 0; i < blockSizeInBytes; i++)
- m[i] ^= iv[i];
- }
- else {
-
- for (var i = 0; i < blockSizeInBytes; i++)
- m[offset + i] ^= m[offset + i - blockSizeInBytes];
- }
-
- cipher._encryptblock(m, offset);
- }
- },
- decrypt: function (cipher, c, iv) {
- var blockSizeInBytes = cipher._blocksize * 4;
-
- for (var offset = 0; offset < c.length; offset += blockSizeInBytes) {
-
- var thisCryptedBlock = c.slice(offset, offset + blockSizeInBytes);
-
- cipher._decryptblock(c, offset);
- if (offset == 0) {
-
- for (var i = 0; i < blockSizeInBytes; i++)
- c[i] ^= iv[i];
- }
- else {
-
- for (var i = 0; i < blockSizeInBytes; i++)
- c[offset + i] ^= prevCryptedBlock[i];
- }
-
- var prevCryptedBlock = thisCryptedBlock;
- }
-
- while (c.pop() != 0x80) ;
- }
- };
|