slh_hash.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. #ifndef OSSL_CRYPTO_SLH_HASH_H
  10. # define OSSL_CRYPTO_SLH_HASH_H
  11. # pragma once
  12. # include <openssl/e_os2.h>
  13. # include "slh_adrs.h"
  14. # include "internal/packet.h"
  15. # define SLH_HASH_FUNC_DECLARE(ctx, hashf) \
  16. const SLH_HASH_FUNC *hashf = ctx->hash_func \
  17. # define SLH_HASH_FN_DECLARE(hashf, t) OSSL_SLH_HASHFUNC_##t * t = hashf->t
  18. /*
  19. * @params out is |m| bytes which ranges from (30..49) bytes
  20. */
  21. typedef int (OSSL_SLH_HASHFUNC_H_MSG)(SLH_DSA_HASH_CTX *ctx, const uint8_t *r,
  22. const uint8_t *pk_seed, const uint8_t *pk_root,
  23. const uint8_t *msg, size_t msg_len,
  24. uint8_t *out, size_t out_len);
  25. typedef int (OSSL_SLH_HASHFUNC_PRF)(SLH_DSA_HASH_CTX *ctx, const uint8_t *pk_seed,
  26. const uint8_t *sk_seed, const uint8_t *adrs,
  27. uint8_t *out, size_t out_len);
  28. typedef int (OSSL_SLH_HASHFUNC_PRF_MSG)(SLH_DSA_HASH_CTX *ctx, const uint8_t *sk_prf,
  29. const uint8_t *opt_rand,
  30. const uint8_t *msg, size_t msg_len,
  31. WPACKET *pkt);
  32. typedef int (OSSL_SLH_HASHFUNC_F)(SLH_DSA_HASH_CTX *ctx, const uint8_t *pk_seed,
  33. const uint8_t *adrs,
  34. const uint8_t *m1, size_t m1_len,
  35. uint8_t *out, size_t out_len);
  36. typedef int (OSSL_SLH_HASHFUNC_H)(SLH_DSA_HASH_CTX *ctx, const uint8_t *pk_seed,
  37. const uint8_t *adrs,
  38. const uint8_t *m1, const uint8_t *m2,
  39. uint8_t *out, size_t out_len);
  40. typedef int (OSSL_SLH_HASHFUNC_T)(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. typedef struct slh_hash_func_st {
  45. OSSL_SLH_HASHFUNC_H_MSG *H_MSG;
  46. OSSL_SLH_HASHFUNC_PRF *PRF;
  47. OSSL_SLH_HASHFUNC_PRF_MSG *PRF_MSG;
  48. OSSL_SLH_HASHFUNC_F *F;
  49. OSSL_SLH_HASHFUNC_H *H;
  50. OSSL_SLH_HASHFUNC_T *T;
  51. } SLH_HASH_FUNC;
  52. const SLH_HASH_FUNC *ossl_slh_get_hash_fn(int is_shake);
  53. #endif