xref: /aosp_15_r20/external/boringssl/src/crypto/spx/spx_util.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_UTIL_H
16 #define OPENSSL_HEADER_CRYPTO_SPX_UTIL_H
17 
18 #include <openssl/base.h>
19 
20 #if defined(__cplusplus)
21 extern "C" {
22 #endif
23 
24 
25 // Encodes the integer value of input to out_len bytes in big-endian order.
26 // Note that input < 2^(8*out_len), as otherwise this function will truncate
27 // the least significant bytes of the integer representation.
28 void spx_uint64_to_len_bytes(uint8_t *output, size_t out_len, uint64_t input);
29 
30 uint64_t spx_to_uint64(const uint8_t *input, size_t input_len);
31 
32 // Compute the base 2^log2_b representation of X.
33 //
34 // As some of the parameter sets in https://eprint.iacr.org/2022/1725.pdf use
35 // a FORS height > 16 we use a uint32_t to store the output.
36 void spx_base_b(uint32_t *output, size_t out_len, const uint8_t *input,
37                 unsigned int log2_b);
38 
39 
40 #if defined(__cplusplus)
41 }  // extern C
42 #endif
43 
44 #endif  // OPENSSL_HEADER_CRYPTO_SPX_UTIL_H
45