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 import 'dart:convert'; | 5 import 'dart:convert'; |
6 import 'dart:typed_data'; | 6 import 'dart:typed_data'; |
7 | 7 |
8 import 'digest.dart'; | 8 import 'digest.dart'; |
9 import 'hash.dart'; | 9 import 'hash.dart'; |
10 import 'hash_sink.dart'; | 10 import 'hash_sink.dart'; |
11 import 'utils.dart'; | 11 import 'utils.dart'; |
12 | 12 |
13 /// An instance of [Sha1]. | 13 /// An instance of [Sha1]. |
14 /// | 14 /// |
15 /// This instance provides convenient access to the [SHA-1][rfc] hash function. | 15 /// This instance provides convenient access to the [SHA-1][rfc] hash function. |
16 /// | 16 /// |
17 /// [rfc]: http://tools.ietf.org/html/rfc3174 | 17 /// [rfc]: http://tools.ietf.org/html/rfc3174 |
18 final sha1 = new Sha1._(); | 18 final sha1 = new Sha1._(); |
19 | 19 |
20 /// An implementation of the [SHA-1][rfc] hash function. | 20 /// An implementation of the [SHA-1][rfc] hash function. |
21 /// | 21 /// |
22 /// [rfc]: http://tools.ietf.org/html/rfc3174 | 22 /// [rfc]: http://tools.ietf.org/html/rfc3174 |
23 class Sha1 extends Hash { | 23 class Sha1 extends Hash { |
24 final int blockSize = 16 * bytesPerWord; | 24 final int blockSize = 16 * bytesPerWord; |
25 | 25 |
26 Sha1._(); | 26 Sha1._(); |
27 | 27 |
28 Sha1 newInstance() => new Sha1._(); | |
29 | |
30 ByteConversionSink startChunkedConversion(Sink<Digest> sink) => | 28 ByteConversionSink startChunkedConversion(Sink<Digest> sink) => |
31 new ByteConversionSink.from(new _Sha1Sink(sink)); | 29 new ByteConversionSink.from(new _Sha1Sink(sink)); |
32 } | 30 } |
33 | 31 |
34 /// This class is deprecated. | |
35 /// | |
36 /// Use [sha1] instead. | |
37 @Deprecated("Will be removed in crypto 1.0.0.") | |
38 class SHA1 extends Sha1 { | |
39 SHA1() : super._(); | |
40 | |
41 SHA1 newInstance() => new SHA1(); | |
42 } | |
43 | |
44 /// The concrete implementation of [Sha1]. | 32 /// The concrete implementation of [Sha1]. |
45 /// | 33 /// |
46 /// This is separate so that it can extend [HashBase] without leaking additional | 34 /// This is separate so that it can extend [HashBase] without leaking additional |
47 /// public memebers. | 35 /// public memebers. |
48 class _Sha1Sink extends HashSink { | 36 class _Sha1Sink extends HashSink { |
49 final digest = new Uint32List(5); | 37 final digest = new Uint32List(5); |
50 | 38 |
51 /// The sixteen words from the original chunk, extended to 80 words. | 39 /// The sixteen words from the original chunk, extended to 80 words. |
52 /// | 40 /// |
53 /// This is an instance variable to avoid re-allocating, but its data isn't | 41 /// This is an instance variable to avoid re-allocating, but its data isn't |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 a = newA & mask32; | 89 a = newA & mask32; |
102 } | 90 } |
103 | 91 |
104 digest[0] = add32(a, digest[0]); | 92 digest[0] = add32(a, digest[0]); |
105 digest[1] = add32(b, digest[1]); | 93 digest[1] = add32(b, digest[1]); |
106 digest[2] = add32(c, digest[2]); | 94 digest[2] = add32(c, digest[2]); |
107 digest[3] = add32(d, digest[3]); | 95 digest[3] = add32(d, digest[3]); |
108 digest[4] = add32(e, digest[4]); | 96 digest[4] = add32(e, digest[4]); |
109 } | 97 } |
110 } | 98 } |
OLD | NEW |