| 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 [SHA1][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 /// | 23 class Sha1 extends Hash { |
| 24 /// Note that it's almost always easier to use [sha1] rather than creating a new | |
| 25 /// instance. | |
| 26 class SHA1 extends Hash { | |
| 27 final int blockSize = 16 * bytesPerWord; | 24 final int blockSize = 16 * bytesPerWord; |
| 28 | 25 |
| 29 @Deprecated("Use the sha1 field instead.") | 26 Sha1._(); |
| 30 SHA1(); | 27 |
| 28 Sha1 newInstance() => new Sha1._(); |
| 29 |
| 30 ByteConversionSink startChunkedConversion(Sink<Digest> sink) => |
| 31 new ByteConversionSink.from(new _Sha1Sink(sink)); |
| 32 } |
| 33 |
| 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._(); |
| 31 | 40 |
| 32 SHA1 newInstance() => new SHA1(); | 41 SHA1 newInstance() => new SHA1(); |
| 33 | |
| 34 ByteConversionSink startChunkedConversion(Sink<Digest> sink) => | |
| 35 new ByteConversionSink.from(new _SHA1Sink(sink)); | |
| 36 } | 42 } |
| 37 | 43 |
| 38 /// The concrete implementation of [SHA1]. | 44 /// The concrete implementation of [Sha1]. |
| 39 /// | 45 /// |
| 40 /// This is separate so that it can extend [HashBase] without leaking additional | 46 /// This is separate so that it can extend [HashBase] without leaking additional |
| 41 /// public memebers. | 47 /// public memebers. |
| 42 class _SHA1Sink extends HashSink { | 48 class _Sha1Sink extends HashSink { |
| 43 final digest = new Uint32List(5); | 49 final digest = new Uint32List(5); |
| 44 | 50 |
| 45 /// The sixteen words from the original chunk, extended to 80 words. | 51 /// The sixteen words from the original chunk, extended to 80 words. |
| 46 /// | 52 /// |
| 47 /// This is an instance variable to avoid re-allocating, but its data isn't | 53 /// This is an instance variable to avoid re-allocating, but its data isn't |
| 48 /// used across invocations of [updateHash]. | 54 /// used across invocations of [updateHash]. |
| 49 final Uint32List _extended; | 55 final Uint32List _extended; |
| 50 | 56 |
| 51 _SHA1Sink(Sink<Digest> sink) | 57 _Sha1Sink(Sink<Digest> sink) |
| 52 : _extended = new Uint32List(80), | 58 : _extended = new Uint32List(80), |
| 53 super(sink, 16) { | 59 super(sink, 16) { |
| 54 digest[0] = 0x67452301; | 60 digest[0] = 0x67452301; |
| 55 digest[1] = 0xEFCDAB89; | 61 digest[1] = 0xEFCDAB89; |
| 56 digest[2] = 0x98BADCFE; | 62 digest[2] = 0x98BADCFE; |
| 57 digest[3] = 0x10325476; | 63 digest[3] = 0x10325476; |
| 58 digest[4] = 0xC3D2E1F0; | 64 digest[4] = 0xC3D2E1F0; |
| 59 } | 65 } |
| 60 | 66 |
| 61 void updateHash(Uint32List chunk) { | 67 void updateHash(Uint32List chunk) { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 a = newA & mask32; | 101 a = newA & mask32; |
| 96 } | 102 } |
| 97 | 103 |
| 98 digest[0] = add32(a, digest[0]); | 104 digest[0] = add32(a, digest[0]); |
| 99 digest[1] = add32(b, digest[1]); | 105 digest[1] = add32(b, digest[1]); |
| 100 digest[2] = add32(c, digest[2]); | 106 digest[2] = add32(c, digest[2]); |
| 101 digest[3] = add32(d, digest[3]); | 107 digest[3] = add32(d, digest[3]); |
| 102 digest[4] = add32(e, digest[4]); | 108 digest[4] = add32(e, digest[4]); |
| 103 } | 109 } |
| 104 } | 110 } |
| OLD | NEW |