Mercurial > dropbear
comparison sha384.c @ 20:b939f2d4431e libtomcrypt
Include files accidentally zeroed when merging 0.96 release
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Tue, 15 Jun 2004 16:47:55 +0000 |
parents | 09ab3354aa21 |
children | 7ed585a2c53b |
comparison
equal
deleted
inserted
replaced
18:712dd6dfb0eb | 20:b939f2d4431e |
---|---|
1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis | |
2 * | |
3 * LibTomCrypt is a library that provides various cryptographic | |
4 * algorithms in a highly modular and flexible manner. | |
5 * | |
6 * The library is free for all purposes without any express | |
7 * guarantee it works. | |
8 * | |
9 * Tom St Denis, [email protected], http://libtomcrypt.org | |
10 */ | |
11 | |
12 /* included in sha512.c */ | |
13 | |
14 const struct _hash_descriptor sha384_desc = | |
15 { | |
16 "sha384", | |
17 4, | |
18 48, | |
19 128, | |
20 | |
21 /* DER identifier */ | |
22 { 0x30, 0x41, 0x30, 0x0D, 0x06, 0x09, 0x60, 0x86, | |
23 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x02, 0x05, | |
24 0x00, 0x04, 0x30 }, | |
25 19, | |
26 | |
27 &sha384_init, | |
28 &sha512_process, | |
29 &sha384_done, | |
30 &sha384_test | |
31 }; | |
32 | |
33 void sha384_init(hash_state * md) | |
34 { | |
35 _ARGCHK(md != NULL); | |
36 | |
37 md->sha512.curlen = 0; | |
38 md->sha512.length = 0; | |
39 md->sha512.state[0] = CONST64(0xcbbb9d5dc1059ed8); | |
40 md->sha512.state[1] = CONST64(0x629a292a367cd507); | |
41 md->sha512.state[2] = CONST64(0x9159015a3070dd17); | |
42 md->sha512.state[3] = CONST64(0x152fecd8f70e5939); | |
43 md->sha512.state[4] = CONST64(0x67332667ffc00b31); | |
44 md->sha512.state[5] = CONST64(0x8eb44a8768581511); | |
45 md->sha512.state[6] = CONST64(0xdb0c2e0d64f98fa7); | |
46 md->sha512.state[7] = CONST64(0x47b5481dbefa4fa4); | |
47 } | |
48 | |
49 int sha384_done(hash_state * md, unsigned char *hash) | |
50 { | |
51 unsigned char buf[64]; | |
52 | |
53 _ARGCHK(md != NULL); | |
54 _ARGCHK(hash != NULL); | |
55 | |
56 if (md->sha512.curlen >= sizeof(md->sha512.buf)) { | |
57 return CRYPT_INVALID_ARG; | |
58 } | |
59 | |
60 sha512_done(md, buf); | |
61 memcpy(hash, buf, 48); | |
62 #ifdef CLEAN_STACK | |
63 zeromem(buf, sizeof(buf)); | |
64 #endif | |
65 return CRYPT_OK; | |
66 } | |
67 | |
68 int sha384_test(void) | |
69 { | |
70 #ifndef LTC_TEST | |
71 return CRYPT_NOP; | |
72 #else | |
73 static const struct { | |
74 char *msg; | |
75 unsigned char hash[48]; | |
76 } tests[] = { | |
77 { "abc", | |
78 { 0xcb, 0x00, 0x75, 0x3f, 0x45, 0xa3, 0x5e, 0x8b, | |
79 0xb5, 0xa0, 0x3d, 0x69, 0x9a, 0xc6, 0x50, 0x07, | |
80 0x27, 0x2c, 0x32, 0xab, 0x0e, 0xde, 0xd1, 0x63, | |
81 0x1a, 0x8b, 0x60, 0x5a, 0x43, 0xff, 0x5b, 0xed, | |
82 0x80, 0x86, 0x07, 0x2b, 0xa1, 0xe7, 0xcc, 0x23, | |
83 0x58, 0xba, 0xec, 0xa1, 0x34, 0xc8, 0x25, 0xa7 } | |
84 }, | |
85 { "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu", | |
86 { 0x09, 0x33, 0x0c, 0x33, 0xf7, 0x11, 0x47, 0xe8, | |
87 0x3d, 0x19, 0x2f, 0xc7, 0x82, 0xcd, 0x1b, 0x47, | |
88 0x53, 0x11, 0x1b, 0x17, 0x3b, 0x3b, 0x05, 0xd2, | |
89 0x2f, 0xa0, 0x80, 0x86, 0xe3, 0xb0, 0xf7, 0x12, | |
90 0xfc, 0xc7, 0xc7, 0x1a, 0x55, 0x7e, 0x2d, 0xb9, | |
91 0x66, 0xc3, 0xe9, 0xfa, 0x91, 0x74, 0x60, 0x39 } | |
92 }, | |
93 }; | |
94 | |
95 int i; | |
96 unsigned char tmp[48]; | |
97 hash_state md; | |
98 | |
99 for (i = 0; i < (int)(sizeof(tests) / sizeof(tests[0])); i++) { | |
100 sha384_init(&md); | |
101 sha384_process(&md, (unsigned char*)tests[i].msg, (unsigned long)strlen(tests[i].msg)); | |
102 sha384_done(&md, tmp); | |
103 if (memcmp(tmp, tests[i].hash, 48) != 0) { | |
104 return CRYPT_FAIL_TESTVECTOR; | |
105 } | |
106 } | |
107 return CRYPT_OK; | |
108 #endif | |
109 } | |
110 | |
111 | |
112 | |
113 | |
114 |