Mercurial > dropbear
comparison sha384.c @ 0:d7da3b1e1540 libtomcrypt
put back the 0.95 makefile which was inadvertently merged over
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Mon, 31 May 2004 18:21:40 +0000 |
parents | |
children | 6362d3854bb4 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:d7da3b1e1540 |
---|---|
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 &sha384_init, | |
21 &sha512_process, | |
22 &sha384_done, | |
23 &sha384_test | |
24 }; | |
25 | |
26 void sha384_init(hash_state * md) | |
27 { | |
28 _ARGCHK(md != NULL); | |
29 | |
30 md->sha512.curlen = 0; | |
31 md->sha512.length = 0; | |
32 md->sha512.state[0] = CONST64(0xcbbb9d5dc1059ed8); | |
33 md->sha512.state[1] = CONST64(0x629a292a367cd507); | |
34 md->sha512.state[2] = CONST64(0x9159015a3070dd17); | |
35 md->sha512.state[3] = CONST64(0x152fecd8f70e5939); | |
36 md->sha512.state[4] = CONST64(0x67332667ffc00b31); | |
37 md->sha512.state[5] = CONST64(0x8eb44a8768581511); | |
38 md->sha512.state[6] = CONST64(0xdb0c2e0d64f98fa7); | |
39 md->sha512.state[7] = CONST64(0x47b5481dbefa4fa4); | |
40 } | |
41 | |
42 int sha384_done(hash_state * md, unsigned char *hash) | |
43 { | |
44 unsigned char buf[64]; | |
45 | |
46 _ARGCHK(md != NULL); | |
47 _ARGCHK(hash != NULL); | |
48 | |
49 if (md->sha512.curlen >= sizeof(md->sha512.buf)) { | |
50 return CRYPT_INVALID_ARG; | |
51 } | |
52 | |
53 sha512_done(md, buf); | |
54 memcpy(hash, buf, 48); | |
55 #ifdef CLEAN_STACK | |
56 zeromem(buf, sizeof(buf)); | |
57 #endif | |
58 return CRYPT_OK; | |
59 } | |
60 | |
61 int sha384_test(void) | |
62 { | |
63 #ifndef LTC_TEST | |
64 return CRYPT_NOP; | |
65 #else | |
66 static const struct { | |
67 char *msg; | |
68 unsigned char hash[48]; | |
69 } tests[] = { | |
70 { "abc", | |
71 { 0xcb, 0x00, 0x75, 0x3f, 0x45, 0xa3, 0x5e, 0x8b, | |
72 0xb5, 0xa0, 0x3d, 0x69, 0x9a, 0xc6, 0x50, 0x07, | |
73 0x27, 0x2c, 0x32, 0xab, 0x0e, 0xde, 0xd1, 0x63, | |
74 0x1a, 0x8b, 0x60, 0x5a, 0x43, 0xff, 0x5b, 0xed, | |
75 0x80, 0x86, 0x07, 0x2b, 0xa1, 0xe7, 0xcc, 0x23, | |
76 0x58, 0xba, 0xec, 0xa1, 0x34, 0xc8, 0x25, 0xa7 } | |
77 }, | |
78 { "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu", | |
79 { 0x09, 0x33, 0x0c, 0x33, 0xf7, 0x11, 0x47, 0xe8, | |
80 0x3d, 0x19, 0x2f, 0xc7, 0x82, 0xcd, 0x1b, 0x47, | |
81 0x53, 0x11, 0x1b, 0x17, 0x3b, 0x3b, 0x05, 0xd2, | |
82 0x2f, 0xa0, 0x80, 0x86, 0xe3, 0xb0, 0xf7, 0x12, | |
83 0xfc, 0xc7, 0xc7, 0x1a, 0x55, 0x7e, 0x2d, 0xb9, | |
84 0x66, 0xc3, 0xe9, 0xfa, 0x91, 0x74, 0x60, 0x39 } | |
85 }, | |
86 }; | |
87 | |
88 int i; | |
89 unsigned char tmp[48]; | |
90 hash_state md; | |
91 | |
92 for (i = 0; i < (int)(sizeof(tests) / sizeof(tests[0])); i++) { | |
93 sha384_init(&md); | |
94 sha384_process(&md, (unsigned char*)tests[i].msg, (unsigned long)strlen(tests[i].msg)); | |
95 sha384_done(&md, tmp); | |
96 if (memcmp(tmp, tests[i].hash, 48) != 0) { | |
97 return CRYPT_FAIL_TESTVECTOR; | |
98 } | |
99 } | |
100 return CRYPT_OK; | |
101 #endif | |
102 } | |
103 | |
104 | |
105 | |
106 | |
107 |