pull in Kojo MDK-ARM projects, changes

This commit is contained in:
toddouska
2013-05-16 09:47:27 -07:00
parent 05f11c4bca
commit cfdfa7b2b3
35 changed files with 7332 additions and 180 deletions

View File

@@ -59,7 +59,8 @@
* document (See note in README).
*/
#include "stm32f2xx.h"
#include "stm32f2xx_cryp.h"
int AesSetKey(Aes* aes, const byte* userKey, word32 keylen, const byte* iv,
int dir)
{
@@ -2212,8 +2213,9 @@ static void GHASH(Aes* aes, const byte* a, word32 aSz,
static void GMULT(word64* X, word64* Y)
{
word64 Z[2] = {0,0};
word64 V[2] = {X[0], X[1]};
int i, j;
word64 V[2] ;
int i, j;
V[0] = X[0] ; V[1] = X[1] ;
for (i = 0; i < 2; i++)
{
@@ -2312,7 +2314,8 @@ static void GHASH(Aes* aes, const byte* a, word32 aSz,
/* Hash in the lengths in bits of A and C */
{
word64 len[2] = {aSz, cSz};
word64 len[2] ;
len[0] = aSz ; len[1] = cSz;
/* Lengths are in bytes. Convert to bits. */
len[0] *= 8;
@@ -2334,9 +2337,11 @@ static void GHASH(Aes* aes, const byte* a, word32 aSz,
static void GMULT(word32* X, word32* Y)
{
word32 Z[4] = {0,0,0,0};
word32 V[4] = {X[0], X[1], X[2], X[3]};
word32 V[4] ;
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];
@@ -2717,7 +2722,7 @@ int AesCcmDecrypt(Aes* aes, byte* out, const byte* in, word32 inSz,
byte A[AES_BLOCK_SIZE];
byte B[AES_BLOCK_SIZE];
byte* o;
word32 i, lenSz, oSz, result = 0;
word32 i, lenSz, oSz; int result = 0;
o = out;
oSz = inSz;

View File

@@ -44,8 +44,10 @@
#include <cyassl/ctaocrypt/sha256.h>
#include <cyassl/ctaocrypt/sha512.h>
#include <cyassl/ctaocrypt/logging.h>
#include <cyassl/ctaocrypt/random.h>
#ifndef NO_RC4
#include <cyassl/ctaocrypt/arc4.h>
#endif
@@ -98,6 +100,15 @@
#define XTIME(t1) pic32_time((t1))
#define XGMTIME(c) gmtime((c))
#define XVALIDATE_DATE(d, f, t) ValidateDate((d), (f), (t))
#elif defined(CYASSL_MDK_ARM)
#include <rtl.h>
#undef RNG
#include "cyassl_MDK_ARM.h"
#undef RNG
#define RNG CyaSSL_RNG /*for avoiding name conflict in "stm32f2xx.h" */
#define XTIME(tl) (0)
#define XGMTIME(c) Cyassl_MDK_gmtime((c))
#define XVALIDATE_DATE(d, f, t) ValidateDate((d), (f), (t))
#elif defined(USER_TIME)
/* user time, and gmtime compatible functions, there is a gmtime
implementation here that WINCE uses, so really just need some ticks
@@ -129,7 +140,7 @@
#else
/* default */
/* uses complete <time.h> facility */
#include <time.h>
#include <time.h>
#define XTIME(tl) time((tl))
#define XGMTIME(c) gmtime((c))
#define XVALIDATE_DATE(d, f, t) ValidateDate((d), (f), (t))
@@ -462,7 +473,8 @@ static int GetShortInt(const byte* input, word32* inOutIdx, int* number)
return *number;
}
#endif
#endif /* !NO_PWDBASED */
/* May not have one, not an error */
static int GetExplicitVersion(const byte* input, word32* inOutIdx, int* version)
@@ -1377,7 +1389,7 @@ static int GetKey(DecodedCert* cert)
return StoreRsaKey(cert);
}
break;
#endif /* NO_RSA */
#ifdef HAVE_NTRU
case NTRUk:
@@ -1782,8 +1794,8 @@ int ValidateDate(const byte* date, byte format, int dateType)
GetTime(&certTime.tm_hour, date, &i);
GetTime(&certTime.tm_min, date, &i);
GetTime(&certTime.tm_sec, date, &i);
if (date[i] != 'Z') { /* only Zulu supported for this profile */
if (date[i] != 'Z') { /* only Zulu supported for this profile */
CYASSL_MSG("Only Zulu time supported for this profile");
return 0;
}
@@ -2307,7 +2319,7 @@ static int ConfirmSignature(const byte* buf, word32 bufSz,
FreeRsaKey(&pubKey);
return ret;
}
break;
#endif /* NO_RSA */
#ifdef HAVE_ECC
case ECDSAk:
@@ -3396,28 +3408,28 @@ static const char* GetOneName(CertName* name, int idx)
switch (idx) {
case 0:
return name->country;
break;
case 1:
return name->state;
break;
case 2:
return name->locality;
break;
case 3:
return name->sur;
break;
case 4:
return name->org;
break;
case 5:
return name->unit;
break;
case 6:
return name->commonName;
break;
case 7:
return name->email;
break;
default:
return 0;
}
@@ -3430,29 +3442,29 @@ static byte GetNameId(int idx)
switch (idx) {
case 0:
return ASN_COUNTRY_NAME;
break;
case 1:
return ASN_STATE_NAME;
break;
case 2:
return ASN_LOCALITY_NAME;
break;
case 3:
return ASN_SUR_NAME;
break;
case 4:
return ASN_ORG_NAME;
break;
case 5:
return ASN_ORGUNIT_NAME;
break;
case 6:
return ASN_COMMON_NAME;
break;
case 7:
/* email uses different id type */
return 0;
break;
default:
return 0;
}
@@ -3602,10 +3614,14 @@ static int SetName(byte* output, CertName* name)
return totalBytes;
}
/* encode info from cert into DER enocder format */
static int EncodeCert(Cert* cert, DerCert* der, RsaKey* rsaKey, RNG* rng,
const byte* ntruKey, word16 ntruSz)
static int EncodeCert(
Cert* cert,
DerCert* der,
RsaKey* rsaKey,
RNG* rng,
const byte* ntruKey,
word16 ntruSz)
{
(void)ntruKey;
(void)ntruSz;
@@ -5305,5 +5321,5 @@ int ParseCRL(DecodedCRL* dcrl, const byte* buff, word32 sz, void* cm)
}
#endif /* HAVE_CRL */
#endif

View File

@@ -51,6 +51,7 @@
* Peripheral Library document (See note in README).
*/
#include "stm32f2xx.h"
#include "stm32f2xx_cryp.h"
void Des_SetKey(Des* des, const byte* key, const byte* iv, int dir)
{

View File

@@ -32,6 +32,7 @@
#include <cyassl/ctaocrypt/logging.h>
#ifdef NO_INLINE
#include <cyassl/ctaocrypt/hc128.h>
#include <cyassl/ctaocrypt/misc.h>
#else
#include <ctaocrypt/src/misc.c>
#endif

View File

@@ -38,7 +38,6 @@
word32 length);
#endif
static int InitHmac(Hmac* hmac, int type)
{
hmac->innerHashKeyed = 0;

View File

@@ -111,6 +111,10 @@ static void cyassl_log(const int logLevel, const char *const logMessage)
#if (NET_SECURE_MGR_CFG_EN == DEF_ENABLED)
NetSecure_TraceOut((CPU_CHAR *)logMessage);
#endif
#elif defined(CYASSL_MDK_ARM)
fflush(stdout) ;
printf("%s\n", logMessage);
fflush(stdout) ;
#else
fprintf(stderr, "%s\n", logMessage);
#endif

View File

@@ -53,6 +53,7 @@
* md5->loLen = num bytes that have been written to STM32 FIFO
*/
XMEMSET(md5->buffer, 0, MD5_REG_SIZE);
md5->buffLen = 0;
md5->loLen = 0;

View File

@@ -25,13 +25,19 @@
#include <cyassl/ctaocrypt/settings.h>
/* submitted by eof */
#ifdef USE_CYASSL_MEMORY
#include <cyassl/ctaocrypt/memory.h>
#include <cyassl/ctaocrypt/error.h>
#ifdef CYASSL_MALLOC_CHECK
#include <stdio.h>
static void err_sys(const char* msg)
{
printf("error = %s\n", msg);
return;
}
#endif
/* Set these to default values initially. */
static CyaSSL_Malloc_cb malloc_function = 0;
@@ -71,7 +77,11 @@ void* CyaSSL_Malloc(size_t size)
res = malloc_function(size);
else
res = malloc(size);
#ifdef CYASSL_MALLOC_CHECK
if(res == NULL)
err_sys("CyaSSL_malloc") ;
#endif
return res;
}

View File

@@ -172,7 +172,5 @@ STATIC INLINE void xorbuf(byte* buf, const byte* mask, word32 count)
for (i = 0; i < count; i++) buf[i] ^= mask[i];
}
}
#undef STATIC

View File

@@ -31,9 +31,10 @@
#include <cyassl/ctaocrypt/hmac.h>
#include <cyassl/ctaocrypt/integer.h>
#include <cyassl/ctaocrypt/error.h>
#ifdef CYASSL_SHA512
#if defined(CYASSL_SHA512) || defined(CYASSL_SHA384)
#include <cyassl/ctaocrypt/sha512.h>
#endif
#ifdef NO_INLINE
#include <cyassl/ctaocrypt/misc.h>
#else

View File

@@ -50,8 +50,8 @@
#include <windows.h>
#include <wincrypt.h>
#else
#ifndef NO_DEV_RANDOM
#include <fcntl.h>
#if !defined(NO_DEV_RANDOM) && !defined(CYASSL_MDK_ARM)
#include <fcntl.h>
#ifndef EBSNET
#include <unistd.h>
#endif
@@ -541,8 +541,9 @@ int GenerateSeed(OS_Seed* os, byte* output, word32 sz)
#endif /* FREESCALE_K70_RNGA */
#elif defined(STM32F2_RNG)
#undef RNG
#include "stm32f2xx_rng.h"
#include "stm32f2xx_rcc.h"
/*
* Generate a RNG seed using the hardware random number generator
* on the STM32F2. Documentation located in STM32F2xx Standard Peripheral
@@ -571,8 +572,13 @@ int GenerateSeed(OS_Seed* os, byte* output, word32 sz)
#elif defined(NO_DEV_RANDOM)
#warning "you need to write an os specific GenerateSeed() here"
#error "you need to write an os specific GenerateSeed() here"
/*
int GenerateSeed(OS_Seed* os, byte* output, word32 sz)
{
return 0;
}
*/
#else /* !USE_WINDOWS_API && !THREADX && !MICRIUM && !NO_DEV_RANDOM */

View File

@@ -43,7 +43,8 @@
* document (See note in README).
*/
#include "stm32f2xx.h"
#include "stm32f2xx_hash.h"
void InitSha(Sha* sha)
{
/* STM32F2 struct notes: