mirror of
				https://github.com/cuberite/polarssl.git
				synced 2025-11-03 20:22:59 -05:00 
			
		
		
		
	Fix the build without persistent storage
Add missing guards on MBEDTLS_PSA_CRYPTO_STORAGE_C. Add test cases to test that psa_create_key and psa_open_key return NOT_SUPPORTED.
This commit is contained in:
		
							parent
							
								
									c5487a8892
								
							
						
					
					
						commit
						4a044739a8
					
				@ -888,6 +888,7 @@ psa_status_t psa_internal_allocate_key_slot( psa_key_handle_t *handle )
 | 
				
			|||||||
psa_status_t psa_internal_make_key_persistent( psa_key_handle_t handle,
 | 
					psa_status_t psa_internal_make_key_persistent( psa_key_handle_t handle,
 | 
				
			||||||
                                               psa_key_id_t id )
 | 
					                                               psa_key_id_t id )
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					#if defined(MBEDTLS_PSA_CRYPTO_STORAGE_C)
 | 
				
			||||||
    key_slot_t *slot;
 | 
					    key_slot_t *slot;
 | 
				
			||||||
    psa_status_t status;
 | 
					    psa_status_t status;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -909,6 +910,12 @@ psa_status_t psa_internal_make_key_persistent( psa_key_handle_t handle,
 | 
				
			|||||||
    status = psa_load_persistent_key_into_slot( slot );
 | 
					    status = psa_load_persistent_key_into_slot( slot );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return( status );
 | 
					    return( status );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#else /* MBEDTLS_PSA_CRYPTO_STORAGE_C */
 | 
				
			||||||
 | 
					    (void) handle;
 | 
				
			||||||
 | 
					    (void) id;
 | 
				
			||||||
 | 
					    return( PSA_ERROR_NOT_SUPPORTED );
 | 
				
			||||||
 | 
					#endif /* !MBEDTLS_PSA_CRYPTO_STORAGE_C */
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
psa_status_t psa_internal_release_key_slot( psa_key_handle_t handle )
 | 
					psa_status_t psa_internal_release_key_slot( psa_key_handle_t handle )
 | 
				
			||||||
 | 
				
			|||||||
@ -38,20 +38,33 @@ depends_on:MBEDTLS_AES_C
 | 
				
			|||||||
create_existent:PSA_KEY_LIFETIME_PERSISTENT:1:PSA_KEY_TYPE_AES:KEEP_OPEN
 | 
					create_existent:PSA_KEY_LIFETIME_PERSISTENT:1:PSA_KEY_TYPE_AES:KEEP_OPEN
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Open failure: non-existent identifier
 | 
					Open failure: non-existent identifier
 | 
				
			||||||
 | 
					depends_on:MBEDTLS_PSA_CRYPTO_STORAGE_C
 | 
				
			||||||
open_fail:PSA_KEY_LIFETIME_PERSISTENT:1:PSA_ERROR_EMPTY_SLOT
 | 
					open_fail:PSA_KEY_LIFETIME_PERSISTENT:1:PSA_ERROR_EMPTY_SLOT
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Open failure: volatile lifetime
 | 
					Open failure: volatile lifetime
 | 
				
			||||||
 | 
					depends_on:MBEDTLS_PSA_CRYPTO_STORAGE_C
 | 
				
			||||||
open_fail:PSA_KEY_LIFETIME_VOLATILE:1:PSA_ERROR_INVALID_ARGUMENT
 | 
					open_fail:PSA_KEY_LIFETIME_VOLATILE:1:PSA_ERROR_INVALID_ARGUMENT
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Open failure: invalid lifetime
 | 
					Open failure: invalid lifetime
 | 
				
			||||||
 | 
					depends_on:MBEDTLS_PSA_CRYPTO_STORAGE_C
 | 
				
			||||||
open_fail:0x7fffffff:0:PSA_ERROR_INVALID_ARGUMENT
 | 
					open_fail:0x7fffffff:0:PSA_ERROR_INVALID_ARGUMENT
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Create failure: volatile lifetime
 | 
					Create failure: volatile lifetime
 | 
				
			||||||
 | 
					depends_on:MBEDTLS_PSA_CRYPTO_STORAGE_C
 | 
				
			||||||
create_fail:PSA_KEY_LIFETIME_VOLATILE:1:PSA_KEY_TYPE_RAW_DATA:8:PSA_ERROR_INVALID_ARGUMENT
 | 
					create_fail:PSA_KEY_LIFETIME_VOLATILE:1:PSA_KEY_TYPE_RAW_DATA:8:PSA_ERROR_INVALID_ARGUMENT
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Create failure: invalid lifetime
 | 
					Create failure: invalid lifetime
 | 
				
			||||||
 | 
					depends_on:MBEDTLS_PSA_CRYPTO_STORAGE_C
 | 
				
			||||||
create_fail:0x7fffffff:0:PSA_KEY_TYPE_RAW_DATA:8:PSA_ERROR_INVALID_ARGUMENT
 | 
					create_fail:0x7fffffff:0:PSA_KEY_TYPE_RAW_DATA:8:PSA_ERROR_INVALID_ARGUMENT
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Open not supported
 | 
				
			||||||
 | 
					depends_on:!MBEDTLS_PSA_CRYPTO_STORAGE_C
 | 
				
			||||||
 | 
					open_fail:PSA_KEY_LIFETIME_PERSISTENT:1:PSA_ERROR_NOT_SUPPORTED
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Create not supported
 | 
				
			||||||
 | 
					depends_on:!MBEDTLS_PSA_CRYPTO_STORAGE_C
 | 
				
			||||||
 | 
					create_fail:PSA_KEY_LIFETIME_PERSISTENT:1:PSA_KEY_TYPE_RAW_DATA:8:PSA_ERROR_NOT_SUPPORTED
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Close/destroy invalid handle
 | 
					Close/destroy invalid handle
 | 
				
			||||||
invalid_handle:
 | 
					invalid_handle:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -29,6 +29,7 @@ typedef enum
 | 
				
			|||||||
 * identifier, and must call psa_purge_key_storage() in their cleanup
 | 
					 * identifier, and must call psa_purge_key_storage() in their cleanup
 | 
				
			||||||
 * code. */
 | 
					 * code. */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if defined(MBEDTLS_PSA_CRYPTO_STORAGE_C)
 | 
				
			||||||
/* There is no API to purge all keys. For this test suite, require that
 | 
					/* There is no API to purge all keys. For this test suite, require that
 | 
				
			||||||
 * all key IDs be less than a certain maximum. */
 | 
					 * all key IDs be less than a certain maximum. */
 | 
				
			||||||
#define MAX_KEY_ID_FOR_TEST 32
 | 
					#define MAX_KEY_ID_FOR_TEST 32
 | 
				
			||||||
@ -43,6 +44,9 @@ void psa_purge_key_storage( void )
 | 
				
			|||||||
    for( i = 0; i <= MAX_KEY_ID_FOR_TEST; i++ )
 | 
					    for( i = 0; i <= MAX_KEY_ID_FOR_TEST; i++ )
 | 
				
			||||||
        psa_destroy_persistent_key( i );
 | 
					        psa_destroy_persistent_key( i );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					#define TEST_MAX_KEY_ID( key_id ) ( (void) ( key_id ) )
 | 
				
			||||||
 | 
					#endif /* MBEDTLS_PSA_CRYPTO_STORAGE_C */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int psa_key_policy_equal( psa_key_policy_t *p1,
 | 
					static int psa_key_policy_equal( psa_key_policy_t *p1,
 | 
				
			||||||
                                 psa_key_policy_t *p2 )
 | 
					                                 psa_key_policy_t *p2 )
 | 
				
			||||||
