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

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

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

Powered by Google App Engine
This is Rietveld 408576698