Diffstat (limited to 'frontend/gamma/js/ClipperzCryptoLibrary/SRP.js') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/gamma/js/ClipperzCryptoLibrary/SRP.js | 326 |
1 files changed, 0 insertions, 326 deletions
diff --git a/frontend/gamma/js/ClipperzCryptoLibrary/SRP.js b/frontend/gamma/js/ClipperzCryptoLibrary/SRP.js deleted file mode 100644 index 8cc80ba..0000000 --- a/frontend/gamma/js/ClipperzCryptoLibrary/SRP.js +++ b/dev/null | |||
@@ -1,326 +0,0 @@ | |||
1 | /* | ||
2 | |||
3 | Copyright 2008-2013 Clipperz Srl | ||
4 | |||
5 | This file is part of Clipperz, the online password manager. | ||
6 | For further information about its features and functionalities please | ||
7 | refer to http://www.clipperz.com. | ||
8 | |||
9 | * Clipperz is free software: you can redistribute it and/or modify it | ||
10 | under the terms of the GNU Affero General Public License as published | ||
11 | by the Free Software Foundation, either version 3 of the License, or | ||
12 | (at your option) any later version. | ||
13 | |||
14 | * Clipperz is distributed in the hope that it will be useful, but | ||
15 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
17 | See the GNU Affero General Public License for more details. | ||
18 | |||
19 | * You should have received a copy of the GNU Affero General Public | ||
20 | License along with Clipperz. If not, see http://www.gnu.org/licenses/. | ||
21 | |||
22 | */ | ||
23 | |||
24 | try { if (typeof(Clipperz.ByteArray) == 'undefined') { throw ""; }} catch (e) { | ||
25 | throw "Clipperz.Crypto.PRNG depends on Clipperz.ByteArray!"; | ||
26 | } | ||
27 | |||
28 | try { if (typeof(Clipperz.Crypto.BigInt) == 'undefined') { throw ""; }} catch (e) { | ||
29 | throw "Clipperz.Crypto.SRP depends on Clipperz.Crypto.BigInt!"; | ||
30 | } | ||
31 | |||
32 | try { if (typeof(Clipperz.Crypto.PRNG) == 'undefined') { throw ""; }} catch (e) { | ||
33 | throw "Clipperz.Crypto.SRP depends on Clipperz.Crypto.PRNG!"; | ||
34 | } | ||
35 | |||
36 | if (typeof(Clipperz.Crypto.SRP) == 'undefined') { Clipperz.Crypto.SRP = {}; } | ||
37 | |||
38 | Clipperz.Crypto.SRP.VERSION = "0.1"; | ||
39 | Clipperz.Crypto.SRP.NAME = "Clipperz.Crypto.SRP"; | ||
40 | |||
41 | //############################################################################# | ||
42 | |||
43 | MochiKit.Base.update(Clipperz.Crypto.SRP, { | ||
44 | |||
45 | '_n': null, | ||
46 | '_g': null, | ||
47 | //------------------------------------------------------------------------- | ||
48 | |||
49 | 'n': function() { | ||
50 | if (Clipperz.Crypto.SRP._n == null) { | ||
51 | Clipperz.Crypto.SRP._n = new Clipperz.Crypto.BigInt("115b8b692e0e045692cf280b436735c77a5a9e8a9e7ed56c965f87db5b2a2ece3", 16); | ||
52 | } | ||
53 | |||
54 | return Clipperz.Crypto.SRP._n; | ||
55 | }, | ||
56 | |||
57 | //------------------------------------------------------------------------- | ||
58 | |||
59 | 'g': function() { | ||
60 | if (Clipperz.Crypto.SRP._g == null) { | ||
61 | Clipperz.Crypto.SRP._g = new Clipperz.Crypto.BigInt(2); //eventually 5 (as suggested on the Diffi-Helmann documentation) | ||
62 | } | ||
63 | |||
64 | return Clipperz.Crypto.SRP._g; | ||
65 | }, | ||
66 | |||
67 | //----------------------------------------------------------------------------- | ||
68 | |||
69 | 'exception': { | ||
70 | 'InvalidValue': new MochiKit.Base.NamedError("Clipperz.Crypto.SRP.exception.InvalidValue") | ||
71 | }, | ||
72 | |||
73 | //------------------------------------------------------------------------- | ||
74 | __syntaxFix__: "syntax fix" | ||
75 | |||
76 | }); | ||
77 | |||
78 | //############################################################################# | ||
79 | // | ||
80 | // S R P C o n n e c t i o n version 1.0 | ||
81 | // | ||
82 | //============================================================================= | ||
83 | Clipperz.Crypto.SRP.Connection = function (args) { | ||
84 | args = args || {}; | ||
85 | |||
86 | this._C = args.C; | ||
87 | this._P = args.P; | ||
88 | this.hash = args.hash; | ||
89 | |||
90 | this._a = null; | ||
91 | this._A = null; | ||
92 | |||
93 | this._s = null; | ||
94 | this._B = null; | ||
95 | |||
96 | this._x = null; | ||
97 | |||
98 | this._u = null; | ||
99 | this._K = null; | ||
100 | this._M1 = null; | ||
101 | this._M2 = null; | ||
102 | |||
103 | this._sessionKey = null; | ||
104 | |||
105 | return this; | ||
106 | } | ||
107 | |||
108 | Clipperz.Crypto.SRP.Connection.prototype = MochiKit.Base.update(null, { | ||
109 | |||
110 | 'toString': function () { | ||
111 | return "Clipperz.Crypto.SRP.Connection (username: " + this.username() + "). Status: " + this.statusDescription(); | ||
112 | }, | ||
113 | |||
114 | //------------------------------------------------------------------------- | ||
115 | |||
116 | 'C': function () { | ||
117 | return this._C; | ||
118 | }, | ||
119 | |||
120 | //------------------------------------------------------------------------- | ||
121 | |||
122 | 'P': function () { | ||
123 | return this._P; | ||
124 | }, | ||
125 | |||
126 | //------------------------------------------------------------------------- | ||
127 | |||
128 | 'a': function () { | ||
129 | if (this._a == null) { | ||
130 | this._a = new Clipperz.Crypto.BigInt(Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(32).toHexString().substring(2), 16); | ||
131 | // this._a = new Clipperz.Crypto.BigInt("37532428169486597638072888476611365392249575518156687476805936694442691012367", 10); | ||
132 | //MochiKit.Logging.logDebug("SRP a: " + this._a); | ||
133 | } | ||
134 | |||
135 | return this._a; | ||
136 | }, | ||
137 | |||
138 | //------------------------------------------------------------------------- | ||
139 | |||
140 | 'A': function () { | ||
141 | if (this._A == null) { | ||
142 | //Warning: this value should be strictly greater than zero: how should we perform this check? | ||
143 | this._A = Clipperz.Crypto.SRP.g().powerModule(this.a(), Clipperz.Crypto.SRP.n()); | ||
144 | |||
145 | if (this._A.equals(0)) { | ||
146 | MochiKit.Logging.logError("Clipperz.Crypto.SRP.Connection: trying to set 'A' to 0."); | ||
147 | throw Clipperz.Crypto.SRP.exception.InvalidValue; | ||
148 | } | ||
149 | //MochiKit.Logging.logDebug("SRP A: " + this._A); | ||
150 | } | ||
151 | |||
152 | return this._A; | ||
153 | }, | ||
154 | |||
155 | //------------------------------------------------------------------------- | ||
156 | |||
157 | 's': function () { | ||
158 | return this._s; | ||
159 | //MochiKit.Logging.logDebug("SRP s: " + this._S); | ||
160 | }, | ||
161 | |||
162 | 'set_s': function(aValue) { | ||
163 | this._s = aValue; | ||
164 | }, | ||
165 | |||
166 | //------------------------------------------------------------------------- | ||
167 | |||
168 | 'B': function () { | ||
169 | return this._B; | ||
170 | }, | ||
171 | |||
172 | 'set_B': function(aValue) { | ||
173 | //Warning: this value should be strictly greater than zero: how should we perform this check? | ||
174 | if (! aValue.equals(0)) { | ||
175 | this._B = aValue; | ||
176 | //MochiKit.Logging.logDebug("SRP B: " + this._B); | ||
177 | } else { | ||
178 | MochiKit.Logging.logError("Clipperz.Crypto.SRP.Connection: trying to set 'B' to 0."); | ||
179 | throw Clipperz.Crypto.SRP.exception.InvalidValue; | ||
180 | } | ||
181 | }, | ||
182 | |||
183 | //------------------------------------------------------------------------- | ||
184 | |||
185 | 'x': function () { | ||
186 | if (this._x == null) { | ||
187 | this._x = new Clipperz.Crypto.BigInt(this.stringHash(this.s().asString(16, 64) + this.P()), 16); | ||
188 | //MochiKit.Logging.logDebug("SRP x: " + this._x); | ||
189 | } | ||
190 | |||
191 | return this._x; | ||
192 | }, | ||
193 | |||
194 | //------------------------------------------------------------------------- | ||
195 | |||
196 | 'u': function () { | ||
197 | if (this._u == null) { | ||
198 | this._u = new Clipperz.Crypto.BigInt(this.stringHash(this.B().asString()), 16); | ||
199 | //MochiKit.Logging.logDebug("SRP u: " + this._u); | ||
200 | } | ||
201 | |||
202 | return this._u; | ||
203 | }, | ||
204 | |||
205 | //------------------------------------------------------------------------- | ||
206 | |||
207 | 'S': function () { | ||
208 | if (this._S == null) { | ||
209 | var bigint; | ||
210 | varsrp; | ||
211 | |||
212 | bigint = Clipperz.Crypto.BigInt; | ||
213 | srp = Clipperz.Crypto.SRP; | ||
214 | |||
215 | this._S =bigint.powerModule( | ||
216 | bigint.subtract(this.B(), bigint.powerModule(srp.g(), this.x(), srp.n())), | ||
217 | bigint.add(this.a(), bigint.multiply(this.u(), this.x())), | ||
218 | srp.n() | ||
219 | ) | ||
220 | //MochiKit.Logging.logDebug("SRP S: " + this._S); | ||
221 | } | ||
222 | |||
223 | return this._S; | ||
224 | }, | ||
225 | |||
226 | //------------------------------------------------------------------------- | ||
227 | |||
228 | 'K': function () { | ||
229 | if (this._K == null) { | ||
230 | this._K = this.stringHash(this.S().asString()); | ||
231 | //MochiKit.Logging.logDebug("SRP K: " + this._K); | ||
232 | } | ||
233 | |||
234 | return this._K; | ||
235 | }, | ||
236 | |||
237 | //------------------------------------------------------------------------- | ||
238 | |||
239 | 'M1': function () { | ||
240 | if (this._M1 == null) { | ||
241 | this._M1 = this.stringHash(this.A().asString(10) + this.B().asString(10) + this.K()); | ||
242 | //MochiKit.Logging.logDebug("SRP M1: " + this._M1); | ||
243 | } | ||
244 | |||
245 | return this._M1; | ||
246 | }, | ||
247 | |||
248 | //------------------------------------------------------------------------- | ||
249 | |||
250 | 'M2': function () { | ||
251 | if (this._M2 == null) { | ||
252 | this._M2 = this.stringHash(this.A().asString(10) + this.M1() + this.K()); | ||
253 | //MochiKit.Logging.logDebug("SRP M2: " + this._M2); | ||
254 | } | ||
255 | |||
256 | return this._M2; | ||
257 | }, | ||
258 | |||
259 | //========================================================================= | ||
260 | |||
261 | 'serverSideCredentialsWithSalt': function(aSalt) { | ||
262 | var result; | ||
263 | var s, x, v; | ||
264 | |||
265 | s = aSalt; | ||
266 | x = this.stringHash(s + this.P()); | ||
267 | v = Clipperz.Crypto.SRP.g().powerModule(new Clipperz.Crypto.BigInt(x, 16), Clipperz.Crypto.SRP.n()); | ||
268 | |||
269 | result = {}; | ||
270 | result['C'] = this.C(); | ||
271 | result['s'] = s; | ||
272 | result['v'] = v.asString(16); | ||
273 | |||
274 | return result; | ||
275 | }, | ||
276 | |||
277 | 'serverSideCredentials': function() { | ||
278 | var result; | ||
279 | var s; | ||
280 | |||
281 | s = Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(32).toHexString().substring(2); | ||
282 | |||
283 | result = this.serverSideCredentialsWithSalt(s); | ||
284 | |||
285 | return result; | ||
286 | }, | ||
287 | |||
288 | //========================================================================= | ||
289 | /* | ||
290 | 'computeServerSide_S': function(b) { | ||
291 | var result; | ||
292 | var v; | ||
293 | var bigint; | ||
294 | varsrp; | ||
295 | |||
296 | bigint = Clipperz.Crypto.BigInt; | ||
297 | srp = Clipperz.Crypto.SRP; | ||
298 | |||
299 | v = new Clipperz.Crypto.BigInt(srpConnection.serverSideCredentialsWithSalt(this.s().asString(16, 64)).v, 16); | ||
300 | // _S = (this.A().multiply(this.v().modPow(this.u(), this.n()))).modPow(this.b(), this.n()); | ||
301 | result = bigint.powerModule( | ||
302 | bigint.multiply( | ||
303 | this.A(), | ||
304 | bigint.powerModule(v, this.u(), srp.n()) | ||
305 | ), new Clipperz.Crypto.BigInt(b, 10), srp.n() | ||
306 | ); | ||
307 | |||
308 | return result; | ||
309 | }, | ||
310 | */ | ||
311 | //========================================================================= | ||
312 | |||
313 | 'stringHash': function(aValue) { | ||
314 | varresult; | ||
315 | |||
316 | result = this.hash(new Clipperz.ByteArray(aValue)).toHexString().substring(2); | ||
317 | |||
318 | return result; | ||
319 | }, | ||
320 | |||
321 | //========================================================================= | ||
322 | __syntaxFix__: "syntax fix" | ||
323 | |||
324 | }); | ||
325 | |||
326 | //############################################################################# | ||