| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 part of dart.crypto; | |
| 6 | |
| 7 // The SHA1 hasher is used to compute an SHA1 message digest. | |
| 8 class _SHA1 extends _HashBase implements SHA1 { | |
| 9 // Construct a SHA1 hasher object. | |
| 10 _SHA1() : _w = new List(80), super(16, 5, true) { | |
| 11 _h[0] = 0x67452301; | |
| 12 _h[1] = 0xEFCDAB89; | |
| 13 _h[2] = 0x98BADCFE; | |
| 14 _h[3] = 0x10325476; | |
| 15 _h[4] = 0xC3D2E1F0; | |
| 16 } | |
| 17 | |
| 18 // Returns a new instance of this Hash. | |
| 19 SHA1 newInstance() { | |
| 20 return new SHA1(); | |
| 21 } | |
| 22 | |
| 23 // Compute one iteration of the SHA1 algorithm with a chunk of | |
| 24 // 16 32-bit pieces. | |
| 25 void _updateHash(List<int> m) { | |
| 26 assert(m.length == 16); | |
| 27 | |
| 28 var a = _h[0]; | |
| 29 var b = _h[1]; | |
| 30 var c = _h[2]; | |
| 31 var d = _h[3]; | |
| 32 var e = _h[4]; | |
| 33 | |
| 34 for (var i = 0; i < 80; i++) { | |
| 35 if (i < 16) { | |
| 36 _w[i] = m[i]; | |
| 37 } else { | |
| 38 var n = _w[i - 3] ^ _w[i - 8] ^ _w[i - 14] ^ _w[i - 16]; | |
| 39 _w[i] = _rotl32(n, 1); | |
| 40 } | |
| 41 var t = _add32(_add32(_rotl32(a, 5), e), _w[i]); | |
| 42 if (i < 20) { | |
| 43 t = _add32(_add32(t, (b & c) | (~b & d)), 0x5A827999); | |
| 44 } else if (i < 40) { | |
| 45 t = _add32(_add32(t, (b ^ c ^ d)), 0x6ED9EBA1); | |
| 46 } else if (i < 60) { | |
| 47 t = _add32(_add32(t, (b & c) | (b & d) | (c & d)), 0x8F1BBCDC); | |
| 48 } else { | |
| 49 t = _add32(_add32(t, b ^ c ^ d), 0xCA62C1D6); | |
| 50 } | |
| 51 | |
| 52 e = d; | |
| 53 d = c; | |
| 54 c = _rotl32(b, 30); | |
| 55 b = a; | |
| 56 a = t & _MASK_32; | |
| 57 } | |
| 58 | |
| 59 _h[0] = _add32(a, _h[0]); | |
| 60 _h[1] = _add32(b, _h[1]); | |
| 61 _h[2] = _add32(c, _h[2]); | |
| 62 _h[3] = _add32(d, _h[3]); | |
| 63 _h[4] = _add32(e, _h[4]); | |
| 64 } | |
| 65 | |
| 66 List<int> _w; | |
| 67 } | |
| OLD | NEW |