comparison dcrypt/crypto/hashes/SHA384.d @ 28:ad687db713a4

Further reworked the code for hash padding. Replaced all instances of 'char[]' with 'string' and removed a few 'const' modifiers as per Glenn Haecker's patch for D2 compatibility. Updated CONTRIBUTORS file.
author Thomas Dixon <reikon@reikon.us>
date Sun, 10 May 2009 22:38:48 -0400
parents 8b5eaf3c2979
children
comparison
equal deleted inserted replaced
27:8b5eaf3c2979 28:ad687db713a4
27 uint digestSize() 27 uint digestSize()
28 { 28 {
29 return 48; 29 return 48;
30 } 30 }
31 31
32 char[] name() 32 string name()
33 { 33 {
34 return "SHA384"; 34 return "SHA384";
35 } 35 }
36 36
37 ubyte[] digest() 37 ubyte[] digest()
38 { 38 {
39 padMessage(MODE_SHA); 39 padMessage(MODE_SHA);
40 ubyte[] result = new ubyte[digestSize]; 40 ubyte[] result = new ubyte[digestSize];
41 41
42 result[0..8] = ByteConverter.BigEndian.from!(ulong)(h0); 42 result[0..8] = ByteConverter.BigEndian.from!(ulong)(h0);
43 result[8..16] = ByteConverter.BigEndian.from!(ulong)(h1); 43 result[8..16] = ByteConverter.BigEndian.from!(ulong)(h1);
44 result[16..24] = ByteConverter.BigEndian.from!(ulong)(h2); 44 result[16..24] = ByteConverter.BigEndian.from!(ulong)(h2);
80 80
81 debug (UnitTest) 81 debug (UnitTest)
82 { 82 {
83 unittest 83 unittest
84 { 84 {
85 static const char[][] test_inputs = [ 85 static string[] test_inputs = [
86 "", 86 "",
87 "abc", 87 "abc",
88 "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmn"~ 88 "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmn"~
89 "hijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu", 89 "hijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu",
90 "a" 90 "a"
91 ]; 91 ];
92 92
93 static const int[] test_repeat = [ 93 static int[] test_repeat = [
94 1, 1, 1, 1000000 94 1, 1, 1, 1000000
95 ]; 95 ];
96 96
97 static const char[][] test_results = [ 97 static string[] test_results = [
98 "38b060a751ac96384cd9327eb1b1e36a21fdb71114be0743"~ 98 "38b060a751ac96384cd9327eb1b1e36a21fdb71114be0743"~
99 "4c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b", 99 "4c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b",
100 100
101 "cb00753f45a35e8bb5a03d699ac65007272c32ab0eded163"~ 101 "cb00753f45a35e8bb5a03d699ac65007272c32ab0eded163"~
102 "1a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7", 102 "1a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7",
107 "9d0e1809716474cb086e834e310a4a1ced149e9c00f24852"~ 107 "9d0e1809716474cb086e834e310a4a1ced149e9c00f24852"~
108 "7972cec5704c2a5b07b8b3dc38ecc4ebae97ddd87f3d8985" 108 "7972cec5704c2a5b07b8b3dc38ecc4ebae97ddd87f3d8985"
109 ]; 109 ];
110 110
111 SHA384 h = new SHA384(); 111 SHA384 h = new SHA384();
112 foreach (uint i, char[] input; test_inputs) 112 foreach (uint i, string input; test_inputs)
113 { 113 {
114 for (int j = 0; j < test_repeat[i]; j++) 114 for (int j = 0; j < test_repeat[i]; j++)
115 h.update(input); 115 h.update(input);
116 char[] digest = h.hexDigest(); 116 string digest = h.hexDigest();
117 assert(digest == test_results[i], 117 assert(digest == test_results[i],
118 h.name~": ("~digest~") != ("~test_results[i]~")"); 118 h.name~": ("~digest~") != ("~test_results[i]~")");
119 } 119 }
120 } 120 }
121 } 121 }