# BRCM_VERSION=3
[bcm963xx.git] / userapps / opensource / sshd / libtomcrypt / sha384.c
1 /* included in sha512.c */
2
3 const struct _hash_descriptor sha384_desc =
4 {
5     "sha384",
6     4,
7     48,
8     128,
9     &sha384_init,
10     &sha384_process,
11     &sha384_done,
12     &sha384_test
13 };
14
15 void sha384_init(hash_state * md)
16 {
17     _ARGCHK(md != NULL);
18
19     md->sha512.curlen = 0;
20     md->sha512.length = 0;
21     md->sha512.state[0] = CONST64(0xcbbb9d5dc1059ed8);
22     md->sha512.state[1] = CONST64(0x629a292a367cd507);
23     md->sha512.state[2] = CONST64(0x9159015a3070dd17);
24     md->sha512.state[3] = CONST64(0x152fecd8f70e5939);
25     md->sha512.state[4] = CONST64(0x67332667ffc00b31);
26     md->sha512.state[5] = CONST64(0x8eb44a8768581511);
27     md->sha512.state[6] = CONST64(0xdb0c2e0d64f98fa7);
28     md->sha512.state[7] = CONST64(0x47b5481dbefa4fa4);
29 }
30
31 void sha384_process(hash_state * md, const unsigned char *buf, unsigned long len)
32 {
33    _ARGCHK(md != NULL);
34    _ARGCHK(buf != NULL);
35    sha512_process(md, buf, len);
36 }
37
38 void sha384_done(hash_state * md, unsigned char *hash)
39 {
40    unsigned char buf[64];
41
42    _ARGCHK(md != NULL);
43    _ARGCHK(hash != NULL);
44
45    sha512_done(md, buf);
46    memcpy(hash, buf, 48);
47 #ifdef CLEAN_STACK
48    zeromem(buf, sizeof(buf));
49 #endif
50 }
51
52 int  sha384_test(void)
53 {
54  #ifndef LTC_TEST
55     return CRYPT_NOP;
56  #else    
57   static const struct {
58       char *msg;
59       unsigned char hash[48];
60   } tests[] = {
61     { "abc",
62       { 0xcb, 0x00, 0x75, 0x3f, 0x45, 0xa3, 0x5e, 0x8b,
63         0xb5, 0xa0, 0x3d, 0x69, 0x9a, 0xc6, 0x50, 0x07,
64         0x27, 0x2c, 0x32, 0xab, 0x0e, 0xde, 0xd1, 0x63,
65         0x1a, 0x8b, 0x60, 0x5a, 0x43, 0xff, 0x5b, 0xed,
66         0x80, 0x86, 0x07, 0x2b, 0xa1, 0xe7, 0xcc, 0x23,
67         0x58, 0xba, 0xec, 0xa1, 0x34, 0xc8, 0x25, 0xa7 }
68     },
69     { "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu",
70       { 0x09, 0x33, 0x0c, 0x33, 0xf7, 0x11, 0x47, 0xe8,
71         0x3d, 0x19, 0x2f, 0xc7, 0x82, 0xcd, 0x1b, 0x47,
72         0x53, 0x11, 0x1b, 0x17, 0x3b, 0x3b, 0x05, 0xd2,
73         0x2f, 0xa0, 0x80, 0x86, 0xe3, 0xb0, 0xf7, 0x12,
74         0xfc, 0xc7, 0xc7, 0x1a, 0x55, 0x7e, 0x2d, 0xb9,
75         0x66, 0xc3, 0xe9, 0xfa, 0x91, 0x74, 0x60, 0x39 }
76     },
77   };
78
79   int i;
80   unsigned char tmp[48];
81   hash_state md;
82
83   for (i = 0; i < (int)(sizeof(tests) / sizeof(tests[0])); i++) {
84       sha384_init(&md);
85       sha384_process(&md, (unsigned char*)tests[i].msg, (unsigned long)strlen(tests[i].msg));
86       sha384_done(&md, tmp);
87       if (memcmp(tmp, tests[i].hash, 48) != 0) {
88          return CRYPT_FAIL_TESTVECTOR;
89       }
90   }
91   return CRYPT_OK;
92  #endif
93 }
94
95
96
97
98