HKDS: Heirarchal Key Derivation System 1.0.0.2 (A2)
A fast post-quantum secure replacement for DUKPT
hkds_config.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_CONFIG_H
41#define HKDS_CONFIG_H
42
43#include "common.h"
44
63
64/*** Enumerations ***/
65
87
103
129
153
154/*** Modifiable Values ***/
155
163//#define HKDS_KECCAK_DOUBLE_ROUNDS
164
172//#define HKDS_KECCAK_HALF_ROUNDS
173
181//#define HKDS_SHAKE_128
182
190#define HKDS_SHAKE_256
191
199//#define HKDS_SHAKE_512
200
210#define HKDS_CACHE_MULTIPLIER 4
211
212/*** Static Values (Do Not Change) ***/
213
218#define HKDS_ADMIN_SIZE 2
219
224#define HKDS_AUTHENTICATION_KMAC 0x11
225
230#define HKDS_AUTHENTICATION_NONE 0x10
231
236#define HKDS_AUTHENTICATION_SHA3 0x12
237
245#define HKDS_PARALLEL_DEPTH 8
246
254#define HKDS_CACHX8_DEPTH 8
255
260#define HKDS_CACHX64_SIZE 64
261
266#define HKDS_CTOK_SIZE 23
267
272#define HKDS_DID_SIZE 12
273
278#define HKDS_ERROR_SIZE 16
279
284#define HKDS_HEADER_SIZE 4
285
290#define HKDS_KID_SIZE 4
291
296#define HKDS_KSN_SIZE 16
297
302#define HKDS_MESSAGE_SIZE 16
303
308#define HKDS_NAME_SIZE 7
309
314#define HKDS_TAG_SIZE 16
315
320#define HKDS_TKC_SIZE 4
321
329#define HKDS_TMS_SIZE (HKDS_KSN_SIZE + HKDS_NAME_SIZE)
330
331#if defined(HKDS_SHAKE_128)
332
337# define HKDS_BDK_SIZE 16
338
343# define HKDS_EDK_SIZE 16
344
349# define HKDS_ETOK_SIZE 32
350
355# define HKDS_PRF_RATE 168
356
361# define HKDS_PROTOCOL_TYPE protocol_shake_128
362
367# define HKDS_STK_SIZE 16
368
372static const uint8_t hkds_formal_name[HKDS_NAME_SIZE] = { 0x48, 0x4B, 0x44, 0x53, 0x31, 0x32, 0x38 };
373
377static const uint8_t hkds_mac_name[HKDS_NAME_SIZE] = { 0x75, 0x4B, 0x77, 0x65, 0x31, 0x32, 0x38 };
378
379#elif defined(HKDS_SHAKE_256)
380
385# define HKDS_BDK_SIZE 32
386
391# define HKDS_EDK_SIZE 32
392
397# define HKDS_ETOK_SIZE 48
398
403# define HKDS_PRF_RATE 136
404
409# define HKDS_PROTOCOL_TYPE protocol_shake_256
410
415# define HKDS_STK_SIZE 32
416
420static const uint8_t hkds_formal_name[HKDS_NAME_SIZE] = { 0x48, 0x4B, 0x44, 0x53, 0x32, 0x35, 0x36 };
421
425static const uint8_t hkds_mac_name[HKDS_NAME_SIZE] = { 0x75, 0x4B, 0x77, 0x65, 0x32, 0x35, 0x36 };
426
427#elif defined(HKDS_SHAKE_512)
428
433# define HKDS_BDK_SIZE 64
434
439# define HKDS_EDK_SIZE 64
440
445# define HKDS_ETOK_SIZE 80
446
451# define HKDS_PRF_RATE 72
452
457# define HKDS_PROTOCOL_TYPE protocol_shake_512
458
463# define HKDS_STK_SIZE 64
464
468static const uint8_t hkds_formal_name[HKDS_NAME_SIZE] = { 0x48, 0x4B, 0x44, 0x53, 0x35, 0x31, 0x32 };
469
473static const uint8_t hkds_mac_name[HKDS_NAME_SIZE] = { 0x75, 0x4B, 0x77, 0x65, 0x35, 0x31, 0x32 };
474
475#endif
476
484#define HKDS_CACHE_SIZE ((HKDS_CACHE_MULTIPLIER * HKDS_PRF_RATE) / HKDS_MESSAGE_SIZE)
485
493#define HKDS_CLIENT_MESSAGE_REQUEST_SIZE (HKDS_HEADER_SIZE + HKDS_KSN_SIZE + HKDS_MESSAGE_SIZE + HKDS_TAG_SIZE)
494
502#define HKDS_CLIENT_TOKEN_REQUEST_SIZE (HKDS_HEADER_SIZE + HKDS_KSN_SIZE)
503
511#define HKDS_SERVER_MESSAGE_RESPONSE_SIZE (HKDS_HEADER_SIZE + HKDS_MESSAGE_SIZE)
512
520#define HKDS_SERVER_TOKEN_RESPONSE_SIZE (HKDS_HEADER_SIZE + HKDS_ETOK_SIZE)
521
529#define HKDS_ADMIN_MESSAGE_SIZE (HKDS_HEADER_SIZE + HKDS_ADMIN_SIZE)
530
538#define HKDS_ERROR_MESSAGE_SIZE (HKDS_HEADER_SIZE + HKDS_ERROR_SIZE)
539
540/*** Packet Headers ***/
541
560
579
595
611
627
643
658
659
660#endif
#define HKDS_MESSAGE_SIZE
The encrypted message size in bytes.
Definition hkds_config.h:302
#define HKDS_NAME_SIZE
Internal: The formal algorithm name size in bytes.
Definition hkds_config.h:308
#define HKDS_TAG_SIZE
The size of the authentication tag (MAC) in bytes.
Definition hkds_config.h:314
hkds_error_type
Enumerates the error types for HKDS packet communications.
Definition hkds_config.h:119
@ error_connection_aborted
Definition hkds_config.h:121
@ error_connection_failure
Definition hkds_config.h:126
@ error_connection_refused
Definition hkds_config.h:123
@ error_unkown_failure
Definition hkds_config.h:127
@ error_disconnected
Definition hkds_config.h:122
@ error_general_failure
Definition hkds_config.h:120
@ error_invalid_format
Definition hkds_config.h:124
@ error_retries_exceeded
Definition hkds_config.h:125
hkds_packet_type
Enumerates the types of packets used in HKDS communications.
Definition hkds_config.h:79
@ packet_administrative_message
Definition hkds_config.h:84
@ packet_error_message
Definition hkds_config.h:85
@ packet_token_request
Definition hkds_config.h:80
@ packet_token_response
Definition hkds_config.h:81
@ packet_message_response
Definition hkds_config.h:83
@ packet_message_request
Definition hkds_config.h:82
#define HKDS_ERROR_SIZE
The error message size in bytes.
Definition hkds_config.h:278
hkds_protocol_id
Enumerates the supported cryptographic protocol identifiers.
Definition hkds_config.h:98
@ protocol_shake_128
Definition hkds_config.h:99
@ protocol_shake_256
Definition hkds_config.h:100
@ protocol_shake_512
Definition hkds_config.h:101
hkds_message_type
Enumerates the HKDS packet message types.
Definition hkds_config.h:143
@ message_reserved1
Definition hkds_config.h:149
@ message_diagnostic
Definition hkds_config.h:148
@ message_reinitialized_token
Definition hkds_config.h:145
@ message_reserved2
Definition hkds_config.h:150
@ message_reserved3
Definition hkds_config.h:151
@ message_synchronize_token
Definition hkds_config.h:144
@ message_token_requests_exceeded
Definition hkds_config.h:146
@ message_remote_reset
Definition hkds_config.h:147
#define HKDS_ETOK_SIZE
The encrypted token (server response) size for SHAKE-256 in bytes.
Definition hkds_config.h:397
#define HKDS_KSN_SIZE
The Key Serial Number (KSN) size in bytes.
Definition hkds_config.h:296
#define HKDS_ADMIN_SIZE
The size of the administrative message in bytes.
Definition hkds_config.h:218
Represents an administrative message packet.
Definition hkds_config.h:639
hkds_packet_header header
Definition hkds_config.h:640
uint8_t message[HKDS_ADMIN_SIZE]
Definition hkds_config.h:641
Represents the client's encrypted message request packet.
Definition hkds_config.h:573
hkds_packet_header header
Definition hkds_config.h:574
uint8_t ksn[HKDS_KSN_SIZE]
Definition hkds_config.h:575
uint8_t message[HKDS_MESSAGE_SIZE]
Definition hkds_config.h:576
uint8_t tag[HKDS_TAG_SIZE]
Definition hkds_config.h:577
Represents the client token request packet.
Definition hkds_config.h:591
hkds_packet_header header
Definition hkds_config.h:592
uint8_t ksn[HKDS_KSN_SIZE]
Definition hkds_config.h:593
Represents an error message packet.
Definition hkds_config.h:654
hkds_packet_header header
Definition hkds_config.h:655
uint8_t message[HKDS_ERROR_SIZE]
Definition hkds_config.h:656
The primary header for all HKDS messages.
Definition hkds_config.h:554
uint8_t length
Definition hkds_config.h:558
uint8_t sequence
Definition hkds_config.h:557
hkds_protocol_id protocol
Definition hkds_config.h:556
hkds_packet_type flag
Definition hkds_config.h:555
Represents the server's plaintext message response packet.
Definition hkds_config.h:607
hkds_packet_header header
Definition hkds_config.h:608
uint8_t message[HKDS_MESSAGE_SIZE]
Definition hkds_config.h:609
Represents the server's token response packet.
Definition hkds_config.h:623
hkds_packet_header header
Definition hkds_config.h:624
uint8_t etok[HKDS_ETOK_SIZE]
Definition hkds_config.h:625