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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library crypto.hash_base; 5 library crypto.hash_base;
6 6
7 import 'dart:math' as math; 7 import 'dart:math' as math;
8 import 'dart:typed_data'; 8 import 'dart:typed_data';
9 9
10 import 'hash.dart'; 10 import 'hash.dart';
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 void _finalizeData() { 118 void _finalizeData() {
119 _pendingData.add(0x80); 119 _pendingData.add(0x80);
120 var contentsLength = _lengthInBytes + 9; 120 var contentsLength = _lengthInBytes + 9;
121 var chunkSizeInBytes = _chunkSizeInWords * BYTES_PER_WORD; 121 var chunkSizeInBytes = _chunkSizeInWords * BYTES_PER_WORD;
122 var finalizedLength = roundUp(contentsLength, chunkSizeInBytes); 122 var finalizedLength = roundUp(contentsLength, chunkSizeInBytes);
123 var zeroPadding = finalizedLength - contentsLength; 123 var zeroPadding = finalizedLength - contentsLength;
124 for (var i = 0; i < zeroPadding; i++) { 124 for (var i = 0; i < zeroPadding; i++) {
125 _pendingData.add(0); 125 _pendingData.add(0);
126 } 126 }
127 var lengthInBits = _lengthInBytes * BITS_PER_BYTE; 127 var lengthInBits = _lengthInBytes * BITS_PER_BYTE;
128 assert(lengthInBits < math.pow(2, 32)); 128 const MAX_UINT64 = 0xFFFFFFFFFFFFFFFF;
129 if (lengthInBits > MAX_UINT64) {
130 throw new UnsupportedError(
131 "Hash undefined for message bit lengths larger than 64 bits");
132 }
129 if (_bigEndianWords) { 133 if (_bigEndianWords) {
130 _pendingData.addAll(_wordToBytes(0)); 134 _pendingData.addAll(_wordToBytes((lengthInBits >> 32) & MASK_32));
131 _pendingData.addAll(_wordToBytes(lengthInBits & MASK_32)); 135 _pendingData.addAll(_wordToBytes(lengthInBits & MASK_32));
132 } else { 136 } else {
133 _pendingData.addAll(_wordToBytes(lengthInBits & MASK_32)); 137 _pendingData.addAll(_wordToBytes(lengthInBits & MASK_32));
134 _pendingData.addAll(_wordToBytes(0)); 138 _pendingData.addAll(_wordToBytes((lengthInBits >> 32) & MASK_32));
135 } 139 }
136 } 140 }
137 } 141 }
OLDNEW
« 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