lsquic_hkdf.c revision 7d09751d
17d09751dSDmitri Tikhonov/* Copyright (c) 2017 - 2020 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 205392f7a3SLiteSpeed Tech unsigned char info[ 2 + 1 + 6 + label_len + 1]; 215392f7a3SLiteSpeed Tech 225392f7a3SLiteSpeed Tech info[0] = out_len >> 8; 235392f7a3SLiteSpeed Tech info[1] = out_len; 245392f7a3SLiteSpeed Tech info[2] = label_len + 6; 255392f7a3SLiteSpeed Tech info[3] = 't'; 265392f7a3SLiteSpeed Tech info[4] = 'l'; 275392f7a3SLiteSpeed Tech info[5] = 's'; 285392f7a3SLiteSpeed Tech info[6] = '1'; 295392f7a3SLiteSpeed Tech info[7] = '3'; 305392f7a3SLiteSpeed Tech info[8] = ' '; 315392f7a3SLiteSpeed Tech memcpy(info + 9, label, label_len); 325392f7a3SLiteSpeed Tech info[9 + label_len] = 0; 335392f7a3SLiteSpeed Tech#ifndef NDEBUG 345392f7a3SLiteSpeed Tech s = 355392f7a3SLiteSpeed Tech#else 365392f7a3SLiteSpeed Tech (void) 375392f7a3SLiteSpeed Tech#endif 385392f7a3SLiteSpeed Tech HKDF_expand(out, out_len, md, secret, secret_len, info, sizeof(info)); 395392f7a3SLiteSpeed Tech assert(s); 405392f7a3SLiteSpeed Tech} 41