From 5d29bf1e49037875f73cd6835216b54aec74b154 Mon Sep 17 00:00:00 2001 From: Chris Conlon Date: Wed, 30 Jan 2013 18:02:18 -0700 Subject: [PATCH] add MPLAB X projects, PIC32 GenerateSeed() --- Makefile.am | 3 + ctaocrypt/src/random.c | 19 +++ cyassl/ctaocrypt/settings.h | 9 +- mplabx/README | 37 ++++++ mplabx/ctaocrypt_benchmark.X/main.c | 116 ++++++++++++++++++ .../nbproject/include.am | 12 ++ .../nbproject/project.xml | 18 +++ mplabx/ctaocrypt_test.X/main.c | 57 +++++++++ mplabx/ctaocrypt_test.X/nbproject/include.am | 12 ++ mplabx/ctaocrypt_test.X/nbproject/project.xml | 18 +++ mplabx/cyassl.X/nbproject/include.am | 12 ++ mplabx/cyassl.X/nbproject/project.xml | 16 +++ 12 files changed, 327 insertions(+), 2 deletions(-) create mode 100644 mplabx/README create mode 100644 mplabx/ctaocrypt_benchmark.X/main.c create mode 100644 mplabx/ctaocrypt_benchmark.X/nbproject/include.am create mode 100644 mplabx/ctaocrypt_benchmark.X/nbproject/project.xml create mode 100644 mplabx/ctaocrypt_test.X/main.c create mode 100644 mplabx/ctaocrypt_test.X/nbproject/include.am create mode 100644 mplabx/ctaocrypt_test.X/nbproject/project.xml create mode 100644 mplabx/cyassl.X/nbproject/include.am create mode 100644 mplabx/cyassl.X/nbproject/project.xml diff --git a/Makefile.am b/Makefile.am index f197d3a47..69d390cf0 100644 --- a/Makefile.am +++ b/Makefile.am @@ -55,6 +55,9 @@ include testsuite/include.am include tests/include.am include sslSniffer/sslSnifferTest/include.am include rpm/include.am +include mplabx/ctaocrypt_benchmark.X/nbproject/include.am +include mplabx/ctaocrypt_test.X/nbproject/include.am +include mplabx/cyassl.X/nbproject/include.am if USE_VALGRIND TESTS_ENVIRONMENT=./valgrind-error.sh diff --git a/ctaocrypt/src/random.c b/ctaocrypt/src/random.c index e1247d16a..e8217034b 100644 --- a/ctaocrypt/src/random.c +++ b/ctaocrypt/src/random.c @@ -455,6 +455,25 @@ int GenerateSeed(OS_Seed* os, byte* output, word32 sz) return 0; } +#elif defined(MICROCHIP_PIC32) + +#include + +/* uses the core timer, in nanoseconds to seed srand */ +int GenerateSeed(OS_Seed* os, byte* output, word32 sz) +{ + int i; + srand(ReadCoreTimer() * 25); + + for (i = 0; i < sz; i++ ) { + output[i] = rand() % 256; + if ( (i % 8) == 7) + srand(ReadCoreTimer() * 25); + } + + return 0; +} + #elif defined(CYASSL_SAFERTOS) || defined(CYASSL_LEANPSK) #warning "write a real random seed!!!!, just for testing now" diff --git a/cyassl/ctaocrypt/settings.h b/cyassl/ctaocrypt/settings.h index 2890ebd18..63888df6a 100644 --- a/cyassl/ctaocrypt/settings.h +++ b/cyassl/ctaocrypt/settings.h @@ -88,9 +88,14 @@ #endif #ifdef MICROCHIP_PIC32 - /* use MBED plus no filesystem */ - #define MBED + #define SIZEOF_LONG_LONG 8 + #define SINGLE_THREADED + #define CYASSL_USER_IO + #define NO_WRITEV + #define NO_DEV_RANDOM #define NO_FILESYSTEM + #define USE_FAST_MATH + #define TFM_TIMING_RESISTANT #endif #ifdef MBED diff --git a/mplabx/README b/mplabx/README new file mode 100644 index 000000000..c0d10f3d0 --- /dev/null +++ b/mplabx/README @@ -0,0 +1,37 @@ +CyaSSL MPLAB X Project Files + +This directory contains project files for the Microchip MPLAB X IDE. These +projects have been set up to use the Microchip PIC32 Ethernet Starter Kit +and the Microchip XC32 compiler. + +In order to generate the necessary auto-generated MPLAB X files, make sure +to import the cyassl.X project into your MPLAB X workspace before trying to +build either the CTaoCrypt test or benchmark applications. + +Included Project Files +----------------------- + +1. CyaSSL library (cyassl.X) + + This project build a static CyaSSL library. Prior to building this + project, uncomment the MICROCHIP_PIC32 define located in: + + /cyassl/ctaocrypt/settings.h + + After this project has been built, the compiled library will be located + at: + + /mplabx/cyassl.X/dist/default/production/cyassl.X.a + +2. CTaoCrypt Test App (ctaocrypt_test.X) + +3. CTaoCrypt Benchmark App (ctaocrypt_benchmark.X) + + +MIPS16 and MIPS32 Support +------------------------- + +These projects support both MIPS16 and MIPS32 instruction sets. Switching +between these two instruction sets can be done in each project's properties +settings by checking the "Generate 16-bit code" checkbox. + diff --git a/mplabx/ctaocrypt_benchmark.X/main.c b/mplabx/ctaocrypt_benchmark.X/main.c new file mode 100644 index 000000000..b2bcf39dc --- /dev/null +++ b/mplabx/ctaocrypt_benchmark.X/main.c @@ -0,0 +1,116 @@ +/* main.c + * + * Copyright (C) 2006-2012 Sawtooth Consulting Ltd. + * + * This file is part of CyaSSL. + * + * CyaSSL is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * CyaSSL is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#define PIC32_STARTER_KIT + +#include +#include +#include + +void bench_des(void); +void bench_arc4(void); +void bench_hc128(void); +void bench_rabbit(void); +void bench_aes(int); +void bench_aesgcm(void); + +void bench_md5(void); +void bench_sha(void); +void bench_sha256(void); +void bench_sha512(void); +void bench_ripemd(void); + +void bench_rsa(void); +void bench_rsaKeyGen(void); +void bench_dh(void); +#ifdef HAVE_ECC +void bench_eccKeyGen(void); +void bench_eccKeyAgree(void); +#endif + +/* + * Main driver for CTaoCrypt benchmarks. + */ +int main(int argc, char** argv) { + + SYSTEMConfigPerformance(80000000); + + DBINIT(); + printf("CTaoCrypt Benchmark:\n"); + +#ifndef NO_AES + bench_aes(0); + bench_aes(1); +#endif +#ifdef HAVE_AESGCM + bench_aesgcm(); +#endif +#ifndef NO_RC4 + bench_arc4(); +#endif +#ifdef HAVE_HC128 + bench_hc128(); +#endif +#ifndef NO_RABBIT + bench_rabbit(); +#endif +#ifndef NO_DES3 + bench_des(); +#endif + + printf("\n"); + +#ifndef NO_MD5 + bench_md5(); +#endif + bench_sha(); +#ifndef NO_SHA256 + bench_sha256(); +#endif +#ifdef CYASSL_SHA512 + bench_sha512(); +#endif +#ifdef CYASSL_RIPEMD + bench_ripemd(); +#endif + + printf("\n"); + +#ifndef NO_RSA + bench_rsa(); +#endif + +#ifndef NO_DH + bench_dh(); +#endif + +#if defined(CYASSL_KEY_GEN) && !defined(NO_RSA) + bench_rsaKeyGen(); +#endif + +#ifdef HAVE_ECC + bench_eccKeyGen(); + bench_eccKeyAgree(); +#endif + + return 0; +} + diff --git a/mplabx/ctaocrypt_benchmark.X/nbproject/include.am b/mplabx/ctaocrypt_benchmark.X/nbproject/include.am new file mode 100644 index 000000000..567fbba38 --- /dev/null +++ b/mplabx/ctaocrypt_benchmark.X/nbproject/include.am @@ -0,0 +1,12 @@ +# vim:ft=automake +# All paths should be given relative to the root +# + +EXTRA_DIST += \ + mplabx/ctaocrypt_benchmark.X/Makefile \ + mplabx/ctaocrypt_benchmark.X/main.c + +EXTRA_DIST += \ + mplabx/ctaocrypt_benchmark.X/nbproject/configurations.xml \ + mplabx/ctaocrypt_benchmark.X/nbproject/project.xml + diff --git a/mplabx/ctaocrypt_benchmark.X/nbproject/project.xml b/mplabx/ctaocrypt_benchmark.X/nbproject/project.xml new file mode 100644 index 000000000..9ec9516cc --- /dev/null +++ b/mplabx/ctaocrypt_benchmark.X/nbproject/project.xml @@ -0,0 +1,18 @@ + + + com.microchip.mplab.nbide.embedded.makeproject + + + ctaocrypt_benchmark + 22e4138b-5f20-4957-ac0a-c181b94d3342 + 0 + c + + + ISO-8859-1 + + ../cyassl.X + + + + diff --git a/mplabx/ctaocrypt_test.X/main.c b/mplabx/ctaocrypt_test.X/main.c new file mode 100644 index 000000000..79a91bc0f --- /dev/null +++ b/mplabx/ctaocrypt_test.X/main.c @@ -0,0 +1,57 @@ +/* main.c + * + * Copyright (C) 2006-2012 Sawtooth Consulting Ltd. + * + * This file is part of CyaSSL. + * + * CyaSSL is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * CyaSSL is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#define PIC32_STARTER_KIT + +#include +#include +#include +#include + +/* func_args from test.h, so don't have to pull in other junk */ +typedef struct func_args { + int argc; + char** argv; + int return_code; +} func_args; + +/* + * Main driver for CTaoCrypt tests. + */ +int main(int argc, char** argv) { + + DBINIT(); + printf("CTaoCrypt Test:\n"); + + func_args args; + + args.argc = argc; + args.argv = argv; + + ctaocrypt_test(&args); + + if (args.return_code == 0) { + printf("All tests passed!\n"); + } + + return 0; +} + diff --git a/mplabx/ctaocrypt_test.X/nbproject/include.am b/mplabx/ctaocrypt_test.X/nbproject/include.am new file mode 100644 index 000000000..e7d868de8 --- /dev/null +++ b/mplabx/ctaocrypt_test.X/nbproject/include.am @@ -0,0 +1,12 @@ +# vim:ft=automake +# All paths should be given relative to the root +# + +EXTRA_DIST += \ + mplabx/ctaocrypt_test.X/Makefile \ + mplabx/ctaocrypt_test.X/main.c + +EXTRA_DIST += \ + mplabx/ctaocrypt_test.X/nbproject/configurations.xml \ + mplabx/ctaocrypt_test.X/nbproject/project.xml + diff --git a/mplabx/ctaocrypt_test.X/nbproject/project.xml b/mplabx/ctaocrypt_test.X/nbproject/project.xml new file mode 100644 index 000000000..3567a51b8 --- /dev/null +++ b/mplabx/ctaocrypt_test.X/nbproject/project.xml @@ -0,0 +1,18 @@ + + + com.microchip.mplab.nbide.embedded.makeproject + + + ctaocrypt_test + b34c4937-7042-4352-88b1-7717bcdf8aeb + 0 + c + + h + ISO-8859-1 + + ../cyassl.X + + + + diff --git a/mplabx/cyassl.X/nbproject/include.am b/mplabx/cyassl.X/nbproject/include.am new file mode 100644 index 000000000..4db3841b2 --- /dev/null +++ b/mplabx/cyassl.X/nbproject/include.am @@ -0,0 +1,12 @@ +# vim:ft=automake +# All paths should be given relative to the root +# + +EXTRA_DIST += \ + mplabx/README \ + mplabx/cyassl.X/Makefile + +EXTRA_DIST += \ + mplabx/cyassl.X/nbproject/configurations.xml \ + mplabx/cyassl.X/nbproject/project.xml + diff --git a/mplabx/cyassl.X/nbproject/project.xml b/mplabx/cyassl.X/nbproject/project.xml new file mode 100644 index 000000000..831eae925 --- /dev/null +++ b/mplabx/cyassl.X/nbproject/project.xml @@ -0,0 +1,16 @@ + + + com.microchip.mplab.nbide.embedded.makeproject + + + cyassl + 93bbfc3a-a0fa-4d48-bbc8-6cd47a2bd05b + 0 + c + + + ISO-8859-1 + + + +