bc-csharp icon indicating copy to clipboard operation
bc-csharp copied to clipboard

KEM PrivateKeyParameters (e.g. FrodoPrivateKeyParameters) not disposable

Open arnomi opened this issue 1 year ago • 1 comments

I am trying to dispose a private KEM key after usage so that it does not linger around in managed memory. All PrivateKeyParameters of KEMs (e.g. FrodoPrivateKeyParameters) seem not to be disposable. Since they also make copies of the provided key material in their constructors it seems impossible to wipe the keys from managed memory. I am wondering whether I am overlooking something or whether there is an oversight that these should implement IDisposable.

arnomi avatar Oct 01 '23 18:10 arnomi

I have the same "problem" and solved it (with an emergency solution) using reflection to access the private fields and wipe the byte array contents. I've seen Bouncy Castle code to wipe keys somewhere, but it seems not to be a common task. Also IDisposable is hard to find. If I could only access the key arrays somehow without reflection - or there would be at last a Clear method - it'd really help a lot... Making everything disposable instead would be a huge breaking change in the current API.

nd1012 avatar Oct 15 '23 07:10 nd1012