From 352946ffee5b8e51caefa9b25ac4965c76b8bdd7 Mon Sep 17 00:00:00 2001 From: kaleb-himes Date: Sat, 19 Aug 2017 15:01:38 -0600 Subject: [PATCH 1/3] Fix some warnings thrown by -Wpointer-sign --- wolfCLU/clu_src/crypto/clu_decrypt.c | 20 ++++++++++---------- wolfCLU/clu_src/crypto/clu_encrypt.c | 18 +++++++++--------- wolfCLU/clu_src/genkey/clu_genkey.c | 8 ++++---- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/wolfCLU/clu_src/crypto/clu_decrypt.c b/wolfCLU/clu_src/crypto/clu_decrypt.c index 536a5952..976c40a1 100644 --- a/wolfCLU/clu_src/crypto/clu_decrypt.c +++ b/wolfCLU/clu_src/crypto/clu_decrypt.c @@ -22,7 +22,7 @@ #include "clu_include/clu_header_main.h" #include "clu_include/genkey/clu_genkey.h" -#define MAX 1024 +#define MAX_LEN 1024 int wolfCLU_decrypt(char* alg, char* mode, byte* pwdKey, byte* key, int size, char* in, char* out, byte* iv, int block, int keyType) @@ -54,7 +54,7 @@ int wolfCLU_decrypt(char* alg, char* mode, byte* pwdKey, byte* key, int size, int i = 0; /* loop variable */ int pad = 0; /* the length to pad */ int length; /* length of message */ - int tempMax = MAX; /* equal to MAX until feof */ + int tempMax = MAX_LEN; /* equal to MAX_LEN until feof */ int sbSize = SALT_SIZE + block; /* size of salt and iv together */ /* opens input file */ @@ -78,17 +78,17 @@ int wolfCLU_decrypt(char* alg, char* mode, byte* pwdKey, byte* key, int size, /* if there is a remainder, * round up else no round */ - if (length % MAX > 0) { - lastLoopFlag = (length/MAX) + 1; + if (length % MAX_LEN > 0) { + lastLoopFlag = (length/MAX_LEN) + 1; } else { - lastLoopFlag = length/MAX; + lastLoopFlag = length/MAX_LEN; } - input = (byte*) XMALLOC(MAX, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); + input = (byte*) XMALLOC(MAX_LEN, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); if (input == NULL) return MEMORY_E; - output = (byte*) XMALLOC(MAX, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); + output = (byte*) XMALLOC(MAX_LEN, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); if (output == NULL) { wolfCLU_freeBins(input, NULL, NULL, NULL, NULL); } @@ -142,7 +142,7 @@ int wolfCLU_decrypt(char* alg, char* mode, byte* pwdKey, byte* key, int size, } /* Read in 1kB */ - if ((ret = (int) fread(input, 1, MAX, inFile)) != MAX) { + if ((ret = (int) fread(input, 1, MAX_LEN, inFile)) != MAX_LEN) { if (feof(inFile)) { tempMax = ret; } @@ -239,8 +239,8 @@ int wolfCLU_decrypt(char* alg, char* mode, byte* pwdKey, byte* key, int size, length -= tempMax; } /* closes the opened files and frees memory */ - XMEMSET(input, 0, MAX); - XMEMSET (output, 0, MAX); + XMEMSET(input, 0, MAX_LEN); + XMEMSET (output, 0, MAX_LEN); wolfCLU_freeBins(input, output, NULL, NULL, NULL); XMEMSET(key, 0, size); /* Use the wolfssl wc_FreeRng to free rng */ diff --git a/wolfCLU/clu_src/crypto/clu_encrypt.c b/wolfCLU/clu_src/crypto/clu_encrypt.c index 184d0c4c..c52d7aa9 100644 --- a/wolfCLU/clu_src/crypto/clu_encrypt.c +++ b/wolfCLU/clu_src/crypto/clu_encrypt.c @@ -22,7 +22,7 @@ #include "clu_include/clu_header_main.h" #include "clu_include/genkey/clu_genkey.h" -#define MAX 1024 +#define MAX_LEN 1024 int wolfCLU_encrypt(char* alg, char* mode, byte* pwdKey, byte* key, int size, char* in, char* out, byte* iv, int block, int ivCheck, int inputHex) @@ -57,9 +57,9 @@ int wolfCLU_encrypt(char* alg, char* mode, byte* pwdKey, byte* key, int size, int hexRet = 0; /* hex -> bin return*/ word32 tempInputL = 0; /* temporary input Length */ - word32 tempMax = MAX; /* controls encryption amount */ + word32 tempMax = MAX_LEN; /* controls encryption amount */ - char inputString[MAX]; /* the input string */ + char inputString[MAX_LEN]; /* the input string */ char* userInputBuffer = NULL; /* buffer when input is not a file */ @@ -142,10 +142,10 @@ int wolfCLU_encrypt(char* alg, char* mode, byte* pwdKey, byte* key, int size, fclose(outFile); /* MALLOC 1kB buffers */ - input = (byte*) XMALLOC(MAX, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); + input = (byte*) XMALLOC(MAX_LEN, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); if (input == NULL) return MEMORY_E; - output = (byte*) XMALLOC(MAX, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); + output = (byte*) XMALLOC(MAX_LEN, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); if (output == NULL) { wolfCLU_freeBins(input, NULL, NULL, NULL, NULL); return MEMORY_E; @@ -155,11 +155,11 @@ int wolfCLU_encrypt(char* alg, char* mode, byte* pwdKey, byte* key, int size, while (length > 0) { /* Read in 1kB to input[] */ if (inputHex == 1) - ret = (int) fread(inputString, 1, MAX, inFile); + ret = (int) fread(inputString, 1, MAX_LEN, inFile); else - ret = (int) fread(input, 1, MAX, inFile); + ret = (int) fread(input, 1, MAX_LEN, inFile); - if (ret != MAX) { + if (ret != MAX_LEN) { /* check for end of file */ if (feof(inFile)) { @@ -280,7 +280,7 @@ int wolfCLU_encrypt(char* alg, char* mode, byte* pwdKey, byte* key, int size, wolfCLU_freeBins(input, output, NULL, NULL, NULL); return FWRITE_ERROR; } - if (ret > MAX) { + if (ret > MAX_LEN) { printf("Wrote too much to file.\n"); if (input != NULL) XMEMSET(input, 0, tempMax); diff --git a/wolfCLU/clu_src/genkey/clu_genkey.c b/wolfCLU/clu_src/genkey/clu_genkey.c index 735d4f84..a69dd81b 100644 --- a/wolfCLU/clu_src/genkey/clu_genkey.c +++ b/wolfCLU/clu_src/genkey/clu_genkey.c @@ -161,7 +161,7 @@ int wolfCLU_genKey_ECC(RNG* rng, char* fName, int directive, int fmt, char* fOutNameBuf = NULL; size_t maxDerBufSz = 4 * keySz * AES_BLOCK_SIZE; - char* derBuf = NULL; + byte* derBuf = NULL; int derBufSz = -1; if (rng == NULL || fName == NULL) @@ -196,7 +196,7 @@ int wolfCLU_genKey_ECC(RNG* rng, char* fName, int directive, int fmt, XMEMSET(fOutNameBuf, 0, fNameSz + fExtSz); XMEMCPY(fOutNameBuf, fName, fNameSz); - derBuf = (char*)XMALLOC(maxDerBufSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); + derBuf = XMALLOC(maxDerBufSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); if (derBuf == NULL) { XFREE(fOutNameBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); return MEMORY_E; @@ -300,7 +300,7 @@ int wolfCLU_genKey_RSA(RNG* rng, char* fName, int directive, int fmt, int char* fOutNameBuf = NULL; size_t maxDerBufSz = 5 * keySz * AES_BLOCK_SIZE; - char* derBuf = NULL; + byte* derBuf = NULL; int derBufSz = -1; if (rng == NULL || fName == NULL) @@ -331,7 +331,7 @@ int wolfCLU_genKey_RSA(RNG* rng, char* fName, int directive, int fmt, int XMEMSET(fOutNameBuf, 0, fNameSz + fExtSz); XMEMCPY(fOutNameBuf, fName, fNameSz); - derBuf = (char*)XMALLOC(maxDerBufSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); + derBuf = XMALLOC(maxDerBufSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); if (derBuf == NULL) { XFREE(fOutNameBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); return MEMORY_E; From abaf07109b2424f57aa984c9a8fe7e32dc93ced4 Mon Sep 17 00:00:00 2001 From: Kaleb Himes Date: Mon, 28 Aug 2017 13:28:04 -0600 Subject: [PATCH 2/3] Review update Thanks Jacob! --- wolfCLU/clu_src/genkey/clu_genkey.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wolfCLU/clu_src/genkey/clu_genkey.c b/wolfCLU/clu_src/genkey/clu_genkey.c index a69dd81b..b0cfa311 100644 --- a/wolfCLU/clu_src/genkey/clu_genkey.c +++ b/wolfCLU/clu_src/genkey/clu_genkey.c @@ -196,7 +196,7 @@ int wolfCLU_genKey_ECC(RNG* rng, char* fName, int directive, int fmt, XMEMSET(fOutNameBuf, 0, fNameSz + fExtSz); XMEMCPY(fOutNameBuf, fName, fNameSz); - derBuf = XMALLOC(maxDerBufSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); + derBuf = (byte*) XMALLOC(maxDerBufSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); if (derBuf == NULL) { XFREE(fOutNameBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); return MEMORY_E; From 2fe3c51bc94a7cdfe13306c3bf1543f7231fd60d Mon Sep 17 00:00:00 2001 From: Kaleb Himes Date: Mon, 28 Aug 2017 13:29:01 -0600 Subject: [PATCH 3/3] Review update (2) --- wolfCLU/clu_src/genkey/clu_genkey.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wolfCLU/clu_src/genkey/clu_genkey.c b/wolfCLU/clu_src/genkey/clu_genkey.c index b0cfa311..dce38690 100644 --- a/wolfCLU/clu_src/genkey/clu_genkey.c +++ b/wolfCLU/clu_src/genkey/clu_genkey.c @@ -331,7 +331,7 @@ int wolfCLU_genKey_RSA(RNG* rng, char* fName, int directive, int fmt, int XMEMSET(fOutNameBuf, 0, fNameSz + fExtSz); XMEMCPY(fOutNameBuf, fName, fNameSz); - derBuf = XMALLOC(maxDerBufSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); + derBuf = (byte*) XMALLOC(maxDerBufSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); if (derBuf == NULL) { XFREE(fOutNameBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); return MEMORY_E;