SIAP: Secure Infrastructure Access Protocol 1.0.0.0a (A1)
A post-quantum secure user verification system and access control mechanism
siap.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: contact@qrcscorp.ca
38 */
39
40#ifndef SIAP_H
41#define SIAP_H
42
43#include "siapcommon.h"
44#include "logger.h"
45#include "sha3.h"
46#include "socket.h"
47#include "socketclient.h"
48
54
59//#define SIAP_EXTENDED_ENCRYPTION
60
65#define SIAP_CLIENT_PASSWORD_MAX 256U
66
71#define SIAP_CLIENT_USERNAME_MAX 256U
72
77#define SIAP_CONFIG_SIZE 26U
78
83#define SIAP_DEVICE_ID_SIZE 4U
84
85#if defined(SIAP_EXTENDED_ENCRYPTION)
90# define SIAP_AUTHENTICATION_TOKEN_SIZE 64U
91#else
96# define SIAP_AUTHENTICATION_TOKEN_SIZE 32U
97#endif
98
103#define SIAP_DOMAIN_ID_SIZE 2U
104
109#define SIAP_ERROR_SIZE 1U
110
115#define SIAP_EXPIRATION_SIZE 8U
116
117#if defined(SIAP_EXTENDED_ENCRYPTION)
122# define SIAP_HASH_SIZE 64U
123#else
128# define SIAP_HASH_SIZE 32U
129#endif
130
135#define SIAP_KEY_DURATION_DAYS 365U
136
141#define SIAP_KEY_DURATION_SECONDS (SIAP_KEY_DURATION_DAYS * 24U * 60U * 60U)
142
147#define SIAP_KEY_ID_SIZE 4U
148
153#define SIAP_KTREE_COUNT 1024
154
155#if defined(SIAP_EXTENDED_ENCRYPTION)
160# define SIAP_KTAG_STATE_HASH 64U
161#else
166# define SIAP_KTAG_STATE_HASH 32U
167#endif
168
169#if defined(SIAP_EXTENDED_ENCRYPTION)
174# define SIAP_MAC_SIZE 64U
175#else
180# define SIAP_MAC_SIZE 32U
181#endif
182
187#define SIAP_NONCE_SIZE 32U
188
189#if defined(SIAP_EXTENDED_ENCRYPTION)
194# define SIAP_SALT_SIZE 64U
195#else
200# define SIAP_SALT_SIZE 32U
201#endif
202
207#define SIAP_SERVER_GROUP_ID_SIZE 2U
208
213#define SIAP_SERVER_ID_SIZE 2U
214
215#if defined(SIAP_EXTENDED_ENCRYPTION)
220# define SIAP_SERVER_KEY_SIZE 64U
221#else
226# define SIAP_SERVER_KEY_SIZE 32U
227#endif
228
233#define SIAP_USER_GROUP_ID_SIZE 2U
234
239#define SIAP_USER_ID_SIZE 4U
240
241/* compound sizes */
242
247#define SIAP_DID_SIZE (SIAP_DOMAIN_ID_SIZE + SIAP_SERVER_GROUP_ID_SIZE + SIAP_SERVER_ID_SIZE + SIAP_USER_GROUP_ID_SIZE + SIAP_USER_ID_SIZE + SIAP_DEVICE_ID_SIZE)
248
253#define SIAP_SID_SIZE (SIAP_DOMAIN_ID_SIZE + SIAP_SERVER_GROUP_ID_SIZE + SIAP_SERVER_ID_SIZE)
254
259#define SIAP_KID_SIZE (SIAP_DID_SIZE + SIAP_KEY_ID_SIZE)
260
265#define SIAP_KTREE_SIZE (SIAP_AUTHENTICATION_TOKEN_SIZE * SIAP_KTREE_COUNT)
266
271#define SIAP_DEVICE_KEY_ENCODED_SIZE ((SIAP_AUTHENTICATION_TOKEN_SIZE * SIAP_KTREE_COUNT) + SIAP_MAC_SIZE + SIAP_KID_SIZE + SIAP_EXPIRATION_SIZE)
272
277#define SIAP_DEVICE_TAG_ENCODED_SIZE (SIAP_KID_SIZE + SIAP_KTAG_STATE_HASH + SIAP_HASH_SIZE)
278
283#define SIAP_SERVER_KEY_ENCODED_SIZE (SIAP_SERVER_KEY_SIZE + SIAP_SID_SIZE + SIAP_SERVER_KEY_SIZE + SIAP_EXPIRATION_SIZE)
284
285/* error code strings */
286
287#if defined(SIAP_EXTENDED_ENCRYPTION)
291static const char SIAP_CONFIG_STRING[SIAP_CONFIG_SIZE + 1U] = "r01-siap-rcs512-keccak512";
292#else
296static const char SIAP_CONFIG_STRING[SIAP_CONFIG_SIZE + 1U] = "r02-siap-rcs256-keccak256";
297#endif
298
300#define SIAP_ERROR_STRING_DEPTH 12U
301#define SIAP_ERROR_STRING_WIDTH 128U
302
303static const char SIAP_ERROR_STRINGS[SIAP_ERROR_STRING_DEPTH][SIAP_ERROR_STRING_WIDTH] =
304{
305 "The operation was succesful",
306 "The authentication has failed",
307 "The identity strings do not match",
308 "The key card has expired",
309 "The device passphrase is unrecognized",
310 "The cards authentication tokens are invalid",
311 "The key card decryption failed",
312 "The authentication token is invalid",
313 "The server could not generate the token",
314 "The file could not be read",
315 "The file path specified is invalid",
316 "The file is locked or unavailable",
317};
319
340
346SIAP_EXPORT_API typedef struct siap_device_key
347{
350 uint64_t expiration;
352
358SIAP_EXPORT_API typedef struct siap_device_tag
359{
364
370SIAP_EXPORT_API typedef struct siap_server_key
371{
375 uint64_t expiration;
377
385SIAP_EXPORT_API void siap_deserialize_device_key(siap_device_key* dkey, const uint8_t* input);
386
394SIAP_EXPORT_API void siap_serialize_device_key(uint8_t* output, const siap_device_key* dkey);
395
404SIAP_EXPORT_API const char* siap_error_to_string(siap_errors error);
405
413SIAP_EXPORT_API const char* siap_get_error_description(siap_errors emsg);
414
421SIAP_EXPORT_API void siap_log_error(siap_errors emsg, const char* msg);
422
428SIAP_EXPORT_API void siap_log_system_error(siap_errors err);
429
437SIAP_EXPORT_API void siap_deserialize_device_tag(siap_device_tag* dtag, const uint8_t* input);
438
446SIAP_EXPORT_API void siap_serialize_device_tag(uint8_t* output, const siap_device_tag* dtag);
447
455SIAP_EXPORT_API void siap_deserialize_server_key(siap_server_key* skey, const uint8_t* input);
456
464SIAP_EXPORT_API void siap_serialize_server_key(uint8_t* output, const siap_server_key* skey);
465
472SIAP_EXPORT_API void siap_increment_device_key(siap_device_key* dkey);
473
474#endif
SIAP logging functions.
#define SIAP_CONFIG_SIZE
The size of the protocol configuration string.
Definition siap.h:77
SIAP_EXPORT_API void siap_serialize_server_key(uint8_t *output, const siap_server_key *skey)
Serialize a server key into a byte array. This function serializes a SIAP server key structure into a...
Definition siap.c:94
SIAP_EXPORT_API void siap_deserialize_device_key(siap_device_key *dkey, const uint8_t *input)
Deserialize a client device key. This function deserializes a byte array into a SIAP device key struc...
Definition siap.c:7
#define SIAP_SALT_SIZE
The SIAP salt size in bytes.
Definition siap.h:200
SIAP_EXPORT_API void siap_log_system_error(siap_errors err)
Log a system error message.
Definition siap.c:141
#define SIAP_KTREE_SIZE
The key tree size in bytes.
Definition siap.h:265
#define SIAP_SID_SIZE
The server ID size in bytes.
Definition siap.h:253
#define SIAP_HASH_SIZE
The SIAP hash size in bytes.
Definition siap.h:128
SIAP_EXPORT_API const char * siap_error_to_string(siap_errors error)
Return a string description of an SIAP error code. This function returns a human-readable string corr...
Definition siap.c:178
#define SIAP_KTAG_STATE_HASH
The client key state hash size.
Definition siap.h:166
#define SIAP_SERVER_KEY_SIZE
The master key size in bytes.
Definition siap.h:226
#define SIAP_MAC_SIZE
The SIAP MAC size in bytes.
Definition siap.h:180
SIAP_EXPORT_API void siap_increment_device_key(siap_device_key *dkey)
Increment the device key This function clears a key at the current position and increments the kid co...
Definition siap.c:113
siap_errors
The SIAP error values. This enumeration defines the error codes returned by SIAP functions.
Definition siap.h:326
@ siap_error_decryption_failure
Definition siap.h:333
@ siap_error_none
Definition siap.h:327
@ siap_error_token_tree_invalid
Definition siap.h:332
@ siap_error_file_read_failure
Definition siap.h:336
@ siap_error_file_copy_failure
Definition siap.h:338
@ siap_error_identity_mismatch
Definition siap.h:329
@ siap_error_authentication_failure
Definition siap.h:328
@ siap_error_token_not_created
Definition siap.h:335
@ siap_error_key_expired
Definition siap.h:330
@ siap_error_token_invalid
Definition siap.h:334
@ siap_error_passphrase_unrecognized
Definition siap.h:331
@ siap_error_file_invalid_path
Definition siap.h:337
#define SIAP_KID_SIZE
The tree-key ID size in bytes.
Definition siap.h:259
SIAP_EXPORT_API const char * siap_get_error_description(siap_errors emsg)
Get the error string description.
Definition siap.c:126
SIAP_EXPORT_API void siap_serialize_device_tag(uint8_t *output, const siap_device_tag *dtag)
Serialize a device tag into a byte array. This function serializes a SIAP device tag structure into a...
Definition siap.c:58
SIAP_EXPORT_API void siap_log_error(siap_errors emsg, const char *msg)
Log the message, socket error, and string description.
Definition siap.c:154
SIAP_EXPORT_API void siap_deserialize_server_key(siap_server_key *skey, const uint8_t *input)
Deserialize a server key from a byte array. This function deserializes a byte array into a SIAP serve...
Definition siap.c:75
SIAP_EXPORT_API void siap_deserialize_device_tag(siap_device_tag *dtag, const uint8_t *input)
Deserialize a device tag from a byte array. This function deserializes a byte array into a SIAP devic...
Definition siap.c:41
SIAP_EXPORT_API void siap_serialize_device_key(uint8_t *output, const siap_device_key *dkey)
Serialize a client device key. This function serializes a SIAP device key structure into a byte array...
Definition siap.c:24
The SIAP device key structure. This structure contains the SIAP device key, the device key identity,...
Definition siap.h:347
uint8_t kid[SIAP_KID_SIZE]
Definition siap.h:349
uint64_t expiration
Definition siap.h:350
uint8_t ktree[SIAP_KTREE_SIZE+SIAP_MAC_SIZE]
Definition siap.h:348
Definition siap.h:359
uint8_t kid[SIAP_KID_SIZE]
Definition siap.h:360
uint8_t khash[SIAP_KTAG_STATE_HASH]
Definition siap.h:361
uint8_t phash[SIAP_HASH_SIZE]
Definition siap.h:362
The SIAP server key structure. This structure contains the SIAP server key, the server's domain ident...
Definition siap.h:371
uint64_t expiration
Definition siap.h:375
uint8_t kbase[SIAP_SERVER_KEY_SIZE]
Definition siap.h:372
uint8_t sid[SIAP_SID_SIZE]
Definition siap.h:373
uint8_t dsalt[SIAP_SALT_SIZE]
Definition siap.h:374