slh_adrs.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. #include <openssl/e_os2.h>
  10. /*
  11. * An Address object is used to store a blob of data that is used by hash
  12. * functions. It stores information related to the type of operation, as well as
  13. * information related to tree addresses and heights.
  14. * SHAKE based algorithms use 32 bytes for this object, whereas SHA2 based
  15. * algorithms use a compressed format of 22 bytes. For this reason there are
  16. * different method tables to support the different formats.
  17. * FIPS 205 Section 4.2 describes the SHAKE related functions.
  18. * The compressed format is discussed in Section 11.2.
  19. */
  20. #define SLH_ADRS_SIZE 32 /* size of the ADRS blob */
  21. #define SLH_ADRSC_SIZE 22 /* size of a compact ADRS blob */
  22. #define SLH_ADRS_SIZE_MAX SLH_ADRS_SIZE
  23. /* 7 Different types of addresses */
  24. #define SLH_ADRS_TYPE_WOTS_HASH 0
  25. #define SLH_ADRS_TYPE_WOTS_PK 1
  26. #define SLH_ADRS_TYPE_TREE 2
  27. #define SLH_ADRS_TYPE_FORS_TREE 3
  28. #define SLH_ADRS_TYPE_FORS_ROOTS 4
  29. #define SLH_ADRS_TYPE_WOTS_PRF 5
  30. #define SLH_ADRS_TYPE_FORS_PRF 6
  31. #define SLH_ADRS_DECLARE(a) uint8_t a[SLH_ADRS_SIZE_MAX]
  32. #define SLH_ADRS_FUNC_DECLARE(ctx, adrsf) \
  33. const SLH_ADRS_FUNC *adrsf = ctx->adrs_func
  34. #define SLH_ADRS_FN_DECLARE(adrsf, t) OSSL_SLH_ADRS_FUNC_##t *t = adrsf->t
  35. typedef void (OSSL_SLH_ADRS_FUNC_zero)(uint8_t *adrs);
  36. typedef void (OSSL_SLH_ADRS_FUNC_copy)(uint8_t *dst, const uint8_t *src);
  37. typedef void (OSSL_SLH_ADRS_FUNC_copy_keypair_address)(uint8_t *dst, const uint8_t *src);
  38. /*
  39. * Note that the tree address is actually 12 bytes in uncompressed format,
  40. * but we only use 8 bytes
  41. */
  42. typedef void (OSSL_SLH_ADRS_FUNC_set_tree_address)(uint8_t *adrs, uint64_t in);
  43. typedef void (OSSL_SLH_ADRS_FUNC_set_layer_address)(uint8_t *adrs, uint32_t layer);
  44. typedef void (OSSL_SLH_ADRS_FUNC_set_type_and_clear)(uint8_t *adrs, uint32_t type);
  45. typedef void (OSSL_SLH_ADRS_FUNC_set_keypair_address)(uint8_t *adrs, uint32_t in);
  46. typedef void (OSSL_SLH_ADRS_FUNC_set_chain_address)(uint8_t *adrs, uint32_t in);
  47. typedef void (OSSL_SLH_ADRS_FUNC_set_tree_height)(uint8_t *adrs, uint32_t in);
  48. typedef void (OSSL_SLH_ADRS_FUNC_set_hash_address)(uint8_t *adrs, uint32_t in);
  49. typedef void (OSSL_SLH_ADRS_FUNC_set_tree_index)(uint8_t *adrs, uint32_t in);
  50. typedef struct slh_adrs_func_st {
  51. OSSL_SLH_ADRS_FUNC_set_layer_address *set_layer_address;
  52. OSSL_SLH_ADRS_FUNC_set_tree_address *set_tree_address;
  53. OSSL_SLH_ADRS_FUNC_set_type_and_clear *set_type_and_clear;
  54. OSSL_SLH_ADRS_FUNC_set_keypair_address *set_keypair_address;
  55. OSSL_SLH_ADRS_FUNC_copy_keypair_address *copy_keypair_address;
  56. OSSL_SLH_ADRS_FUNC_set_chain_address *set_chain_address;
  57. OSSL_SLH_ADRS_FUNC_set_tree_height *set_tree_height;
  58. OSSL_SLH_ADRS_FUNC_set_hash_address *set_hash_address;
  59. OSSL_SLH_ADRS_FUNC_set_tree_index *set_tree_index;
  60. OSSL_SLH_ADRS_FUNC_zero *zero;
  61. OSSL_SLH_ADRS_FUNC_copy *copy;
  62. } SLH_ADRS_FUNC;
  63. const SLH_ADRS_FUNC *ossl_slh_get_adrs_fn(int is_compressed);