mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-07-29 11:41:15 +03:00
Merge pull request #4338 from paul-elliott-arm/psa-m-aead
Implement multipart PSA AEAD
This commit is contained in:
@ -77,6 +77,41 @@ typedef struct
|
||||
|
||||
#define MBEDTLS_PSA_MAC_OPERATION_INIT {0, {0}}
|
||||
|
||||
#if defined(MBEDTLS_PSA_BUILTIN_ALG_GCM) || \
|
||||
defined(MBEDTLS_PSA_BUILTIN_ALG_CCM) || \
|
||||
defined(MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305)
|
||||
#define MBEDTLS_PSA_BUILTIN_AEAD 1
|
||||
#endif
|
||||
|
||||
/* Context structure for the Mbed TLS AEAD implementation. */
|
||||
typedef struct
|
||||
{
|
||||
psa_algorithm_t MBEDTLS_PRIVATE(alg);
|
||||
psa_key_type_t MBEDTLS_PRIVATE(key_type);
|
||||
|
||||
unsigned int MBEDTLS_PRIVATE(is_encrypt) : 1;
|
||||
|
||||
uint8_t MBEDTLS_PRIVATE(tag_length);
|
||||
|
||||
union
|
||||
{
|
||||
unsigned dummy; /* Enable easier initializing of the union. */
|
||||
#if defined(MBEDTLS_PSA_BUILTIN_ALG_CCM)
|
||||
mbedtls_ccm_context MBEDTLS_PRIVATE(ccm);
|
||||
#endif /* MBEDTLS_PSA_BUILTIN_ALG_CCM */
|
||||
#if defined(MBEDTLS_PSA_BUILTIN_ALG_GCM)
|
||||
mbedtls_gcm_context MBEDTLS_PRIVATE(gcm);
|
||||
#endif /* MBEDTLS_PSA_BUILTIN_ALG_GCM */
|
||||
#if defined(MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305)
|
||||
mbedtls_chachapoly_context MBEDTLS_PRIVATE(chachapoly);
|
||||
#endif /* MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305 */
|
||||
|
||||
} ctx;
|
||||
|
||||
} mbedtls_psa_aead_operation_t;
|
||||
|
||||
#define MBEDTLS_PSA_AEAD_OPERATION_INIT {0, 0, 0, 0, {0}}
|
||||
|
||||
/*
|
||||
* BEYOND THIS POINT, TEST DRIVER DECLARATIONS ONLY.
|
||||
*/
|
||||
@ -88,6 +123,10 @@ typedef mbedtls_psa_mac_operation_t mbedtls_opaque_test_driver_mac_operation_t;
|
||||
#define MBEDTLS_TRANSPARENT_TEST_DRIVER_MAC_OPERATION_INIT MBEDTLS_PSA_MAC_OPERATION_INIT
|
||||
#define MBEDTLS_OPAQUE_TEST_DRIVER_MAC_OPERATION_INIT MBEDTLS_PSA_MAC_OPERATION_INIT
|
||||
|
||||
typedef mbedtls_psa_aead_operation_t mbedtls_transparent_test_driver_aead_operation_t;
|
||||
|
||||
#define MBEDTLS_TRANSPARENT_TEST_DRIVER_AEAD_OPERATION_INIT MBEDTLS_PSA_AEAD_OPERATION_INIT
|
||||
|
||||
#endif /* PSA_CRYPTO_DRIVER_TEST */
|
||||
|
||||
#endif /* PSA_CRYPTO_BUILTIN_COMPOSITES_H */
|
||||
|
@ -58,5 +58,13 @@ typedef union {
|
||||
#endif
|
||||
} psa_driver_mac_context_t;
|
||||
|
||||
typedef union {
|
||||
unsigned dummy; /* Make sure this union is always non-empty */
|
||||
mbedtls_psa_aead_operation_t mbedtls_ctx;
|
||||
#if defined(PSA_CRYPTO_DRIVER_TEST)
|
||||
mbedtls_transparent_test_driver_aead_operation_t transparent_test_driver_ctx;
|
||||
#endif
|
||||
} psa_driver_aead_context_t;
|
||||
|
||||
#endif /* PSA_CRYPTO_DRIVER_CONTEXTS_COMPOSITES_H */
|
||||
/* End of automatically generated file. */
|
||||
|
@ -72,6 +72,8 @@ extern "C" {
|
||||
|
||||
#include "mbedtls/cmac.h"
|
||||
#include "mbedtls/gcm.h"
|
||||
#include "mbedtls/ccm.h"
|
||||
#include "mbedtls/chachapoly.h"
|
||||
|
||||
/* Include the context definition for the compiled-in drivers for the primitive
|
||||
* algorithms. */
|
||||
@ -148,19 +150,31 @@ static inline struct psa_mac_operation_s psa_mac_operation_init( void )
|
||||
|
||||
struct psa_aead_operation_s
|
||||
{
|
||||
|
||||
/** Unique ID indicating which driver got assigned to do the
|
||||
* operation. Since driver contexts are driver-specific, swapping
|
||||
* drivers halfway through the operation is not supported.
|
||||
* ID values are auto-generated in psa_crypto_driver_wrappers.h
|
||||
* ID value zero means the context is not valid or not assigned to
|
||||
* any driver (i.e. none of the driver contexts are active). */
|
||||
unsigned int MBEDTLS_PRIVATE(id);
|
||||
|
||||
psa_algorithm_t MBEDTLS_PRIVATE(alg);
|
||||
unsigned int MBEDTLS_PRIVATE(key_set) : 1;
|
||||
unsigned int MBEDTLS_PRIVATE(iv_set) : 1;
|
||||
uint8_t MBEDTLS_PRIVATE(iv_size);
|
||||
uint8_t MBEDTLS_PRIVATE(block_size);
|
||||
union
|
||||
{
|
||||
unsigned MBEDTLS_PRIVATE(dummy); /* Enable easier initializing of the union. */
|
||||
mbedtls_cipher_context_t MBEDTLS_PRIVATE(cipher);
|
||||
} MBEDTLS_PRIVATE(ctx);
|
||||
psa_key_type_t MBEDTLS_PRIVATE(key_type);
|
||||
|
||||
size_t MBEDTLS_PRIVATE(ad_remaining);
|
||||
size_t MBEDTLS_PRIVATE(body_remaining);
|
||||
|
||||
unsigned int MBEDTLS_PRIVATE(nonce_set) : 1;
|
||||
unsigned int MBEDTLS_PRIVATE(lengths_set) : 1;
|
||||
unsigned int MBEDTLS_PRIVATE(ad_started) : 1;
|
||||
unsigned int MBEDTLS_PRIVATE(body_started) : 1;
|
||||
unsigned int MBEDTLS_PRIVATE(is_encrypt) : 1;
|
||||
|
||||
psa_driver_aead_context_t MBEDTLS_PRIVATE(ctx);
|
||||
};
|
||||
|
||||
#define PSA_AEAD_OPERATION_INIT { 0, 0, 0, 0, 0, { 0 } }
|
||||
#define PSA_AEAD_OPERATION_INIT {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0}}
|
||||
static inline struct psa_aead_operation_s psa_aead_operation_init( void )
|
||||
{
|
||||
const struct psa_aead_operation_s v = PSA_AEAD_OPERATION_INIT;
|
||||
|
Reference in New Issue
Block a user