Change maximum message width to 3ffff...ff (#52)
* Change max message length.
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 10f2921..3e279ea 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,8 @@
+## 2.0.5
+
+* Changed the max message size instead to 0x3ffffffffffff, which is the largest
+ portable value for both JS and the Dart VM.
+
## 2.0.4
* Made max message size a BigNum instead of an int so that dart2js can compile
diff --git a/lib/src/hash_sink.dart b/lib/src/hash_sink.dart
index 592dd22..fde6b08 100644
--- a/lib/src/hash_sink.dart
+++ b/lib/src/hash_sink.dart
@@ -26,6 +26,11 @@
/// used across invocations of [_iterate].
final Uint32List _currentChunk;
+ /// Messages with more than 2^53-1 bits are not supported. (This is the
+ /// largest value that is representable on both JS and the Dart VM.)
+ /// So the maximum length in bytes is (2^53-1)/8.
+ static const _maxMessageLengthInBytes = 0x0003ffffffffffff;
+
/// The length of the input data so far, in bytes.
int _lengthInBytes = 0;
@@ -121,12 +126,9 @@
_pendingData.add(0);
}
- if (new BigInt.from(_lengthInBytes) >
- (new BigInt.from(2).pow(64) - BigInt.one)) {
- // Messages with more than 2^64-1 bits are not supported.
- // So the maximum length in bytes is (2^64-1)/8.
+ if (_lengthInBytes > _maxMessageLengthInBytes) {
throw new UnsupportedError(
- 'Hashing is unsupported for messages with more than 2^64 bits.');
+ 'Hashing is unsupported for messages with more than 2^53 bits.');
}
var lengthInBits = _lengthInBytes * bitsPerByte;
diff --git a/pubspec.yaml b/pubspec.yaml
index 085f972..ff8f0aa 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,5 +1,5 @@
name: crypto
-version: 2.0.4
+version: 2.0.5
author: Dart Team <misc@dartlang.org>
description: Library of cryptographic functions.
homepage: https://www.github.com/dart-lang/crypto