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 part of dart.crypto; | 5 part of dart.crypto; |
6 | 6 |
7 // Constants. | 7 // Constants. |
8 const _MASK_8 = 0xff; | 8 const _MASK_8 = 0xff; |
9 const _MASK_32 = 0xffffffff; | 9 const _MASK_32 = 0xffffffff; |
10 const _BITS_PER_BYTE = 8; | 10 const _BITS_PER_BYTE = 8; |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 // chunk. | 109 // chunk. |
110 _iterate() { | 110 _iterate() { |
111 var len = _pendingData.length; | 111 var len = _pendingData.length; |
112 var chunkSizeInBytes = _chunkSizeInWords * _BYTES_PER_WORD; | 112 var chunkSizeInBytes = _chunkSizeInWords * _BYTES_PER_WORD; |
113 if (len >= chunkSizeInBytes) { | 113 if (len >= chunkSizeInBytes) { |
114 var index = 0; | 114 var index = 0; |
115 for (; (len - index) >= chunkSizeInBytes; index += chunkSizeInBytes) { | 115 for (; (len - index) >= chunkSizeInBytes; index += chunkSizeInBytes) { |
116 _bytesToChunk(_pendingData, index); | 116 _bytesToChunk(_pendingData, index); |
117 _updateHash(_currentChunk); | 117 _updateHash(_currentChunk); |
118 } | 118 } |
119 var remaining = len - index; | 119 _pendingData = _pendingData.sublist(index, len); |
120 _pendingData = _pendingData.getRange(index, remaining); | |
121 } | 120 } |
122 } | 121 } |
123 | 122 |
124 // Finalize the data. Add a 1 bit to the end of the message. Expand with | 123 // Finalize the data. Add a 1 bit to the end of the message. Expand with |
125 // 0 bits and add the length of the message. | 124 // 0 bits and add the length of the message. |
126 _finalizeData() { | 125 _finalizeData() { |
127 _pendingData.add(0x80); | 126 _pendingData.add(0x80); |
128 var contentsLength = _lengthInBytes + 9; | 127 var contentsLength = _lengthInBytes + 9; |
129 var chunkSizeInBytes = _chunkSizeInWords * _BYTES_PER_WORD; | 128 var chunkSizeInBytes = _chunkSizeInWords * _BYTES_PER_WORD; |
130 var finalizedLength = _roundUp(contentsLength, chunkSizeInBytes); | 129 var finalizedLength = _roundUp(contentsLength, chunkSizeInBytes); |
(...skipping 15 matching lines...) Expand all Loading... |
146 // Hasher state. | 145 // Hasher state. |
147 final int _chunkSizeInWords; | 146 final int _chunkSizeInWords; |
148 final int _digestSizeInWords; | 147 final int _digestSizeInWords; |
149 final bool _bigEndianWords; | 148 final bool _bigEndianWords; |
150 int _lengthInBytes = 0; | 149 int _lengthInBytes = 0; |
151 List<int> _pendingData; | 150 List<int> _pendingData; |
152 List<int> _currentChunk; | 151 List<int> _currentChunk; |
153 List<int> _h; | 152 List<int> _h; |
154 bool _digestCalled = false; | 153 bool _digestCalled = false; |
155 } | 154 } |
OLD | NEW |