x509 begin and fix mallocs with sanity checks

pull/32/head
kaleb-himes 2016-11-23 22:26:51 -07:00
parent 01c7b27da4
commit 9dda838075
11 changed files with 291 additions and 134 deletions

View File

@ -74,6 +74,15 @@
#define MEGABYTE (1024*1024)
#define MAX_THREADS 64
#include <wolfssl/wolfcrypt/types.h>
#ifdef WOLFSSL_STATIC_MEMORY
#include <wolfssl/wolfcrypt/memory.h>
static WOLFSSL_HEAP_HINT* HEAP_HINT;
#else
#define HEAP_HINT NULL
#endif
/* @VERSION
* Update every time library change,
* functionality shift,
@ -81,50 +90,6 @@
*/
#define VERSION 0.3
/* Enumerated types for long arguments */
enum {
ENCRYPT = 1000,
DECRYPT,
BENCHMARK,
HASH,
INFILE,
OUTFILE,
PASSWORD,
KEY,
IV,
ALL,
SIZE,
TIME,
VERIFY,
VERBOSE,
X509
};
/* Structure for holding long arguments */
static struct option long_options[] = {
{"encrypt", required_argument, 0, ENCRYPT },
{"decrypt", required_argument, 0, DECRYPT },
{"bench", required_argument, 0, BENCHMARK },
{"hash", required_argument, 0, HASH },
{"in", required_argument, 0, INFILE },
{"out", required_argument, 0, OUTFILE },
{"pwd", required_argument, 0, PASSWORD },
{"key", required_argument, 0, KEY },
{"iv", required_argument, 0, IV },
{"all", 0, 0, ALL },
{"size", required_argument, 0, SIZE },
{"time", required_argument, 0, TIME },
{"verify", 0, 0, VERIFY },
{"verbose", 0, 0, VERBOSE },
{"x509", required_argument, 0, X509 },
{"v", 0, 0, 'v' },
{"version", 0, 0, 'v' },
{0, 0, 0, 0}
};
/* encryption argument function
*
* @param argc holds all command line input
@ -239,7 +204,7 @@ int wolfsslHexToBin(const char* h1, byte** b1, word32* b1Sz,
const char* h3, byte** b3, word32* b3Sz,
const char* h4, byte** b4, word32* b4Sz);
/* A function to free malloced byte* buffers after conversion
/* A function to free MALLOCED buffers
*
* @param b1 a buffer to be freed, can be set to NULL
* @param b2 a buffer to be freed, can be set to NULL

View File

@ -19,10 +19,19 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <getopt.h>
#include <wolfssl/wolfcrypt/random.h>
#include <wolfssl/wolfcrypt/error-crypt.h>
#ifdef WOLFSSL_STATIC_MEMORY
#include <wolfssl/wolfcrypt/memory.h>
static WOLFSSL_HEAP_HINT* HEAP_HINT;
#else
#define HEAP_HINT NULL
#endif
/* handles incoming arguments for certificate generation */
int wolfsslCertSetup(int argc, char** argv, char action);
int wolfsslCertSetup(int argc, char** argv);
/* print help info */
void wolfsslCertHelp();

View File

