Skip to content

Commit 0de74c2

Browse files
committed
[nrf noup] psa: Using simpler initialization for operation structs
-This simplifies PSA crypto operation struct initialization to better tailor to the SSF use-case. This simplifies the initializers to only be empty brackets, assuming zero-initialized structs without the added complexities of writing every sub-type out. This is done to prevent compilation warnings for PSA crypto builds. Signed-off-by: Frank Audun Kvamtrø <frank.kvamtro@nordicsemi.no>
1 parent c3443d2 commit 0de74c2

File tree

1 file changed

+23
-43
lines changed

1 file changed

+23
-43
lines changed

include/psa/crypto_struct.h

+23-43
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@
5454
#define PSA_CRYPTO_STRUCT_H
5555
#include "mbedtls/private_access.h"
5656

57+
#include <inttypes.h>
58+
5759
#ifdef __cplusplus
5860
extern "C" {
5961
#endif
@@ -85,11 +87,9 @@ struct psa_hash_operation_s {
8587
psa_driver_hash_context_t MBEDTLS_PRIVATE(ctx);
8688
#endif
8789
};
88-
#if defined(MBEDTLS_PSA_CRYPTO_CLIENT) && !defined(MBEDTLS_PSA_CRYPTO_C)
89-
#define PSA_HASH_OPERATION_INIT { 0 }
90-
#else
91-
#define PSA_HASH_OPERATION_INIT { 0, { 0 } }
92-
#endif
90+
91+
#define PSA_HASH_OPERATION_INIT { }
92+
9393
static inline struct psa_hash_operation_s psa_hash_operation_init(void)
9494
{
9595
const struct psa_hash_operation_s v = PSA_HASH_OPERATION_INIT;
@@ -117,11 +117,9 @@ struct psa_cipher_operation_s {
117117
#endif
118118
};
119119

120-
#if defined(MBEDTLS_PSA_CRYPTO_CLIENT) && !defined(MBEDTLS_PSA_CRYPTO_C)
121-
#define PSA_CIPHER_OPERATION_INIT { 0 }
122-
#else
123-
#define PSA_CIPHER_OPERATION_INIT { 0, 0, 0, 0, { 0 } }
124-
#endif
120+
121+
#define PSA_CIPHER_OPERATION_INIT { }
122+
125123
static inline struct psa_cipher_operation_s psa_cipher_operation_init(void)
126124
{
127125
const struct psa_cipher_operation_s v = PSA_CIPHER_OPERATION_INIT;
@@ -149,11 +147,8 @@ struct psa_mac_operation_s {
149147
#endif
150148
};
151149

152-
#if defined(MBEDTLS_PSA_CRYPTO_CLIENT) && !defined(MBEDTLS_PSA_CRYPTO_C)
153-
#define PSA_MAC_OPERATION_INIT { 0 }
154-
#else
155-
#define PSA_MAC_OPERATION_INIT { 0, 0, 0, { 0 } }
156-
#endif
150+
#define PSA_MAC_OPERATION_INIT { }
151+
157152
static inline struct psa_mac_operation_s psa_mac_operation_init(void)
158153
{
159154
const struct psa_mac_operation_s v = PSA_MAC_OPERATION_INIT;
@@ -188,11 +183,9 @@ struct psa_aead_operation_s {
188183
#endif
189184
};
190185

191-
#if defined(MBEDTLS_PSA_CRYPTO_CLIENT) && !defined(MBEDTLS_PSA_CRYPTO_C)
192-
#define PSA_AEAD_OPERATION_INIT { 0 }
193-
#else
194-
#define PSA_AEAD_OPERATION_INIT { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, { 0 } }
195-
#endif
186+
187+
#define PSA_AEAD_OPERATION_INIT { }
188+
196189
static inline struct psa_aead_operation_s psa_aead_operation_init(void)
197190
{
198191
const struct psa_aead_operation_s v = PSA_AEAD_OPERATION_INIT;
@@ -233,12 +226,9 @@ struct psa_key_derivation_s { /*!!OM*/
233226
#endif
234227
};
235228

236-
#if defined(MBEDTLS_PSA_CRYPTO_CLIENT) && !defined(MBEDTLS_PSA_CRYPTO_C)
237-
#define PSA_KEY_DERIVATION_OPERATION_INIT { 0 }
238-
#else
239-
/* This only zeroes out the first byte in the union, the rest is unspecified. */
240-
#define PSA_KEY_DERIVATION_OPERATION_INIT { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, { 0 } }
241-
#endif
229+
230+
#define PSA_KEY_DERIVATION_OPERATION_INIT { }
231+
242232
static inline struct psa_key_derivation_s psa_key_derivation_operation_init(
243233
void)
244234
{
@@ -321,7 +311,7 @@ struct psa_key_attributes_s {
321311
};
322312

323313
/* This will assert if there has ben an incompatible change in psa_key_attributes_s */
324-
_Static_assert(sizeof(psa_key_attributes_s) == 32, "Unexpected struct size.");
314+
//_Static_assert(sizeof(struct psa_key_attributes_s) == 32, "Unexpected struct size.");
325315

326316
#if defined(MBEDTLS_PSA_CRYPTO_SE_C)
327317
#define PSA_KEY_ATTRIBUTES_MAYBE_SLOT_NUMBER 0, 0,
@@ -507,12 +497,9 @@ struct psa_pake_operation_s { /*!!OM*/
507497
#endif
508498
};
509499

510-
#if defined(MBEDTLS_PSA_CRYPTO_CLIENT) && !defined(MBEDTLS_PSA_CRYPTO_C)
511-
#define PSA_PAKE_OPERATION_INIT { 0 }
512-
#else
513-
/* This only zeroes out the first byte in the union, the rest is unspecified. */
514-
#define PSA_PAKE_OPERATION_INIT { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, { 0 } }
515-
#endif
500+
501+
#define PSA_PAKE_OPERATION_INIT { }
502+
516503
static inline struct psa_pake_operation_s psa_pake_operation_init(void)
517504
{
518505
const struct psa_pake_operation_s v = PSA_PAKE_OPERATION_INIT;
@@ -542,11 +529,7 @@ struct psa_sign_hash_interruptible_operation_s {
542529
#endif
543530
};
544531

545-
#if defined(MBEDTLS_PSA_CRYPTO_CLIENT) && !defined(MBEDTLS_PSA_CRYPTO_C)
546-
#define PSA_SIGN_HASH_INTERRUPTIBLE_OPERATION_INIT { 0 }
547-
#else
548-
#define PSA_SIGN_HASH_INTERRUPTIBLE_OPERATION_INIT { 0, { 0 }, 0, 0 }
549-
#endif
532+
#define PSA_SIGN_HASH_INTERRUPTIBLE_OPERATION_INIT { }
550533

551534
static inline struct psa_sign_hash_interruptible_operation_s
552535
psa_sign_hash_interruptible_operation_init(void)
@@ -580,11 +563,8 @@ struct psa_verify_hash_interruptible_operation_s {
580563
#endif
581564
};
582565

583-
#if defined(MBEDTLS_PSA_CRYPTO_CLIENT) && !defined(MBEDTLS_PSA_CRYPTO_C)
584-
#define PSA_VERIFY_HASH_INTERRUPTIBLE_OPERATION_INIT { 0 }
585-
#else
586-
#define PSA_VERIFY_HASH_INTERRUPTIBLE_OPERATION_INIT { 0, { 0 }, 0, 0 }
587-
#endif
566+
567+
#define PSA_VERIFY_HASH_INTERRUPTIBLE_OPERATION_INIT { }
588568

589569
static inline struct psa_verify_hash_interruptible_operation_s
590570
psa_verify_hash_interruptible_operation_init(void)

0 commit comments

Comments
 (0)