0
|
1 /**
|
|
2 * This file is part of the dcrypt project.
|
|
3 *
|
|
4 * Copyright: Copyright (C) dcrypt contributors 2008. All rights reserved.
|
|
5 * License: MIT
|
|
6 * Authors: Thomas Dixon
|
|
7 */
|
|
8
|
|
9 module dcrypt.crypto.hashes.SHA384;
|
|
10
|
|
11 import dcrypt.crypto.hashes.SHA512;
|
|
12
|
|
13 /** Implementation of SHA-384. */
|
|
14 class SHA384 : SHA512 {
|
|
15 this (void[] input_=null) {
|
|
16 reset();
|
|
17 super(input_);
|
|
18 }
|
|
19
|
|
20 uint digestSize() {
|
|
21 return 48;
|
|
22 }
|
|
23
|
|
24 char[] name() {
|
|
25 return "SHA384";
|
|
26 }
|
|
27
|
|
28 ubyte[] digest() {
|
|
29 padMessage(MODE_SHA);
|
|
30 ubyte[] result = new ubyte[digestSize];
|
|
31
|
|
32 Util.ulongToUbytesBig(h0, result, 0);
|
|
33 Util.ulongToUbytesBig(h1, result, 8);
|
|
34 Util.ulongToUbytesBig(h2, result, 16);
|
|
35 Util.ulongToUbytesBig(h3, result, 24);
|
|
36 Util.ulongToUbytesBig(h4, result, 32);
|
|
37 Util.ulongToUbytesBig(h5, result, 40);
|
|
38
|
|
39 reset();
|
|
40 return result;
|
|
41 }
|
|
42
|
|
43 void reset() {
|
|
44 super.reset();
|
|
45 h0 = 0xcbbb9d5dc1059ed8u,
|
|
46 h1 = 0x629a292a367cd507u,
|
|
47 h2 = 0x9159015a3070dd17u,
|
|
48 h3 = 0x152fecd8f70e5939u,
|
|
49 h4 = 0x67332667ffc00b31u,
|
|
50 h5 = 0x8eb44a8768581511u,
|
|
51 h6 = 0xdb0c2e0d64f98fa7u,
|
|
52 h7 = 0x47b5481dbefa4fa4u;
|
|
53 }
|
|
54
|
|
55 version (UnitTest) {
|
|
56 unittest {
|
|
57 static const char[][] test_inputs = [
|
|
58 "",
|
|
59 "abc",
|
|
60 "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmn"~
|
|
61 "hijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu",
|
|
62 "a"
|
|
63 ];
|
|
64
|
|
65 static const int[] test_repeat = [
|
|
66 1, 1, 1, 1000000
|
|
67 ];
|
|
68
|
|
69 static const char[][] test_results = [
|
|
70 "38b060a751ac96384cd9327eb1b1e36a21fdb71114be0743"~
|
|
71 "4c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b",
|
|
72
|
|
73 "cb00753f45a35e8bb5a03d699ac65007272c32ab0eded163"~
|
|
74 "1a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7",
|
|
75
|
|
76 "09330c33f71147e83d192fc782cd1b4753111b173b3b05d2"~
|
|
77 "2fa08086e3b0f712fcc7c71a557e2db966c3e9fa91746039",
|
|
78
|
|
79 "9d0e1809716474cb086e834e310a4a1ced149e9c00f24852"~
|
|
80 "7972cec5704c2a5b07b8b3dc38ecc4ebae97ddd87f3d8985"
|
|
81 ];
|
|
82
|
|
83 SHA384 h = new SHA384();
|
|
84 foreach (uint i, char[] input; test_inputs) {
|
|
85 for (int j = 0; j < test_repeat[i]; j++)
|
|
86 h.update(input);
|
|
87 char[] digest = h.hexDigest();
|
|
88 assert(digest == test_results[i],
|
|
89 h.name()~": ("~digest~") != ("~test_results[i]~")");
|
|
90 }
|
|
91 }
|
|
92 }
|
|
93 }
|