pad-zeropadding.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. ;(function (root, factory, undef) {
  2. if (typeof exports === "object") {
  3. // CommonJS
  4. module.exports = exports = factory(require("./core"), require("./cipher-core"));
  5. } else if (typeof define === "function" && define.amd) {
  6. // AMD
  7. define(["./core", "./cipher-core"], factory);
  8. } else {
  9. // Global (browser)
  10. factory(root.CryptoJS);
  11. }
  12. }(this, function (CryptoJS) {
  13. /**
  14. * Zero padding strategy.
  15. */
  16. CryptoJS.pad.ZeroPadding = {
  17. pad: function (data, blockSize) {
  18. // Shortcut
  19. var blockSizeBytes = blockSize * 4;
  20. // Pad
  21. data.clamp();
  22. data.sigBytes += blockSizeBytes - ((data.sigBytes % blockSizeBytes) || blockSizeBytes);
  23. },
  24. unpad: function (data) {
  25. // Shortcut
  26. var dataWords = data.words;
  27. // Unpad
  28. var i = data.sigBytes - 1;
  29. while (!((dataWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff)) {
  30. i--;
  31. }
  32. data.sigBytes = i + 1;
  33. }
  34. };
  35. return CryptoJS.pad.ZeroPadding;
  36. }));