Hi Niels,
Niels Möller nisse@lysator.liu.se writes:
So my question: Would it improve security if Nettle is changed to make more of an effort of explicitly clear deallocated (or otherwise no longer used) memory on the heap and the stack? Or maybe make an mainly regarding the stack; an applications can configure custom heap allocation functions, and that way ensure that memory is cleared on free, but there's no corresponding application control over Nettle's stack usage.
While I cannot speak extensively to the security implications of this approach, we include this patch[1] in the gnutls package in CentOS Stream, to clear stack-allocated objects in Nettle to satisfy FIPS 140-3 zeroization requirements.
For heap allocated objects, applications indeed have an option to install custom memory allocation functions, though implementing this is usually not straightforward[2][3].
Footnotes: [1] https://gitlab.com/redhat/centos-stream/rpms/gnutls/-/blob/c10s/nettle-3.8-z...
[2] https://gitlab.com/gnutls/gnutls/-/merge_requests/1554
[3] https://gitlab.com/gnutls/gnutls/-/merge_requests/1635
Regards,