Prevent compiler to optiize-out memset for on-stack variables.

Also see
https://cryptocoding.net/index.php/Coding_rules#Prevent_compiler_interference_with_security-critical_operations

The used code is inspired by the code in Blake2 implementation.
This commit is contained in:
Milan Broz
2015-01-11 20:26:45 +01:00
parent dc40b91cdf
commit f7b61b2617
12 changed files with 51 additions and 31 deletions

View File

@@ -35,7 +35,7 @@ struct volume_key *crypt_alloc_volume_key(unsigned keylength, const char *key)
if (key)
memcpy(&vk->key, key, keylength);
else
memset(&vk->key, 0, keylength);
crypt_memzero(&vk->key, keylength);
return vk;
}
@@ -43,7 +43,7 @@ struct volume_key *crypt_alloc_volume_key(unsigned keylength, const char *key)
void crypt_free_volume_key(struct volume_key *vk)
{
if (vk) {
memset(vk->key, 0, vk->keylength);
crypt_memzero(vk->key, vk->keylength);
vk->keylength = 0;
free(vk);
}