Skip to content

Commit 5530329

Browse files
committed
sys/psa_crypto: Split asymmetric signature size definitions into separate file
TODO Signed-off-by: Armin Wolf <[email protected]>
1 parent 8e7b60d commit 5530329

File tree

3 files changed

+83
-47
lines changed

3 files changed

+83
-47
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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+
/** @} */

sys/include/psa_crypto/psa/crypto_sizes.h

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ extern "C" {
3333

3434
#include "aead/sizes.h"
3535
#include "asymmetric_encryption/sizes.h"
36+
#include "asymmetric_signature/sizes.h"
3637
#include "cipher/sizes.h"
3738
#include "hash/sizes.h"
3839
#include "key/sizes.h"
@@ -42,40 +43,6 @@ extern "C" {
4243
#include "mac/sizes.h"
4344
#include "sizes.h"
4445

45-
/**
46-
* @brief ECDSA signature size for a given curve bit size
47-
*
48-
* @note This macro returns a compile-time constant if its argument is one.
49-
*
50-
* @param curve_bits Curve size in bits.
51-
*
52-
* @return Signature size in bytes.
53-
*/
54-
#define PSA_ECDSA_SIGNATURE_SIZE(curve_bits) \
55-
((size_t)(PSA_BITS_TO_BYTES(curve_bits) * 2))
56-
57-
/**
58-
* @brief Sufficient signature buffer size for @ref psa_sign_message() and @ref psa_sign_hash().
59-
*
60-
* @details If the size of the signature buffer is at least this large, it is guaranteed that
61-
* @ref psa_sign_message() and @ref psa_sign_hash() will not fail due to an insufficient
62-
* buffer size. The actual size of the output might be smaller in any given call.
63-
*
64-
* See also @ref PSA_SIGNATURE_MAX_SIZE.
65-
*
66-
* @param key_type An asymmetric key type. This can be a key pair type or a public key type.
67-
* @param key_bits The size of the key in bits.
68-
* @param alg The signature algorithm.
69-
*
70-
* @return A sufficient signature buffer size for the specified asymmetric signature algorithm and
71-
* key parameters.
72-
* 0 if algorithm and key parameters are not supported.
73-
* If the parameters are not valid, the return value is unspecified.
74-
*/
75-
#define PSA_SIGN_OUTPUT_SIZE(key_type, key_bits, alg) \
76-
(PSA_KEY_TYPE_IS_ECC(key_type) ? PSA_ECDSA_SIGNATURE_SIZE(key_bits) : \
77-
((void)alg, 0))
78-
7946
#ifdef __cplusplus
8047
}
8148
#endif

sys/include/psa_crypto/psa/crypto_values.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,6 @@ extern "C" {
3939
#include "psa/asymmetric_encryption/algorithm.h"
4040
#include "psa/asymmetric_signature/algorithm.h"
4141

42-
/**
43-
* @brief A sufficient signature buffer size for @ref psa_sign_message() and
44-
* @ref psa_sign_hash(), for any of the supported key types and asymmetric signature
45-
* algorithms.
46-
*
47-
* @details If the size of the signature buffer is at least this large, it is guaranteed that
48-
* @ref psa_sign_message() and @ref psa_sign_hash() will not fail due to an insufficient
49-
* buffer size.
50-
*
51-
* See also @ref PSA_SIGN_OUTPUT_SIZE().
52-
*/
53-
#define PSA_SIGNATURE_MAX_SIZE /* implementation-defined value */
54-
5542
#ifdef __cplusplus
5643
}
5744
#endif

0 commit comments

Comments
 (0)