Skip to content

Commit 31df0b2

Browse files
committed
Release 2.0.0
1 parent 29e0e12 commit 31df0b2

File tree

100 files changed

+4948
-2612
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+4948
-2612
lines changed

.reuse/dep5

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
22
Upstream-Name: xmss-library
3-
Source: https://github.com/foxcrypto/xmss-library
3+
Source: https://github.com/FoxCryptoNL/xmss-library
44

55
Files: docs/doxygen-awesome-css/*
66
Copyright: 2021-2023 jothepro

CMakeLists.txt

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# CMake 3.22.1 is the version installed with Ubuntu 22.04.1.
55
cmake_minimum_required(VERSION 3.22.1 FATAL_ERROR)
66

7-
project(xmss-library VERSION 1.0.0 LANGUAGES C)
7+
project(xmss-library VERSION 2.0.0 LANGUAGES C)
88

99
# All compiler options are in a separate file
1010
include("cmake/compiler_options.cmake")
@@ -47,6 +47,14 @@ else()
4747
endif()
4848
endif()
4949

50+
# When set to OFF (default), static libraries are built.
51+
# When set to ON, shared libraries are built.
52+
option(BUILD_SHARED_LIBS "Build shared libraries instead of static ones." OFF)
53+
54+
# When set to ON (default), both the full library (including signing) and a verification-only library are built.
55+
# When set to OFF, just the verification-only library is built.
56+
option(XMSS_ENABLE_SIGNING "Enable signing support in the library." ON)
57+
5058
# The C tests are part of the early validation of the compiler/platform combination with the XMSS library and must not
5159
# be disabled for normal testing or production builds.
5260
# The full test suite contains several tests that require hash overrides that will completely fail these tests, though.
@@ -65,12 +73,24 @@ else()
6573
set(XMSS_ENABLE_SHA256 ON)
6674
endif()
6775

76+
if(XMSS_SHA256 STREQUAL "Default")
77+
set(XMSS_ENABLE_SHA256_DEFAULT ON)
78+
else()
79+
set(XMSS_ENABLE_SHA256_DEFAULT OFF)
80+
endif()
81+
6882
if(XMSS_SHAKE256_256 STREQUAL "Disabled")
6983
set(XMSS_ENABLE_SHAKE256_256 OFF)
7084
else()
7185
set(XMSS_ENABLE_SHAKE256_256 ON)
7286
endif()
7387

88+
if(XMSS_SHAKE256_256 STREQUAL "Default")
89+
set(XMSS_ENABLE_SHAKE256_256_DEFAULT ON)
90+
else()
91+
set(XMSS_ENABLE_SHAKE256_256_DEFAULT OFF)
92+
endif()
93+
7494
if(NOT XMSS_ENABLE_SHA256 AND NOT XMSS_ENABLE_SHAKE256_256)
7595
message(FATAL_ERROR "XMSS_SHA256 and XMSS_SHAKE256_256 cannot be both Disabled.")
7696
endif()
@@ -139,7 +159,14 @@ try_compile(XMSS_CAN_USE_EXTENSION_STATIC_ASSERT ${CMAKE_CURRENT_BINARY_DIR}
139159
configure_file(include/xmss_config.in.h include/xmss_config.h NO_SOURCE_PERMISSIONS)
140160
configure_file(src/config.in.h src/config.h NO_SOURCE_PERMISSIONS)
141161

162+
add_library(config INTERFACE)
163+
target_include_directories(config
164+
INTERFACE ${CMAKE_CURRENT_BINARY_DIR}/include
165+
INTERFACE ${CMAKE_CURRENT_BINARY_DIR}/src
166+
)
167+
142168
enable_testing()
169+
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
143170

144171
add_subdirectory(include)
145172
add_subdirectory(src)

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ eXtended Merkle Signature Scheme is a post-quantum safe signature algorithm
99
([RFC](https://datatracker.ietf.org/doc/html/rfc8391)).
1010

1111
![XMSS C Library License](https://img.shields.io/github/license/FoxCryptoNL/xmss-library?style=plastic)
12-
[![XMSS C Library Release](https://img.shields.io/github/v/release/FoxCryptoNL/xmss-library?style=plastic)](
13-
https://github.com/FoxCryptoNL/xmss-library/releases)
12+
[![XMSS C Library Release](https://img.shields.io/github/v/release/FoxCryptoNL/xmss-library?style=plastic)](https://github.com/FoxCryptoNL/xmss-library/releases)
1413

1514
## XMSS C Library Source Code
1615

include/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
set(XMSS_HEADER_FILES
55
compat.h
6+
errors.h
67
generic_digest.h
78
opaque_structures.h
89
override_sha256_generic.h
@@ -13,6 +14,7 @@ set(XMSS_HEADER_FILES
1314
structures.h
1415
types.h
1516
verification.h
17+
version.h
1618
${CMAKE_CURRENT_BINARY_DIR}/xmss_config.h
1719
)
1820

@@ -41,6 +43,7 @@ int main(void) { return 0; }
4143
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
4244
PRIVATE ${CMAKE_CURRENT_BINARY_DIR}
4345
)
46+
set_property(TARGET _verify_${HEADER_FILENAME} PROPERTY FOLDER tests/verify_headers)
4447
# Note that building the executable is the real test. They're added as tests, anyway, to ensure that they're built
4548
# as part of the test cycle.
4649
add_test(NAME "Verify ${HEADER_FILENAME} is standalone" COMMAND "_verify_${HEADER_FILENAME}")
@@ -50,3 +53,5 @@ add_library(xmss_headers INTERFACE ${XMSS_HEADER_FILES})
5053
target_include_directories(xmss_headers
5154
INTERFACE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}
5255
)
56+
57+
install(FILES ${XMSS_HEADER_FILES} DESTINATION include/xmss)

include/compat.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,21 @@
2727

2828
/**
2929
* @brief
30-
* Syntactical equivalent of _Static_assert(), which is C11.
30+
* Syntactical equivalent of `_Static_assert()`, which is C11.
3131
*
3232
* @details
33-
* C11 supports _Static_assert(). CMake can detect if it is available anyway, even if the compiler is not C11.
33+
* C11 supports `_Static_assert()`. CMake can detect if it is available anyway, even if the compiler is not C11.
3434
* If CMake detects that static asserts are not supported, then this macro is a no-op.
3535
*
3636
* @see XMSS_CAN_USE_STATIC_ASSERT
3737
* @see XMSS_CAN_USE_EXTENSION_STATIC_ASSERT
3838
*/
3939
#if (__STDC_VERSION__ >= 201112L) || XMSS_CAN_USE_STATIC_ASSERT || defined(DOXYGEN)
40-
# define STATIC_ASSERT(cond, msg) _Static_assert(cond, msg)
40+
# define XMSS_STATIC_ASSERT(cond, msg) _Static_assert(cond, msg)
4141
#elif XMSS_CAN_USE_EXTENSION_STATIC_ASSERT
42-
# define STATIC_ASSERT(cond, msg) __extension__ _Static_assert(cond, msg)
42+
# define XMSS_STATIC_ASSERT(cond, msg) __extension__ _Static_assert(cond, msg)
4343
#else
44-
# define STATIC_ASSERT(cond, msg) struct xmss_static_assert_unsupported
44+
# define XMSS_STATIC_ASSERT(cond, msg) struct xmss_static_assert_unsupported
4545
#endif
4646

