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