Use {0} initializer for all stack allocated char arrays

Lots of places in the code were already using {0} to initialize stack char
arrays, but memset() was being used as well.  This commit removes all
unnecessary memset() calls against char arrays that are already initialized
via {0} (which sets all members to zero for such arrays).
This commit is contained in:
Michael Rash
2013-05-21 22:00:15 -04:00
parent 2e2e7fcc0e
commit 52462e7dba
20 changed files with 79 additions and 116 deletions

View File

@@ -118,19 +118,14 @@ static void
rij_salt_and_iv(RIJNDAEL_context *ctx, const char *key,
const int key_len, const unsigned char *data, const int mode_flag)
{
char pw_buf[RIJNDAEL_MAX_KEYSIZE];
unsigned char tmp_buf[MD5_DIGEST_LEN+RIJNDAEL_MAX_KEYSIZE+RIJNDAEL_BLOCKSIZE];
unsigned char kiv_buf[RIJNDAEL_MAX_KEYSIZE+RIJNDAEL_BLOCKSIZE]; /* Key and IV buffer */
unsigned char md5_buf[MD5_DIGEST_LEN]; /* Buffer for computed md5 hash */
char pw_buf[RIJNDAEL_MAX_KEYSIZE] = {0};
unsigned char tmp_buf[MD5_DIGEST_LEN+RIJNDAEL_MAX_KEYSIZE+RIJNDAEL_BLOCKSIZE] = {0};
unsigned char kiv_buf[RIJNDAEL_MAX_KEYSIZE+RIJNDAEL_BLOCKSIZE] = {0}; /* Key and IV buffer */
unsigned char md5_buf[MD5_DIGEST_LEN] = {0}; /* Buffer for computed md5 hash */
int final_key_len = 0;
size_t kiv_len = 0;
memset(pw_buf, 0x00, RIJNDAEL_MAX_KEYSIZE);
memset(tmp_buf, 0x00, MD5_DIGEST_LEN+RIJNDAEL_MAX_KEYSIZE+RIJNDAEL_BLOCKSIZE);
memset(kiv_buf, 0x00, RIJNDAEL_MAX_KEYSIZE+RIJNDAEL_BLOCKSIZE);
memset(md5_buf, 0x00, MD5_DIGEST_LEN);
if(mode_flag == FKO_ENC_MODE_CBC_LEGACY_IV)
{
/* Pad the pw with '0' chars up to the minimum Rijndael key size.

View File

@@ -209,8 +209,6 @@ int fko_set_spa_hmac(fko_ctx_t ctx,
if(hmac_key_len > MAX_DIGEST_BLOCK_LEN)
return(FKO_ERROR_INVALID_HMAC_KEY_LEN);
memset(hmac, 0x00, SHA512_DIGEST_STR_LEN);
if(ctx->hmac_type == FKO_HMAC_MD5)
{
hmac_md5(ctx->encrypted_msg,

View File

@@ -103,9 +103,6 @@ hmac_md5_init(hmac_md5_ctx *ctx, const char *key, const int key_len)
unsigned char init_key[MAX_DIGEST_BLOCK_LEN] = {0};
int final_len = key_len;
memset(final_key, 0x00, MAX_DIGEST_BLOCK_LEN);
memset(init_key, 0x00, MAX_DIGEST_BLOCK_LEN);
if(key_len > MAX_DIGEST_BLOCK_LEN)
final_len = MAX_DIGEST_BLOCK_LEN;
@@ -177,9 +174,6 @@ hmac_sha1_init(hmac_sha1_ctx *ctx, const char *key, const int key_len)
unsigned char init_key[MAX_DIGEST_BLOCK_LEN] = {0};
int final_len = key_len;
memset(final_key, 0x00, MAX_DIGEST_BLOCK_LEN);
memset(init_key, 0x00, MAX_DIGEST_BLOCK_LEN);
if(key_len > MAX_DIGEST_BLOCK_LEN)
final_len = MAX_DIGEST_BLOCK_LEN;
@@ -251,9 +245,6 @@ hmac_sha256_init(hmac_sha256_ctx *ctx, const char *key, const int key_len)
unsigned char init_key[MAX_DIGEST_BLOCK_LEN] = {0};
int final_len = key_len;
memset(final_key, 0x00, MAX_DIGEST_BLOCK_LEN);
memset(init_key, 0x00, MAX_DIGEST_BLOCK_LEN);
if(key_len > MAX_DIGEST_BLOCK_LEN)
final_len = MAX_DIGEST_BLOCK_LEN;
@@ -324,8 +315,6 @@ hmac_sha384_init(hmac_sha384_ctx *ctx, const char *key, const int key_len)
unsigned char final_key[MAX_DIGEST_BLOCK_LEN] = {0};
int final_len = key_len;
memset(final_key, 0x00, MAX_DIGEST_BLOCK_LEN);
if(key_len > MAX_DIGEST_BLOCK_LEN)
final_len = MAX_DIGEST_BLOCK_LEN;
@@ -388,8 +377,6 @@ hmac_sha512_init(hmac_sha512_ctx *ctx, const char *key, const int key_len)
unsigned char final_key[MAX_DIGEST_BLOCK_LEN] = {0};
int final_len = key_len;
memset(final_key, 0x00, MAX_DIGEST_BLOCK_LEN);
if(key_len > MAX_DIGEST_BLOCK_LEN)
final_len = MAX_DIGEST_BLOCK_LEN;