XMSS Library
types.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2022 Fox Crypto B.V.
3  * SPDX-License-Identifier: MIT
4  *
5  * SPDX-FileContributor: Thomas Schaap
6  */
7 
17 #pragma once
18 
19 #ifndef XMSS_TYPES_H_INCLUDED
21 #define XMSS_TYPES_H_INCLUDED
22 
23 #include <stddef.h>
24 #include <stdint.h>
25 
26 #include "compat.h"
27 
39 {
42 
45 
48 
51 
54 
57 
60 
63 
66 
69 
72 
75 
78 
81 
84 
87 };
88 
102 typedef enum XmssError
103 {
104  /* NOTE to developers
105  * ==================
106  *
107  * Keep the enumeration-constants synchronized with xmss_error_to_name().
108  * Keep the Doxygen descriptions for the enumeration-constants synchronized with xmss_error_to_description().
109  */
110 
111  /* XMSS_DISTANT_VALUE_0 must not be used. */
112 
115 
118 
121 
124 
127 
130 
133 
136 
139 
142 
145 
148 
151 
160 
170 
186 {
189 
192 
195 
198 
201 
205 
214 #define XMSS_TREE_DEPTH(param_set) \
215  (((param_set) == XMSS_PARAM_SHA2_10_256 || (param_set) == XMSS_PARAM_SHAKE256_10_256) ? 10u : \
216  (((param_set) == XMSS_PARAM_SHA2_16_256 || (param_set) == XMSS_PARAM_SHAKE256_16_256) ? 16u : \
217  (((param_set) == XMSS_PARAM_SHA2_20_256 || (param_set) == XMSS_PARAM_SHAKE256_20_256) ? 20u : \
218  0u /* Garbage in, 0 out */ \
219  ) \
220  ) \
221  )
222 
228 {
231 
235 
240 typedef enum XmssCacheType
241 {
244 
264 
279 typedef struct XmssValue256 {
281  uint8_t data[32];
282 } XmssValue256;
283 
291 #define XMSS_VALUE_256_WORDS 8
292 
294 XMSS_STATIC_ASSERT(XMSS_VALUE_256_WORDS == sizeof(XmssValue256) / sizeof(uint32_t),
295  "inconsistent value of XMSS_VALUE_256_WORDS");
296 
316 typedef struct XmssNativeValue256 {
320 
323  "XmssNativeValue256 and XmssValue256 should have equal size");
324 
329 typedef struct XmssBuffer {
331  size_t data_size;
333  uint8_t *data;
334 } XmssBuffer;
335 
354 typedef void *(*XmssReallocFunction)(void *ptr, size_t size);
355 
371 typedef void (*XmssFreeFunction)(void *ptr);
372 
383 typedef void (*XmssZeroizeFunction)(void *ptr, size_t size);
384 
385 #endif /* !XMSS_TYPES_H_INCLUDED */
C99 compatibility layer.
#define XMSS_STATIC_ASSERT(cond, msg)
Syntactical equivalent of _Static_assert(), which is C11.
Definition: compat.h:40
A pointer to a buffer with a given size.
Definition: types.h:329
size_t data_size
The size in bytes of data.
Definition: types.h:331
uint8_t * data
The data. May be NULL if and only if data_size is 0.
Definition: types.h:333
The internal (native) representation of a 256-bit value.
Definition: types.h:316
uint32_t data[XMSS_VALUE_256_WORDS]
The contents of the value.
Definition: types.h:318
A generic 256-bit value, represented as a byte stream.
Definition: types.h:279
uint8_t data[32]
The byte stream representation of the value.
Definition: types.h:281
#define XMSS_VALUE_256_WORDS
The number of 32-bits words in an XmssValue256.
Definition: types.h:291
void(* XmssFreeFunction)(void *ptr)
A function to deallocate memory.
Definition: types.h:371
XmssError
The return codes for the functions in the XMSS library.
Definition: types.h:103
@ XMSS_ERR_INVALID_BLOB
A blob structure was found to be invalid.
Definition: types.h:129
@ XMSS_ERR_INVALID_SIGNATURE
The signature is invalid.
Definition: types.h:120
@ XMSS_ERR_INVALID_ARGUMENT
The value of an argument was invalid.
Definition: types.h:135
@ XMSS_ERR_PARTITIONS_NOT_CONSECUTIVE
Partitions are not consecutive.
Definition: types.h:147
@ XMSS_ERR_UNFINISHED_PARTITIONS
Not all key generation partition calculations were completed.
Definition: types.h:141
@ XMSS_ERR_ARGUMENT_MISMATCH
A mismatch was detected between arguments.
Definition: types.h:123
@ XMSS_ERR_TOO_FEW_SIGNATURES_AVAILABLE
There are not enough signatures available to allow the operation.
Definition: types.h:144
@ XMSS_ERR_ALLOC_ERROR
An error occurred with memory allocation.
Definition: types.h:126
@ XMSS_UNINITIALIZED
Function returned prematurely.
Definition: types.h:168
@ XMSS_OKAY
Success.
Definition: types.h:114
@ XMSS_ERR_NULL_POINTER
An unexpected NULL pointer was passed.
Definition: types.h:117
@ XMSS_ERR_NO_PUBLIC_KEY
The key context does not have a public key loaded.
Definition: types.h:150
@ XMSS_ERR_PARTITION_DONE
The calculations for the key generation partition were already performed.
Definition: types.h:138
@ XMSS_ERR_FAULT_DETECTED
A fault was detected.
Definition: types.h:159
@ XMSS_ERR_BAD_CONTEXT
The passed context is in an incorrect state.
Definition: types.h:132
XmssDistantValues
A list of Hamming(8,4) code words.
Definition: types.h:39
@ XMSS_DISTANT_VALUE_7
Code word 7: $00011110_2$.
Definition: types.h:62
@ XMSS_DISTANT_VALUE_6
Code word 6: $11001100_2$.
Definition: types.h:59
@ XMSS_DISTANT_VALUE_5
Code word 5: $01001011_2$.
Definition: types.h:56
@ XMSS_DISTANT_VALUE_D
Code word D: $10101010_2$.
Definition: types.h:80
@ XMSS_DISTANT_VALUE_9
Code word 9: $00110011_2$.
Definition: types.h:68
@ XMSS_DISTANT_VALUE_0
Code word 0: $00000000_2$.
Definition: types.h:41
@ XMSS_DISTANT_VALUE_F
Code word F: $11111111_2$.
Definition: types.h:86
@ XMSS_DISTANT_VALUE_C
Code word C: $01111000_2$.
Definition: types.h:77
@ XMSS_DISTANT_VALUE_A
Code word A: $10110100_2$.
Definition: types.h:71
@ XMSS_DISTANT_VALUE_B
Code word B: $01100110_2$.
Definition: types.h:74
@ XMSS_DISTANT_VALUE_2
Code word 2: $01010101_2$.
Definition: types.h:47
@ XMSS_DISTANT_VALUE_3
Code word 3: $10000111_2$.
Definition: types.h:50
@ XMSS_DISTANT_VALUE_E
Code word E: $00101101_2$.
Definition: types.h:83
@ XMSS_DISTANT_VALUE_4
Code word 4: $10011001_2$.
Definition: types.h:53
@ XMSS_DISTANT_VALUE_1
Code word 1: $11010010_2$.
Definition: types.h:44
@ XMSS_DISTANT_VALUE_8
Code word 8: $11100001_2$.
Definition: types.h:65
XmssCacheType
The type of caching to use.
Definition: types.h:241
@ XMSS_CACHE_NONE
No caching.
Definition: types.h:243
@ XMSS_CACHE_SINGLE_LEVEL
Single level caching.
Definition: types.h:253
@ XMSS_CACHE_TOP
Top caching.
Definition: types.h:262
void(* XmssZeroizeFunction)(void *ptr, size_t size)
A function to securely erase sensitive data.
Definition: types.h:383
XmssIndexObfuscationSetting
The supported settings for index obfuscation.
Definition: types.h:228
@ XMSS_INDEX_OBFUSCATION_ON
Index obfuscation is enabled.
Definition: types.h:233
@ XMSS_INDEX_OBFUSCATION_OFF
No index obfuscation.
Definition: types.h:230
XmssParameterSetOID
The XMSS parameter sets that are supported by this library.
Definition: types.h:186
@ XMSS_PARAM_SHAKE256_16_256
SHAKE256/256, tree height 16.
Definition: types.h:200
@ XMSS_PARAM_SHA2_16_256
SHA-256, tree height 16.
Definition: types.h:191
@ XMSS_PARAM_SHAKE256_20_256
SHAKE256/256, tree height 20.
Definition: types.h:203
@ XMSS_PARAM_SHA2_20_256
SHA-256, tree height 20.
Definition: types.h:194
@ XMSS_PARAM_SHAKE256_10_256
SHAKE256/256, tree height 10.
Definition: types.h:197
@ XMSS_PARAM_SHA2_10_256
SHA-256, tree height 10.
Definition: types.h:188