HKDS: Heirarchal Key Derivation System 1.0.0.2 (A2)
A fast post-quantum secure replacement for DUKPT
hkds_queue.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_MESSAGE_QUEUE_H
41#define HKDS_MESSAGE_QUEUE_H
42
43#include "common.h"
44#include "hkds_config.h"
45
56
61#define HKDS_MESSAGE_QUEUE_TAG_SIZE 16
62
67#define HKDS_QUEUE_ALIGNMENT 64
68
73#define HKDS_QUEUE_MAX_DEPTH 64
74
86HKDS_EXPORT_API typedef struct hkds_queue_state
87{
88 uint8_t** queue;
90 size_t count;
91 size_t depth;
92 size_t position;
93 size_t width;
95
108
119
130HKDS_EXPORT_API void hkds_message_queue_flush(hkds_message_queue_state* ctx, uint8_t* output);
131
144HKDS_EXPORT_API void hkds_message_queue_initialize(hkds_message_queue_state* ctx, size_t depth, size_t width, uint8_t* tag);
145
157HKDS_EXPORT_API void hkds_message_queue_pop(hkds_message_queue_state* ctx, uint8_t* output, size_t outlen);
158
169HKDS_EXPORT_API void hkds_message_queue_push(hkds_message_queue_state* ctx, const uint8_t* inpput, size_t inplen);
170
180HKDS_EXPORT_API bool hkds_message_queue_full(const hkds_message_queue_state* ctx);
181
191HKDS_EXPORT_API bool hkds_message_queue_empty(const hkds_message_queue_state* ctx);
192
202HKDS_EXPORT_API size_t hkds_message_queue_count(const hkds_message_queue_state* ctx);
203
204/* block message export */
205
218
231
243HKDS_EXPORT_API size_t hkds_message_queue_extract_stream(hkds_message_queue_state* ctx, uint8_t* stream, size_t items);
244
245#endif
HKDS configuration definitions.
#define HKDS_MESSAGE_SIZE
The encrypted message size in bytes.
Definition hkds_config.h:302
#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
HKDS_EXPORT_API size_t hkds_message_queue_count(const hkds_message_queue_state *ctx)
Returns the number of items in the queue.
Definition hkds_queue.c:169
HKDS_EXPORT_API void hkds_message_queue_pop(hkds_message_queue_state *ctx, uint8_t *output, size_t outlen)
Removes an item from the queue and copies it to the output array.
Definition hkds_queue.c:79
HKDS_EXPORT_API void hkds_message_queue_initialize(hkds_message_queue_state *ctx, size_t depth, size_t width, uint8_t *tag)
Initializes the queue state context.
Definition hkds_queue.c:50
HKDS_EXPORT_API bool hkds_message_queue_full(const hkds_message_queue_state *ctx)
Checks if the queue is full.
Definition hkds_queue.c:137
HKDS_EXPORT_API void hkds_message_queue_push(hkds_message_queue_state *ctx, const uint8_t *inpput, size_t inplen)
Adds an item to the queue.
Definition hkds_queue.c:115
HKDS_EXPORT_API size_t hkds_message_queue_extract_block_x8(hkds_message_queue_state *ctx, uint8_t output[HKDS_CACHX8_DEPTH][HKDS_MESSAGE_SIZE])
Exports a block of 8 messages to a 2-dimensional message queue.
Definition hkds_queue.c:187
HKDS_EXPORT_API bool hkds_message_queue_empty(const hkds_message_queue_state *ctx)
Checks if the queue is empty.
Definition hkds_queue.c:153
HKDS_EXPORT_API size_t hkds_message_queue_extract_block_x64(hkds_message_queue_state *ctx, uint8_t output[HKDS_PARALLEL_DEPTH][HKDS_CACHX8_DEPTH][HKDS_MESSAGE_SIZE])
Exports 8 slots (8 blocks of messages) to a 3-dimensional message queue.
Definition hkds_queue.c:204
HKDS_EXPORT_API void hkds_message_queue_destroy(hkds_message_queue_state *ctx)
Resets the queue context state.
Definition hkds_queue.c:4
#define HKDS_QUEUE_MAX_DEPTH
The maximum queue depth.
Definition hkds_queue.h:73
HKDS_EXPORT_API size_t hkds_message_queue_extract_stream(hkds_message_queue_state *ctx, uint8_t *stream, size_t items)
Serializes a set of messages from the queue to a linear array.
Definition hkds_queue.c:228
HKDS_EXPORT_API void hkds_message_queue_flush(hkds_message_queue_state *ctx, uint8_t *output)
Flushes the contents of the queue to a byte array.
Definition hkds_queue.c:28
Contains the HKDS message queue context state.
Definition hkds_queue.h:104
uint8_t * tag
Definition hkds_queue.h:105
hkds_queue_state state
Definition hkds_queue.h:106
Contains the queue context state.
Definition hkds_queue.h:87
size_t width
Definition hkds_queue.h:93
size_t count
Definition hkds_queue.h:90
size_t position
Definition hkds_queue.h:92
size_t depth
Definition hkds_queue.h:91
uint8_t ** queue
Definition hkds_queue.h:88
uint64_t tags[HKDS_QUEUE_MAX_DEPTH]
Definition hkds_queue.h:89