OLD | NEW |
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, -2, -2, -2, -2, -2, -2, -2, -2, -2, -1, -2, -2, -1, -2, -2, // |
26 -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, | 26 -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, // |
27 -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, 62, -2, 62, -2, 63, | 27 -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, 62, -2, 62, -2, 63, // |
28 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -2, -2, -2, 0, -2, -2, | 28 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -2, -2, -2, 00, -2, -2, // |
29 -2, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, | 29 -2, 00, 01, 02, 03, 04, 05, 06, 07, 08, 09, 10, 11, 12, 13, 14, // |
30 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -2, -2, -2, -2, 63, | 30 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -2, -2, -2, -2, 63, // |
31 -2, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, | 31 -2, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, // |
32 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -2, -2, -2, -2, -2, | 32 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -2, -2, -2, -2, -2, // |
33 -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, | 33 -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, // |
34 -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, | 34 -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, // |
35 -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, | 35 -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, // |
36 -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, | 36 -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, // |
37 -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, | 37 -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, // |
38 -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, | 38 -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, // |
39 -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, | 39 -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, // |
40 -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2 ]; | 40 -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2 |
| 41 ]; |
41 | 42 |
42 static String bytesToHex(List<int> bytes) { | 43 static String bytesToHex(List<int> bytes) { |
43 var result = new StringBuffer(); | 44 var result = new StringBuffer(); |
44 for (var part in bytes) { | 45 for (var part in bytes) { |
45 result.write('${part < 16 ? '0' : ''}${part.toRadixString(16)}'); | 46 result.write('${part < 16 ? '0' : ''}${part.toRadixString(16)}'); |
46 } | 47 } |
47 return result.toString(); | 48 return result.toString(); |
48 } | 49 } |
49 | 50 |
50 static String bytesToBase64(List<int> bytes, | 51 static String bytesToBase64(List<int> bytes, |
51 [bool urlSafe = false, | 52 [bool urlSafe = false, bool addLineSeparator = false]) { |
52 bool addLineSeparator = false]) { | |
53 int len = bytes.length; | 53 int len = bytes.length; |
54 if (len == 0) { | 54 if (len == 0) { |
55 return ""; | 55 return ""; |
56 } | 56 } |
57 final String lookup = urlSafe ? _encodeTableUrlSafe : _encodeTable; | 57 final String lookup = urlSafe ? _encodeTableUrlSafe : _encodeTable; |
58 // Size of 24 bit chunks. | 58 // Size of 24 bit chunks. |
59 final int remainderLength = len.remainder(3); | 59 final int remainderLength = len.remainder(3); |
60 final int chunkLength = len - remainderLength; | 60 final int chunkLength = len - remainderLength; |
61 // Size of base output. | 61 // Size of base output. |
62 int outputLen = ((len ~/ 3) * 4) + ((remainderLength > 0) ? 4 : 0); | 62 int outputLen = ((len ~/ 3) * 4) + ((remainderLength > 0) ? 4 : 0); |
63 // Add extra for line separators. | 63 // Add extra for line separators. |
64 if (addLineSeparator) { | 64 if (addLineSeparator) { |
65 outputLen += ((outputLen - 1) ~/ LINE_LENGTH) << 1; | 65 outputLen += ((outputLen - 1) ~/ LINE_LENGTH) << 1; |
66 } | 66 } |
67 List<int> out = new List<int>(outputLen); | 67 List<int> out = new List<int>(outputLen); |
68 | 68 |
69 // Encode 24 bit chunks. | 69 // Encode 24 bit chunks. |
70 int j = 0, i = 0, c = 0; | 70 int j = 0, i = 0, c = 0; |
71 while (i < chunkLength) { | 71 while (i < chunkLength) { |
72 int x = ((bytes[i++] << 16) & 0xFFFFFF) | | 72 int x = ((bytes[i++] << 16) & 0xFFFFFF) | |
73 ((bytes[i++] << 8) & 0xFFFFFF) | | 73 ((bytes[i++] << 8) & 0xFFFFFF) | |
74 bytes[i++]; | 74 bytes[i++]; |
75 out[j++] = lookup.codeUnitAt(x >> 18); | 75 out[j++] = lookup.codeUnitAt(x >> 18); |
76 out[j++] = lookup.codeUnitAt((x >> 12) & 0x3F); | 76 out[j++] = lookup.codeUnitAt((x >> 12) & 0x3F); |
77 out[j++] = lookup.codeUnitAt((x >> 6) & 0x3F); | 77 out[j++] = lookup.codeUnitAt((x >> 6) & 0x3F); |
78 out[j++] = lookup.codeUnitAt(x & 0x3f); | 78 out[j++] = lookup.codeUnitAt(x & 0x3f); |
79 // Add optional line separator for each 76 char output. | 79 // Add optional line separator for each 76 char output. |
80 if (addLineSeparator && ++c == 19 && j < outputLen - 2) { | 80 if (addLineSeparator && ++c == 19 && j < outputLen - 2) { |
81 out[j++] = CR; | 81 out[j++] = CR; |
82 out[j++] = LF; | 82 out[j++] = LF; |
83 c = 0; | 83 c = 0; |
84 } | 84 } |
85 } | 85 } |
86 | 86 |
87 // If input length if not a multiple of 3, encode remaining bytes and | 87 // If input length if not a multiple of 3, encode remaining bytes and |
88 // add padding. | 88 // add padding. |
89 if (remainderLength == 1) { | 89 if (remainderLength == 1) { |
90 int x = bytes[i]; | 90 int x = bytes[i]; |
91 out[j++] = lookup.codeUnitAt(x >> 2); | 91 out[j++] = lookup.codeUnitAt(x >> 2); |
92 out[j++] = lookup.codeUnitAt((x << 4) & 0x3F); | 92 out[j++] = lookup.codeUnitAt((x << 4) & 0x3F); |
93 out[j++] = PAD; | 93 out[j++] = PAD; |
94 out[j++] = PAD; | 94 out[j++] = PAD; |
95 } else if (remainderLength == 2) { | 95 } else if (remainderLength == 2) { |
96 int x = bytes[i]; | 96 int x = bytes[i]; |
97 int y = bytes[i + 1]; | 97 int y = bytes[i + 1]; |
98 out[j++] = lookup.codeUnitAt(x >> 2); | 98 out[j++] = lookup.codeUnitAt(x >> 2); |
99 out[j++] = lookup.codeUnitAt(((x << 4) | (y >> 4)) & 0x3F); | 99 out[j++] = lookup.codeUnitAt(((x << 4) | (y >> 4)) & 0x3F); |
100 out[j++] = lookup.codeUnitAt((y << 2) & 0x3F); | 100 out[j++] = lookup.codeUnitAt((y << 2) & 0x3F); |
101 out[j++] = PAD; | 101 out[j++] = PAD; |
102 } | 102 } |
103 | 103 |
104 return new String.fromCharCodes(out); | 104 return new String.fromCharCodes(out); |
105 } | 105 } |
106 | 106 |
107 static List<int> base64StringToBytes(String input, | 107 static List<int> base64StringToBytes(String input, |
108 [bool ignoreInvalidCharacters = true]) { | 108 [bool ignoreInvalidCharacters = true]) { |
109 int len = input.length; | 109 int len = input.length; |
110 if (len == 0) { | 110 if (len == 0) { |
111 return new List<int>(0); | 111 return new List<int>(0); |
112 } | 112 } |
113 | 113 |
114 // Count '\r', '\n' and illegal characters, For illegal characters, | 114 // Count '\r', '\n' and illegal characters, For illegal characters, |
115 // if [ignoreInvalidCharacters] is false, throw an exception. | 115 // if [ignoreInvalidCharacters] is false, throw an exception. |
116 int extrasLen = 0; | 116 int extrasLen = 0; |
117 for (int i = 0; i < len; i++) { | 117 for (int i = 0; i < len; i++) { |
118 int c = _decodeTable[input.codeUnitAt(i)]; | 118 int c = _decodeTable[input.codeUnitAt(i)]; |
119 if (c < 0) { | 119 if (c < 0) { |
120 extrasLen++; | 120 extrasLen++; |
121 if(c == -2 && !ignoreInvalidCharacters) { | 121 if (c == -2 && !ignoreInvalidCharacters) { |
122 throw new FormatException('Invalid character: ${input[i]}'); | 122 throw new FormatException('Invalid character: ${input[i]}'); |
123 } | 123 } |
124 } | 124 } |
125 } | 125 } |
126 | 126 |
127 if ((len - extrasLen) % 4 != 0) { | 127 if ((len - extrasLen) % 4 != 0) { |
128 throw new FormatException('''Size of Base 64 characters in Input | 128 throw new FormatException('''Size of Base 64 characters in Input |
129 must be a multiple of 4. Input: $input'''); | 129 must be a multiple of 4. Input: $input'''); |
130 } | 130 } |
131 | 131 |
(...skipping 18 matching lines...) Expand all Loading... |
150 } | 150 } |
151 } | 151 } |
152 out[o++] = x >> 16; | 152 out[o++] = x >> 16; |
153 if (o < outputLen) { | 153 if (o < outputLen) { |
154 out[o++] = (x >> 8) & 0xFF; | 154 out[o++] = (x >> 8) & 0xFF; |
155 if (o < outputLen) out[o++] = x & 0xFF; | 155 if (o < outputLen) out[o++] = x & 0xFF; |
156 } | 156 } |
157 } | 157 } |
158 return out; | 158 return out; |
159 } | 159 } |
160 | |
161 } | 160 } |
162 | 161 |
163 // Constants. | 162 // Constants. |
164 const _MASK_8 = 0xff; | 163 const _MASK_8 = 0xff; |
165 const _MASK_32 = 0xffffffff; | 164 const _MASK_32 = 0xffffffff; |
166 const _BITS_PER_BYTE = 8; | 165 const _BITS_PER_BYTE = 8; |
167 const _BYTES_PER_WORD = 4; | 166 const _BYTES_PER_WORD = 4; |
168 | 167 |
169 // Base class encapsulating common behavior for cryptographic hash | 168 // Base class encapsulating common behavior for cryptographic hash |
170 // functions. | 169 // functions. |
171 abstract class _HashBase { | 170 abstract class _HashBase { |
172 // Hasher state. | 171 // Hasher state. |
173 final int _chunkSizeInWords; | 172 final int _chunkSizeInWords; |
174 final int _digestSizeInWords; | 173 final int _digestSizeInWords; |
175 final bool _bigEndianWords; | 174 final bool _bigEndianWords; |
176 int _lengthInBytes = 0; | 175 int _lengthInBytes = 0; |
177 List<int> _pendingData; | 176 List<int> _pendingData; |
178 List<int> _currentChunk; | 177 List<int> _currentChunk; |
179 List<int> _h; | 178 List<int> _h; |
180 bool _digestCalled = false; | 179 bool _digestCalled = false; |
181 | 180 |
182 _HashBase(this._chunkSizeInWords, | 181 _HashBase( |
183 this._digestSizeInWords, | 182 this._chunkSizeInWords, this._digestSizeInWords, this._bigEndianWords) |
184 this._bigEndianWords) | |
185 : _pendingData = [] { | 183 : _pendingData = [] { |
186 _currentChunk = new List(_chunkSizeInWords); | 184 _currentChunk = new List(_chunkSizeInWords); |
187 _h = new List(_digestSizeInWords); | 185 _h = new List(_digestSizeInWords); |
188 } | 186 } |
189 | 187 |
190 // Update the hasher with more data. | 188 // Update the hasher with more data. |
191 add(List<int> data) { | 189 add(List<int> data) { |
192 if (_digestCalled) { | 190 if (_digestCalled) { |
193 throw new StateError( | 191 throw new StateError( |
194 'Hash update method called after digest was retrieved'); | 192 'Hash update method called after digest was retrieved'); |
(...skipping 30 matching lines...) Expand all Loading... |
225 _add32(x, y) => (x + y) & _MASK_32; | 223 _add32(x, y) => (x + y) & _MASK_32; |
226 _roundUp(val, n) => (val + n - 1) & -n; | 224 _roundUp(val, n) => (val + n - 1) & -n; |
227 | 225 |
228 // Rotate left limiting to unsigned 32-bit values. | 226 // Rotate left limiting to unsigned 32-bit values. |
229 int _rotl32(int val, int shift) { | 227 int _rotl32(int val, int shift) { |
230 var mod_shift = shift & 31; | 228 var mod_shift = shift & 31; |
231 return ((val << mod_shift) & _MASK_32) | | 229 return ((val << mod_shift) & _MASK_32) | |
232 ((val & _MASK_32) >> (32 - mod_shift)); | 230 ((val & _MASK_32) >> (32 - mod_shift)); |
233 } | 231 } |
234 | 232 |
235 | |
236 // Compute the final result as a list of bytes from the hash words. | 233 // Compute the final result as a list of bytes from the hash words. |
237 List<int> _resultAsBytes() { | 234 List<int> _resultAsBytes() { |
238 var result = <int>[]; | 235 var result = <int>[]; |
239 for (var i = 0; i < _h.length; i++) { | 236 for (var i = 0; i < _h.length; i++) { |
240 result.addAll(_wordToBytes(_h[i])); | 237 result.addAll(_wordToBytes(_h[i])); |
241 } | 238 } |
242 return result; | 239 return result; |
243 } | 240 } |
244 | 241 |
245 // Converts a list of bytes to a chunk of 32-bit words. | 242 // Converts a list of bytes to a chunk of 32-bit words. |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 _h[2] = 0x98badcfe; | 313 _h[2] = 0x98badcfe; |
317 _h[3] = 0x10325476; | 314 _h[3] = 0x10325476; |
318 } | 315 } |
319 | 316 |
320 // Returns a new instance of this Hash. | 317 // Returns a new instance of this Hash. |
321 _MD5 newInstance() { | 318 _MD5 newInstance() { |
322 return new _MD5(); | 319 return new _MD5(); |
323 } | 320 } |
324 | 321 |
325 static const _k = const [ | 322 static const _k = const [ |
326 0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee, 0xf57c0faf, 0x4787c62a, | 323 0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee, 0xf57c0faf, 0x4787c62a, // |
327 0xa8304613, 0xfd469501, 0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be, | 324 0xa8304613, 0xfd469501, 0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be, // |
328 0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821, 0xf61e2562, 0xc040b340, | 325 0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821, 0xf61e2562, 0xc040b340, // |
329 0x265e5a51, 0xe9b6c7aa, 0xd62f105d, 0x02441453, 0xd8a1e681, 0xe7d3fbc8, | 326 0x265e5a51, 0xe9b6c7aa, 0xd62f105d, 0x02441453, 0xd8a1e681, 0xe7d3fbc8, // |
330 0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed, 0xa9e3e905, 0xfcefa3f8, | 327 0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed, 0xa9e3e905, 0xfcefa3f8, // |
331 0x676f02d9, 0x8d2a4c8a, 0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c, | 328 0x676f02d9, 0x8d2a4c8a, 0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c, // |
332 0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70, 0x289b7ec6, 0xeaa127fa, | 329 0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70, 0x289b7ec6, 0xeaa127fa, // |
333 0xd4ef3085, 0x04881d05, 0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665, | 330 0xd4ef3085, 0x04881d05, 0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665, // |
334 0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039, 0x655b59c3, 0x8f0ccc92, | 331 0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039, 0x655b59c3, 0x8f0ccc92, // |
335 0xffeff47d, 0x85845dd1, 0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1, | 332 0xffeff47d, 0x85845dd1, 0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1, // |
336 0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391 ]; | 333 0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391 |
| 334 ]; |
337 | 335 |
338 static const _r = const [ | 336 static const _r = const [ |
339 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 5, 9, 14, | 337 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 5, 9, 14, // |
340 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 4, 11, 16, 23, 4, 11, | 338 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 4, 11, 16, 23, 4, 11, // |
341 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 6, 10, 15, 21, 6, 10, 15, 21, 6, | 339 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 6, 10, 15, 21, 6, 10, 15, 21, 6, // |
342 10, 15, 21, 6, 10, 15, 21 ]; | 340 10, 15, 21, 6, 10, 15, 21 |
| 341 ]; |
343 | 342 |
344 // Compute one iteration of the MD5 algorithm with a chunk of | 343 // Compute one iteration of the MD5 algorithm with a chunk of |
345 // 16 32-bit pieces. | 344 // 16 32-bit pieces. |
346 void _updateHash(List<int> m) { | 345 void _updateHash(List<int> m) { |
347 assert(m.length == 16); | 346 assert(m.length == 16); |
348 | 347 |
349 var a = _h[0]; | 348 var a = _h[0]; |
350 var b = _h[1]; | 349 var b = _h[1]; |
351 var c = _h[2]; | 350 var c = _h[2]; |
352 var d = _h[3]; | 351 var d = _h[3]; |
(...skipping 12 matching lines...) Expand all Loading... |
365 t0 = b ^ c ^ d; | 364 t0 = b ^ c ^ d; |
366 t1 = ((3 * i) + 5) % 16; | 365 t1 = ((3 * i) + 5) % 16; |
367 } else { | 366 } else { |
368 t0 = c ^ (b | (~d & _MASK_32)); | 367 t0 = c ^ (b | (~d & _MASK_32)); |
369 t1 = (7 * i) % 16; | 368 t1 = (7 * i) % 16; |
370 } | 369 } |
371 | 370 |
372 var temp = d; | 371 var temp = d; |
373 d = c; | 372 d = c; |
374 c = b; | 373 c = b; |
375 b = _add32(b, _rotl32(_add32(_add32(a, t0), | 374 b = _add32( |
376 _add32(_k[i], m[t1])), | 375 b, _rotl32(_add32(_add32(a, t0), _add32(_k[i], m[t1])), _r[i])); |
377 _r[i])); | |
378 a = temp; | 376 a = temp; |
379 } | 377 } |
380 | 378 |
381 _h[0] = _add32(a, _h[0]); | 379 _h[0] = _add32(a, _h[0]); |
382 _h[1] = _add32(b, _h[1]); | 380 _h[1] = _add32(b, _h[1]); |
383 _h[2] = _add32(c, _h[2]); | 381 _h[2] = _add32(c, _h[2]); |
384 _h[3] = _add32(d, _h[3]); | 382 _h[3] = _add32(d, _h[3]); |
385 } | 383 } |
386 } | 384 } |
387 | 385 |
388 // The SHA1 hasher is used to compute an SHA1 message digest. | 386 // The SHA1 hasher is used to compute an SHA1 message digest. |
389 class _SHA1 extends _HashBase { | 387 class _SHA1 extends _HashBase { |
390 // Construct a SHA1 hasher object. | 388 // Construct a SHA1 hasher object. |
391 _SHA1() : _w = new List(80), super(16, 5, true) { | 389 _SHA1() |
| 390 : _w = new List(80), |
| 391 super(16, 5, true) { |
392 _h[0] = 0x67452301; | 392 _h[0] = 0x67452301; |
393 _h[1] = 0xEFCDAB89; | 393 _h[1] = 0xEFCDAB89; |
394 _h[2] = 0x98BADCFE; | 394 _h[2] = 0x98BADCFE; |
395 _h[3] = 0x10325476; | 395 _h[3] = 0x10325476; |
396 _h[4] = 0xC3D2E1F0; | 396 _h[4] = 0xC3D2E1F0; |
397 } | 397 } |
398 | 398 |
399 // Returns a new instance of this Hash. | 399 // Returns a new instance of this Hash. |
400 _SHA1 newInstance() { | 400 _SHA1 newInstance() { |
401 return new _SHA1(); | 401 return new _SHA1(); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 | 439 |
440 _h[0] = _add32(a, _h[0]); | 440 _h[0] = _add32(a, _h[0]); |
441 _h[1] = _add32(b, _h[1]); | 441 _h[1] = _add32(b, _h[1]); |
442 _h[2] = _add32(c, _h[2]); | 442 _h[2] = _add32(c, _h[2]); |
443 _h[3] = _add32(d, _h[3]); | 443 _h[3] = _add32(d, _h[3]); |
444 _h[4] = _add32(e, _h[4]); | 444 _h[4] = _add32(e, _h[4]); |
445 } | 445 } |
446 | 446 |
447 List<int> _w; | 447 List<int> _w; |
448 } | 448 } |
OLD | NEW |