QSC Post Quantum Cryptographic Library 1.3.0.0 (C1)
A post quantum secure library written in Ansi C
Loading...
Searching...
No Matches
x509key.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
52#ifndef QSC_X509_KEY_H
53#define QSC_X509_KEY_H
54
55#include "qsccommon.h"
56#include "x509types.h"
57
74
75
80#define QSC_X509_EDDSA_SEED_SIZE 32U
81
86#define QSC_X509_EDDSA_PUBLIC_KEY_SIZE 32U
87
92#define QSC_X509_ML_DSA_44_PRIVATEKEY_SIZE 2560U
93
98#define QSC_X509_ML_DSA_65_PRIVATEKEY_SIZE 4032U
99
104#define QSC_X509_ML_DSA_87_PRIVATEKEY_SIZE 4896U
105
110#define QSC_X509_ML_KEM_512_PRIVATEKEY_SIZE 1632U
111
116#define QSC_X509_ML_KEM_768_PRIVATEKEY_SIZE 2400U
117
122#define QSC_X509_ML_KEM_1024_PRIVATEKEY_SIZE 3168U
123
124#ifndef QSC_X509_ML_DSA_44_PUBLICKEY_SIZE
129#define QSC_X509_ML_DSA_44_PUBLICKEY_SIZE 1312U
130#endif
131
132#ifndef QSC_X509_ML_DSA_65_PUBLICKEY_SIZE
137#define QSC_X509_ML_DSA_65_PUBLICKEY_SIZE 1952U
138#endif
139
140#ifndef QSC_X509_ML_DSA_87_PUBLICKEY_SIZE
145#define QSC_X509_ML_DSA_87_PUBLICKEY_SIZE 2592U
146#endif
147
148#ifndef QSC_X509_ML_KEM_512_PUBLICKEY_SIZE
153#define QSC_X509_ML_KEM_512_PUBLICKEY_SIZE 800U
154#endif
155
156#ifndef QSC_X509_ML_KEM_768_PUBLICKEY_SIZE
161#define QSC_X509_ML_KEM_768_PUBLICKEY_SIZE 1184U
162#endif
163
164#ifndef QSC_X509_ML_KEM_1024_PUBLICKEY_SIZE
169#define QSC_X509_ML_KEM_1024_PUBLICKEY_SIZE 1568U
170#endif
171
172QSC_CPLUSPLUS_ENABLED_START
173
182#define QSC_X509_PRIVATE_KEY_MAX QSC_X509_ML_DSA_87_PRIVATEKEY_SIZE
183
192#define QSC_X509_PRIVATE_KEY_PUBLIC_MAX QSC_X509_SPKI_MAX
193
205{
206 qsc_x509_algorithm_identifier algorithm;
207 uint8_t privatekey[QSC_X509_PRIVATE_KEY_MAX];
213
226
241
256
271
286
299
314
315QSC_EXPORT_API size_t qsc_x509_private_key_expected_private_size(const qsc_x509_algorithm_identifier* algorithm);
316
329QSC_EXPORT_API size_t qsc_x509_private_key_expected_public_size(const qsc_x509_algorithm_identifier* algorithm);
330
355QSC_EXPORT_API qsc_asn1_status qsc_x509_private_key_decode_pkcs8_der_ex(const uint8_t* data, size_t datalen, qsc_x509_algorithm_identifier* algorithm,
356 uint8_t* privatekey, size_t privatekeycapacity, size_t* privatekeylen,
357 uint8_t* publickey, size_t publickeycapacity, size_t* publickeylen, bool* publickeypresent);
358
382QSC_EXPORT_API qsc_asn1_status qsc_x509_private_key_decode_pkcs8_pem_ex(const char* pem, size_t pemlen, qsc_x509_algorithm_identifier* algorithm,
383 uint8_t* privatekey, size_t privatekeycapacity, size_t* privatekeylen,
384 uint8_t* publickey, size_t publickeycapacity, size_t* publickeylen, bool* publickeypresent);
385
398QSC_EXPORT_API bool qsc_x509_certificate_key_match(const qsc_x509_certificate* certificate, const qsc_x509_private_key* key);
399
400QSC_CPLUSPLUS_ENABLED_END
401
402#endif
enum qsc_asn1_status_t qsc_asn1_status
ASN.1 helper status codes.
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
Definition x509key.h:205
uint8_t publickey[QSC_X509_PRIVATE_KEY_PUBLIC_MAX]
Definition x509key.h:209
qsc_x509_algorithm_identifier algorithm
Definition x509key.h:206
size_t privatekeylen
Definition x509key.h:208
bool publickey_present
Definition x509key.h:211
size_t publickeylen
Definition x509key.h:210
uint8_t privatekey[QSC_X509_PRIVATE_KEY_MAX]
Definition x509key.h:207
A decoded private key object with optional embedded public key material.
QSC_EXPORT_API qsc_asn1_status qsc_x509_private_key_decode_sec1_pem(const char *pem, size_t pemlen, qsc_x509_private_key *key)
Decode a SEC 1 PEM private key.
Definition x509key.c:1049
QSC_EXPORT_API qsc_asn1_status qsc_x509_private_key_validate(const qsc_x509_private_key *key)
Get the expected private key size for an algorithm identifier.
Definition x509key.c:732
QSC_EXPORT_API qsc_asn1_status qsc_x509_private_key_decode_pkcs8_der(const uint8_t *data, size_t datalen, qsc_x509_private_key *key)
Decode a PKCS #8 DER private key.
Definition x509key.c:1068
QSC_EXPORT_API size_t qsc_x509_private_key_expected_public_size(const qsc_x509_algorithm_identifier *algorithm)
Get the expected public key size for an algorithm identifier.
Definition x509key.c:829
QSC_EXPORT_API qsc_asn1_status qsc_x509_private_key_decode_sec1_der(const uint8_t *data, size_t datalen, qsc_x509_private_key *key)
Decode a SEC 1 DER private key.
Definition x509key.c:1004
#define QSC_X509_PRIVATE_KEY_PUBLIC_MAX
The maximum supported embedded public key length in bytes.
Definition x509key.h:192
QSC_EXPORT_API void qsc_x509_private_key_initialize(qsc_x509_private_key *key)
Initialize a private-key container.
Definition x509key.c:994
QSC_EXPORT_API qsc_asn1_status qsc_x509_private_key_decode_pkcs8_pem_ex(const char *pem, size_t pemlen, qsc_x509_algorithm_identifier *algorithm, uint8_t *privatekey, size_t privatekeycapacity, size_t *privatekeylen, uint8_t *publickey, size_t publickeycapacity, size_t *publickeylen, bool *publickeypresent)
Decode a PKCS #8 PEM private key into caller-supplied buffers.
Definition x509key.c:947
QSC_EXPORT_API qsc_asn1_status qsc_x509_private_key_decode_pkcs8_der_ex(const uint8_t *data, size_t datalen, qsc_x509_algorithm_identifier *algorithm, uint8_t *privatekey, size_t privatekeycapacity, size_t *privatekeylen, uint8_t *publickey, size_t publickeycapacity, size_t *publickeylen, bool *publickeypresent)
Decode a PKCS #8 DER private key into caller-supplied buffers.
Definition x509key.c:890
QSC_EXPORT_API bool qsc_x509_certificate_key_match(const qsc_x509_certificate *certificate, const qsc_x509_private_key *key)
Test whether a certificate matches a private key object.
Definition x509key.c:1127
QSC_EXPORT_API qsc_asn1_status qsc_x509_private_key_decode_pkcs8_pem(const char *pem, size_t pemlen, qsc_x509_private_key *key)
Decode a PKCS #8 PEM private key.
Definition x509key.c:1108