Merge branch 'master' into ti

This commit is contained in:
toddouska 2014-05-09 14:50:44 -07:00
commit 4c8d94023b
9 changed files with 316 additions and 202 deletions

View File

@ -1166,10 +1166,10 @@ void bench_eccKeyAgree(void)
#elif defined MICROCHIP_PIC32
#if defined(CYASSL_MICROCHIP_PIC32MZ)
#define CLOCK 8000000.0
#define CLOCK 80000000.0
#else
#include <peripheral/timer.h>
#define CLOCK 4000000.0
#define CLOCK 40000000.0
#endif
double current_time(int reset)

View File

@ -63,7 +63,7 @@
#if defined(CYASSL_PIC32MZ_CRYPT)
#include "../../cyassl/ctaocrypt/port/pic32/pic32mz-crypt.h"
#include "cyassl/ctaocrypt/port/pic32/pic32mz-crypt.h"
#define DEBUG_CYASSL
/* core hardware crypt engine driver */
@ -148,14 +148,14 @@
(cryptoalgo == PIC32_CRYPTOALGO_RCBC)) {
/* set iv for the next call */
if(dir == PIC32_ENCRYPTION) {
XMEMCPY((void *)aes->iv_ce,
XMEMCPY((void *)aes->iv_ce,
(void*)KVA0_TO_KVA1(out + sz - AES_BLOCK_SIZE),
AES_BLOCK_SIZE) ;
} else {
} else {
ByteReverseWords((word32*)aes->iv_ce,
(word32 *)KVA0_TO_KVA1(in + sz - AES_BLOCK_SIZE),
AES_BLOCK_SIZE);
}
}
}
XMEMCPY((byte *)out, (byte *)KVA0_TO_KVA1(out), sz) ;
ByteReverseWords((word32*)out, (word32 *)out, sz);
@ -165,12 +165,14 @@
{
AesCrypt(aes, out, in, sz, PIC32_ENCRYPTION, PIC32_ALGO_AES,
PIC32_CRYPTOALGO_RCBC );
return 0 ;
}
int AesCbcDecrypt(Aes* aes, byte* out, const byte* in, word32 sz)
{
AesCrypt(aes, out, in, sz, PIC32_DECRYPTION, PIC32_ALGO_AES,
PIC32_CRYPTOALGO_RCBC);
return 0 ;
}
#if defined(CYASSL_AES_COUNTER)
@ -603,124 +605,153 @@
#endif /* CYASSL_AES_COUNTER */
#elif defined(HAVE_COLDFIRE_SEC)
#elif defined(HAVE_COLDFIRE_SEC)
#include <cyassl/ctaocrypt/types.h>
#include "sec.h"
#include "mcf548x_sec.h"
#include "mcf548x_siu.h"
#include "mcf5475_sec.h"
#include "mcf5475_siu.h"
#if defined (HAVE_THREADX)
#include "memory_pools.h"
extern TX_BYTE_POOL mp_ncached; /* Non Cached memory pool */
#define AES_BUFFER_SIZE (AES_BLOCK_SIZE * 8)
static unsigned char *AESBuffer = NULL ;
#endif
#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_DECRYPT 0x60200010
#define AES_BLOCK_LENGTH 16
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)
{
return(AesCbcCrypt(aes, po, pi, sz, SEC_DESC_AES_CBC_ENCRYPT)) ;
return(AesCbcCrypt(aes, po, pi, sz, SEC_DESC_AES_CBC_ENCRYPT)) ;
}
int AesCbcDecrypt(Aes* aes, byte* po, const byte* pi, word32 sz)
{
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 */
return(AesCbcCrypt(aes, po, pi, sz, SEC_DESC_AES_CBC_DECRYPT)) ;
}
int AesSetKey(Aes* aes, const byte* userKey, word32 keylen, const byte* iv,
int dir)
{
int status ;
if(AESBuffer == NULL) {
status = tx_byte_allocate(&mp_ncached,(void *)&AESBuffer, AES_BUFFER_SIZE,TX_NO_WAIT);
}
if(AESBuffIn == 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 *)&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)))
return BAD_FUNC_ARG;
@ -732,6 +763,7 @@ int AesSetKey(Aes* aes, const byte* userKey, word32 keylen, const byte* iv,
XMEMCPY(aes->key, userKey, keylen);
if (iv)
XMEMCPY(aes->reg, iv, AES_BLOCK_SIZE);
return 0;
}
@ -2724,7 +2756,7 @@ static void GMULT(word64* X, word64* Y)
{
word64 Z[2] = {0,0};
word64 V[2] ;
int i, j;
int i, j;
V[0] = X[0] ; V[1] = X[1] ;
for (i = 0; i < 2; i++)
@ -2825,7 +2857,7 @@ static void GHASH(Aes* aes, const byte* a, word32 aSz,
/* Hash in the lengths in bits of A and C */
{
word64 len[2] ;
len[0] = aSz ; len[1] = cSz;
len[0] = aSz ; len[1] = cSz;
/* Lengths are in bytes. Convert to bits. */
len[0] *= 8;
@ -2851,7 +2883,7 @@ static void GMULT(word32* X, word32* Y)
int i, j;
V[0] = X[0]; V[1] = X[1]; V[2] = X[2]; V[3] = X[3];
for (i = 0; i < 4; i++)
{
word32 y = Y[i];

View File

@ -273,32 +273,72 @@
return 0;
}
#elif defined(HAVE_COLDFIRE_SEC)
#elif defined(HAVE_COLDFIRE_SEC)
#include <cyassl/ctaocrypt/types.h>
#include "sec.h"
#include "mcf548x_sec.h"
#include "mcf5475_sec.h"
#include "mcf5475_siu.h"
#if defined (HAVE_THREADX)
#include "memory_pools.h"
extern TX_BYTE_POOL mp_ncached; /* Non Cached memory pool */
#define DES_BUFFER_SIZE (DES_BLOCK_SIZE * 16)
static unsigned char *DesBuffer = NULL ;
#endif
#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_DECRYPT 0x20400010
#define SEC_DESC_DES3_CBC_ENCRYPT 0x20700010
#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[];
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 } ;
int ret ; int stat1,stat2 ;
int i ; int size ;
#ifdef DEBUG_CYASSL
int ret ; int stat1,stat2 ;
#endif
int size ;
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) {
XMEMCPY(secIV, iv, secDesc->length2) ;
if((sz%DES_BUFFER_SIZE) == sz) {
size = sz ;
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 ;
}
descriptor.header = desc ;
/*
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 ;
*/
XMEMCPY(desBuffIn, in, size) ;
XMEMCPY(secKey, key, secDesc->length3) ;
/* 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 */
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 */
while (!(MCF_SEC_SISRL) && !(MCF_SEC_SISRH))
;
for(v=0; v<500; v++) ;
v=0 ;
while((secDesc->header>> 24) != 0xff) {
if(v++ > 1000)break ;
}
#ifdef DEBUG_CYASSL
ret = MCF_SEC_SISRH;
stat1 = MCF_SEC_DSR ;
stat2 = MCF_SEC_DISR ;
if(ret & 0xe0000000)
db_printf("Des_Cbc(%x):ISRH=%08x, DSR=%08x, DISR=%08x\n", desc, ret, stat1, stat2) ;
XMEMCPY(out, DesBuffer, size) ;
stat1 = MCF_SEC_DSR ;
stat2 = MCF_SEC_DISR ;
if(ret & 0xe0000000) {
/* db_printf("Des_Cbc(%x):ISRH=%08x, DSR=%08x, DISR=%08x\n", desc, ret, stat1, stat2) ; */
}
#endif
XMEMCPY(out, desBuffOut, size) ;
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 {
XMEMCPY((void*)des->iv, (void*)&(in[size-DES_IVLEN]), DES_IVLEN) ;
XMEMCPY((void*)iv, (void*)&(in[size-secDesc->length2]), secDesc->length2) ;
}
in += size ;
out += size ;
}
UnLockMutex(&Mutex_DesSEC) ;
}
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)
{
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)
{
Des_Cbc((Des *)des3, out, in, sz, SEC_DESC_DES3_CBC_ENCRYPT) ;
return 0;
Des_Cbc(out, in, sz, (byte *)des3->key, (byte *)des3->reg, SEC_DESC_DES3_CBC_ENCRYPT) ;
return 0;
}
int Des3_CbcDecrypt(Des3* des3, byte* out, const byte* in, word32 sz)
{
Des_Cbc((Des *)des3, out, in, sz, SEC_DESC_DES3_CBC_DECRYPT) ;
return 0;
Des_Cbc(out, in, sz, (byte *)des3->key, (byte *)des3->reg, SEC_DESC_DES3_CBC_DECRYPT) ;
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 i ; int status ;
if(DesBuffer == NULL) {
status = tx_byte_allocate(&mp_ncached,(void *)&DesBuffer,DES_BUFFER_SIZE,TX_NO_WAIT);
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
InitMutex(&Mutex_DesSEC) ;
}
XMEMCPY(des->key, key, DES_KEYLEN);
des->keylen = DES_KEYLEN ;
des->ivlen = 0 ;
XMEMCPY(des->key, key, DES_KEYLEN);
setParity((byte *)des->key, DES_KEYLEN) ;
if (iv) {
XMEMCPY(des->iv, iv, DES_IVLEN);
des->ivlen = DES_IVLEN ;
XMEMCPY(des->reg, iv, DES_IVLEN);
} else {
for(i=0; i<DES_IVLEN; i++)
des->iv[i] = 0x0 ;
XMEMSET(des->reg, 0x0, DES_IVLEN) ;
}
return 0;
return 0;
}
int Des3_SetKey(Des3* des3, const byte* key, const byte* iv, int dir)
{
int i ; int status ;
if(DesBuffer == NULL) {
status = tx_byte_allocate(&mp_ncached,(void *)&DesBuffer,DES_BUFFER_SIZE,TX_NO_WAIT);
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);
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);
des3->keylen = DES3_KEYLEN ;
des3->ivlen = 0 ;
XMEMCPY(des3->key[0], key, DES3_KEYLEN);
setParity((byte *)des3->key[0], DES3_KEYLEN) ;
if (iv) {
XMEMCPY(des3->iv, iv, DES3_IVLEN);
des3->ivlen = DES3_IVLEN ;
XMEMCPY(des3->reg, iv, DES3_IVLEN);
} else {
for(i=0; i<DES_IVLEN; i++)
des3->iv[i] = 0x0 ;
XMEMSET(des3->reg, 0x0, DES3_IVLEN) ;
}
return 0;
}
#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)
#include "../../cyassl/ctaocrypt/port/pic32/pic32mz-crypt.h"
#include "cyassl/ctaocrypt/port/pic32/pic32mz-crypt.h"
void Des_SetIV(Des* des, const byte* iv);
int Des3_SetIV(Des3* des, const byte* iv);

