Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(278)

Unified Diff: lib/src/sha1.dart

Issue 1349373002: Improve the style of code in lib/. (Closed) Base URL: git@github.com:dart-lang/crypto.git@master
Patch Set: Code review changes Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/src/md5.dart ('k') | lib/src/sha256.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/sha1.dart
diff --git a/lib/src/sha1.dart b/lib/src/sha1.dart
index 7041a6ff75c9d8f50c4641fdc41b269fafc2e4d2..098b0a841725ebf53411a2117ae247eaaba101d5 100644
--- a/lib/src/sha1.dart
+++ b/lib/src/sha1.dart
@@ -24,64 +24,67 @@ abstract class SHA1 implements Hash {
/// This is separate so that it can extend [HashBase] without leaking additional
/// public memebers.
class _SHA1 extends HashBase implements SHA1 {
+ final digest = new Uint32List(5);
+
/// The sixteen words from the original chunk, extended to 80 words.
///
/// This is an instance variable to avoid re-allocating, but its data isn't
/// used across invocations of [updateHash].
- final Uint32List _w;
+ final Uint32List _extended;
_SHA1()
- : _w = new Uint32List(80),
- super(16, 5, true) {
- h[0] = 0x67452301;
- h[1] = 0xEFCDAB89;
- h[2] = 0x98BADCFE;
- h[3] = 0x10325476;
- h[4] = 0xC3D2E1F0;
+ : _extended = new Uint32List(80),
+ super(16) {
+ digest[0] = 0x67452301;
+ digest[1] = 0xEFCDAB89;
+ digest[2] = 0x98BADCFE;
+ digest[3] = 0x10325476;
+ digest[4] = 0xC3D2E1F0;
}
- SHA1 newInstance() {
- return new _SHA1();
- }
+ SHA1 newInstance() => new _SHA1();
- void updateHash(Uint32List m) {
- assert(m.length == 16);
+ void updateHash(Uint32List chunk) {
+ assert(chunk.length == 16);
- var a = h[0];
- var b = h[1];
- var c = h[2];
- var d = h[3];
- var e = h[4];
+ var a = digest[0];
+ var b = digest[1];
+ var c = digest[2];
+ var d = digest[3];
+ var e = digest[4];
for (var i = 0; i < 80; i++) {
if (i < 16) {
- _w[i] = m[i];
+ _extended[i] = chunk[i];
} else {
- var n = _w[i - 3] ^ _w[i - 8] ^ _w[i - 14] ^ _w[i - 16];
- _w[i] = rotl32(n, 1);
+ _extended[i] = rotl32(
+ _extended[i - 3] ^ _extended[i - 8] ^ _extended[i - 14] ^
+ _extended[i - 16],
+ 1);
}
- var t = add32(add32(rotl32(a, 5), e), _w[i]);
+
+ var newA = add32(add32(rotl32(a, 5), e), _extended[i]);
if (i < 20) {
- t = add32(add32(t, (b & c) | (~b & d)), 0x5A827999);
+ newA = add32(add32(newA, (b & c) | (~b & d)), 0x5A827999);
} else if (i < 40) {
- t = add32(add32(t, (b ^ c ^ d)), 0x6ED9EBA1);
+ newA = add32(add32(newA, (b ^ c ^ d)), 0x6ED9EBA1);
} else if (i < 60) {
- t = add32(add32(t, (b & c) | (b & d) | (c & d)), 0x8F1BBCDC);
+ newA = add32(add32(newA, (b & c) | (b & d) | (c & d)), 0x8F1BBCDC);
} else {
- t = add32(add32(t, b ^ c ^ d), 0xCA62C1D6);
+ newA = add32(add32(newA, b ^ c ^ d), 0xCA62C1D6);
}
e = d;
d = c;
c = rotl32(b, 30);
b = a;
- a = t & MASK_32;
+ a = newA & mask32;
}
- 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]);
+ digest[0] = add32(a, digest[0]);
+ digest[1] = add32(b, digest[1]);
+ digest[2] = add32(c, digest[2]);
+ digest[3] = add32(d, digest[3]);
+ digest[4] = add32(e, digest[4]);
}
}
« no previous file with comments | « lib/src/md5.dart ('k') | lib/src/sha256.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698