[PATCH] Use memset for short constant length wipememory2

Jussi Kivilinna jussi.kivilinna at iki.fi
Sun Mar 28 15:09:08 CEST 2021


On 28.3.2021 5.05, Jacob Bachmeyer via Gcrypt-devel wrote:
> Jussi Kivilinna wrote:
>> Use of memset allows better code generation by compiler -
>> for example, use of vector registers for memory clearing.
> 
> 
> Are you sure that this is a good idea?  The comment indicates that the original purpose of not using memset was to ensure that a compiler cannot optimize the call away.
> 

New approach uses inline assembly memory barrier to prevent optimizing away preceding memset:

     memset(ptr_memory_to_wipe, 0, memory_length);
     asm volatile ("\n"::"r"(ptr_memory_to_wipe):"memory");

I'll update the comment to better explain this.

-Jussi



More information about the Gcrypt-devel mailing list