View File

@ -187,21 +187,23 @@ void Md5Final(Md5* md5, byte* hash)
#endif
#ifndef NO_SHA
void InitSha(Sha* sha)
int InitSha(Sha* sha)
{
CYASSL_ENTER("InitSha\n") ;
XMEMSET((void *)sha, 0xcc, sizeof(Sha)) ;
XMEMSET((void *)KVA0_TO_KVA1(sha), 0xcc, sizeof(Sha)) ;
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") ;
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") ;
start_engine(&(sha->desc)) ;
@ -209,16 +211,18 @@ void ShaFinal(Sha* sha, byte* hash)
XMEMCPY(hash, sha->digest, SHA1_HASH_SIZE) ;
InitSha(sha); /* reset state */
return 0;
}
#endif /* NO_SHA */
#ifndef NO_SHA256
void InitSha256(Sha256* sha256)
int InitSha256(Sha256* sha256)
{
CYASSL_ENTER("InitSha256\n") ;
XMEMSET((void *)sha256, 0xcc, sizeof(Sha256)) ;
XMEMSET((void *)KVA0_TO_KVA1(sha256), 0xcc, sizeof(Sha256)) ;
reset_engine(&(sha256->desc), PIC32_ALGO_SHA256) ;
return 0;
}
int Sha256Update(Sha256* sha256, const byte* data, word32 len)

