Software APIs
thash.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/thash.h
7 
8 #ifndef OPENTITAN_SW_DEVICE_SILICON_CREATOR_LIB_SIGVERIFY_SPHINCSPLUS_THASH_H_
9 #define OPENTITAN_SW_DEVICE_SILICON_CREATOR_LIB_SIGVERIFY_SPHINCSPLUS_THASH_H_
10 
12 #include "sw/device/silicon_creator/lib/error.h"
13 #include "sw/device/silicon_creator/lib/sigverify/sphincsplus/address.h"
14 #include "sw/device/silicon_creator/lib/sigverify/sphincsplus/context.h"
15 
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19 
20 /**
21  * Tweakable hash function.
22  *
23  * Produces a digest of length `kSpxN` bytes based on the input buffer,
24  * address, and public key seed from `ctx`. The exact construction depends on
25  * the SPHINCS+ parameters.
26  *
27  * For details on tweakable hash constructions for SPHINCS+, see the
28  * paper: https://sphincs.org/data/sphincs+-paper.pdf
29  *
30  * @param in Input buffer.
31  * @param inblocks Number of `kSpxN`-byte blocks in input buffer.
32  * @param ctx Context object.
33  * @param addr Hypertree address.
34  * @param[out] out Output buffer (at least `kSpxN` bytes).
35  */
36 void thash(const uint32_t *in, size_t inblocks, const spx_ctx_t *ctx,
37  const spx_addr_t *addr, uint32_t *out);
38 
39 #ifdef __cplusplus
40 }
41 #endif
42 
43 #endif // OPENTITAN_SW_DEVICE_SILICON_CREATOR_LIB_SIGVERIFY_SPHINCSPLUS_THASH_H_