mode-ofb.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. CryptoJS v3.1.2
  3. code.google.com/p/crypto-js
  4. (c) 2009-2013 by Jeff Mott. All rights reserved.
  5. code.google.com/p/crypto-js/wiki/License
  6. */
  7. /**
  8. * Output Feedback block mode.
  9. */
  10. CryptoJS.mode.OFB = (function () {
  11. var OFB = CryptoJS.lib.BlockCipherMode.extend();
  12. var Encryptor = OFB.Encryptor = OFB.extend({
  13. processBlock: function (words, offset) {
  14. // Shortcuts
  15. var cipher = this._cipher
  16. var blockSize = cipher.blockSize;
  17. var iv = this._iv;
  18. var keystream = this._keystream;
  19. // Generate keystream
  20. if (iv) {
  21. keystream = this._keystream = iv.slice(0);
  22. // Remove IV for subsequent blocks
  23. this._iv = undefined;
  24. }
  25. cipher.encryptBlock(keystream, 0);
  26. // Encrypt
  27. for (var i = 0; i < blockSize; i++) {
  28. words[offset + i] ^= keystream[i];
  29. }
  30. }
  31. });
  32. OFB.Decryptor = Encryptor;
  33. return OFB;
  34. }());