Skip to content
This repository has been archived by the owner on Oct 17, 2024. It is now read-only.

Commit

Permalink
Change maximum message width to 3ffff...ff (#52)
Browse files Browse the repository at this point in the history
* Change max message length.
  • Loading branch information
efortuna authored Jun 7, 2018
1 parent c714b42 commit 01b9190
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
12 changes: 7 additions & 5 deletions lib/src/hash_sink.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ abstract class HashSink implements Sink<List<int>> {
/// 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;

Expand Down Expand Up @@ -121,12 +126,9 @@ abstract class HashSink implements Sink<List<int>> {
_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;
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: crypto
version: 2.0.4
version: 2.0.5
author: Dart Team <[email protected]>
description: Library of cryptographic functions.
homepage: https://www.github.com/dart-lang/crypto
Expand Down

0 comments on commit 01b9190

Please sign in to comment.