|
| 1 | +/* |
| 2 | + * Copyright (C) 2025 TU Dresden |
| 3 | + * Copyright (C) 2021 HAW Hamburg |
| 4 | + * |
| 5 | + * This file is subject to the terms and conditions of the GNU Lesser |
| 6 | + * General Public License v2.1. See the file LICENSE in the top level |
| 7 | + * directory for more details. |
| 8 | + */ |
| 9 | + |
| 10 | +/** |
| 11 | + * @ingroup sys_psa_crypto |
| 12 | + * @{ |
| 13 | + * |
| 14 | + * @file asymmetric_signature/sizes.h |
| 15 | + * @brief Asymmetric signature size definitions for the PSA Crypto API |
| 16 | + * |
| 17 | + * @author Armin Wolf <[email protected]> |
| 18 | + * @author Lena Boeckmann <[email protected]> |
| 19 | + * |
| 20 | + */ |
| 21 | + |
| 22 | +#pragma once |
| 23 | + |
| 24 | +#ifdef __cplusplus |
| 25 | +extern "C" { |
| 26 | +#endif |
| 27 | + |
| 28 | +#include "psa/sizes.h" |
| 29 | +#include "psa/key/type.h" |
| 30 | + |
| 31 | +/** |
| 32 | + * @brief A sufficient signature buffer size for @ref psa_sign_message() and |
| 33 | + * @ref psa_sign_hash(), for any of the supported key types and asymmetric signature |
| 34 | + * algorithms. |
| 35 | + * |
| 36 | + * @details If the size of the signature buffer is at least this large, it is guaranteed that |
| 37 | + * @ref psa_sign_message() and @ref psa_sign_hash() will not fail due to an insufficient |
| 38 | + * buffer size. |
| 39 | + * |
| 40 | + * See also @ref PSA_SIGN_OUTPUT_SIZE(). |
| 41 | + */ |
| 42 | +#define PSA_SIGNATURE_MAX_SIZE /* implementation-defined value */ |
| 43 | + |
| 44 | +/** |
| 45 | + * @brief ECDSA signature size for a given curve bit size |
| 46 | + * |
| 47 | + * @note This macro returns a compile-time constant if its argument is one. |
| 48 | + * |
| 49 | + * @param curve_bits Curve size in bits. |
| 50 | + * |
| 51 | + * @return Signature size in bytes. |
| 52 | + */ |
| 53 | +#define PSA_ECDSA_SIGNATURE_SIZE(curve_bits) \ |
| 54 | + ((size_t)(PSA_BITS_TO_BYTES(curve_bits) * 2)) |
| 55 | + |
| 56 | +/** |
| 57 | + * @brief Sufficient signature buffer size for @ref psa_sign_message() and @ref psa_sign_hash(). |
| 58 | + * |
| 59 | + * @details If the size of the signature buffer is at least this large, it is guaranteed that |
| 60 | + * @ref psa_sign_message() and @ref psa_sign_hash() will not fail due to an insufficient |
| 61 | + * buffer size. The actual size of the output might be smaller in any given call. |
| 62 | + * |
| 63 | + * See also @ref PSA_SIGNATURE_MAX_SIZE. |
| 64 | + * |
| 65 | + * @param key_type An asymmetric key type. This can be a key pair type or a public key type. |
| 66 | + * @param key_bits The size of the key in bits. |
| 67 | + * @param alg The signature algorithm. |
| 68 | + * |
| 69 | + * @return A sufficient signature buffer size for the specified asymmetric signature algorithm and |
| 70 | + * key parameters. |
| 71 | + * 0 if algorithm and key parameters are not supported. |
| 72 | + * If the parameters are not valid, the return value is unspecified. |
| 73 | + */ |
| 74 | +#define PSA_SIGN_OUTPUT_SIZE(key_type, key_bits, alg) \ |
| 75 | + (PSA_KEY_TYPE_IS_ECC(key_type) ? PSA_ECDSA_SIGNATURE_SIZE(key_bits) : \ |
| 76 | + ((void)alg, 0)) |
| 77 | + |
| 78 | +#ifdef __cplusplus |
| 79 | +} |
| 80 | +#endif |
| 81 | + |
| 82 | +/** @} */ |
0 commit comments