diff --git a/IDE/SimplicityStudio/test_wolf.c b/IDE/SimplicityStudio/test_wolf.c index d06e9eadd..3c232e092 100644 --- a/IDE/SimplicityStudio/test_wolf.c +++ b/IDE/SimplicityStudio/test_wolf.c @@ -23,7 +23,11 @@ * SiLabs Simplicity Studio's CLI example */ #include +#include +#include +#include #include +#include #include #include #include @@ -82,4 +86,91 @@ void wolf_bench(sl_cli_command_arg_t *arguments) (void)ret; } +/* ecc key gen, sign and verify examples */ +#define TEST_ECC_KEYSZ 32 +#define TEST_DATA_SIZE 128 +#define TEST_KEYGEN_TRIES 100 +#define TEST_ECDSA_TRIES 100 +void wolf_ecc_test(sl_cli_command_arg_t *arguments) +{ + int ret = 0, i, j; + byte data[TEST_DATA_SIZE]; + word32 dataLen = (word32)sizeof(data); + byte sig[ECC_MAX_SIG_SIZE]; + word32 sigLen; + WC_RNG rng; + ecc_key eccKey; + + memset(&rng, 0, sizeof(rng)); + memset(&eccKey, 0, sizeof(eccKey)); + + wolfSSL_Debugging_ON(); + + wolfCrypt_Init(); + + /* test data */ + for (i=0; i<(int)dataLen; i++) { + data[i] = (byte)i; + } + + ret = wc_InitRng(&rng); + if (ret != 0) { + goto exit; + } + + for (i=0; ikey), + &private_key->key, &pub_key, &key_out); @@ -298,4 +298,66 @@ int silabs_ecc_shared_secret(ecc_key* private_key, ecc_key* public_key, return (sl_stat == SL_STATUS_OK) ? 0 : WC_HW_E; } +int silabs_ecc_export_public(ecc_key* key, sl_se_key_descriptor_t* seKey) +{ + int ret; + sl_status_t sl_stat; + sl_se_command_context_t cmd; + + if (key == NULL || seKey == NULL) + return BAD_FUNC_ARG; + + if (seKey->type == SL_SE_KEY_TYPE_ECC_P192) + ret = wc_ecc_set_curve(key, 24, ECC_SECP192R1); + else if (seKey->type == SL_SE_KEY_TYPE_ECC_P256) + ret = wc_ecc_set_curve(key, 32, ECC_SECP256R1); +#ifdef SL_SE_KEY_TYPE_ECC_P384 + else if (seKey->type == SL_SE_KEY_TYPE_ECC_P384) + ret = wc_ecc_set_curve(key, 48, ECC_SECP384R1); +#endif +#ifdef SL_SE_KEY_TYPE_ECC_P521 + else if (seKey->type == SL_SE_KEY_TYPE_ECC_P521) + ret = wc_ecc_set_curve(key, 66, ECC_SECP521R1); +#endif + else + ret = ECC_CURVE_OID_E; + if (ret != 0) + return ret; + + key->type = ECC_PUBLICKEY; + key->key.size = key->dp->size; + key->key.storage.method = SL_SE_KEY_STORAGE_EXTERNAL_PLAINTEXT; + key->key.flags = (SL_SE_KEY_FLAG_ASYMMETRIC_BUFFER_HAS_PUBLIC_KEY); + + sl_stat = sl_se_get_storage_size(&key->key, + &key->key.storage.location.buffer.size); + key->key.storage.location.buffer.pointer = key->key_raw; + if (sl_stat == SL_STATUS_OK) { + sl_stat = sl_se_export_public_key(&cmd, seKey, &key->key); + } + if (sl_stat != SL_STATUS_OK) { + ret = WC_HW_E; + } + if (ret == 0) { + /* export public x and y */ + ret = mp_read_unsigned_bin(key->pubkey.x, + key->key.storage.location.buffer.pointer, + key->key.size); + } + if (ret == 0) { + ret = mp_read_unsigned_bin(key->pubkey.y, + key->key.storage.location.buffer.pointer + key->key.size, + key->key.size); + } + + return ret; +} + +#if (_SILICON_LABS_SECURITY_FEATURE == _SILICON_LABS_SECURITY_FEATURE_VAULT) +int silabs_ecc_load_vault(ecc_key* key) +{ + return silabs_ecc_export_public(key, &private_device_key); +} +#endif + #endif /* WOLFSSL_SILABS_SE_ACCEL */ diff --git a/wolfssl/wolfcrypt/port/silabs/silabs_ecc.h b/wolfssl/wolfcrypt/port/silabs/silabs_ecc.h index 88cc5c02b..43cd0f097 100644 --- a/wolfssl/wolfcrypt/port/silabs/silabs_ecc.h +++ b/wolfssl/wolfcrypt/port/silabs/silabs_ecc.h @@ -47,10 +47,16 @@ int silabs_ecc_verify_hash (const byte* sig, word32 siglen, int silabs_ecc_make_key(ecc_key* key, int keysize); int silabs_ecc_import(ecc_key* key, word32 keysize, int pub, int priv); +int silabs_ecc_export_public(ecc_key* key, sl_se_key_descriptor_t* seKey); int silabs_ecc_shared_secret(ecc_key* private_key, ecc_key* public_key, byte* out, word32* outlen); +#if (_SILICON_LABS_SECURITY_FEATURE == _SILICON_LABS_SECURITY_FEATURE_VAULT) +int silabs_ecc_load_vault(ecc_key* key); +#endif + + #endif /* WOLFSSL_SILABS_SE_ACCEL */ #endif /* _SILABS_ECC_H_ */