Mercurial > dropbear
comparison libtomcrypt/src/hashes/sha2/sha224.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 sha224.c | 10 @param sha224.c |
13 LTC_SHA-224 new NIST standard based off of LTC_SHA-256 truncated to 224 bits (Tom St Denis) | 11 LTC_SHA-224 new NIST standard based off of LTC_SHA-256 truncated to 224 bits (Tom St Denis) |
14 */ | 12 */ |
13 | |
14 #include "tomcrypt.h" | |
15 | |
16 #if defined(LTC_SHA224) && defined(LTC_SHA256) | |
15 | 17 |
16 const struct ltc_hash_descriptor sha224_desc = | 18 const struct ltc_hash_descriptor sha224_desc = |
17 { | 19 { |
18 "sha224", | 20 "sha224", |
19 10, | 21 10, |
70 | 72 |
71 err = sha256_done(md, buf); | 73 err = sha256_done(md, buf); |
72 XMEMCPY(out, buf, 28); | 74 XMEMCPY(out, buf, 28); |
73 #ifdef LTC_CLEAN_STACK | 75 #ifdef LTC_CLEAN_STACK |
74 zeromem(buf, sizeof(buf)); | 76 zeromem(buf, sizeof(buf)); |
75 #endif | 77 #endif |
76 return err; | 78 return err; |
77 } | 79 } |
78 | 80 |
79 /** | 81 /** |
80 Self-test the hash | 82 Self-test the hash |
81 @return CRYPT_OK if successful, CRYPT_NOP if self-tests have been disabled | 83 @return CRYPT_OK if successful, CRYPT_NOP if self-tests have been disabled |
82 */ | 84 */ |
83 int sha224_test(void) | 85 int sha224_test(void) |
84 { | 86 { |
85 #ifndef LTC_TEST | 87 #ifndef LTC_TEST |
86 return CRYPT_NOP; | 88 return CRYPT_NOP; |
87 #else | 89 #else |
88 static const struct { | 90 static const struct { |
89 char *msg; | 91 const char *msg; |
90 unsigned char hash[28]; | 92 unsigned char hash[28]; |
91 } tests[] = { | 93 } tests[] = { |
92 { "abc", | 94 { "abc", |
93 { 0x23, 0x09, 0x7d, 0x22, 0x34, 0x05, 0xd8, | 95 { 0x23, 0x09, 0x7d, 0x22, 0x34, 0x05, 0xd8, |
94 0x22, 0x86, 0x42, 0xa4, 0x77, 0xbd, 0xa2, | 96 0x22, 0x86, 0x42, 0xa4, 0x77, 0xbd, 0xa2, |
109 | 111 |
110 for (i = 0; i < (int)(sizeof(tests) / sizeof(tests[0])); i++) { | 112 for (i = 0; i < (int)(sizeof(tests) / sizeof(tests[0])); i++) { |
111 sha224_init(&md); | 113 sha224_init(&md); |
112 sha224_process(&md, (unsigned char*)tests[i].msg, (unsigned long)strlen(tests[i].msg)); | 114 sha224_process(&md, (unsigned char*)tests[i].msg, (unsigned long)strlen(tests[i].msg)); |
113 sha224_done(&md, tmp); | 115 sha224_done(&md, tmp); |
114 if (XMEMCMP(tmp, tests[i].hash, 28) != 0) { | 116 if (compare_testvector(tmp, sizeof(tmp), tests[i].hash, sizeof(tests[i].hash), "SHA224", i)) { |
115 return CRYPT_FAIL_TESTVECTOR; | 117 return CRYPT_FAIL_TESTVECTOR; |
116 } | 118 } |
117 } | 119 } |
118 return CRYPT_OK; | 120 return CRYPT_OK; |
119 #endif | 121 #endif |
120 } | 122 } |
121 | 123 |
124 #endif /* defined(LTC_SHA224) && defined(LTC_SHA256) */ | |
122 | 125 |
123 /* $Source$ */ | 126 |
124 /* $Revision$ */ | 127 /* ref: $Format:%D$ */ |
125 /* $Date$ */ | 128 /* git commit: $Format:%H$ */ |
129 /* commit time: $Format:%ai$ */ |