Software APIs
sw
device
silicon_creator
lib
sigverify
sphincsplus
hash.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/hash.h
7
8
#ifndef OPENTITAN_SW_DEVICE_SILICON_CREATOR_LIB_SIGVERIFY_SPHINCSPLUS_HASH_H_
9
#define OPENTITAN_SW_DEVICE_SILICON_CREATOR_LIB_SIGVERIFY_SPHINCSPLUS_HASH_H_
10
11
#include "
sw/device/lib/base/macros.h
"
12
#include "sw/device/silicon_creator/lib/error.h"
13
#include "sw/device/silicon_creator/lib/sigverify/sphincsplus/context.h"
14
#include "sw/device/silicon_creator/lib/sigverify/sphincsplus/params.h"
15
16
#ifdef __cplusplus
17
extern
"C"
{
18
#endif
19
20
/**
21
* Initialize the SPHINCS+ hash function.
22
*
23
* Hook for any precomputation or setup tasks the hash function needs to do
24
* before a SPHINCS+ operation takes place.
25
*
26
* Appears in reference code as `initialize_hash_function`.
27
*
28
* @param ctx Context object.
29
* @return Error code indicating if the operation succeeded.
30
*/
31
OT_WARN_UNUSED_RESULT
32
rom_error_t spx_hash_initialize(
spx_ctx_t
*ctx);
33
34
/**
35
* Hash the input message and derive the leaf index.
36
*
37
* Computes H(R, pk, msg), where R is the random number included in the SPHINCS+
38
* signature and H is the underlying hash function (Hmsg in the SPHINCS+
39
* paper). Outputs the message digest and the index of the leaf. The index is
40
* split in the tree index and the leaf index, for convenient copying to an
41
* address.
42
*
43
* @param R Per-signature random number.
44
* @param pk Public key.
45
* @param msg_prefix_1 Optional message prefix.
46
* @param msg_prefix_1_len Length of the first prefix.
47
* @param msg_prefix_2 Optional message prefix.
48
* @param msg_prefix_2_len Length of the second prefix.
49
* @param msg_prefix_3 Optional message prefix.
50
* @param msg_prefix_3_len Length of the third prefix.
51
* @param msg Input message.
52
* @param msg_len Input message length.
53
* @param[out] digest Output buffer for message digest.
54
* @param[out] tree Tree index.
55
* @param[out] leaf_idx Leaf index.
56
* @return Error code indicating if the operation succeeded.
57
*/
58
OT_WARN_UNUSED_RESULT
59
rom_error_t spx_hash_message(
60
const
uint32_t *R,
const
uint32_t *pk,
const
uint8_t *msg_prefix_1,
61
size_t
msg_prefix_1_len,
const
uint8_t *msg_prefix_2,
62
size_t
msg_prefix_2_len,
const
uint8_t *msg_prefix_3,
63
size_t
msg_prefix_3_len,
const
uint8_t *msg,
size_t
msg_len,
64
uint8_t *digest, uint64_t *tree, uint32_t *leaf_idx);
65
66
#ifdef __cplusplus
67
}
68
#endif
69
70
#endif
// OPENTITAN_SW_DEVICE_SILICON_CREATOR_LIB_SIGVERIFY_SPHINCSPLUS_HASH_H_
Return to
OpenTitan Documentation