UDIF: Universal Digital Identification Framework
1.0.0.0a (A1)
A quantum-secure cryptographic identification
encode.h
Go to the documentation of this file.
1
/* 2025-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 UDIF_ENCODE_H
53
#define UDIF_ENCODE_H
54
55
#include "
udif.h
"
56
72
74
//
76
//#define UDIF_TLV_CERT_SUITE_ID 1U
77
//#define UDIF_TLV_CERT_ROLE 2U
78
//#define UDIF_TLV_CERT_SERIAL 3U
79
//#define UDIF_TLV_CERT_ISSUER_SERIAL 4U
80
//#define UDIF_TLV_CERT_VALID_FROM 5U
81
//#define UDIF_TLV_CERT_VALID_TO 6U
82
//#define UDIF_TLV_CERT_PUBKEY 7U
83
//#define UDIF_TLV_CERT_POLICY_EPOCH 8U
84
//#define UDIF_TLV_CERT_CAP_BITMAP 9U
85
//#define UDIF_TLV_CERT_SIGNATURE 10U
86
//
88
//#define UDIF_TLV_CAP_VERBS 1U
89
//#define UDIF_TLV_CAP_SCOPES 2U
90
//#define UDIF_TLV_CAP_ISSUED_TO 3U
91
//#define UDIF_TLV_CAP_ISSUED_BY 4U
92
//#define UDIF_TLV_CAP_VALID_TO 5U
93
//#define UDIF_TLV_CAP_POLICY_EPOCH 6U
94
//#define UDIF_TLV_CAP_DIGEST 7U
95
//#define UDIF_TLV_CAP_TAG 8U
96
//
98
//#define UDIF_TLV_OBJ_SERIAL 1U
99
//#define UDIF_TLV_OBJ_TYPE_CODE 2U
100
//#define UDIF_TLV_OBJ_CREATOR_CERT 3U
101
//#define UDIF_TLV_OBJ_ATTR_ROOT 4U
102
//#define UDIF_TLV_OBJ_CURRENT_OWNER 5U
103
//#define UDIF_TLV_OBJ_CREATED_AT 6U
104
//#define UDIF_TLV_OBJ_UPDATED_AT 7U
105
//#define UDIF_TLV_OBJ_FLAGS 8U
106
//#define UDIF_TLV_OBJ_SIGNATURE 9U
107
//
109
//#define UDIF_TLV_ANCHOR_CHILD_SERIAL 1U
110
//#define UDIF_TLV_ANCHOR_SEQ 2U
111
//#define UDIF_TLV_ANCHOR_TIMESTAMP 3U
112
//#define UDIF_TLV_ANCHOR_REGROOT 4U
113
//#define UDIF_TLV_ANCHOR_TXROOT 5U
114
//#define UDIF_TLV_ANCHOR_MROOT 6U
115
//#define UDIF_TLV_ANCHOR_REG_COUNT 7U
116
//#define UDIF_TLV_ANCHOR_TX_COUNT 8U
117
//#define UDIF_TLV_ANCHOR_MEM_COUNT 9U
118
//#define UDIF_TLV_ANCHOR_SIGNATURE 10U
119
//
120
//#define UDIF_CERT_SUITE_ID_ENCODED_SIZE 3U
121
//#define UDIF_CERT_ROLE_ENCODED_SIZE 3U
122
//#define UDIF_CERT_SERIAL_ENCODED_SIZE 18U
123
//#define UDIF_CERT_VALID_FROM_ENCODED_SIZE 10U
124
//#define UDIF_CERT_VALID_TO_ENCODED_SIZE 10U
125
//#define UDIF_CERT_PUBLIC_KEY_ENCODED_SIZE (UDIF_ASYMMETRIC_VERIFICATION_KEY_SIZE + 2U)
126
//#define UDIF_CERT_POLICY_ENCODED_EPOCH 6U
127
//#define UDIF_CERT_CAP_BITMAP_ENCODED_EPOCH 10U
128
//
129
//#define UDIF_ENCODED_CERTIFICATE_SIZE (UDIF_CERT_SUITE_ID_ENCODED_SIZE + UDIF_CERT_ROLE_ENCODED_SIZE + UDIF_CERT_SERIAL_ENCODED_SIZE + \
130
// UDIF_CERT_SERIAL_ENCODED_SIZE + UDIF_CERT_VALID_FROM_ENCODED_SIZE + UDIF_CERT_VALID_TO_ENCODED_SIZE + UDIF_CERT_PUBLIC_KEY_ENCODED_SIZE + \
131
// UDIF_CERT_POLICY_ENCODED_EPOCH + UDIF_CERT_CAP_BITMAP_ENCODED_EPOCH)
132
//
134
//* \brief Encode a uvarint
135
//*
136
//* Encodes a 64-bit value as a minimal-length uvarint.
137
//*
138
//* \param output: The output buffer (max 9 bytes)
139
//* \param value: The value to encode
140
//*
141
//* \return The number of bytes written
142
//*/
143
//UDIF_EXPORT_API size_t udif_encode_uvarint(uint8_t* output, uint64_t value);
144
//
146
//* \brief Decode a uvarint
147
//*
148
//* Decodes a uvarint from the input buffer.
149
//*
150
//* \param value: Pointer to receive the decoded value
151
//* \param input: [const] The input buffer
152
//* \param inlen: The input buffer length
153
//*
154
//* \return The number of bytes consumed (0 on error)
155
//*/
156
//UDIF_EXPORT_API size_t udif_decode_uvarint(uint64_t* value, const uint8_t* input, size_t inlen);
157
//
159
//* \brief Encode a TLV field
160
//*
161
//* Encodes a single TLV field to the output buffer.
162
//*
163
//* \param output: The output buffer
164
//* \param outlen: The output buffer length
165
//* \param tag: The field tag
166
//* \param value: [const] The field value
167
//* \param vallen: The value length
168
//*
169
//* \return The number of bytes written (0 on error)
170
//*/
171
//UDIF_EXPORT_API size_t udif_encode_tlv(uint8_t* output, size_t outlen, uint64_t tag, const uint8_t* value, size_t vallen);
172
//
174
//* \brief Decode a TLV field
175
//*
176
//* Decodes a single TLV field from the input buffer.
177
//*
178
//* \param tag: Pointer to receive the tag
179
//* \param value: Pointer to receive value pointer (points into input)
180
//* \param vallen: Pointer to receive value length
181
//* \param input: [const] The input buffer
182
//* \param inlen: The input buffer length
183
//* \param consumed: Pointer to receive bytes consumed
184
//*
185
//* \return Returns true on success
186
//*/
187
//UDIF_EXPORT_API bool udif_decode_tlv(uint64_t* tag, const uint8_t** value, size_t* vallen, const uint8_t* input, size_t inlen, size_t* consumed);
188
//
190
//* \brief Encode a uint8 value as TLV
191
//*
192
//* \param output: The output buffer
193
//* \param outlen: The output buffer length
194
//* \param tag: The field tag
195
//* \param value: The uint8 value
196
//*
197
//* \return The number of bytes written
198
//*/
199
//UDIF_EXPORT_API size_t udif_encode_tlv_uint8(uint8_t* output, size_t outlen, uint64_t tag, uint8_t value);
200
//
202
//* \brief Encode a uint32 value as TLV
203
//*
204
//* \param output: The output buffer
205
//* \param outlen: The output buffer length
206
//* \param tag: The field tag
207
//* \param value: The uint32 value
208
//*
209
//* \return The number of bytes written
210
//*/
211
//UDIF_EXPORT_API size_t udif_encode_tlv_uint32(uint8_t* output, size_t outlen, uint64_t tag, uint32_t value);
212
//
214
//* \brief Encode a uint64 value as TLV
215
//*
216
//* \param output: The output buffer
217
//* \param outlen: The output buffer length
218
//* \param tag: The field tag
219
//* \param value: The uint64 value
220
//*
221
//* \return The number of bytes written
222
//*/
223
//UDIF_EXPORT_API size_t udif_encode_tlv_uint64(uint8_t* output, size_t outlen, uint64_t tag, uint64_t value);
224
//
226
//* \brief Decode a uint8 value from TLV
227
//*
228
//* \param value: Pointer to receive the value
229
//* \param input: [const] The input buffer
230
//* \param inlen: The input buffer length
231
//* \param expected_tag: The expected tag value
232
//*
233
//* \return Returns true on success
234
//*/
235
//UDIF_EXPORT_API bool udif_decode_tlv_uint8(uint8_t* value, const uint8_t* input, size_t inlen, uint64_t expected_tag);
236
//
238
//* \brief Decode a uint32 value from TLV
239
//*
240
//* \param value: Pointer to receive the value
241
//* \param input: [const] The input buffer
242
//* \param inlen: The input buffer length
243
//* \param expected_tag: The expected tag value
244
//*
245
//* \return Returns true on success
246
//*/
247
//UDIF_EXPORT_API bool udif_decode_tlv_uint32(uint32_t* value, const uint8_t* input, size_t inlen, uint64_t expected_tag);
248
//
250
//* \brief Decode a uint64 value from TLV
251
//*
252
//* \param value: Pointer to receive the value
253
//* \param input: [const] The input buffer
254
//* \param inlen: The input buffer length
255
//* \param expected_tag: The expected tag value
256
//*
257
//* \return Returns true on success
258
//*/
259
//UDIF_EXPORT_API bool udif_decode_tlv_uint64(uint64_t* value, const uint8_t* input, size_t inlen, uint64_t expected_tag);
260
261
#endif
udif.h
UDIF Common Definitions and Protocol Configuration.
UDIF
Saved
encode.h
Generated by
1.14.0