pad-zeropadding.js 1.0 KB

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