3
code.google.com/p/crypto-js
4
(c) 2009-2012 by Jeff Mott. All rights reserved.
5
code.google.com/p/crypto-js/wiki/License
8
* Cipher Feedback block mode.
10
CryptoJS.mode.CFB = (function () {
11
var CFB = CryptoJS.lib.BlockCipherMode.extend();
13
CFB.Encryptor = CFB.extend({
14
processBlock: function (words, offset) {
16
var cipher = this._cipher;
17
var blockSize = cipher.blockSize;
19
generateKeystreamAndEncrypt.call(this, words, offset, blockSize, cipher);
21
// Remember this block to use with next block
22
this._prevBlock = words.slice(offset, offset + blockSize);
26
CFB.Decryptor = CFB.extend({
27
processBlock: function (words, offset) {
29
var cipher = this._cipher;
30
var blockSize = cipher.blockSize;
32
// Remember this block to use with next block
33
var thisBlock = words.slice(offset, offset + blockSize);
35
generateKeystreamAndEncrypt.call(this, words, offset, blockSize, cipher);
37
// This block becomes the previous block
38
this._prevBlock = thisBlock;
42
function generateKeystreamAndEncrypt(words, offset, blockSize, cipher) {
48
var keystream = iv.slice(0);
50
// Remove IV for subsequent blocks
53
var keystream = this._prevBlock;
55
cipher.encryptBlock(keystream, 0);
58
for (var i = 0; i < blockSize; i++) {
59
words[offset + i] ^= keystream[i];