4747
#endif /* !XMSS_COMPAT_H_INCLUDED */

include/errors.h

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2024 Fox Crypto B.V.
3+
* SPDX-License-Identifier: MIT
4+
*
5+
* SPDX-FileContributor: Thomas Schaap
6+
* SPDX-FileContributor: Frans van Dorsselaer
7+
*/
8+
9+
/**
10+
* @file
11+
* @brief
12+
* Public API for XMSS error handling.
13+
*/
14+
15+
#pragma once
16+
17+
#ifndef XMSS_ERRORS_H_INCLUDED
18+
/** @private @brief Include guard. */
19+
#define XMSS_ERRORS_H_INCLUDED
20+
21+
#include <types.h>
22+
23+
24+
/**
25+
* Translate an XMSS error to the string with the enumeration-constant name.
26+
*
27+
* @details
28+
* As an example, `xmss_error_to_name(XMSS_OKAY)` returns `"XMSS_OKAY"`.
29+
*
30+
* @remark
31+
* This function returns `"XmssError_Undefined"` for values of `error` that are not defined in #XmssError.
32+
*
33+
* @param[in] error The error to translate.
34+
*
35+
* @returns A pointer to a static string with the enumeration-constant name corresponding to `error`.
36+
*/
37+
const char *xmss_error_to_name(XmssError error);
38+
39+
40+
/**
41+
* Translate an XMSS error to a human-readable message.
42+
*
43+
* @param[in] error The error to translate.
44+
*
45+
* @returns A pointer to a static string with a message corresponding to `error`.
46+
*/
47+
const char *xmss_error_to_description(XmssError error);
48+
49+
50+
#endif /* !XMSS_ERRORS_H_INCLUDED */

