forked from wolfSSL/wolfssl
Fix build issues with rebase for ECC and RSA. Changed user_settings.h example when LTC is enabled to disable Shamir and ECC-521. Cleanup to add USE_NXP_MMCAU and USE_NXP_LTC for the example user_settings.h, so the project file can automatically configure.
This commit is contained in:
@ -27,20 +27,23 @@ Also the "Target Processor" in each of the projects ("Project Properties" -> "Ta
|
||||
|
||||
## Hardware Crypto Acceleration
|
||||
|
||||
To enable Freescale MMCAU:
|
||||
To enable NXP/Freescale MMCAU:
|
||||
|
||||
1. [Download the MMCAU library](http://www.freescale.com/products/arm-processors/kinetis-cortex-m/k-series/k7x-glcd-mcus/crypto-acceleration-unit-cau-and-mmcau-software-library:CAUAP).
|
||||
2. Copy the `lib_mmcau.a` and `cau_api.h` files into the project.
|
||||
3. Enable the `FREESCALE_MMCAU` define in `user_settings.h` and make sure its value is `1`.
|
||||
3. Define `USE_NXP_MMCAU` to enable in `user_settings.h`.
|
||||
4. Add the `lib_mmcau.a` file to `Source Files` in the application project.
|
||||
5. Open the wolfssl_ltc.hzp CrossWorks project
|
||||
6. Build and run
|
||||
|
||||
To enable the NXP LTC:
|
||||
To enable the NXP/Freescale MMCAU and/or LTC:
|
||||
|
||||
1. [Download the NXP KSDK 2.0](https://nxp.flexnetoperations.com/control/frse/download?agree=Accept&element=7353807)
|
||||
2. Copy the following folders into IDE/ROWLEY-CROSSWORKS-ARM: drivers, mmcau_2.0.0 and CMSIS.
|
||||
3. Copy the following files into IDE/ROWLEY-CROSSWORKS-ARM: clock_config.c, clock_config.h, fsl_debug_console.c, fsl_debug_console.h, fsl_device_registers.h, system_MK82F25615.c, system_MK82F25615.h, MK82F25615.h and MK82F25615_features.h.
|
||||
4. Open the wolfssl_ltc.hzp CrossWorks project
|
||||
5. Build and run
|
||||
4. Define `USE_NXP_LTX` to enable in `user_settings.h`.
|
||||
5. Open the wolfssl_ltc.hzp CrossWorks project
|
||||
6. Build and run
|
||||
|
||||
# Project Files
|
||||
|
||||
|
@ -54,7 +54,7 @@ void main(void)
|
||||
|
||||
/*
|
||||
SAMPLE OUTPUT: Freescale K64 running at 96MHz with no MMCAU:
|
||||
Benchmark Test 1:
|
||||
Benchmark Test 0:
|
||||
AES 25 kB took 0.073 seconds, 0.334 MB/s
|
||||
ARC4 25 kB took 0.033 seconds, 0.740 MB/s
|
||||
RABBIT 25 kB took 0.027 seconds, 0.904 MB/s
|
||||
@ -66,10 +66,10 @@ RSA 1024 encryption took 91.000 milliseconds, avg over 1 iterations
|
||||
RSA 1024 decryption took 573.000 milliseconds, avg over 1 iterations
|
||||
DH 1024 key generation 253.000 milliseconds, avg over 1 iterations
|
||||
DH 1024 key agreement 311.000 milliseconds, avg over 1 iterations
|
||||
Benchmark Test 1: Return code 0
|
||||
Benchmark Test 0: Return code 0
|
||||
|
||||
SAMPLE OUTPUT: Freescale K64 running at 96MHz with MMCAU enabled:
|
||||
Benchmark Test 1:
|
||||
Benchmark Test 0:
|
||||
AES 25 kB took 0.019 seconds, 1.285 MB/s
|
||||
ARC4 25 kB took 0.033 seconds, 0.740 MB/s
|
||||
RABBIT 25 kB took 0.028 seconds, 0.872 MB/s
|
||||
@ -81,5 +81,72 @@ RSA 1024 encryption took 89.000 milliseconds, avg over 1 iterations
|
||||
RSA 1024 decryption took 573.000 milliseconds, avg over 1 iterations
|
||||
DH 1024 key generation 250.000 milliseconds, avg over 1 iterations
|
||||
DH 1024 key agreement 308.000 milliseconds, avg over 1 iterations
|
||||
Benchmark Test 1: Return code 0
|
||||
Benchmark Test 0: Return code 0
|
||||
|
||||
|
||||
SAMPLE OUTPUT: NXP K82 running at 150Mhz w/MMCAU and LTC
|
||||
Benchmark Test 0:
|
||||
RNG 25 kB took 0.026 seconds, 0.939 MB/s
|
||||
AES enc 25 kB took 0.002 seconds, 12.207 MB/s
|
||||
AES dec 25 kB took 0.002 seconds, 12.207 MB/s
|
||||
AES-GCM 25 kB took 0.002 seconds, 12.207 MB/s
|
||||
AES-CTR 25 kB took 0.003 seconds, 8.138 MB/s
|
||||
AES-CCM 25 kB took 0.004 seconds, 6.104 MB/s
|
||||
CHACHA 25 kB took 0.008 seconds, 3.052 MB/s
|
||||
CHA-POLY 25 kB took 0.013 seconds, 1.878 MB/s
|
||||
|
||||
POLY1305 25 kB took 0.003 seconds, 8.138 MB/s
|
||||
SHA 25 kB took 0.006 seconds, 4.069 MB/s
|
||||
SHA-256 25 kB took 0.009 seconds, 2.713 MB/s
|
||||
SHA-384 25 kB took 0.032 seconds, 0.763 MB/s
|
||||
SHA-512 25 kB took 0.035 seconds, 0.698 MB/s
|
||||
|
||||
RSA 2048 public 12.000 milliseconds, avg over 1 iterations
|
||||
RSA 2048 private 135.000 milliseconds, avg over 1 iterations
|
||||
|
||||
ECC 256 key generation 17.400 milliseconds, avg over 5 iterations
|
||||
EC-DHE key agreement 15.200 milliseconds, avg over 5 iterations
|
||||
EC-DSA sign time 20.200 milliseconds, avg over 5 iterations
|
||||
EC-DSA verify time 33.000 milliseconds, avg over 5 iterations
|
||||
|
||||
CURVE25519 256 key generation 14.400 milliseconds, avg over 5 iterations
|
||||
CURVE25519 key agreement 14.400 milliseconds, avg over 5 iterations
|
||||
|
||||
ED25519 key generation 14.800 milliseconds, avg over 5 iterations
|
||||
ED25519 sign time 16.800 milliseconds, avg over 5 iterations
|
||||
ED25519 verify time 30.400 milliseconds, avg over 5 iterations
|
||||
Benchmark Test 0: Return code 0
|
||||
|
||||
SAMPLE OUTPUT: NXP K82 running at 150Mhz software only
|
||||
Benchmark Test 0:
|
||||
RNG 25 kB took 0.026 seconds, 0.939 MB/s
|
||||
AES enc 25 kB took 0.002 seconds, 12.207 MB/s
|
||||
AES dec 25 kB took 0.002 seconds, 12.207 MB/s
|
||||
AES-GCM 25 kB took 0.002 seconds, 12.207 MB/s
|
||||
AES-CTR 25 kB took 0.002 seconds, 12.207 MB/s
|
||||
AES-CCM 25 kB took 0.004 seconds, 6.104 MB/s
|
||||
CHACHA 25 kB took 0.009 seconds, 2.713 MB/s
|
||||
CHA-POLY 25 kB took 0.013 seconds, 1.878 MB/s
|
||||
|
||||
POLY1305 25 kB took 0.003 seconds, 8.138 MB/s
|
||||
SHA 25 kB took 0.006 seconds, 4.069 MB/s
|
||||
SHA-256 25 kB took 0.008 seconds, 3.052 MB/s
|
||||
SHA-384 25 kB took 0.033 seconds, 0.740 MB/s
|
||||
SHA-512 25 kB took 0.034 seconds, 0.718 MB/s
|
||||
|
||||
RSA 2048 public 11.000 milliseconds, avg over 1 iterations
|
||||
RSA 2048 private 135.000 milliseconds, avg over 1 iterations
|
||||
|
||||
ECC 256 key generation 17.400 milliseconds, avg over 5 iterations
|
||||
EC-DHE key agreement 15.000 milliseconds, avg over 5 iterations
|
||||
EC-DSA sign time 20.400 milliseconds, avg over 5 iterations
|
||||
EC-DSA verify time 33.200 milliseconds, avg over 5 iterations
|
||||
|
||||
CURVE25519 256 key generation 14.600 milliseconds, avg over 5 iterations
|
||||
CURVE25519 key agreement 14.400 milliseconds, avg over 5 iterations
|
||||
|
||||
ED25519 key generation 15.000 milliseconds, avg over 5 iterations
|
||||
ED25519 sign time 16.800 milliseconds, avg over 5 iterations
|
||||
ED25519 verify time 30.400 milliseconds, avg over 5 iterations
|
||||
Benchmark Test 0: Return code 0
|
||||
*/
|
||||
|
@ -54,24 +54,26 @@ void main(void)
|
||||
|
||||
|
||||
/* SAMPLE OUTPUT:
|
||||
Crypt Test 1:
|
||||
MD5 test passed!
|
||||
MD4 test passed!
|
||||
Crypt Test 0:
|
||||
SHA test passed!
|
||||
SHA-256 test passed!
|
||||
HMAC-MD5 test passed!
|
||||
SHA-384 test passed!
|
||||
SHA-512 test passed!
|
||||
HMAC-SHA test passed!
|
||||
HMAC-SHA256 test passed!
|
||||
ARC4 test passed!
|
||||
HC-128 test passed!
|
||||
Rabbit test passed!
|
||||
DES test passed!
|
||||
DES3 test passed!
|
||||
HMAC-SHA384 test passed!
|
||||
HMAC-SHA512 test passed!
|
||||
GMAC test passed!
|
||||
Chacha test passed!
|
||||
POLY1305 test passed!
|
||||
ChaCha20-Poly1305 AEAD test passed!
|
||||
AES test passed!
|
||||
AES-GCM test passed!
|
||||
AES-CCM test passed!
|
||||
RANDOM test passed!
|
||||
RSA test passed!
|
||||
DH test passed!
|
||||
DSA test passed!
|
||||
PWDBASED test passed!
|
||||
Crypt Test 1: Return code 0
|
||||
ECC test passed!
|
||||
CURVE25519 test passed!
|
||||
ED25519 test passed!
|
||||
Crypt Test 0: Return code 0
|
||||
*/
|
||||
|
@ -56,7 +56,9 @@ extern "C" {
|
||||
#define HAVE_ECC224
|
||||
#undef NO_ECC256
|
||||
#define HAVE_ECC384
|
||||
#define HAVE_ECC521
|
||||
#ifndef USE_NXP_LTC /* NXP LTC HW supports up to 512 */
|
||||
#define HAVE_ECC521
|
||||
#endif
|
||||
|
||||
/* Fixed point cache (speeds repeated operations against same private key) */
|
||||
#undef FP_ECC
|
||||
@ -72,7 +74,9 @@ extern "C" {
|
||||
/* Optional ECC calculation method */
|
||||
/* Note: doubles heap usage, but slightly faster */
|
||||
#undef ECC_SHAMIR
|
||||
#define ECC_SHAMIR
|
||||
#ifndef USE_NXP_LTC /* Don't enable Shamir code for HW ECC */
|
||||
#define ECC_SHAMIR
|
||||
#endif
|
||||
|
||||
/* Reduces heap usage, but slower */
|
||||
#undef ECC_TIMING_RESISTANT
|
||||
@ -83,16 +87,22 @@ extern "C" {
|
||||
#undef ALT_ECC_SIZE
|
||||
#define ALT_ECC_SIZE
|
||||
|
||||
/* optionally override the default max ecc bits */
|
||||
#undef FP_MAX_BITS_ECC
|
||||
//#define FP_MAX_BITS_ECC 512
|
||||
|
||||
/* Enable TFM optimizations for ECC */
|
||||
#define TFM_ECC192
|
||||
#define TFM_ECC224
|
||||
#define TFM_ECC256
|
||||
#define TFM_ECC384
|
||||
#define TFM_ECC521
|
||||
#if defined(HAVE_ECC192) || defined(HAVE_ALL_CURVES)
|
||||
#define TFM_ECC192
|
||||
#endif
|
||||
#if defined(HAVE_ECC224) || defined(HAVE_ALL_CURVES)
|
||||
#define TFM_ECC224
|
||||
#endif
|
||||
#if !defined(NO_ECC256) || defined(HAVE_ALL_CURVES)
|
||||
#define TFM_ECC256
|
||||
#endif
|
||||
#if defined(HAVE_ECC384) || defined(HAVE_ALL_CURVES)
|
||||
#define TFM_ECC384
|
||||
#endif
|
||||
#if defined(HAVE_ECC521) || defined(HAVE_ALL_CURVES)
|
||||
#define TFM_ECC521
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@ -195,21 +205,21 @@ extern "C" {
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* HW Crypto Acceleration */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
// See README.md for instructions
|
||||
#if 0
|
||||
#define FREESCALE_MMCAU 1
|
||||
#if 1
|
||||
/* NXP MMCAU / LTC Support (See README.md for instructions) */
|
||||
#if defined(USE_NXP_MMCAU) || defined(USE_NXP_LTC)
|
||||
#define FSL_HW_CRYPTO_MANUAL_SELECTION
|
||||
#ifdef USE_NXP_MMCAU
|
||||
#define FREESCALE_USE_MMCAU
|
||||
#endif
|
||||
#ifdef USE_NXP_LTC
|
||||
#define FREESCALE_USE_LTC
|
||||
#define LTC_MAX_ECC_BITS (512)
|
||||
#define LTC_MAX_INT_BYTES (256)
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* NXP LTC Support (See README.md for instructions) */
|
||||
#if 0
|
||||
#define FSL_HW_CRYPTO_MANUAL_SELECTION
|
||||
#define FREESCALE_USE_MMCAU
|
||||
#define FREESCALE_USE_LTC
|
||||
#define LTC_MAX_ECC_BITS (512)
|
||||
#define LTC_MAX_INT_BYTES (256)
|
||||
#endif
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* Benchmark / Test */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
@ -4,7 +4,7 @@
|
||||
<configuration
|
||||
Name="Common"
|
||||
build_output_file_name="$(OutDir)/$(ProjectName)$(LibExt)$(LIB)"
|
||||
c_preprocessor_definitions="WOLFSSL_ROWLEY_ARM;WOLFSSL_USER_SETTINGS"
|
||||
c_preprocessor_definitions="WOLFSSL_ROWLEY_ARM;WOLFSSL_USER_SETTINGS;USE_NXP_LTC;USE_NXP_MMCAU"
|
||||
c_user_include_directories=".;../;../../;./drivers;./mmcau_2.0.0;./CMSIS/Include"
|
||||
project_directory=""
|
||||
project_type="Library" />
|
||||
@ -322,7 +322,7 @@
|
||||
arm_simulator_memory_simulation_parameter="MK82FN256xxx15;0x40000;0x0;0x0;0x40000;4"
|
||||
arm_target_loader_applicable_loaders="Flash"
|
||||
arm_target_loader_default_loader="Flash"
|
||||
c_preprocessor_definitions="WOLFSSL_ROWLEY_ARM;WOLFSSL_USER_SETTINGS"
|
||||
c_preprocessor_definitions="WOLFSSL_ROWLEY_ARM;WOLFSSL_USER_SETTINGS;USE_NXP_LTC;USE_NXP_MMCAU"
|
||||
c_user_include_directories=".;./drivers;./mmcau_2.0.0;./CMSIS/Include;../;../../;$(TargetsDir);$(TargetsDir)/Kinetis;$(TargetsDir)/Kinetis/CMSIS;$(TargetsDir)/Kinetis/CMSIS/include;$(TargetsDir)/CMSIS_3/CMSIS/include"
|
||||
debug_register_definition_file="$(TargetsDir)/Kinetis/MK82F25615_Peripherals.xml"
|
||||
linker_memory_map_file="$(TargetsDir)/Kinetis/MK82FN256xxx15_MemoryMap.xml"
|
||||
@ -377,7 +377,7 @@
|
||||
arm_simulator_memory_simulation_parameter="MK82FN256xxx15;0x40000;0x0;0x0;0x40000;4"
|
||||
arm_target_loader_applicable_loaders="Flash"
|
||||
arm_target_loader_default_loader="Flash"
|
||||
c_preprocessor_definitions="WOLFSSL_ROWLEY_ARM;WOLFSSL_USER_SETTINGS"
|
||||
c_preprocessor_definitions="WOLFSSL_ROWLEY_ARM;WOLFSSL_USER_SETTINGS;USE_NXP_LTC;USE_NXP_MMCAU"
|
||||
c_user_include_directories=".;./drivers;./mmcau_2.0.0;./CMSIS/Include;../;../../;$(TargetsDir);$(TargetsDir)/Kinetis;$(TargetsDir)/Kinetis/CMSIS;$(TargetsDir)/Kinetis/CMSIS/include;$(TargetsDir)/CMSIS_3/CMSIS/include"
|
||||
debug_register_definition_file="$(TargetsDir)/Kinetis/MK82F25615_Peripherals.xml"
|
||||
linker_memory_map_file="$(TargetsDir)/Kinetis/MK82FN256xxx15_MemoryMap.xml"
|
||||
|
@ -3380,11 +3380,11 @@ int wc_ecc_verify_hash_ex(mp_int *r, mp_int *s, const byte* hash,
|
||||
#ifdef FREESCALE_LTC_ECC
|
||||
/* use PKHA to compute u1*mG + u2*mQ */
|
||||
if (err == MP_OKAY)
|
||||
err = wc_ecc_mulmod_ex(&u1, mG, mG, &m, 0, NULL);
|
||||
err = wc_ecc_mulmod_ex(&u1, mG, mG, &a, &modulus, 0, NULL);
|
||||
if (err == MP_OKAY)
|
||||
err = wc_ecc_mulmod_ex(&u2, mQ, mQ, &m, 0, NULL);
|
||||
err = wc_ecc_mulmod_ex(&u2, mQ, mQ, &a, &modulus, 0, NULL);
|
||||
if (err == MP_OKAY)
|
||||
err = wc_ecc_point_add(mG, mQ, mG, &m);
|
||||
err = wc_ecc_point_add(mG, mQ, mG, &modulus);
|
||||
#else /* FREESCALE_LTC_ECC */
|
||||
#ifndef ECC_SHAMIR
|
||||
{
|
||||
|
@ -435,12 +435,14 @@ int _fp_exptmod(fp_int *G, fp_int *X, fp_int *P, fp_int *Y)
|
||||
}
|
||||
|
||||
#ifndef NO_RSA
|
||||
int wc_RsaFunction(const byte *in, word32 inLen, byte *out, word32 *outLen, int type, RsaKey *key)
|
||||
int wc_RsaFunction(const byte *in, word32 inLen, byte *out, word32 *outLen, int type, RsaKey *key, WC_RNG* rng)
|
||||
{
|
||||
mp_int tmp;
|
||||
int ret = 0;
|
||||
word32 keyLen, len;
|
||||
|
||||
(void)rng;
|
||||
|
||||
if (mp_init(&tmp) != MP_OKAY)
|
||||
return MP_INIT_E;
|
||||
|
||||
@ -788,8 +790,8 @@ static int ltc_get_ecc_specs(const uint8_t **modulus, const uint8_t **r2modn,
|
||||
(1==map, 0 == leave in projective)
|
||||
return MP_OKAY on success
|
||||
*/
|
||||
int wc_ecc_mulmod_ex(mp_int *k, ecc_point *G, ecc_point *R, mp_int *modulus,
|
||||
int map, void* heap)
|
||||
int wc_ecc_mulmod_ex(mp_int *k, ecc_point *G, ecc_point *R, mp_int* a,
|
||||
mp_int *modulus, int map, void* heap)
|
||||
{
|
||||
ltc_pkha_ecc_point_t B;
|
||||
uint8_t size;
|
||||
@ -798,6 +800,8 @@ int wc_ecc_mulmod_ex(mp_int *k, ecc_point *G, ecc_point *R, mp_int *modulus,
|
||||
bool point_of_infinity;
|
||||
status_t status;
|
||||
|
||||
(void)a;
|
||||
|
||||
uint8_t Gxbin[LTC_MAX_ECC_BITS / 8];
|
||||
uint8_t Gybin[LTC_MAX_ECC_BITS / 8];
|
||||
uint8_t kbin[LTC_MAX_INT_BYTES];
|
||||
|
@ -43,7 +43,7 @@ int ksdk_port_init(void);
|
||||
int _fp_exptmod(fp_int *G, fp_int *X, fp_int *P, fp_int *Y);
|
||||
#ifndef NO_RSA
|
||||
#include <wolfssl/wolfcrypt/rsa.h>
|
||||
int wc_RsaFunction(const byte *in, word32 inLen, byte *out, word32 *outLen, int type, RsaKey *key);
|
||||
int wc_RsaFunction(const byte* in, word32 inLen, byte* out, word32* outLen, int type, RsaKey* key, WC_RNG* rng);
|
||||
#endif
|
||||
#endif /* FREESCALE_LTC_TFM */
|
||||
|
||||
|
Reference in New Issue
Block a user