| 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 // The SHA1 hasher is used to compute an SHA1 message digest. | 5 // The SHA1 hasher is used to compute an SHA1 message digest. |
| 6 class _SHA1 extends _SHAHashBase implements SHA1 { | 6 class _SHA1 extends _HashBase implements SHA1 { |
| 7 // Construct a SHA1 hasher object. | 7 // Construct a SHA1 hasher object. |
| 8 _SHA1() : _w = new List(80), super(16, 5) { | 8 _SHA1() : _w = new List(80), super(16, 5, true) { |
| 9 _h[0] = 0x67452301; | 9 _h[0] = 0x67452301; |
| 10 _h[1] = 0xEFCDAB89; | 10 _h[1] = 0xEFCDAB89; |
| 11 _h[2] = 0x98BADCFE; | 11 _h[2] = 0x98BADCFE; |
| 12 _h[3] = 0x10325476; | 12 _h[3] = 0x10325476; |
| 13 _h[4] = 0xC3D2E1F0; | 13 _h[4] = 0xC3D2E1F0; |
| 14 } | 14 } |
| 15 | 15 |
| 16 // Returns a new instance of this Hash. | 16 // Returns a new instance of this Hash. |
| 17 SHA1 newInstance() { | 17 SHA1 newInstance() { |
| 18 return new SHA1(); | 18 return new SHA1(); |
| 19 } | 19 } |
| 20 | 20 |
| 21 // Rotate left limiting to unsigned 32-bit values. | |
| 22 int _rotl32(int val, int shift) { | |
| 23 var mod_shift = shift & 31; | |
| 24 return ((val << mod_shift) & _MASK_32) | | |
| 25 ((val & _MASK_32) >> (32 - mod_shift)); | |
| 26 } | |
| 27 | |
| 28 // Compute one iteration of the SHA1 algorithm with a chunk of | 21 // Compute one iteration of the SHA1 algorithm with a chunk of |
| 29 // 16 32-bit pieces. | 22 // 16 32-bit pieces. |
| 30 void _updateHash(List<int> m) { | 23 void _updateHash(List<int> m) { |
| 31 assert(m.length == 16); | 24 assert(m.length == 16); |
| 32 | 25 |
| 33 var a = _h[0]; | 26 var a = _h[0]; |
| 34 var b = _h[1]; | 27 var b = _h[1]; |
| 35 var c = _h[2]; | 28 var c = _h[2]; |
| 36 var d = _h[3]; | 29 var d = _h[3]; |
| 37 var e = _h[4]; | 30 var e = _h[4]; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 63 | 56 |
| 64 _h[0] = _add32(a, _h[0]); | 57 _h[0] = _add32(a, _h[0]); |
| 65 _h[1] = _add32(b, _h[1]); | 58 _h[1] = _add32(b, _h[1]); |
| 66 _h[2] = _add32(c, _h[2]); | 59 _h[2] = _add32(c, _h[2]); |
| 67 _h[3] = _add32(d, _h[3]); | 60 _h[3] = _add32(d, _h[3]); |
| 68 _h[4] = _add32(e, _h[4]); | 61 _h[4] = _add32(e, _h[4]); |
| 69 } | 62 } |
| 70 | 63 |
| 71 List<int> _w; | 64 List<int> _w; |
| 72 } | 65 } |
| OLD | NEW |