]>
git.ipfire.org Git - thirdparty/hostap.git/blob - src/crypto/sha1-prf.c
3 * Copyright (c) 2003-2005, 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 * sha1_prf - SHA1-based Pseudo-Random Function (PRF) (IEEE 802.11i, 8.5.1.1)
19 * @key_len: Length of the key in bytes
20 * @label: A unique label for each purpose of the PRF
21 * @data: Extra data to bind into the key
22 * @data_len: Length of the data
23 * @buf: Buffer for the generated pseudo-random key
24 * @buf_len: Number of bytes of key to generate
25 * Returns: 0 on success, -1 of failure
27 * This function is used to derive new, cryptographically separate keys from a
28 * given key (e.g., PMK in IEEE 802.11i).
30 int sha1_prf(const u8
*key
, size_t key_len
, const char *label
,
31 const u8
*data
, size_t data_len
, u8
*buf
, size_t buf_len
)
35 u8 hash
[SHA1_MAC_LEN
];
36 size_t label_len
= os_strlen(label
) + 1;
37 const unsigned char *addr
[3];
40 addr
[0] = (u8
*) label
;
48 while (pos
< buf_len
) {
50 if (plen
>= SHA1_MAC_LEN
) {
51 if (hmac_sha1_vector(key
, key_len
, 3, addr
, len
,
56 if (hmac_sha1_vector(key
, key_len
, 3, addr
, len
,
59 os_memcpy(&buf
[pos
], hash
, plen
);
64 forced_memzero(hash
, sizeof(hash
));