]>
git.ipfire.org Git - thirdparty/hostap.git/blob - src/crypto/sha384.c
2 * SHA-384 hash implementation and interface functions
3 * Copyright (c) 2003-2017, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
17 * hmac_sha384_vector - HMAC-SHA384 over data vector (RFC 2104)
18 * @key: Key for HMAC operations
19 * @key_len: Length of the key in bytes
20 * @num_elem: Number of elements in the data vector
21 * @addr: Pointers to the data areas
22 * @len: Lengths of the data blocks
23 * @mac: Buffer for the hash (48 bytes)
24 * Returns: 0 on success, -1 on failure
26 int hmac_sha384_vector(const u8
*key
, size_t key_len
, size_t num_elem
,
27 const u8
*addr
[], const size_t *len
, u8
*mac
)
29 unsigned char k_pad
[128]; /* padding - key XORd with ipad/opad */
36 * Fixed limit on the number of fragments to avoid having to
37 * allocate memory (which could fail).
42 /* if key is longer than 128 bytes reset it to key = SHA384(key) */
44 if (sha384_vector(1, &key
, &key_len
, tk
) < 0)
50 /* the HMAC_SHA384 transform looks like:
52 * SHA384(K XOR opad, SHA384(K XOR ipad, text))
54 * where K is an n byte key
55 * ipad is the byte 0x36 repeated 128 times
56 * opad is the byte 0x5c repeated 128 times
57 * and text is the data being protected */
59 /* start out by storing key in ipad */
60 os_memset(k_pad
, 0, sizeof(k_pad
));
61 os_memcpy(k_pad
, key
, key_len
);
62 /* XOR key with ipad values */
63 for (i
= 0; i
< 128; i
++)
66 /* perform inner SHA384 */
69 for (i
= 0; i
< num_elem
; i
++) {
70 _addr
[i
+ 1] = addr
[i
];
73 if (sha384_vector(1 + num_elem
, _addr
, _len
, mac
) < 0)
76 os_memset(k_pad
, 0, sizeof(k_pad
));
77 os_memcpy(k_pad
, key
, key_len
);
78 /* XOR key with opad values */
79 for (i
= 0; i
< 128; i
++)
82 /* perform outer SHA384 */
86 _len
[1] = SHA384_MAC_LEN
;
87 return sha384_vector(2, _addr
, _len
, mac
);
92 * hmac_sha384 - HMAC-SHA384 over data buffer (RFC 2104)
93 * @key: Key for HMAC operations
94 * @key_len: Length of the key in bytes
95 * @data: Pointers to the data area
96 * @data_len: Length of the data area
97 * @mac: Buffer for the hash (48 bytes)
98 * Returns: 0 on success, -1 on failure
100 int hmac_sha384(const u8
*key
, size_t key_len
, const u8
*data
,
101 size_t data_len
, u8
*mac
)
103 return hmac_sha384_vector(key
, key_len
, 1, &data
, &data_len
, mac
);