Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(870)

Side by Side Diff: sdk/lib/io/crypto.dart

Issue 2822303002: Format all files under the sdk/lib directory. (Closed)
Patch Set: Format all files under the sdk/lib directory. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of dart.io; 5 part of dart.io;
6 6
7 class _CryptoUtils { 7 class _CryptoUtils {
8 static const int PAD = 61; // '=' 8 static const int PAD = 61; // '='
9 static const int CR = 13; // '\r' 9 static const int CR = 13; // '\r'
10 static const int LF = 10; // '\n' 10 static const int LF = 10; // '\n'
11 static const int LINE_LENGTH = 76; 11 static const int LINE_LENGTH = 76;
12 12
13 static const String _encodeTable = 13 static const String _encodeTable =
14 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; 14 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
15 15
16 static const String _encodeTableUrlSafe = 16 static const String _encodeTableUrlSafe =
17 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"; 17 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
18 18
19 // Lookup table used for finding Base 64 alphabet index of a given byte. 19 // Lookup table used for finding Base 64 alphabet index of a given byte.
20 // -2 : Outside Base 64 alphabet. 20 // -2 : Outside Base 64 alphabet.
21 // -1 : '\r' or '\n' 21 // -1 : '\r' or '\n'
22 // 0 : = (Padding character). 22 // 0 : = (Padding character).
23 // >0 : Base 64 alphabet index of given byte. 23 // >0 : Base 64 alphabet index of given byte.
24 static const List<int> _decodeTable = 24 static const List<int> _decodeTable = const [
25 const [ -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -1, -2, -2, -1, -2, -2, 25 -2,
floitsch 2017/04/19 09:34:20 These tables should stay aligned.
26 -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, 26 -2,
27 -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, 62, -2, 62, -2, 63, 27 -2,
28 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -2, -2, -2, 0, -2, -2, 28 -2,
29 -2, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 29 -2,
30 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -2, -2, -2, -2, 63, 30 -2,
31 -2, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 31 -2,
32 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -2, -2, -2, -2, -2, 32 -2,
33 -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, 33 -2,
34 -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, 34 -2,
35 -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, 35 -1,
36 -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, 36 -2,
37 -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, 37 -2,
38 -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, 38 -1,
39 -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, 39 -2,
40 -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2 ]; 40 -2,
41 -2,
42 -2,
43 -2,
44 -2,
45 -2,
46 -2,
47 -2,
48 -2,
49 -2,
50 -2,
51 -2,
52 -2,
53 -2,
54 -2,
55 -2,
56 -2,
57 -2,
58 -2,
59 -2,
60 -2,
61 -2,
62 -2,
63 -2,
64 -2,
65 -2,
66 -2,
67 -2,
68 62,
69 -2,
70 62,
71 -2,
72 63,
73 52,
74 53,
75 54,
76 55,
77 56,
78 57,
79 58,
80 59,
81 60,
82 61,
83 -2,
84 -2,
85 -2,
86 0,
87 -2,
88 -2,
89 -2,
90 0,
91 1,
92 2,
93 3,
94 4,
95 5,
96 6,
97 7,
98 8,
99 9,
100 10,
101 11,
102 12,
103 13,
104 14,
105 15,
106 16,
107 17,
108 18,
109 19,
110 20,
111 21,
112 22,
113 23,
114 24,
115 25,
116 -2,
117 -2,
118 -2,
119 -2,
120 63,
121 -2,
122 26,
123 27,
124 28,
125 29,
126 30,
127 31,
128 32,
129 33,
130 34,
131 35,
132 36,
133 37,
134 38,
135 39,
136 40,
137 41,
138 42,
139 43,
140 44,
141 45,
142 46,
143 47,
144 48,
145 49,
146 50,
147 51,
148 -2,
149 -2,
150 -2,
151 -2,
152 -2,
153 -2,
154 -2,
155 -2,
156 -2,
157 -2,
158 -2,
159 -2,
160 -2,
161 -2,
162 -2,
163 -2,
164 -2,
165 -2,
166 -2,
167 -2,
168 -2,
169 -2,
170 -2,
171 -2,
172 -2,
173 -2,
174 -2,
175 -2,
176 -2,
177 -2,
178 -2,
179 -2,
180 -2,
181 -2,
182 -2,
183 -2,
184 -2,
185 -2,
186 -2,
187 -2,
188 -2,
189 -2,
190 -2,
191 -2,
192 -2,
193 -2,
194 -2,
195 -2,
196 -2,
197 -2,
198 -2,
199 -2,
200 -2,
201 -2,
202 -2,
203 -2,
204 -2,
205 -2,
206 -2,
207 -2,
208 -2,
209 -2,
210 -2,
211 -2,
212 -2,
213 -2,
214 -2,
215 -2,
216 -2,
217 -2,
218 -2,
219 -2,
220 -2,
221 -2,
222 -2,
223 -2,
224 -2,
225 -2,
226 -2,
227 -2,
228 -2,
229 -2,
230 -2,
231 -2,
232 -2,
233 -2,
234 -2,
235 -2,
236 -2,
237 -2,
238 -2,
239 -2,
240 -2,
241 -2,
242 -2,
243 -2,
244 -2,
245 -2,
246 -2,
247 -2,
248 -2,
249 -2,
250 -2,
251 -2,
252 -2,
253 -2,
254 -2,
255 -2,
256 -2,
257 -2,
258 -2,
259 -2,
260 -2,
261 -2,
262 -2,
263 -2,
264 -2,
265 -2,
266 -2,
267 -2,
268 -2,
269 -2,
270 -2,
271 -2,
272 -2,
273 -2,
274 -2,
275 -2,
276 -2,
277 -2,
278 -2,
279 -2,
280 -2
281 ];
41 282
42 static String bytesToHex(List<int> bytes) { 283 static String bytesToHex(List<int> bytes) {
43 var result = new StringBuffer(); 284 var result = new StringBuffer();
44 for (var part in bytes) { 285 for (var part in bytes) {
45 result.write('${part < 16 ? '0' : ''}${part.toRadixString(16)}'); 286 result.write('${part < 16 ? '0' : ''}${part.toRadixString(16)}');
46 } 287 }
47 return result.toString(); 288 return result.toString();
48 } 289 }
49 290
50 static String bytesToBase64(List<int> bytes, 291 static String bytesToBase64(List<int> bytes,
51 [bool urlSafe = false, 292 [bool urlSafe = false, bool addLineSeparator = false]) {
52 bool addLineSeparator = false]) {
53 int len = bytes.length; 293 int len = bytes.length;
54 if (len == 0) { 294 if (len == 0) {
55 return ""; 295 return "";
56 } 296 }
57 final String lookup = urlSafe ? _encodeTableUrlSafe : _encodeTable; 297 final String lookup = urlSafe ? _encodeTableUrlSafe : _encodeTable;
58 // Size of 24 bit chunks. 298 // Size of 24 bit chunks.
59 final int remainderLength = len.remainder(3); 299 final int remainderLength = len.remainder(3);
60 final int chunkLength = len - remainderLength; 300 final int chunkLength = len - remainderLength;
61 // Size of base output. 301 // Size of base output.
62 int outputLen = ((len ~/ 3) * 4) + ((remainderLength > 0) ? 4 : 0); 302 int outputLen = ((len ~/ 3) * 4) + ((remainderLength > 0) ? 4 : 0);
63 // Add extra for line separators. 303 // Add extra for line separators.
64 if (addLineSeparator) { 304 if (addLineSeparator) {
65 outputLen += ((outputLen - 1) ~/ LINE_LENGTH) << 1; 305 outputLen += ((outputLen - 1) ~/ LINE_LENGTH) << 1;
66 } 306 }
67 List<int> out = new List<int>(outputLen); 307 List<int> out = new List<int>(outputLen);
68 308
69 // Encode 24 bit chunks. 309 // Encode 24 bit chunks.
70 int j = 0, i = 0, c = 0; 310 int j = 0, i = 0, c = 0;
71 while (i < chunkLength) { 311 while (i < chunkLength) {
72 int x = ((bytes[i++] << 16) & 0xFFFFFF) | 312 int x = ((bytes[i++] << 16) & 0xFFFFFF) |
73 ((bytes[i++] << 8) & 0xFFFFFF) | 313 ((bytes[i++] << 8) & 0xFFFFFF) |
74 bytes[i++]; 314 bytes[i++];
75 out[j++] = lookup.codeUnitAt(x >> 18); 315 out[j++] = lookup.codeUnitAt(x >> 18);
76 out[j++] = lookup.codeUnitAt((x >> 12) & 0x3F); 316 out[j++] = lookup.codeUnitAt((x >> 12) & 0x3F);
77 out[j++] = lookup.codeUnitAt((x >> 6) & 0x3F); 317 out[j++] = lookup.codeUnitAt((x >> 6) & 0x3F);
78 out[j++] = lookup.codeUnitAt(x & 0x3f); 318 out[j++] = lookup.codeUnitAt(x & 0x3f);
79 // Add optional line separator for each 76 char output. 319 // Add optional line separator for each 76 char output.
80 if (addLineSeparator && ++c == 19 && j < outputLen - 2) { 320 if (addLineSeparator && ++c == 19 && j < outputLen - 2) {
81 out[j++] = CR; 321 out[j++] = CR;
82 out[j++] = LF; 322 out[j++] = LF;
83 c = 0; 323 c = 0;
84 } 324 }
85 } 325 }
86 326
87 // If input length if not a multiple of 3, encode remaining bytes and 327 // If input length if not a multiple of 3, encode remaining bytes and
88 // add padding. 328 // add padding.
89 if (remainderLength == 1) { 329 if (remainderLength == 1) {
90 int x = bytes[i]; 330 int x = bytes[i];
91 out[j++] = lookup.codeUnitAt(x >> 2); 331 out[j++] = lookup.codeUnitAt(x >> 2);
92 out[j++] = lookup.codeUnitAt((x << 4) & 0x3F); 332 out[j++] = lookup.codeUnitAt((x << 4) & 0x3F);
93 out[j++] = PAD; 333 out[j++] = PAD;
94 out[j++] = PAD; 334 out[j++] = PAD;
95 } else if (remainderLength == 2) { 335 } else if (remainderLength == 2) {
96 int x = bytes[i]; 336 int x = bytes[i];
97 int y = bytes[i + 1]; 337 int y = bytes[i + 1];
98 out[j++] = lookup.codeUnitAt(x >> 2); 338 out[j++] = lookup.codeUnitAt(x >> 2);
99 out[j++] = lookup.codeUnitAt(((x << 4) | (y >> 4)) & 0x3F); 339 out[j++] = lookup.codeUnitAt(((x << 4) | (y >> 4)) & 0x3F);
100 out[j++] = lookup.codeUnitAt((y << 2) & 0x3F); 340 out[j++] = lookup.codeUnitAt((y << 2) & 0x3F);
101 out[j++] = PAD; 341 out[j++] = PAD;
102 } 342 }
103 343
104 return new String.fromCharCodes(out); 344 return new String.fromCharCodes(out);
105 } 345 }
106 346
107 static List<int> base64StringToBytes(String input, 347 static List<int> base64StringToBytes(String input,
108 [bool ignoreInvalidCharacters = true]) { 348 [bool ignoreInvalidCharacters = true]) {
109 int len = input.length; 349 int len = input.length;
110 if (len == 0) { 350 if (len == 0) {
111 return new List<int>(0); 351 return new List<int>(0);
112 } 352 }
113 353
114 // Count '\r', '\n' and illegal characters, For illegal characters, 354 // Count '\r', '\n' and illegal characters, For illegal characters,
115 // if [ignoreInvalidCharacters] is false, throw an exception. 355 // if [ignoreInvalidCharacters] is false, throw an exception.
116 int extrasLen = 0; 356 int extrasLen = 0;
117 for (int i = 0; i < len; i++) { 357 for (int i = 0; i < len; i++) {
118 int c = _decodeTable[input.codeUnitAt(i)]; 358 int c = _decodeTable[input.codeUnitAt(i)];
119 if (c < 0) { 359 if (c < 0) {
120 extrasLen++; 360 extrasLen++;
121 if(c == -2 && !ignoreInvalidCharacters) { 361 if (c == -2 && !ignoreInvalidCharacters) {
122 throw new FormatException('Invalid character: ${input[i]}'); 362 throw new FormatException('Invalid character: ${input[i]}');
123 } 363 }
124 } 364 }
125 } 365 }
126 366
127 if ((len - extrasLen) % 4 != 0) { 367 if ((len - extrasLen) % 4 != 0) {
128 throw new FormatException('''Size of Base 64 characters in Input 368 throw new FormatException('''Size of Base 64 characters in Input
129 must be a multiple of 4. Input: $input'''); 369 must be a multiple of 4. Input: $input''');
130 } 370 }
131 371
(...skipping 18 matching lines...) Expand all
150 } 390 }
151 } 391 }
152 out[o++] = x >> 16; 392 out[o++] = x >> 16;
153 if (o < outputLen) { 393 if (o < outputLen) {
154 out[o++] = (x >> 8) & 0xFF; 394 out[o++] = (x >> 8) & 0xFF;
155 if (o < outputLen) out[o++] = x & 0xFF; 395 if (o < outputLen) out[o++] = x & 0xFF;
156 } 396 }
157 } 397 }
158 return out; 398 return out;
159 } 399 }
160
161 } 400 }
162 401
163 // Constants. 402 // Constants.
164 const _MASK_8 = 0xff; 403 const _MASK_8 = 0xff;
165 const _MASK_32 = 0xffffffff; 404 const _MASK_32 = 0xffffffff;
166 const _BITS_PER_BYTE = 8; 405 const _BITS_PER_BYTE = 8;
167 const _BYTES_PER_WORD = 4; 406 const _BYTES_PER_WORD = 4;
168 407
169 // Base class encapsulating common behavior for cryptographic hash 408 // Base class encapsulating common behavior for cryptographic hash
170 // functions. 409 // functions.
171 abstract class _HashBase { 410 abstract class _HashBase {
172 // Hasher state. 411 // Hasher state.
173 final int _chunkSizeInWords; 412 final int _chunkSizeInWords;
174 final int _digestSizeInWords; 413 final int _digestSizeInWords;
175 final bool _bigEndianWords; 414 final bool _bigEndianWords;
176 int _lengthInBytes = 0; 415 int _lengthInBytes = 0;
177 List<int> _pendingData; 416 List<int> _pendingData;
178 List<int> _currentChunk; 417 List<int> _currentChunk;
179 List<int> _h; 418 List<int> _h;
180 bool _digestCalled = false; 419 bool _digestCalled = false;
181 420
182 _HashBase(this._chunkSizeInWords, 421 _HashBase(
183 this._digestSizeInWords, 422 this._chunkSizeInWords, this._digestSizeInWords, this._bigEndianWords)
184 this._bigEndianWords)
185 : _pendingData = [] { 423 : _pendingData = [] {
186 _currentChunk = new List(_chunkSizeInWords); 424 _currentChunk = new List(_chunkSizeInWords);
187 _h = new List(_digestSizeInWords); 425 _h = new List(_digestSizeInWords);
188 } 426 }
189 427
190 // Update the hasher with more data. 428 // Update the hasher with more data.
191 add(List<int> data) { 429 add(List<int> data) {
192 if (_digestCalled) { 430 if (_digestCalled) {
193 throw new StateError( 431 throw new StateError(
194 'Hash update method called after digest was retrieved'); 432 'Hash update method called after digest was retrieved');
(...skipping 30 matching lines...) Expand all
225 _add32(x, y) => (x + y) & _MASK_32; 463 _add32(x, y) => (x + y) & _MASK_32;
226 _roundUp(val, n) => (val + n - 1) & -n; 464 _roundUp(val, n) => (val + n - 1) & -n;
227 465
228 // Rotate left limiting to unsigned 32-bit values. 466 // Rotate left limiting to unsigned 32-bit values.
229 int _rotl32(int val, int shift) { 467 int _rotl32(int val, int shift) {
230 var mod_shift = shift & 31; 468 var mod_shift = shift & 31;
231 return ((val << mod_shift) & _MASK_32) | 469 return ((val << mod_shift) & _MASK_32) |
232 ((val & _MASK_32) >> (32 - mod_shift)); 470 ((val & _MASK_32) >> (32 - mod_shift));
233 } 471 }
234 472
235
236 // Compute the final result as a list of bytes from the hash words. 473 // Compute the final result as a list of bytes from the hash words.
237 List<int> _resultAsBytes() { 474 List<int> _resultAsBytes() {
238 var result = <int>[]; 475 var result = <int>[];
239 for (var i = 0; i < _h.length; i++) { 476 for (var i = 0; i < _h.length; i++) {
240 result.addAll(_wordToBytes(_h[i])); 477 result.addAll(_wordToBytes(_h[i]));
241 } 478 }
242 return result; 479 return result;
243 } 480 }
244 481
245 // Converts a list of bytes to a chunk of 32-bit words. 482 // Converts a list of bytes to a chunk of 32-bit words.
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 _h[2] = 0x98badcfe; 553 _h[2] = 0x98badcfe;
317 _h[3] = 0x10325476; 554 _h[3] = 0x10325476;
318 } 555 }
319 556
320 // Returns a new instance of this Hash. 557 // Returns a new instance of this Hash.
321 _MD5 newInstance() { 558 _MD5 newInstance() {
322 return new _MD5(); 559 return new _MD5();
323 } 560 }
324 561
325 static const _k = const [ 562 static const _k = const [
326 0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee, 0xf57c0faf, 0x4787c62a, 563 0xd76aa478,
floitsch 2017/04/19 09:34:20 Should (probably) stay aligned, although it's just
327 0xa8304613, 0xfd469501, 0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be, 564 0xe8c7b756,
328 0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821, 0xf61e2562, 0xc040b340, 565 0x242070db,
329 0x265e5a51, 0xe9b6c7aa, 0xd62f105d, 0x02441453, 0xd8a1e681, 0xe7d3fbc8, 566 0xc1bdceee,
330 0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed, 0xa9e3e905, 0xfcefa3f8, 567 0xf57c0faf,
331 0x676f02d9, 0x8d2a4c8a, 0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c, 568 0x4787c62a,
332 0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70, 0x289b7ec6, 0xeaa127fa, 569 0xa8304613,
333 0xd4ef3085, 0x04881d05, 0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665, 570 0xfd469501,
334 0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039, 0x655b59c3, 0x8f0ccc92, 571 0x698098d8,
335 0xffeff47d, 0x85845dd1, 0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1, 572 0x8b44f7af,
336 0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391 ]; 573 0xffff5bb1,
574 0x895cd7be,
575 0x6b901122,
576 0xfd987193,
577 0xa679438e,
578 0x49b40821,
579 0xf61e2562,
580 0xc040b340,
581 0x265e5a51,
582 0xe9b6c7aa,
583 0xd62f105d,
584 0x02441453,
585 0xd8a1e681,
586 0xe7d3fbc8,
587 0x21e1cde6,
588 0xc33707d6,
589 0xf4d50d87,
590 0x455a14ed,
591 0xa9e3e905,
592 0xfcefa3f8,
593 0x676f02d9,
594 0x8d2a4c8a,
595 0xfffa3942,
596 0x8771f681,
597 0x6d9d6122,
598 0xfde5380c,
599 0xa4beea44,
600 0x4bdecfa9,
601 0xf6bb4b60,
602 0xbebfbc70,
603 0x289b7ec6,
604 0xeaa127fa,
605 0xd4ef3085,
606 0x04881d05,
607 0xd9d4d039,
608 0xe6db99e5,
609 0x1fa27cf8,
610 0xc4ac5665,
611 0xf4292244,
612 0x432aff97,
613 0xab9423a7,
614 0xfc93a039,
615 0x655b59c3,
616 0x8f0ccc92,
617 0xffeff47d,
618 0x85845dd1,
619 0x6fa87e4f,
620 0xfe2ce6e0,
621 0xa3014314,
622 0x4e0811a1,
623 0xf7537e82,
624 0xbd3af235,
625 0x2ad7d2bb,
626 0xeb86d391
627 ];
337 628
338 static const _r = const [ 629 static const _r = const [
339 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 5, 9, 14, 630 7,
floitsch 2017/04/19 09:34:20 ditto.
340 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 4, 11, 16, 23, 4, 11, 631 12,
341 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 6, 10, 15, 21, 6, 10, 15, 21, 6, 632 17,
342 10, 15, 21, 6, 10, 15, 21 ]; 633 22,
634 7,
635 12,
636 17,
637 22,
638 7,
639 12,
640 17,
641 22,
642 7,
643 12,
644 17,
645 22,
646 5,
647 9,
648 14,
649 20,
650 5,
651 9,
652 14,
653 20,
654 5,
655 9,
656 14,
657 20,
658 5,
659 9,
660 14,
661 20,
662 4,
663 11,
664 16,
665 23,
666 4,
667 11,
668 16,
669 23,
670 4,
671 11,
672 16,
673 23,
674 4,
675 11,
676 16,
677 23,
678 6,
679 10,
680 15,
681 21,
682 6,
683 10,
684 15,
685 21,
686 6,
687 10,
688 15,
689 21,
690 6,
691 10,
692 15,
693 21
694 ];
343 695
344 // Compute one iteration of the MD5 algorithm with a chunk of 696 // Compute one iteration of the MD5 algorithm with a chunk of
345 // 16 32-bit pieces. 697 // 16 32-bit pieces.
346 void _updateHash(List<int> m) { 698 void _updateHash(List<int> m) {
347 assert(m.length == 16); 699 assert(m.length == 16);
348 700
349 var a = _h[0]; 701 var a = _h[0];
350 var b = _h[1]; 702 var b = _h[1];
351 var c = _h[2]; 703 var c = _h[2];
352 var d = _h[3]; 704 var d = _h[3];
(...skipping 12 matching lines...) Expand all
365 t0 = b ^ c ^ d; 717 t0 = b ^ c ^ d;
366 t1 = ((3 * i) + 5) % 16; 718 t1 = ((3 * i) + 5) % 16;
367 } else { 719 } else {
368 t0 = c ^ (b | (~d & _MASK_32)); 720 t0 = c ^ (b | (~d & _MASK_32));
369 t1 = (7 * i) % 16; 721 t1 = (7 * i) % 16;
370 } 722 }
371 723
372 var temp = d; 724 var temp = d;
373 d = c; 725 d = c;
374 c = b; 726 c = b;
375 b = _add32(b, _rotl32(_add32(_add32(a, t0), 727 b = _add32(
376 _add32(_k[i], m[t1])), 728 b, _rotl32(_add32(_add32(a, t0), _add32(_k[i], m[t1])), _r[i]));
377 _r[i]));
378 a = temp; 729 a = temp;
379 } 730 }
380 731
381 _h[0] = _add32(a, _h[0]); 732 _h[0] = _add32(a, _h[0]);
382 _h[1] = _add32(b, _h[1]); 733 _h[1] = _add32(b, _h[1]);
383 _h[2] = _add32(c, _h[2]); 734 _h[2] = _add32(c, _h[2]);
384 _h[3] = _add32(d, _h[3]); 735 _h[3] = _add32(d, _h[3]);
385 } 736 }
386 } 737 }
387 738
388 // The SHA1 hasher is used to compute an SHA1 message digest. 739 // The SHA1 hasher is used to compute an SHA1 message digest.
389 class _SHA1 extends _HashBase { 740 class _SHA1 extends _HashBase {
390 // Construct a SHA1 hasher object. 741 // Construct a SHA1 hasher object.
391 _SHA1() : _w = new List(80), super(16, 5, true) { 742 _SHA1()
743 : _w = new List(80),
744 super(16, 5, true) {
392 _h[0] = 0x67452301; 745 _h[0] = 0x67452301;
393 _h[1] = 0xEFCDAB89; 746 _h[1] = 0xEFCDAB89;
394 _h[2] = 0x98BADCFE; 747 _h[2] = 0x98BADCFE;
395 _h[3] = 0x10325476; 748 _h[3] = 0x10325476;
396 _h[4] = 0xC3D2E1F0; 749 _h[4] = 0xC3D2E1F0;
397 } 750 }
398 751
399 // Returns a new instance of this Hash. 752 // Returns a new instance of this Hash.
400 _SHA1 newInstance() { 753 _SHA1 newInstance() {
401 return new _SHA1(); 754 return new _SHA1();
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 792
440 _h[0] = _add32(a, _h[0]); 793 _h[0] = _add32(a, _h[0]);
441 _h[1] = _add32(b, _h[1]); 794 _h[1] = _add32(b, _h[1]);
442 _h[2] = _add32(c, _h[2]); 795 _h[2] = _add32(c, _h[2]);
443 _h[3] = _add32(d, _h[3]); 796 _h[3] = _add32(d, _h[3]);
444 _h[4] = _add32(e, _h[4]); 797 _h[4] = _add32(e, _h[4]);
445 } 798 }
446 799
447 List<int> _w; 800 List<int> _w;
448 } 801 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698