pixel-react 1.15.21 → 1.15.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/_virtual/aesCipherSuites.js +4 -0
- package/lib/_virtual/aesCipherSuites.js.map +1 -0
- package/lib/_virtual/asn1-validator.js +4 -0
- package/lib/_virtual/asn1-validator.js.map +1 -0
- package/lib/_virtual/asn1.js +4 -0
- package/lib/_virtual/asn1.js.map +1 -0
- package/lib/_virtual/cipherModes.js +4 -0
- package/lib/_virtual/cipherModes.js.map +1 -0
- package/lib/_virtual/hmac.js +4 -0
- package/lib/_virtual/hmac.js.map +1 -0
- package/lib/_virtual/index11.js +2 -2
- package/lib/_virtual/index12.js +2 -2
- package/lib/_virtual/index13.js +2 -2
- package/lib/_virtual/index14.js +4 -0
- package/lib/_virtual/index14.js.map +1 -0
- package/lib/_virtual/index2.js +5 -3
- package/lib/_virtual/index2.js.map +1 -1
- package/lib/_virtual/index3.js +4 -2
- package/lib/_virtual/index3.js.map +1 -1
- package/lib/_virtual/index4.js +2 -4
- package/lib/_virtual/index4.js.map +1 -1
- package/lib/_virtual/index5.js +4 -2
- package/lib/_virtual/index5.js.map +1 -1
- package/lib/_virtual/index6.js +2 -2
- package/lib/_virtual/index7.js +2 -6
- package/lib/_virtual/index7.js.map +1 -1
- package/lib/_virtual/index8.js +6 -2
- package/lib/_virtual/index8.js.map +1 -1
- package/lib/_virtual/index9.js +2 -2
- package/lib/_virtual/md5.js +4 -0
- package/lib/_virtual/md5.js.map +1 -0
- package/lib/_virtual/mgf1.js +4 -0
- package/lib/_virtual/mgf1.js.map +1 -0
- package/lib/_virtual/oids.js +4 -0
- package/lib/_virtual/oids.js.map +1 -0
- package/lib/_virtual/pem.js +4 -0
- package/lib/_virtual/pem.js.map +1 -0
- package/lib/_virtual/pkcs1.js +4 -0
- package/lib/_virtual/pkcs1.js.map +1 -0
- package/lib/_virtual/pkcs12.js +4 -0
- package/lib/_virtual/pkcs12.js.map +1 -0
- package/lib/_virtual/pkcs7.js +4 -0
- package/lib/_virtual/pkcs7.js.map +1 -0
- package/lib/_virtual/pkcs7asn1.js +4 -0
- package/lib/_virtual/pkcs7asn1.js.map +1 -0
- package/lib/_virtual/pki.js +4 -0
- package/lib/_virtual/pki.js.map +1 -0
- package/lib/_virtual/prime.js +4 -0
- package/lib/_virtual/prime.js.map +1 -0
- package/lib/_virtual/prng.js +4 -0
- package/lib/_virtual/prng.js.map +1 -0
- package/lib/_virtual/pss.js +4 -0
- package/lib/_virtual/pss.js.map +1 -0
- package/lib/_virtual/random.js +4 -0
- package/lib/_virtual/random.js.map +1 -0
- package/lib/_virtual/sha1.js +4 -0
- package/lib/_virtual/sha1.js.map +1 -0
- package/lib/_virtual/sha256.js +4 -0
- package/lib/_virtual/sha256.js.map +1 -0
- package/lib/_virtual/sha512.js +4 -0
- package/lib/_virtual/sha512.js.map +1 -0
- package/lib/_virtual/ssh.js +4 -0
- package/lib/_virtual/ssh.js.map +1 -0
- package/lib/_virtual/util.js +4 -0
- package/lib/_virtual/util.js.map +1 -0
- package/lib/_virtual/x509.js +4 -0
- package/lib/_virtual/x509.js.map +1 -0
- package/lib/assets/icons/testify_icon.svg.js +6 -0
- package/lib/assets/icons/testify_icon.svg.js.map +1 -0
- package/lib/assets/icons/testify_loader.svg.js +6 -0
- package/lib/assets/icons/testify_loader.svg.js.map +1 -0
- package/lib/assets/icons/testify_logo_name.svg.js +6 -0
- package/lib/assets/icons/testify_logo_name.svg.js.map +1 -0
- package/lib/components/AllProjectsDropdown/AllProjectsDropdown.js +3 -1
- package/lib/components/AllProjectsDropdown/AllProjectsDropdown.js.map +1 -1
- package/lib/components/Charts/DashboardDonutChart/DashboardDonutChart.js +2 -9
- package/lib/components/Charts/DashboardDonutChart/DashboardDonutChart.js.map +1 -1
- package/lib/components/Charts/DashboardDonutChart/types.d.ts +1 -1
- package/lib/components/ConditionalDropdown/ConditionalDropdown.js +2 -9
- package/lib/components/ConditionalDropdown/ConditionalDropdown.js.map +1 -1
- package/lib/components/Editor/Editor.js +37 -17
- package/lib/components/Editor/Editor.js.map +1 -1
- package/lib/components/Icon/iconList.js +6 -0
- package/lib/components/Icon/iconList.js.map +1 -1
- package/lib/components/MultiSelect/MultiSelect.js +9 -10
- package/lib/components/MultiSelect/MultiSelect.js.map +1 -1
- package/lib/components/PhoneInput/PhoneInput.js +1 -0
- package/lib/components/PhoneInput/PhoneInput.js.map +1 -1
- package/lib/components/SessionDropdown/SessionDropdown.js +4 -2
- package/lib/components/SessionDropdown/SessionDropdown.js.map +1 -1
- package/lib/index.cjs +27423 -379
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/node_modules/classnames/index.js +1 -1
- package/lib/node_modules/input-format/modules/react/Input.js +1 -1
- package/lib/node_modules/js-beautify/js/index.js +1 -1
- package/lib/node_modules/js-beautify/js/src/html/beautifier.js +1 -1
- package/lib/node_modules/js-beautify/js/src/html/index.js +1 -1
- package/lib/node_modules/js-beautify/js/src/html/options.js +1 -1
- package/lib/node_modules/js-beautify/js/src/html/tokenizer.js +1 -1
- package/lib/node_modules/js-beautify/js/src/index.js +1 -1
- package/lib/node_modules/js-beautify/js/src/javascript/beautifier.js +1 -1
- package/lib/node_modules/js-beautify/js/src/javascript/index.js +1 -1
- package/lib/node_modules/js-beautify/js/src/javascript/options.js +1 -1
- package/lib/node_modules/js-beautify/js/src/javascript/tokenizer.js +1 -1
- package/lib/node_modules/node-forge/lib/aes.js +1014 -0
- package/lib/node_modules/node-forge/lib/aes.js.map +1 -0
- package/lib/node_modules/node-forge/lib/aesCipherSuites.js +286 -0
- package/lib/node_modules/node-forge/lib/aesCipherSuites.js.map +1 -0
- package/lib/node_modules/node-forge/lib/asn1-validator.js +100 -0
- package/lib/node_modules/node-forge/lib/asn1-validator.js.map +1 -0
- package/lib/node_modules/node-forge/lib/asn1.js +1379 -0
- package/lib/node_modules/node-forge/lib/asn1.js.map +1 -0
- package/lib/node_modules/node-forge/lib/baseN.js +181 -0
- package/lib/node_modules/node-forge/lib/baseN.js.map +1 -0
- package/lib/node_modules/node-forge/lib/cipher.js +236 -0
- package/lib/node_modules/node-forge/lib/cipher.js.map +1 -0
- package/lib/node_modules/node-forge/lib/cipherModes.js +936 -0
- package/lib/node_modules/node-forge/lib/cipherModes.js.map +1 -0
- package/lib/node_modules/node-forge/lib/des.js +467 -0
- package/lib/node_modules/node-forge/lib/des.js.map +1 -0
- package/lib/node_modules/node-forge/lib/ed25519.js +1108 -0
- package/lib/node_modules/node-forge/lib/ed25519.js.map +1 -0
- package/lib/node_modules/node-forge/lib/forge.js +23 -0
- package/lib/node_modules/node-forge/lib/forge.js.map +1 -0
- package/lib/node_modules/node-forge/lib/hmac.js +158 -0
- package/lib/node_modules/node-forge/lib/hmac.js.map +1 -0
- package/lib/node_modules/node-forge/lib/index.js +70 -0
- package/lib/node_modules/node-forge/lib/index.js.map +1 -0
- package/lib/node_modules/node-forge/lib/jsbn.js +1481 -0
- package/lib/node_modules/node-forge/lib/jsbn.js.map +1 -0
- package/lib/node_modules/node-forge/lib/kem.js +178 -0
- package/lib/node_modules/node-forge/lib/kem.js.map +1 -0
- package/lib/node_modules/node-forge/lib/log.js +325 -0
- package/lib/node_modules/node-forge/lib/log.js.map +1 -0
- package/lib/node_modules/node-forge/lib/md.all.js +28 -0
- package/lib/node_modules/node-forge/lib/md.all.js.map +1 -0
- package/lib/node_modules/node-forge/lib/md.js +22 -0
- package/lib/node_modules/node-forge/lib/md.js.map +1 -0
- package/lib/node_modules/node-forge/lib/md5.js +288 -0
- package/lib/node_modules/node-forge/lib/md5.js.map +1 -0
- package/lib/node_modules/node-forge/lib/mgf.js +24 -0
- package/lib/node_modules/node-forge/lib/mgf.js.map +1 -0
- package/lib/node_modules/node-forge/lib/mgf1.js +68 -0
- package/lib/node_modules/node-forge/lib/mgf1.js.map +1 -0
- package/lib/node_modules/node-forge/lib/oids.js +185 -0
- package/lib/node_modules/node-forge/lib/oids.js.map +1 -0
- package/lib/node_modules/node-forge/lib/pbe.js +966 -0
- package/lib/node_modules/node-forge/lib/pbe.js.map +1 -0
- package/lib/node_modules/node-forge/lib/pbkdf2.js +209 -0
- package/lib/node_modules/node-forge/lib/pbkdf2.js.map +1 -0
- package/lib/node_modules/node-forge/lib/pem.js +250 -0
- package/lib/node_modules/node-forge/lib/pem.js.map +1 -0
- package/lib/node_modules/node-forge/lib/pkcs1.js +273 -0
- package/lib/node_modules/node-forge/lib/pkcs1.js.map +1 -0
- package/lib/node_modules/node-forge/lib/pkcs12.js +980 -0
- package/lib/node_modules/node-forge/lib/pkcs12.js.map +1 -0
- package/lib/node_modules/node-forge/lib/pkcs7.js +1073 -0
- package/lib/node_modules/node-forge/lib/pkcs7.js.map +1 -0
- package/lib/node_modules/node-forge/lib/pkcs7asn1.js +415 -0
- package/lib/node_modules/node-forge/lib/pkcs7asn1.js.map +1 -0
- package/lib/node_modules/node-forge/lib/pki.js +125 -0
- package/lib/node_modules/node-forge/lib/pki.js.map +1 -0
- package/lib/node_modules/node-forge/lib/prime.js +297 -0
- package/lib/node_modules/node-forge/lib/prime.js.map +1 -0
- package/lib/node_modules/node-forge/lib/prng.js +433 -0
- package/lib/node_modules/node-forge/lib/prng.js.map +1 -0
- package/lib/node_modules/node-forge/lib/pss.js +246 -0
- package/lib/node_modules/node-forge/lib/pss.js.map +1 -0
- package/lib/node_modules/node-forge/lib/random.js +191 -0
- package/lib/node_modules/node-forge/lib/random.js.map +1 -0
- package/lib/node_modules/node-forge/lib/rc2.js +382 -0
- package/lib/node_modules/node-forge/lib/rc2.js.map +1 -0
- package/lib/node_modules/node-forge/lib/rsa.js +1815 -0
- package/lib/node_modules/node-forge/lib/rsa.js.map +1 -0
- package/lib/node_modules/node-forge/lib/sha1.js +325 -0
- package/lib/node_modules/node-forge/lib/sha1.js.map +1 -0
- package/lib/node_modules/node-forge/lib/sha256.js +306 -0
- package/lib/node_modules/node-forge/lib/sha256.js.map +1 -0
- package/lib/node_modules/node-forge/lib/sha512.js +479 -0
- package/lib/node_modules/node-forge/lib/sha512.js.map +1 -0
- package/lib/node_modules/node-forge/lib/ssh.js +244 -0
- package/lib/node_modules/node-forge/lib/ssh.js.map +1 -0
- package/lib/node_modules/node-forge/lib/tls.js +4207 -0
- package/lib/node_modules/node-forge/lib/tls.js.map +1 -0
- package/lib/node_modules/node-forge/lib/util.js +2565 -0
- package/lib/node_modules/node-forge/lib/util.js.map +1 -0
- package/lib/node_modules/node-forge/lib/x509.js +2986 -0
- package/lib/node_modules/node-forge/lib/x509.js.map +1 -0
- package/lib/node_modules/prop-types/index.js +1 -1
- package/lib/node_modules/react-async-script/lib/esm/async-script-loader.js +1 -1
- package/lib/node_modules/react-google-recaptcha/lib/esm/recaptcha.js +1 -1
- package/lib/node_modules/react-is/index.js +1 -1
- package/lib/node_modules/react-phone-number-input/modules/CountryIcon.js +1 -1
- package/lib/node_modules/react-phone-number-input/modules/CountrySelect.js +1 -1
- package/lib/node_modules/react-phone-number-input/modules/Flag.js +1 -1
- package/lib/node_modules/react-phone-number-input/modules/InputBasic.js +1 -1
- package/lib/node_modules/react-phone-number-input/modules/InputSmart.js +1 -1
- package/lib/node_modules/react-phone-number-input/modules/InternationalIcon.js +1 -1
- package/lib/node_modules/react-phone-number-input/modules/PhoneInputWithCountry.js +1 -1
- package/lib/node_modules/react-phone-number-input/modules/PropTypes.js +1 -1
- package/lib/node_modules/scheduler/index.js +1 -1
- package/lib/node_modules/use-context-selector/dist/index.js +1 -1
- package/lib/styles.css +1 -1
- package/lib/styles.css.map +1 -1
- package/lib/utils/getEncryptedData/getEncryptedData.js +10 -13
- package/lib/utils/getEncryptedData/getEncryptedData.js.map +1 -1
- package/package.json +3 -1
|
@@ -0,0 +1,936 @@
|
|
|
1
|
+
import { __module as cipherModes } from '../../../_virtual/cipherModes.js';
|
|
2
|
+
import { __require as requireForge } from './forge.js';
|
|
3
|
+
import { __require as requireUtil } from './util.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Supported cipher modes.
|
|
7
|
+
*
|
|
8
|
+
* @author Dave Longley
|
|
9
|
+
*
|
|
10
|
+
* Copyright (c) 2010-2014 Digital Bazaar, Inc.
|
|
11
|
+
*/
|
|
12
|
+
var hasRequiredCipherModes;
|
|
13
|
+
function requireCipherModes() {
|
|
14
|
+
if (hasRequiredCipherModes) return cipherModes.exports;
|
|
15
|
+
hasRequiredCipherModes = 1;
|
|
16
|
+
var forge = requireForge();
|
|
17
|
+
requireUtil();
|
|
18
|
+
forge.cipher = forge.cipher || {};
|
|
19
|
+
|
|
20
|
+
// supported cipher modes
|
|
21
|
+
var modes = cipherModes.exports = forge.cipher.modes = forge.cipher.modes || {};
|
|
22
|
+
|
|
23
|
+
/** Electronic codebook (ECB) (Don't use this; it's not secure) **/
|
|
24
|
+
|
|
25
|
+
modes.ecb = function (options) {
|
|
26
|
+
options = options || {};
|
|
27
|
+
this.name = 'ECB';
|
|
28
|
+
this.cipher = options.cipher;
|
|
29
|
+
this.blockSize = options.blockSize || 16;
|
|
30
|
+
this._ints = this.blockSize / 4;
|
|
31
|
+
this._inBlock = new Array(this._ints);
|
|
32
|
+
this._outBlock = new Array(this._ints);
|
|
33
|
+
};
|
|
34
|
+
modes.ecb.prototype.start = function (options) {};
|
|
35
|
+
modes.ecb.prototype.encrypt = function (input, output, finish) {
|
|
36
|
+
// not enough input to encrypt
|
|
37
|
+
if (input.length() < this.blockSize && !(finish && input.length() > 0)) {
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// get next block
|
|
42
|
+
for (var i = 0; i < this._ints; ++i) {
|
|
43
|
+
this._inBlock[i] = input.getInt32();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// encrypt block
|
|
47
|
+
this.cipher.encrypt(this._inBlock, this._outBlock);
|
|
48
|
+
|
|
49
|
+
// write output
|
|
50
|
+
for (var i = 0; i < this._ints; ++i) {
|
|
51
|
+
output.putInt32(this._outBlock[i]);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
modes.ecb.prototype.decrypt = function (input, output, finish) {
|
|
55
|
+
// not enough input to decrypt
|
|
56
|
+
if (input.length() < this.blockSize && !(finish && input.length() > 0)) {
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// get next block
|
|
61
|
+
for (var i = 0; i < this._ints; ++i) {
|
|
62
|
+
this._inBlock[i] = input.getInt32();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// decrypt block
|
|
66
|
+
this.cipher.decrypt(this._inBlock, this._outBlock);
|
|
67
|
+
|
|
68
|
+
// write output
|
|
69
|
+
for (var i = 0; i < this._ints; ++i) {
|
|
70
|
+
output.putInt32(this._outBlock[i]);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
modes.ecb.prototype.pad = function (input, options) {
|
|
74
|
+
// add PKCS#7 padding to block (each pad byte is the
|
|
75
|
+
// value of the number of pad bytes)
|
|
76
|
+
var padding = input.length() === this.blockSize ? this.blockSize : this.blockSize - input.length();
|
|
77
|
+
input.fillWithByte(padding, padding);
|
|
78
|
+
return true;
|
|
79
|
+
};
|
|
80
|
+
modes.ecb.prototype.unpad = function (output, options) {
|
|
81
|
+
// check for error: input data not a multiple of blockSize
|
|
82
|
+
if (options.overflow > 0) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// ensure padding byte count is valid
|
|
87
|
+
var len = output.length();
|
|
88
|
+
var count = output.at(len - 1);
|
|
89
|
+
if (count > this.blockSize << 2) {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// trim off padding bytes
|
|
94
|
+
output.truncate(count);
|
|
95
|
+
return true;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
/** Cipher-block Chaining (CBC) **/
|
|
99
|
+
|
|
100
|
+
modes.cbc = function (options) {
|
|
101
|
+
options = options || {};
|
|
102
|
+
this.name = 'CBC';
|
|
103
|
+
this.cipher = options.cipher;
|
|
104
|
+
this.blockSize = options.blockSize || 16;
|
|
105
|
+
this._ints = this.blockSize / 4;
|
|
106
|
+
this._inBlock = new Array(this._ints);
|
|
107
|
+
this._outBlock = new Array(this._ints);
|
|
108
|
+
};
|
|
109
|
+
modes.cbc.prototype.start = function (options) {
|
|
110
|
+
// Note: legacy support for using IV residue (has security flaws)
|
|
111
|
+
// if IV is null, reuse block from previous processing
|
|
112
|
+
if (options.iv === null) {
|
|
113
|
+
// must have a previous block
|
|
114
|
+
if (!this._prev) {
|
|
115
|
+
throw new Error('Invalid IV parameter.');
|
|
116
|
+
}
|
|
117
|
+
this._iv = this._prev.slice(0);
|
|
118
|
+
} else if (!('iv' in options)) {
|
|
119
|
+
throw new Error('Invalid IV parameter.');
|
|
120
|
+
} else {
|
|
121
|
+
// save IV as "previous" block
|
|
122
|
+
this._iv = transformIV(options.iv, this.blockSize);
|
|
123
|
+
this._prev = this._iv.slice(0);
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
modes.cbc.prototype.encrypt = function (input, output, finish) {
|
|
127
|
+
// not enough input to encrypt
|
|
128
|
+
if (input.length() < this.blockSize && !(finish && input.length() > 0)) {
|
|
129
|
+
return true;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// get next block
|
|
133
|
+
// CBC XOR's IV (or previous block) with plaintext
|
|
134
|
+
for (var i = 0; i < this._ints; ++i) {
|
|
135
|
+
this._inBlock[i] = this._prev[i] ^ input.getInt32();
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// encrypt block
|
|
139
|
+
this.cipher.encrypt(this._inBlock, this._outBlock);
|
|
140
|
+
|
|
141
|
+
// write output, save previous block
|
|
142
|
+
for (var i = 0; i < this._ints; ++i) {
|
|
143
|
+
output.putInt32(this._outBlock[i]);
|
|
144
|
+
}
|
|
145
|
+
this._prev = this._outBlock;
|
|
146
|
+
};
|
|
147
|
+
modes.cbc.prototype.decrypt = function (input, output, finish) {
|
|
148
|
+
// not enough input to decrypt
|
|
149
|
+
if (input.length() < this.blockSize && !(finish && input.length() > 0)) {
|
|
150
|
+
return true;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// get next block
|
|
154
|
+
for (var i = 0; i < this._ints; ++i) {
|
|
155
|
+
this._inBlock[i] = input.getInt32();
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// decrypt block
|
|
159
|
+
this.cipher.decrypt(this._inBlock, this._outBlock);
|
|
160
|
+
|
|
161
|
+
// write output, save previous ciphered block
|
|
162
|
+
// CBC XOR's IV (or previous block) with ciphertext
|
|
163
|
+
for (var i = 0; i < this._ints; ++i) {
|
|
164
|
+
output.putInt32(this._prev[i] ^ this._outBlock[i]);
|
|
165
|
+
}
|
|
166
|
+
this._prev = this._inBlock.slice(0);
|
|
167
|
+
};
|
|
168
|
+
modes.cbc.prototype.pad = function (input, options) {
|
|
169
|
+
// add PKCS#7 padding to block (each pad byte is the
|
|
170
|
+
// value of the number of pad bytes)
|
|
171
|
+
var padding = input.length() === this.blockSize ? this.blockSize : this.blockSize - input.length();
|
|
172
|
+
input.fillWithByte(padding, padding);
|
|
173
|
+
return true;
|
|
174
|
+
};
|
|
175
|
+
modes.cbc.prototype.unpad = function (output, options) {
|
|
176
|
+
// check for error: input data not a multiple of blockSize
|
|
177
|
+
if (options.overflow > 0) {
|
|
178
|
+
return false;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// ensure padding byte count is valid
|
|
182
|
+
var len = output.length();
|
|
183
|
+
var count = output.at(len - 1);
|
|
184
|
+
if (count > this.blockSize << 2) {
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// trim off padding bytes
|
|
189
|
+
output.truncate(count);
|
|
190
|
+
return true;
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
/** Cipher feedback (CFB) **/
|
|
194
|
+
|
|
195
|
+
modes.cfb = function (options) {
|
|
196
|
+
options = options || {};
|
|
197
|
+
this.name = 'CFB';
|
|
198
|
+
this.cipher = options.cipher;
|
|
199
|
+
this.blockSize = options.blockSize || 16;
|
|
200
|
+
this._ints = this.blockSize / 4;
|
|
201
|
+
this._inBlock = null;
|
|
202
|
+
this._outBlock = new Array(this._ints);
|
|
203
|
+
this._partialBlock = new Array(this._ints);
|
|
204
|
+
this._partialOutput = forge.util.createBuffer();
|
|
205
|
+
this._partialBytes = 0;
|
|
206
|
+
};
|
|
207
|
+
modes.cfb.prototype.start = function (options) {
|
|
208
|
+
if (!('iv' in options)) {
|
|
209
|
+
throw new Error('Invalid IV parameter.');
|
|
210
|
+
}
|
|
211
|
+
// use IV as first input
|
|
212
|
+
this._iv = transformIV(options.iv, this.blockSize);
|
|
213
|
+
this._inBlock = this._iv.slice(0);
|
|
214
|
+
this._partialBytes = 0;
|
|
215
|
+
};
|
|
216
|
+
modes.cfb.prototype.encrypt = function (input, output, finish) {
|
|
217
|
+
// not enough input to encrypt
|
|
218
|
+
var inputLength = input.length();
|
|
219
|
+
if (inputLength === 0) {
|
|
220
|
+
return true;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// encrypt block
|
|
224
|
+
this.cipher.encrypt(this._inBlock, this._outBlock);
|
|
225
|
+
|
|
226
|
+
// handle full block
|
|
227
|
+
if (this._partialBytes === 0 && inputLength >= this.blockSize) {
|
|
228
|
+
// XOR input with output, write input as output
|
|
229
|
+
for (var i = 0; i < this._ints; ++i) {
|
|
230
|
+
this._inBlock[i] = input.getInt32() ^ this._outBlock[i];
|
|
231
|
+
output.putInt32(this._inBlock[i]);
|
|
232
|
+
}
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// handle partial block
|
|
237
|
+
var partialBytes = (this.blockSize - inputLength) % this.blockSize;
|
|
238
|
+
if (partialBytes > 0) {
|
|
239
|
+
partialBytes = this.blockSize - partialBytes;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// XOR input with output, write input as partial output
|
|
243
|
+
this._partialOutput.clear();
|
|
244
|
+
for (var i = 0; i < this._ints; ++i) {
|
|
245
|
+
this._partialBlock[i] = input.getInt32() ^ this._outBlock[i];
|
|
246
|
+
this._partialOutput.putInt32(this._partialBlock[i]);
|
|
247
|
+
}
|
|
248
|
+
if (partialBytes > 0) {
|
|
249
|
+
// block still incomplete, restore input buffer
|
|
250
|
+
input.read -= this.blockSize;
|
|
251
|
+
} else {
|
|
252
|
+
// block complete, update input block
|
|
253
|
+
for (var i = 0; i < this._ints; ++i) {
|
|
254
|
+
this._inBlock[i] = this._partialBlock[i];
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// skip any previous partial bytes
|
|
259
|
+
if (this._partialBytes > 0) {
|
|
260
|
+
this._partialOutput.getBytes(this._partialBytes);
|
|
261
|
+
}
|
|
262
|
+
if (partialBytes > 0 && !finish) {
|
|
263
|
+
output.putBytes(this._partialOutput.getBytes(partialBytes - this._partialBytes));
|
|
264
|
+
this._partialBytes = partialBytes;
|
|
265
|
+
return true;
|
|
266
|
+
}
|
|
267
|
+
output.putBytes(this._partialOutput.getBytes(inputLength - this._partialBytes));
|
|
268
|
+
this._partialBytes = 0;
|
|
269
|
+
};
|
|
270
|
+
modes.cfb.prototype.decrypt = function (input, output, finish) {
|
|
271
|
+
// not enough input to decrypt
|
|
272
|
+
var inputLength = input.length();
|
|
273
|
+
if (inputLength === 0) {
|
|
274
|
+
return true;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
// encrypt block (CFB always uses encryption mode)
|
|
278
|
+
this.cipher.encrypt(this._inBlock, this._outBlock);
|
|
279
|
+
|
|
280
|
+
// handle full block
|
|
281
|
+
if (this._partialBytes === 0 && inputLength >= this.blockSize) {
|
|
282
|
+
// XOR input with output, write input as output
|
|
283
|
+
for (var i = 0; i < this._ints; ++i) {
|
|
284
|
+
this._inBlock[i] = input.getInt32();
|
|
285
|
+
output.putInt32(this._inBlock[i] ^ this._outBlock[i]);
|
|
286
|
+
}
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// handle partial block
|
|
291
|
+
var partialBytes = (this.blockSize - inputLength) % this.blockSize;
|
|
292
|
+
if (partialBytes > 0) {
|
|
293
|
+
partialBytes = this.blockSize - partialBytes;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// XOR input with output, write input as partial output
|
|
297
|
+
this._partialOutput.clear();
|
|
298
|
+
for (var i = 0; i < this._ints; ++i) {
|
|
299
|
+
this._partialBlock[i] = input.getInt32();
|
|
300
|
+
this._partialOutput.putInt32(this._partialBlock[i] ^ this._outBlock[i]);
|
|
301
|
+
}
|
|
302
|
+
if (partialBytes > 0) {
|
|
303
|
+
// block still incomplete, restore input buffer
|
|
304
|
+
input.read -= this.blockSize;
|
|
305
|
+
} else {
|
|
306
|
+
// block complete, update input block
|
|
307
|
+
for (var i = 0; i < this._ints; ++i) {
|
|
308
|
+
this._inBlock[i] = this._partialBlock[i];
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
// skip any previous partial bytes
|
|
313
|
+
if (this._partialBytes > 0) {
|
|
314
|
+
this._partialOutput.getBytes(this._partialBytes);
|
|
315
|
+
}
|
|
316
|
+
if (partialBytes > 0 && !finish) {
|
|
317
|
+
output.putBytes(this._partialOutput.getBytes(partialBytes - this._partialBytes));
|
|
318
|
+
this._partialBytes = partialBytes;
|
|
319
|
+
return true;
|
|
320
|
+
}
|
|
321
|
+
output.putBytes(this._partialOutput.getBytes(inputLength - this._partialBytes));
|
|
322
|
+
this._partialBytes = 0;
|
|
323
|
+
};
|
|
324
|
+
|
|
325
|
+
/** Output feedback (OFB) **/
|
|
326
|
+
|
|
327
|
+
modes.ofb = function (options) {
|
|
328
|
+
options = options || {};
|
|
329
|
+
this.name = 'OFB';
|
|
330
|
+
this.cipher = options.cipher;
|
|
331
|
+
this.blockSize = options.blockSize || 16;
|
|
332
|
+
this._ints = this.blockSize / 4;
|
|
333
|
+
this._inBlock = null;
|
|
334
|
+
this._outBlock = new Array(this._ints);
|
|
335
|
+
this._partialOutput = forge.util.createBuffer();
|
|
336
|
+
this._partialBytes = 0;
|
|
337
|
+
};
|
|
338
|
+
modes.ofb.prototype.start = function (options) {
|
|
339
|
+
if (!('iv' in options)) {
|
|
340
|
+
throw new Error('Invalid IV parameter.');
|
|
341
|
+
}
|
|
342
|
+
// use IV as first input
|
|
343
|
+
this._iv = transformIV(options.iv, this.blockSize);
|
|
344
|
+
this._inBlock = this._iv.slice(0);
|
|
345
|
+
this._partialBytes = 0;
|
|
346
|
+
};
|
|
347
|
+
modes.ofb.prototype.encrypt = function (input, output, finish) {
|
|
348
|
+
// not enough input to encrypt
|
|
349
|
+
var inputLength = input.length();
|
|
350
|
+
if (input.length() === 0) {
|
|
351
|
+
return true;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
// encrypt block (OFB always uses encryption mode)
|
|
355
|
+
this.cipher.encrypt(this._inBlock, this._outBlock);
|
|
356
|
+
|
|
357
|
+
// handle full block
|
|
358
|
+
if (this._partialBytes === 0 && inputLength >= this.blockSize) {
|
|
359
|
+
// XOR input with output and update next input
|
|
360
|
+
for (var i = 0; i < this._ints; ++i) {
|
|
361
|
+
output.putInt32(input.getInt32() ^ this._outBlock[i]);
|
|
362
|
+
this._inBlock[i] = this._outBlock[i];
|
|
363
|
+
}
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
// handle partial block
|
|
368
|
+
var partialBytes = (this.blockSize - inputLength) % this.blockSize;
|
|
369
|
+
if (partialBytes > 0) {
|
|
370
|
+
partialBytes = this.blockSize - partialBytes;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
// XOR input with output
|
|
374
|
+
this._partialOutput.clear();
|
|
375
|
+
for (var i = 0; i < this._ints; ++i) {
|
|
376
|
+
this._partialOutput.putInt32(input.getInt32() ^ this._outBlock[i]);
|
|
377
|
+
}
|
|
378
|
+
if (partialBytes > 0) {
|
|
379
|
+
// block still incomplete, restore input buffer
|
|
380
|
+
input.read -= this.blockSize;
|
|
381
|
+
} else {
|
|
382
|
+
// block complete, update input block
|
|
383
|
+
for (var i = 0; i < this._ints; ++i) {
|
|
384
|
+
this._inBlock[i] = this._outBlock[i];
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
// skip any previous partial bytes
|
|
389
|
+
if (this._partialBytes > 0) {
|
|
390
|
+
this._partialOutput.getBytes(this._partialBytes);
|
|
391
|
+
}
|
|
392
|
+
if (partialBytes > 0 && !finish) {
|
|
393
|
+
output.putBytes(this._partialOutput.getBytes(partialBytes - this._partialBytes));
|
|
394
|
+
this._partialBytes = partialBytes;
|
|
395
|
+
return true;
|
|
396
|
+
}
|
|
397
|
+
output.putBytes(this._partialOutput.getBytes(inputLength - this._partialBytes));
|
|
398
|
+
this._partialBytes = 0;
|
|
399
|
+
};
|
|
400
|
+
modes.ofb.prototype.decrypt = modes.ofb.prototype.encrypt;
|
|
401
|
+
|
|
402
|
+
/** Counter (CTR) **/
|
|
403
|
+
|
|
404
|
+
modes.ctr = function (options) {
|
|
405
|
+
options = options || {};
|
|
406
|
+
this.name = 'CTR';
|
|
407
|
+
this.cipher = options.cipher;
|
|
408
|
+
this.blockSize = options.blockSize || 16;
|
|
409
|
+
this._ints = this.blockSize / 4;
|
|
410
|
+
this._inBlock = null;
|
|
411
|
+
this._outBlock = new Array(this._ints);
|
|
412
|
+
this._partialOutput = forge.util.createBuffer();
|
|
413
|
+
this._partialBytes = 0;
|
|
414
|
+
};
|
|
415
|
+
modes.ctr.prototype.start = function (options) {
|
|
416
|
+
if (!('iv' in options)) {
|
|
417
|
+
throw new Error('Invalid IV parameter.');
|
|
418
|
+
}
|
|
419
|
+
// use IV as first input
|
|
420
|
+
this._iv = transformIV(options.iv, this.blockSize);
|
|
421
|
+
this._inBlock = this._iv.slice(0);
|
|
422
|
+
this._partialBytes = 0;
|
|
423
|
+
};
|
|
424
|
+
modes.ctr.prototype.encrypt = function (input, output, finish) {
|
|
425
|
+
// not enough input to encrypt
|
|
426
|
+
var inputLength = input.length();
|
|
427
|
+
if (inputLength === 0) {
|
|
428
|
+
return true;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
// encrypt block (CTR always uses encryption mode)
|
|
432
|
+
this.cipher.encrypt(this._inBlock, this._outBlock);
|
|
433
|
+
|
|
434
|
+
// handle full block
|
|
435
|
+
if (this._partialBytes === 0 && inputLength >= this.blockSize) {
|
|
436
|
+
// XOR input with output
|
|
437
|
+
for (var i = 0; i < this._ints; ++i) {
|
|
438
|
+
output.putInt32(input.getInt32() ^ this._outBlock[i]);
|
|
439
|
+
}
|
|
440
|
+
} else {
|
|
441
|
+
// handle partial block
|
|
442
|
+
var partialBytes = (this.blockSize - inputLength) % this.blockSize;
|
|
443
|
+
if (partialBytes > 0) {
|
|
444
|
+
partialBytes = this.blockSize - partialBytes;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
// XOR input with output
|
|
448
|
+
this._partialOutput.clear();
|
|
449
|
+
for (var i = 0; i < this._ints; ++i) {
|
|
450
|
+
this._partialOutput.putInt32(input.getInt32() ^ this._outBlock[i]);
|
|
451
|
+
}
|
|
452
|
+
if (partialBytes > 0) {
|
|
453
|
+
// block still incomplete, restore input buffer
|
|
454
|
+
input.read -= this.blockSize;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
// skip any previous partial bytes
|
|
458
|
+
if (this._partialBytes > 0) {
|
|
459
|
+
this._partialOutput.getBytes(this._partialBytes);
|
|
460
|
+
}
|
|
461
|
+
if (partialBytes > 0 && !finish) {
|
|
462
|
+
output.putBytes(this._partialOutput.getBytes(partialBytes - this._partialBytes));
|
|
463
|
+
this._partialBytes = partialBytes;
|
|
464
|
+
return true;
|
|
465
|
+
}
|
|
466
|
+
output.putBytes(this._partialOutput.getBytes(inputLength - this._partialBytes));
|
|
467
|
+
this._partialBytes = 0;
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
// block complete, increment counter (input block)
|
|
471
|
+
inc32(this._inBlock);
|
|
472
|
+
};
|
|
473
|
+
modes.ctr.prototype.decrypt = modes.ctr.prototype.encrypt;
|
|
474
|
+
|
|
475
|
+
/** Galois/Counter Mode (GCM) **/
|
|
476
|
+
|
|
477
|
+
modes.gcm = function (options) {
|
|
478
|
+
options = options || {};
|
|
479
|
+
this.name = 'GCM';
|
|
480
|
+
this.cipher = options.cipher;
|
|
481
|
+
this.blockSize = options.blockSize || 16;
|
|
482
|
+
this._ints = this.blockSize / 4;
|
|
483
|
+
this._inBlock = new Array(this._ints);
|
|
484
|
+
this._outBlock = new Array(this._ints);
|
|
485
|
+
this._partialOutput = forge.util.createBuffer();
|
|
486
|
+
this._partialBytes = 0;
|
|
487
|
+
|
|
488
|
+
// R is actually this value concatenated with 120 more zero bits, but
|
|
489
|
+
// we only XOR against R so the other zeros have no effect -- we just
|
|
490
|
+
// apply this value to the first integer in a block
|
|
491
|
+
this._R = 0xE1000000;
|
|
492
|
+
};
|
|
493
|
+
modes.gcm.prototype.start = function (options) {
|
|
494
|
+
if (!('iv' in options)) {
|
|
495
|
+
throw new Error('Invalid IV parameter.');
|
|
496
|
+
}
|
|
497
|
+
// ensure IV is a byte buffer
|
|
498
|
+
var iv = forge.util.createBuffer(options.iv);
|
|
499
|
+
|
|
500
|
+
// no ciphered data processed yet
|
|
501
|
+
this._cipherLength = 0;
|
|
502
|
+
|
|
503
|
+
// default additional data is none
|
|
504
|
+
var additionalData;
|
|
505
|
+
if ('additionalData' in options) {
|
|
506
|
+
additionalData = forge.util.createBuffer(options.additionalData);
|
|
507
|
+
} else {
|
|
508
|
+
additionalData = forge.util.createBuffer();
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
// default tag length is 128 bits
|
|
512
|
+
if ('tagLength' in options) {
|
|
513
|
+
this._tagLength = options.tagLength;
|
|
514
|
+
} else {
|
|
515
|
+
this._tagLength = 128;
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
// if tag is given, ensure tag matches tag length
|
|
519
|
+
this._tag = null;
|
|
520
|
+
if (options.decrypt) {
|
|
521
|
+
// save tag to check later
|
|
522
|
+
this._tag = forge.util.createBuffer(options.tag).getBytes();
|
|
523
|
+
if (this._tag.length !== this._tagLength / 8) {
|
|
524
|
+
throw new Error('Authentication tag does not match tag length.');
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
// create tmp storage for hash calculation
|
|
529
|
+
this._hashBlock = new Array(this._ints);
|
|
530
|
+
|
|
531
|
+
// no tag generated yet
|
|
532
|
+
this.tag = null;
|
|
533
|
+
|
|
534
|
+
// generate hash subkey
|
|
535
|
+
// (apply block cipher to "zero" block)
|
|
536
|
+
this._hashSubkey = new Array(this._ints);
|
|
537
|
+
this.cipher.encrypt([0, 0, 0, 0], this._hashSubkey);
|
|
538
|
+
|
|
539
|
+
// generate table M
|
|
540
|
+
// use 4-bit tables (32 component decomposition of a 16 byte value)
|
|
541
|
+
// 8-bit tables take more space and are known to have security
|
|
542
|
+
// vulnerabilities (in native implementations)
|
|
543
|
+
this.componentBits = 4;
|
|
544
|
+
this._m = this.generateHashTable(this._hashSubkey, this.componentBits);
|
|
545
|
+
|
|
546
|
+
// Note: support IV length different from 96 bits? (only supporting
|
|
547
|
+
// 96 bits is recommended by NIST SP-800-38D)
|
|
548
|
+
// generate J_0
|
|
549
|
+
var ivLength = iv.length();
|
|
550
|
+
if (ivLength === 12) {
|
|
551
|
+
// 96-bit IV
|
|
552
|
+
this._j0 = [iv.getInt32(), iv.getInt32(), iv.getInt32(), 1];
|
|
553
|
+
} else {
|
|
554
|
+
// IV is NOT 96-bits
|
|
555
|
+
this._j0 = [0, 0, 0, 0];
|
|
556
|
+
while (iv.length() > 0) {
|
|
557
|
+
this._j0 = this.ghash(this._hashSubkey, this._j0, [iv.getInt32(), iv.getInt32(), iv.getInt32(), iv.getInt32()]);
|
|
558
|
+
}
|
|
559
|
+
this._j0 = this.ghash(this._hashSubkey, this._j0, [0, 0].concat(from64To32(ivLength * 8)));
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
// generate ICB (initial counter block)
|
|
563
|
+
this._inBlock = this._j0.slice(0);
|
|
564
|
+
inc32(this._inBlock);
|
|
565
|
+
this._partialBytes = 0;
|
|
566
|
+
|
|
567
|
+
// consume authentication data
|
|
568
|
+
additionalData = forge.util.createBuffer(additionalData);
|
|
569
|
+
// save additional data length as a BE 64-bit number
|
|
570
|
+
this._aDataLength = from64To32(additionalData.length() * 8);
|
|
571
|
+
// pad additional data to 128 bit (16 byte) block size
|
|
572
|
+
var overflow = additionalData.length() % this.blockSize;
|
|
573
|
+
if (overflow) {
|
|
574
|
+
additionalData.fillWithByte(0, this.blockSize - overflow);
|
|
575
|
+
}
|
|
576
|
+
this._s = [0, 0, 0, 0];
|
|
577
|
+
while (additionalData.length() > 0) {
|
|
578
|
+
this._s = this.ghash(this._hashSubkey, this._s, [additionalData.getInt32(), additionalData.getInt32(), additionalData.getInt32(), additionalData.getInt32()]);
|
|
579
|
+
}
|
|
580
|
+
};
|
|
581
|
+
modes.gcm.prototype.encrypt = function (input, output, finish) {
|
|
582
|
+
// not enough input to encrypt
|
|
583
|
+
var inputLength = input.length();
|
|
584
|
+
if (inputLength === 0) {
|
|
585
|
+
return true;
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
// encrypt block
|
|
589
|
+
this.cipher.encrypt(this._inBlock, this._outBlock);
|
|
590
|
+
|
|
591
|
+
// handle full block
|
|
592
|
+
if (this._partialBytes === 0 && inputLength >= this.blockSize) {
|
|
593
|
+
// XOR input with output
|
|
594
|
+
for (var i = 0; i < this._ints; ++i) {
|
|
595
|
+
output.putInt32(this._outBlock[i] ^= input.getInt32());
|
|
596
|
+
}
|
|
597
|
+
this._cipherLength += this.blockSize;
|
|
598
|
+
} else {
|
|
599
|
+
// handle partial block
|
|
600
|
+
var partialBytes = (this.blockSize - inputLength) % this.blockSize;
|
|
601
|
+
if (partialBytes > 0) {
|
|
602
|
+
partialBytes = this.blockSize - partialBytes;
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
// XOR input with output
|
|
606
|
+
this._partialOutput.clear();
|
|
607
|
+
for (var i = 0; i < this._ints; ++i) {
|
|
608
|
+
this._partialOutput.putInt32(input.getInt32() ^ this._outBlock[i]);
|
|
609
|
+
}
|
|
610
|
+
if (partialBytes <= 0 || finish) {
|
|
611
|
+
// handle overflow prior to hashing
|
|
612
|
+
if (finish) {
|
|
613
|
+
// get block overflow
|
|
614
|
+
var overflow = inputLength % this.blockSize;
|
|
615
|
+
this._cipherLength += overflow;
|
|
616
|
+
// truncate for hash function
|
|
617
|
+
this._partialOutput.truncate(this.blockSize - overflow);
|
|
618
|
+
} else {
|
|
619
|
+
this._cipherLength += this.blockSize;
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
// get output block for hashing
|
|
623
|
+
for (var i = 0; i < this._ints; ++i) {
|
|
624
|
+
this._outBlock[i] = this._partialOutput.getInt32();
|
|
625
|
+
}
|
|
626
|
+
this._partialOutput.read -= this.blockSize;
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
// skip any previous partial bytes
|
|
630
|
+
if (this._partialBytes > 0) {
|
|
631
|
+
this._partialOutput.getBytes(this._partialBytes);
|
|
632
|
+
}
|
|
633
|
+
if (partialBytes > 0 && !finish) {
|
|
634
|
+
// block still incomplete, restore input buffer, get partial output,
|
|
635
|
+
// and return early
|
|
636
|
+
input.read -= this.blockSize;
|
|
637
|
+
output.putBytes(this._partialOutput.getBytes(partialBytes - this._partialBytes));
|
|
638
|
+
this._partialBytes = partialBytes;
|
|
639
|
+
return true;
|
|
640
|
+
}
|
|
641
|
+
output.putBytes(this._partialOutput.getBytes(inputLength - this._partialBytes));
|
|
642
|
+
this._partialBytes = 0;
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
// update hash block S
|
|
646
|
+
this._s = this.ghash(this._hashSubkey, this._s, this._outBlock);
|
|
647
|
+
|
|
648
|
+
// increment counter (input block)
|
|
649
|
+
inc32(this._inBlock);
|
|
650
|
+
};
|
|
651
|
+
modes.gcm.prototype.decrypt = function (input, output, finish) {
|
|
652
|
+
// not enough input to decrypt
|
|
653
|
+
var inputLength = input.length();
|
|
654
|
+
if (inputLength < this.blockSize && !(finish && inputLength > 0)) {
|
|
655
|
+
return true;
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
// encrypt block (GCM always uses encryption mode)
|
|
659
|
+
this.cipher.encrypt(this._inBlock, this._outBlock);
|
|
660
|
+
|
|
661
|
+
// increment counter (input block)
|
|
662
|
+
inc32(this._inBlock);
|
|
663
|
+
|
|
664
|
+
// update hash block S
|
|
665
|
+
this._hashBlock[0] = input.getInt32();
|
|
666
|
+
this._hashBlock[1] = input.getInt32();
|
|
667
|
+
this._hashBlock[2] = input.getInt32();
|
|
668
|
+
this._hashBlock[3] = input.getInt32();
|
|
669
|
+
this._s = this.ghash(this._hashSubkey, this._s, this._hashBlock);
|
|
670
|
+
|
|
671
|
+
// XOR hash input with output
|
|
672
|
+
for (var i = 0; i < this._ints; ++i) {
|
|
673
|
+
output.putInt32(this._outBlock[i] ^ this._hashBlock[i]);
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
// increment cipher data length
|
|
677
|
+
if (inputLength < this.blockSize) {
|
|
678
|
+
this._cipherLength += inputLength % this.blockSize;
|
|
679
|
+
} else {
|
|
680
|
+
this._cipherLength += this.blockSize;
|
|
681
|
+
}
|
|
682
|
+
};
|
|
683
|
+
modes.gcm.prototype.afterFinish = function (output, options) {
|
|
684
|
+
var rval = true;
|
|
685
|
+
|
|
686
|
+
// handle overflow
|
|
687
|
+
if (options.decrypt && options.overflow) {
|
|
688
|
+
output.truncate(this.blockSize - options.overflow);
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
// handle authentication tag
|
|
692
|
+
this.tag = forge.util.createBuffer();
|
|
693
|
+
|
|
694
|
+
// concatenate additional data length with cipher length
|
|
695
|
+
var lengths = this._aDataLength.concat(from64To32(this._cipherLength * 8));
|
|
696
|
+
|
|
697
|
+
// include lengths in hash
|
|
698
|
+
this._s = this.ghash(this._hashSubkey, this._s, lengths);
|
|
699
|
+
|
|
700
|
+
// do GCTR(J_0, S)
|
|
701
|
+
var tag = [];
|
|
702
|
+
this.cipher.encrypt(this._j0, tag);
|
|
703
|
+
for (var i = 0; i < this._ints; ++i) {
|
|
704
|
+
this.tag.putInt32(this._s[i] ^ tag[i]);
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
// trim tag to length
|
|
708
|
+
this.tag.truncate(this.tag.length() % (this._tagLength / 8));
|
|
709
|
+
|
|
710
|
+
// check authentication tag
|
|
711
|
+
if (options.decrypt && this.tag.bytes() !== this._tag) {
|
|
712
|
+
rval = false;
|
|
713
|
+
}
|
|
714
|
+
return rval;
|
|
715
|
+
};
|
|
716
|
+
|
|
717
|
+
/**
|
|
718
|
+
* See NIST SP-800-38D 6.3 (Algorithm 1). This function performs Galois
|
|
719
|
+
* field multiplication. The field, GF(2^128), is defined by the polynomial:
|
|
720
|
+
*
|
|
721
|
+
* x^128 + x^7 + x^2 + x + 1
|
|
722
|
+
*
|
|
723
|
+
* Which is represented in little-endian binary form as: 11100001 (0xe1). When
|
|
724
|
+
* the value of a coefficient is 1, a bit is set. The value R, is the
|
|
725
|
+
* concatenation of this value and 120 zero bits, yielding a 128-bit value
|
|
726
|
+
* which matches the block size.
|
|
727
|
+
*
|
|
728
|
+
* This function will multiply two elements (vectors of bytes), X and Y, in
|
|
729
|
+
* the field GF(2^128). The result is initialized to zero. For each bit of
|
|
730
|
+
* X (out of 128), x_i, if x_i is set, then the result is multiplied (XOR'd)
|
|
731
|
+
* by the current value of Y. For each bit, the value of Y will be raised by
|
|
732
|
+
* a power of x (multiplied by the polynomial x). This can be achieved by
|
|
733
|
+
* shifting Y once to the right. If the current value of Y, prior to being
|
|
734
|
+
* multiplied by x, has 0 as its LSB, then it is a 127th degree polynomial.
|
|
735
|
+
* Otherwise, we must divide by R after shifting to find the remainder.
|
|
736
|
+
*
|
|
737
|
+
* @param x the first block to multiply by the second.
|
|
738
|
+
* @param y the second block to multiply by the first.
|
|
739
|
+
*
|
|
740
|
+
* @return the block result of the multiplication.
|
|
741
|
+
*/
|
|
742
|
+
modes.gcm.prototype.multiply = function (x, y) {
|
|
743
|
+
var z_i = [0, 0, 0, 0];
|
|
744
|
+
var v_i = y.slice(0);
|
|
745
|
+
|
|
746
|
+
// calculate Z_128 (block has 128 bits)
|
|
747
|
+
for (var i = 0; i < 128; ++i) {
|
|
748
|
+
// if x_i is 0, Z_{i+1} = Z_i (unchanged)
|
|
749
|
+
// else Z_{i+1} = Z_i ^ V_i
|
|
750
|
+
// get x_i by finding 32-bit int position, then left shift 1 by remainder
|
|
751
|
+
var x_i = x[i / 32 | 0] & 1 << 31 - i % 32;
|
|
752
|
+
if (x_i) {
|
|
753
|
+
z_i[0] ^= v_i[0];
|
|
754
|
+
z_i[1] ^= v_i[1];
|
|
755
|
+
z_i[2] ^= v_i[2];
|
|
756
|
+
z_i[3] ^= v_i[3];
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
// if LSB(V_i) is 1, V_i = V_i >> 1
|
|
760
|
+
// else V_i = (V_i >> 1) ^ R
|
|
761
|
+
this.pow(v_i, v_i);
|
|
762
|
+
}
|
|
763
|
+
return z_i;
|
|
764
|
+
};
|
|
765
|
+
modes.gcm.prototype.pow = function (x, out) {
|
|
766
|
+
// if LSB(x) is 1, x = x >>> 1
|
|
767
|
+
// else x = (x >>> 1) ^ R
|
|
768
|
+
var lsb = x[3] & 1;
|
|
769
|
+
|
|
770
|
+
// always do x >>> 1:
|
|
771
|
+
// starting with the rightmost integer, shift each integer to the right
|
|
772
|
+
// one bit, pulling in the bit from the integer to the left as its top
|
|
773
|
+
// most bit (do this for the last 3 integers)
|
|
774
|
+
for (var i = 3; i > 0; --i) {
|
|
775
|
+
out[i] = x[i] >>> 1 | (x[i - 1] & 1) << 31;
|
|
776
|
+
}
|
|
777
|
+
// shift the first integer normally
|
|
778
|
+
out[0] = x[0] >>> 1;
|
|
779
|
+
|
|
780
|
+
// if lsb was not set, then polynomial had a degree of 127 and doesn't
|
|
781
|
+
// need to divided; otherwise, XOR with R to find the remainder; we only
|
|
782
|
+
// need to XOR the first integer since R technically ends w/120 zero bits
|
|
783
|
+
if (lsb) {
|
|
784
|
+
out[0] ^= this._R;
|
|
785
|
+
}
|
|
786
|
+
};
|
|
787
|
+
modes.gcm.prototype.tableMultiply = function (x) {
|
|
788
|
+
// assumes 4-bit tables are used
|
|
789
|
+
var z = [0, 0, 0, 0];
|
|
790
|
+
for (var i = 0; i < 32; ++i) {
|
|
791
|
+
var idx = i / 8 | 0;
|
|
792
|
+
var x_i = x[idx] >>> (7 - i % 8) * 4 & 0xF;
|
|
793
|
+
var ah = this._m[i][x_i];
|
|
794
|
+
z[0] ^= ah[0];
|
|
795
|
+
z[1] ^= ah[1];
|
|
796
|
+
z[2] ^= ah[2];
|
|
797
|
+
z[3] ^= ah[3];
|
|
798
|
+
}
|
|
799
|
+
return z;
|
|
800
|
+
};
|
|
801
|
+
|
|
802
|
+
/**
|
|
803
|
+
* A continuing version of the GHASH algorithm that operates on a single
|
|
804
|
+
* block. The hash block, last hash value (Ym) and the new block to hash
|
|
805
|
+
* are given.
|
|
806
|
+
*
|
|
807
|
+
* @param h the hash block.
|
|
808
|
+
* @param y the previous value for Ym, use [0, 0, 0, 0] for a new hash.
|
|
809
|
+
* @param x the block to hash.
|
|
810
|
+
*
|
|
811
|
+
* @return the hashed value (Ym).
|
|
812
|
+
*/
|
|
813
|
+
modes.gcm.prototype.ghash = function (h, y, x) {
|
|
814
|
+
y[0] ^= x[0];
|
|
815
|
+
y[1] ^= x[1];
|
|
816
|
+
y[2] ^= x[2];
|
|
817
|
+
y[3] ^= x[3];
|
|
818
|
+
return this.tableMultiply(y);
|
|
819
|
+
//return this.multiply(y, h);
|
|
820
|
+
};
|
|
821
|
+
|
|
822
|
+
/**
|
|
823
|
+
* Precomputes a table for multiplying against the hash subkey. This
|
|
824
|
+
* mechanism provides a substantial speed increase over multiplication
|
|
825
|
+
* performed without a table. The table-based multiplication this table is
|
|
826
|
+
* for solves X * H by multiplying each component of X by H and then
|
|
827
|
+
* composing the results together using XOR.
|
|
828
|
+
*
|
|
829
|
+
* This function can be used to generate tables with different bit sizes
|
|
830
|
+
* for the components, however, this implementation assumes there are
|
|
831
|
+
* 32 components of X (which is a 16 byte vector), therefore each component
|
|
832
|
+
* takes 4-bits (so the table is constructed with bits=4).
|
|
833
|
+
*
|
|
834
|
+
* @param h the hash subkey.
|
|
835
|
+
* @param bits the bit size for a component.
|
|
836
|
+
*/
|
|
837
|
+
modes.gcm.prototype.generateHashTable = function (h, bits) {
|
|
838
|
+
// TODO: There are further optimizations that would use only the
|
|
839
|
+
// first table M_0 (or some variant) along with a remainder table;
|
|
840
|
+
// this can be explored in the future
|
|
841
|
+
var multiplier = 8 / bits;
|
|
842
|
+
var perInt = 4 * multiplier;
|
|
843
|
+
var size = 16 * multiplier;
|
|
844
|
+
var m = new Array(size);
|
|
845
|
+
for (var i = 0; i < size; ++i) {
|
|
846
|
+
var tmp = [0, 0, 0, 0];
|
|
847
|
+
var idx = i / perInt | 0;
|
|
848
|
+
var shft = (perInt - 1 - i % perInt) * bits;
|
|
849
|
+
tmp[idx] = 1 << bits - 1 << shft;
|
|
850
|
+
m[i] = this.generateSubHashTable(this.multiply(tmp, h), bits);
|
|
851
|
+
}
|
|
852
|
+
return m;
|
|
853
|
+
};
|
|
854
|
+
|
|
855
|
+
/**
|
|
856
|
+
* Generates a table for multiplying against the hash subkey for one
|
|
857
|
+
* particular component (out of all possible component values).
|
|
858
|
+
*
|
|
859
|
+
* @param mid the pre-multiplied value for the middle key of the table.
|
|
860
|
+
* @param bits the bit size for a component.
|
|
861
|
+
*/
|
|
862
|
+
modes.gcm.prototype.generateSubHashTable = function (mid, bits) {
|
|
863
|
+
// compute the table quickly by minimizing the number of
|
|
864
|
+
// POW operations -- they only need to be performed for powers of 2,
|
|
865
|
+
// all other entries can be composed from those powers using XOR
|
|
866
|
+
var size = 1 << bits;
|
|
867
|
+
var half = size >>> 1;
|
|
868
|
+
var m = new Array(size);
|
|
869
|
+
m[half] = mid.slice(0);
|
|
870
|
+
var i = half >>> 1;
|
|
871
|
+
while (i > 0) {
|
|
872
|
+
// raise m0[2 * i] and store in m0[i]
|
|
873
|
+
this.pow(m[2 * i], m[i] = []);
|
|
874
|
+
i >>= 1;
|
|
875
|
+
}
|
|
876
|
+
i = 2;
|
|
877
|
+
while (i < half) {
|
|
878
|
+
for (var j = 1; j < i; ++j) {
|
|
879
|
+
var m_i = m[i];
|
|
880
|
+
var m_j = m[j];
|
|
881
|
+
m[i + j] = [m_i[0] ^ m_j[0], m_i[1] ^ m_j[1], m_i[2] ^ m_j[2], m_i[3] ^ m_j[3]];
|
|
882
|
+
}
|
|
883
|
+
i *= 2;
|
|
884
|
+
}
|
|
885
|
+
m[0] = [0, 0, 0, 0];
|
|
886
|
+
/* Note: We could avoid storing these by doing composition during multiply
|
|
887
|
+
calculate top half using composition by speed is preferred. */
|
|
888
|
+
for (i = half + 1; i < size; ++i) {
|
|
889
|
+
var c = m[i ^ half];
|
|
890
|
+
m[i] = [mid[0] ^ c[0], mid[1] ^ c[1], mid[2] ^ c[2], mid[3] ^ c[3]];
|
|
891
|
+
}
|
|
892
|
+
return m;
|
|
893
|
+
};
|
|
894
|
+
|
|
895
|
+
/** Utility functions */
|
|
896
|
+
|
|
897
|
+
function transformIV(iv, blockSize) {
|
|
898
|
+
if (typeof iv === 'string') {
|
|
899
|
+
// convert iv string into byte buffer
|
|
900
|
+
iv = forge.util.createBuffer(iv);
|
|
901
|
+
}
|
|
902
|
+
if (forge.util.isArray(iv) && iv.length > 4) {
|
|
903
|
+
// convert iv byte array into byte buffer
|
|
904
|
+
var tmp = iv;
|
|
905
|
+
iv = forge.util.createBuffer();
|
|
906
|
+
for (var i = 0; i < tmp.length; ++i) {
|
|
907
|
+
iv.putByte(tmp[i]);
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
if (iv.length() < blockSize) {
|
|
911
|
+
throw new Error('Invalid IV length; got ' + iv.length() + ' bytes and expected ' + blockSize + ' bytes.');
|
|
912
|
+
}
|
|
913
|
+
if (!forge.util.isArray(iv)) {
|
|
914
|
+
// convert iv byte buffer into 32-bit integer array
|
|
915
|
+
var ints = [];
|
|
916
|
+
var blocks = blockSize / 4;
|
|
917
|
+
for (var i = 0; i < blocks; ++i) {
|
|
918
|
+
ints.push(iv.getInt32());
|
|
919
|
+
}
|
|
920
|
+
iv = ints;
|
|
921
|
+
}
|
|
922
|
+
return iv;
|
|
923
|
+
}
|
|
924
|
+
function inc32(block) {
|
|
925
|
+
// increment last 32 bits of block only
|
|
926
|
+
block[block.length - 1] = block[block.length - 1] + 1 & 0xFFFFFFFF;
|
|
927
|
+
}
|
|
928
|
+
function from64To32(num) {
|
|
929
|
+
// convert 64-bit number to two BE Int32s
|
|
930
|
+
return [num / 0x100000000 | 0, num & 0xFFFFFFFF];
|
|
931
|
+
}
|
|
932
|
+
return cipherModes.exports;
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
export { requireCipherModes as __require };
|
|
936
|
+
//# sourceMappingURL=cipherModes.js.map
|