Mercurial > dropbear
comparison libtomcrypt/src/hashes/sha2/sha384.c @ 1471:6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Fri, 09 Feb 2018 21:44:05 +0800 |
parents | f849a5ca2efc |
children |
comparison
equal
deleted
inserted
replaced
1470:8bba51a55704 | 1471:6dba84798cd5 |
---|---|
3 * LibTomCrypt is a library that provides various cryptographic | 3 * LibTomCrypt is a library that provides various cryptographic |
4 * algorithms in a highly modular and flexible manner. | 4 * algorithms in a highly modular and flexible manner. |
5 * | 5 * |
6 * The library is free for all purposes without any express | 6 * The library is free for all purposes without any express |
7 * guarantee it works. | 7 * guarantee it works. |
8 * | |
9 * Tom St Denis, [email protected], http://libtom.org | |
10 */ | 8 */ |
11 /** | 9 /** |
12 @param sha384.c | 10 @param sha384.c |
13 LTC_SHA384 hash included in sha512.c, Tom St Denis | 11 LTC_SHA384 hash included in sha512.c, Tom St Denis |
14 */ | 12 */ |
13 | |
14 #include "tomcrypt.h" | |
15 | |
16 #if defined(LTC_SHA384) && defined(LTC_SHA512) | |
15 | 17 |
16 const struct ltc_hash_descriptor sha384_desc = | 18 const struct ltc_hash_descriptor sha384_desc = |
17 { | 19 { |
18 "sha384", | 20 "sha384", |
19 4, | 21 4, |
79 } | 81 } |
80 | 82 |
81 /** | 83 /** |
82 Self-test the hash | 84 Self-test the hash |
83 @return CRYPT_OK if successful, CRYPT_NOP if self-tests have been disabled | 85 @return CRYPT_OK if successful, CRYPT_NOP if self-tests have been disabled |
84 */ | 86 */ |
85 int sha384_test(void) | 87 int sha384_test(void) |
86 { | 88 { |
87 #ifndef LTC_TEST | 89 #ifndef LTC_TEST |
88 return CRYPT_NOP; | 90 return CRYPT_NOP; |
89 #else | 91 #else |
90 static const struct { | 92 static const struct { |
91 char *msg; | 93 const char *msg; |
92 unsigned char hash[48]; | 94 unsigned char hash[48]; |
93 } tests[] = { | 95 } tests[] = { |
94 { "abc", | 96 { "abc", |
95 { 0xcb, 0x00, 0x75, 0x3f, 0x45, 0xa3, 0x5e, 0x8b, | 97 { 0xcb, 0x00, 0x75, 0x3f, 0x45, 0xa3, 0x5e, 0x8b, |
96 0xb5, 0xa0, 0x3d, 0x69, 0x9a, 0xc6, 0x50, 0x07, | 98 0xb5, 0xa0, 0x3d, 0x69, 0x9a, 0xc6, 0x50, 0x07, |
115 | 117 |
116 for (i = 0; i < (int)(sizeof(tests) / sizeof(tests[0])); i++) { | 118 for (i = 0; i < (int)(sizeof(tests) / sizeof(tests[0])); i++) { |
117 sha384_init(&md); | 119 sha384_init(&md); |
118 sha384_process(&md, (unsigned char*)tests[i].msg, (unsigned long)strlen(tests[i].msg)); | 120 sha384_process(&md, (unsigned char*)tests[i].msg, (unsigned long)strlen(tests[i].msg)); |
119 sha384_done(&md, tmp); | 121 sha384_done(&md, tmp); |
120 if (XMEMCMP(tmp, tests[i].hash, 48) != 0) { | 122 if (compare_testvector(tmp, sizeof(tmp), tests[i].hash, sizeof(tests[i].hash), "SHA384", i)) { |
121 return CRYPT_FAIL_TESTVECTOR; | 123 return CRYPT_FAIL_TESTVECTOR; |
122 } | 124 } |
123 } | 125 } |
124 return CRYPT_OK; | 126 return CRYPT_OK; |
125 #endif | 127 #endif |
126 } | 128 } |
127 | 129 |
130 #endif /* defined(LTC_SHA384) && defined(LTC_SHA512) */ | |
128 | 131 |
129 | 132 /* ref: $Format:%D$ */ |
130 | 133 /* git commit: $Format:%H$ */ |
131 | 134 /* commit time: $Format:%ai$ */ |
132 | |
133 /* $Source$ */ | |
134 /* $Revision$ */ | |
135 /* $Date$ */ |