Convert crypto libraries to use Uint32Lists.
R=iposva@google.com
Review URL: https://codereview.chromium.org//873273008
git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart/pkg/crypto@43161 260f80e4-7a28-3924-810f-c04153c831b5
diff --git a/lib/crypto.dart b/lib/crypto.dart
index 5125912..892626f 100644
--- a/lib/crypto.dart
+++ b/lib/crypto.dart
@@ -9,6 +9,7 @@
library crypto;
import 'dart:math';
+import 'dart:typed_data';
part 'src/crypto_utils.dart';
part 'src/hash_utils.dart';
diff --git a/lib/src/hash_utils.dart b/lib/src/hash_utils.dart
index 1d90e69..c39ddd0 100644
--- a/lib/src/hash_utils.dart
+++ b/lib/src/hash_utils.dart
@@ -25,8 +25,8 @@
final int _chunkSizeInWords;
final int _digestSizeInWords;
final bool _bigEndianWords;
- final List<int> _currentChunk;
- final List<int> _h;
+ final Uint32List _currentChunk;
+ final Uint32List _h;
int _lengthInBytes = 0;
List<int> _pendingData;
bool _digestCalled = false;
@@ -35,8 +35,8 @@
int digestSizeInWords,
bool this._bigEndianWords)
: _pendingData = [],
- _currentChunk = new List(chunkSizeInWords),
- _h = new List(digestSizeInWords),
+ _currentChunk = new Uint32List(chunkSizeInWords),
+ _h = new Uint32List(digestSizeInWords),
_chunkSizeInWords = chunkSizeInWords,
_digestSizeInWords = digestSizeInWords;
@@ -69,7 +69,7 @@
}
// One round of the hash computation.
- void _updateHash(List<int> m);
+ void _updateHash(Uint32List m);
// Helper methods.
int _add32(x, y) => (x + y) & _MASK_32;
@@ -103,8 +103,8 @@
}
// Convert a 32-bit word to four bytes.
- List<int> _wordToBytes(int word) {
- List<int> bytes = new List(_BYTES_PER_WORD);
+ Uint32List _wordToBytes(int word) {
+ Uint32List bytes = new Uint32List(_BYTES_PER_WORD);
bytes[0] = (word >> (_bigEndianWords ? 24 : 0)) & _MASK_8;
bytes[1] = (word >> (_bigEndianWords ? 16 : 8)) & _MASK_8;
bytes[2] = (word >> (_bigEndianWords ? 8 : 16)) & _MASK_8;
diff --git a/lib/src/md5.dart b/lib/src/md5.dart
index 07b567e..54bf3be 100644
--- a/lib/src/md5.dart
+++ b/lib/src/md5.dart
@@ -44,7 +44,7 @@
// Compute one iteration of the MD5 algorithm with a chunk of
// 16 32-bit pieces.
- void _updateHash(List<int> m) {
+ void _updateHash(Uint32List m) {
assert(m.length == 16);
var a = _h[0];
diff --git a/lib/src/sha1.dart b/lib/src/sha1.dart
index 0b55b8d..6e8ea48 100644
--- a/lib/src/sha1.dart
+++ b/lib/src/sha1.dart
@@ -8,10 +8,10 @@
* SHA1 hash function implementation.
*/
class SHA1 extends _HashBase {
- final List<int> _w;
+ final Uint32List _w;
// Construct a SHA1 hasher object.
- SHA1() : _w = new List(80), super(16, 5, true) {
+ SHA1() : _w = new Uint32List(80), super(16, 5, true) {
_h[0] = 0x67452301;
_h[1] = 0xEFCDAB89;
_h[2] = 0x98BADCFE;
@@ -26,7 +26,7 @@
// Compute one iteration of the SHA1 algorithm with a chunk of
// 16 32-bit pieces.
- void _updateHash(List<int> m) {
+ void _updateHash(Uint32List m) {
assert(m.length == 16);
var a = _h[0];
diff --git a/lib/src/sha256.dart b/lib/src/sha256.dart
index 88b701e..f36561f 100644
--- a/lib/src/sha256.dart
+++ b/lib/src/sha256.dart
@@ -8,10 +8,10 @@
* SHA256 hash function implementation.
*/
class SHA256 extends _HashBase {
- final List<int> _w;
+ final Uint32List _w;
// Construct a SHA256 hasher object.
- SHA256() : _w = new List(64), super(16, 8, true) {
+ SHA256() : _w = new Uint32List(64), super(16, 8, true) {
// Initial value of the hash parts. First 32 bits of the fractional parts
// of the square roots of the first 8 prime numbers.
_h[0] = 0x6a09e667;
@@ -57,7 +57,7 @@
// Compute one iteration of the SHA256 algorithm with a chunk of
// 16 32-bit pieces.
- void _updateHash(List<int> M) {
+ void _updateHash(Uint32List M) {
assert(M.length == 16);
// Prepare message schedule.