View File

@ -63,22 +63,12 @@ enum {
typedef struct Des {
word32 reg[DES_BLOCK_SIZE / sizeof(word32)]; /* for CBC mode */
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];
} Des;
/* DES3 encryption and decryption */
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 reg[DES_BLOCK_SIZE / sizeof(word32)]; /* for CBC mode */
word32 tmp[DES_BLOCK_SIZE / sizeof(word32)]; /* same */

11
mplabx/MZ-configBits.h Normal file
View File

@ -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) */

View File

@ -7,12 +7,12 @@ static void init_serial() {
SYSKEY = 0x00000000;
SYSKEY = 0xAA996655;
SYSKEY = 0x556699AA;
PB2DIV = 0x00008018;
PB2DIV = 0x00008808;
SYSKEY = 0x33333333;
/* UART2 Init */
// U2BRG = 0x0C;
U2BRG = 0x7;
U2BRG = 0x047;
ANSELBCLR = 0x4000;
ANSELGCLR = 0x0040;
RPB14R = 0x02;

View File

@ -33,6 +33,8 @@ Included Project Files
3. CTaoCrypt Benchmark App (ctaocrypt_benchmark.X)
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
---------------

View File

@ -27,8 +27,9 @@
#if defined(CYASSL_MICROCHIP_PIC32MZ)
#define MICROCHIP_PIC32
#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"
#define SYSTEMConfigPerformance /* void out SYSTEMConfigPerformance(); */
#else
@ -66,11 +67,18 @@ void bench_eccKeyAgree(void);
int main(int argc, char** argv) {
volatile int i ;
int j ;
PRECONbits.PFMWS = 2;
PRECONbits.PREFEN = 0b11;
init_serial() ; /* initialize PIC32MZ serial I/O */
SYSTEMConfigPerformance(80000000);
DBINIT();
for(j=0; j<100; j++) {
for(i=0; i<10000000; i++);
printf("time=%f\n", current_time(0)) ;
}
printf("wolfCrypt Benchmark:\n");
#ifndef NO_AES