1a74702c6SGeorge Wang/* Copyright (c) 2017 - 2022 LiteSpeed Technologies Inc. See LICENSE. */ 25392f7a3SLiteSpeed Tech#include <assert.h> 35392f7a3SLiteSpeed Tech#include <stddef.h> 45392f7a3SLiteSpeed Tech#include <string.h> 55392f7a3SLiteSpeed Tech 65392f7a3SLiteSpeed Tech#include <openssl/hkdf.h> 75392f7a3SLiteSpeed Tech 85392f7a3SLiteSpeed Tech#include "lsquic_hkdf.h" 95392f7a3SLiteSpeed Tech 105392f7a3SLiteSpeed Tech 115392f7a3SLiteSpeed Tech/* [draft-ietf-quic-tls-17] Section 5 */ 125392f7a3SLiteSpeed Techvoid 135392f7a3SLiteSpeed Techlsquic_qhkdf_expand (const EVP_MD *md, const unsigned char *secret, 145392f7a3SLiteSpeed Tech unsigned secret_len, const char *label, uint8_t label_len, 155392f7a3SLiteSpeed Tech unsigned char *out, uint16_t out_len) 165392f7a3SLiteSpeed Tech{ 175392f7a3SLiteSpeed Tech#ifndef NDEBUG 185392f7a3SLiteSpeed Tech int s; 195392f7a3SLiteSpeed Tech#endif 20fb3e20e0SDmitri Tikhonov const size_t len = 2 + 1 + 6 + label_len + 1; 21fb3e20e0SDmitri Tikhonov#ifndef WIN32 225392f7a3SLiteSpeed Tech unsigned char info[ 2 + 1 + 6 + label_len + 1]; 23fb3e20e0SDmitri Tikhonov#else 24fb3e20e0SDmitri Tikhonov unsigned char info[ 2 + 1 + 6 + UINT8_MAX + 1]; 25fb3e20e0SDmitri Tikhonov#endif 265392f7a3SLiteSpeed Tech 275392f7a3SLiteSpeed Tech info[0] = out_len >> 8; 285392f7a3SLiteSpeed Tech info[1] = out_len; 295392f7a3SLiteSpeed Tech info[2] = label_len + 6; 305392f7a3SLiteSpeed Tech info[3] = 't'; 315392f7a3SLiteSpeed Tech info[4] = 'l'; 325392f7a3SLiteSpeed Tech info[5] = 's'; 335392f7a3SLiteSpeed Tech info[6] = '1'; 345392f7a3SLiteSpeed Tech info[7] = '3'; 355392f7a3SLiteSpeed Tech info[8] = ' '; 365392f7a3SLiteSpeed Tech memcpy(info + 9, label, label_len); 375392f7a3SLiteSpeed Tech info[9 + label_len] = 0; 385392f7a3SLiteSpeed Tech#ifndef NDEBUG 395392f7a3SLiteSpeed Tech s = 405392f7a3SLiteSpeed Tech#else 415392f7a3SLiteSpeed Tech (void) 425392f7a3SLiteSpeed Tech#endif 43fb3e20e0SDmitri Tikhonov HKDF_expand(out, out_len, md, secret, secret_len, info, len); 445392f7a3SLiteSpeed Tech assert(s); 455392f7a3SLiteSpeed Tech} 46