Diffstat (limited to 'frontend/gamma/js/Clipperz/Crypto/AES.js') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/gamma/js/Clipperz/Crypto/AES.js | 29 |
1 files changed, 11 insertions, 18 deletions
diff --git a/frontend/gamma/js/Clipperz/Crypto/AES.js b/frontend/gamma/js/Clipperz/Crypto/AES.js index c811f1c..cb56f11 100644 --- a/frontend/gamma/js/Clipperz/Crypto/AES.js +++ b/frontend/gamma/js/Clipperz/Crypto/AES.js | |||
@@ -1,243 +1,240 @@ | |||
1 | /* | 1 | /* |
2 | 2 | ||
3 | Copyright 2008-2011 Clipperz Srl | 3 | Copyright 2008-2013 Clipperz Srl |
4 | 4 | ||
5 | This file is part of Clipperz Community Edition. | 5 | This file is part of Clipperz, the online password manager. |
6 | Clipperz Community Edition is an online password manager. | ||
7 | For further information about its features and functionalities please | 6 | For further information about its features and functionalities please |
8 | refer to http://www.clipperz.com. | 7 | refer 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 | ||
26 | try { if (typeof(Clipperz.ByteArray) == 'undefined') { throw ""; }} catch (e) { | 24 | try { if (typeof(Clipperz.ByteArray) == 'undefined') { throw ""; }} catch (e) { |
27 | throw "Clipperz.Crypto.AES depends on Clipperz.ByteArray!"; | 25 | throw "Clipperz.Crypto.AES depends on Clipperz.ByteArray!"; |
28 | } | 26 | } |
29 | 27 | ||
30 | //Dependency commented to avoid a circular reference | 28 | //Dependency commented to avoid a circular reference |
31 | //try { if (typeof(Clipperz.Crypto.PRNG) == 'undefined') { throw ""; }} catch (e) { | 29 | //try { if (typeof(Clipperz.Crypto.PRNG) == 'undefined') { throw ""; }} catch (e) { |
32 | //throw "Clipperz.Crypto.AES depends on Clipperz.Crypto.PRNG!"; | 30 | //throw "Clipperz.Crypto.AES depends on Clipperz.Crypto.PRNG!"; |
33 | //} | 31 | //} |
34 | 32 | ||
35 | if (typeof(Clipperz.Crypto.AES) == 'undefined') { Clipperz.Crypto.AES = {}; } | 33 | if (typeof(Clipperz.Crypto.AES) == 'undefined') { Clipperz.Crypto.AES = {}; } |
36 | 34 | ||
37 | //############################################################################# | 35 | //############################################################################# |
38 | 36 | ||
39 | Clipperz.Crypto.AES.DeferredExecutionContext = function(args) { | 37 | Clipperz.Crypto.AES.DeferredExecutionContext = function(args) { |
40 | args = args || {}; | 38 | args = args || {}; |
41 | 39 | ||
42 | this._key = args.key; | 40 | this._key = args.key; |
43 | this._message = args.message; | 41 | this._message = args.message; |
44 | this._result = args.message.clone(); | 42 | this._result = args.message.clone(); |
45 | this._nonce = args.nonce; | 43 | this._nonce = args.nonce; |
46 | this._messageLength = this._message.length(); | 44 | this._messageLength = this._message.length(); |
47 | 45 | ||
48 | this._messageArray = this._message.arrayValues(); | 46 | this._messageArray = this._message.arrayValues(); |
49 | this._resultArray = this._result.arrayValues(); | 47 | this._resultArray = this._result.arrayValues(); |
50 | this._nonceArray = this._nonce.arrayValues(); | 48 | this._nonceArray = this._nonce.arrayValues(); |
51 | 49 | ||
52 | this._executionStep = 0; | 50 | this._executionStep = 0; |
53 | 51 | ||
54 | // this._elaborationChunkSize = 1024; // 4096; // 16384; //4096; | 52 | // this._elaborationChunkSize = 1024; // 4096; // 16384; //4096; |
55 | this._elaborationChunks = 10; | 53 | this._elaborationChunks = 10; |
56 | this._pauseTime = 0.02; // 0.02 //0.2; | 54 | this._pauseTime = 0.02; // 0.02 //0.2; |
57 | 55 | ||
58 | return this; | 56 | return this; |
59 | } | 57 | } |
60 | 58 | ||
61 | Clipperz.Crypto.AES.DeferredExecutionContext.prototype = MochiKit.Base.update(null, { | 59 | Clipperz.Crypto.AES.DeferredExecutionContext.prototype = MochiKit.Base.update(null, { |
62 | 60 | ||
63 | 'key': function() { | 61 | 'key': function() { |
64 | return this._key; | 62 | return this._key; |
65 | }, | 63 | }, |
66 | 64 | ||
67 | 'message': function() { | 65 | 'message': function() { |
68 | return this._message; | 66 | return this._message; |
69 | }, | 67 | }, |
70 | 68 | ||
71 | 'messageLength': function() { | 69 | 'messageLength': function() { |
72 | return this._messageLength; | 70 | return this._messageLength; |
73 | }, | 71 | }, |
74 | 72 | ||
75 | 'result': function() { | 73 | 'result': function() { |
76 | return new Clipperz.ByteArray(this.resultArray()); | 74 | return new Clipperz.ByteArray(this.resultArray()); |
77 | }, | 75 | }, |
78 | 76 | ||
79 | 'nonce': function() { | 77 | 'nonce': function() { |
80 | return this._nonce; | 78 | return this._nonce; |
81 | }, | 79 | }, |
82 | 80 | ||
83 | 'messageArray': function() { | 81 | 'messageArray': function() { |
84 | return this._messageArray; | 82 | return this._messageArray; |
85 | }, | 83 | }, |
86 | 84 | ||
87 | 'resultArray': function() { | 85 | 'resultArray': function() { |
88 | return this._resultArray; | 86 | return this._resultArray; |
89 | }, | 87 | }, |
90 | 88 | ||
91 | 'nonceArray': function() { | 89 | 'nonceArray': function() { |
92 | return this._nonceArray; | 90 | return this._nonceArray; |
93 | }, | 91 | }, |
94 | 92 | ||
95 | 'elaborationChunkSize': function() { | 93 | 'elaborationChunkSize': function() { |
96 | // return Clipperz.Crypto.AES.DeferredExecution.chunkSize; | 94 | // return Clipperz.Crypto.AES.DeferredExecution.chunkSize; |
97 | // return this._elaborationChunkSize; | 95 | // return this._elaborationChunkSize; |
98 | return (this._elaborationChunks * 1024); | 96 | return (this._elaborationChunks * 1024); |
99 | }, | 97 | }, |
100 | 98 | ||
101 | 'executionStep': function() { | 99 | 'executionStep': function() { |
102 | return this._executionStep; | 100 | return this._executionStep; |
103 | }, | 101 | }, |
104 | 102 | ||
105 | 'setExecutionStep': function(aValue) { | 103 | 'setExecutionStep': function(aValue) { |
106 | this._executionStep = aValue; | 104 | this._executionStep = aValue; |
107 | }, | 105 | }, |
108 | 106 | ||
109 | 'tuneExecutionParameters': function (anElapsedTime) { | 107 | 'tuneExecutionParameters': function (anElapsedTime) { |
110 | //var originalChunks = this._elaborationChunks; | 108 | //var originalChunks = this._elaborationChunks; |
111 | if (anElapsedTime > 0) { | 109 | if (anElapsedTime > 0) { |
112 | this._elaborationChunks = Math.round(this._elaborationChunks * ((anElapsedTime + 1000)/(anElapsedTime * 2))); | 110 | this._elaborationChunks = Math.round(this._elaborationChunks * ((anElapsedTime + 1000)/(anElapsedTime * 2))); |
113 | } | 111 | } |
114 | //Clipperz.log("tuneExecutionParameters - elapsedTime: " + anElapsedTime + /*originalChunks,*/ " chunks # " + this._elaborationChunks + " [" + this._executionStep + " / " + this._messageLength + "]"); | 112 | //Clipperz.log("tuneExecutionParameters - elapsedTime: " + anElapsedTime + /*originalChunks,*/ " chunks # " + this._elaborationChunks + " [" + this._executionStep + " / " + this._messageLength + "]"); |
115 | }, | 113 | }, |
116 | 114 | ||
117 | 'pause': function(aValue) { | 115 | 'pause': function(aValue) { |
118 | // return MochiKit.Async.wait(Clipperz.Crypto.AES.DeferredExecution.pauseTime, aValue); | 116 | // return MochiKit.Async.wait(Clipperz.Crypto.AES.DeferredExecution.pauseTime, aValue); |
119 | return MochiKit.Async.wait(this._pauseTime, aValue); | 117 | return MochiKit.Async.wait(this._pauseTime, aValue); |
120 | }, | 118 | }, |
121 | 119 | ||
122 | 'isDone': function () { | 120 | 'isDone': function () { |
123 | //console.log("isDone", this.executionStep(), this.messageLength()); | ||
124 | return (this._executionStep >= this._messageLength); | 121 | return (this._executionStep >= this._messageLength); |
125 | }, | 122 | }, |
126 | 123 | ||
127 | //----------------------------------------------------------------------------- | 124 | //----------------------------------------------------------------------------- |
128 | __syntaxFix__: "syntax fix" | 125 | __syntaxFix__: "syntax fix" |
129 | 126 | ||
130 | }); | 127 | }); |
131 | 128 | ||
132 | //############################################################################# | 129 | //############################################################################# |
133 | 130 | ||
134 | Clipperz.Crypto.AES.Key = function(args) { | 131 | Clipperz.Crypto.AES.Key = function(args) { |
135 | args = args || {}; | 132 | args = args || {}; |
136 | 133 | ||
137 | this._key = args.key; | 134 | this._key = args.key; |
138 | this._keySize = args.keySize || this.key().length(); | 135 | this._keySize = args.keySize || this.key().length(); |
139 | 136 | ||
140 | if (this.keySize() == 128/8) { | 137 | if (this.keySize() == 128/8) { |
141 | this._b = 176; | 138 | this._b = 176; |
142 | this._numberOfRounds = 10; | 139 | this._numberOfRounds = 10; |
143 | } else if (this.keySize() == 256/8) { | 140 | } else if (this.keySize() == 256/8) { |
144 | this._b = 240; | 141 | this._b = 240; |
145 | this._numberOfRounds = 14; | 142 | this._numberOfRounds = 14; |
146 | } else { | 143 | } else { |
147 | MochiKit.Logging.logError("AES unsupported key size: " + (this.keySize() * 8) + " bits"); | 144 | Clipperz.logError("AES unsupported key size: " + (this.keySize() * 8) + " bits"); |
148 | throw Clipperz.Crypto.AES.exception.UnsupportedKeySize; | 145 | throw Clipperz.Crypto.AES.exception.UnsupportedKeySize; |
149 | } | 146 | } |
150 | 147 | ||
151 | this._stretchedKey = null; | 148 | this._stretchedKey = null; |
152 | 149 | ||
153 | return this; | 150 | return this; |
154 | } | 151 | } |
155 | 152 | ||
156 | Clipperz.Crypto.AES.Key.prototype = MochiKit.Base.update(null, { | 153 | Clipperz.Crypto.AES.Key.prototype = MochiKit.Base.update(null, { |
157 | 154 | ||
158 | 'asString': function() { | 155 | 'asString': function() { |
159 | return "Clipperz.Crypto.AES.Key (" + this.key().toHexString() + ")"; | 156 | return "Clipperz.Crypto.AES.Key (" + this.key().toHexString() + ")"; |
160 | }, | 157 | }, |
161 | 158 | ||
162 | //----------------------------------------------------------------------------- | 159 | //----------------------------------------------------------------------------- |
163 | 160 | ||
164 | 'key': function() { | 161 | 'key': function() { |
165 | return this._key; | 162 | return this._key; |
166 | }, | 163 | }, |
167 | 164 | ||
168 | 'keySize': function() { | 165 | 'keySize': function() { |
169 | return this._keySize; | 166 | return this._keySize; |
170 | }, | 167 | }, |
171 | 168 | ||
172 | 'b': function() { | 169 | 'b': function() { |
173 | return this._b; | 170 | return this._b; |
174 | }, | 171 | }, |
175 | 172 | ||
176 | 'numberOfRounds': function() { | 173 | 'numberOfRounds': function() { |
177 | return this._numberOfRounds; | 174 | return this._numberOfRounds; |
178 | }, | 175 | }, |
179 | //========================================================================= | 176 | //========================================================================= |
180 | 177 | ||
181 | 'keyScheduleCore': function(aWord, aRoundConstantsIndex) { | 178 | 'keyScheduleCore': function(aWord, aRoundConstantsIndex) { |
182 | varresult; | 179 | varresult; |
183 | var sbox; | 180 | var sbox; |
184 | 181 | ||
185 | sbox = Clipperz.Crypto.AES.sbox(); | 182 | sbox = Clipperz.Crypto.AES.sbox(); |
186 | 183 | ||
187 | result = [sbox[aWord[1]] ^ Clipperz.Crypto.AES.roundConstants()[aRoundConstantsIndex], | 184 | result = [sbox[aWord[1]] ^ Clipperz.Crypto.AES.roundConstants()[aRoundConstantsIndex], |
188 | sbox[aWord[2]], | 185 | sbox[aWord[2]], |
189 | sbox[aWord[3]], | 186 | sbox[aWord[3]], |
190 | sbox[aWord[0]]]; | 187 | sbox[aWord[0]]]; |
191 | 188 | ||
192 | return result; | 189 | return result; |
193 | }, | 190 | }, |
194 | 191 | ||
195 | //----------------------------------------------------------------------------- | 192 | //----------------------------------------------------------------------------- |
196 | 193 | ||
197 | 'xorWithPreviousStretchValues': function(aKey, aWord, aPreviousWordIndex) { | 194 | 'xorWithPreviousStretchValues': function(aKey, aWord, aPreviousWordIndex) { |
198 | varresult; | 195 | varresult; |
199 | var i,c; | 196 | var i,c; |
200 | 197 | ||
201 | result = []; | 198 | result = []; |
202 | c = 4; | 199 | c = 4; |
203 | for (i=0; i<c; i++) { | 200 | for (i=0; i<c; i++) { |
204 | result[i] = aWord[i] ^ aKey.byteAtIndex(aPreviousWordIndex + i); | 201 | result[i] = aWord[i] ^ aKey.byteAtIndex(aPreviousWordIndex + i); |
205 | } | 202 | } |
206 | 203 | ||
207 | return result; | 204 | return result; |
208 | }, | 205 | }, |
209 | 206 | ||
210 | //----------------------------------------------------------------------------- | 207 | //----------------------------------------------------------------------------- |
211 | 208 | ||
212 | 'sboxShakeup': function(aWord) { | 209 | 'sboxShakeup': function(aWord) { |
213 | var result; | 210 | var result; |
214 | var sbox; | 211 | var sbox; |
215 | var i,c; | 212 | var i,c; |
216 | 213 | ||
217 | result = []; | 214 | result = []; |
218 | sbox = Clipperz.Crypto.AES.sbox(); | 215 | sbox = Clipperz.Crypto.AES.sbox(); |
219 | c =4; | 216 | c =4; |
220 | for (i=0; i<c; i++) { | 217 | for (i=0; i<c; i++) { |
221 | result[i] = sbox[aWord[i]]; | 218 | result[i] = sbox[aWord[i]]; |
222 | } | 219 | } |
223 | 220 | ||
224 | return result; | 221 | return result; |
225 | }, | 222 | }, |
226 | 223 | ||
227 | //----------------------------------------------------------------------------- | 224 | //----------------------------------------------------------------------------- |
228 | 225 | ||
229 | 'stretchKey': function(aKey) { | 226 | 'stretchKey': function(aKey) { |
230 | varcurrentWord; | 227 | varcurrentWord; |
231 | varkeyLength; | 228 | varkeyLength; |
232 | varpreviousStretchIndex; | 229 | varpreviousStretchIndex; |
233 | var i,c; | 230 | var i,c; |
234 | 231 | ||
235 | keyLength = aKey.length(); | 232 | keyLength = aKey.length(); |
236 | previousStretchIndex = keyLength - this.keySize(); | 233 | previousStretchIndex = keyLength - this.keySize(); |
237 | 234 | ||
238 | currentWord = [aKey.byteAtIndex(keyLength - 4), | 235 | currentWord = [aKey.byteAtIndex(keyLength - 4), |
239 | aKey.byteAtIndex(keyLength - 3), | 236 | aKey.byteAtIndex(keyLength - 3), |
240 | aKey.byteAtIndex(keyLength - 2), | 237 | aKey.byteAtIndex(keyLength - 2), |
241 | aKey.byteAtIndex(keyLength - 1)]; | 238 | aKey.byteAtIndex(keyLength - 1)]; |
242 | currentWord = this.keyScheduleCore(currentWord, keyLength / this.keySize()); | 239 | currentWord = this.keyScheduleCore(currentWord, keyLength / this.keySize()); |
243 | 240 | ||
@@ -715,152 +712,148 @@ MochiKit.Base.update(Clipperz.Crypto.AES, { | |||
715 | varmessageLength; | 712 | varmessageLength; |
716 | var blockSize; | 713 | var blockSize; |
717 | var executionLimit; | 714 | var executionLimit; |
718 | var startTime, endTime; | 715 | var startTime, endTime; |
719 | 716 | ||
720 | self = Clipperz.Crypto.AES; | 717 | self = Clipperz.Crypto.AES; |
721 | startTime = new Date(); | 718 | startTime = new Date(); |
722 | blockSize = 128/8; | 719 | blockSize = 128/8; |
723 | messageLength = anExecutionContext.messageArray().length; | 720 | messageLength = anExecutionContext.messageArray().length; |
724 | nonce = anExecutionContext.nonceArray(); | 721 | nonce = anExecutionContext.nonceArray(); |
725 | result = anExecutionContext.resultArray(); | 722 | result = anExecutionContext.resultArray(); |
726 | 723 | ||
727 | messageIndex = anExecutionContext.executionStep(); | 724 | messageIndex = anExecutionContext.executionStep(); |
728 | executionLimit = messageIndex + anExecutionContext.elaborationChunkSize(); | 725 | executionLimit = messageIndex + anExecutionContext.elaborationChunkSize(); |
729 | executionLimit = Math.min(executionLimit, messageLength); | 726 | executionLimit = Math.min(executionLimit, messageLength); |
730 | 727 | ||
731 | while (messageIndex < executionLimit) { | 728 | while (messageIndex < executionLimit) { |
732 | var encryptedBlock; | 729 | var encryptedBlock; |
733 | var i,c; | 730 | var i,c; |
734 | 731 | ||
735 | self.incrementNonce(nonce); | 732 | self.incrementNonce(nonce); |
736 | encryptedBlock = self.encryptBlock(anExecutionContext.key(), nonce); | 733 | encryptedBlock = self.encryptBlock(anExecutionContext.key(), nonce); |
737 | 734 | ||
738 | if ((executionLimit - messageIndex) > blockSize) { | 735 | if ((executionLimit - messageIndex) > blockSize) { |
739 | c = blockSize; | 736 | c = blockSize; |
740 | } else { | 737 | } else { |
741 | c = executionLimit - messageIndex; | 738 | c = executionLimit - messageIndex; |
742 | } | 739 | } |
743 | 740 | ||
744 | for (i=0; i<c; i++) { | 741 | for (i=0; i<c; i++) { |
745 | result[messageIndex + i] = result[messageIndex + i] ^ encryptedBlock[i]; | 742 | result[messageIndex + i] = result[messageIndex + i] ^ encryptedBlock[i]; |
746 | } | 743 | } |
747 | 744 | ||
748 | messageIndex += blockSize; | 745 | messageIndex += blockSize; |
749 | } | 746 | } |
750 | anExecutionContext.setExecutionStep(messageIndex); | 747 | anExecutionContext.setExecutionStep(messageIndex); |
751 | endTime = new Date(); | 748 | endTime = new Date(); |
752 | anExecutionContext.tuneExecutionParameters(endTime - startTime); | 749 | anExecutionContext.tuneExecutionParameters(endTime - startTime); |
753 | 750 | ||
754 | return anExecutionContext; | 751 | return anExecutionContext; |
755 | }, | 752 | }, |
756 | 753 | ||
757 | //----------------------------------------------------------------------------- | 754 | //----------------------------------------------------------------------------- |
758 | /* | 755 | /* |
759 | 'deferredEncryptBlocks': function(anExecutionContext) { | 756 | 'deferredEncryptBlocks': function(anExecutionContext) { |
760 | vardeferredResult; | 757 | vardeferredResult; |
761 | varmessageSize; | 758 | varmessageSize; |
762 | var i,c; | 759 | var i,c; |
763 | 760 | ||
764 | messageSize = anExecutionContext.messageLength(); | 761 | messageSize = anExecutionContext.messageLength(); |
765 | 762 | ||
766 | deferredResult = new Clipperz.Async.Deferred("AES.deferredEncryptBloks"); | 763 | deferredResult = new Clipperz.Async.Deferred("AES.deferredEncryptBloks"); |
767 | 764 | ||
768 | c = Math.ceil(messageSize / anExecutionContext.elaborationChunkSize()); | 765 | c = Math.ceil(messageSize / anExecutionContext.elaborationChunkSize()); |
769 | for (i=0; i<c; i++) { | 766 | for (i=0; i<c; i++) { |
770 | deferredResult.addCallback(Clipperz.Crypto.AES.deferredEncryptExecutionChunk); | 767 | deferredResult.addCallback(Clipperz.Crypto.AES.deferredEncryptExecutionChunk); |
771 | deferredResult.addMethod(anExecutionContext, 'pause'); | 768 | deferredResult.addMethod(anExecutionContext, 'pause'); |
772 | } | 769 | } |
773 | 770 | ||
774 | deferredResult.callback(anExecutionContext); | 771 | deferredResult.callback(anExecutionContext); |
775 | 772 | ||
776 | return deferredResult; | 773 | return deferredResult; |
777 | }, | 774 | }, |
778 | */ | 775 | */ |
779 | 776 | ||
780 | 'deferredEncryptBlocks': function(anExecutionContext) { | 777 | 'deferredEncryptBlocks': function(anExecutionContext) { |
781 | vardeferredResult; | 778 | vardeferredResult; |
782 | 779 | ||
783 | if (! anExecutionContext.isDone()) { | 780 | if (! anExecutionContext.isDone()) { |
784 | deferredResult = Clipperz.Async.callbacks("Clipperz.Crypto.AES.deferredEncryptBloks", [ | 781 | deferredResult = Clipperz.Async.callbacks("Clipperz.Crypto.AES.deferredEncryptBloks", [ |
785 | Clipperz.Crypto.AES.deferredEncryptExecutionChunk, | 782 | Clipperz.Crypto.AES.deferredEncryptExecutionChunk, |
786 | MochiKit.Base.method(anExecutionContext, 'pause'), | 783 | MochiKit.Base.method(anExecutionContext, 'pause'), |
787 | Clipperz.Crypto.AES.deferredEncryptBlocks | 784 | Clipperz.Crypto.AES.deferredEncryptBlocks |
788 | ], {trace:false}, anExecutionContext); | 785 | ], {trace:false}, anExecutionContext); |
789 | } else { | 786 | } else { |
790 | deferredResult = MochiKit.Async.succeed(anExecutionContext); | 787 | deferredResult = MochiKit.Async.succeed(anExecutionContext); |
791 | } | 788 | } |
792 | 789 | ||
793 | return deferredResult; | 790 | return deferredResult; |
794 | }, | 791 | }, |
795 | 792 | ||
796 | //----------------------------------------------------------------------------- | 793 | //----------------------------------------------------------------------------- |
797 | 794 | ||
798 | 'deferredEncrypt': function(aKey, someData, aNonce) { | 795 | 'deferredEncrypt': function(aKey, someData, aNonce) { |
799 | var deferredResult; | 796 | var deferredResult; |
800 | varexecutionContext; | 797 | varexecutionContext; |
801 | var result; | 798 | var result; |
802 | var nonce; | 799 | var nonce; |
803 | var key; | 800 | var key; |
804 | 801 | ||
805 | key = new Clipperz.Crypto.AES.Key({key:aKey}); | 802 | key = new Clipperz.Crypto.AES.Key({key:aKey}); |
806 | nonce = aNonce ? aNonce.clone() : Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(128/8); | 803 | nonce = aNonce ? aNonce.clone() : Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(128/8); |
807 | 804 | ||
808 | executionContext = new Clipperz.Crypto.AES.DeferredExecutionContext({key:key, message:someData, nonce:nonce}); | 805 | executionContext = new Clipperz.Crypto.AES.DeferredExecutionContext({key:key, message:someData, nonce:nonce}); |
809 | 806 | ||
810 | deferredResult = new Clipperz.Async.Deferred("AES.deferredEncrypt"); | 807 | deferredResult = new Clipperz.Async.Deferred("AES.deferredEncrypt"); |
811 | //deferredResult.addCallback(function (aValue) { console.log(">>> deferredEncrypt"); return aValue; }); | ||
812 | deferredResult.addCallback(Clipperz.Crypto.AES.deferredEncryptBlocks); | 808 | deferredResult.addCallback(Clipperz.Crypto.AES.deferredEncryptBlocks); |
813 | deferredResult.addCallback(function(anExecutionContext) { | 809 | deferredResult.addCallback(function(anExecutionContext) { |
814 | var result; | 810 | var result; |
815 | 811 | ||
816 | result = anExecutionContext.nonce().clone(); | 812 | result = anExecutionContext.nonce().clone(); |
817 | result.appendBytes(anExecutionContext.resultArray()); | 813 | result.appendBytes(anExecutionContext.resultArray()); |
818 | 814 | ||
819 | return result; | 815 | return result; |
820 | }); | 816 | }); |
821 | //deferredResult.addCallback(function (aValue) { console.log("<<< deferredEncrypt"); return aValue; }); | ||
822 | deferredResult.callback(executionContext) | 817 | deferredResult.callback(executionContext) |
823 | 818 | ||
824 | return deferredResult; | 819 | return deferredResult; |
825 | }, | 820 | }, |
826 | 821 | ||
827 | //----------------------------------------------------------------------------- | 822 | //----------------------------------------------------------------------------- |
828 | 823 | ||
829 | 'deferredDecrypt': function(aKey, someData) { | 824 | 'deferredDecrypt': function(aKey, someData) { |
830 | var deferredResult | 825 | var deferredResult |
831 | var nonce; | 826 | var nonce; |
832 | var message; | 827 | var message; |
833 | var key; | 828 | var key; |
834 | 829 | ||
835 | key = new Clipperz.Crypto.AES.Key({key:aKey}); | 830 | key = new Clipperz.Crypto.AES.Key({key:aKey}); |
836 | nonce = someData.split(0, (128/8)); | 831 | nonce = someData.split(0, (128/8)); |
837 | message = someData.split(128/8); | 832 | message = someData.split(128/8); |
838 | executionContext = new Clipperz.Crypto.AES.DeferredExecutionContext({key:key, message:message, nonce:nonce}); | 833 | executionContext = new Clipperz.Crypto.AES.DeferredExecutionContext({key:key, message:message, nonce:nonce}); |
839 | 834 | ||
840 | deferredResult = new Clipperz.Async.Deferred("AES.deferredDecrypt"); | 835 | deferredResult = new Clipperz.Async.Deferred("AES.deferredDecrypt"); |
841 | //deferredResult.addCallback(function (aValue) { console.log(">>> deferredDecrypt"); return aValue; }); | ||
842 | deferredResult.addCallback(Clipperz.Crypto.AES.deferredEncryptBlocks); | 836 | deferredResult.addCallback(Clipperz.Crypto.AES.deferredEncryptBlocks); |
843 | deferredResult.addCallback(function(anExecutionContext) { | 837 | deferredResult.addCallback(function(anExecutionContext) { |
844 | return anExecutionContext.result(); | 838 | return anExecutionContext.result(); |
845 | }); | 839 | }); |
846 | //deferredResult.addCallback(function (aValue) { console.log("<<< deferredDecrypt"); return aValue; }); | ||
847 | deferredResult.callback(executionContext); | 840 | deferredResult.callback(executionContext); |
848 | 841 | ||
849 | return deferredResult; | 842 | return deferredResult; |
850 | }, | 843 | }, |
851 | 844 | ||
852 | //----------------------------------------------------------------------------- | 845 | //----------------------------------------------------------------------------- |
853 | __syntaxFix__: "syntax fix" | 846 | __syntaxFix__: "syntax fix" |
854 | 847 | ||
855 | }); | 848 | }); |
856 | 849 | ||
857 | //############################################################################# | 850 | //############################################################################# |
858 | 851 | ||
859 | //Clipperz.Crypto.AES.DeferredExecution = { | 852 | //Clipperz.Crypto.AES.DeferredExecution = { |
860 | // 'chunkSize': 16384, // 4096, // 1024 4096 8192 1638432768; | 853 | // 'chunkSize': 16384, // 4096, // 1024 4096 8192 1638432768; |
861 | // 'pauseTime': 0.02 //0.2 | 854 | // 'pauseTime': 0.02 //0.2 |
862 | //} | 855 | //} |
863 | 856 | ||
864 | Clipperz.Crypto.AES.exception = { | 857 | Clipperz.Crypto.AES.exception = { |
865 | 'UnsupportedKeySize': new MochiKit.Base.NamedError("Clipperz.Crypto.AES.exception.UnsupportedKeySize") | 858 | 'UnsupportedKeySize': new MochiKit.Base.NamedError("Clipperz.Crypto.AES.exception.UnsupportedKeySize") |
866 | }; | 859 | }; |