QSC Post Quantum Cryptographic Library 1.3.0.0 (C1)
A post quantum secure library written in Ansi C
Loading...
Searching...
No Matches
tlskeyschedule.h
Go to the documentation of this file.
1/* 2020-2026 Quantum Resistant Cryptographic Solutions Corporation
2 * All Rights Reserved.
3 *
4 * NOTICE:
5 * This software and all accompanying materials are the exclusive property of
6 * Quantum Resistant Cryptographic Solutions Corporation (QRCS). The intellectual
7 * and technical concepts contained herein are proprietary to QRCS and are
8 * protected under applicable Canadian, U.S., and international copyright,
9 * patent, and trade secret laws.
10 *
11 * CRYPTOGRAPHIC ALGORITHMS AND IMPLEMENTATIONS:
12 * - This software includes implementations of cryptographic primitives and
13 * algorithms that are standardized or in the public domain, such as AES
14 * and SHA-3, which are not proprietary to QRCS.
15 * - This software also includes cryptographic primitives, constructions, and
16 * algorithms designed by QRCS, including but not limited to RCS, SCB, CSX, QMAC, and
17 * related components, which are proprietary to QRCS.
18 * - All source code, implementations, protocol compositions, optimizations,
19 * parameter selections, and engineering work contained in this software are
20 * original works of QRCS and are protected under this license.
21 *
22 * LICENSE AND USE RESTRICTIONS:
23 * - This software is licensed under the Quantum Resistant Cryptographic Solutions
24 * Public Research and Evaluation License (QRCS-PREL), 2025-2026.
25 * - Permission is granted solely for non-commercial evaluation, academic research,
26 * cryptographic analysis, interoperability testing, and feasibility assessment.
27 * - Commercial use, production deployment, commercial redistribution, or
28 * integration into products or services is strictly prohibited without a
29 * separate written license agreement executed with QRCS.
30 * - Licensing and authorized distribution are solely at the discretion of QRCS.
31 *
32 * EXPERIMENTAL CRYPTOGRAPHY NOTICE:
33 * Portions of this software may include experimental, novel, or evolving
34 * cryptographic designs. Use of this software is entirely at the user's risk.
35 *
36 * DISCLAIMER:
37 * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
38 * IMPLIED, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS
39 * FOR A PARTICULAR PURPOSE, SECURITY, OR NON-INFRINGEMENT. QRCS DISCLAIMS ALL
40 * LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
41 * ARISING FROM THE USE OR MISUSE OF THIS SOFTWARE.
42 *
43 * FULL LICENSE:
44 * This software is subject to the Quantum Resistant Cryptographic Solutions
45 * Public Research and Evaluation License (QRCS-PREL), 2025-2026. The complete license terms
46 * are provided in the accompanying LICENSE file or at https://www.qrcscorp.ca.
47 *
48 * Written by: John G. Underhill
49 * Contact: contact@qrcscorp.ca
50 */
51
102
103#ifndef QSC_TLS_KEYSCHEDULE_H
104#define QSC_TLS_KEYSCHEDULE_H
105
106#include "qsccommon.h"
107#include "tlserrors.h"
108#include "tlstypes.h"
109#include "tlsstate.h"
110
111QSC_CPLUSPLUS_ENABLED_START
112
151
165
176
195QSC_EXPORT_API qsc_tls_status qsc_tls_keyschedule_hkdf_extract(qsc_tls_hash_algorithm hash, const uint8_t* salt, size_t saltlen, const uint8_t* ikm,
196 size_t ikmlen, uint8_t* output, size_t outlen);
197
215QSC_EXPORT_API qsc_tls_status qsc_tls_keyschedule_hkdf_expand(qsc_tls_hash_algorithm hash, const uint8_t* prk, size_t prklen, const uint8_t* info,
216 size_t infolen, uint8_t* output, size_t outlen);
217
238 const char* label, size_t labellen, const uint8_t* context, size_t contextlen, uint8_t* output, size_t outlen);
239
260 const char* label, size_t labellen, const uint8_t* transcripthash, size_t transcripthashlen, uint8_t* output, size_t outlen);
261
280 const char* label, size_t labellen, uint8_t* output, size_t outlen);
281
296
311
324
338QSC_EXPORT_API qsc_tls_status qsc_tls_keyschedule_derive_handshake_traffic_secrets(qsc_tls_key_schedule_state* state, const uint8_t* transcripthash, size_t transcripthashlen);
339
353QSC_EXPORT_API qsc_tls_status qsc_tls_keyschedule_derive_application_traffic_secrets(qsc_tls_key_schedule_state* state, const uint8_t* transcripthash, size_t transcripthashlen);
354
368QSC_EXPORT_API qsc_tls_status qsc_tls_keyschedule_derive_exporter_master_secret(qsc_tls_key_schedule_state* state, const uint8_t* transcripthash, size_t transcripthashlen);
369
383QSC_EXPORT_API qsc_tls_status qsc_tls_keyschedule_derive_resumption_master_secret(qsc_tls_key_schedule_state* state, const uint8_t* transcripthash, size_t transcripthashlen);
384
403 const uint8_t* trafficsecret, size_t trafficsecretlen, size_t keylen, size_t ivlen, uint8_t* keyoutput, uint8_t* ivoutput);
404
421 size_t trafficsecretlen, uint8_t* nexttrafficsecret);
422
442 const uint8_t* transcripthash, size_t transcripthashlen, uint8_t* output, size_t outlen, size_t* written);
443
461QSC_EXPORT_API qsc_tls_status qsc_tls_keyschedule_verify_finished(qsc_tls_hash_algorithm hash, const uint8_t* basekey, size_t basekeylen,
462 const uint8_t* transcripthash, size_t transcripthashlen, const uint8_t* candidate, size_t candidatelen);
463
481QSC_EXPORT_API qsc_tls_status qsc_tls_keyschedule_build_certificate_verify_input(const char* contextstring, const uint8_t* transcripthash,
482 size_t transcripthashlen, uint8_t* output, size_t outlen, size_t* written);
483
497
510
527 size_t noncelen, uint8_t* output, size_t outlen);
528
543
557QSC_EXPORT_API qsc_tls_status qsc_tls_keyschedule_derive_client_early_traffic_secret(qsc_tls_key_schedule_state* state, const uint8_t* transcripthash, size_t transcripthashlen);
558
572QSC_EXPORT_API qsc_tls_status qsc_tls_keyschedule_derive_early_exporter_secret(qsc_tls_key_schedule_state* state, const uint8_t* transcripthash, size_t transcripthashlen);
573
593QSC_EXPORT_API qsc_tls_status qsc_tls_keyschedule_compute_psk_binder(qsc_tls_hash_algorithm hash, const uint8_t* binderkey, size_t binderkeylen,
594 const uint8_t* partialtranshash, size_t transcripthashlen, uint8_t* output, size_t outlen, size_t* written);
595
596QSC_CPLUSPLUS_ENABLED_END
597
598#endif
Contains common definitions for the Quantum Secure Cryptographic (QSC) library.
#define QSC_EXPORT_API
API export macro for Microsoft compilers when importing from a DLL.
Definition qsccommon.h:645
TLS 1.3 key schedule state and derived secret container.
Definition tlskeyschedule.h:129
uint8_t clienthandshaketrafficsecret[QSC_TLS_HASH_MAX_SIZE]
Definition tlskeyschedule.h:133
bool handshakedone
Definition tlskeyschedule.h:147
uint8_t mastersecret[QSC_TLS_HASH_MAX_SIZE]
Definition tlskeyschedule.h:138
uint8_t earlyexportermastersecret[QSC_TLS_HASH_MAX_SIZE]
Definition tlskeyschedule.h:134
bool masterdone
Definition tlskeyschedule.h:149
qsc_tls_hash_algorithm hash
Definition tlskeyschedule.h:143
size_t digestsize
Definition tlskeyschedule.h:142
bool earlydone
Definition tlskeyschedule.h:145
bool binderderived
Definition tlskeyschedule.h:144
uint8_t earlysecret[QSC_TLS_HASH_MAX_SIZE]
Definition tlskeyschedule.h:136
bool earlytrafficderived
Definition tlskeyschedule.h:146
uint8_t clientapplicationtrafficsecret[QSC_TLS_HASH_MAX_SIZE]
Definition tlskeyschedule.h:131
uint8_t handshakesecret[QSC_TLS_HASH_MAX_SIZE]
Definition tlskeyschedule.h:137
uint8_t resumptionmastersecret[QSC_TLS_HASH_MAX_SIZE]
Definition tlskeyschedule.h:139
uint8_t serverapplicationtrafficsecret[QSC_TLS_HASH_MAX_SIZE]
Definition tlskeyschedule.h:141
uint8_t clientearlytrafficsecret[QSC_TLS_HASH_MAX_SIZE]
Definition tlskeyschedule.h:132
uint8_t exportermastersecret[QSC_TLS_HASH_MAX_SIZE]
Definition tlskeyschedule.h:135
uint8_t binderkey[QSC_TLS_HASH_MAX_SIZE]
Definition tlskeyschedule.h:130
bool initialized
Definition tlskeyschedule.h:148
uint8_t serverhandshaketrafficsecret[QSC_TLS_HASH_MAX_SIZE]
Definition tlskeyschedule.h:140
#define QSC_TLS_HASH_MAX_SIZE
Defines the maximum supported transcript hash size in bytes.
Definition tlsdefs.h:120
TLS status code definitions and diagnostic string conversion.
qsc_tls_status
Definition tlserrors.h:65
QSC_EXPORT_API qsc_tls_status qsc_tls_keyschedule_extract_handshake_secret(qsc_tls_key_schedule_state *state, const uint8_t *dhe, size_t dhelen)
Extract the TLS 1.3 handshake secret.
Definition tlskeyschedule.c:461
QSC_EXPORT_API qsc_tls_status qsc_tls_keyschedule_extract_master_secret(qsc_tls_key_schedule_state *state)
Extract the TLS 1.3 master secret.
Definition tlskeyschedule.c:500
QSC_EXPORT_API qsc_tls_status qsc_tls_keyschedule_derive_early_exporter_secret(qsc_tls_key_schedule_state *state, const uint8_t *transcripthash, size_t transcripthashlen)
Derive the early exporter master secret.
Definition tlskeyschedule.c:915
QSC_EXPORT_API qsc_tls_status qsc_tls_keyschedule_state_initialize(qsc_tls_key_schedule_state *state, qsc_tls_hash_algorithm hash)
Initialize a TLS key schedule state.
Definition tlskeyschedule.c:383
QSC_EXPORT_API qsc_tls_status qsc_tls_keyschedule_hkdf_expand(qsc_tls_hash_algorithm hash, const uint8_t *prk, size_t prklen, const uint8_t *info, size_t infolen, uint8_t *output, size_t outlen)
Perform HKDF-Expand for the selected TLS hash algorithm.
Definition tlskeyschedule.c:144
QSC_EXPORT_API qsc_tls_status qsc_tls_keyschedule_derive_application_traffic_secrets(qsc_tls_key_schedule_state *state, const uint8_t *transcripthash, size_t transcripthashlen)
Derive the client and server application traffic secrets.
Definition tlskeyschedule.c:556
QSC_EXPORT_API qsc_tls_hash_algorithm qsc_tls_keyschedule_suite_hash(qsc_tls_cipher_suite suite)
Resolve the hash algorithm associated with a TLS cipher suite.
Definition tlskeyschedule.c:807
QSC_EXPORT_API qsc_tls_status qsc_tls_keyschedule_derive_binder_key(qsc_tls_key_schedule_state *state, bool external)
Derive the TLS 1.3 PSK binder key.
Definition tlskeyschedule.c:859
QSC_EXPORT_API qsc_tls_status qsc_tls_keyschedule_suite_record_sizes(qsc_tls_cipher_suite suite, size_t *keylen, size_t *ivlen)
Resolve record protection key and IV lengths for a TLS cipher suite.
Definition tlskeyschedule.c:757
QSC_EXPORT_API qsc_tls_status qsc_tls_keyschedule_derive_resumption_master_secret(qsc_tls_key_schedule_state *state, const uint8_t *transcripthash, size_t transcripthashlen)
Derive the resumption master secret.
Definition tlskeyschedule.c:597
QSC_EXPORT_API qsc_tls_status qsc_tls_keyschedule_extract_early_secret(qsc_tls_key_schedule_state *state, const uint8_t *psk, size_t psklen)
Extract the TLS 1.3 early secret.
Definition tlskeyschedule.c:426
QSC_EXPORT_API qsc_tls_status qsc_tls_keyschedule_derive_exporter_master_secret(qsc_tls_key_schedule_state *state, const uint8_t *transcripthash, size_t transcripthashlen)
Derive the exporter master secret.
Definition tlskeyschedule.c:579
QSC_EXPORT_API qsc_tls_status qsc_tls_keyschedule_verify_finished(qsc_tls_hash_algorithm hash, const uint8_t *basekey, size_t basekeylen, const uint8_t *transcripthash, size_t transcripthashlen, const uint8_t *candidate, size_t candidatelen)
Verify a TLS 1.3 Finished verify_data value.
Definition tlskeyschedule.c:724
QSC_EXPORT_API qsc_tls_status qsc_tls_keyschedule_derive_handshake_traffic_secrets(qsc_tls_key_schedule_state *state, const uint8_t *transcripthash, size_t transcripthashlen)
Derive the client and server handshake traffic secrets.
Definition tlskeyschedule.c:533
QSC_EXPORT_API qsc_tls_status qsc_tls_keyschedule_hkdf_extract(qsc_tls_hash_algorithm hash, const uint8_t *salt, size_t saltlen, const uint8_t *ikm, size_t ikmlen, uint8_t *output, size_t outlen)
Perform HKDF-Extract for the selected TLS hash algorithm.
Definition tlskeyschedule.c:102
QSC_EXPORT_API qsc_tls_status qsc_tls_keyschedule_hkdf_expand_label(qsc_tls_hash_algorithm hash, const uint8_t *secret, size_t secretlen, const char *label, size_t labellen, const uint8_t *context, size_t contextlen, uint8_t *output, size_t outlen)
Perform TLS 1.3 HKDF-Expand-Label.
Definition tlskeyschedule.c:166
QSC_EXPORT_API qsc_tls_status qsc_tls_keyschedule_build_certificate_verify_input(const char *contextstring, const uint8_t *transcripthash, size_t transcripthashlen, uint8_t *output, size_t outlen, size_t *written)
Build the TLS 1.3 CertificateVerify signature input.
Definition tlskeyschedule.c:312
QSC_EXPORT_API qsc_tls_status qsc_tls_keyschedule_derive_client_early_traffic_secret(qsc_tls_key_schedule_state *state, const uint8_t *transcripthash, size_t transcripthashlen)
Derive the client early traffic secret for 0-RTT data.
Definition tlskeyschedule.c:894
QSC_EXPORT_API qsc_tls_status qsc_tls_keyschedule_derive_secret_with_hash(qsc_tls_hash_algorithm hash, const uint8_t *secret, size_t secretlen, const char *label, size_t labellen, const uint8_t *transcripthash, size_t transcripthashlen, uint8_t *output, size_t outlen)
Derive a TLS 1.3 secret using a supplied transcript hash.
Definition tlskeyschedule.c:231
QSC_EXPORT_API qsc_tls_status qsc_tls_keyschedule_derive_secret_empty(qsc_tls_hash_algorithm hash, const uint8_t *secret, size_t secretlen, const char *label, size_t labellen, uint8_t *output, size_t outlen)
Derive a TLS 1.3 secret using the hash of the empty string.
Definition tlskeyschedule.c:258
QSC_EXPORT_API qsc_tls_status qsc_tls_keyschedule_derive_traffic_keys(qsc_tls_hash_algorithm hash, const uint8_t *trafficsecret, size_t trafficsecretlen, size_t keylen, size_t ivlen, uint8_t *keyoutput, uint8_t *ivoutput)
Derive record protection key and IV material from a traffic secret.
Definition tlskeyschedule.c:615
QSC_EXPORT_API qsc_tls_status qsc_tls_keyschedule_derive_resumption_psk(const qsc_tls_key_schedule_state *state, const uint8_t *nonce, size_t noncelen, uint8_t *output, size_t outlen)
Derive a resumption PSK from the resumption master secret.
Definition tlskeyschedule.c:834
QSC_EXPORT_API void qsc_tls_keyschedule_state_dispose(qsc_tls_key_schedule_state *state)
Dispose of a TLS key schedule state.
Definition tlskeyschedule.c:416
QSC_EXPORT_API qsc_tls_status qsc_tls_keyschedule_compute_finished(qsc_tls_hash_algorithm hash, const uint8_t *basekey, size_t basekeylen, const uint8_t *transcripthash, size_t transcripthashlen, uint8_t *output, size_t outlen, size_t *written)
Compute a TLS 1.3 Finished verify_data value.
Definition tlskeyschedule.c:645
QSC_EXPORT_API qsc_tls_status qsc_tls_keyschedule_advance_traffic_secret(qsc_tls_hash_algorithm hash, const uint8_t *currenttrafficsecret, size_t trafficsecretlen, uint8_t *nexttrafficsecret)
Advance an application traffic secret for TLS KeyUpdate.
Definition tlskeyschedule.c:640
QSC_EXPORT_API qsc_tls_status qsc_tls_keyschedule_compute_psk_binder(qsc_tls_hash_algorithm hash, const uint8_t *binderkey, size_t binderkeylen, const uint8_t *partialtranshash, size_t transcripthashlen, uint8_t *output, size_t outlen, size_t *written)
Compute a TLS 1.3 PSK binder MAC.
Definition tlskeyschedule.c:931
TLS internal state container type definitions shared across the record and handshake layers.
Public TLS type definitions.
qsc_tls_cipher_suite
TLS 1.3 cipher-suite identifiers.
Definition tlstypes.h:129
qsc_tls_hash_algorithm
Identifies the transcript and HKDF hash algorithm associated with a TLS cipher suite.
Definition tlstypes.h:69