summaryrefslogtreecommitdiff
path: root/frontend/beta/js/Clipperz/Crypto/PRNG.js
Unidiff
Diffstat (limited to 'frontend/beta/js/Clipperz/Crypto/PRNG.js') (more/less context) (ignore whitespace changes)
-rw-r--r--frontend/beta/js/Clipperz/Crypto/PRNG.js22
1 files changed, 10 insertions, 12 deletions
diff --git a/frontend/beta/js/Clipperz/Crypto/PRNG.js b/frontend/beta/js/Clipperz/Crypto/PRNG.js
index 39d0045..b5c3f8a 100644
--- a/frontend/beta/js/Clipperz/Crypto/PRNG.js
+++ b/frontend/beta/js/Clipperz/Crypto/PRNG.js
@@ -1,214 +1,212 @@
1/* 1/*
2 2
3Copyright 2008-2011 Clipperz Srl 3Copyright 2008-2013 Clipperz Srl
4 4
5This file is part of Clipperz Community Edition. 5This file is part of Clipperz, the online password manager.
6Clipperz Community Edition is an online password manager.
7For further information about its features and functionalities please 6For further information about its features and functionalities please
8refer to http://www.clipperz.com. 7refer to http://www.clipperz.com.
9 8
10* Clipperz Community Edition is free software: you can redistribute 9* Clipperz is free software: you can redistribute it and/or modify it
11 it and/or modify it under the terms of the GNU Affero General Public 10 under the terms of the GNU Affero General Public License as published
12 License as published by the Free Software Foundation, either version 11 by the Free Software Foundation, either version 3 of the License, or
13 3 of the License, or (at your option) any later version. 12 (at your option) any later version.
14 13
15* Clipperz Community Edition is distributed in the hope that it will 14* Clipperz is distributed in the hope that it will be useful, but
16 be useful, but WITHOUT ANY WARRANTY; without even the implied 15 WITHOUT ANY WARRANTY; without even the implied warranty of
17 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 See the GNU Affero General Public License for more details. 17 See the GNU Affero General Public License for more details.
19 18
20* You should have received a copy of the GNU Affero General Public 19* You should have received a copy of the GNU Affero General Public
21 License along with Clipperz Community Edition. If not, see 20 License along with Clipperz. If not, see http://www.gnu.org/licenses/.
22 <http://www.gnu.org/licenses/>.
23 21
24*/ 22*/
25 23
26try { if (typeof(Clipperz.ByteArray) == 'undefined') { throw ""; }} catch (e) { 24try { if (typeof(Clipperz.ByteArray) == 'undefined') { throw ""; }} catch (e) {
27 throw "Clipperz.Crypto.PRNG depends on Clipperz.ByteArray!"; 25 throw "Clipperz.Crypto.PRNG depends on Clipperz.ByteArray!";
28} 26}
29 27
30try { if (typeof(Clipperz.Crypto.SHA) == 'undefined') { throw ""; }} catch (e) { 28try { if (typeof(Clipperz.Crypto.SHA) == 'undefined') { throw ""; }} catch (e) {
31 throw "Clipperz.Crypto.PRNG depends on Clipperz.Crypto.SHA!"; 29 throw "Clipperz.Crypto.PRNG depends on Clipperz.Crypto.SHA!";
32} 30}
33 31
34try { if (typeof(Clipperz.Crypto.AES) == 'undefined') { throw ""; }} catch (e) { 32try { if (typeof(Clipperz.Crypto.AES) == 'undefined') { throw ""; }} catch (e) {
35 throw "Clipperz.Crypto.PRNG depends on Clipperz.Crypto.AES!"; 33 throw "Clipperz.Crypto.PRNG depends on Clipperz.Crypto.AES!";
36} 34}
37 35
38if (typeof(Clipperz.Crypto.PRNG) == 'undefined') { Clipperz.Crypto.PRNG = {}; } 36if (typeof(Clipperz.Crypto.PRNG) == 'undefined') { Clipperz.Crypto.PRNG = {}; }
39 37
40//############################################################################# 38//#############################################################################
41 39
42Clipperz.Crypto.PRNG.EntropyAccumulator = function(args) { 40Clipperz.Crypto.PRNG.EntropyAccumulator = function(args) {
43 args = args || {}; 41 args = args || {};
44 //MochiKit.Base.bindMethods(this); 42 //MochiKit.Base.bindMethods(this);
45 43
46 this._stack = new Clipperz.ByteArray(); 44 this._stack = new Clipperz.ByteArray();
47 this._maxStackLengthBeforeHashing = args.maxStackLengthBeforeHashing || 256; 45 this._maxStackLengthBeforeHashing = args.maxStackLengthBeforeHashing || 256;
48 return this; 46 return this;
49} 47}
50 48
51Clipperz.Crypto.PRNG.EntropyAccumulator.prototype = MochiKit.Base.update(null, { 49Clipperz.Crypto.PRNG.EntropyAccumulator.prototype = MochiKit.Base.update(null, {
52 50
53 'toString': function() { 51 'toString': function() {
54 return "Clipperz.Crypto.PRNG.EntropyAccumulator"; 52 return "Clipperz.Crypto.PRNG.EntropyAccumulator";
55 }, 53 },
56 54
57 //------------------------------------------------------------------------- 55 //-------------------------------------------------------------------------
58 56
59 'stack': function() { 57 'stack': function() {
60 return this._stack; 58 return this._stack;
61 }, 59 },
62 60
63 'setStack': function(aValue) { 61 'setStack': function(aValue) {
64 this._stack = aValue; 62 this._stack = aValue;
65 }, 63 },
66 64
67 'resetStack': function() { 65 'resetStack': function() {
68 this.stack().reset(); 66 this.stack().reset();
69 }, 67 },
70 68
71 'maxStackLengthBeforeHashing': function() { 69 'maxStackLengthBeforeHashing': function() {
72 return this._maxStackLengthBeforeHashing; 70 return this._maxStackLengthBeforeHashing;
73 }, 71 },
74 72
75 //------------------------------------------------------------------------- 73 //-------------------------------------------------------------------------
76 74
77 'addRandomByte': function(aValue) { 75 'addRandomByte': function(aValue) {
78 this.stack().appendByte(aValue); 76 this.stack().appendByte(aValue);
79 77
80 if (this.stack().length() > this.maxStackLengthBeforeHashing()) { 78 if (this.stack().length() > this.maxStackLengthBeforeHashing()) {
81 this.setStack(Clipperz.Crypto.SHA.sha_d256(this.stack())); 79 this.setStack(Clipperz.Crypto.SHA.sha_d256(this.stack()));
82 } 80 }
83 }, 81 },
84 82
85 //------------------------------------------------------------------------- 83 //-------------------------------------------------------------------------
86 __syntaxFix__: "syntax fix" 84 __syntaxFix__: "syntax fix"
87}); 85});
88 86
89//############################################################################# 87//#############################################################################
90 88
91Clipperz.Crypto.PRNG.RandomnessSource = function(args) { 89Clipperz.Crypto.PRNG.RandomnessSource = function(args) {
92 args = args || {}; 90 args = args || {};
93 MochiKit.Base.bindMethods(this); 91 MochiKit.Base.bindMethods(this);
94 92
95 this._generator = args.generator || null; 93 this._generator = args.generator || null;
96 this._sourceId = args.sourceId || null; 94 this._sourceId = args.sourceId || null;
97 this._boostMode = args.boostMode || false; 95 this._boostMode = args.boostMode || false;
98 96
99 this._nextPoolIndex = 0; 97 this._nextPoolIndex = 0;
100 98
101 return this; 99 return this;
102} 100}
103 101
104Clipperz.Crypto.PRNG.RandomnessSource.prototype = MochiKit.Base.update(null, { 102Clipperz.Crypto.PRNG.RandomnessSource.prototype = MochiKit.Base.update(null, {
105 103
106 'generator': function() { 104 'generator': function() {
107 return this._generator; 105 return this._generator;
108 }, 106 },
109 107
110 'setGenerator': function(aValue) { 108 'setGenerator': function(aValue) {
111 this._generator = aValue; 109 this._generator = aValue;
112 }, 110 },
113 111
114 //------------------------------------------------------------------------- 112 //-------------------------------------------------------------------------
115 113
116 'boostMode': function() { 114 'boostMode': function() {
117 return this._boostMode; 115 return this._boostMode;
118 }, 116 },
119 117
120 'setBoostMode': function(aValue) { 118 'setBoostMode': function(aValue) {
121 this._boostMode = aValue; 119 this._boostMode = aValue;
122 }, 120 },
123 121
124 //------------------------------------------------------------------------- 122 //-------------------------------------------------------------------------
125 123
126 'sourceId': function() { 124 'sourceId': function() {
127 return this._sourceId; 125 return this._sourceId;
128 }, 126 },
129 127
130 'setSourceId': function(aValue) { 128 'setSourceId': function(aValue) {
131 this._sourceId = aValue; 129 this._sourceId = aValue;
132 }, 130 },
133 131
134 //------------------------------------------------------------------------- 132 //-------------------------------------------------------------------------
135 133
136 'nextPoolIndex': function() { 134 'nextPoolIndex': function() {
137 return this._nextPoolIndex; 135 return this._nextPoolIndex;
138 }, 136 },
139 137
140 'incrementNextPoolIndex': function() { 138 'incrementNextPoolIndex': function() {
141 this._nextPoolIndex = ((this._nextPoolIndex + 1) % this.generator().numberOfEntropyAccumulators()); 139 this._nextPoolIndex = ((this._nextPoolIndex + 1) % this.generator().numberOfEntropyAccumulators());
142 }, 140 },
143 141
144 //------------------------------------------------------------------------- 142 //-------------------------------------------------------------------------
145 143
146 'updateGeneratorWithValue': function(aRandomValue) { 144 'updateGeneratorWithValue': function(aRandomValue) {
147 if (this.generator() != null) { 145 if (this.generator() != null) {
148 this.generator().addRandomByte(this.sourceId(), this.nextPoolIndex(), aRandomValue); 146 this.generator().addRandomByte(this.sourceId(), this.nextPoolIndex(), aRandomValue);
149 this.incrementNextPoolIndex(); 147 this.incrementNextPoolIndex();
150 } 148 }
151 }, 149 },
152 150
153 //------------------------------------------------------------------------- 151 //-------------------------------------------------------------------------
154 __syntaxFix__: "syntax fix" 152 __syntaxFix__: "syntax fix"
155}); 153});
156 154
157//############################################################################# 155//#############################################################################
158 156
159Clipperz.Crypto.PRNG.TimeRandomnessSource = function(args) { 157Clipperz.Crypto.PRNG.TimeRandomnessSource = function(args) {
160 args = args || {}; 158 args = args || {};
161 //MochiKit.Base.bindMethods(this); 159 //MochiKit.Base.bindMethods(this);
162 160
163 this._intervalTime = args.intervalTime || 1000; 161 this._intervalTime = args.intervalTime || 1000;
164 162
165 Clipperz.Crypto.PRNG.RandomnessSource.call(this, args); 163 Clipperz.Crypto.PRNG.RandomnessSource.call(this, args);
166 164
167 this.collectEntropy(); 165 this.collectEntropy();
168 return this; 166 return this;
169} 167}
170 168
171Clipperz.Crypto.PRNG.TimeRandomnessSource.prototype = MochiKit.Base.update(new Clipperz.Crypto.PRNG.RandomnessSource, { 169Clipperz.Crypto.PRNG.TimeRandomnessSource.prototype = MochiKit.Base.update(new Clipperz.Crypto.PRNG.RandomnessSource, {
172 170
173 'intervalTime': function() { 171 'intervalTime': function() {
174 return this._intervalTime; 172 return this._intervalTime;
175 }, 173 },
176 174
177 //------------------------------------------------------------------------- 175 //-------------------------------------------------------------------------
178 176
179 'collectEntropy': function() { 177 'collectEntropy': function() {
180 varnow; 178 varnow;
181 varentropyByte; 179 varentropyByte;
182 var intervalTime; 180 var intervalTime;
183 now = new Date(); 181 now = new Date();
184 entropyByte = (now.getTime() & 0xff); 182 entropyByte = (now.getTime() & 0xff);
185 183
186 intervalTime = this.intervalTime(); 184 intervalTime = this.intervalTime();
187 if (this.boostMode() == true) { 185 if (this.boostMode() == true) {
188 intervalTime = intervalTime / 9; 186 intervalTime = intervalTime / 9;
189 } 187 }
190 188
191 this.updateGeneratorWithValue(entropyByte); 189 this.updateGeneratorWithValue(entropyByte);
192 setTimeout(this.collectEntropy, intervalTime); 190 setTimeout(this.collectEntropy, intervalTime);
193 }, 191 },
194 192
195 //------------------------------------------------------------------------- 193 //-------------------------------------------------------------------------
196 194
197 'numberOfRandomBits': function() { 195 'numberOfRandomBits': function() {
198 return 5; 196 return 5;
199 }, 197 },
200 198
201 //------------------------------------------------------------------------- 199 //-------------------------------------------------------------------------
202 200
203 'pollingFrequency': function() { 201 'pollingFrequency': function() {
204 return 10; 202 return 10;
205 }, 203 },
206 204
207 //------------------------------------------------------------------------- 205 //-------------------------------------------------------------------------
208 __syntaxFix__: "syntax fix" 206 __syntaxFix__: "syntax fix"
209}); 207});
210 208
211//***************************************************************************** 209//*****************************************************************************
212 210
213Clipperz.Crypto.PRNG.MouseRandomnessSource = function(args) { 211Clipperz.Crypto.PRNG.MouseRandomnessSource = function(args) {
214 args = args || {}; 212 args = args || {};