65 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
		
		
			
		
	
	
			65 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
|  | #include <stdio.h>
 | ||
|  | #include <stdbool.h>
 | ||
|  | #include "iot_config.h"
 | ||
|  | #include "keypair.h"
 | ||
|  | #include "log.h"
 | ||
|  | static bool | ||
|  | _test_create_fail() | ||
|  | { | ||
|  |     if (IOTELIC_OK == keypair_create(KEY_SLOT_0, KEYPAIR_INVALID)) { | ||
|  |         LOG("Success result with wrong intup data. So, it's bug."); | ||
|  |         return false; | ||
|  |     } | ||
|  |     return true; | ||
|  | } | ||
|  | static bool | ||
|  | _test_create_key(KEYSTORAGE_SLOT key_slot, KEYPAIR_TYPE keypair_type) | ||
|  | { | ||
|  |     if (IOTELIC_OK != keypair_create(key_slot, keypair_type)) { | ||
|  |         LOG("%s keypair can't be created", keypair_name(keypair_type)); | ||
|  |         return false; | ||
|  |     } else { | ||
|  |         LOG("    %s keypair created successfully", keypair_name(keypair_type)); | ||
|  |     } | ||
|  |     return true; | ||
|  | } | ||
|  | 
 | ||
|  | static bool | ||
|  | _test_key_get_nist256r1_pass() | ||
|  | { | ||
|  |     uint8_t public_key[128]; | ||
|  |     size_t public_key_sz; | ||
|  |     KEYPAIR_TYPE type = KEYPAIR_INVALID; | ||
|  | 
 | ||
|  |     if (IOTELIC_OK == keypair_create(KEY_SLOT_1, KEYPAIR_EC_SECP256R1)) { | ||
|  |         return IOTELIC_OK == keypair_get_pubkey(KEY_SLOT_1, public_key, sizeof(public_key), &public_key_sz, &type) | ||
|  |                && public_key_sz | ||
|  |                && KEYPAIR_EC_SECP256R1 == type; | ||
|  |     } | ||
|  |     return false; | ||
|  | } | ||
|  | 
 | ||
|  | bool | ||
|  | test_keypair(void) | ||
|  | { | ||
|  |     if (!_test_create_key(KEY_SLOT_1, KEYPAIR_EC_ED25519)) return false; | ||
|  |     if (!_test_create_key(KEY_SLOT_2, KEYPAIR_EC_SECP192R1)) return false; | ||
|  |     if (!_test_create_key(KEY_SLOT_3, KEYPAIR_EC_SECP256R1)) return false; | ||
|  |     if (!_test_create_key(KEY_SLOT_0, KEYPAIR_EC_SECP384R1)) return false; | ||
|  |     if (!_test_create_key(KEY_SLOT_1, KEYPAIR_EC_SECP521R1)) return false; | ||
|  |     if (!_test_create_key(KEY_SLOT_2, KEYPAIR_EC_SECP192K1)) return false; | ||
|  |     if (!_test_create_key(KEY_SLOT_3, KEYPAIR_EC_SECP224K1)) return false; | ||
|  |     if (!_test_create_key(KEY_SLOT_0, KEYPAIR_EC_SECP256K1)) return false; | ||
|  |     if (!_test_create_key(KEY_SLOT_1, KEYPAIR_EC_SECP256K1)) return false; | ||
|  |     if (!_test_create_key(KEY_SLOT_2, KEYPAIR_EC_CURVE25519)) return false; | ||
|  |     if (!_test_key_get_nist256r1_pass()) return false; | ||
|  |     if (!_test_create_fail()) return false; | ||
|  | #if (TARGET_VERSION == TARGET_KUNLUN3)
 | ||
|  |     if (!_test_create_key(KEY_SLOT_1, KEYPAIR_RSA_2048)) return false; | ||
|  |     if (!_test_create_key(KEY_SLOT_2, KEYPAIR_RSA_3072)) return false; | ||
|  |     if (!_test_create_key(KEY_SLOT_1, KEYPAIR_RSA_4096)) return false; | ||
|  | #endif
 | ||
|  | 
 | ||
|  |     return true; | ||
|  | } |