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

Side by Side Diff: pkg/crypto/lib/src/sha256.dart

Issue 873273008: Convert crypto libraries to use Uint32Lists. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 5 years, 11 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
« no previous file with comments | « pkg/crypto/lib/src/sha1.dart ('k') | no next file » | 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 part of crypto; 5 part of crypto;
6 6
7 /** 7 /**
8 * SHA256 hash function implementation. 8 * SHA256 hash function implementation.
9 */ 9 */
10 class SHA256 extends _HashBase { 10 class SHA256 extends _HashBase {
11 final List<int> _w; 11 final Uint32List _w;
12 12
13 // Construct a SHA256 hasher object. 13 // Construct a SHA256 hasher object.
14 SHA256() : _w = new List(64), super(16, 8, true) { 14 SHA256() : _w = new Uint32List(64), super(16, 8, true) {
15 // Initial value of the hash parts. First 32 bits of the fractional parts 15 // Initial value of the hash parts. First 32 bits of the fractional parts
16 // of the square roots of the first 8 prime numbers. 16 // of the square roots of the first 8 prime numbers.
17 _h[0] = 0x6a09e667; 17 _h[0] = 0x6a09e667;
18 _h[1] = 0xbb67ae85; 18 _h[1] = 0xbb67ae85;
19 _h[2] = 0x3c6ef372; 19 _h[2] = 0x3c6ef372;
20 _h[3] = 0xa54ff53a; 20 _h[3] = 0xa54ff53a;
21 _h[4] = 0x510e527f; 21 _h[4] = 0x510e527f;
22 _h[5] = 0x9b05688c; 22 _h[5] = 0x9b05688c;
23 _h[6] = 0x1f83d9ab; 23 _h[6] = 0x1f83d9ab;
24 _h[7] = 0x5be0cd19; 24 _h[7] = 0x5be0cd19;
(...skipping 25 matching lines...) Expand all
50 _rotr32(n, x) => (x >> n) | ((x << (32 - n)) & _MASK_32); 50 _rotr32(n, x) => (x >> n) | ((x << (32 - n)) & _MASK_32);
51 _ch(x, y, z) => (x & y) ^ ((~x & _MASK_32) & z); 51 _ch(x, y, z) => (x & y) ^ ((~x & _MASK_32) & z);
52 _maj(x, y, z) => (x & y) ^ (x & z) ^ (y & z); 52 _maj(x, y, z) => (x & y) ^ (x & z) ^ (y & z);
53 _bsig0(x) => _rotr32(2, x) ^ _rotr32(13, x) ^ _rotr32(22, x); 53 _bsig0(x) => _rotr32(2, x) ^ _rotr32(13, x) ^ _rotr32(22, x);
54 _bsig1(x) => _rotr32(6, x) ^ _rotr32(11, x) ^ _rotr32(25, x); 54 _bsig1(x) => _rotr32(6, x) ^ _rotr32(11, x) ^ _rotr32(25, x);
55 _ssig0(x) => _rotr32(7, x) ^ _rotr32(18, x) ^ (x >> 3); 55 _ssig0(x) => _rotr32(7, x) ^ _rotr32(18, x) ^ (x >> 3);
56 _ssig1(x) => _rotr32(17, x) ^ _rotr32(19, x) ^ (x >> 10); 56 _ssig1(x) => _rotr32(17, x) ^ _rotr32(19, x) ^ (x >> 10);
57 57
58 // Compute one iteration of the SHA256 algorithm with a chunk of 58 // Compute one iteration of the SHA256 algorithm with a chunk of
59 // 16 32-bit pieces. 59 // 16 32-bit pieces.
60 void _updateHash(List<int> M) { 60 void _updateHash(Uint32List M) {
61 assert(M.length == 16); 61 assert(M.length == 16);
62 62
63 // Prepare message schedule. 63 // Prepare message schedule.
64 var i = 0; 64 var i = 0;
65 for (; i < 16; i++) { 65 for (; i < 16; i++) {
66 _w[i] = M[i]; 66 _w[i] = M[i];
67 } 67 }
68 for (; i < 64; i++) { 68 for (; i < 64; i++) {
69 _w[i] = _add32(_add32(_ssig1(_w[i - 2]), _w[i - 7]), 69 _w[i] = _add32(_add32(_ssig1(_w[i - 2]), _w[i - 7]),
70 _add32(_ssig0(_w[i - 15]), _w[i - 16])); 70 _add32(_ssig0(_w[i - 15]), _w[i - 16]));
(...skipping 27 matching lines...) Expand all
98 _h[0] = _add32(a, _h[0]); 98 _h[0] = _add32(a, _h[0]);
99 _h[1] = _add32(b, _h[1]); 99 _h[1] = _add32(b, _h[1]);
100 _h[2] = _add32(c, _h[2]); 100 _h[2] = _add32(c, _h[2]);
101 _h[3] = _add32(d, _h[3]); 101 _h[3] = _add32(d, _h[3]);
102 _h[4] = _add32(e, _h[4]); 102 _h[4] = _add32(e, _h[4]);
103 _h[5] = _add32(f, _h[5]); 103 _h[5] = _add32(f, _h[5]);
104 _h[6] = _add32(g, _h[6]); 104 _h[6] = _add32(g, _h[6]);
105 _h[7] = _add32(h, _h[7]); 105 _h[7] = _add32(h, _h[7]);
106 } 106 }
107 } 107 }
OLDNEW
« no previous file with comments | « pkg/crypto/lib/src/sha1.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698