annotate sha384.c @ 144:7ed585a2c53b libtomcrypt

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