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

Side by Side Diff: lib/crypto/sha1.dart

Issue 10170027: Implement HMAC support in lib/crypto. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 8 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 // The SHA1 hasher is used to compute an SHA1 message digest. 5 // The SHA1 hasher is used to compute an SHA1 message digest.
6 class _SHA1 extends _SHACryptoHashBase implements SHA1 { 6 class _SHA1 extends _SHACryptoHashBase implements SHA1 {
7 // Construct a SHA1 hasher object. 7 // Construct a SHA1 hasher object.
8 _SHA1() : _w = new List(80), super(16, 5) { 8 _SHA1() : _w = new List(80), super(16, 5) {
9 // Initial value of the hash parts. First 32 bits of the fractional parts
10 // of the square roots of the first 8 prime numbers.
11 _h[0] = 0x67452301; 9 _h[0] = 0x67452301;
12 _h[1] = 0xEFCDAB89; 10 _h[1] = 0xEFCDAB89;
13 _h[2] = 0x98BADCFE; 11 _h[2] = 0x98BADCFE;
14 _h[3] = 0x10325476; 12 _h[3] = 0x10325476;
15 _h[4] = 0xC3D2E1F0; 13 _h[4] = 0xC3D2E1F0;
16 } 14 }
17 15
16 // Returns a new instance of this CryptoHash.
17 SHA1 newInstance() {
18 return new SHA1();
19 }
20
18 // Rotate left limiting to unsigned 32-bit values. 21 // Rotate left limiting to unsigned 32-bit values.
19 int _rotl32(int val, int shift) { 22 int _rotl32(int val, int shift) {
20 var mod_shift = shift & 31; 23 var mod_shift = shift & 31;
21 return ((val << mod_shift) & _MASK_32) | 24 return ((val << mod_shift) & _MASK_32) |
22 ((val & _MASK_32) >> (32 - mod_shift)); 25 ((val & _MASK_32) >> (32 - mod_shift));
23 } 26 }
24 27
25 // Compute one iteration of the SHA1 algorithm with a chunk of 28 // Compute one iteration of the SHA1 algorithm with a chunk of
26 // 16 32-bit pieces. 29 // 16 32-bit pieces.
27 void _updateHash(List<int> m) { 30 void _updateHash(List<int> m) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 63
61 _h[0] = _add32(a, _h[0]); 64 _h[0] = _add32(a, _h[0]);
62 _h[1] = _add32(b, _h[1]); 65 _h[1] = _add32(b, _h[1]);
63 _h[2] = _add32(c, _h[2]); 66 _h[2] = _add32(c, _h[2]);
64 _h[3] = _add32(d, _h[3]); 67 _h[3] = _add32(d, _h[3]);
65 _h[4] = _add32(e, _h[4]); 68 _h[4] = _add32(e, _h[4]);
66 } 69 }
67 70
68 List<int> _w; 71 List<int> _w;
69 } 72 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698