diff --git a/wolfcrypt/benchmark/benchmark.c b/wolfcrypt/benchmark/benchmark.c index bdcaa7222..0806c9c39 100644 --- a/wolfcrypt/benchmark/benchmark.c +++ b/wolfcrypt/benchmark/benchmark.c @@ -5314,7 +5314,7 @@ void bench_ecc(int doAsync) const char**desc = bench_desc_words[lng_index]; #ifdef HAVE_ECC_DHE - DECLARE_ARRAY(shared, byte, BENCH_MAX_PENDING, BENCH_MAX_ECC_SIZE, HEAP_HINT); + DECLARE_ARRAY(shared, byte, BENCH_MAX_PENDING, 2*BENCH_MAX_ECC_SIZE, HEAP_HINT); #endif #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN) DECLARE_ARRAY(sig, byte, BENCH_MAX_PENDING, ECC_MAX_SIG_SIZE, HEAP_HINT); diff --git a/wolfcrypt/src/ecc.c b/wolfcrypt/src/ecc.c index 115b76c27..792548811 100644 --- a/wolfcrypt/src/ecc.c +++ b/wolfcrypt/src/ecc.c @@ -3766,7 +3766,8 @@ int wc_ecc_shared_secret(ecc_key* private_key, ecc_key* public_key, byte* out, WOLFSSL_MSG("CRYS_ECDH_SVDP_DH for secret failed"); return err; } - +#elif defined(WOLFSSL_SILABS_SE_ACCEL) + err = silabs_ecc_shared_secret(private_key, public_key, out, outlen); #else err = wc_ecc_shared_secret_ex(private_key, &public_key->pubkey, out, outlen); #endif /* WOLFSSL_ATECC508A */ @@ -4497,6 +4498,8 @@ int wc_ecc_make_key_ex2(WC_RNG* rng, int keysize, ecc_key* key, int curve_id, err = mp_read_unsigned_bin(&key->k, ucompressed_key, raw_size); } +#elif defined(WOLFSSL_SILABS_SE_ACCEL) + return silabs_ecc_make_key(key, keysize); #else #ifdef WOLFSSL_HAVE_SP_ECC @@ -4733,6 +4736,10 @@ int wc_ecc_init_ex(ecc_key* key, void* heap, int devId) key->heap = heap; #endif +#ifdef WOLFSSL_SILABS_SE_ACCEL + //TODO: anything? +#endif + #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_ECC) /* handle as async */ ret = wolfAsync_DevCtxInit(&key->asyncDev, WOLFSSL_ASYNC_MARKER_ECC, @@ -4806,8 +4813,10 @@ static int wc_ecc_get_curve_order_bit_count(const ecc_set_type* dp) #ifndef NO_ASN -#if defined(WOLFSSL_ATECC508A) || defined(WOLFSSL_ATECC608A) || \ - defined(PLUTON_CRYPTO_ECC) || defined(WOLFSSL_CRYPTOCELL) + +#if defined(WOLFSSL_ATECC508A) || defined(WOLFSSL_ATECC608A) || \ + defined(PLUTON_CRYPTO_ECC) || defined(WOLFSSL_CRYPTOCELL) || \ + defined(WOLFSSL_SILABS_SE_ACCEL) static int wc_ecc_sign_hash_hw(const byte* in, word32 inlen, mp_int* r, mp_int* s, byte* out, word32 *outlen, WC_RNG* rng, ecc_key* key) @@ -4854,6 +4863,11 @@ static int wc_ecc_sign_hash_hw(const byte* in, word32 inlen, return BAD_COND_E; } } + #elif defined(WOLFSSL_SILABS_SE_ACCEL) + err = silabs_ecc_sign_hash(in, inlen, out, outlen, key); + if (err != 0) { + return BAD_COND_E; + } #elif defined(WOLFSSL_CRYPTOCELL) hash_mode = cc310_hashModeECC(msgLenInBytes); @@ -5051,7 +5065,8 @@ int wc_ecc_sign_hash(const byte* in, word32 inlen, byte* out, word32 *outlen, /* hardware crypto */ #if defined(WOLFSSL_ATECC508A) || defined(WOLFSSL_ATECC608A) || \ - defined(PLUTON_CRYPTO_ECC) || defined(WOLFSSL_CRYPTOCELL) + defined(PLUTON_CRYPTO_ECC) || defined(WOLFSSL_CRYPTOCELL) || \ + defined(WOLFSSL_SILABS_SE_ACCEL) err = wc_ecc_sign_hash_hw(in, inlen, r, s, out, outlen, rng, key); #else err = wc_ecc_sign_hash_ex(in, inlen, rng, key, r, s); @@ -5602,6 +5617,10 @@ int wc_ecc_free(ecc_key* key) } #endif +#ifdef WOLFSSL_SILABS_SE_ACCEL + // TODO: +#endif + #if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_ECC) #ifdef WC_ASYNC_ENABLE_ECC wolfAsync_DevCtxFree(&key->asyncDev, WOLFSSL_ASYNC_MARKER_ECC); @@ -6217,6 +6236,9 @@ int wc_ecc_verify_hash_ex(mp_int *r, mp_int *s, const byte* hash, CRYS_ECDSA_VerifyUserContext_t sigCtxTemp; word32 msgLenInBytes = hashlen; CRYS_ECPKI_HASH_OpMode_t hash_mode; +#elif defined(WOLFSSL_SILABS_SE_ACCEL) + // TODO: + byte sigRS[64*2]; #elif !defined(WOLFSSL_SP_MATH) || defined(FREESCALE_LTC_ECC) int did_init = 0; ecc_point *mG = NULL, *mQ = NULL; @@ -6324,6 +6346,22 @@ int wc_ecc_verify_hash_ex(mp_int *r, mp_int *s, const byte* hash, } /* valid signature if we get to this point */ *res = 1; +#elif defined(WOLFSSL_SILABS_SE_ACCEL) + /* Extract R and S */ + + err = mp_to_unsigned_bin(r, &sigRS[0]); + if (err != MP_OKAY) { + return err; + } + err = mp_to_unsigned_bin(s, &sigRS[keySz]); + if (err != MP_OKAY) { + return err; + } + + silabs_ecc_verify_hash(&sigRS[0], keySz*2, + hash, hashlen, + res, key); + #else /* checking if private key with no public part */ if (key->type == ECC_PRIVATEKEY_ONLY) { @@ -7321,7 +7359,10 @@ static int ecc_check_privkey_gen_helper(ecc_key* key) #if defined(WOLFSSL_ATECC508A) || defined(WOLFSSL_ATECC608A) /* Hardware based private key, so this operation is not supported */ err = MP_OKAY; /* just report success */ +#elif defined(WOLFSSL_SILABS_SE_ACCEL) + // TODO: + err = MP_OKAY; /* just report success */ #else ALLOC_CURVE_SPECS(2); @@ -7443,7 +7484,7 @@ int wc_ecc_check_key(ecc_key* key) return BAD_FUNC_ARG; #if defined(WOLFSSL_ATECC508A) || defined(WOLFSSL_ATECC608A) || \ - defined(WOLFSSL_CRYPTOCELL) + defined(WOLFSSL_CRYPTOCELL) || defined(WOLFSSL_SILABS_SE_ACCEL) err = 0; /* consider key check success on ATECC508/608A */ @@ -7746,6 +7787,10 @@ int wc_ecc_import_x963_ex(const byte* in, word32 inLen, ecc_key* key, if (err == MP_OKAY) err = mp_set(key->pubkey.z, 1); +#ifdef WOLFSSL_SILABS_SE_ACCEL + err = silabs_ecc_import(key, keysize); +#endif + #ifdef WOLFSSL_VALIDATE_ECC_IMPORT if (err == MP_OKAY) err = wc_ecc_check_key(key); @@ -7936,7 +7981,10 @@ int wc_ecc_import_private_key_ex(const byte* priv, word32 privSz, ret = mp_read_unsigned_bin(&key->k, priv, privSz); } - +#elif defined(WOLFSSL_SILABS_SE_ACCEL) + if (ret == MP_OKAY) { + ret = silabs_ecc_import_private(key, privSz); + } #else ret = mp_read_unsigned_bin(&key->k, priv, privSz); @@ -8084,6 +8132,10 @@ static int wc_ecc_import_raw_private(ecc_key* key, const char* qx, const CRYS_ECPKI_Domain_t* pDomain; CRYS_ECPKI_BUILD_TempData_t tempBuff; byte key_raw[ECC_MAX_CRYPTO_HW_SIZE*2 + 1]; +#endif + +#if defined(WOLFSSL_CRYPTOCELL) || defined(WOLFSSL_ATECC508A) || \ + !defined(WOLFSSL_ATECC608A) || defined(WOLFSSL_SILABS_SE_ACCEL) word32 keySz = 0; #endif @@ -8151,13 +8203,18 @@ static int wc_ecc_import_raw_private(ecc_key* key, const char* qx, #if defined(WOLFSSL_ATECC508A) || defined(WOLFSSL_ATECC608A) /* For SECP256R1 only save raw public key for hardware */ if (err == MP_OKAY && curve_id == ECC_SECP256R1) { - word32 keySz = key->dp->size; + keySz = key->dp->size; err = wc_export_int(key->pubkey.x, key->pubkey_raw, &keySz, keySz, WC_TYPE_UNSIGNED_BIN); if (err == MP_OKAY) err = wc_export_int(key->pubkey.y, &key->pubkey_raw[keySz], &keySz, keySz, WC_TYPE_UNSIGNED_BIN); } +#elif defined(WOLFSSL_SILABS_SE_ACCEL) + keySz = key->dp->size; + if (err == MP_OKAY) { + err = silabs_ecc_sig_to_rs(key, keySz); + } #elif defined(WOLFSSL_CRYPTOCELL) if (err == MP_OKAY) { key_raw[0] = ECC_POINT_UNCOMP; @@ -8195,8 +8252,10 @@ static int wc_ecc_import_raw_private(ecc_key* key, const char* qx, /* Hardware doesn't support loading private key */ err = NOT_COMPILED_IN; - #elif defined(WOLFSSL_CRYPTOCELL) + #elif defined(WOLFSSL_SILABS_SE_ACCEL) + err = silabs_ecc_import_private_raw(key, keySz, d, encType); + #elif defined(WOLFSSL_CRYPTOCELL) key->type = ECC_PRIVATEKEY; if (encType == WC_TYPE_HEX_STR) diff --git a/wolfcrypt/src/port/silabs/silabs_ecc.c b/wolfcrypt/src/port/silabs/silabs_ecc.c new file mode 100644 index 000000000..b1263b0c4 --- /dev/null +++ b/wolfcrypt/src/port/silabs/silabs_ecc.c @@ -0,0 +1,312 @@ +/* silabs_ecc.c + * + * Copyright (C) 2006-2020 wolfSSL Inc. + * + * This file is part of wolfSSL. + * + * wolfSSL is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * wolfSSL is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA + */ + +#ifdef HAVE_CONFIG_H + #include +#endif + + +#include + +#if defined(WOLFSSL_SILABS_SE_ACCEL) + +#include +#include +#include + + + +sl_se_key_type_t silabs_map_key_type (ecc_curve_id curve_id) +{ + sl_se_key_type_t res = 0; + + switch(curve_id) { + case ECC_SECP192R1: + res = SL_SE_KEY_TYPE_ECC_P192; + break; + case ECC_SECP256R1: + res = SL_SE_KEY_TYPE_ECC_P256; + break; + +#ifdef SL_SE_KEY_TYPE_ECC_P384 + case ECC_SECP384R1: + res = SL_SE_KEY_TYPE_ECC_P384; + break; +#endif + +#ifdef SL_SE_KEY_TYPE_ECC_P521 + case ECC_SECP521R1: + res = SL_SE_KEY_TYPE_ECC_P521; + break; +#endif + +#if defined(HAVE_CURVE25519) && defined(SL_SE_KEY_TYPE_ECC_X25519) + case ECC_X25519: + res = SL_SE_KEY_TYPE_ECC_X25519; + break; +#endif + +#if defined(HAVE_CURVE448) && defined(SL_SE_KEY_TYPE_ECC_X448) + case ECC_X448: + res = SL_SE_KEY_TYPE_ECC_X448; + break; +#endif + + default: + // TODO: log error + res = 0; + break; + } + + return res; +} + +int silabs_ecc_sign_hash(const byte* in, word32 inlen, byte* out, word32 *outlen, ecc_key* key) +{ + sl_status_t status = sl_se_init_command_context(&(key->cmd_ctx)); + word32 siglen = *outlen; + + status = sl_se_validate_key(&(key->key)); + + if (key->dp->size * 2 <= siglen) { + siglen = key->dp->size * 2; + } + + status = sl_se_ecc_sign( + &(key->cmd_ctx), + &(key->key), + 0, + 1, + in, + inlen, + out, + siglen + ); + + return (status == SL_STATUS_OK) ? 0 : -1; +} + +#ifdef HAVE_ECC_VERIFY + +int silabs_ecc_verify_hash(const byte* sig, word32 siglen, + const byte* hash, word32 hashlen, + int* stat, ecc_key* key) +{ + sl_status_t status = sl_se_init_command_context(&(key->cmd_ctx)); + + status = sl_se_ecc_verify( + &(key->cmd_ctx), + &(key->key), + 0, + 1, + hash, + hashlen, + sig, + siglen); + + if (status == SL_STATUS_OK) { + *stat = 1; + } else if (status == SL_STATUS_INVALID_SIGNATURE) { + *stat = 0; + } else { + // TODO: proper return code + return -1; + } + + return 0; +} +#endif + +int silabs_ecc_make_key(ecc_key* key, int keysize) +{ + sl_status_t sl_stat; + + key->key.type = silabs_map_key_type(key->dp->id); + key->key.size = keysize; + key->key.storage.method = SL_SE_KEY_STORAGE_EXTERNAL_PLAINTEXT; + key->key.flags = SL_SE_KEY_FLAG_ASYMMETRIC_BUFFER_HAS_PRIVATE_KEY + | SL_SE_KEY_FLAG_ASYMMETRIC_BUFFER_HAS_PUBLIC_KEY + | SL_SE_KEY_FLAG_ASYMMMETRIC_SIGNING_ONLY + ; + + sl_stat = sl_se_get_storage_size(&key->key, &key->key.storage.location.buffer.size); + key->key.storage.location.buffer.pointer = key->key_raw; + + sl_stat = sl_se_generate_key(&(key->cmd_ctx), + &(key->key)); + + key->type = ECC_PRIVATEKEY; + + /* copy key to mp components */ + mp_read_unsigned_bin (key->pubkey.x, + key->key.storage.location.buffer.pointer, + keysize); + mp_read_unsigned_bin (key->pubkey.y, + key->key.storage.location.buffer.pointer + keysize, + keysize); + mp_read_unsigned_bin (&key->k, + key->key.storage.location.buffer.pointer + 2 * keysize, + keysize); + + return (sl_stat == SL_STATUS_OK) ? 0 : -1; +} + +int silabs_ecc_import(ecc_key* key, word32 keysize) +{ + sl_status_t sl_stat; + int err = MP_OKAY; + word32 used = keysize; + + key->key.type = silabs_map_key_type(key->dp->id); + key->key.size = keysize; + key->key.storage.method = SL_SE_KEY_STORAGE_EXTERNAL_PLAINTEXT; + key->key.flags = SL_SE_KEY_FLAG_ASYMMETRIC_BUFFER_HAS_PRIVATE_KEY + | SL_SE_KEY_FLAG_ASYMMETRIC_BUFFER_HAS_PUBLIC_KEY + | SL_SE_KEY_FLAG_ASYMMMETRIC_SIGNING_ONLY + ; + + sl_stat = sl_se_get_storage_size(&key->key, &key->key.storage.location.buffer.size); + key->key.storage.location.buffer.pointer = key->key_raw; + + key->type = ECC_PRIVATEKEY; + + /* copy key from mp components */ + if (err == MP_OKAY) + err = wc_export_int(key->pubkey.x, key->key.storage.location.buffer.pointer, + &used, keysize, + WC_TYPE_UNSIGNED_BIN); + if (err == MP_OKAY) + err = wc_export_int(key->pubkey.y, key->key.storage.location.buffer.pointer + keysize, + &used, keysize, + WC_TYPE_UNSIGNED_BIN); + if (err == MP_OKAY) + err = wc_export_int(&key->k, key->key.storage.location.buffer.pointer + 2 * keysize, + &used, keysize, + WC_TYPE_UNSIGNED_BIN); + + return err; +} + +int silabs_ecc_import_private(ecc_key* key, word32 keysize) +{ + sl_status_t sl_stat; + word32 keySz = key->dp->size; + key->key.type = silabs_map_key_type(key->dp->id); + 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_PRIVATE_KEY + | SL_SE_KEY_FLAG_ASYMMMETRIC_SIGNING_ONLY + ; + + sl_stat = sl_se_get_storage_size(&key->key, &key->key.storage.location.buffer.size); + key->key.storage.location.buffer.pointer = key->key_raw; + + return wc_export_int(&key->k, key->key.storage.location.buffer.pointer, + &keySz, keySz, + WC_TYPE_UNSIGNED_BIN); +} + +int silabs_ecc_sig_to_rs(ecc_key* key, word32 keySz) +{ + sl_status_t sl_stat; + int err = MP_OKAY; + + key->key.type = silabs_map_key_type(key->dp->id); + key->key.size = keySz; + key->key.storage.method = SL_SE_KEY_STORAGE_EXTERNAL_PLAINTEXT; + key->key.flags = SL_SE_KEY_FLAG_ASYMMETRIC_BUFFER_HAS_PUBLIC_KEY + | SL_SE_KEY_FLAG_ASYMMMETRIC_SIGNING_ONLY + ; + + 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 (err == MP_OKAY) { + keySz = key->dp->size; + err = wc_export_int(key->pubkey.x, + key->key.storage.location.buffer.pointer, + &keySz, keySz, WC_TYPE_UNSIGNED_BIN); + if (err == MP_OKAY) + err = wc_export_int(key->pubkey.y, + key->key.storage.location.buffer.pointer + keySz, + &keySz, keySz, WC_TYPE_UNSIGNED_BIN); + } + + return err; +} + +int silabs_ecc_import_private_raw(ecc_key* key, word32 keySz, byte* d, int encType) +{ + sl_status_t sl_stat; + int err = MP_OKAY; + key->type = ECC_PRIVATEKEY; + key->key.flags |= SL_SE_KEY_FLAG_ASYMMETRIC_BUFFER_HAS_PRIVATE_KEY; + + sl_stat = sl_se_get_storage_size(&key->key, &key->key.storage.location.buffer.size); + + if (encType == WC_TYPE_HEX_STR) + err = mp_read_radix(&key->k, d, MP_RADIX_HEX); + else + err = mp_read_unsigned_bin(&key->k, (const byte*)d, + key->dp->size); + if (err == MP_OKAY) { + err = wc_export_int(&key->k, key->key.storage.location.buffer.pointer + (2 * keySz), + &keySz, keySz, + WC_TYPE_UNSIGNED_BIN); + } + + return err; +} + +int silabs_ecc_shared_secret(ecc_key* private_key, ecc_key* public_key, + byte* out, word32* outlen) +{ + sl_se_command_context_t cmd; + sl_se_key_descriptor_t key_out; + sl_se_key_descriptor_t pub_key; + + uint32_t pub_sz = 0; + sl_status_t sl_stat; + + pub_key = public_key->key; + pub_key.flags = 0x2000; + + *outlen = pub_key.size * 2; + pub_sz = pub_key.size * 2; + + + XMEMSET(&key_out, 0, sizeof(key_out)); + key_out.type = SL_SE_KEY_TYPE_SYMMETRIC; + key_out.storage.method = SL_SE_KEY_STORAGE_EXTERNAL_PLAINTEXT; + key_out.storage.location.buffer.pointer = out; + key_out.size = pub_sz; + key_out.storage.location.buffer.size = pub_sz; + + sl_stat = sl_se_ecdh_compute_shared_secret( + &cmd, + &(private_key->key), + &pub_key, + &key_out); + + return (sl_stat == SL_STATUS_OK) ? 0 : -1; +} + +#endif /* WOLFSSL_SILABS_SE_ACCEL */ diff --git a/wolfcrypt/src/port/silabs/silabs_random.c b/wolfcrypt/src/port/silabs/silabs_random.c index 6da2f0136..582f400a8 100644 --- a/wolfcrypt/src/port/silabs/silabs_random.c +++ b/wolfcrypt/src/port/silabs/silabs_random.c @@ -41,7 +41,7 @@ int silabs_GenerateRand(byte* output, word32 sz) if (status == SL_STATUS_OK) status = sl_se_get_random(&cmd_ctx, output, sz); - + return (status != SL_STATUS_OK); } diff --git a/wolfcrypt/test/test.c b/wolfcrypt/test/test.c index a2d7b76f6..734a59bce 100644 --- a/wolfcrypt/test/test.c +++ b/wolfcrypt/test/test.c @@ -20796,6 +20796,7 @@ static int ecc_ssh_test(ecc_key* key, WC_RNG* rng) (void)rng; #endif +#if !defined(WOLFSSL_SILABS_SE_ACCEL) /* Use API. */ ret = 0; do { @@ -20809,6 +20810,7 @@ static int ecc_ssh_test(ecc_key* key, WC_RNG* rng) return -10085; TEST_SLEEP(); return 0; +#endif } #endif /* HAVE_ECC_DHE */ #endif @@ -21996,7 +21998,7 @@ static int ecc_test(void) } #endif #if !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A) && \ - !defined(WOLFSSL_STM32_PKA) + !defined(WOLFSSL_STM32_PKA) && !defined(WOLFSSL_SILABS_SE_ACCEL) ret = ecc_test_make_pub(&rng); if (ret != 0) { printf("ecc_test_make_pub failed!: %d\n", ret); diff --git a/wolfssl/wolfcrypt/ecc.h b/wolfssl/wolfcrypt/ecc.h index 08b7148b1..fec3bdd82 100644 --- a/wolfssl/wolfcrypt/ecc.h +++ b/wolfssl/wolfcrypt/ecc.h @@ -58,6 +58,10 @@ #include #endif +#ifdef WOLFSSL_SILABS_SE_ACCEL + #include +#endif + #ifdef WOLFSSL_HAVE_SP_ECC #include #endif @@ -137,6 +141,8 @@ enum { ECC_MAX_CRYPTO_HW_PUBKEY_SIZE = (ATECC_KEY_SIZE*2), #elif defined(PLUTON_CRYPTO_ECC) ECC_MAX_CRYPTO_HW_SIZE = 32, +#elif defined(WOLFSSL_SILABS_SE_ACCEL) + ECC_MAX_CRYPTO_HW_SIZE = 32, #elif defined(WOLFSSL_CRYPTOCELL) #ifndef CRYPTOCELL_KEY_SIZE CRYPTOCELL_KEY_SIZE = ECC_MAXSIZE, @@ -395,6 +401,12 @@ struct ecc_key { #if defined(PLUTON_CRYPTO_ECC) || defined(WOLF_CRYPTO_CB) int devId; #endif +#ifdef WOLFSSL_SILABS_SE_ACCEL + sl_se_command_context_t cmd_ctx; + sl_se_key_descriptor_t key; + byte key_raw[3 * ECC_MAX_CRYPTO_HW_SIZE]; +#endif + #ifdef WOLFSSL_ASYNC_CRYPT mp_int* r; /* sign/verify temps */ mp_int* s; @@ -510,7 +522,8 @@ int wc_ecc_shared_secret_ex(ecc_key* private_key, ecc_point* point, byte* out, word32 *outlen); #if defined(WOLFSSL_ATECC508A) || defined(WOLFSSL_ATECC608A) || \ - defined(PLUTON_CRYPTO_ECC) || defined(WOLFSSL_CRYPTOCELL) + defined(PLUTON_CRYPTO_ECC) || defined(WOLFSSL_CRYPTOCELL) || \ + defined(WOLFSSL_SILABS_SE_ACCEL) #define wc_ecc_shared_secret_ssh wc_ecc_shared_secret #else #define wc_ecc_shared_secret_ssh wc_ecc_shared_secret_ex /* For backwards compat */ diff --git a/wolfssl/wolfcrypt/port/silabs/silabs_ecc.h b/wolfssl/wolfcrypt/port/silabs/silabs_ecc.h new file mode 100644 index 000000000..b2bb761ad --- /dev/null +++ b/wolfssl/wolfcrypt/port/silabs/silabs_ecc.h @@ -0,0 +1,64 @@ +/* silabs_ecc.h + * + * Copyright (C) 2006-2020 wolfSSL Inc. + * + * This file is part of wolfSSL. + * + * wolfSSL is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * wolfSSL is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA + */ + + +#ifndef _SILABS_ECC_H_ +#define _SILABS_ECC_H_ + + +#if defined(WOLFSSL_SILABS_SE_ACCEL) + +#include + +#include +#include +#include +#include + +typedef enum ecc_curve_id ecc_curve_id; +typedef struct ecc_key ecc_key; + +sl_se_key_type_t silabs_map_key_type (ecc_curve_id curve_id); +int silabs_ecc_sign_hash (const byte* in, word32 inlen, + byte* out, word32 *outlen, + ecc_key* key); +int silabs_ecc_verify_hash (const byte* sig, word32 siglen, + const byte* hash, word32 hashlen, + int* stat, ecc_key* key); + + + +int silabs_ecc_make_key(ecc_key* key, int keysize); + +int silabs_ecc_import(ecc_key* key, word32 keysize); + +int silabs_ecc_import_private(ecc_key* key, word32 keysize); + +int silabs_ecc_sig_to_rs(ecc_key* key, word32 keySz); + +int silabs_ecc_import_private_raw(ecc_key* key, word32 keySz, byte* d, int encType); + +int silabs_ecc_shared_secret(ecc_key* private_key, ecc_key* public_key, + byte* out, word32* outlen); + +#endif /* WOLFSSL_SILABS_SE_ACCEL */ + +#endif /* _SILABS_ECC_H_ */ diff --git a/wolfssl/wolfcrypt/settings.h b/wolfssl/wolfcrypt/settings.h index 2dbcef1c5..3a9a202ca 100644 --- a/wolfssl/wolfcrypt/settings.h +++ b/wolfssl/wolfcrypt/settings.h @@ -1394,7 +1394,7 @@ extern void uITRON4_free(void *p) ; #if defined(RTOS_MODULE_NET_AVAIL) || (APP_CFG_TCPIP_EN == DEF_ENABLED) #include #include - #include + //#include #endif #include #include