mirror of https://github.com/wolfSSL/wolfssl.git
Merge branch 'master' into ti
commit
4c8d94023b
|
@ -1166,10 +1166,10 @@ void bench_eccKeyAgree(void)
|
||||||
|
|
||||||
#elif defined MICROCHIP_PIC32
|
#elif defined MICROCHIP_PIC32
|
||||||
#if defined(CYASSL_MICROCHIP_PIC32MZ)
|
#if defined(CYASSL_MICROCHIP_PIC32MZ)
|
||||||
#define CLOCK 8000000.0
|
#define CLOCK 80000000.0
|
||||||
#else
|
#else
|
||||||
#include <peripheral/timer.h>
|
#include <peripheral/timer.h>
|
||||||
#define CLOCK 4000000.0
|
#define CLOCK 40000000.0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
double current_time(int reset)
|
double current_time(int reset)
|
||||||
|
|
|
@ -63,7 +63,7 @@
|
||||||
|
|
||||||
#if defined(CYASSL_PIC32MZ_CRYPT)
|
#if defined(CYASSL_PIC32MZ_CRYPT)
|
||||||
|
|
||||||
#include "../../cyassl/ctaocrypt/port/pic32/pic32mz-crypt.h"
|
#include "cyassl/ctaocrypt/port/pic32/pic32mz-crypt.h"
|
||||||
#define DEBUG_CYASSL
|
#define DEBUG_CYASSL
|
||||||
|
|
||||||
/* core hardware crypt engine driver */
|
/* core hardware crypt engine driver */
|
||||||
|
@ -165,12 +165,14 @@
|
||||||
{
|
{
|
||||||
AesCrypt(aes, out, in, sz, PIC32_ENCRYPTION, PIC32_ALGO_AES,
|
AesCrypt(aes, out, in, sz, PIC32_ENCRYPTION, PIC32_ALGO_AES,
|
||||||
PIC32_CRYPTOALGO_RCBC );
|
PIC32_CRYPTOALGO_RCBC );
|
||||||
|
return 0 ;
|
||||||
}
|
}
|
||||||
|
|
||||||
int AesCbcDecrypt(Aes* aes, byte* out, const byte* in, word32 sz)
|
int AesCbcDecrypt(Aes* aes, byte* out, const byte* in, word32 sz)
|
||||||
{
|
{
|
||||||
AesCrypt(aes, out, in, sz, PIC32_DECRYPTION, PIC32_ALGO_AES,
|
AesCrypt(aes, out, in, sz, PIC32_DECRYPTION, PIC32_ALGO_AES,
|
||||||
PIC32_CRYPTOALGO_RCBC);
|
PIC32_CRYPTOALGO_RCBC);
|
||||||
|
return 0 ;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(CYASSL_AES_COUNTER)
|
#if defined(CYASSL_AES_COUNTER)
|
||||||
|
@ -603,24 +605,121 @@
|
||||||
|
|
||||||
#endif /* CYASSL_AES_COUNTER */
|
#endif /* CYASSL_AES_COUNTER */
|
||||||
|
|
||||||
|
|
||||||
#elif defined(HAVE_COLDFIRE_SEC)
|
#elif defined(HAVE_COLDFIRE_SEC)
|
||||||
|
|
||||||
#include "sec.h"
|
#include <cyassl/ctaocrypt/types.h>
|
||||||
#include "mcf548x_sec.h"
|
|
||||||
#include "mcf548x_siu.h"
|
|
||||||
|
|
||||||
|
#include "sec.h"
|
||||||
|
#include "mcf5475_sec.h"
|
||||||
|
#include "mcf5475_siu.h"
|
||||||
|
|
||||||
|
#if defined (HAVE_THREADX)
|
||||||
#include "memory_pools.h"
|
#include "memory_pools.h"
|
||||||
extern TX_BYTE_POOL mp_ncached; /* Non Cached memory pool */
|
extern TX_BYTE_POOL mp_ncached; /* Non Cached memory pool */
|
||||||
#define AES_BUFFER_SIZE (AES_BLOCK_SIZE * 8)
|
#endif
|
||||||
static unsigned char *AESBuffer = NULL ;
|
|
||||||
|
#define AES_BUFFER_SIZE (AES_BLOCK_SIZE * 64)
|
||||||
|
static unsigned char *AESBuffIn = NULL ;
|
||||||
|
static unsigned char *AESBuffOut = NULL ;
|
||||||
|
static byte *secReg ;
|
||||||
|
static byte *secKey ;
|
||||||
|
static volatile SECdescriptorType *secDesc ;
|
||||||
|
|
||||||
|
static CyaSSL_Mutex Mutex_AesSEC ;
|
||||||
|
|
||||||
#define SEC_DESC_AES_CBC_ENCRYPT 0x60300010
|
#define SEC_DESC_AES_CBC_ENCRYPT 0x60300010
|
||||||
#define SEC_DESC_AES_CBC_DECRYPT 0x60200010
|
#define SEC_DESC_AES_CBC_DECRYPT 0x60200010
|
||||||
#define AES_BLOCK_LENGTH 16
|
|
||||||
|
|
||||||
extern volatile unsigned char __MBAR[];
|
extern volatile unsigned char __MBAR[];
|
||||||
|
|
||||||
|
static int AesCbcCrypt(Aes* aes, byte* po, const byte* pi, word32 sz, word32 descHeader)
|
||||||
|
{
|
||||||
|
#ifdef DEBUG_CYASSL
|
||||||
|
int i ; int stat1, stat2 ; int ret ;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int size ;
|
||||||
|
volatile int v ;
|
||||||
|
|
||||||
|
if((pi == NULL) || (po == NULL))
|
||||||
|
return BAD_FUNC_ARG;/*wrong pointer*/
|
||||||
|
|
||||||
|
LockMutex(&Mutex_AesSEC) ;
|
||||||
|
|
||||||
|
/* Set descriptor for SEC */
|
||||||
|
secDesc->length1 = 0x0;
|
||||||
|
secDesc->pointer1 = NULL;
|
||||||
|
|
||||||
|
secDesc->length2 = AES_BLOCK_SIZE;
|
||||||
|
secDesc->pointer2 = (byte *)secReg ; /* Initial Vector */
|
||||||
|
|
||||||
|
switch(aes->rounds) {
|
||||||
|
case 10: secDesc->length3 = 16 ; break ;
|
||||||
|
case 12: secDesc->length3 = 24 ; break ;
|
||||||
|
case 14: secDesc->length3 = 32 ; break ;
|
||||||
|
}
|
||||||
|
XMEMCPY(secKey, aes->key, secDesc->length3) ;
|
||||||
|
|
||||||
|
secDesc->pointer3 = (byte *)secKey;
|
||||||
|
secDesc->pointer4 = AESBuffIn ;
|
||||||
|
secDesc->pointer5 = AESBuffOut ;
|
||||||
|
secDesc->length6 = 0x0;
|
||||||
|
secDesc->pointer6 = NULL;
|
||||||
|
secDesc->length7 = 0x0;
|
||||||
|
secDesc->pointer7 = NULL;
|
||||||
|
secDesc->nextDescriptorPtr = NULL;
|
||||||
|
|
||||||
|
while(sz) {
|
||||||
|
secDesc->header = descHeader ;
|
||||||
|
XMEMCPY(secReg, aes->reg, AES_BLOCK_SIZE) ;
|
||||||
|
if((sz%AES_BUFFER_SIZE) == sz) {
|
||||||
|
size = sz ;
|
||||||
|
sz = 0 ;
|
||||||
|
} else {
|
||||||
|
size = AES_BUFFER_SIZE ;
|
||||||
|
sz -= AES_BUFFER_SIZE ;
|
||||||
|
}
|
||||||
|
secDesc->length4 = size;
|
||||||
|
secDesc->length5 = size;
|
||||||
|
|
||||||
|
XMEMCPY(AESBuffIn, pi, size) ;
|
||||||
|
if(descHeader == SEC_DESC_AES_CBC_DECRYPT) {
|
||||||
|
XMEMCPY((void*)aes->tmp, (void*)&(pi[size-AES_BLOCK_SIZE]), AES_BLOCK_SIZE) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Point SEC to the location of the descriptor */
|
||||||
|
MCF_SEC_FR0 = (uint32)secDesc;
|
||||||
|
/* Initialize SEC and wait for encryption to complete */
|
||||||
|
MCF_SEC_CCCR0 = 0x0000001a;
|
||||||
|
/* poll SISR to determine when channel is complete */
|
||||||
|
v=0 ;
|
||||||
|
while((secDesc->header>> 24) != 0xff)v++ ;
|
||||||
|
|
||||||
|
#ifdef DEBUG_CYASSL
|
||||||
|
ret = MCF_SEC_SISRH;
|
||||||
|
stat1 = MCF_SEC_AESSR ;
|
||||||
|
stat2 = MCF_SEC_AESISR ;
|
||||||
|
if(ret & 0xe0000000)
|
||||||
|
{
|
||||||
|
db_printf("Aes_Cbc(i=%d):ISRH=%08x, AESSR=%08x, AESISR=%08x\n", i, ret, stat1, stat2) ;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
XMEMCPY(po, AESBuffOut, size) ;
|
||||||
|
|
||||||
|
if(descHeader == SEC_DESC_AES_CBC_ENCRYPT) {
|
||||||
|
XMEMCPY((void*)aes->reg, (void*)&(po[size-AES_BLOCK_SIZE]), AES_BLOCK_SIZE) ;
|
||||||
|
} else {
|
||||||
|
XMEMCPY((void*)aes->reg, (void*)aes->tmp, AES_BLOCK_SIZE) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
pi += size ;
|
||||||
|
po += size ;
|
||||||
|
}
|
||||||
|
UnLockMutex(&Mutex_AesSEC) ;
|
||||||
|
return 0 ;
|
||||||
|
}
|
||||||
|
|
||||||
int AesCbcEncrypt(Aes* aes, byte* po, const byte* pi, word32 sz)
|
int AesCbcEncrypt(Aes* aes, byte* po, const byte* pi, word32 sz)
|
||||||
{
|
{
|
||||||
return(AesCbcCrypt(aes, po, pi, sz, SEC_DESC_AES_CBC_ENCRYPT)) ;
|
return(AesCbcCrypt(aes, po, pi, sz, SEC_DESC_AES_CBC_ENCRYPT)) ;
|
||||||
|
@ -631,95 +730,27 @@ int AesCbcDecrypt(Aes* aes, byte* po, const byte* pi, word32 sz)
|
||||||
return(AesCbcCrypt(aes, po, pi, sz, SEC_DESC_AES_CBC_DECRYPT)) ;
|
return(AesCbcCrypt(aes, po, pi, sz, SEC_DESC_AES_CBC_DECRYPT)) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int AesCbcCrypt(Aes* aes, byte* po, const byte* pi, word32 sz, word32 descHeader)
|
|
||||||
{
|
|
||||||
|
|
||||||
int i ; int stat1, stat2 ;
|
|
||||||
int ret ; int size ;
|
|
||||||
static SECdescriptorType descriptor;
|
|
||||||
volatile int v ;
|
|
||||||
|
|
||||||
if((pi == NULL) || (po == NULL))
|
|
||||||
return BAD_FUNC_ARG;/*wrong pointer*/
|
|
||||||
|
|
||||||
while(sz) {
|
|
||||||
if((sz%AES_BUFFER_SIZE) == sz) {
|
|
||||||
size = sz ;
|
|
||||||
sz = 0 ;
|
|
||||||
} else {
|
|
||||||
size = AES_BUFFER_SIZE ;
|
|
||||||
sz -= AES_BUFFER_SIZE ;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Set descriptor for SEC */
|
|
||||||
descriptor.header = descHeader ;
|
|
||||||
/*
|
|
||||||
descriptor.length1 = 0x0;
|
|
||||||
descriptor.pointer1 = NULL;
|
|
||||||
*/
|
|
||||||
descriptor.length2 = AES_BLOCK_SIZE;
|
|
||||||
descriptor.pointer2 = (byte *)aes->reg ; /* Initial Vector */
|
|
||||||
|
|
||||||
switch(aes->rounds) {
|
|
||||||
case 10: descriptor.length3 = 16 ; break ;
|
|
||||||
case 12: descriptor.length3 = 24 ; break ;
|
|
||||||
case 14: descriptor.length3 = 32 ; break ;
|
|
||||||
}
|
|
||||||
|
|
||||||
descriptor.pointer3 = (byte *)aes->key;
|
|
||||||
descriptor.length4 = size;
|
|
||||||
descriptor.pointer4 = (byte *)pi ;
|
|
||||||
descriptor.length5 = size;
|
|
||||||
descriptor.pointer5 = AESBuffer ;
|
|
||||||
/*
|
|
||||||
descriptor.length6 = 0x0;
|
|
||||||
descriptor.pointer6 = NULL;
|
|
||||||
descriptor.length7 = 0x0;
|
|
||||||
descriptor.pointer7 = NULL;
|
|
||||||
descriptor.nextDescriptorPtr = NULL;
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Initialize SEC and wait for encryption to complete */
|
|
||||||
MCF_SEC_CCCR0 = 0x00000000;
|
|
||||||
|
|
||||||
/* Point SEC to the location of the descriptor */
|
|
||||||
MCF_SEC_FR0 = (uint32)&descriptor;
|
|
||||||
|
|
||||||
/* poll SISR to determine when channel is complete */
|
|
||||||
i=0 ;
|
|
||||||
while (!(MCF_SEC_SISRL) && !(MCF_SEC_SISRH))i++ ;
|
|
||||||
for(v=0; v<100; v++) ;
|
|
||||||
|
|
||||||
ret = MCF_SEC_SISRH;
|
|
||||||
stat1 = MCF_SEC_AESSR ;
|
|
||||||
stat2 = MCF_SEC_AESISR ;
|
|
||||||
if(ret & 0xe0000000)
|
|
||||||
{
|
|
||||||
db_printf("Aes_Cbc(i=%d):ISRH=%08x, AESSR=%08x, AESISR=%08x\n", i, ret, stat1, stat2) ;
|
|
||||||
}
|
|
||||||
|
|
||||||
XMEMCPY(po, AESBuffer, size) ;
|
|
||||||
|
|
||||||
if(descHeader == SEC_DESC_AES_CBC_ENCRYPT) {
|
|
||||||
XMEMCPY((void*)aes->reg, (void*)&(po[size-AES_BLOCK_SIZE]), AES_BLOCK_SIZE) ;
|
|
||||||
} else {
|
|
||||||
XMEMCPY((void*)aes->reg, (void*)&(pi[size-AES_BLOCK_SIZE]), AES_BLOCK_SIZE) ;
|
|
||||||
}
|
|
||||||
|
|
||||||
pi += size ;
|
|
||||||
po += size ;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0 ; /* for descriptier header 0xff000000 mode */
|
|
||||||
}
|
|
||||||
|
|
||||||
int AesSetKey(Aes* aes, const byte* userKey, word32 keylen, const byte* iv,
|
int AesSetKey(Aes* aes, const byte* userKey, word32 keylen, const byte* iv,
|
||||||
int dir)
|
int dir)
|
||||||
{
|
{
|
||||||
int status ;
|
|
||||||
|
|
||||||
if(AESBuffer == NULL) {
|
if(AESBuffIn == NULL) {
|
||||||
status = tx_byte_allocate(&mp_ncached,(void *)&AESBuffer, AES_BUFFER_SIZE,TX_NO_WAIT);
|
#if defined (HAVE_THREADX)
|
||||||
|
int s1, s2, s3, s4, s5 ;
|
||||||
|
s5 = tx_byte_allocate(&mp_ncached,(void *)&secDesc, sizeof(SECdescriptorType), TX_NO_WAIT);
|
||||||
|
s1 = tx_byte_allocate(&mp_ncached,(void *)&AESBuffIn, AES_BUFFER_SIZE, TX_NO_WAIT);
|
||||||
|
s2 = tx_byte_allocate(&mp_ncached,(void *)&AESBuffOut, AES_BUFFER_SIZE, TX_NO_WAIT);
|
||||||
|
s3 = tx_byte_allocate(&mp_ncached,(void *)&secKey, AES_BLOCK_SIZE*2,TX_NO_WAIT);
|
||||||
|
s4 = tx_byte_allocate(&mp_ncached,(void *)&secReg, AES_BLOCK_SIZE, TX_NO_WAIT);
|
||||||
|
|
||||||
|
if(s1 || s2 || s3 || s4 || s5)
|
||||||
|
return BAD_FUNC_ARG;
|
||||||
|
|
||||||
|
#else
|
||||||
|
#warning "Allocate non-Cache buffers"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
InitMutex(&Mutex_AesSEC) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!((keylen == 16) || (keylen == 24) || (keylen == 32)))
|
if (!((keylen == 16) || (keylen == 24) || (keylen == 32)))
|
||||||
|
@ -732,6 +763,7 @@ int AesSetKey(Aes* aes, const byte* userKey, word32 keylen, const byte* iv,
|
||||||
XMEMCPY(aes->key, userKey, keylen);
|
XMEMCPY(aes->key, userKey, keylen);
|
||||||
if (iv)
|
if (iv)
|
||||||
XMEMCPY(aes->reg, iv, AES_BLOCK_SIZE);
|
XMEMCPY(aes->reg, iv, AES_BLOCK_SIZE);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -273,32 +273,72 @@
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#elif defined(HAVE_COLDFIRE_SEC)
|
#elif defined(HAVE_COLDFIRE_SEC)
|
||||||
|
|
||||||
#include "sec.h"
|
#include <cyassl/ctaocrypt/types.h>
|
||||||
#include "mcf548x_sec.h"
|
|
||||||
|
|
||||||
|
#include "sec.h"
|
||||||
|
#include "mcf5475_sec.h"
|
||||||
|
#include "mcf5475_siu.h"
|
||||||
|
|
||||||
|
#if defined (HAVE_THREADX)
|
||||||
#include "memory_pools.h"
|
#include "memory_pools.h"
|
||||||
extern TX_BYTE_POOL mp_ncached; /* Non Cached memory pool */
|
extern TX_BYTE_POOL mp_ncached; /* Non Cached memory pool */
|
||||||
#define DES_BUFFER_SIZE (DES_BLOCK_SIZE * 16)
|
#endif
|
||||||
static unsigned char *DesBuffer = NULL ;
|
|
||||||
|
#define DES_BUFFER_SIZE (DES_BLOCK_SIZE * 64)
|
||||||
|
static unsigned char *desBuffIn = NULL ;
|
||||||
|
static unsigned char *desBuffOut = NULL ;
|
||||||
|
static byte *secIV ;
|
||||||
|
static byte *secKey ;
|
||||||
|
static volatile SECdescriptorType *secDesc ;
|
||||||
|
|
||||||
|
static CyaSSL_Mutex Mutex_DesSEC ;
|
||||||
|
|
||||||
#define SEC_DESC_DES_CBC_ENCRYPT 0x20500010
|
#define SEC_DESC_DES_CBC_ENCRYPT 0x20500010
|
||||||
#define SEC_DESC_DES_CBC_DECRYPT 0x20400010
|
#define SEC_DESC_DES_CBC_DECRYPT 0x20400010
|
||||||
#define SEC_DESC_DES3_CBC_ENCRYPT 0x20700010
|
#define SEC_DESC_DES3_CBC_ENCRYPT 0x20700010
|
||||||
#define SEC_DESC_DES3_CBC_DECRYPT 0x20600010
|
#define SEC_DESC_DES3_CBC_DECRYPT 0x20600010
|
||||||
|
|
||||||
|
#define DES_IVLEN 8
|
||||||
|
#define DES_KEYLEN 8
|
||||||
|
#define DES3_IVLEN 8
|
||||||
|
#define DES3_KEYLEN 24
|
||||||
|
|
||||||
extern volatile unsigned char __MBAR[];
|
extern volatile unsigned char __MBAR[];
|
||||||
|
|
||||||
static void Des_Cbc(Des* des, byte* out, const byte* in, word32 sz, word32 desc)
|
static void Des_Cbc(byte* out, const byte* in, word32 sz,
|
||||||
|
byte *key, byte *iv, word32 desc)
|
||||||
{
|
{
|
||||||
static volatile SECdescriptorType descriptor = { NULL } ;
|
#ifdef DEBUG_CYASSL
|
||||||
int ret ; int stat1,stat2 ;
|
int ret ; int stat1,stat2 ;
|
||||||
int i ; int size ;
|
#endif
|
||||||
|
int size ;
|
||||||
volatile int v ;
|
volatile int v ;
|
||||||
|
|
||||||
|
LockMutex(&Mutex_DesSEC) ;
|
||||||
|
|
||||||
|
secDesc->length1 = 0x0;
|
||||||
|
secDesc->pointer1 = NULL;
|
||||||
|
if((desc==SEC_DESC_DES_CBC_ENCRYPT)||(desc==SEC_DESC_DES_CBC_DECRYPT)){
|
||||||
|
secDesc->length2 = DES_IVLEN ;
|
||||||
|
secDesc->length3 = DES_KEYLEN ;
|
||||||
|
} else {
|
||||||
|
secDesc->length2 = DES3_IVLEN ;
|
||||||
|
secDesc->length3 = DES3_KEYLEN ;
|
||||||
|
}
|
||||||
|
secDesc->pointer2 = secIV ;
|
||||||
|
secDesc->pointer3 = secKey;
|
||||||
|
secDesc->pointer4 = desBuffIn ;
|
||||||
|
secDesc->pointer5 = desBuffOut ;
|
||||||
|
secDesc->length6 = 0;
|
||||||
|
secDesc->pointer6 = NULL;
|
||||||
|
secDesc->length7 = 0x0;
|
||||||
|
secDesc->pointer7 = NULL;
|
||||||
|
secDesc->nextDescriptorPtr = NULL ;
|
||||||
|
|
||||||
while(sz) {
|
while(sz) {
|
||||||
|
XMEMCPY(secIV, iv, secDesc->length2) ;
|
||||||
if((sz%DES_BUFFER_SIZE) == sz) {
|
if((sz%DES_BUFFER_SIZE) == sz) {
|
||||||
size = sz ;
|
size = sz ;
|
||||||
sz = 0 ;
|
sz = 0 ;
|
||||||
|
@ -307,125 +347,152 @@ static void Des_Cbc(Des* des, byte* out, const byte* in, word32 sz, word32 desc)
|
||||||
sz -= DES_BUFFER_SIZE ;
|
sz -= DES_BUFFER_SIZE ;
|
||||||
}
|
}
|
||||||
|
|
||||||
descriptor.header = desc ;
|
XMEMCPY(desBuffIn, in, size) ;
|
||||||
/*
|
XMEMCPY(secKey, key, secDesc->length3) ;
|
||||||
escriptor.length1 = 0x0;
|
|
||||||
descriptor.pointer1 = NULL;
|
|
||||||
*/
|
|
||||||
descriptor.length2 = des->ivlen ;
|
|
||||||
descriptor.pointer2 = (byte *)des->iv ;
|
|
||||||
descriptor.length3 = des->keylen ;
|
|
||||||
descriptor.pointer3 = (byte *)des->key;
|
|
||||||
descriptor.length4 = size;
|
|
||||||
descriptor.pointer4 = (byte *)in ;
|
|
||||||
descriptor.length5 = size;
|
|
||||||
descriptor.pointer5 = DesBuffer ;
|
|
||||||
/*
|
|
||||||
descriptor.length6 = 0;
|
|
||||||
descriptor.pointer6 = NULL;
|
|
||||||
descriptor.length7 = 0x0;
|
|
||||||
descriptor.pointer7 = NULL;
|
|
||||||
descriptor.nextDescriptorPtr = NULL ;
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Initialize SEC and wait for encryption to complete */
|
|
||||||
MCF_SEC_CCCR0 = 0x0000001A; //enable channel done notification
|
|
||||||
|
|
||||||
|
secDesc->header = desc ;
|
||||||
|
secDesc->length4 = size;
|
||||||
|
secDesc->length5 = size;
|
||||||
/* Point SEC to the location of the descriptor */
|
/* Point SEC to the location of the descriptor */
|
||||||
MCF_SEC_FR0 = (uint32)&descriptor;
|
MCF_SEC_FR0 = (uint32)secDesc;
|
||||||
|
/* Initialize SEC and wait for encryption to complete */
|
||||||
|
MCF_SEC_CCCR0 = 0x0000001a;
|
||||||
/* poll SISR to determine when channel is complete */
|
/* poll SISR to determine when channel is complete */
|
||||||
while (!(MCF_SEC_SISRL) && !(MCF_SEC_SISRH))
|
v=0 ;
|
||||||
;
|
while((secDesc->header>> 24) != 0xff) {
|
||||||
|
if(v++ > 1000)break ;
|
||||||
for(v=0; v<500; v++) ;
|
}
|
||||||
|
|
||||||
|
#ifdef DEBUG_CYASSL
|
||||||
ret = MCF_SEC_SISRH;
|
ret = MCF_SEC_SISRH;
|
||||||
stat1 = MCF_SEC_DSR ;
|
stat1 = MCF_SEC_DSR ;
|
||||||
stat2 = MCF_SEC_DISR ;
|
stat2 = MCF_SEC_DISR ;
|
||||||
if(ret & 0xe0000000)
|
if(ret & 0xe0000000) {
|
||||||
db_printf("Des_Cbc(%x):ISRH=%08x, DSR=%08x, DISR=%08x\n", desc, ret, stat1, stat2) ;
|
/* db_printf("Des_Cbc(%x):ISRH=%08x, DSR=%08x, DISR=%08x\n", desc, ret, stat1, stat2) ; */
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
XMEMCPY(out, DesBuffer, size) ;
|
XMEMCPY(out, desBuffOut, size) ;
|
||||||
|
|
||||||
if((desc==SEC_DESC_DES3_CBC_ENCRYPT)||(desc==SEC_DESC_DES_CBC_ENCRYPT)) {
|
if((desc==SEC_DESC_DES3_CBC_ENCRYPT)||(desc==SEC_DESC_DES_CBC_ENCRYPT)) {
|
||||||
XMEMCPY((void*)des->iv, (void*)&(out[size-DES_IVLEN]), DES_IVLEN) ;
|
XMEMCPY((void*)iv, (void*)&(out[size-secDesc->length2]), secDesc->length2) ;
|
||||||
} else {
|
} else {
|
||||||
XMEMCPY((void*)des->iv, (void*)&(in[size-DES_IVLEN]), DES_IVLEN) ;
|
XMEMCPY((void*)iv, (void*)&(in[size-secDesc->length2]), secDesc->length2) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
in += size ;
|
in += size ;
|
||||||
out += size ;
|
out += size ;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
UnLockMutex(&Mutex_DesSEC) ;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Des_CbcEncrypt(Des* des, byte* out, const byte* in, word32 sz)
|
void Des_CbcEncrypt(Des* des, byte* out, const byte* in, word32 sz)
|
||||||
{
|
{
|
||||||
Des_Cbc(des, out, in, sz, SEC_DESC_DES_CBC_ENCRYPT) ;
|
Des_Cbc(out, in, sz, (byte *)des->key, (byte *)des->reg, SEC_DESC_DES_CBC_ENCRYPT) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Des_CbcDecrypt(Des* des, byte* out, const byte* in, word32 sz)
|
void Des_CbcDecrypt(Des* des, byte* out, const byte* in, word32 sz)
|
||||||
{
|
{
|
||||||
Des_Cbc(des, out, in, sz, SEC_DESC_DES_CBC_DECRYPT) ;
|
Des_Cbc(out, in, sz, (byte *)des->key, (byte *)des->reg, SEC_DESC_DES_CBC_DECRYPT) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Des3_CbcEncrypt(Des3* des3, byte* out, const byte* in, word32 sz)
|
int Des3_CbcEncrypt(Des3* des3, byte* out, const byte* in, word32 sz)
|
||||||
{
|
{
|
||||||
Des_Cbc((Des *)des3, out, in, sz, SEC_DESC_DES3_CBC_ENCRYPT) ;
|
Des_Cbc(out, in, sz, (byte *)des3->key, (byte *)des3->reg, SEC_DESC_DES3_CBC_ENCRYPT) ;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int Des3_CbcDecrypt(Des3* des3, byte* out, const byte* in, word32 sz)
|
int Des3_CbcDecrypt(Des3* des3, byte* out, const byte* in, word32 sz)
|
||||||
{
|
{
|
||||||
Des_Cbc((Des *)des3, out, in, sz, SEC_DESC_DES3_CBC_DECRYPT) ;
|
Des_Cbc(out, in, sz, (byte *)des3->key, (byte *)des3->reg, SEC_DESC_DES3_CBC_DECRYPT) ;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void setParity(byte *buf, int len)
|
||||||
|
{
|
||||||
|
int i, j ;
|
||||||
|
byte v ;
|
||||||
|
int bits ;
|
||||||
|
|
||||||
|
for(i=0; i<len; i++)
|
||||||
|
{
|
||||||
|
v = buf[i] >> 1 ;
|
||||||
|
buf[i] = v << 1 ;
|
||||||
|
bits = 0 ;
|
||||||
|
for(j=0; j<7; j++)
|
||||||
|
{
|
||||||
|
bits += (v&0x1) ;
|
||||||
|
v = v >> 1 ;
|
||||||
|
}
|
||||||
|
buf[i] |= (1 - (bits&0x1)) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int Des_SetKey(Des* des, const byte* key, const byte* iv, int dir)
|
int Des_SetKey(Des* des, const byte* key, const byte* iv, int dir)
|
||||||
{
|
{
|
||||||
int i ; int status ;
|
if(desBuffIn == NULL) {
|
||||||
|
#if defined (HAVE_THREADX)
|
||||||
|
int s1, s2, s3, s4, s5 ;
|
||||||
|
s5 = tx_byte_allocate(&mp_ncached,(void *)&secDesc,
|
||||||
|
sizeof(SECdescriptorType), TX_NO_WAIT);
|
||||||
|
s1 = tx_byte_allocate(&mp_ncached,(void *)&desBuffIn, DES_BUFFER_SIZE, TX_NO_WAIT);
|
||||||
|
s2 = tx_byte_allocate(&mp_ncached,(void *)&desBuffOut, DES_BUFFER_SIZE, TX_NO_WAIT);
|
||||||
|
/* Don't know des or des3 to be used. Allocate larger buffers */
|
||||||
|
s3 = tx_byte_allocate(&mp_ncached,(void *)&secKey, DES3_KEYLEN,TX_NO_WAIT);
|
||||||
|
s4 = tx_byte_allocate(&mp_ncached,(void *)&secIV, DES3_IVLEN, TX_NO_WAIT);
|
||||||
|
#else
|
||||||
|
#warning "Allocate non-Cache buffers"
|
||||||
|
#endif
|
||||||
|
|
||||||
if(DesBuffer == NULL) {
|
InitMutex(&Mutex_DesSEC) ;
|
||||||
status = tx_byte_allocate(&mp_ncached,(void *)&DesBuffer,DES_BUFFER_SIZE,TX_NO_WAIT);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
XMEMCPY(des->key, key, DES_KEYLEN);
|
XMEMCPY(des->key, key, DES_KEYLEN);
|
||||||
des->keylen = DES_KEYLEN ;
|
setParity((byte *)des->key, DES_KEYLEN) ;
|
||||||
des->ivlen = 0 ;
|
|
||||||
if (iv) {
|
|
||||||
XMEMCPY(des->iv, iv, DES_IVLEN);
|
|
||||||
des->ivlen = DES_IVLEN ;
|
|
||||||
} else {
|
|
||||||
for(i=0; i<DES_IVLEN; i++)
|
|
||||||
des->iv[i] = 0x0 ;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (iv) {
|
||||||
|
XMEMCPY(des->reg, iv, DES_IVLEN);
|
||||||
|
} else {
|
||||||
|
XMEMSET(des->reg, 0x0, DES_IVLEN) ;
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Des3_SetKey(Des3* des3, const byte* key, const byte* iv, int dir)
|
int Des3_SetKey(Des3* des3, const byte* key, const byte* iv, int dir)
|
||||||
{
|
{
|
||||||
int i ; int status ;
|
|
||||||
|
|
||||||
if(DesBuffer == NULL) {
|
if(desBuffIn == NULL) {
|
||||||
status = tx_byte_allocate(&mp_ncached,(void *)&DesBuffer,DES_BUFFER_SIZE,TX_NO_WAIT);
|
#if defined (HAVE_THREADX)
|
||||||
|
int s1, s2, s3, s4, s5 ;
|
||||||
|
s5 = tx_byte_allocate(&mp_ncached,(void *)&secDesc,
|
||||||
|
sizeof(SECdescriptorType), TX_NO_WAIT);
|
||||||
|
s1 = tx_byte_allocate(&mp_ncached,(void *)&desBuffIn, DES_BUFFER_SIZE, TX_NO_WAIT);
|
||||||
|
s2 = tx_byte_allocate(&mp_ncached,(void *)&desBuffOut, DES_BUFFER_SIZE, TX_NO_WAIT);
|
||||||
|
s3 = tx_byte_allocate(&mp_ncached,(void *)&secKey, DES3_KEYLEN,TX_NO_WAIT);
|
||||||
|
s4 = tx_byte_allocate(&mp_ncached,(void *)&secIV, DES3_IVLEN, TX_NO_WAIT);
|
||||||
|
#else
|
||||||
|
#warning "Allocate non-Cache buffers"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
InitMutex(&Mutex_DesSEC) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
XMEMCPY(des3->key, key, DES3_KEYLEN);
|
XMEMCPY(des3->key[0], key, DES3_KEYLEN);
|
||||||
des3->keylen = DES3_KEYLEN ;
|
setParity((byte *)des3->key[0], DES3_KEYLEN) ;
|
||||||
des3->ivlen = 0 ;
|
|
||||||
if (iv) {
|
if (iv) {
|
||||||
XMEMCPY(des3->iv, iv, DES3_IVLEN);
|
XMEMCPY(des3->reg, iv, DES3_IVLEN);
|
||||||
des3->ivlen = DES3_IVLEN ;
|
|
||||||
} else {
|
} else {
|
||||||
for(i=0; i<DES_IVLEN; i++)
|
XMEMSET(des3->reg, 0x0, DES3_IVLEN) ;
|
||||||
des3->iv[i] = 0x0 ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif defined FREESCALE_MMCAU
|
#elif defined FREESCALE_MMCAU
|
||||||
|
@ -618,7 +685,7 @@ int Des3_SetKey(Des3* des3, const byte* key, const byte* iv, int dir)
|
||||||
|
|
||||||
#elif defined(CYASSL_PIC32MZ_CRYPT)
|
#elif defined(CYASSL_PIC32MZ_CRYPT)
|
||||||
|
|
||||||
#include "../../cyassl/ctaocrypt/port/pic32/pic32mz-crypt.h"
|
#include "cyassl/ctaocrypt/port/pic32/pic32mz-crypt.h"
|
||||||
|
|
||||||
void Des_SetIV(Des* des, const byte* iv);
|
void Des_SetIV(Des* des, const byte* iv);
|
||||||
int Des3_SetIV(Des3* des, const byte* iv);
|
int Des3_SetIV(Des3* des, const byte* iv);
|
||||||
|
|
|
@ -187,21 +187,23 @@ void Md5Final(Md5* md5, byte* hash)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef NO_SHA
|
#ifndef NO_SHA
|
||||||
void InitSha(Sha* sha)
|
int InitSha(Sha* sha)
|
||||||
{
|
{
|
||||||
CYASSL_ENTER("InitSha\n") ;
|
CYASSL_ENTER("InitSha\n") ;
|
||||||
XMEMSET((void *)sha, 0xcc, sizeof(Sha)) ;
|
XMEMSET((void *)sha, 0xcc, sizeof(Sha)) ;
|
||||||
XMEMSET((void *)KVA0_TO_KVA1(sha), 0xcc, sizeof(Sha)) ;
|
XMEMSET((void *)KVA0_TO_KVA1(sha), 0xcc, sizeof(Sha)) ;
|
||||||
reset_engine(&(sha->desc), PIC32_ALGO_SHA1) ;
|
reset_engine(&(sha->desc), PIC32_ALGO_SHA1) ;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaUpdate(Sha* sha, const byte* data, word32 len)
|
int ShaUpdate(Sha* sha, const byte* data, word32 len)
|
||||||
{
|
{
|
||||||
CYASSL_ENTER("ShaUpdate\n") ;
|
CYASSL_ENTER("ShaUpdate\n") ;
|
||||||
update_engine(&(sha->desc), data, len, sha->digest) ;
|
update_engine(&(sha->desc), data, len, sha->digest) ;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaFinal(Sha* sha, byte* hash)
|
int ShaFinal(Sha* sha, byte* hash)
|
||||||
{
|
{
|
||||||
CYASSL_ENTER("ShaFinal\n") ;
|
CYASSL_ENTER("ShaFinal\n") ;
|
||||||
start_engine(&(sha->desc)) ;
|
start_engine(&(sha->desc)) ;
|
||||||
|
@ -209,16 +211,18 @@ void ShaFinal(Sha* sha, byte* hash)
|
||||||
XMEMCPY(hash, sha->digest, SHA1_HASH_SIZE) ;
|
XMEMCPY(hash, sha->digest, SHA1_HASH_SIZE) ;
|
||||||
|
|
||||||
InitSha(sha); /* reset state */
|
InitSha(sha); /* reset state */
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
#endif /* NO_SHA */
|
#endif /* NO_SHA */
|
||||||
|
|
||||||
#ifndef NO_SHA256
|
#ifndef NO_SHA256
|
||||||
void InitSha256(Sha256* sha256)
|
int InitSha256(Sha256* sha256)
|
||||||
{
|
{
|
||||||
CYASSL_ENTER("InitSha256\n") ;
|
CYASSL_ENTER("InitSha256\n") ;
|
||||||
XMEMSET((void *)sha256, 0xcc, sizeof(Sha256)) ;
|
XMEMSET((void *)sha256, 0xcc, sizeof(Sha256)) ;
|
||||||
XMEMSET((void *)KVA0_TO_KVA1(sha256), 0xcc, sizeof(Sha256)) ;
|
XMEMSET((void *)KVA0_TO_KVA1(sha256), 0xcc, sizeof(Sha256)) ;
|
||||||
reset_engine(&(sha256->desc), PIC32_ALGO_SHA256) ;
|
reset_engine(&(sha256->desc), PIC32_ALGO_SHA256) ;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Sha256Update(Sha256* sha256, const byte* data, word32 len)
|
int Sha256Update(Sha256* sha256, const byte* data, word32 len)
|
||||||
|
|
|
@ -63,22 +63,12 @@ enum {
|
||||||
typedef struct Des {
|
typedef struct Des {
|
||||||
word32 reg[DES_BLOCK_SIZE / sizeof(word32)]; /* for CBC mode */
|
word32 reg[DES_BLOCK_SIZE / sizeof(word32)]; /* for CBC mode */
|
||||||
word32 tmp[DES_BLOCK_SIZE / sizeof(word32)]; /* same */
|
word32 tmp[DES_BLOCK_SIZE / sizeof(word32)]; /* same */
|
||||||
#ifdef HAVE_COLDFIRE_SEC
|
|
||||||
byte keylen ; /* for Coldfire SEC */
|
|
||||||
byte ivlen ; /* for Coldfire SEC */
|
|
||||||
byte iv[DES3_IVLEN]; /* for Coldfire SEC */
|
|
||||||
#endif
|
|
||||||
word32 key[DES_KS_SIZE];
|
word32 key[DES_KS_SIZE];
|
||||||
} Des;
|
} Des;
|
||||||
|
|
||||||
|
|
||||||
/* DES3 encryption and decryption */
|
/* DES3 encryption and decryption */
|
||||||
typedef struct Des3 {
|
typedef struct Des3 {
|
||||||
#ifdef HAVE_COLDFIRE_SEC
|
|
||||||
byte keylen ; /* for Coldfire SEC */
|
|
||||||
byte ivlen ; /* for Coldfire SEC */
|
|
||||||
byte iv[DES3_IVLEN]; /* for Coldfire SEC */
|
|
||||||
#endif
|
|
||||||
word32 key[3][DES_KS_SIZE];
|
word32 key[3][DES_KS_SIZE];
|
||||||
word32 reg[DES_BLOCK_SIZE / sizeof(word32)]; /* for CBC mode */
|
word32 reg[DES_BLOCK_SIZE / sizeof(word32)]; /* for CBC mode */
|
||||||
word32 tmp[DES_BLOCK_SIZE / sizeof(word32)]; /* same */
|
word32 tmp[DES_BLOCK_SIZE / sizeof(word32)]; /* same */
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
/* Config bits for PI32MZ, Starter Kit */
|
||||||
|
#pragma config FPLLIDIV = DIV_1 // System PLL Input Divider (1x Divider)
|
||||||
|
#pragma config FPLLRNG = RANGE_5_10_MHZ
|
||||||
|
#pragma config FPLLICLK = PLL_FRC // System PLL Input Clock Selection (FRC is input to the System PLL)
|
||||||
|
#pragma config FPLLMULT = MUL_50 // System PLL Multiplier (PLL Multiply by 50)
|
||||||
|
#pragma config FPLLODIV = DIV_2
|
||||||
|
// DEVCFG1
|
||||||
|
#pragma config FNOSC = SPLL // Oscillator Selection (System PLL)
|
||||||
|
|
||||||
|
#pragma config ICESEL = ICS_PGx2
|
||||||
|
/* ICE/ICD Comm Channel Select (Communicate on PGEC2/PGED2) */
|
|
@ -7,12 +7,12 @@ static void init_serial() {
|
||||||
SYSKEY = 0x00000000;
|
SYSKEY = 0x00000000;
|
||||||
SYSKEY = 0xAA996655;
|
SYSKEY = 0xAA996655;
|
||||||
SYSKEY = 0x556699AA;
|
SYSKEY = 0x556699AA;
|
||||||
PB2DIV = 0x00008018;
|
PB2DIV = 0x00008808;
|
||||||
SYSKEY = 0x33333333;
|
SYSKEY = 0x33333333;
|
||||||
|
|
||||||
/* UART2 Init */
|
/* UART2 Init */
|
||||||
// U2BRG = 0x0C;
|
// U2BRG = 0x0C;
|
||||||
U2BRG = 0x7;
|
U2BRG = 0x047;
|
||||||
ANSELBCLR = 0x4000;
|
ANSELBCLR = 0x4000;
|
||||||
ANSELGCLR = 0x0040;
|
ANSELGCLR = 0x0040;
|
||||||
RPB14R = 0x02;
|
RPB14R = 0x02;
|
||||||
|
|
|
@ -33,6 +33,8 @@ Included Project Files
|
||||||
3. CTaoCrypt Benchmark App (ctaocrypt_benchmark.X)
|
3. CTaoCrypt Benchmark App (ctaocrypt_benchmark.X)
|
||||||
|
|
||||||
This project builds the CTaoCrypt benchmark application.
|
This project builds the CTaoCrypt benchmark application.
|
||||||
|
For the benchmark timer, adjust CLOCK value under
|
||||||
|
"#elif defined MICROCHIP_PIC32" in ctaocrypt/benchmark/benchmark.c
|
||||||
|
|
||||||
PIC32MX/PIC32MZ
|
PIC32MX/PIC32MZ
|
||||||
---------------
|
---------------
|
||||||
|
|
|
@ -27,8 +27,9 @@
|
||||||
#if defined(CYASSL_MICROCHIP_PIC32MZ)
|
#if defined(CYASSL_MICROCHIP_PIC32MZ)
|
||||||
#define MICROCHIP_PIC32
|
#define MICROCHIP_PIC32
|
||||||
#include <xc.h>
|
#include <xc.h>
|
||||||
#pragma config ICESEL = ICS_PGx2
|
|
||||||
/* ICE/ICD Comm Channel Select (Communicate on PGEC2/PGED2) */
|
#include "MZ-configBits.h"
|
||||||
|
|
||||||
#include "PIC32MZ-serial.h"
|
#include "PIC32MZ-serial.h"
|
||||||
#define SYSTEMConfigPerformance /* void out SYSTEMConfigPerformance(); */
|
#define SYSTEMConfigPerformance /* void out SYSTEMConfigPerformance(); */
|
||||||
#else
|
#else
|
||||||
|
@ -67,10 +68,17 @@ int main(int argc, char** argv) {
|
||||||
volatile int i ;
|
volatile int i ;
|
||||||
int j ;
|
int j ;
|
||||||
|
|
||||||
|
PRECONbits.PFMWS = 2;
|
||||||
|
PRECONbits.PREFEN = 0b11;
|
||||||
|
|
||||||
init_serial() ; /* initialize PIC32MZ serial I/O */
|
init_serial() ; /* initialize PIC32MZ serial I/O */
|
||||||
SYSTEMConfigPerformance(80000000);
|
SYSTEMConfigPerformance(80000000);
|
||||||
DBINIT();
|
DBINIT();
|
||||||
|
|
||||||
|
for(j=0; j<100; j++) {
|
||||||
|
for(i=0; i<10000000; i++);
|
||||||
|
printf("time=%f\n", current_time(0)) ;
|
||||||
|
}
|
||||||
printf("wolfCrypt Benchmark:\n");
|
printf("wolfCrypt Benchmark:\n");
|
||||||
|
|
||||||
#ifndef NO_AES
|
#ifndef NO_AES
|
||||||
|
|
Loading…
Reference in New Issue