7a29f7b569
It might be nicer to leave it out because we do not want to encourage its use. On the other hand, there are multiple places where md5 hashing is used so making it available seems like the right thing to do. R=sgjesse@google.com,benl@google.com BUG= TEST= Review URL: https://chromiumcodereview.appspot.com//10351008 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@7406 260f80e4-7a28-3924-810f-c04153c831b5
66 lines
1.6 KiB
Dart
66 lines
1.6 KiB
Dart
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
// The SHA1 hasher is used to compute an SHA1 message digest.
|
|
class _SHA1 extends _HashBase implements SHA1 {
|
|
// Construct a SHA1 hasher object.
|
|
_SHA1() : _w = new List(80), super(16, 5, true) {
|
|
_h[0] = 0x67452301;
|
|
_h[1] = 0xEFCDAB89;
|
|
_h[2] = 0x98BADCFE;
|
|
_h[3] = 0x10325476;
|
|
_h[4] = 0xC3D2E1F0;
|
|
}
|
|
|
|
// Returns a new instance of this Hash.
|
|
SHA1 newInstance() {
|
|
return new SHA1();
|
|
}
|
|
|
|
// Compute one iteration of the SHA1 algorithm with a chunk of
|
|
// 16 32-bit pieces.
|
|
void _updateHash(List<int> m) {
|
|
assert(m.length == 16);
|
|
|
|
var a = _h[0];
|
|
var b = _h[1];
|
|
var c = _h[2];
|
|
var d = _h[3];
|
|
var e = _h[4];
|
|
|
|
for (var i = 0; i < 80; i++) {
|
|
if (i < 16) {
|
|
_w[i] = m[i];
|
|
} else {
|
|
var n = _w[i - 3] ^ _w[i - 8] ^ _w[i - 14] ^ _w[i - 16];
|
|
_w[i] = _rotl32(n, 1);
|
|
}
|
|
var t = _rotl32(a, 5) + e + _w[i];
|
|
if (i < 20) {
|
|
t = t + ((b & c) | (~b & d)) + 0x5A827999;
|
|
} else if (i < 40) {
|
|
t = t + (b ^ c ^ d) + 0x6ED9EBA1;
|
|
} else if (i < 60) {
|
|
t = t + ((b & c) | (b & d) | (c & d)) + 0x8F1BBCDC;
|
|
} else {
|
|
t = t + (b ^ c ^ d) + 0xCA62C1D6;
|
|
}
|
|
|
|
e = d;
|
|
d = c;
|
|
c = _rotl32(b, 30);
|
|
b = a;
|
|
a = t & _MASK_32;
|
|
}
|
|
|
|
_h[0] = _add32(a, _h[0]);
|
|
_h[1] = _add32(b, _h[1]);
|
|
_h[2] = _add32(c, _h[2]);
|
|
_h[3] = _add32(d, _h[3]);
|
|
_h[4] = _add32(e, _h[4]);
|
|
}
|
|
|
|
List<int> _w;
|
|
}
|