lsquic_hkdf.c revision a74702c6
1/* Copyright (c) 2017 - 2022 LiteSpeed Technologies Inc. See LICENSE. */ 2#include <assert.h> 3#include <stddef.h> 4#include <string.h> 5 6#include <openssl/hkdf.h> 7 8#include "lsquic_hkdf.h" 9 10 11/* [draft-ietf-quic-tls-17] Section 5 */ 12void 13lsquic_qhkdf_expand (const EVP_MD *md, const unsigned char *secret, 14 unsigned secret_len, const char *label, uint8_t label_len, 15 unsigned char *out, uint16_t out_len) 16{ 17#ifndef NDEBUG 18 int s; 19#endif 20 const size_t len = 2 + 1 + 6 + label_len + 1; 21#ifndef WIN32 22 unsigned char info[ 2 + 1 + 6 + label_len + 1]; 23#else 24 unsigned char info[ 2 + 1 + 6 + UINT8_MAX + 1]; 25#endif 26 27 info[0] = out_len >> 8; 28 info[1] = out_len; 29 info[2] = label_len + 6; 30 info[3] = 't'; 31 info[4] = 'l'; 32 info[5] = 's'; 33 info[6] = '1'; 34 info[7] = '3'; 35 info[8] = ' '; 36 memcpy(info + 9, label, label_len); 37 info[9 + label_len] = 0; 38#ifndef NDEBUG 39 s = 40#else 41 (void) 42#endif 43 HKDF_expand(out, out_len, md, secret, secret_len, info, len); 44 assert(s); 45} 46