forked from wolfSSL/wolfssl
For MDK5
This commit is contained in:
@@ -263,156 +263,6 @@
|
||||
Des3Crypt(des, out, in, sz, DES_DECRYPTION);
|
||||
}
|
||||
|
||||
|
||||
#elif defined(HAVE_COLDFIRE_SEC)
|
||||
|
||||
#include "sec.h"
|
||||
#include "mcf548x_sec.h"
|
||||
|
||||
#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 ;
|
||||
|
||||
#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
|
||||
|
||||
extern volatile unsigned char __MBAR[];
|
||||
|
||||
static void Des_Cbc(Des* des, byte* out, const byte* in, word32 sz, word32 desc)
|
||||
{
|
||||
static volatile SECdescriptorType descriptor = { NULL } ;
|
||||
int ret ; int stat1,stat2 ;
|
||||
int i ; int size ;
|
||||
volatile int v ;
|
||||
|
||||
while(sz) {
|
||||
if((sz%DES_BUFFER_SIZE) == sz) {
|
||||
size = sz ;
|
||||
sz = 0 ;
|
||||
} else {
|
||||
size = DES_BUFFER_SIZE ;
|
||||
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 ;
|
||||
*/
|
||||
|
||||
/* Initialize SEC and wait for encryption to complete */
|
||||
MCF_SEC_CCCR0 = 0x0000001A; //enable channel done notification
|
||||
|
||||
/* Point SEC to the location of the descriptor */
|
||||
MCF_SEC_FR0 = (uint32)&descriptor;
|
||||
|
||||
/* poll SISR to determine when channel is complete */
|
||||
while (!(MCF_SEC_SISRL) && !(MCF_SEC_SISRH))
|
||||
;
|
||||
|
||||
for(v=0; v<500; v++) ;
|
||||
|
||||
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) ;
|
||||
|
||||
if((desc==SEC_DESC_DES3_CBC_ENCRYPT)||(desc==SEC_DESC_DES_CBC_ENCRYPT)) {
|
||||
XMEMCPY((void*)des->iv, (void*)&(out[size-DES_IVLEN]), DES_IVLEN) ;
|
||||
} else {
|
||||
XMEMCPY((void*)des->iv, (void*)&(in[size-DES_IVLEN]), DES_IVLEN) ;
|
||||
}
|
||||
|
||||
in += size ;
|
||||
out += size ;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Des_CbcEncrypt(Des* des, byte* out, const byte* in, word32 sz)
|
||||
{
|
||||
Des_Cbc(des, out, in, sz, 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) ;
|
||||
}
|
||||
|
||||
void Des3_CbcEncrypt(Des3* des3, byte* out, const byte* in, word32 sz)
|
||||
{
|
||||
Des_Cbc((Des *)des3, out, in, sz, SEC_DESC_DES3_CBC_ENCRYPT) ;
|
||||
}
|
||||
|
||||
void Des3_CbcDecrypt(Des3* des3, byte* out, const byte* in, word32 sz)
|
||||
{
|
||||
Des_Cbc((Des *)des3, out, in, sz, SEC_DESC_DES3_CBC_DECRYPT) ;
|
||||
}
|
||||
|
||||
|
||||
void 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);
|
||||
}
|
||||
|
||||
XMEMCPY(des->key, key, DES_KEYLEN);
|
||||
des->keylen = 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 ;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void 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);
|
||||
}
|
||||
|
||||
XMEMCPY(des3->key, key, DES3_KEYLEN);
|
||||
des3->keylen = DES3_KEYLEN ;
|
||||
des3->ivlen = 0 ;
|
||||
if (iv) {
|
||||
XMEMCPY(des3->iv, iv, DES3_IVLEN);
|
||||
des3->ivlen = DES3_IVLEN ;
|
||||
} else {
|
||||
for(i=0; i<DES_IVLEN; i++)
|
||||
des3->iv[i] = 0x0 ;
|
||||
}
|
||||
}
|
||||
|
||||
#else /* CTaoCrypt software implementation */
|
||||
|
||||
/* permuted choice table (key) */
|
||||
|
||||
@@ -179,28 +179,6 @@ mp_count_bits (mp_int * a)
|
||||
}
|
||||
|
||||
|
||||
int mp_leading_bit (mp_int * a)
|
||||
{
|
||||
int bit = 0;
|
||||
mp_int t;
|
||||
|
||||
if (mp_init_copy(&t, a) != MP_OKAY)
|
||||
return 0;
|
||||
|
||||
while (mp_iszero(&t) == 0) {
|
||||
#ifndef MP_8BIT
|
||||
bit = (t.dp[0] & 0x80) != 0;
|
||||
#else
|
||||
bit = (t.dp[0] | ((t.dp[1] & 0x01) << 7)) & 0x80 != 0;
|
||||
#endif
|
||||
if (mp_div_2d (&t, 8, &t, NULL) != MP_OKAY)
|
||||
break;
|
||||
}
|
||||
mp_clear(&t);
|
||||
return bit;
|
||||
}
|
||||
|
||||
|
||||
/* store in unsigned [big endian] format */
|
||||
int mp_to_unsigned_bin (mp_int * a, unsigned char *b)
|
||||
{
|
||||
@@ -3765,7 +3743,7 @@ int mp_sqrmod (mp_int * a, mp_int * b, mp_int * c)
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(HAVE_ECC) || !defined(NO_PWDBASED) || defined(CYASSL_SNIFFER)
|
||||
#if defined(HAVE_ECC) || !defined(NO_PWDBASED)
|
||||
|
||||
/* single digit addition */
|
||||
int mp_add_d (mp_int* a, mp_digit b, mp_int* c)
|
||||
|
||||
Reference in New Issue
Block a user