2
0

bzero is nonstandard. Replace with memset_s.

This commit is contained in:
Maarten Billemont 2017-09-24 13:14:16 -04:00
parent 0a024b2594
commit fafe56166e
5 changed files with 16 additions and 15 deletions

View File

@ -487,7 +487,7 @@ void AES_ECB_encrypt(uint8_t *output, const uint8_t *input, const uint32_t lengt
// The next function call encrypts the PlainText with the Key using AES algorithm. // The next function call encrypts the PlainText with the Key using AES algorithm.
Cipher(); Cipher();
bzero( RoundKey, keyExpSize ); memset_s( RoundKey, keyExpSize, 0, keyExpSize );
} }
void AES_ECB_decrypt(uint8_t *output, const uint8_t *input, const uint32_t length, const uint8_t *key) void AES_ECB_decrypt(uint8_t *output, const uint8_t *input, const uint32_t length, const uint8_t *key)
@ -502,7 +502,7 @@ void AES_ECB_decrypt(uint8_t *output, const uint8_t *input, const uint32_t lengt
InvCipher(); InvCipher();
bzero( RoundKey, keyExpSize ); memset_s( RoundKey, keyExpSize, 0, keyExpSize );
} }
@ -560,7 +560,7 @@ void AES_CBC_encrypt_buffer(uint8_t* output, uint8_t* input, uint32_t length, co
Cipher(); Cipher();
} }
bzero( RoundKey, keyExpSize ); memset_s( RoundKey, keyExpSize, 0, keyExpSize );
} }
void AES_CBC_decrypt_buffer(uint8_t* output, uint8_t* input, uint32_t length, const uint8_t* key, const uint8_t* iv) void AES_CBC_decrypt_buffer(uint8_t* output, uint8_t* input, uint32_t length, const uint8_t* key, const uint8_t* iv)
@ -599,7 +599,7 @@ void AES_CBC_decrypt_buffer(uint8_t* output, uint8_t* input, uint32_t length, co
InvCipher(); InvCipher();
} }
bzero( RoundKey, keyExpSize ); memset_s( RoundKey, keyExpSize, 0, keyExpSize );
} }
#endif // #if defined(AES_CBC) && (AES_CBC == 1) #endif // #if defined(AES_CBC) && (AES_CBC == 1)

View File

@ -217,12 +217,12 @@ uint8_t const *mpw_kdf_blake2b(const size_t subkeySize, const uint8_t *key, cons
} }
uint8_t saltBuf[crypto_generichash_blake2b_SALTBYTES]; uint8_t saltBuf[crypto_generichash_blake2b_SALTBYTES];
bzero( saltBuf, sizeof saltBuf ); memset( saltBuf, 0, sizeof saltBuf );
if (id) if (id)
mpw_uint64( id, saltBuf ); mpw_uint64( id, saltBuf );
uint8_t personalBuf[crypto_generichash_blake2b_PERSONALBYTES]; uint8_t personalBuf[crypto_generichash_blake2b_PERSONALBYTES];
bzero( personalBuf, sizeof saltBuf ); memset( personalBuf, 0, sizeof personalBuf );
if (personal && strlen( personal )) if (personal && strlen( personal ))
memcpy( personalBuf, personal, strlen( personal ) ); memcpy( personalBuf, personal, strlen( personal ) );
@ -274,7 +274,7 @@ static uint8_t const *mpw_aes(bool encrypt, const uint8_t *key, const size_t key
// IV = zero // IV = zero
uint8_t iv[16]; uint8_t iv[16];
bzero( (void *)iv, sizeof( iv ) ); memset( iv, 0, sizeof iv );
// Add PKCS#7 padding // Add PKCS#7 padding
uint32_t aesSize = (uint32_t)*bufSize; uint32_t aesSize = (uint32_t)*bufSize;
@ -289,8 +289,8 @@ static uint8_t const *mpw_aes(bool encrypt, const uint8_t *key, const size_t key
AES_CBC_encrypt_buffer( resultBuf, aesBuf, aesSize, key, iv ); AES_CBC_encrypt_buffer( resultBuf, aesBuf, aesSize, key, iv );
else else
AES_CBC_decrypt_buffer( resultBuf, aesBuf, aesSize, key, iv ); AES_CBC_decrypt_buffer( resultBuf, aesBuf, aesSize, key, iv );
bzero( aesBuf, aesSize ); memset_s( aesBuf, aesSize, 0, aesSize );
bzero( iv, 16 ); memset_s( iv, 16, 0, 16 );
// Truncate PKCS#7 padding // Truncate PKCS#7 padding
if (encrypt) if (encrypt)

View File

@ -186,10 +186,10 @@ bcrypt_hashpass(const char *key, const uint8_t *salt, char *encrypted,
snprintf( encrypted, 8, "$2%c$%2.2u$", minor, logr ); snprintf( encrypted, 8, "$2%c$%2.2u$", minor, logr );
encode_base64( encrypted + 7, csalt, BCRYPT_MAXSALT ); encode_base64( encrypted + 7, csalt, BCRYPT_MAXSALT );
encode_base64( encrypted + 7 + 22, ciphertext, 4 * BCRYPT_WORDS - 1 ); encode_base64( encrypted + 7 + 22, ciphertext, 4 * BCRYPT_WORDS - 1 );
bzero( &state, sizeof( state ) ); memset_s( &state, sizeof state, 0, sizeof state );
bzero( ciphertext, sizeof( ciphertext ) ); memset_s( ciphertext, sizeof ciphertext, 0, sizeof ciphertext );
bzero( csalt, sizeof( csalt ) ); memset_s( csalt, sizeof csalt, 0, sizeof csalt );
bzero( cdata, sizeof( cdata ) ); memset_s( cdata, sizeof cdata, 0, sizeof cdata );
return 0; return 0;
inval: inval:

View File

@ -128,7 +128,7 @@ const char *mpw_getpass(const char *prompt) {
return NULL; return NULL;
password = strdup( answer ); password = strdup( answer );
bzero( answer, strlen( answer ) ); memset_s( answer, strlen( answer ), 0, strlen( answer ) );
return password; return password;
} }

View File

@ -272,7 +272,8 @@ void cli_free(Arguments *args, Operation *operation) {
void cli_args(Arguments *args, Operation *operation, const int argc, char *const argv[]) { void cli_args(Arguments *args, Operation *operation, const int argc, char *const argv[]) {
for (int opt; (opt = getopt( argc, argv, "u:U:m:M:t:P:c:a:p:C:f:F:R:vqh" )) != EOF; optarg? bzero( optarg, strlen( optarg ) ): NULL) for (int opt; (opt = getopt( argc, argv, "u:U:m:M:t:P:c:a:p:C:f:F:R:vqh" )) != EOF;
optarg? memset_s( optarg, strlen( optarg ), 0, strlen( optarg ) ): 0)
switch (opt) { switch (opt) {
case 'u': case 'u':
args->fullName = optarg && strlen( optarg )? strdup( optarg ): NULL; args->fullName = optarg && strlen( optarg )? strdup( optarg ): NULL;