Mercurial > dropbear
comparison sha224.c @ 3:7faae8f46238 libtomcrypt-orig
Branch renaming
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Mon, 31 May 2004 18:25:41 +0000 |
parents | |
children | 6362d3854bb4 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 3:7faae8f46238 |
---|---|
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 /* SHA-224 new NIST standard based off of SHA-256 truncated to 224 bits */ | |
13 const struct _hash_descriptor sha224_desc = | |
14 { | |
15 "sha224", | |
16 10, | |
17 28, | |
18 64, | |
19 &sha224_init, | |
20 &sha256_process, | |
21 &sha224_done, | |
22 &sha224_test | |
23 }; | |
24 | |
25 /* init the sha256 er... sha224 state ;-) */ | |
26 void sha224_init(hash_state * md) | |
27 { | |
28 _ARGCHK(md != NULL); | |
29 | |
30 md->sha256.curlen = 0; | |
31 md->sha256.length = 0; | |
32 md->sha256.state[0] = 0xc1059ed8UL; | |
33 md->sha256.state[1] = 0x367cd507UL; | |
34 md->sha256.state[2] = 0x3070dd17UL; | |
35 md->sha256.state[3] = 0xf70e5939UL; | |
36 md->sha256.state[4] = 0xffc00b31UL; | |
37 md->sha256.state[5] = 0x68581511UL; | |
38 md->sha256.state[6] = 0x64f98fa7UL; | |
39 md->sha256.state[7] = 0xbefa4fa4UL; | |
40 } | |
41 | |
42 int sha224_done(hash_state * md, unsigned char *hash) | |
43 { | |
44 unsigned char buf[32]; | |
45 int err; | |
46 | |
47 err = sha256_done(md, buf); | |
48 memcpy(hash, buf, 28); | |
49 #ifdef CLEAN_STACK | |
50 zeromem(buf, sizeof(buf)); | |
51 #endif | |
52 return err; | |
53 } | |
54 | |
55 int sha224_test(void) | |
56 { | |
57 #ifndef LTC_TEST | |
58 return CRYPT_NOP; | |
59 #else | |
60 static const struct { | |
61 char *msg; | |
62 unsigned char hash[28]; | |
63 } tests[] = { | |
64 { "abc", | |
65 { 0x23, 0x09, 0x7d, 0x22, 0x34, 0x05, 0xd8, | |
66 0x22, 0x86, 0x42, 0xa4, 0x77, 0xbd, 0xa2, | |
67 0x55, 0xb3, 0x2a, 0xad, 0xbc, 0xe4, 0xbd, | |
68 0xa0, 0xb3, 0xf7, 0xe3, 0x6c, 0x9d, 0xa7 } | |
69 }, | |
70 { "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", | |
71 { 0x75, 0x38, 0x8b, 0x16, 0x51, 0x27, 0x76, | |
72 0xcc, 0x5d, 0xba, 0x5d, 0xa1, 0xfd, 0x89, | |
73 0x01, 0x50, 0xb0, 0xc6, 0x45, 0x5c, 0xb4, | |
74 0xf5, 0x8b, 0x19, 0x52, 0x52, 0x25, 0x25 } | |
75 }, | |
76 }; | |
77 | |
78 int i; | |
79 unsigned char tmp[28]; | |
80 hash_state md; | |
81 | |
82 for (i = 0; i < (int)(sizeof(tests) / sizeof(tests[0])); i++) { | |
83 sha224_init(&md); | |
84 sha224_process(&md, (unsigned char*)tests[i].msg, (unsigned long)strlen(tests[i].msg)); | |
85 sha224_done(&md, tmp); | |
86 if (memcmp(tmp, tests[i].hash, 28) != 0) { | |
87 return CRYPT_FAIL_TESTVECTOR; | |
88 } | |
89 } | |
90 return CRYPT_OK; | |
91 #endif | |
92 } | |
93 |