XMSS Library
structures.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 
16 #pragma once
17 
18 #ifndef XMSS_STRUCTURES_H_INCLUDED
20 #define XMSS_STRUCTURES_H_INCLUDED
21 
22 #include "compat.h"
23 #include "opaque_structures.h"
24 #include "types.h"
25 
41  size_t data_size;
43  uint8_t data[];
45 
50 #define XMSS_PRIVATE_KEY_STATELESS_BLOB_SIZE \
51  (sizeof(XmssPrivateKeyStatelessBlob) + sizeof(XmssValue256) + 4 + 4 + 4 + 4 + XMSS_PRIVATE_KEY_STATELESS_PART_SIZE)
52 
68  size_t data_size;
70  uint8_t data[];
72 
77 #define XMSS_PRIVATE_KEY_STATEFUL_BLOB_SIZE \
78  (sizeof(XmssPrivateKeyStatefulBlob) + sizeof(XmssValue256) + 4 + 4 + 4 + 4 + sizeof(XmssValue256) + \
79  2 * XMSS_PRIVATE_KEY_STATEFUL_PART_SIZE)
80 
94 typedef struct XmssPublicKeyInternalBlob {
96  size_t data_size;
98  uint8_t data[];
100 
112 #define XMSS_PUBLIC_KEY_INTERNAL_BLOB_SIZE(cache_type, cache_level, param_set) \
113  (sizeof(XmssPublicKeyInternalBlob) + sizeof(XmssValue256) + 4u + 4u + sizeof(XmssValue256) + sizeof(XmssValue256) + \
114  4u + 4u + 4u + 4u + sizeof(XmssValue256) * XMSS_CACHE_ENTRY_COUNT(cache_type, cache_level, param_set))
115 
116 
126 typedef struct XmssPublicKey {
139 } XmssPublicKey;
140 
148 #define XMSS_PUBLIC_KEY_SIZE \
149  (sizeof(XmssPublicKey))
150 
160 typedef struct XmssSignature {
169  uint32_t leaf_index;
182 } XmssSignature;
183 
194 typedef struct XmssSignatureBlob {
205  size_t data_size;
211  uint8_t data[];
213 
221 static inline XmssSignature *xmss_get_signature_struct(const XmssSignatureBlob *const signature)
222 {
223  if (signature == NULL) {
224  return NULL;
225  }
226  return (XmssSignature *)signature->data;
227 }
228 
239 #define XMSS_SIGNATURE_SIZE(param_set) \
240  (sizeof(XmssSignature) + sizeof(XmssValue256) * XMSS_TREE_DEPTH(param_set))
241 
250 #define XMSS_SIGNATURE_BLOB_SIZE(param_set) \
251  (sizeof(XmssSignatureBlob) + XMSS_SIGNATURE_SIZE(param_set))
252 
254 XMSS_STATIC_ASSERT(sizeof(XmssSignatureBlob) + sizeof(XmssSignature) + 10 * sizeof(XmssValue256)
255  == XMSS_SIGNATURE_BLOB_SIZE(XMSS_PARAM_SHA2_10_256), "XMSS_SIGNATURE_BLOB_SIZE mismatch");
257 XMSS_STATIC_ASSERT(sizeof(XmssSignatureBlob) + sizeof(XmssSignature) + 16 * sizeof(XmssValue256)
258  == XMSS_SIGNATURE_BLOB_SIZE(XMSS_PARAM_SHA2_16_256), "XMSS_SIGNATURE_BLOB_SIZE mismatch");
259 
261 #define XMSS_VERIFICATION_CONTEXT_SIZE (4 + 4 + 8 + 8 + 200 + 8 + 32)
262 
267 typedef union XmssVerificationContext {
271  uint64_t alignment;
273 
274 #endif /* !XMSS_STRUCTURES_H_INCLUDED */
C99 compatibility layer.
#define XMSS_STATIC_ASSERT(cond, msg)
Syntactical equivalent of _Static_assert(), which is C11.
Definition: compat.h:40
Public definitions of opaque structures and memory management calls for those.
A stored stateful private key part.
Definition: structures.h:66
uint8_t data[]
The data to be stored.
Definition: structures.h:70
size_t data_size
The size in bytes of the data array.
Definition: structures.h:68
A stored stateless private key part.
Definition: structures.h:39
size_t data_size
The size in bytes of the data array.
Definition: structures.h:41
uint8_t data[]
The data to be stored.
Definition: structures.h:43
A stored public key for the signing library.
Definition: structures.h:94
size_t data_size
The size in bytes of the data array.
Definition: structures.h:96
uint8_t data[]
The data to be stored.
Definition: structures.h:98
Exportable format for a public key.
Definition: structures.h:126
uint32_t scheme_identifier
The XmssParameterSetOID with which this public key was generated.
Definition: structures.h:134
XmssValue256 root
The public key root.
Definition: structures.h:136
XmssValue256 seed
The public SEED.
Definition: structures.h:138
Structure that embeds the exportable format for a signature, along with the signature's data size.
Definition: structures.h:194
size_t data_size
The size in bytes of the exported signature.
Definition: structures.h:205
uint8_t data[]
The signature data in the format described by RFC 8391, Section 4.1.8. This will always contain one s...
Definition: structures.h:211
Exportable format for a signature.
Definition: structures.h:160
XmssValue256 authentication_path[]
The authentication path.
Definition: structures.h:181
XmssValue256 wots_signature[67]
The WOTS+ signature.
Definition: structures.h:173
XmssValue256 random_bytes
The randomized hashing string $r$.
Definition: structures.h:171
uint32_t leaf_index
The leaf index of the key that was used for generating the signature. If index obfuscation is used,...
Definition: structures.h:169
A generic 256-bit value, represented as a byte stream.
Definition: types.h:279
#define XMSS_SIGNATURE_BLOB_SIZE(param_set)
The size in bytes of an XmssSignatureBlob.
Definition: structures.h:250
static XmssSignature * xmss_get_signature_struct(const XmssSignatureBlob *const signature)
Provide access to an XmssSignatureBlob's data as a structured type.
Definition: structures.h:221
#define XMSS_VERIFICATION_CONTEXT_SIZE
Size of an XmssVerificationContext.
Definition: structures.h:261
Enumerations, basic types and callback function specifications.
@ XMSS_PARAM_SHA2_16_256
SHA-256, tree height 16.
Definition: types.h:191
@ XMSS_PARAM_SHA2_10_256
SHA-256, tree height 10.
Definition: types.h:188
The context for signature verification.
Definition: structures.h:267
uint8_t data[XMSS_VERIFICATION_CONTEXT_SIZE]
Content of the XmssVerificationContext, opaque to the library user.
Definition: structures.h:269
uint64_t alignment
Enforces alignment of data.
Definition: structures.h:271