use XMEMSET instead of memset for security
parent
1f53805a5e
commit
8a4b656ae9
|
@ -92,10 +92,10 @@ int wolfsslBenchmark(int timer, int* option)
|
|||
printf("\n");
|
||||
printf("AES-CBC ");
|
||||
wolfsslStats(start, AES_BLOCK_SIZE, blocks);
|
||||
memset(plain, 0, AES_BLOCK_SIZE);
|
||||
memset(cipher, 0, AES_BLOCK_SIZE);
|
||||
memset(key, 0, AES_BLOCK_SIZE);
|
||||
memset(iv, 0, AES_BLOCK_SIZE);
|
||||
XMEMSET(plain, 0, AES_BLOCK_SIZE);
|
||||
XMEMSET(cipher, 0, AES_BLOCK_SIZE);
|
||||
XMEMSET(key, 0, AES_BLOCK_SIZE);
|
||||
XMEMSET(iv, 0, AES_BLOCK_SIZE);
|
||||
free(plain);
|
||||
free(cipher);
|
||||
free(key);
|
||||
|
@ -131,10 +131,10 @@ int wolfsslBenchmark(int timer, int* option)
|
|||
}
|
||||
printf("AES-CTR ");
|
||||
wolfsslStats(start, AES_BLOCK_SIZE, blocks);
|
||||
memset(plain, 0, AES_BLOCK_SIZE);
|
||||
memset(cipher, 0, AES_BLOCK_SIZE);
|
||||
memset(key, 0, AES_BLOCK_SIZE);
|
||||
memset(iv, 0, AES_BLOCK_SIZE);
|
||||
XMEMSET(plain, 0, AES_BLOCK_SIZE);
|
||||
XMEMSET(cipher, 0, AES_BLOCK_SIZE);
|
||||
XMEMSET(key, 0, AES_BLOCK_SIZE);
|
||||
XMEMSET(iv, 0, AES_BLOCK_SIZE);
|
||||
free(plain);
|
||||
free(cipher);
|
||||
free(key);
|
||||
|
@ -171,10 +171,10 @@ int wolfsslBenchmark(int timer, int* option)
|
|||
}
|
||||
printf("3DES ");
|
||||
wolfsslStats(start, DES3_BLOCK_SIZE, blocks);
|
||||
memset(plain, 0, DES3_BLOCK_SIZE);
|
||||
memset(cipher, 0, DES3_BLOCK_SIZE);
|
||||
memset(key, 0, DES3_BLOCK_SIZE);
|
||||
memset(iv, 0, DES3_BLOCK_SIZE);
|
||||
XMEMSET(plain, 0, DES3_BLOCK_SIZE);
|
||||
XMEMSET(cipher, 0, DES3_BLOCK_SIZE);
|
||||
XMEMSET(key, 0, DES3_BLOCK_SIZE);
|
||||
XMEMSET(iv, 0, DES3_BLOCK_SIZE);
|
||||
free(plain);
|
||||
free(cipher);
|
||||
free(key);
|
||||
|
@ -213,10 +213,10 @@ int wolfsslBenchmark(int timer, int* option)
|
|||
}
|
||||
printf("Camellia ");
|
||||
wolfsslStats(start, CAMELLIA_BLOCK_SIZE, blocks);
|
||||
memset(plain, 0, CAMELLIA_BLOCK_SIZE);
|
||||
memset(cipher, 0, CAMELLIA_BLOCK_SIZE);
|
||||
memset(key, 0, CAMELLIA_BLOCK_SIZE);
|
||||
memset(iv, 0, CAMELLIA_BLOCK_SIZE);
|
||||
XMEMSET(plain, 0, CAMELLIA_BLOCK_SIZE);
|
||||
XMEMSET(cipher, 0, CAMELLIA_BLOCK_SIZE);
|
||||
XMEMSET(key, 0, CAMELLIA_BLOCK_SIZE);
|
||||
XMEMSET(iv, 0, CAMELLIA_BLOCK_SIZE);
|
||||
free(plain);
|
||||
free(cipher);
|
||||
free(key);
|
||||
|
@ -250,8 +250,8 @@ int wolfsslBenchmark(int timer, int* option)
|
|||
Md5Final(&md5, digest);
|
||||
printf("MD5 ");
|
||||
wolfsslStats(start, MEGABYTE, blocks);
|
||||
memset(plain, 0, MEGABYTE);
|
||||
memset(digest, 0, MD5_DIGEST_SIZE);
|
||||
XMEMSET(plain, 0, MEGABYTE);
|
||||
XMEMSET(digest, 0, MD5_DIGEST_SIZE);
|
||||
free(plain);
|
||||
free(digest);
|
||||
blocks = 0;
|
||||
|
@ -283,8 +283,8 @@ int wolfsslBenchmark(int timer, int* option)
|
|||
ShaFinal(&sha, digest);
|
||||
printf("Sha ");
|
||||
wolfsslStats(start, MEGABYTE, blocks);
|
||||
memset(plain, 0, MEGABYTE);
|
||||
memset(digest, 0, SHA_DIGEST_SIZE);
|
||||
XMEMSET(plain, 0, MEGABYTE);
|
||||
XMEMSET(digest, 0, SHA_DIGEST_SIZE);
|
||||
free(plain);
|
||||
free(digest);
|
||||
blocks = 0;
|
||||
|
@ -316,8 +316,8 @@ int wolfsslBenchmark(int timer, int* option)
|
|||
Sha256Final(&sha256, digest);
|
||||
printf("Sha256 ");
|
||||
wolfsslStats(start, MEGABYTE, blocks);
|
||||
memset(plain, 0, MEGABYTE);
|
||||
memset(digest, 0, SHA256_DIGEST_SIZE);
|
||||
XMEMSET(plain, 0, MEGABYTE);
|
||||
XMEMSET(digest, 0, SHA256_DIGEST_SIZE);
|
||||
free(plain);
|
||||
free(digest);
|
||||
/* resets used for debug, uncomment if needed */
|
||||
|
@ -350,8 +350,8 @@ int wolfsslBenchmark(int timer, int* option)
|
|||
Sha384Final(&sha384, digest);
|
||||
printf("Sha384 ");
|
||||
wolfsslStats(start, MEGABYTE, blocks);
|
||||
memset(plain, 0, MEGABYTE);
|
||||
memset(digest, 0, SHA384_DIGEST_SIZE);
|
||||
XMEMSET(plain, 0, MEGABYTE);
|
||||
XMEMSET(digest, 0, SHA384_DIGEST_SIZE);
|
||||
free(plain);
|
||||
free(digest);
|
||||
blocks = 0;
|
||||
|
@ -383,8 +383,8 @@ int wolfsslBenchmark(int timer, int* option)
|
|||
Sha512Final(&sha512, digest);
|
||||
printf("Sha512 ");
|
||||
wolfsslStats(start, MEGABYTE, blocks);
|
||||
memset(plain, 0, MEGABYTE);
|
||||
memset(digest, 0, SHA512_DIGEST_SIZE);
|
||||
XMEMSET(plain, 0, MEGABYTE);
|
||||
XMEMSET(digest, 0, SHA512_DIGEST_SIZE);
|
||||
free(plain);
|
||||
free(digest);
|
||||
blocks = 0;
|
||||
|
@ -416,8 +416,8 @@ int wolfsslBenchmark(int timer, int* option)
|
|||
Blake2bFinal(&b2b, digest, BLAKE_DIGEST_SIZE);
|
||||
printf("Blake2b ");
|
||||
wolfsslStats(start, MEGABYTE, blocks);
|
||||
memset(plain, 0, MEGABYTE);
|
||||
memset(digest, 0, BLAKE_DIGEST_SIZE);
|
||||
XMEMSET(plain, 0, MEGABYTE);
|
||||
XMEMSET(digest, 0, BLAKE_DIGEST_SIZE);
|
||||
free(plain);
|
||||
free(digest);
|
||||
}
|
||||
|
|
|
@ -217,25 +217,25 @@ int wolfsslDecrypt(char* alg, char* mode, byte* pwdKey, byte* key, int size,
|
|||
else {
|
||||
fwrite(output, 1, tempMax, outFile);
|
||||
|
||||
memset(input, 0, tempMax);
|
||||
memset(output, 0, tempMax);
|
||||
XMEMSET(input, 0, tempMax);
|
||||
XMEMSET(output, 0, tempMax);
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* writes output to the outFile */
|
||||
fwrite(output, 1, tempMax, outFile);
|
||||
|
||||
memset(input, 0, tempMax);
|
||||
memset(output, 0, tempMax);
|
||||
XMEMSET(input, 0, tempMax);
|
||||
XMEMSET(output, 0, tempMax);
|
||||
|
||||
currLoopFlag++;
|
||||
length -= tempMax;
|
||||
}
|
||||
/* closes the opened files and frees memory */
|
||||
memset(input, 0, MAX);
|
||||
memset (output, 0, MAX);
|
||||
XMEMSET(input, 0, MAX);
|
||||
XMEMSET (output, 0, MAX);
|
||||
wolfsslFreeBins(input, output, NULL, NULL, NULL);
|
||||
memset(key, 0, size);
|
||||
XMEMSET(key, 0, size);
|
||||
/* Use the cyassl FreeRng to free rng */
|
||||
FreeRng(&rng);
|
||||
fclose(inFile);
|
||||
|
|
|
@ -276,17 +276,17 @@ int wolfsslEncrypt(char* alg, char* mode, byte* pwdKey, byte* key, int size,
|
|||
if (length < 0)
|
||||
printf("length went past zero.\n");
|
||||
if (input != NULL)
|
||||
memset(input, 0, tempMax);
|
||||
XMEMSET(input, 0, tempMax);
|
||||
if (output != NULL)
|
||||
memset(output, 0, tempMax);
|
||||
XMEMSET(output, 0, tempMax);
|
||||
}
|
||||
|
||||
/* closes the opened files and frees the memory */
|
||||
fclose(inFile);
|
||||
memset(key, 0, size);
|
||||
memset(iv, 0 , block);
|
||||
memset(alg, 0, size);
|
||||
memset(mode, 0 , block);
|
||||
XMEMSET(key, 0, size);
|
||||
XMEMSET(iv, 0 , block);
|
||||
XMEMSET(alg, 0, size);
|
||||
XMEMSET(mode, 0 , block);
|
||||
/* Use the cyassl free for rng */
|
||||
FreeRng(&rng);
|
||||
wolfsslFreeBins(input, output, NULL, NULL, NULL);
|
||||
|
|
|
@ -41,7 +41,7 @@ int wolfsslHash(char* in, char* out, char* alg, int size)
|
|||
int length; /* length of hash */
|
||||
|
||||
output = malloc(size);
|
||||
memset(output, 0, size);
|
||||
XMEMSET(output, 0, size);
|
||||
|
||||
/* opens input file */
|
||||
inFile = fopen(in, "rb");
|
||||
|
@ -50,7 +50,7 @@ int wolfsslHash(char* in, char* out, char* alg, int size)
|
|||
length = LENGTH_IN;
|
||||
|
||||
input = malloc(length);
|
||||
memset(input, 0, length);
|
||||
XMEMSET(input, 0, length);
|
||||
for (i = 0; i < length; i++) {
|
||||
/* copies text from in to input */
|
||||
if (i <= LENGTH_IN ) {
|
||||
|
@ -67,7 +67,7 @@ int wolfsslHash(char* in, char* out, char* alg, int size)
|
|||
length = leng;
|
||||
|
||||
input = malloc(length+1);
|
||||
memset(input, 0, length+1);
|
||||
XMEMSET(input, 0, length+1);
|
||||
if (input == NULL) {
|
||||
printf("Failed to create input buffer\n");
|
||||
return FATAL_ERROR;
|
||||
|
@ -133,8 +133,8 @@ int wolfsslHash(char* in, char* out, char* alg, int size)
|
|||
}
|
||||
|
||||
/* closes the opened files and frees the memory */
|
||||
memset(input, 0, length);
|
||||
memset(output, 0, size);
|
||||
XMEMSET(input, 0, length);
|
||||
XMEMSET(output, 0, size);
|
||||
free(input);
|
||||
free(output);
|
||||
return ret;
|
||||
|
|
|
@ -249,7 +249,7 @@ int wolfsslSetup(int argc, char** argv, char action)
|
|||
}
|
||||
|
||||
if (pwdKeyChk == 1 && keyCheck == 1) {
|
||||
memset(pwdKey, 0, size);
|
||||
XMEMSET(pwdKey, 0, size);
|
||||
}
|
||||
|
||||
/* encryption function call */
|
||||
|
@ -284,9 +284,9 @@ int wolfsslSetup(int argc, char** argv, char action)
|
|||
wolfsslHelp();
|
||||
}
|
||||
/* clear and free data */
|
||||
memset(key, 0, size);
|
||||
memset(pwdKey, 0, size);
|
||||
memset(iv, 0, block);
|
||||
XMEMSET(key, 0, size);
|
||||
XMEMSET(pwdKey, 0, size);
|
||||
XMEMSET(iv, 0, block);
|
||||
wolfsslFreeBins(pwdKey, iv, key, NULL, NULL);
|
||||
}
|
||||
else
|
||||
|
|
Loading…
Reference in New Issue