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 library crypto.md5; | 5 library crypto.md5; |
6 | 6 |
7 import 'dart:convert'; | 7 import 'dart:convert'; |
8 import 'dart:typed_data'; | 8 import 'dart:typed_data'; |
9 | 9 |
10 import 'digest.dart'; | 10 import 'digest.dart'; |
11 import 'hash.dart'; | 11 import 'hash.dart'; |
12 import 'hash_sink.dart'; | 12 import 'hash_sink.dart'; |
13 import 'utils.dart'; | 13 import 'utils.dart'; |
14 | 14 |
15 /// An instance of [MD5]. | 15 /// An instance of [MD5]. |
16 /// | 16 /// |
17 /// This instance provides convenient access to the [MD5][rfc] hash function. | 17 /// This instance provides convenient access to the [MD5][rfc] hash function. |
18 /// | 18 /// |
19 /// [rfc]: https://tools.ietf.org/html/rfc1321 | 19 /// [rfc]: https://tools.ietf.org/html/rfc1321 |
20 /// | 20 /// |
21 /// **Warning**: MD5 has known collisions and should only be used when required | 21 /// **Warning**: MD5 has known collisions and should only be used when required |
22 /// for backwards compatibility. | 22 /// for backwards compatibility. |
23 final md5 = new MD5._(); | 23 final md5 = new MD5(); |
24 | 24 |
25 /// An implementation of the [MD5][rfc] hash function. | 25 /// An implementation of the [MD5][rfc] hash function. |
26 /// | 26 /// |
27 /// [rfc]: https://tools.ietf.org/html/rfc1321 | 27 /// [rfc]: https://tools.ietf.org/html/rfc1321 |
28 /// | 28 /// |
29 /// **Warning**: MD5 has known collisions and should only be used when required | 29 /// **Warning**: MD5 has known collisions and should only be used when required |
30 /// for backwards compatibility. | 30 /// for backwards compatibility. |
31 /// | 31 /// |
32 /// Note that it's almost always easier to use [md5] rather than creating a new | 32 /// Note that it's almost always easier to use [md5] rather than creating a new |
33 /// instance. | 33 /// instance. |
34 class MD5 extends Hash { | 34 class MD5 extends Hash { |
35 final int blockSize = 16 * bytesPerWord; | 35 final int blockSize = 16 * bytesPerWord; |
36 | 36 |
37 @Deprecated("Use the md5 field instead.") | 37 @Deprecated("Use the md5 field instead.") |
38 MD5(); | 38 MD5(); |
39 | 39 |
40 MD5 newInstance() => new MD5._(); | 40 MD5 newInstance() => new MD5(); |
41 | 41 |
42 ByteConversionSink startChunkedConversion(Sink<Digest> sink) => | 42 ByteConversionSink startChunkedConversion(Sink<Digest> sink) => |
43 new ByteConversionSink.from(new _MD5Sink(sink)); | 43 new ByteConversionSink.from(new _MD5Sink(sink)); |
44 } | 44 } |
45 | 45 |
46 /// Data from a non-linear mathematical function that functions as | 46 /// Data from a non-linear mathematical function that functions as |
47 /// reproducible noise. | 47 /// reproducible noise. |
48 const _noise = const [ | 48 const _noise = const [ |
49 0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee, 0xf57c0faf, 0x4787c62a, | 49 0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee, 0xf57c0faf, 0x4787c62a, |
50 0xa8304613, 0xfd469501, 0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be, | 50 0xa8304613, 0xfd469501, 0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be, |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 _shiftAmounts[i])); | 120 _shiftAmounts[i])); |
121 a = temp; | 121 a = temp; |
122 } | 122 } |
123 | 123 |
124 digest[0] = add32(a, digest[0]); | 124 digest[0] = add32(a, digest[0]); |
125 digest[1] = add32(b, digest[1]); | 125 digest[1] = add32(b, digest[1]); |
126 digest[2] = add32(c, digest[2]); | 126 digest[2] = add32(c, digest[2]); |
127 digest[3] = add32(d, digest[3]); | 127 digest[3] = add32(d, digest[3]); |
128 } | 128 } |
129 } | 129 } |
OLD | NEW |