include/generic_digest.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
* @file
1010
* @brief Abstract typedefs for hash function overrides using the generic interface.
1111
* @details
12-
* Do not include this file. Instead, either include `override_sha256_generic.h` or
13-
* `override_shake256_256_generic.h`, depending on the specific algorithm you are overriding.
12+
* Do not include this file. Instead, either include override_sha256_generic.h or
13+
* override_shake256_256_generic.h, depending on the specific algorithm you are overriding.
1414
*
1515
* For each digest algorithm (SHA-256 and/or SHAKE256/256), the library allows to override its internal implementation.
1616
* The main use case is hardware acceleration.
@@ -20,9 +20,9 @@
2020
*
2121
* When supplying an override using the generic interface, you will have to implement 3 functions (per algorithm, that
2222
* you are overriding):
23-
* - initialize
24-
* - update
25-
* - finalize
23+
* - #XmssGenericDigestInit
24+
* - #XmssGenericDigestUpdate
25+
* - #XmssGenericDigestFinalize
2626
*
2727
* The library guarantees that the functions are called in the following order:
2828
* - exactly one call to the initialize function
@@ -31,7 +31,7 @@
3131
*
3232
* Per thread, there will be at most one digest in use at any one time. This implies that if you use the library single
3333
* threaded, then you could use a single statically allocated context. In that case the opaque `context` parameter does
34-
* not necessarily have to be provided or used (i.e., it could simply be 0).
34+
* not necessarily have to be provided or used (i.e., it could simply be NULL).
3535
*
3636
* **Error handling**
3737
*
@@ -84,10 +84,10 @@ typedef void *(*XmssGenericDigestInit)(void);
8484
* @param[in] context An opaque context, i.e., the result of the most recent call to the initialization function on
8585
* this thread.
8686
* @param[in] data The byte stream of additional data to be included in the message; may be NULL if and only if
87-
* data_length is zero.
88-
* @param[in] data_length The number of bytes pointed to by data.
87+
* `data_length` is zero.
88+
* @param[in] data_length The number of bytes pointed to by `data`.
8989
*/
90-
typedef void (*XmssGenericDigestUpdate)(void *restrict context, const uint8_t *restrict data, size_t data_length);
90+
typedef void (*XmssGenericDigestUpdate)(void *context, const uint8_t *data, size_t data_length);
9191

9292
/**
9393
* @brief
@@ -98,6 +98,6 @@ typedef void (*XmssGenericDigestUpdate)(void *restrict context, const uint8_t *r
9898
* this thread.
9999
* @param[out] digest The output of the hash function.
100100
*/
101-
typedef void (*XmssGenericDigestFinalize)(void *restrict context, XmssValue256 *restrict digest);
101+
typedef void (*XmssGenericDigestFinalize)(void *context, XmssValue256 *digest);
102102

103103
#endif /* !XMSS_GENERIC_DIGEST_H_INCLUDED */

