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

Unified Diff: lib/src/sha1.dart

Issue 1350933002: Stop using parts. (Closed) Base URL: git@github.com:dart-lang/crypto.git@master
Patch Set: 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
Index: lib/src/sha1.dart
diff --git a/lib/src/sha1.dart b/lib/src/sha1.dart
index 3946484172fc54ba44fed78c0c46d53031e66f31..d05922661e1f1a3ed0c071e6f4ac4cc8240b24bd 100644
--- a/lib/src/sha1.dart
+++ b/lib/src/sha1.dart
@@ -2,70 +2,82 @@
// 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.
-part of crypto;
+library crypto.sha1;
+
+import 'dart:typed_data';
+
+import 'hash.dart';
+import 'hash_base.dart';
+import 'utils.dart';
/**
* SHA1 hash function implementation.
*/
-class SHA1 extends _HashBase {
+abstract class SHA1 implements Hash {
+ factory SHA1() = _SHA1;
+
+ SHA1 newInstance();
+}
+
+class _SHA1 extends HashBase implements SHA1 {
final Uint32List _w;
// Construct a SHA1 hasher object.
- SHA1()
+ _SHA1()
: _w = new Uint32List(80),
super(16, 5, true) {
- _h[0] = 0x67452301;
- _h[1] = 0xEFCDAB89;
- _h[2] = 0x98BADCFE;
- _h[3] = 0x10325476;
- _h[4] = 0xC3D2E1F0;
+ 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();
+ return new _SHA1();
}
// Compute one iteration of the SHA1 algorithm with a chunk of
// 16 32-bit pieces.
- void _updateHash(Uint32List m) {
+ void updateHash(Uint32List 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];
+ 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);
+ _w[i] = rotl32(n, 1);
}
- var t = _add32(_add32(_rotl32(a, 5), e), _w[i]);
+ var t = add32(add32(rotl32(a, 5), e), _w[i]);
if (i < 20) {
- t = _add32(_add32(t, (b & c) | (~b & d)), 0x5A827999);
+ t = add32(add32(t, (b & c) | (~b & d)), 0x5A827999);
} else if (i < 40) {
- t = _add32(_add32(t, (b ^ c ^ d)), 0x6ED9EBA1);
+ t = add32(add32(t, (b ^ c ^ d)), 0x6ED9EBA1);
} else if (i < 60) {
- t = _add32(_add32(t, (b & c) | (b & d) | (c & d)), 0x8F1BBCDC);
+ t = add32(add32(t, (b & c) | (b & d) | (c & d)), 0x8F1BBCDC);
} else {
- t = _add32(_add32(t, b ^ c ^ d), 0xCA62C1D6);
+ t = add32(add32(t, b ^ c ^ d), 0xCA62C1D6);
}
e = d;
d = c;
- c = _rotl32(b, 30);
+ c = rotl32(b, 30);
b = a;
- a = t & _MASK_32;
+ 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]);
+ 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]);
}
}
« lib/src/hash_base.dart ('K') | « lib/src/md5.dart ('k') | lib/src/sha256.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698