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

Side by Side Diff: lib/src/md5.dart

Issue 1350933002: Stop using parts. (Closed) Base URL: git@github.com:dart-lang/crypto.git@master
Patch Set: Created 5 years, 3 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
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 library crypto.md5;
6
7 import 'dart:typed_data';
8
9 import 'hash.dart';
10 import 'hash_base.dart';
11 import 'utils.dart';
6 12
7 /** 13 /**
8 * MD5 hash function implementation. 14 * MD5 hash function implementation.
9 * 15 *
10 * WARNING: MD5 has known collisions and should only be used when 16 * WARNING: MD5 has known collisions and should only be used when
11 * required for backwards compatibility. 17 * required for backwards compatibility.
12 */ 18 */
13 class MD5 extends _HashBase { 19 abstract class MD5 implements Hash {
14 MD5() : super(16, 4, false) { 20 factory MD5() = _MD5;
15 _h[0] = 0x67452301; 21
16 _h[1] = 0xefcdab89; 22 MD5 newInstance();
17 _h[2] = 0x98badcfe; 23 }
18 _h[3] = 0x10325476; 24
25 class _MD5 extends HashBase implements MD5 {
26 _MD5() : super(16, 4, false) {
27 h[0] = 0x67452301;
28 h[1] = 0xefcdab89;
29 h[2] = 0x98badcfe;
30 h[3] = 0x10325476;
19 } 31 }
20 32
21 // Returns a new instance of this Hash. 33 // Returns a new instance of this Hash.
22 MD5 newInstance() { 34 MD5 newInstance() {
23 return new MD5(); 35 return new _MD5();
24 } 36 }
25 37
26 static const _k = const [ 38 static const _k = const [
27 0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee, 0xf57c0faf, 0x4787c62a, 39 0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee, 0xf57c0faf, 0x4787c62a,
28 0xa8304613, 0xfd469501, 0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be, 40 0xa8304613, 0xfd469501, 0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be,
29 0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821, 0xf61e2562, 0xc040b340, 41 0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821, 0xf61e2562, 0xc040b340,
30 0x265e5a51, 0xe9b6c7aa, 0xd62f105d, 0x02441453, 0xd8a1e681, 0xe7d3fbc8, 42 0x265e5a51, 0xe9b6c7aa, 0xd62f105d, 0x02441453, 0xd8a1e681, 0xe7d3fbc8,
31 0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed, 0xa9e3e905, 0xfcefa3f8, 43 0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed, 0xa9e3e905, 0xfcefa3f8,
32 0x676f02d9, 0x8d2a4c8a, 0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c, 44 0x676f02d9, 0x8d2a4c8a, 0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c,
33 0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70, 0x289b7ec6, 0xeaa127fa, 45 0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70, 0x289b7ec6, 0xeaa127fa,
34 0xd4ef3085, 0x04881d05, 0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665, 46 0xd4ef3085, 0x04881d05, 0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665,
35 0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039, 0x655b59c3, 0x8f0ccc92, 47 0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039, 0x655b59c3, 0x8f0ccc92,
36 0xffeff47d, 0x85845dd1, 0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1, 48 0xffeff47d, 0x85845dd1, 0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1,
37 0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391 49 0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391
38 ]; 50 ];
39 51
40 static const _r = const [ 52 static const _r = const [
41 07, 12, 17, 22, 07, 12, 17, 22, 07, 12, 17, 22, 07, 12, 17, 22, 05, 09, 14, 53 07, 12, 17, 22, 07, 12, 17, 22, 07, 12, 17, 22, 07, 12, 17, 22, 05, 09, 14,
42 20, 05, 09, 14, 20, 05, 09, 14, 20, 05, 09, 14, 20, 04, 11, 16, 23, 04, 11, 54 20, 05, 09, 14, 20, 05, 09, 14, 20, 05, 09, 14, 20, 04, 11, 16, 23, 04, 11,
43 16, 23, 04, 11, 16, 23, 04, 11, 16, 23, 06, 10, 15, 21, 06, 10, 15, 21, 06, 55 16, 23, 04, 11, 16, 23, 04, 11, 16, 23, 06, 10, 15, 21, 06, 10, 15, 21, 06,
44 10, 15, 21, 06, 10, 15, 21 56 10, 15, 21, 06, 10, 15, 21
45 ]; 57 ];
46 58
47 // Compute one iteration of the MD5 algorithm with a chunk of 59 // Compute one iteration of the MD5 algorithm with a chunk of
48 // 16 32-bit pieces. 60 // 16 32-bit pieces.
49 void _updateHash(Uint32List m) { 61 void updateHash(Uint32List m) {
50 assert(m.length == 16); 62 assert(m.length == 16);
51 63
52 var a = _h[0]; 64 var a = h[0];
53 var b = _h[1]; 65 var b = h[1];
54 var c = _h[2]; 66 var c = h[2];
55 var d = _h[3]; 67 var d = h[3];
56 68
57 var t0; 69 var t0;
58 var t1; 70 var t1;
59 71
60 for (var i = 0; i < 64; i++) { 72 for (var i = 0; i < 64; i++) {
61 if (i < 16) { 73 if (i < 16) {
62 t0 = (b & c) | ((~b & _MASK_32) & d); 74 t0 = (b & c) | ((~b & MASK_32) & d);
63 t1 = i; 75 t1 = i;
64 } else if (i < 32) { 76 } else if (i < 32) {
65 t0 = (d & b) | ((~d & _MASK_32) & c); 77 t0 = (d & b) | ((~d & MASK_32) & c);
66 t1 = ((5 * i) + 1) % 16; 78 t1 = ((5 * i) + 1) % 16;
67 } else if (i < 48) { 79 } else if (i < 48) {
68 t0 = b ^ c ^ d; 80 t0 = b ^ c ^ d;
69 t1 = ((3 * i) + 5) % 16; 81 t1 = ((3 * i) + 5) % 16;
70 } else { 82 } else {
71 t0 = c ^ (b | (~d & _MASK_32)); 83 t0 = c ^ (b | (~d & MASK_32));
72 t1 = (7 * i) % 16; 84 t1 = (7 * i) % 16;
73 } 85 }
74 86
75 var temp = d; 87 var temp = d;
76 d = c; 88 d = c;
77 c = b; 89 c = b;
78 b = _add32( 90 b = add32(
79 b, _rotl32(_add32(_add32(a, t0), _add32(_k[i], m[t1])), _r[i])); 91 b, rotl32(add32(add32(a, t0), add32(_k[i], m[t1])), _r[i]));
80 a = temp; 92 a = temp;
81 } 93 }
82 94
83 _h[0] = _add32(a, _h[0]); 95 h[0] = add32(a, h[0]);
84 _h[1] = _add32(b, _h[1]); 96 h[1] = add32(b, h[1]);
85 _h[2] = _add32(c, _h[2]); 97 h[2] = add32(c, h[2]);
86 _h[3] = _add32(d, _h[3]); 98 h[3] = add32(d, h[3]);
87 } 99 }
88 } 100 }
OLDNEW
« lib/src/hash_base.dart ('K') | « lib/src/hmac.dart ('k') | lib/src/sha1.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698