@ -21,6 +21,7 @@
#include "include/wolfssl.h"
#define DES3_BLOCK_SIZE 24
#ifdef HAVE_BLAKE2
@ -50,13 +51,13 @@ int wolfsslBenchmark(int timer, int* option)
double stop = 0.0; /* stop breaks loop */
double start; /* start time */
double currTime; /* current time*/
ALIGN16 byte* plain; /* plain text */
ALIGN16 byte* cipher; /* cipher */
ALIGN16 byte* key; /* key for testing */
ALIGN16 byte* iv; /* iv for initial encoding */
byte* digest; /* message digest */
wc_InitRng(&rng);
@ -66,10 +67,25 @@ int wolfsslBenchmark(int timer, int* option)
#ifndef NO_AES
/* aes test */
if (option[i] == 1) {
plain = malloc(AES_BLOCK_SIZE);
cipher = malloc(AES_BLOCK_SIZE);
key = malloc(AES_BLOCK_SIZE);
iv = malloc(AES_BLOCK_SIZE);
plain = XMALLOC(AES_BLOCK_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
if (plain == NULL) {
return MEMORY_E;
}
cipher = XMALLOC(AES_BLOCK_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
if (cipher == NULL) {
wolfsslFreeBins(plain, NULL, NULL, NULL, NULL);
return MEMORY_E;
}
key = XMALLOC(AES_BLOCK_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
if (key == NULL) {
wolfsslFreeBins(plain, cipher, NULL, NULL, NULL);
return MEMORY_E;
}
iv = XMALLOC(AES_BLOCK_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
if (iv == NULL) {
wolfsslFreeBins(plain, cipher, key, NULL, NULL);
return MEMORY_E;
}
wc_RNG_GenerateBlock(&rng, plain, AES_BLOCK_SIZE);
wc_RNG_GenerateBlock(&rng, cipher, AES_BLOCK_SIZE);
@ -95,10 +111,7 @@ int wolfsslBenchmark(int timer, int* option)
XMEMSET(cipher, 0, AES_BLOCK_SIZE);
XMEMSET(key, 0, AES_BLOCK_SIZE);
XMEMSET(iv, 0, AES_BLOCK_SIZE);
free(plain);
free(cipher);
free(key);
free(iv);
wolfsslFreeBins(plain, cipher, key, iv, NULL);
blocks = 0;
loop = 1;
}
@ -107,10 +120,25 @@ int wolfsslBenchmark(int timer, int* option)
#ifdef WOLFSSL_AES_COUNTER
/* aes-ctr test */
if (option[i] == 1) {
plain = malloc(AES_BLOCK_SIZE);
cipher = malloc(AES_BLOCK_SIZE);
key = malloc(AES_BLOCK_SIZE);
iv = malloc(AES_BLOCK_SIZE);
plain = XMALLOC(AES_BLOCK_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
if (plain == NULL) {
return MEMORY_E;
}
cipher = XMALLOC(AES_BLOCK_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
if (cipher == NULL) {
wolfsslFreeBins(plain, NULL, NULL, NULL, NULL);
return MEMORY_E;
}
key = XMALLOC(AES_BLOCK_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
if (key == NULL) {
wolfsslFreeBins(plain, cipher, NULL, NULL, NULL);
return MEMORY_E;
}
iv = XMALLOC(AES_BLOCK_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
if (iv == NULL) {
wolfsslFreeBins(plain, cipher, key, NULL, NULL);
return MEMORY_E;
}
wc_RNG_GenerateBlock(&rng, plain, AES_BLOCK_SIZE);
wc_RNG_GenerateBlock(&rng, cipher, AES_BLOCK_SIZE);
@ -134,10 +162,7 @@ int wolfsslBenchmark(int timer, int* option)
XMEMSET(cipher, 0, AES_BLOCK_SIZE);
XMEMSET(key, 0, AES_BLOCK_SIZE);
XMEMSET(iv, 0, AES_BLOCK_SIZE);
free(plain);
free(cipher);
free(key);
free(iv);
wolfsslFreeBins(plain, cipher, key, iv, NULL);
blocks = 0;
loop = 1;
}
@ -145,11 +170,26 @@ int wolfsslBenchmark(int timer, int* option)
#endif
#ifndef NO_DES3
/* 3des test */
if (option[i] == 1) {
plain = malloc(DES3_BLOCK_SIZE);
cipher = malloc(DES3_BLOCK_SIZE);
key = malloc(DES3_BLOCK_SIZE);
iv = malloc(DES3_BLOCK_SIZE);
if (option[i] == 1) {
plain = XMALLOC(DES3_BLOCK_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
if (plain == NULL) {
return MEMORY_E;
}
cipher = XMALLOC(DES3_BLOCK_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
if (cipher == NULL) {
wolfsslFreeBins(plain, NULL, NULL, NULL, NULL);
return MEMORY_E;
}
key = XMALLOC(DES3_BLOCK_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
if (key == NULL) {
wolfsslFreeBins(plain, cipher, NULL, NULL, NULL);
return MEMORY_E;
}
iv = XMALLOC(DES3_BLOCK_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
if (iv == NULL) {
wolfsslFreeBins(plain, cipher, key, NULL, NULL);
return MEMORY_E;
}
wc_RNG_GenerateBlock(&rng, plain, DES3_BLOCK_SIZE);
wc_RNG_GenerateBlock(&rng, cipher, DES3_BLOCK_SIZE);
@ -174,24 +214,37 @@ int wolfsslBenchmark(int timer, int* option)
XMEMSET(cipher, 0, DES3_BLOCK_SIZE);
XMEMSET(key, 0, DES3_BLOCK_SIZE);
XMEMSET(iv, 0, DES3_BLOCK_SIZE);
free(plain);
free(cipher);
free(key);
free(iv);
wolfsslFreeBins(plain, cipher, key, iv, NULL);
blocks = 0;
loop = 1;
}
i++;
#endif
#ifdef HAVE_CAMELLIA
#define CAM_SZ CAMELLIA_BLOCK_SIZE
/* camellia test */
if (option[i] == 1) {
Camellia camellia;
plain = malloc(CAMELLIA_BLOCK_SIZE);
cipher = malloc(CAMELLIA_BLOCK_SIZE);
key = malloc(CAMELLIA_BLOCK_SIZE);
iv = malloc(CAMELLIA_BLOCK_SIZE);
plain = XMALLOC(CAM_SZ, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
if (plain == NULL) {
return MEMORY_E;
}
cipher = XMALLOC(CAM_SZ, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
if (cipher == NULL) {
wolfsslFreeBins(plain, NULL, NULL, NULL, NULL);
return MEMORY_E;
}
key = XMALLOC(CAM_SZ, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
if (key == NULL) {
wolfsslFreeBins(plain, cipher, NULL, NULL, NULL);
return MEMORY_E;
}
iv = XMALLOC(CAM_SZ, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
if (iv == NULL) {
wolfsslFreeBins(plain, cipher, key, NULL, NULL);
return MEMORY_E;
}
wc_RNG_GenerateBlock(&rng, plain, CAMELLIA_BLOCK_SIZE);
wc_RNG_GenerateBlock(&rng, cipher, CAMELLIA_BLOCK_SIZE);
@ -216,10 +269,7 @@ int wolfsslBenchmark(int timer, int* option)
XMEMSET(cipher, 0, CAMELLIA_BLOCK_SIZE);
XMEMSET(key, 0, CAMELLIA_BLOCK_SIZE);
XMEMSET(iv, 0, CAMELLIA_BLOCK_SIZE);
free(plain);
free(cipher);
free(key);
free(iv);
wolfsslFreeBins(plain, cipher, key, iv, NULL);
blocks = 0;
loop = 1;
}
@ -230,8 +280,14 @@ int wolfsslBenchmark(int timer, int* option)
if (option[i] == 1) {
Md5 md5;
digest = malloc(MD5_DIGEST_SIZE);
plain = malloc(MEGABYTE);
digest = XMALLOC(MD5_DIGEST_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
if (digest == NULL)
return MEMORY_E;
plain = XMALLOC(MEGABYTE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
if (plain == NULL) {
wolfsslFreeBins(digest, NULL, NULL, NULL, NULL);
return MEMORY_E;
}
wc_RNG_GenerateBlock(&rng, plain, MEGABYTE);
wc_InitMd5(&md5);
@ -251,8 +307,7 @@ int wolfsslBenchmark(int timer, int* option)
wolfsslStats(start, MEGABYTE, blocks);
XMEMSET(plain, 0, MEGABYTE);
XMEMSET(digest, 0, MD5_DIGEST_SIZE);
free(plain);
free(digest);
wolfsslFreeBins(digest, plain, NULL, NULL, NULL);
blocks = 0;
loop = 1;
}
@ -263,8 +318,14 @@ int wolfsslBenchmark(int timer, int* option)
if (option[i] == 1) {
Sha sha;
digest = malloc(SHA_DIGEST_SIZE);
plain = malloc(MEGABYTE);
digest = XMALLOC(SHA_DIGEST_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
if (digest == NULL)
return MEMORY_E;
plain = XMALLOC(MEGABYTE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
if (plain == NULL) {
wolfsslFreeBins(digest, NULL, NULL, NULL, NULL);
return MEMORY_E;
}
wc_RNG_GenerateBlock(&rng, plain, MEGABYTE);
wc_InitSha(&sha);
@ -284,20 +345,27 @@ int wolfsslBenchmark(int timer, int* option)
wolfsslStats(start, MEGABYTE, blocks);
XMEMSET(plain, 0, MEGABYTE);
XMEMSET(digest, 0, SHA_DIGEST_SIZE);
free(plain);
free(digest);
wolfsslFreeBins(plain, digest, NULL, NULL, NULL);
blocks = 0;
loop = 1;
}
i++;
#endif
#ifndef NO_SHA256
#define SHA256_SZ SHA256_DIGEST_SIZE
/* sha256 test */
if (option[i] == 1) {
Sha256 sha256;
digest = malloc(SHA256_DIGEST_SIZE);
plain = malloc(MEGABYTE);
digest = XMALLOC(SHA256_SZ, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
if (digest == NULL)
return MEMORY_E;
plain = XMALLOC(MEGABYTE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
if (plain == NULL) {
wolfsslFreeBins(digest, NULL, NULL, NULL, NULL);
return MEMORY_E;
}
wc_RNG_GenerateBlock(&rng, plain, MEGABYTE);
wc_InitSha256(&sha256);
@ -317,8 +385,7 @@ int wolfsslBenchmark(int timer, int* option)
wolfsslStats(start, MEGABYTE, blocks);
XMEMSET(plain, 0, MEGABYTE);
XMEMSET(digest, 0, SHA256_DIGEST_SIZE);
free(plain);
free(digest);
wolfsslFreeBins(plain, digest, NULL, NULL, NULL);
/* resets used for debug, uncomment if needed */
blocks = 0;
loop = 1;
@ -326,12 +393,20 @@ int wolfsslBenchmark(int timer, int* option)
i++;
#endif
#ifdef WOLFSSL_SHA384
#define SHA384_SZ SHA384_DIGEST_SIZE
/* sha384 test */
if (option[i] == 1) {
Sha384 sha384;
digest = malloc(SHA384_DIGEST_SIZE);
plain = malloc(MEGABYTE);
digest = XMALLOC(SHA384_SZ, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
if (digest == NULL)
return MEMORY_E;
plain = XMALLOC(MEGABYTE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
if (plain == NULL) {
wolfsslFreeBins(digest, NULL, NULL, NULL, NULL);
return MEMORY_E;
}
wc_RNG_GenerateBlock(&rng, plain, MEGABYTE);
wc_InitSha384(&sha384);
@ -351,20 +426,27 @@ int wolfsslBenchmark(int timer, int* option)
wolfsslStats(start, MEGABYTE, blocks);
XMEMSET(plain, 0, MEGABYTE);
XMEMSET(digest, 0, SHA384_DIGEST_SIZE);
free(plain);
free(digest);
wolfsslFreeBins(plain, digest, NULL, NULL, NULL);
blocks = 0;
loop = 1;
}
i++;
#endif
#ifdef WOLFSSL_SHA512
#define SHA512_SZ SHA512_DIGEST_SIZE
/* sha512 test */
if (option[i] == 1) {
Sha512 sha512;
digest = malloc(SHA512_DIGEST_SIZE);
plain = malloc(MEGABYTE);
digest = XMALLOC(SHA512_SZ, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
if (digest == NULL)
return MEMORY_E;
plain = XMALLOC(MEGABYTE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
if (plain == NULL) {
wolfsslFreeBins(digest, NULL, NULL, NULL, NULL);
return MEMORY_E;
}
wc_RNG_GenerateBlock(&rng, plain, MEGABYTE);
wc_InitSha512(&sha512);
@ -384,8 +466,7 @@ int wolfsslBenchmark(int timer, int* option)
wolfsslStats(start, MEGABYTE, blocks);
XMEMSET(plain, 0, MEGABYTE);
XMEMSET(digest, 0, SHA512_DIGEST_SIZE);
free(plain);
free(digest);
wolfsslFreeBins(plain, digest, NULL, NULL, NULL);
blocks = 0;
loop = 1;
}
@ -396,8 +477,15 @@ int wolfsslBenchmark(int timer, int* option)
if (option[i] == 1) {
Blake2b b2b;
digest = malloc(BLAKE_DIGEST_SIZE);
plain = malloc(MEGABYTE);
digest = XMALLOC(BLAKE_DIGEST_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
if (digest == NULL)
return MEMORY_E;
plain = XMALLOC(MEGABYTE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
if (plain == NULL) {
wolfsslFreeBins(digest, NULL, NULL, NULL, NULL);
return MEMORY_E;
}
wc_RNG_GenerateBlock(&rng, plain, MEGABYTE);
wc_InitBlake2b(&b2b, BLAKE_DIGEST_SIZE);
@ -417,8 +505,7 @@ int wolfsslBenchmark(int timer, int* option)
wolfsslStats(start, MEGABYTE, blocks);
XMEMSET(plain, 0, MEGABYTE);
XMEMSET(digest, 0, BLAKE_DIGEST_SIZE);
free(plain);
free(digest);
wolfsslFreeBins(digest, plain, NULL, NULL, NULL);
}
#endif
return ret;

View File

@ -85,8 +85,13 @@ int wolfsslDecrypt(char* alg, char* mode, byte* pwdKey, byte* key, int size,
lastLoopFlag = length/MAX;
}
input = (byte*) malloc(MAX);
output = (byte*) malloc(MAX);
input = (byte*) XMALLOC(MAX, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
if (input == NULL)
return MEMORY_E;
output = (byte*) XMALLOC(MAX, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
if (output == NULL) {
wolfsslFreeBins(input, NULL, NULL, NULL, NULL);
}
wc_InitRng(&rng);

View File

@ -69,7 +69,10 @@ int wolfsslEncrypt(char* alg, char* mode, byte* pwdKey, byte* key, int size,
/* use user entered data to encrypt */
inputLength = (int) strlen(in);
userInputBuffer = (char*) malloc(inputLength);
userInputBuffer = (char*) XMALLOC(inputLength, HEAP_HINT,
DYNAMIC_TYPE_TMP_BUFFER);
if (userInputBuffer == NULL)
return MEMORY_E;
/* writes the entered text to the input buffer */
XMEMCPY(userInputBuffer, in, inputLength);
@ -80,7 +83,7 @@ int wolfsslEncrypt(char* alg, char* mode, byte* pwdKey, byte* key, int size,
fclose(tempInFile);
/* free buffer */
free(userInputBuffer);
XFREE(userInputBuffer, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
}
/* open the inFile in read mode */
@ -138,9 +141,15 @@ int wolfsslEncrypt(char* alg, char* mode, byte* pwdKey, byte* key, int size,
fwrite(iv, 1, block, outFile);
fclose(outFile);
/* malloc 1kB buffers */
input = (byte*) malloc(MAX);
output = (byte*) malloc(MAX);
/* MALLOC 1kB buffers */
input = (byte*) XMALLOC(MAX, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
if (input == NULL)
return MEMORY_E;
output = (byte*) XMALLOC(MAX, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
if (output == NULL) {
wolfsslFreeBins(input, NULL, NULL, NULL, NULL);
return MEMORY_E;
}
/* loop, encrypt 1kB at a time till length <= 0 */
while (length > 0) {

View File

@ -79,9 +79,19 @@ int wolfsslSetup(int argc, char** argv, char action)
block = wolfsslGetAlgo(name, &alg, &mode, &size);
if (block != FATAL_ERROR) {
pwdKey = (byte*) malloc(size);
iv = (byte*) malloc(block);
key = (byte*) malloc(size);
pwdKey = (byte*) XMALLOC(size, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
if (pwdKey == NULL)
return MEMORY_E;
iv = (byte*) XMALLOC(block, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
if (iv == NULL) {
wolfsslFreeBins(pwdKey, NULL, NULL, NULL, NULL);
return MEMORY_E;
}
key = (byte*) XMALLOC(size, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
if (key == NULL) {
wolfsslFreeBins(pwdKey, iv, NULL, NULL, NULL);
return MEMORY_E;
}
/* Start at the third flag entered */
i = 3;

View File

@ -48,7 +48,10 @@ int wolfsslHash(char* in, char* out, char* alg, int size)
/* if no input file was provided */
length = LENGTH_IN;
input = malloc(length);
input = XMALLOC(length, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
if (input == NULL)
return MEMORY_E;
XMEMSET(input, 0, length);
for (i = 0; i < length; i++) {
/* copies text from in to input */
@ -65,7 +68,10 @@ int wolfsslHash(char* in, char* out, char* alg, int size)
length = leng;
input = malloc(length+1);
input = XMALLOC(length+1, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
if (input == NULL)
return MEMORY_E;
XMEMSET(input, 0, length+1);
if (input == NULL) {
printf("Failed to create input buffer\n");
@ -80,7 +86,11 @@ int wolfsslHash(char* in, char* out, char* alg, int size)
size = length * 4;
}
output = malloc(size);
output = XMALLOC(size, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
if (output == NULL) {
wolfsslFreeBins(input, NULL, NULL, NULL, NULL);
return MEMORY_E;
}
XMEMSET(output, 0, size);
/* hashes using accepted algorithm */
@ -112,8 +122,11 @@ int wolfsslHash(char* in, char* out, char* alg, int size)
#ifdef HAVE_BLAKE2
else if (strcmp(alg, "blake2b") == 0) {
ret = wc_InitBlake2b(&hash, size);
if (ret != 0) return ret;
ret = wc_Blake2bUpdate(&hash, input, length);
if (ret != 0) return ret;
ret = wc_Blake2bFinal(&hash, output, size);
if (ret != 0) return ret;
}
#endif
@ -163,7 +176,6 @@ int wolfsslHash(char* in, char* out, char* alg, int size)
/* closes the opened files and frees the memory */
XMEMSET(input, 0, length);
XMEMSET(output, 0, size);
free(input);
free(output);
wolfsslFreeBins(input, output, NULL, NULL, NULL);
return ret;
}

View File

@ -93,7 +93,11 @@ int wolfsslHashSetup(int argc, char** argv)
for (i = 3; i < argc; i++) {
if (XSTRNCMP(argv[i], "-in", 3) == 0 && argv[i+1] != NULL) {
/* input file/text */
in = malloc(strlen(argv[i+1])+1);
in = XMALLOC(strlen(argv[i+1])+1, HEAP_HINT,
DYNAMIC_TYPE_TMP_BUFFER);
if (in == NULL)
return MEMORY_E;
XSTRNCPY(in, &argv[i+1][0], XSTRLEN(&argv[i+1][0]));
in[XSTRLEN(argv[i+1])] = '\0';
inCheck = 1;
@ -154,6 +158,7 @@ int wolfsslHashSetup(int argc, char** argv)
/* hashing function */
ret = wolfsslHash(in, out, alg, size);
XFREE(in, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
free(in);
return ret;

View File

@ -30,16 +30,22 @@
#include <wolfssl/wolfcrypt/coding.h>
#include <wolfssl/wolfcrypt/error-crypt.h>
#include <stdio.h>
#include "include/wolfssl.h"
//#include <include/wolfssl.h>
/* free up to 5 binary buffers using wolfssl abstraction layer */
void wolfsslFreeBins(byte* b1, byte* b2, byte* b3, byte* b4, byte* b5)
{
XFREE(b1, NULL, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(b2, NULL, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(b3, NULL, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(b4, NULL, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(b5, NULL, DYNAMIC_TYPE_TMP_BUFFER);
if (b1 != NULL)
XFREE(b1, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
if (b2 != NULL)
XFREE(b2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
if (b3 != NULL)
XFREE(b3, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
if (b4 != NULL)
XFREE(b4, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
if (b5 != NULL)
XFREE(b5, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
}

View File

@ -21,6 +21,7 @@
#include "include/wolfssl.h"
#include "include/x509/wolfsslCert.h"
#include "include/optargs.h"
/* enumerate optionals beyond ascii range to dis-allow use of alias IE we
* do not want "-e" to work for encrypt, user must use "encrypt"
@ -40,19 +41,19 @@ int main(int argc, char** argv)
switch (option) {
/* Encrypt */
case ENCRYPT: ret = wolfsslSetup(argc, argv, 'e');
case ENCRYPT: ret = wolfsslSetup(argc, argv, 'e');
break;
/* Decrypt */
case DECRYPT: ret = wolfsslSetup(argc, argv, 'd');;
case DECRYPT: ret = wolfsslSetup(argc, argv, 'd');;
break;
/* Benchmark */
case BENCHMARK:ret = wolfsslBenchSetup(argc, argv);
case BENCHMARK:ret = wolfsslBenchSetup(argc, argv);
break;
/* Hash */
case HASH: ret = wolfsslHashSetup(argc, argv);
case HASH: ret = wolfsslHashSetup(argc, argv);
break;
/* Certificate Stuff*/
case X509: ret = wolfsslCertSetup(argc, argv, 'n');
/* x509 Certificate processing */
case X509: ret = wolfsslCertSetup(argc, argv);
break;
/* Ignore the following arguments for now. Will be handled by their respective
@ -76,6 +77,9 @@ int main(int argc, char** argv)
case TIME: break;
/* Verify results, used with -iv and -key */
case VERIFY: break;
/* Certificate Stuff*/
case INFORM: break;
case OUTFORM: break;
/* which version of clu am I using */
case VERBOSE:
wolfsslVerboseHelp();
@ -84,6 +88,7 @@ int main(int argc, char** argv)
case 'v': wolfsslVersion();
return 0;
default:
printf("Main help default.\n");
wolfsslHelp();

View File

@ -22,23 +22,67 @@
#include <stdio.h>
#include <include/x509/wolfsslCert.h>
#include <wolfssl/wolfcrypt/types.h>
#include "include/optargs.h"
int wolfsslCertSetup(int argc, char** argv, char action)
#ifdef WOLFSSL_STATIC_MEMORY
#include <wolfssl/wolfcrypt/memory.h>
static WOLFSSL_HEAP_HINT* HEAP_HINT;
#else
#define HEAP_HINT NULL
#endif
int wolfsslCertSetup(int argc, char** argv)
{
int i; /* loop counter */
int i;
char* inform;
char* outform;
printf("In x509 loop\n");
for (i = 2; i < argc; i++) {
convert_to_lower(argv[i], (int) XSTRLEN(argv[i]));
if (XSTRNCMP(argv[i], "-help", 5) == 0) {
wolfsslCertHelp();
return 0;
} else if (XSTRNCMP(argv[i], "-h", 2) == 0) {
wolfsslCertHelp();
return 0;
} else if (XSTRNCMP(argv[i], "-inform", 7) == 0) {
convert_to_lower(argv[i+1], (int) XSTRLEN(argv[i+1]));
inform = argv[i+1];
printf("inform is %s\n", inform);
if (XSTRNCMP(inform, "pem", 3) == 0)
printf("IDENTIFIED PEM\n");
if (XSTRNCMP(inform, "der", 3) == 0)
printf("IDENTIFIED DER\n");
} else if (XSTRNCMP(argv[i], "-outform", 8) == 0) {
convert_to_lower(argv[i+1], (int) XSTRLEN(argv[i+1]));
outform = argv[i+1];
printf("outform is %s\n", outform);
if (XSTRNCMP(outform, "pem", 3) == 0)
printf("IDENTIFIED PEM\n");
if (XSTRNCMP(outform, "der", 3) == 0)
printf("IDENTIFIED DER\n");
}
}
return 0;
}
void convert_to_lower(char* s, int sSz)
{
int i;
for (i = 0; i < sSz; i++) {
s[i] = tolower(s[i]);
}
}
void wolfsslCertHelp()
{
printf("\n\n\nThis would be the certificate help.\n\n\n");