lsquic_hkdf.c revision 7d09751d
1/* Copyright (c) 2017 - 2020 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    unsigned char info[ 2 + 1 + 6 + label_len + 1];
21
22    info[0] = out_len >> 8;
23    info[1] = out_len;
24    info[2] = label_len + 6;
25    info[3] = 't';
26    info[4] = 'l';
27    info[5] = 's';
28    info[6] = '1';
29    info[7] = '3';
30    info[8] = ' ';
31    memcpy(info + 9, label, label_len);
32    info[9 + label_len] = 0;
33#ifndef NDEBUG
34    s =
35#else
36    (void)
37#endif
38    HKDF_expand(out, out_len, md, secret, secret_len, info, sizeof(info));
39    assert(s);
40}
41