pad-zeropadding.js 755 B

12345678910111213141516171819202122232425262728293031
  1. /*
  2. CryptoJS v3.0.2
  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
  6. */
  7. /**
  8. * Zero padding strategy.
  9. */
  10. CryptoJS.pad.ZeroPadding = {
  11. pad: function (data, blockSize) {
  12. // Shortcut
  13. var blockSizeBytes = blockSize * 4;
  14. // Pad
  15. data.clamp();
  16. data.sigBytes += blockSizeBytes - ((data.sigBytes % blockSizeBytes) || blockSizeBytes);
  17. },
  18. unpad: function (data) {
  19. // Shortcut
  20. var dataWords = data.words;
  21. // Unpad
  22. var i = data.sigBytes - 1;
  23. while (!((dataWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff)) {
  24. i--;
  25. }
  26. data.sigBytes = i + 1;
  27. }
  28. };