Software APIs
utils.h
1 // Copyright lowRISC contributors (OpenTitan project).
2 // Licensed under the Apache License, Version 2.0, see LICENSE for details.
3 // SPDX-License-Identifier: Apache-2.0
4 //
5 // Derived from code in the SPHINCS+ reference implementation (CC0 license):
6 // https://github.com/sphincs/sphincsplus/blob/ed15dd78658f63288c7492c00260d86154b84637/ref/utils.h
7 
8 #ifndef OPENTITAN_SW_DEVICE_SILICON_CREATOR_LIB_SIGVERIFY_SPHINCSPLUS_UTILS_H_
9 #define OPENTITAN_SW_DEVICE_SILICON_CREATOR_LIB_SIGVERIFY_SPHINCSPLUS_UTILS_H_
10 
11 #include <stdint.h>
12 
14 #include "sw/device/silicon_creator/lib/error.h"
15 #include "sw/device/silicon_creator/lib/sigverify/sphincsplus/address.h"
16 #include "sw/device/silicon_creator/lib/sigverify/sphincsplus/context.h"
17 
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21 
22 /**
23  * Convert from big-endian bytes to a 64-bit integer.
24  *
25  * It is the caller's responsibility to ensure the number of bytes is small
26  * enough to fit a 64-bit integer (i.e. `inlen` <= 8).
27  *
28  * Appears in the reference code as `bytes_to_ull`.
29  *
30  * @param in Input buffer
31  * @param inlen Size of input buffer (in bytes).
32  */
34 uint64_t spx_utils_bytes_to_u64(const uint8_t *in, size_t inlen);
35 
36 /**
37  * Computes a root node of a subtree.
38  *
39  * Computes the root node based on the provided leaf and authentication path.
40  * Expects address to be complete other than the tree_height and tree_index.
41  *
42  * @param leaf Input leaf.
43  * @param leaf_idx Index of input leaf.
44  * @param idx_offset Leaf index offset.
45  * @param auth_path Input authentication path.
46  * @param tree_height Tree height.
47  * @param ctx Context object.
48  * @param addr Hypertree address.
49  * @param[out] root Resulting root node.
50  */
51 void spx_utils_compute_root(const uint32_t *leaf, uint32_t leaf_idx,
52  uint32_t idx_offset, const uint32_t *auth_path,
53  uint8_t tree_height, const spx_ctx_t *ctx,
54  spx_addr_t *addr, uint32_t *root);
55 
56 #ifdef __cplusplus
57 }
58 #endif
59 
60 #endif // OPENTITAN_SW_DEVICE_SILICON_CREATOR_LIB_SIGVERIFY_SPHINCSPLUS_UTILS_H_