xref: /freebsd/crypto/openssl/crypto/slh_dsa/slh_hash.h (revision f25b8c9fb4f58cf61adb47d7570abe7caa6d385d)
1 /*
2  * Copyright 2024-2025 The OpenSSL Project Authors. All Rights Reserved.
3  *
4  * Licensed under the Apache License 2.0 (the "License").  You may not use
5  * this file except in compliance with the License.  You can obtain a copy
6  * in the file LICENSE in the source distribution or at
7  * https://www.openssl.org/source/license.html
8  */
9 
10 #ifndef OSSL_CRYPTO_SLH_HASH_H
11 #define OSSL_CRYPTO_SLH_HASH_H
12 #pragma once
13 
14 #include <openssl/e_os2.h>
15 #include "slh_adrs.h"
16 #include "internal/packet.h"
17 
18 #define SLH_HASH_FUNC_DECLARE(ctx, hashf) \
19     const SLH_HASH_FUNC *hashf = ctx->hash_func
20 
21 #define SLH_HASH_FN_DECLARE(hashf, t) OSSL_SLH_HASHFUNC_##t *t = hashf->t
22 
23 /*
24  * @params out is |m| bytes which ranges from (30..49) bytes
25  */
26 typedef int(OSSL_SLH_HASHFUNC_H_MSG)(SLH_DSA_HASH_CTX *ctx, const uint8_t *r,
27     const uint8_t *pk_seed, const uint8_t *pk_root,
28     const uint8_t *msg, size_t msg_len,
29     uint8_t *out, size_t out_len);
30 
31 typedef int(OSSL_SLH_HASHFUNC_PRF)(SLH_DSA_HASH_CTX *ctx, const uint8_t *pk_seed,
32     const uint8_t *sk_seed, const uint8_t *adrs,
33     uint8_t *out, size_t out_len);
34 
35 typedef int(OSSL_SLH_HASHFUNC_PRF_MSG)(SLH_DSA_HASH_CTX *ctx, const uint8_t *sk_prf,
36     const uint8_t *opt_rand,
37     const uint8_t *msg, size_t msg_len,
38     WPACKET *pkt);
39 
40 typedef int(OSSL_SLH_HASHFUNC_F)(SLH_DSA_HASH_CTX *ctx, const uint8_t *pk_seed,
41     const uint8_t *adrs,
42     const uint8_t *m1, size_t m1_len,
43     uint8_t *out, size_t out_len);
44 
45 typedef int(OSSL_SLH_HASHFUNC_H)(SLH_DSA_HASH_CTX *ctx, const uint8_t *pk_seed,
46     const uint8_t *adrs,
47     const uint8_t *m1, const uint8_t *m2,
48     uint8_t *out, size_t out_len);
49 
50 typedef int(OSSL_SLH_HASHFUNC_T)(SLH_DSA_HASH_CTX *ctx, const uint8_t *pk_seed,
51     const uint8_t *adrs,
52     const uint8_t *m1, size_t m1_len,
53     uint8_t *out, size_t out_len);
54 
55 typedef struct slh_hash_func_st {
56     OSSL_SLH_HASHFUNC_H_MSG *H_MSG;
57     OSSL_SLH_HASHFUNC_PRF *PRF;
58     OSSL_SLH_HASHFUNC_PRF_MSG *PRF_MSG;
59     OSSL_SLH_HASHFUNC_F *F;
60     OSSL_SLH_HASHFUNC_H *H;
61     OSSL_SLH_HASHFUNC_T *T;
62 } SLH_HASH_FUNC;
63 
64 const SLH_HASH_FUNC *ossl_slh_get_hash_fn(int is_shake);
65 
66 #endif
67