xref: /aosp_15_r20/external/boringssl/src/crypto/spx/fors.h (revision 8fb009dc861624b67b6cdb62ea21f0f22d0c584b)
1 /* Copyright (c) 2023, Google LLC
2  *
3  * Permission to use, copy, modify, and/or distribute this software for any
4  * purpose with or without fee is hereby granted, provided that the above
5  * copyright notice and this permission notice appear in all copies.
6  *
7  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
10  * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
13  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
14 
15 #ifndef OPENSSL_HEADER_CRYPTO_SPX_FORS_H
16 #define OPENSSL_HEADER_CRYPTO_SPX_FORS_H
17 
18 #include <openssl/base.h>
19 
20 #include "./params.h"
21 
22 #if defined(__cplusplus)
23 extern "C" {
24 #endif
25 
26 
27 // Algorithm 13: Generate a FORS private key value.
28 void spx_fors_sk_gen(uint8_t *fors_sk, uint32_t idx,
29                      const uint8_t sk_seed[SPX_N], const uint8_t pk_seed[SPX_N],
30                      uint8_t addr[32]);
31 
32 // Algorithm 14: Compute the root of a Merkle subtree of FORS public values.
33 void spx_fors_treehash(uint8_t root_node[SPX_N], const uint8_t sk_seed[SPX_N],
34                        uint32_t i /*target node index*/,
35                        uint32_t z /*target node height*/,
36                        const uint8_t pk_seed[SPX_N], uint8_t addr[32]);
37 
38 // Algorithm 15: Generate a FORS signature.
39 void spx_fors_sign(uint8_t *fors_sig, const uint8_t message[SPX_FORS_MSG_BYTES],
40                    const uint8_t sk_seed[SPX_N], const uint8_t pk_seed[SPX_N],
41                    uint8_t addr[32]);
42 
43 // Algorithm 16: Compute a FORS public key from a FORS signature.
44 void spx_fors_pk_from_sig(uint8_t *fors_pk,
45                           const uint8_t fors_sig[SPX_FORS_BYTES],
46                           const uint8_t message[SPX_FORS_MSG_BYTES],
47                           const uint8_t pk_seed[SPX_N], uint8_t addr[32]);
48 
49 
50 #if defined(__cplusplus)
51 }  // extern C
52 #endif
53 
54 #endif  // OPENSSL_HEADER_CRYPTO_SPX_FORS_H
55