mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-11 19:00:02 +01:00
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:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user