HKDS: Heirarchal Key Derivation System 1.0.0.2 (A2)
A fast post-quantum secure replacement for DUKPT
hkds_server.h
Go to the documentation of this file.
1/* 2025 Quantum Resistant Cryptographic Solutions Corporation
2 * All Rights Reserved.
3 *
4 * NOTICE: This software and all accompanying materials are the exclusive
5 * property of Quantum Resistant Cryptographic Solutions Corporation (QRCS).
6 * The intellectual and technical concepts contained within this implementation
7 * are proprietary to QRCS and its authorized licensors and are protected under
8 * applicable U.S. and international copyright, patent, and trade secret laws.
9 *
10 * CRYPTOGRAPHIC STANDARDS:
11 * - This software includes implementations of cryptographic algorithms such as
12 * SHA3, AES, and others. These algorithms are public domain or standardized
13 * by organizations such as NIST and are NOT the property of QRCS.
14 * - However, all source code, optimizations, and implementations in this library
15 * are original works of QRCS and are protected under this license.
16 *
17 * RESTRICTIONS:
18 * - Redistribution, modification, or unauthorized distribution of this software,
19 * in whole or in part, is strictly prohibited.
20 * - This software is provided for non-commercial, educational, and research
21 * purposes only. Commercial use in any form is expressly forbidden.
22 * - Licensing and authorized distribution are solely at the discretion of QRCS.
23 * - Any use of this software implies acceptance of these restrictions.
24 *
25 * DISCLAIMER:
26 * This software is provided "as is," without warranty of any kind, express or
27 * implied, including but not limited to warranties of merchantability or fitness
28 * for a particular purpose. QRCS disclaims all liability for any direct, indirect,
29 * incidental, or consequential damages resulting from the use or misuse of this software.
30 *
31 * FULL LICENSE:
32 * This software is subject to the **Quantum Resistant Cryptographic Solutions
33 * Proprietary License (QRCS-PL)**. The complete license terms are included
34 * in the LICENSE.txt file distributed with this software.
35 *
36 * Written by: John G. Underhill
37 * Contact: john.underhill@protonmail.com
38 */
39
40#ifndef HKDS_SERVER_H
41#define HKDS_SERVER_H
42
43#include "hkds_config.h"
44
55
66HKDS_EXPORT_API typedef struct
67{
68 uint8_t bdk[HKDS_BDK_SIZE];
69 uint8_t stk[HKDS_STK_SIZE];
70 uint8_t kid[HKDS_KID_SIZE];
72
84HKDS_EXPORT_API typedef struct
85{
86 uint8_t ksn[HKDS_KSN_SIZE];
88 size_t count;
89 size_t rate;
91
103HKDS_EXPORT_API void hkds_server_decrypt_message(hkds_server_state* state, const uint8_t* ciphertext, uint8_t* plaintext);
104
121HKDS_EXPORT_API bool hkds_server_decrypt_verify_message(hkds_server_state* state, const uint8_t* ciphertext, const uint8_t* data,
122 size_t datalen, uint8_t* plaintext);
123
134HKDS_EXPORT_API void hkds_server_encrypt_token(hkds_server_state* state, uint8_t* etok);
135
148HKDS_EXPORT_API void hkds_server_generate_edk(const uint8_t* bdk, const uint8_t* did, uint8_t* edk);
149
162HKDS_EXPORT_API void hkds_server_generate_mdk(bool (*rng_generate)(uint8_t*, size_t), hkds_master_key* mdk, const uint8_t* kid);
163
175HKDS_EXPORT_API void hkds_server_initialize_state(hkds_server_state* state, hkds_master_key* mdk, const uint8_t* ksn);
176
177/* --- Parallel Vectorized x8 API --- */
178
188HKDS_EXPORT_API typedef struct
189{
193
205HKDS_EXPORT_API void hkds_server_decrypt_message_x8(hkds_server_x8_state* state,
206 const uint8_t ciphertext[HKDS_CACHX8_DEPTH][HKDS_MESSAGE_SIZE],
207 uint8_t plaintext[HKDS_CACHX8_DEPTH][HKDS_MESSAGE_SIZE]);
208
224 const uint8_t ciphertext[HKDS_CACHX8_DEPTH][HKDS_MESSAGE_SIZE + HKDS_TAG_SIZE],
225 const uint8_t data[HKDS_CACHX8_DEPTH][HKDS_MESSAGE_SIZE], size_t datalen,
226 uint8_t plaintext[HKDS_CACHX8_DEPTH][HKDS_MESSAGE_SIZE],
227 bool valid[HKDS_CACHX8_DEPTH]);
228
239HKDS_EXPORT_API void hkds_server_encrypt_token_x8(hkds_server_x8_state* state,
241
253HKDS_EXPORT_API void hkds_server_generate_edk_x8(const hkds_server_x8_state* state,
254 const uint8_t did[HKDS_CACHX8_DEPTH][HKDS_DID_SIZE],
255 uint8_t edk[HKDS_CACHX8_DEPTH][HKDS_EDK_SIZE]);
256
268HKDS_EXPORT_API void hkds_server_initialize_state_x8(hkds_server_x8_state* state,
269 hkds_master_key* mdk,
270 const uint8_t ksn[HKDS_CACHX8_DEPTH][HKDS_KSN_SIZE]);
271
272#if defined(SYSTEM_OPENMP)
273
274/* --- Parallel SIMD Vectorized x64 API --- */
275
286HKDS_EXPORT_API void hkds_server_decrypt_message_x64(hkds_server_x8_state state[HKDS_PARALLEL_DEPTH],
287 const uint8_t ciphertext[HKDS_PARALLEL_DEPTH][HKDS_CACHX8_DEPTH][HKDS_MESSAGE_SIZE],
289
304HKDS_EXPORT_API void hkds_server_decrypt_verify_message_x64(hkds_server_x8_state state[HKDS_PARALLEL_DEPTH],
306 const uint8_t data[HKDS_PARALLEL_DEPTH][HKDS_CACHX8_DEPTH][HKDS_MESSAGE_SIZE], size_t datalen,
309
319HKDS_EXPORT_API void hkds_server_encrypt_token_x64(hkds_server_x8_state state[HKDS_PARALLEL_DEPTH],
321
332HKDS_EXPORT_API void hkds_server_generate_edk_x64(const hkds_server_x8_state state[HKDS_PARALLEL_DEPTH],
335
347HKDS_EXPORT_API void hkds_server_initialize_state_x64(hkds_server_x8_state state[HKDS_PARALLEL_DEPTH],
350
351#endif
352#endif
HKDS configuration definitions.
#define HKDS_MESSAGE_SIZE
The encrypted message size in bytes.
Definition hkds_config.h:302
#define HKDS_TAG_SIZE
The size of the authentication tag (MAC) in bytes.
Definition hkds_config.h:314
#define HKDS_EDK_SIZE
The Embedded Device Key size for SHAKE-256 in bytes.
Definition hkds_config.h:391
#define HKDS_PARALLEL_DEPTH
The AVX512 depth multiplier.
Definition hkds_config.h:245
#define HKDS_CACHX8_DEPTH
The AVX512 depth multiplier for cache operations.
Definition hkds_config.h:254
#define HKDS_BDK_SIZE
The Base Derivation Key size for SHAKE-256 in bytes.
Definition hkds_config.h:385
#define HKDS_STK_SIZE
The Secret Token Key size for SHAKE-256 in bytes.
Definition hkds_config.h:415
#define HKDS_KSN_SIZE
The Key Serial Number (KSN) size in bytes.
Definition hkds_config.h:296
#define HKDS_DID_SIZE
The device identity size in bytes.
Definition hkds_config.h:272
#define HKDS_KID_SIZE
The master key identity string size in bytes.
Definition hkds_config.h:290
HKDS_EXPORT_API void hkds_server_generate_edk_x8(const hkds_server_x8_state *state, const uint8_t did[HKDS_CACHX8_DEPTH][HKDS_DID_SIZE], uint8_t edk[HKDS_CACHX8_DEPTH][HKDS_EDK_SIZE])
Generate a 2-dimensional x8 set of client embedded device keys.
Definition hkds_server.c:515
HKDS_EXPORT_API void hkds_server_decrypt_message(hkds_server_state *state, const uint8_t *ciphertext, uint8_t *plaintext)
Decrypt a message sent by the client.
Definition hkds_server.c:102
HKDS_EXPORT_API void hkds_server_initialize_state(hkds_server_state *state, hkds_master_key *mdk, const uint8_t *ksn)
Initialize the HKDS server state.
Definition hkds_server.c:224
HKDS_EXPORT_API void hkds_server_decrypt_message_x8(hkds_server_x8_state *state, const uint8_t ciphertext[HKDS_CACHX8_DEPTH][HKDS_MESSAGE_SIZE], uint8_t plaintext[HKDS_CACHX8_DEPTH][HKDS_MESSAGE_SIZE])
Decrypt a 2-dimensional x8 set of client messages.
Definition hkds_server.c:383
HKDS_EXPORT_API void hkds_server_decrypt_verify_message_x8(hkds_server_x8_state *state, const uint8_t ciphertext[HKDS_CACHX8_DEPTH][HKDS_MESSAGE_SIZE+HKDS_TAG_SIZE], const uint8_t data[HKDS_CACHX8_DEPTH][HKDS_MESSAGE_SIZE], size_t datalen, uint8_t plaintext[HKDS_CACHX8_DEPTH][HKDS_MESSAGE_SIZE], bool valid[HKDS_CACHX8_DEPTH])
Verify and decrypt a 2-dimensional x8 set of client messages.
Definition hkds_server.c:461
HKDS_EXPORT_API void hkds_server_generate_mdk(bool(*rng_generate)(uint8_t *, size_t), hkds_master_key *mdk, const uint8_t *kid)
Generate a master key set.
Definition hkds_server.c:214
HKDS_EXPORT_API void hkds_server_generate_edk(const uint8_t *bdk, const uint8_t *did, uint8_t *edk)
Generate the embedded device key (EDK) for a client.
Definition hkds_server.c:146
HKDS_EXPORT_API void hkds_server_initialize_state_x8(hkds_server_x8_state *state, hkds_master_key *mdk, const uint8_t ksn[HKDS_CACHX8_DEPTH][HKDS_KSN_SIZE])
Initialize a 2-dimensional x8 set of server states with client KSNs.
Definition hkds_server.c:539
HKDS_EXPORT_API bool hkds_server_decrypt_verify_message(hkds_server_state *state, const uint8_t *ciphertext, const uint8_t *data, size_t datalen, uint8_t *plaintext)
Verify a ciphertext's integrity with a keyed MAC and decrypt the message.
Definition hkds_server.c:111
HKDS_EXPORT_API void hkds_server_encrypt_token_x8(hkds_server_x8_state *state, uint8_t etok[HKDS_CACHX8_DEPTH][HKDS_STK_SIZE+HKDS_TAG_SIZE])
Encrypt a 2-dimensional x8 set of secret token keys.
Definition hkds_server.c:397
HKDS_EXPORT_API void hkds_server_encrypt_token(hkds_server_state *state, uint8_t *etok)
Encrypt a secret token key to send to the client.
Definition hkds_server.c:164
Contains the HKDS master key set.
Definition hkds_server.h:67
uint8_t bdk[HKDS_BDK_SIZE]
Definition hkds_server.h:68
uint8_t stk[HKDS_STK_SIZE]
Definition hkds_server.h:69
uint8_t kid[HKDS_KID_SIZE]
Definition hkds_server.h:70
Contains the HKDS server state.
Definition hkds_server.h:85
uint8_t ksn[HKDS_KSN_SIZE]
Definition hkds_server.h:86
size_t rate
Definition hkds_server.h:89
size_t count
Definition hkds_server.h:88
hkds_master_key * mdk
Definition hkds_server.h:87
Contains the HKDS parallel x8 server state.
Definition hkds_server.h:189
uint8_t ksn[HKDS_CACHX8_DEPTH][HKDS_KSN_SIZE]
Definition hkds_server.h:190
hkds_master_key * mdk
Definition hkds_server.h:191