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

Unified Diff: lib/src/hash_base.dart

Issue 1349293002: Don't assume 32-bit message bit lengths. (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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/hash_base.dart
diff --git a/lib/src/hash_base.dart b/lib/src/hash_base.dart
index c325fe097b89f66ea22b0e86e64b7d584036bc3a..6cdf235ad894273e0917536755a7cd6264834ac3 100644
--- a/lib/src/hash_base.dart
+++ b/lib/src/hash_base.dart
@@ -125,13 +125,17 @@ abstract class HashBase implements Hash {
_pendingData.add(0);
}
var lengthInBits = _lengthInBytes * BITS_PER_BYTE;
- assert(lengthInBits < math.pow(2, 32));
+ const MAX_UINT64 = 0xFFFFFFFFFFFFFFFF;
+ if (lengthInBits > MAX_UINT64) {
+ throw new UnsupportedError(
+ "Hash undefined for message bit lengths larger than 64 bits");
+ }
if (_bigEndianWords) {
- _pendingData.addAll(_wordToBytes(0));
+ _pendingData.addAll(_wordToBytes((lengthInBits >> 32) & MASK_32));
_pendingData.addAll(_wordToBytes(lengthInBits & MASK_32));
} else {
_pendingData.addAll(_wordToBytes(lengthInBits & MASK_32));
- _pendingData.addAll(_wordToBytes(0));
+ _pendingData.addAll(_wordToBytes((lengthInBits >> 32) & MASK_32));
}
}
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698