mirror of
https://github.com/vanhoefm/fragattacks.git
synced 2024-11-28 18:28:23 -05:00
Add TLS-PRF using HMAC with P_SHA384 for TEAP
This version of TLS PRF is needed when using TEAP with TLS ciphersuites that are defined to use SHA384 instead of SHA256. Signed-off-by: Jouni Malinen <j@w1.fi>
This commit is contained in:
parent
263c0cbdc0
commit
52069c7eff
@ -494,6 +494,8 @@ OBJS += src/eap_common/eap_teap_common.c
|
|||||||
TLS_FUNCS=y
|
TLS_FUNCS=y
|
||||||
NEED_T_PRF=y
|
NEED_T_PRF=y
|
||||||
NEED_SHA384=y
|
NEED_SHA384=y
|
||||||
|
NEED_TLS_PRF_SHA256=y
|
||||||
|
NEED_TLS_PRF_SHA384=y
|
||||||
NEED_AES_UNWRAP=y
|
NEED_AES_UNWRAP=y
|
||||||
endif
|
endif
|
||||||
|
|
||||||
@ -923,6 +925,9 @@ endif
|
|||||||
ifdef NEED_TLS_PRF_SHA256
|
ifdef NEED_TLS_PRF_SHA256
|
||||||
OBJS += src/crypto/sha256-tlsprf.c
|
OBJS += src/crypto/sha256-tlsprf.c
|
||||||
endif
|
endif
|
||||||
|
ifdef NEED_TLS_PRF_SHA384
|
||||||
|
OBJS += src/crypto/sha384-tlsprf.c
|
||||||
|
endif
|
||||||
ifdef NEED_HMAC_SHA256_KDF
|
ifdef NEED_HMAC_SHA256_KDF
|
||||||
OBJS += src/crypto/sha256-kdf.c
|
OBJS += src/crypto/sha256-kdf.c
|
||||||
endif
|
endif
|
||||||
|
@ -533,6 +533,8 @@ OBJS += ../src/eap_common/eap_teap_common.o
|
|||||||
TLS_FUNCS=y
|
TLS_FUNCS=y
|
||||||
NEED_T_PRF=y
|
NEED_T_PRF=y
|
||||||
NEED_SHA384=y
|
NEED_SHA384=y
|
||||||
|
NEED_TLS_PRF_SHA256=y
|
||||||
|
NEED_TLS_PRF_SHA384=y
|
||||||
NEED_AES_UNWRAP=y
|
NEED_AES_UNWRAP=y
|
||||||
endif
|
endif
|
||||||
|
|
||||||
@ -1068,6 +1070,9 @@ endif
|
|||||||
ifdef NEED_TLS_PRF_SHA256
|
ifdef NEED_TLS_PRF_SHA256
|
||||||
OBJS += ../src/crypto/sha256-tlsprf.o
|
OBJS += ../src/crypto/sha256-tlsprf.o
|
||||||
endif
|
endif
|
||||||
|
ifdef NEED_TLS_PRF_SHA384
|
||||||
|
OBJS += ../src/crypto/sha384-tlsprf.o
|
||||||
|
endif
|
||||||
ifdef NEED_HMAC_SHA256_KDF
|
ifdef NEED_HMAC_SHA256_KDF
|
||||||
OBJS += ../src/crypto/sha256-kdf.o
|
OBJS += ../src/crypto/sha256-kdf.o
|
||||||
endif
|
endif
|
||||||
|
71
src/crypto/sha384-tlsprf.c
Normal file
71
src/crypto/sha384-tlsprf.c
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
/*
|
||||||
|
* TLS PRF P_SHA384
|
||||||
|
* Copyright (c) 2011-2019, Jouni Malinen <j@w1.fi>
|
||||||
|
*
|
||||||
|
* This software may be distributed under the terms of the BSD license.
|
||||||
|
* See README for more details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "includes.h"
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
|
#include "sha384.h"
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* tls_prf_sha384 - Pseudo-Random Function for TLS v1.2 (P_SHA384, RFC 5246)
|
||||||
|
* @secret: Key for PRF
|
||||||
|
* @secret_len: Length of the key in bytes
|
||||||
|
* @label: A unique label for each purpose of the PRF
|
||||||
|
* @seed: Seed value to bind into the key
|
||||||
|
* @seed_len: Length of the seed
|
||||||
|
* @out: Buffer for the generated pseudo-random key
|
||||||
|
* @outlen: Number of bytes of key to generate
|
||||||
|
* Returns: 0 on success, -1 on failure.
|
||||||
|
*
|
||||||
|
* This function is used to derive new, cryptographically separate keys from a
|
||||||
|
* given key in TLS. This PRF is defined in RFC 5246, Chapter 5.
|
||||||
|
*/
|
||||||
|
int tls_prf_sha384(const u8 *secret, size_t secret_len, const char *label,
|
||||||
|
const u8 *seed, size_t seed_len, u8 *out, size_t outlen)
|
||||||
|
{
|
||||||
|
size_t clen;
|
||||||
|
u8 A[SHA384_MAC_LEN];
|
||||||
|
u8 P[SHA384_MAC_LEN];
|
||||||
|
size_t pos;
|
||||||
|
const unsigned char *addr[3];
|
||||||
|
size_t len[3];
|
||||||
|
|
||||||
|
addr[0] = A;
|
||||||
|
len[0] = SHA384_MAC_LEN;
|
||||||
|
addr[1] = (unsigned char *) label;
|
||||||
|
len[1] = os_strlen(label);
|
||||||
|
addr[2] = seed;
|
||||||
|
len[2] = seed_len;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* RFC 5246, Chapter 5
|
||||||
|
* A(0) = seed, A(i) = HMAC(secret, A(i-1))
|
||||||
|
* P_hash = HMAC(secret, A(1) + seed) + HMAC(secret, A(2) + seed) + ..
|
||||||
|
* PRF(secret, label, seed) = P_SHA384(secret, label + seed)
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (hmac_sha384_vector(secret, secret_len, 2, &addr[1], &len[1], A) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
pos = 0;
|
||||||
|
while (pos < outlen) {
|
||||||
|
if (hmac_sha384_vector(secret, secret_len, 3, addr, len, P) <
|
||||||
|
0 ||
|
||||||
|
hmac_sha384(secret, secret_len, A, SHA384_MAC_LEN, A) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
clen = outlen - pos;
|
||||||
|
if (clen > SHA384_MAC_LEN)
|
||||||
|
clen = SHA384_MAC_LEN;
|
||||||
|
os_memcpy(out + pos, P, clen);
|
||||||
|
pos += clen;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
@ -20,6 +20,9 @@ int sha384_prf(const u8 *key, size_t key_len, const char *label,
|
|||||||
int sha384_prf_bits(const u8 *key, size_t key_len, const char *label,
|
int sha384_prf_bits(const u8 *key, size_t key_len, const char *label,
|
||||||
const u8 *data, size_t data_len, u8 *buf,
|
const u8 *data, size_t data_len, u8 *buf,
|
||||||
size_t buf_len_bits);
|
size_t buf_len_bits);
|
||||||
|
int tls_prf_sha384(const u8 *secret, size_t secret_len,
|
||||||
|
const char *label, const u8 *seed, size_t seed_len,
|
||||||
|
u8 *out, size_t outlen);
|
||||||
int hmac_sha384_kdf(const u8 *secret, size_t secret_len,
|
int hmac_sha384_kdf(const u8 *secret, size_t secret_len,
|
||||||
const char *label, const u8 *seed, size_t seed_len,
|
const char *label, const u8 *seed, size_t seed_len,
|
||||||
u8 *out, size_t outlen);
|
u8 *out, size_t outlen);
|
||||||
|
@ -659,6 +659,8 @@ TLS_FUNCS=y
|
|||||||
CONFIG_IEEE8021X_EAPOL=y
|
CONFIG_IEEE8021X_EAPOL=y
|
||||||
NEED_T_PRF=y
|
NEED_T_PRF=y
|
||||||
NEED_SHA384=y
|
NEED_SHA384=y
|
||||||
|
NEED_TLS_PRF_SHA256=y
|
||||||
|
NEED_TLS_PRF_SHA384=y
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifdef CONFIG_EAP_PAX
|
ifdef CONFIG_EAP_PAX
|
||||||
@ -1366,6 +1368,9 @@ endif
|
|||||||
ifdef NEED_TLS_PRF_SHA256
|
ifdef NEED_TLS_PRF_SHA256
|
||||||
SHA256OBJS += src/crypto/sha256-tlsprf.c
|
SHA256OBJS += src/crypto/sha256-tlsprf.c
|
||||||
endif
|
endif
|
||||||
|
ifdef NEED_TLS_PRF_SHA384
|
||||||
|
SHA256OBJS += src/crypto/sha384-tlsprf.c
|
||||||
|
endif
|
||||||
ifdef NEED_HMAC_SHA256_KDF
|
ifdef NEED_HMAC_SHA256_KDF
|
||||||
L_CFLAGS += -DCONFIG_HMAC_SHA256_KDF
|
L_CFLAGS += -DCONFIG_HMAC_SHA256_KDF
|
||||||
SHA256OBJS += src/crypto/sha256-kdf.c
|
SHA256OBJS += src/crypto/sha256-kdf.c
|
||||||
|
@ -686,6 +686,8 @@ TLS_FUNCS=y
|
|||||||
CONFIG_IEEE8021X_EAPOL=y
|
CONFIG_IEEE8021X_EAPOL=y
|
||||||
NEED_T_PRF=y
|
NEED_T_PRF=y
|
||||||
NEED_SHA384=y
|
NEED_SHA384=y
|
||||||
|
NEED_TLS_PRF_SHA256=y
|
||||||
|
NEED_TLS_PRF_SHA384=y
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifdef CONFIG_EAP_PAX
|
ifdef CONFIG_EAP_PAX
|
||||||
@ -1501,6 +1503,9 @@ endif
|
|||||||
ifdef NEED_TLS_PRF_SHA256
|
ifdef NEED_TLS_PRF_SHA256
|
||||||
SHA256OBJS += ../src/crypto/sha256-tlsprf.o
|
SHA256OBJS += ../src/crypto/sha256-tlsprf.o
|
||||||
endif
|
endif
|
||||||
|
ifdef NEED_TLS_PRF_SHA384
|
||||||
|
SHA256OBJS += ../src/crypto/sha384-tlsprf.o
|
||||||
|
endif
|
||||||
ifdef NEED_HMAC_SHA256_KDF
|
ifdef NEED_HMAC_SHA256_KDF
|
||||||
CFLAGS += -DCONFIG_HMAC_SHA256_KDF
|
CFLAGS += -DCONFIG_HMAC_SHA256_KDF
|
||||||
OBJS += ../src/crypto/sha256-kdf.o
|
OBJS += ../src/crypto/sha256-kdf.o
|
||||||
|
Loading…
Reference in New Issue
Block a user