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

Side by Side Diff: sdk/lib/crypto/hash_utils.dart

Issue 12328104: Change new List(n) to return fixed length list. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 10 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 | Annotate | Revision Log
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 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;
11 const _BYTES_PER_WORD = 4; 11 const _BYTES_PER_WORD = 4;
12 12
13 // Helper functions used by more than one hasher. 13 // Helper functions used by more than one hasher.
14 14
15 // Rotate left limiting to unsigned 32-bit values. 15 // Rotate left limiting to unsigned 32-bit values.
16 int _rotl32(int val, int shift) { 16 int _rotl32(int val, int shift) {
17 var mod_shift = shift & 31; 17 var mod_shift = shift & 31;
18 return ((val << mod_shift) & _MASK_32) | 18 return ((val << mod_shift) & _MASK_32) |
19 ((val & _MASK_32) >> (32 - mod_shift)); 19 ((val & _MASK_32) >> (32 - mod_shift));
20 } 20 }
21 21
22 // Base class encapsulating common behavior for cryptographic hash 22 // Base class encapsulating common behavior for cryptographic hash
23 // functions. 23 // functions.
24 abstract class _HashBase implements Hash { 24 abstract class _HashBase implements Hash {
25 _HashBase(int this._chunkSizeInWords, 25 _HashBase(int this._chunkSizeInWords,
26 int this._digestSizeInWords, 26 int this._digestSizeInWords,
27 bool this._bigEndianWords) 27 bool this._bigEndianWords)
28 : _pendingData = [] { 28 : _pendingData = [] {
29 _currentChunk = new List.fixedLength(_chunkSizeInWords); 29 _currentChunk = new List(_chunkSizeInWords);
30 _h = new List.fixedLength(_digestSizeInWords); 30 _h = new List(_digestSizeInWords);
31 } 31 }
32 32
33 // Update the hasher with more data. 33 // Update the hasher with more data.
34 add(List<int> data) { 34 add(List<int> data) {
35 if (_digestCalled) { 35 if (_digestCalled) {
36 throw new HashException( 36 throw new HashException(
37 'Hash update method called after digest was retrieved'); 37 'Hash update method called after digest was retrieved');
38 } 38 }
39 _lengthInBytes += data.length; 39 _lengthInBytes += data.length;
40 _pendingData.addAll(data); 40 _pendingData.addAll(data);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 var word = (w3 & 0xff) << 24; 90 var word = (w3 & 0xff) << 24;
91 word |= (w2 & _MASK_8) << 16; 91 word |= (w2 & _MASK_8) << 16;
92 word |= (w1 & _MASK_8) << 8; 92 word |= (w1 & _MASK_8) << 8;
93 word |= (w0 & _MASK_8); 93 word |= (w0 & _MASK_8);
94 _currentChunk[wordIndex] = word; 94 _currentChunk[wordIndex] = word;
95 } 95 }
96 } 96 }
97 97
98 // Convert a 32-bit word to four bytes. 98 // Convert a 32-bit word to four bytes.
99 _wordToBytes(int word) { 99 _wordToBytes(int word) {
100 List<int> bytes = new List.fixedLength(_BYTES_PER_WORD); 100 List<int> bytes = new List(_BYTES_PER_WORD);
101 bytes[0] = (word >> (_bigEndianWords ? 24 : 0)) & _MASK_8; 101 bytes[0] = (word >> (_bigEndianWords ? 24 : 0)) & _MASK_8;
102 bytes[1] = (word >> (_bigEndianWords ? 16 : 8)) & _MASK_8; 102 bytes[1] = (word >> (_bigEndianWords ? 16 : 8)) & _MASK_8;
103 bytes[2] = (word >> (_bigEndianWords ? 8 : 16)) & _MASK_8; 103 bytes[2] = (word >> (_bigEndianWords ? 8 : 16)) & _MASK_8;
104 bytes[3] = (word >> (_bigEndianWords ? 0 : 24)) & _MASK_8; 104 bytes[3] = (word >> (_bigEndianWords ? 0 : 24)) & _MASK_8;
105 return bytes; 105 return bytes;
106 } 106 }
107 107
108 // Iterate through data updating the hash computation for each 108 // Iterate through data updating the hash computation for each
109 // chunk. 109 // chunk.
110 _iterate() { 110 _iterate() {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 // Hasher state. 146 // Hasher state.
147 final int _chunkSizeInWords; 147 final int _chunkSizeInWords;
148 final int _digestSizeInWords; 148 final int _digestSizeInWords;
149 final bool _bigEndianWords; 149 final bool _bigEndianWords;
150 int _lengthInBytes = 0; 150 int _lengthInBytes = 0;
151 List<int> _pendingData; 151 List<int> _pendingData;
152 List<int> _currentChunk; 152 List<int> _currentChunk;
153 List<int> _h; 153 List<int> _h;
154 bool _digestCalled = false; 154 bool _digestCalled = false;
155 } 155 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698