summaryrefslogtreecommitdiff
path: root/frontend/delta/js/Clipperz/Crypto/PRNG.js
Unidiff
Diffstat (limited to 'frontend/delta/js/Clipperz/Crypto/PRNG.js') (more/less context) (show whitespace changes)
-rw-r--r--frontend/delta/js/Clipperz/Crypto/PRNG.js4
1 files changed, 2 insertions, 2 deletions
diff --git a/frontend/delta/js/Clipperz/Crypto/PRNG.js b/frontend/delta/js/Clipperz/Crypto/PRNG.js
index 7885429..80d972f 100644
--- a/frontend/delta/js/Clipperz/Crypto/PRNG.js
+++ b/frontend/delta/js/Clipperz/Crypto/PRNG.js
@@ -225,195 +225,195 @@ Clipperz.Crypto.PRNG.MouseRandomnessSource.prototype = MochiKit.Base.update(new
225 'numberOfBitsToCollectAtEachEvent': function() { 225 'numberOfBitsToCollectAtEachEvent': function() {
226 return this._numberOfBitsToCollectAtEachEvent; 226 return this._numberOfBitsToCollectAtEachEvent;
227 }, 227 },
228 228
229 //------------------------------------------------------------------------- 229 //-------------------------------------------------------------------------
230 230
231 'randomBitsCollector': function() { 231 'randomBitsCollector': function() {
232 return this._randomBitsCollector; 232 return this._randomBitsCollector;
233 }, 233 },
234 234
235 'setRandomBitsCollector': function(aValue) { 235 'setRandomBitsCollector': function(aValue) {
236 this._randomBitsCollector = aValue; 236 this._randomBitsCollector = aValue;
237 }, 237 },
238 238
239 'appendRandomBitsToRandomBitsCollector': function(aValue) { 239 'appendRandomBitsToRandomBitsCollector': function(aValue) {
240 var collectedBits; 240 var collectedBits;
241 var numberOfRandomBitsCollected; 241 var numberOfRandomBitsCollected;
242 242
243 numberOfRandomBitsCollected = this.numberOfRandomBitsCollected(); 243 numberOfRandomBitsCollected = this.numberOfRandomBitsCollected();
244 collectedBits = this.randomBitsCollector() | (aValue << numberOfRandomBitsCollected); 244 collectedBits = this.randomBitsCollector() | (aValue << numberOfRandomBitsCollected);
245 this.setRandomBitsCollector(collectedBits); 245 this.setRandomBitsCollector(collectedBits);
246 numberOfRandomBitsCollected += this.numberOfBitsToCollectAtEachEvent(); 246 numberOfRandomBitsCollected += this.numberOfBitsToCollectAtEachEvent();
247 247
248 if (numberOfRandomBitsCollected == 8) { 248 if (numberOfRandomBitsCollected == 8) {
249 this.updateGeneratorWithValue(collectedBits); 249 this.updateGeneratorWithValue(collectedBits);
250 numberOfRandomBitsCollected = 0; 250 numberOfRandomBitsCollected = 0;
251 this.setRandomBitsCollector(0); 251 this.setRandomBitsCollector(0);
252 } 252 }
253 253
254 this.setNumberOfRandomBitsCollected(numberOfRandomBitsCollected) 254 this.setNumberOfRandomBitsCollected(numberOfRandomBitsCollected)
255 }, 255 },
256 256
257 //------------------------------------------------------------------------- 257 //-------------------------------------------------------------------------
258 258
259 'numberOfRandomBitsCollected': function() { 259 'numberOfRandomBitsCollected': function() {
260 return this._numberOfRandomBitsCollected; 260 return this._numberOfRandomBitsCollected;
261 }, 261 },
262 262
263 'setNumberOfRandomBitsCollected': function(aValue) { 263 'setNumberOfRandomBitsCollected': function(aValue) {
264 this._numberOfRandomBitsCollected = aValue; 264 this._numberOfRandomBitsCollected = aValue;
265 }, 265 },
266 266
267 //------------------------------------------------------------------------- 267 //-------------------------------------------------------------------------
268 268
269 'collectEntropy': function(anEvent) { 269 'collectEntropy': function(anEvent) {
270 var mouseLocation; 270 var mouseLocation;
271 var randomBit; 271 var randomBit;
272 var mask; 272 var mask;
273 273
274 mask = 0xffffffff >>> (32 - this.numberOfBitsToCollectAtEachEvent()); 274 mask = 0xffffffff >>> (32 - this.numberOfBitsToCollectAtEachEvent());
275 275
276 mouseLocation = anEvent.mouse().client; 276 mouseLocation = anEvent.mouse().client;
277 randomBit = ((mouseLocation.x ^ mouseLocation.y) & mask); 277 randomBit = ((mouseLocation.x ^ mouseLocation.y) & mask);
278 this.appendRandomBitsToRandomBitsCollector(randomBit) 278 this.appendRandomBitsToRandomBitsCollector(randomBit)
279 }, 279 },
280 280
281 //------------------------------------------------------------------------- 281 //-------------------------------------------------------------------------
282 282
283 'numberOfRandomBits': function() { 283 'numberOfRandomBits': function() {
284 return 1; 284 return 1;
285 }, 285 },
286 286
287 //------------------------------------------------------------------------- 287 //-------------------------------------------------------------------------
288 __syntaxFix__: "syntax fix" 288 __syntaxFix__: "syntax fix"
289}); 289});
290 290
291//***************************************************************************** 291//*****************************************************************************
292 292
293Clipperz.Crypto.PRNG.CryptoRandomRandomnessSource = function(args) { 293Clipperz.Crypto.PRNG.CryptoRandomRandomnessSource = function(args) {
294 args = args || {}; 294 args = args || {};
295 295
296 this._intervalTime = args.intervalTime || 1000; 296 this._intervalTime = args.intervalTime || 1000;
297 this._browserCrypto = args.browserCrypto; 297 this._browserCrypto = args.browserCrypto;
298 298
299 Clipperz.Crypto.PRNG.RandomnessSource.call(this, args); 299 Clipperz.Crypto.PRNG.RandomnessSource.call(this, args);
300 300
301 this.collectEntropy(); 301 this.collectEntropy();
302 return this; 302 return this;
303} 303}
304 304
305Clipperz.Crypto.PRNG.CryptoRandomRandomnessSource.prototype = MochiKit.Base.update(new Clipperz.Crypto.PRNG.RandomnessSource, { 305Clipperz.Crypto.PRNG.CryptoRandomRandomnessSource.prototype = MochiKit.Base.update(new Clipperz.Crypto.PRNG.RandomnessSource, {
306 306
307 'intervalTime': function() { 307 'intervalTime': function() {
308 return this._intervalTime; 308 return this._intervalTime;
309 }, 309 },
310 310
311 'browserCrypto': function () { 311 'browserCrypto': function () {
312 return this._browserCrypto; 312 return this._browserCrypto;
313 }, 313 },
314 314
315 //------------------------------------------------------------------------- 315 //-------------------------------------------------------------------------
316 316
317 'collectEntropy': function() { 317 'collectEntropy': function() {
318 varbytesToCollect; 318 varbytesToCollect;
319 319
320 if (this.boostMode() == true) { 320 if (this.boostMode() == true) {
321 bytesToCollect = 8; 321 bytesToCollect = 64;
322 } else { 322 } else {
323 bytesToCollect = 32; 323 bytesToCollect = 8;
324 } 324 }
325 325
326 var randomValuesArray = new Uint8Array(bytesToCollect); 326 var randomValuesArray = new Uint8Array(bytesToCollect);
327 this.browserCrypto().getRandomValues(randomValuesArray); 327 this.browserCrypto().getRandomValues(randomValuesArray);
328 for (var i = 0; i < randomValuesArray.length; i++) { 328 for (var i = 0; i < randomValuesArray.length; i++) {
329 this.updateGeneratorWithValue(randomValuesArray[i]); 329 this.updateGeneratorWithValue(randomValuesArray[i]);
330 } 330 }
331 331
332 setTimeout(this.collectEntropy, this.intervalTime()); 332 setTimeout(this.collectEntropy, this.intervalTime());
333 }, 333 },
334 334
335 //------------------------------------------------------------------------- 335 //-------------------------------------------------------------------------
336 __syntaxFix__: "syntax fix" 336 __syntaxFix__: "syntax fix"
337}); 337});
338 338
339//############################################################################# 339//#############################################################################
340 340
341Clipperz.Crypto.PRNG.Fortuna = function(args) { 341Clipperz.Crypto.PRNG.Fortuna = function(args) {
342 vari,c; 342 vari,c;
343 343
344 args = args || {}; 344 args = args || {};
345 345
346 this._key = args.seed || null; 346 this._key = args.seed || null;
347 if (this._key == null) { 347 if (this._key == null) {
348 this._counter = 0; 348 this._counter = 0;
349 this._key = new Clipperz.ByteArray(); 349 this._key = new Clipperz.ByteArray();
350 } else { 350 } else {
351 this._counter = 1; 351 this._counter = 1;
352 } 352 }
353 353
354 this._aesKey = null; 354 this._aesKey = null;
355 355
356 this._firstPoolReseedLevel = args.firstPoolReseedLevel || 32 || 64; 356 this._firstPoolReseedLevel = args.firstPoolReseedLevel || 32 || 64;
357 this._numberOfEntropyAccumulators = args.numberOfEntropyAccumulators || 32; 357 this._numberOfEntropyAccumulators = args.numberOfEntropyAccumulators || 32;
358 358
359 this._accumulators = []; 359 this._accumulators = [];
360 c = this.numberOfEntropyAccumulators(); 360 c = this.numberOfEntropyAccumulators();
361 for (i=0; i<c; i++) { 361 for (i=0; i<c; i++) {
362 this._accumulators.push(new Clipperz.Crypto.PRNG.EntropyAccumulator()); 362 this._accumulators.push(new Clipperz.Crypto.PRNG.EntropyAccumulator());
363 } 363 }
364 364
365 this._randomnessSources = []; 365 this._randomnessSources = [];
366 this._reseedCounter = 0; 366 this._reseedCounter = 0;
367 367
368 return this; 368 return this;
369} 369}
370 370
371Clipperz.Crypto.PRNG.Fortuna.prototype = MochiKit.Base.update(null, { 371Clipperz.Crypto.PRNG.Fortuna.prototype = MochiKit.Base.update(null, {
372 372
373 'toString': function() { 373 'toString': function() {
374 return "Clipperz.Crypto.PRNG.Fortuna"; 374 return "Clipperz.Crypto.PRNG.Fortuna";
375 }, 375 },
376 376
377 //------------------------------------------------------------------------- 377 //-------------------------------------------------------------------------
378 378
379 'key': function() { 379 'key': function() {
380 return this._key; 380 return this._key;
381 }, 381 },
382 382
383 'setKey': function(aValue) { 383 'setKey': function(aValue) {
384 this._key = aValue; 384 this._key = aValue;
385 this._aesKey = null; 385 this._aesKey = null;
386 }, 386 },
387 387
388 'aesKey': function() { 388 'aesKey': function() {
389 if (this._aesKey == null) { 389 if (this._aesKey == null) {
390 this._aesKey = new Clipperz.Crypto.AES.Key({key:this.key()}); 390 this._aesKey = new Clipperz.Crypto.AES.Key({key:this.key()});
391 } 391 }
392 392
393 return this._aesKey; 393 return this._aesKey;
394 }, 394 },
395 395
396 'accumulators': function() { 396 'accumulators': function() {
397 return this._accumulators; 397 return this._accumulators;
398 }, 398 },
399 399
400 'firstPoolReseedLevel': function() { 400 'firstPoolReseedLevel': function() {
401 return this._firstPoolReseedLevel; 401 return this._firstPoolReseedLevel;
402 }, 402 },
403 403
404 //------------------------------------------------------------------------- 404 //-------------------------------------------------------------------------
405 405
406 'reseedCounter': function() { 406 'reseedCounter': function() {
407 return this._reseedCounter; 407 return this._reseedCounter;
408 }, 408 },
409 409
410 'incrementReseedCounter': function() { 410 'incrementReseedCounter': function() {
411 this._reseedCounter = this._reseedCounter +1; 411 this._reseedCounter = this._reseedCounter +1;
412 }, 412 },
413 413
414 //------------------------------------------------------------------------- 414 //-------------------------------------------------------------------------
415 415
416 'reseed': function() { 416 'reseed': function() {
417 varnewKeySeed; 417 varnewKeySeed;
418 var reseedCounter; 418 var reseedCounter;
419 varreseedCounterMask; 419 varreseedCounterMask;