@ -109,7 +113,7 @@ exit:
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
/* END_CASE */
 | 
					/* END_CASE */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* BEGIN_CASE */
 | 
					/* BEGIN_CASE depends_on:MBEDTLS_PSA_CRYPTO_STORAGE_C */
 | 
				
			||||||
void persistent_slot_lifecycle( int lifetime_arg, int id_arg,
 | 
					void persistent_slot_lifecycle( int lifetime_arg, int id_arg,
 | 
				
			||||||
                                int type_arg, int max_bits_arg,
 | 
					                                int type_arg, int max_bits_arg,
 | 
				
			||||||
                                int alg_arg, int usage_arg,
 | 
					                                int alg_arg, int usage_arg,
 | 
				
			||||||
@ -188,7 +192,7 @@ exit:
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
/* END_CASE */
 | 
					/* END_CASE */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* BEGIN_CASE */
 | 
					/* BEGIN_CASE depends_on:MBEDTLS_PSA_CRYPTO_STORAGE_C */
 | 
				
			||||||
void create_existent( int lifetime_arg, int id_arg,
 | 
					void create_existent( int lifetime_arg, int id_arg,
 | 
				
			||||||
                      int new_type_arg,
 | 
					                      int new_type_arg,
 | 
				
			||||||
                      int reopen_policy_arg )
 | 
					                      int reopen_policy_arg )
 | 
				
			||||||
@ -293,7 +297,9 @@ void create_fail( int lifetime_arg, int id_arg,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
exit:
 | 
					exit:
 | 
				
			||||||
    mbedtls_psa_crypto_free( );
 | 
					    mbedtls_psa_crypto_free( );
 | 
				
			||||||
 | 
					#if defined(MBEDTLS_PSA_CRYPTO_STORAGE_C)
 | 
				
			||||||
    psa_purge_key_storage( );
 | 
					    psa_purge_key_storage( );
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
/* END_CASE */
 | 
					/* END_CASE */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user