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