| OLD | NEW |
| 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 Loading... |
| 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 } |
| OLD | NEW |