UNPKG

1.26 kBJavaScriptView Raw
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 /**
17 * ANSI X.923 padding strategy.
18 */
19 CryptoJS.pad.AnsiX923 = {
20 pad: function (data, blockSize) {
21 // Shortcuts
22 var dataSigBytes = data.sigBytes;
23 var blockSizeBytes = blockSize * 4;
24
25 // Count padding bytes
26 var nPaddingBytes = blockSizeBytes - dataSigBytes % blockSizeBytes;
27
28 // Compute last byte position
29 var lastBytePos = dataSigBytes + nPaddingBytes - 1;
30
31 // Pad
32 data.clamp();
33 data.words[lastBytePos >>> 2] |= nPaddingBytes << (24 - (lastBytePos % 4) * 8);
34 data.sigBytes += nPaddingBytes;
35 },
36
37 unpad: function (data) {
38 // Get number of padding bytes from last byte
39 var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff;
40
41 // Remove padding
42 data.sigBytes -= nPaddingBytes;
43 }
44 };
45
46
47 return CryptoJS.pad.Ansix923;
48
49}));
\No newline at end of file