mirror of
				https://github.com/Mbed-TLS/mbedtls.git
				synced 2025-10-31 21:50:31 +03:00 
			
		
		
		
	Add PSA interuptable key agreement APIs
Signed-off-by: Waleed Elmelegy <waleed.elmelegy@arm.com>
This commit is contained in:
		| @@ -2701,6 +2701,116 @@ static inline psa_status_t psa_driver_wrapper_key_agreement( | ||||
|     } | ||||
| } | ||||
|  | ||||
| static inline uint32_t psa_driver_wrapper_key_agreement_get_num_ops( | ||||
|     psa_key_agreement_iop_t *operation) | ||||
| { | ||||
|     switch( operation->id ) | ||||
|     { | ||||
|         /* If uninitialised, return 0, as no work can have been done. */ | ||||
|         case 0: | ||||
|             return 0; | ||||
|  | ||||
|         case PSA_CRYPTO_MBED_TLS_DRIVER_ID: | ||||
|             return(mbedtls_psa_key_agreement_get_num_ops(&operation->ctx.mbedtls_ctx)); | ||||
|  | ||||
| #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) | ||||
|  | ||||
| #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ | ||||
|     } | ||||
|  | ||||
|     return 0; | ||||
| } | ||||
|  | ||||
| static inline psa_status_t psa_driver_wrapper_key_agreement_setup( | ||||
|     psa_key_agreement_iop_t *operation, | ||||
|     const uint8_t *private_key_buffer, | ||||
|     size_t private_key_buffer_len, | ||||
|     const uint8_t *peer_key, | ||||
|     size_t peer_key_length, | ||||
|     const psa_key_attributes_t *attributes) | ||||
| { | ||||
|     psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED; | ||||
|     psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION( | ||||
|                                                     psa_get_key_lifetime(attributes) ); | ||||
|  | ||||
|     switch( location ) | ||||
|     { | ||||
|         case PSA_KEY_LOCATION_LOCAL_STORAGE: | ||||
|             /* Key is stored in the slot in export representation, so | ||||
|              * cycle through all known transparent accelerators */ | ||||
|  | ||||
| #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) | ||||
|  | ||||
|  | ||||
| #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ | ||||
|  | ||||
|             /* Fell through, meaning no accelerator supports this operation */ | ||||
|             operation->id = PSA_CRYPTO_MBED_TLS_DRIVER_ID; | ||||
|             status = mbedtls_psa_key_agreement_setup(&operation->ctx.mbedtls_ctx, private_key_buffer, | ||||
|                                                     private_key_buffer_len, peer_key, | ||||
|                                                     peer_key_length, | ||||
|                                                     attributes); | ||||
|             break; | ||||
|  | ||||
|             /* Add cases for opaque driver here */ | ||||
|  | ||||
|             default: | ||||
|                 /* Key is declared with a lifetime not known to us */ | ||||
|                 status = PSA_ERROR_INVALID_ARGUMENT; | ||||
|                 break; | ||||
|     } | ||||
|     return( status ); | ||||
|  | ||||
| } | ||||
|  | ||||
| static inline psa_status_t psa_driver_wrapper_key_agreement_complete( | ||||
|     psa_key_agreement_iop_t *operation, | ||||
|     uint8_t *shared_secret, | ||||
|     size_t shared_secret_size, | ||||
|     size_t *shared_secret_length) | ||||
| { | ||||
|     psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED; | ||||
|     switch( operation->id ) | ||||
|     { | ||||
|         case PSA_CRYPTO_MBED_TLS_DRIVER_ID: | ||||
|             status = mbedtls_psa_key_agreement_complete(&operation->ctx.mbedtls_ctx, shared_secret, | ||||
|                                                         shared_secret_size, | ||||
|                                                         shared_secret_length); | ||||
|             break; | ||||
|  | ||||
| #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) | ||||
|  | ||||
|  | ||||
| #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ | ||||
|         default: | ||||
|             status = PSA_ERROR_INVALID_ARGUMENT; | ||||
|             break; | ||||
|     } | ||||
|     return( status ); | ||||
| } | ||||
|  | ||||
| static inline psa_status_t psa_driver_wrapper_key_agreement_abort( | ||||
|     psa_key_agreement_iop_t *operation) | ||||
| { | ||||
|     psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED; | ||||
|     switch( operation->id ) | ||||
|     { | ||||
|         case PSA_CRYPTO_MBED_TLS_DRIVER_ID: | ||||
|             status = mbedtls_psa_key_agreement_abort(&operation->ctx.mbedtls_ctx); | ||||
|             break; | ||||
|  | ||||
| #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT) | ||||
|  | ||||
|  | ||||
| #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */ | ||||
|         default: | ||||
|             status = PSA_ERROR_INVALID_ARGUMENT; | ||||
|             break; | ||||
|     } | ||||
|     return( status ); | ||||
| } | ||||
|  | ||||
|  | ||||
| static inline psa_status_t psa_driver_wrapper_pake_setup( | ||||
|     psa_pake_operation_t *operation, | ||||
|     const psa_crypto_driver_pake_inputs_t *inputs ) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user