include/opaque_structures.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
* @details
3131
* The signing context defines the parameter set and the hash functions to use.
3232
*
33-
* When creating an XmssSigningContext, the XMSS_SIGNING_CONTEXT_SIZE macro can be used to allocate the correct size.
33+
* When creating an XmssSigningContext, the #XMSS_SIGNING_CONTEXT_SIZE macro can be used to allocate the correct size.
3434
*
3535
* XmssSigningContext is an opaque type, do not access its members.
3636
*/
@@ -40,7 +40,7 @@ typedef struct XmssSigningContext XmssSigningContext;
4040
* @brief
4141
* The size in bytes of an XmssSigningContext.
4242
*/
43-
#define XMSS_SIGNING_CONTEXT_SIZE (4u + 4u + 4u + 4u + 11u * sizeof(void(*)()))
43+
#define XMSS_SIGNING_CONTEXT_SIZE (4u + 4u + 4u + 4u + 4u * sizeof(void(*)(void)))
4444

4545
/**
4646
* @brief
@@ -60,7 +60,7 @@ void xmss_free_signing_context(XmssSigningContext *signing_context);
6060
* In-memory representation of a loaded cache.
6161
*
6262
* @details
63-
* When creating an XmssInternalCache, the XMSS_INTERNAL_CACHE_SIZE macro can be used to allocate the correct size.
63+
* When creating an XmssInternalCache, the #XMSS_INTERNAL_CACHE_SIZE() macro can be used to allocate the correct size.
6464
*
6565
* XmssInternalCache is an opaque type, do not access its members.
6666
*/
@@ -70,12 +70,12 @@ typedef struct XmssInternalCache XmssInternalCache;
7070
* @brief
7171
* The number of cached entries for a specific cache configuration.
7272
*
73-
* @note The arguments to XMSS_CACHE_ENTRY_COUNT will be evaluated multiple times.
73+
* @note The arguments to #XMSS_CACHE_ENTRY_COUNT() will be evaluated multiple times.
7474
*
7575
* @param[in] cache_type The cache type that is used.
7676
* @param[in] cache_level The cache level that is to be held.
7777
* @param[in] param_set The parameter set of the key for which the cache will be used.
78-
* @see xmss_generate_public_key for more information about the cache type and level.
78+
* @see xmss_generate_public_key() for more information about the cache type and level.
7979
*/
8080
#define XMSS_CACHE_ENTRY_COUNT(cache_type, cache_level, param_set) \
8181
((cache_type) == XMSS_CACHE_NONE ? 0u : \
@@ -92,12 +92,12 @@ typedef struct XmssInternalCache XmssInternalCache;
9292
* @brief
9393
* The size in bytes of an XmssInternalCache.
9494
*
95-
* @note The arguments to XMSS_INTERNAL_CACHE_SIZE will be evaluated multiple times.
95+
* @note The arguments to #XMSS_INTERNAL_CACHE_SIZE() will be evaluated multiple times.
9696
*
9797
* @param[in] cache_type The cache type that is used.
9898
* @param[in] cache_level The cache level that is to be held.
9999
* @param[in] param_set The parameter set of the key for which the cache will be used.
100-
* @see xmss_generate_public_key for more information about the cache type and level.
100+
* @see xmss_generate_public_key() for more information about the cache type and level.
101101
*/
102102
#define XMSS_INTERNAL_CACHE_SIZE(cache_type, cache_level, param_set) \
103103
(4 + 4 + sizeof(XmssValue256) * XMSS_CACHE_ENTRY_COUNT((cache_type), (cache_level), (param_set)))
@@ -116,7 +116,7 @@ typedef struct XmssInternalCache XmssInternalCache;
116116
* Context for using the signature generation part of the library, with a loaded private key partition.
117117
*
118118
* @details
119-
* When creating an XmssKeyContext, the XMSS_KEY_CONTEXT_SIZE macro can be used to allocate the correct size.
119+
* When creating an XmssKeyContext, the #XMSS_KEY_CONTEXT_SIZE macro can be used to allocate the correct size.
120120
*
121121
* XmssKeyContext is an opaque type, do not access its members.
122122
*/
@@ -144,10 +144,10 @@ typedef struct XmssKeyContext XmssKeyContext;
144144
* @brief
145145
* The size in bytes of an XmssKeyContext.
146146
*
147-
* @note The param_set argument will be evaluated multiple times.
147+
* @note The `param_set` argument will be evaluated multiple times.
148148
*
149-
* @param[in] param_set The XmssParameterSetOID that is to be used for the private key.
150-
* @param[in] obfuscation_setting The XmssIndexObfuscationSetting that is to be used with the private key.
149+
* @param[in] param_set The #XmssParameterSetOID that is to be used for the private key.
150+
* @param[in] obfuscation_setting The #XmssIndexObfuscationSetting that is to be used with the private key.
151151
*/
152152
#define XMSS_KEY_CONTEXT_SIZE(param_set, obfuscation_setting) \
153153
(4u + 4u + XMSS_SIGNING_CONTEXT_SIZE + XMSS_PRIVATE_KEY_STATELESS_PART_SIZE + \
@@ -170,7 +170,7 @@ void xmss_free_key_context(XmssKeyContext *key_context);
170170
* The temporary context to gather all the results of generating a public key.
171171
*
172172
* @details
173-
* When creating an XmssKeyGenerationContext, the XMSS_KEY_GENERATION_CONTEXT_SIZE macro may be used to allocate the
173+
* When creating an XmssKeyGenerationContext, the #XMSS_KEY_GENERATION_CONTEXT_SIZE macro may be used to allocate the
174174
* correct size.
175175
*
176176
* The elements of an XmssKeyGenerationContext are generally to be considered invalid outside of their specific use in
@@ -185,7 +185,7 @@ typedef struct XmssKeyGenerationContext XmssKeyGenerationContext;
185185
* The size in bytes of XmssKeyGenerationContext.
186186
*
187187
* @param[in] generation_partitions The number of calculation partitions that will divide the work.
188-
* @see xmss_generate_public_key for more information about generation_partitions
188+
* @see xmss_generate_public_key() for more information about generation_partitions.
189189
*/
190190
#define XMSS_KEY_GENERATION_CONTEXT_SIZE(generation_partitions) \
191191
(sizeof(void*) + sizeof(uint32_t) + sizeof(uint32_t) + sizeof(void*) + sizeof(void*) + \

include/override_sha256_generic.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,22 @@
3737
* @details
3838
* This is the specialization for the SHA-256 algorithm.
3939
*/
40-
void *sha256_init(void);
40+
void *xmss_sha256_init(void);
4141

4242
/**
4343
* @copydoc XmssGenericDigestUpdate
4444
* @see XmssGenericDigestUpdate
4545
* @details
4646
* This is the specialization for the SHA-256 algorithm.
4747
*/
48-
void sha256_update(void *restrict context, const uint8_t *restrict data, size_t data_length);
48+
void xmss_sha256_update(void *context, const uint8_t *data, size_t data_length);
4949

5050
/**
5151
* @copydoc XmssGenericDigestFinalize
5252
* @see XmssGenericDigestFinalize
5353
* @details
5454
* This is the specialization for the SHA-256 algorithm.
5555
*/
56-
void sha256_finalize(void *restrict context, XmssValue256 *restrict digest);
56+
void xmss_sha256_finalize(void *context, XmssValue256 *digest);
5757

5858
#endif /* !XMSS_OVERRIDE_SHA256_GENERIC_H_INCLUDED */

include/override_sha256_internal.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,12 @@
5252
* This function implements the loop body of the SHA-256($M$) function as defined by NIST FIPS 180-4, Section 6.2.2,
5353
* Steps 1, 2, 3, and 4.
5454
*
55+
* For performance reasons, it is recommended not to validate the input. This function is guaranteed to be called by the
56+
* library with valid input.
57+
*
5558
* @param[in,out] Hi Intermediate hash value $H_i$ in native form.
5659
* @param[in] Mi Message block $M_i$ in native form (uint32_t[16] == 64 bytes).
5760
*/
58-
void sha256_process_block(XmssNativeValue256 *restrict Hi, const uint32_t *restrict Mi);
61+
void xmss_sha256_process_block(XmssNativeValue256 *Hi, const uint32_t *Mi);
5962

6063
#endif /* !XMSS_OVERRIDE_SHA256_INTERNAL_H_INCLUDED */

0 commit comments

Comments
 (0)