mirror of
				https://github.com/cuberite/polarssl.git
				synced 2025-11-03 20:22:59 -05:00 
			
		
		
		
	Addapt psa_generate_key() tests
Signed-off-by: Przemyslaw Stekiel <przemyslaw.stekiel@mobica.com>
This commit is contained in:
		
							parent
							
								
									770153e836
								
							
						
					
					
						commit
						d9d630cdf3
					
				@ -133,7 +133,7 @@ class Information:
 | 
				
			|||||||
        return constructors
 | 
					        return constructors
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def test_case_for_key_type_not_supported(
 | 
					def test_case_for_key_type_not_supported_invalid_arg(
 | 
				
			||||||
        verb: str, key_type: str, bits: int,
 | 
					        verb: str, key_type: str, bits: int,
 | 
				
			||||||
        dependencies: List[str],
 | 
					        dependencies: List[str],
 | 
				
			||||||
        *args: str,
 | 
					        *args: str,
 | 
				
			||||||
@ -148,10 +148,15 @@ def test_case_for_key_type_not_supported(
 | 
				
			|||||||
    adverb = 'not' if dependencies else 'never'
 | 
					    adverb = 'not' if dependencies else 'never'
 | 
				
			||||||
    if param_descr:
 | 
					    if param_descr:
 | 
				
			||||||
        adverb = param_descr + ' ' + adverb
 | 
					        adverb = param_descr + ' ' + adverb
 | 
				
			||||||
    tc.set_description('PSA {} {} {}-bit {} supported'
 | 
					    if (verb == "generate") and ("PUBLIC" in short_key_type):
 | 
				
			||||||
                       .format(verb, short_key_type, bits, adverb))
 | 
					        tc.set_description('PSA {} {} {}-bit invalid argument'
 | 
				
			||||||
 | 
					                    .format(verb, short_key_type, bits))
 | 
				
			||||||
 | 
					        tc.set_function(verb + '_invalid_arg')
 | 
				
			||||||
 | 
					    else:
 | 
				
			||||||
 | 
					        tc.set_description('PSA {} {} {}-bit {} supported'
 | 
				
			||||||
 | 
					                        .format(verb, short_key_type, bits, adverb))
 | 
				
			||||||
 | 
					        tc.set_function(verb + '_not_supported')
 | 
				
			||||||
    tc.set_dependencies(dependencies)
 | 
					    tc.set_dependencies(dependencies)
 | 
				
			||||||
    tc.set_function(verb + '_not_supported')
 | 
					 | 
				
			||||||
    tc.set_arguments([key_type] + list(args))
 | 
					    tc.set_arguments([key_type] + list(args))
 | 
				
			||||||
    return tc
 | 
					    return tc
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -192,7 +197,7 @@ class NotSupported:
 | 
				
			|||||||
        else:
 | 
					        else:
 | 
				
			||||||
            generate_dependencies = import_dependencies
 | 
					            generate_dependencies = import_dependencies
 | 
				
			||||||
        for bits in kt.sizes_to_test():
 | 
					        for bits in kt.sizes_to_test():
 | 
				
			||||||
            yield test_case_for_key_type_not_supported(
 | 
					            yield test_case_for_key_type_not_supported_invalid_arg(
 | 
				
			||||||
                'import', kt.expression, bits,
 | 
					                'import', kt.expression, bits,
 | 
				
			||||||
                finish_family_dependencies(import_dependencies, bits),
 | 
					                finish_family_dependencies(import_dependencies, bits),
 | 
				
			||||||
                test_case.hex_string(kt.key_material(bits)),
 | 
					                test_case.hex_string(kt.key_material(bits)),
 | 
				
			||||||
@ -203,7 +208,7 @@ class NotSupported:
 | 
				
			|||||||
                # supported or not depending on implementation capabilities,
 | 
					                # supported or not depending on implementation capabilities,
 | 
				
			||||||
                # only generate the test case once.
 | 
					                # only generate the test case once.
 | 
				
			||||||
                continue
 | 
					                continue
 | 
				
			||||||
            yield test_case_for_key_type_not_supported(
 | 
					            yield test_case_for_key_type_not_supported_invalid_arg(
 | 
				
			||||||
                'generate', kt.expression, bits,
 | 
					                'generate', kt.expression, bits,
 | 
				
			||||||
                finish_family_dependencies(generate_dependencies, bits),
 | 
					                finish_family_dependencies(generate_dependencies, bits),
 | 
				
			||||||
                str(bits),
 | 
					                str(bits),
 | 
				
			||||||
 | 
				
			|||||||
@ -4705,7 +4705,7 @@ generate_random:2 * MBEDTLS_CTR_DRBG_MAX_REQUEST + 1
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
PSA generate key: bad type (RSA public key)
 | 
					PSA generate key: bad type (RSA public key)
 | 
				
			||||||
depends_on:PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY
 | 
					depends_on:PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY
 | 
				
			||||||
generate_key:PSA_KEY_TYPE_RSA_PUBLIC_KEY:512:PSA_KEY_USAGE_EXPORT:0:PSA_ERROR_NOT_SUPPORTED:0
 | 
					generate_key:PSA_KEY_TYPE_RSA_PUBLIC_KEY:512:PSA_KEY_USAGE_EXPORT:0:PSA_ERROR_INVALID_ARGUMENT:0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
PSA generate key: raw data, 0 bits: invalid argument
 | 
					PSA generate key: raw data, 0 bits: invalid argument
 | 
				
			||||||
# The spec allows either INVALID_ARGUMENT or NOT_SUPPORTED
 | 
					# The spec allows either INVALID_ARGUMENT or NOT_SUPPORTED
 | 
				
			||||||
 | 
				
			|||||||
@ -50,3 +50,22 @@ exit:
 | 
				
			|||||||
    PSA_DONE( );
 | 
					    PSA_DONE( );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
/* END_CASE */
 | 
					/* END_CASE */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* BEGIN_CASE */
 | 
				
			||||||
 | 
					void generate_invalid_arg( int key_type, int bits )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
 | 
				
			||||||
 | 
					    mbedtls_svc_key_id_t key_id = INVALID_KEY_ID;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    PSA_ASSERT( psa_crypto_init( ) );
 | 
				
			||||||
 | 
					    psa_set_key_type( &attributes, key_type );
 | 
				
			||||||
 | 
					    psa_set_key_bits( &attributes, bits );
 | 
				
			||||||
 | 
					    TEST_EQUAL( psa_generate_key( &attributes, &key_id ),
 | 
				
			||||||
 | 
					                PSA_ERROR_INVALID_ARGUMENT );
 | 
				
			||||||
 | 
					    TEST_ASSERT( mbedtls_svc_key_id_equal( key_id, MBEDTLS_SVC_KEY_ID_INIT ) );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					exit:
 | 
				
			||||||
 | 
					    psa_destroy_key( key_id );
 | 
				
			||||||
 | 
					    PSA_DONE( );
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					/* END_CASE */
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user