ofb.js 652 B

1234567891011121314151617181920212223242526272829303132333435
  1. /*!
  2. * Crypto-JS v1.1.0
  3. * http://code.google.com/p/crypto-js/
  4. * Copyright (c) 2009, Jeff Mott. All rights reserved.
  5. * http://code.google.com/p/crypto-js/wiki/License
  6. */
  7. (function(){
  8. // Public API
  9. Crypto.mode.OFB = {
  10. encrypt: OFB,
  11. decrypt: OFB
  12. };
  13. // The mode function
  14. function OFB(cipher, m, iv) {
  15. var blockSizeInBytes = cipher._blocksize * 4,
  16. keystream = iv.slice(0);
  17. // Encrypt each byte
  18. for (var i = 0; i < m.length; i++) {
  19. // Generate keystream
  20. if (i % blockSizeInBytes == 0)
  21. cipher._encryptblock(keystream, 0);
  22. // Encrypt byte
  23. m[i] ^= keystream[i % blockSizeInBytes];
  24. }
  25. }
  26. })();