2 * SHA-384 hash implementation and interface functions
3 * Copyright (c) 2015, Pali Rohár <pali.rohar@gmail.com>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
17 * sha384_vector - SHA384 hash for data vector
18 * @num_elem: Number of elements in the data vector
19 * @addr: Pointers to the data areas
20 * @len: Lengths of the data blocks
21 * @mac: Buffer for the hash
22 * Returns: 0 on success, -1 of failure
24 int sha384_vector(size_t num_elem, const u8 *addr[], const size_t *len,
27 struct sha384_state ctx;
31 for (i = 0; i < num_elem; i++)
32 if (sha384_process(&ctx, addr[i], len[i]))
34 if (sha384_done(&ctx, mac))
40 /* ===== start - public domain SHA384 implementation ===== */
42 /* This is based on SHA384 implementation in LibTomCrypt that was released into
43 * public domain by Tom St Denis. */
45 #define CONST64(n) n ## ULL
48 Initialize the hash state
49 @param md The hash state you wish to initialize
50 @return CRYPT_OK if successful
52 void sha384_init(struct sha384_state *md)
56 md->state[0] = CONST64(0xcbbb9d5dc1059ed8);
57 md->state[1] = CONST64(0x629a292a367cd507);
58 md->state[2] = CONST64(0x9159015a3070dd17);
59 md->state[3] = CONST64(0x152fecd8f70e5939);
60 md->state[4] = CONST64(0x67332667ffc00b31);
61 md->state[5] = CONST64(0x8eb44a8768581511);
62 md->state[6] = CONST64(0xdb0c2e0d64f98fa7);
63 md->state[7] = CONST64(0x47b5481dbefa4fa4);
66 int sha384_process(struct sha384_state *md, const unsigned char *in,
69 return sha512_process(md, in, inlen);
73 Terminate the hash to get the digest
74 @param md The hash state
75 @param out [out] The destination of the hash (48 bytes)
76 @return CRYPT_OK if successful
78 int sha384_done(struct sha384_state *md, unsigned char *out)
80 unsigned char buf[64];
82 if (md->curlen >= sizeof(md->buf))
85 if (sha512_done(md, buf) != 0)
88 os_memcpy(out, buf, 48);
92 /* ===== end - public domain SHA384 implementation ===== */