forked from wolfSSL/wolfssl
Merge pull request #927 from dgarske/fix_nxp_ltc
Build fixes for NXP KSDK with MMCAU / LTC after Hexiwear changes
This commit is contained in:
@ -29,6 +29,12 @@ void __assert(const char *__expression, const char *__filename, int __line)
|
|||||||
printf("Assert: %s, File %s (%d)\n", __expression, __filename, __line);
|
printf("Assert: %s, File %s (%d)\n", __expression, __filename, __line);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned long ksdk_time(unsigned long* timer)
|
||||||
|
{
|
||||||
|
(void)timer;
|
||||||
|
return hw_get_time_sec();
|
||||||
|
}
|
||||||
|
|
||||||
unsigned int LowResTimer(void)
|
unsigned int LowResTimer(void)
|
||||||
{
|
{
|
||||||
return hw_get_time_sec();
|
return hw_get_time_sec();
|
||||||
|
@ -7,6 +7,8 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <stddef.h> /* for size_t */
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------- */
|
/* ------------------------------------------------------------------------- */
|
||||||
/* Platform */
|
/* Platform */
|
||||||
/* ------------------------------------------------------------------------- */
|
/* ------------------------------------------------------------------------- */
|
||||||
@ -270,6 +272,8 @@ extern "C" {
|
|||||||
/* Allows custom "custom_time()" function to be used for benchmark */
|
/* Allows custom "custom_time()" function to be used for benchmark */
|
||||||
#define WOLFSSL_USER_CURRTIME
|
#define WOLFSSL_USER_CURRTIME
|
||||||
#define USER_TICKS
|
#define USER_TICKS
|
||||||
|
extern unsigned long ksdk_time(unsigned long* timer);
|
||||||
|
#define XTIME ksdk_time
|
||||||
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------- */
|
/* ------------------------------------------------------------------------- */
|
||||||
|
@ -52,9 +52,10 @@
|
|||||||
#else
|
#else
|
||||||
#include <nio.h>
|
#include <nio.h>
|
||||||
#endif
|
#endif
|
||||||
#elif defined(FREESCALE_KSDK_BM)
|
#elif defined(FREESCALE_KSDK_1_3)
|
||||||
#include "fsl_debug_console.h"
|
#include "fsl_debug_console.h"
|
||||||
#include "fsl_os_abstraction.h"
|
#include "fsl_os_abstraction.h"
|
||||||
|
|
||||||
#undef printf
|
#undef printf
|
||||||
#define printf PRINTF
|
#define printf PRINTF
|
||||||
#else
|
#else
|
||||||
|
@ -2516,6 +2516,7 @@ int wc_AesSetIV(Aes* aes, const byte* iv)
|
|||||||
uint32_t keySize;
|
uint32_t keySize;
|
||||||
status_t status;
|
status_t status;
|
||||||
byte *iv, *enc_key;
|
byte *iv, *enc_key;
|
||||||
|
word32 blocks = (sz / AES_BLOCK_SIZE);
|
||||||
|
|
||||||
iv = (byte*)aes->reg;
|
iv = (byte*)aes->reg;
|
||||||
enc_key = (byte*)aes->key;
|
enc_key = (byte*)aes->key;
|
||||||
@ -2525,7 +2526,7 @@ int wc_AesSetIV(Aes* aes, const byte* iv)
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
status = LTC_AES_EncryptCbc(LTC_BASE, in, out, sz,
|
status = LTC_AES_EncryptCbc(LTC_BASE, in, out, blocks * AES_BLOCK_SIZE,
|
||||||
iv, enc_key, keySize);
|
iv, enc_key, keySize);
|
||||||
return (status == kStatus_Success) ? 0 : -1;
|
return (status == kStatus_Success) ? 0 : -1;
|
||||||
}
|
}
|
||||||
@ -2536,6 +2537,7 @@ int wc_AesSetIV(Aes* aes, const byte* iv)
|
|||||||
uint32_t keySize;
|
uint32_t keySize;
|
||||||
status_t status;
|
status_t status;
|
||||||
byte* iv, *dec_key;
|
byte* iv, *dec_key;
|
||||||
|
word32 blocks = (sz / AES_BLOCK_SIZE);
|
||||||
|
|
||||||
iv = (byte*)aes->reg;
|
iv = (byte*)aes->reg;
|
||||||
dec_key = (byte*)aes->key;
|
dec_key = (byte*)aes->key;
|
||||||
@ -2545,7 +2547,7 @@ int wc_AesSetIV(Aes* aes, const byte* iv)
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
status = LTC_AES_DecryptCbc(LTC_BASE, in, out, sz,
|
status = LTC_AES_DecryptCbc(LTC_BASE, in, out, blocks * AES_BLOCK_SIZE,
|
||||||
iv, dec_key, keySize, kLTC_EncryptKey);
|
iv, dec_key, keySize, kLTC_EncryptKey);
|
||||||
return (status == kStatus_Success) ? 0 : -1;
|
return (status == kStatus_Success) ? 0 : -1;
|
||||||
}
|
}
|
||||||
@ -2556,15 +2558,13 @@ int wc_AesSetIV(Aes* aes, const byte* iv)
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
int len = sz;
|
word32 blocks = (sz / AES_BLOCK_SIZE);
|
||||||
|
|
||||||
byte *iv;
|
byte *iv;
|
||||||
byte temp_block[AES_BLOCK_SIZE];
|
byte temp_block[AES_BLOCK_SIZE];
|
||||||
|
|
||||||
iv = (byte*)aes->reg;
|
iv = (byte*)aes->reg;
|
||||||
|
|
||||||
while (len > 0)
|
while (blocks--) {
|
||||||
{
|
|
||||||
XMEMCPY(temp_block, in + offset, AES_BLOCK_SIZE);
|
XMEMCPY(temp_block, in + offset, AES_BLOCK_SIZE);
|
||||||
|
|
||||||
/* XOR block with IV for CBC */
|
/* XOR block with IV for CBC */
|
||||||
@ -2573,7 +2573,6 @@ int wc_AesSetIV(Aes* aes, const byte* iv)
|
|||||||
|
|
||||||
wc_AesEncrypt(aes, temp_block, out + offset);
|
wc_AesEncrypt(aes, temp_block, out + offset);
|
||||||
|
|
||||||
len -= AES_BLOCK_SIZE;
|
|
||||||
offset += AES_BLOCK_SIZE;
|
offset += AES_BLOCK_SIZE;
|
||||||
|
|
||||||
/* store IV for next block */
|
/* store IV for next block */
|
||||||
@ -2587,16 +2586,13 @@ int wc_AesSetIV(Aes* aes, const byte* iv)
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
int len = sz;
|
word32 blocks = (sz / AES_BLOCK_SIZE);
|
||||||
|
|
||||||
byte* iv;
|
byte* iv;
|
||||||
byte temp_block[AES_BLOCK_SIZE];
|
byte temp_block[AES_BLOCK_SIZE];
|
||||||
|
|
||||||
iv = (byte*)aes->reg;
|
iv = (byte*)aes->reg;
|
||||||
|
|
||||||
|
while (blocks--) {
|
||||||
while (len > 0)
|
|
||||||
{
|
|
||||||
XMEMCPY(temp_block, in + offset, AES_BLOCK_SIZE);
|
XMEMCPY(temp_block, in + offset, AES_BLOCK_SIZE);
|
||||||
|
|
||||||
wc_AesDecrypt(aes, in + offset, out + offset);
|
wc_AesDecrypt(aes, in + offset, out + offset);
|
||||||
@ -2608,7 +2604,6 @@ int wc_AesSetIV(Aes* aes, const byte* iv)
|
|||||||
/* store IV for next block */
|
/* store IV for next block */
|
||||||
XMEMCPY(iv, temp_block, AES_BLOCK_SIZE);
|
XMEMCPY(iv, temp_block, AES_BLOCK_SIZE);
|
||||||
|
|
||||||
len -= AES_BLOCK_SIZE;
|
|
||||||
offset += AES_BLOCK_SIZE;
|
offset += AES_BLOCK_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2623,7 +2618,6 @@ int wc_AesSetIV(Aes* aes, const byte* iv)
|
|||||||
{
|
{
|
||||||
securityAssociation *sa_p;
|
securityAssociation *sa_p;
|
||||||
bufferDescriptor *bd_p;
|
bufferDescriptor *bd_p;
|
||||||
|
|
||||||
volatile securityAssociation sa __attribute__((aligned (8)));
|
volatile securityAssociation sa __attribute__((aligned (8)));
|
||||||
volatile bufferDescriptor bd __attribute__((aligned (8)));
|
volatile bufferDescriptor bd __attribute__((aligned (8)));
|
||||||
volatile int k;
|
volatile int k;
|
||||||
@ -2633,7 +2627,7 @@ int wc_AesSetIV(Aes* aes, const byte* iv)
|
|||||||
bd_p = KVA0_TO_KVA1(&bd);
|
bd_p = KVA0_TO_KVA1(&bd);
|
||||||
|
|
||||||
/* Sync cache and physical memory */
|
/* Sync cache and physical memory */
|
||||||
if(PIC32MZ_IF_RAM(in)) {
|
if (PIC32MZ_IF_RAM(in)) {
|
||||||
XMEMCPY((void *)KVA0_TO_KVA1(in), (void *)in, sz);
|
XMEMCPY((void *)KVA0_TO_KVA1(in), (void *)in, sz);
|
||||||
}
|
}
|
||||||
XMEMSET((void *)KVA0_TO_KVA1(out), 0, sz);
|
XMEMSET((void *)KVA0_TO_KVA1(out), 0, sz);
|
||||||
@ -2646,17 +2640,17 @@ int wc_AesSetIV(Aes* aes, const byte* iv)
|
|||||||
sa_p->SA_CTRL.ENCTYPE = dir; /* Encryption/Decryption */
|
sa_p->SA_CTRL.ENCTYPE = dir; /* Encryption/Decryption */
|
||||||
sa_p->SA_CTRL.CRYPTOALGO = cryptoalgo;
|
sa_p->SA_CTRL.CRYPTOALGO = cryptoalgo;
|
||||||
|
|
||||||
if(cryptoalgo == PIC32_CRYPTOALGO_AES_GCM){
|
if (cryptoalgo == PIC32_CRYPTOALGO_AES_GCM) {
|
||||||
switch(aes->keylen) {
|
switch(aes->keylen) {
|
||||||
case 32:
|
case 32:
|
||||||
sa_p->SA_CTRL.KEYSIZE = PIC32_AES_KEYSIZE_256;
|
sa_p->SA_CTRL.KEYSIZE = PIC32_AES_KEYSIZE_256;
|
||||||
break;
|
break;
|
||||||
case 24:
|
case 24:
|
||||||
sa_p->SA_CTRL.KEYSIZE = PIC32_AES_KEYSIZE_192;
|
sa_p->SA_CTRL.KEYSIZE = PIC32_AES_KEYSIZE_192;
|
||||||
break;
|
break;
|
||||||
case 16:
|
case 16:
|
||||||
sa_p->SA_CTRL.KEYSIZE = PIC32_AES_KEYSIZE_128;
|
sa_p->SA_CTRL.KEYSIZE = PIC32_AES_KEYSIZE_128;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
sa_p->SA_CTRL.KEYSIZE = PIC32_AES_KEYSIZE_128;
|
sa_p->SA_CTRL.KEYSIZE = PIC32_AES_KEYSIZE_128;
|
||||||
@ -2670,7 +2664,7 @@ int wc_AesSetIV(Aes* aes, const byte* iv)
|
|||||||
XMEMSET((byte *)KVA0_TO_KVA1(&bd), 0, sizeof(bd));
|
XMEMSET((byte *)KVA0_TO_KVA1(&bd), 0, sizeof(bd));
|
||||||
/* Set up the Buffer Descriptor */
|
/* Set up the Buffer Descriptor */
|
||||||
bd_p->BD_CTRL.BUFLEN = sz;
|
bd_p->BD_CTRL.BUFLEN = sz;
|
||||||
if(cryptoalgo == PIC32_CRYPTOALGO_AES_GCM) {
|
if (cryptoalgo == PIC32_CRYPTOALGO_AES_GCM) {
|
||||||
if(sz % 0x10)
|
if(sz % 0x10)
|
||||||
bd_p->BD_CTRL.BUFLEN = (sz/0x10 + 1) * 0x10;
|
bd_p->BD_CTRL.BUFLEN = (sz/0x10 + 1) * 0x10;
|
||||||
}
|
}
|
||||||
@ -2698,7 +2692,7 @@ int wc_AesSetIV(Aes* aes, const byte* iv)
|
|||||||
(cryptoalgo == PIC32_CRYPTOALGO_TCBC)||
|
(cryptoalgo == PIC32_CRYPTOALGO_TCBC)||
|
||||||
(cryptoalgo == PIC32_CRYPTOALGO_RCBC)) {
|
(cryptoalgo == PIC32_CRYPTOALGO_RCBC)) {
|
||||||
/* set iv for the next call */
|
/* set iv for the next call */
|
||||||
if(dir == PIC32_ENCRYPTION) {
|
if (dir == PIC32_ENCRYPTION) {
|
||||||
XMEMCPY((void *)aes->iv_ce,
|
XMEMCPY((void *)aes->iv_ce,
|
||||||
(void*)KVA0_TO_KVA1(out + sz - AES_BLOCK_SIZE),
|
(void*)KVA0_TO_KVA1(out + sz - AES_BLOCK_SIZE),
|
||||||
AES_BLOCK_SIZE);
|
AES_BLOCK_SIZE);
|
||||||
@ -2730,7 +2724,7 @@ int wc_AesSetIV(Aes* aes, const byte* iv)
|
|||||||
#else
|
#else
|
||||||
int wc_AesCbcEncrypt(Aes* aes, byte* out, const byte* in, word32 sz)
|
int wc_AesCbcEncrypt(Aes* aes, byte* out, const byte* in, word32 sz)
|
||||||
{
|
{
|
||||||
word32 blocks = sz / AES_BLOCK_SIZE;
|
word32 blocks = (sz / AES_BLOCK_SIZE);
|
||||||
|
|
||||||
#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_AES)
|
#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_AES)
|
||||||
/* if async and byte count above threshold */
|
/* if async and byte count above threshold */
|
||||||
|
@ -159,6 +159,7 @@ ASN Options:
|
|||||||
#elif defined(FREESCALE_KSDK_BM) || defined(FREESCALE_FREE_RTOS) || defined(FREESCALE_KSDK_FREERTOS)
|
#elif defined(FREESCALE_KSDK_BM) || defined(FREESCALE_FREE_RTOS) || defined(FREESCALE_KSDK_FREERTOS)
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#ifndef XTIME
|
#ifndef XTIME
|
||||||
|
/*extern time_t ksdk_time(time_t* timer);*/
|
||||||
#define XTIME(t1) ksdk_time((t1))
|
#define XTIME(t1) ksdk_time((t1))
|
||||||
#endif
|
#endif
|
||||||
#define XGMTIME(c, t) gmtime((c))
|
#define XGMTIME(c, t) gmtime((c))
|
||||||
@ -244,10 +245,6 @@ ASN Options:
|
|||||||
struct tm* gmtime(const time_t* timer);
|
struct tm* gmtime(const time_t* timer);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(FREESCALE_KSDK_BM) || defined(FREESCALE_FREE_RTOS)
|
|
||||||
/* extern time_t ksdk_time(time_t* timer); */
|
|
||||||
#endif /* FREESCALE_KSDK_BM || FREESCALE_FREE_RTOS */
|
|
||||||
|
|
||||||
|
|
||||||
#if defined(_WIN32_WCE)
|
#if defined(_WIN32_WCE)
|
||||||
time_t windows_time(time_t* timer)
|
time_t windows_time(time_t* timer)
|
||||||
|
@ -2283,6 +2283,8 @@ exit:
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif /* !FREESCALE_LTC_ECC */
|
||||||
|
|
||||||
/** ECC Fixed Point mulmod global
|
/** ECC Fixed Point mulmod global
|
||||||
k The multiplicand
|
k The multiplicand
|
||||||
G Base point to multiply
|
G Base point to multiply
|
||||||
@ -2299,8 +2301,6 @@ int wc_ecc_mulmod(mp_int* k, ecc_point *G, ecc_point *R, mp_int* a,
|
|||||||
return wc_ecc_mulmod_ex(k, G, R, a, modulus, map, NULL);
|
return wc_ecc_mulmod_ex(k, G, R, a, modulus, map, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* !FREESCALE_LTC_ECC */
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef ALT_ECC_SIZE
|
#ifdef ALT_ECC_SIZE
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user