From 38ac17864e7bdd220582b4ca1b20e194c1285152 Mon Sep 17 00:00:00 2001 From: lchristina26 Date: Wed, 9 Dec 2015 13:18:42 -0700 Subject: [PATCH 1/6] added entropy, wc_GenerateSeed() for VxWorks --- wolfcrypt/src/random.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/wolfcrypt/src/random.c b/wolfcrypt/src/random.c index 044a77021..a9ce055bd 100644 --- a/wolfcrypt/src/random.c +++ b/wolfcrypt/src/random.c @@ -1265,6 +1265,32 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz) return 0; } +#elif defined(WOLFSSL_VXWORKS) + + #include + + int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz) { + STATUS status; + unsigned char seed[1024]; + int i = 0; + + for (i=0; i < sizeof(seed); i++) { + seed[i]= i*3%256; + } + /* build entropy */ + (void) randAdd(seed, 0, 0); + for (i=4; i<=sizeof(seed); i*=2) { + (void) randAdd (seed, i-1, i); + } + + status = randBytes (output, sz); + if (status == ERROR) { + return status; + } + + return 0; + } + #elif defined(CUSTOM_RAND_GENERATE) /* Implement your own random generation function From cb73064c10bc7b52df9aacb8f48901bd65be20a7 Mon Sep 17 00:00:00 2001 From: lchristina26 Date: Wed, 9 Dec 2015 13:22:13 -0700 Subject: [PATCH 2/6] format changes to VXWORKS GenerateSeed() --- wolfcrypt/src/random.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/wolfcrypt/src/random.c b/wolfcrypt/src/random.c index a9ce055bd..a91a279fd 100644 --- a/wolfcrypt/src/random.c +++ b/wolfcrypt/src/random.c @@ -1274,13 +1274,13 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz) unsigned char seed[1024]; int i = 0; - for (i=0; i < sizeof(seed); i++) { - seed[i]= i*3%256; + for (i = 0; i < sizeof(seed); i++) { + seed[i] = i * 3 % 256; } /* build entropy */ (void) randAdd(seed, 0, 0); - for (i=4; i<=sizeof(seed); i*=2) { - (void) randAdd (seed, i-1, i); + for (i = 4; i <= sizeof(seed); i*=2) { + (void) randAdd (seed, i - 1, i); } status = randBytes (output, sz); From 8b99cea5c80104f1fe7229710c4d741b623bdda6 Mon Sep 17 00:00:00 2001 From: lchristina26 Date: Fri, 11 Dec 2015 13:19:44 -0700 Subject: [PATCH 3/6] update README with entropy instructions --- IDE/WORKBENCH/README.md | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/IDE/WORKBENCH/README.md b/IDE/WORKBENCH/README.md index 1e0ca243a..74253f0f3 100644 --- a/IDE/WORKBENCH/README.md +++ b/IDE/WORKBENCH/README.md @@ -50,11 +50,21 @@ wolfcrypt directories. Uncheck the following: \#ifdef WOLFSSL\_VXWORKS block, a new GenerateSeed() function will need to be defined in wolfcrypt/src/random.c. +8. Include Entropy: + - Create a new project, similar to step 1 but choose VxWorks Source Build Project as the type of project instead of VxWorks Image Project. + + - In the project directory, double click "Source Build Configuration" and under os > core > CORE\_KERNEL Menu > VxWorks Kernel Component Configuration find "Inject entropy in interrupts". Double click this. + + - Go back to your VIP project. Right click the project and select "Properties". + + - In "Properties", select "Project References". Check the box next to the new project you created. Click "Ok". + + - Rebuild the project. + ####3 Testing wolfSSL with VxWorks: #####3.1 wolfCrypt Test and Benchmark Applications The wolfCrypt test application will test each of the cryptographic algorithms -and output the status for each as a success or failure. The benchmark application will output the runtime of -the cryptographic algorithms in milliseconds. +and output the status for each as a success or failure. The benchmark application will output the runtime of the cryptographic algorithms in milliseconds. 1. Include the following at the top of usrAppInit.c: From e2456214f47a322db441521db4832ac49d548450 Mon Sep 17 00:00:00 2001 From: lchristina26 Date: Fri, 11 Dec 2015 13:22:33 -0700 Subject: [PATCH 4/6] update random.c for better entropy with VXWORKS --- wolfcrypt/src/random.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/wolfcrypt/src/random.c b/wolfcrypt/src/random.c index a91a279fd..e53947fdd 100644 --- a/wolfcrypt/src/random.c +++ b/wolfcrypt/src/random.c @@ -1271,20 +1271,10 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz) int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz) { STATUS status; - unsigned char seed[1024]; - int i = 0; - - for (i = 0; i < sizeof(seed); i++) { - seed[i] = i * 3 % 256; - } - /* build entropy */ - (void) randAdd(seed, 0, 0); - for (i = 4; i <= sizeof(seed); i*=2) { - (void) randAdd (seed, i - 1, i); - } status = randBytes (output, sz); if (status == ERROR) { + printf("Random seed failed! Enable RANDOM ENTROPY INJECT."); return status; } From 6ab9c87f137b73fff4e0e0de705cf274bd44c315 Mon Sep 17 00:00:00 2001 From: lchristina26 Date: Fri, 11 Dec 2015 13:41:05 -0700 Subject: [PATCH 5/6] add comment to VXWORKS GenerateSeed() --- wolfcrypt/src/random.c | 1 + 1 file changed, 1 insertion(+) diff --git a/wolfcrypt/src/random.c b/wolfcrypt/src/random.c index e53947fdd..cb623ab37 100644 --- a/wolfcrypt/src/random.c +++ b/wolfcrypt/src/random.c @@ -1272,6 +1272,7 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz) int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz) { STATUS status; + /* RANDOM ENTORPY INJECT component must be enabled in VSB project */ status = randBytes (output, sz); if (status == ERROR) { printf("Random seed failed! Enable RANDOM ENTROPY INJECT."); From 3113c8db9bc5d05b9dc44909d39495b94e4869c8 Mon Sep 17 00:00:00 2001 From: lchristina26 Date: Tue, 15 Dec 2015 16:52:21 -0700 Subject: [PATCH 6/6] update VXWORKS GenerateSeed() - no printf, error return --- wolfcrypt/src/random.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wolfcrypt/src/random.c b/wolfcrypt/src/random.c index cb623ab37..6456825b7 100644 --- a/wolfcrypt/src/random.c +++ b/wolfcrypt/src/random.c @@ -1275,8 +1275,8 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz) /* RANDOM ENTORPY INJECT component must be enabled in VSB project */ status = randBytes (output, sz); if (status == ERROR) { - printf("Random seed failed! Enable RANDOM ENTROPY INJECT."); - return status; + WOLFSSL_MSG("Random seed failed! Enable RANDOM ENTROPY INJECT."); + return RNG_FAILURE_E; } return 0;