I've noticed that #333 is missing zeroize for the SIMD backends, and that the zeroize crate seems to support SIMD registers. There are 2 ways that I can identify for incorporating zeroize. Both methods, however, would require the MSRV to be increased to 1.60.
Method 1
The first method is kind of easy, as it requires a relatively small amount of code, but it is a little inefficient. Basically, .zeroize() could be called on the SIMD results arrays, as well as the state arrays after generating results.
Pros:
- it should successfully zeroize the SIMD registers
Cons:
- every time the SIMD backend generates either a block or
PAR_BLOCKS blocks of output, it will need to zeroize the SIMD registers
Method 2
This would involve a little bit of a reimplementation of some features that chacha20 previously had (persisting Core structs via autodetect.rs and backend.rs). The persisting Core structs can provide a few benefits:
- they should only be initialized once
.zeroize() could only be applied once to the SIMD registers, instead of every time the Core generates results
- the RNG shouldn't need
unsafe fn generate(&mut self, dest_ptr: *mut u8, num_blocks: usize) to achieve a performance that is comparable with .apply_keystream() on AVX2... unless .apply_keystream()'s performance also increases by 5-7%. The RNG could still benefit from using a pointer though.
Cons:
- a little more code would be required
Here's a link to v0.8.1 for reference. I will need it if I will be adding the functionality back:
https://github.com/RustCrypto/stream-ciphers/blob/338c078d731692fba3b8256e45de2c3e334d46d8/chacha20/src/backend.rs
I've noticed that #333 is missing
zeroizefor the SIMD backends, and that thezeroizecrate seems to support SIMD registers. There are 2 ways that I can identify for incorporatingzeroize. Both methods, however, would require the MSRV to be increased to1.60.Method 1
The first method is kind of easy, as it requires a relatively small amount of code, but it is a little inefficient. Basically,
.zeroize()could be called on the SIMD results arrays, as well as the state arrays after generating results.Pros:
Cons:
PAR_BLOCKSblocks of output, it will need to zeroize the SIMD registersMethod 2
This would involve a little bit of a reimplementation of some features that
chacha20previously had (persistingCorestructs viaautodetect.rsandbackend.rs). The persistingCorestructs can provide a few benefits:.zeroize()could only be applied once to the SIMD registers, instead of every time theCoregenerates resultsunsafe fn generate(&mut self, dest_ptr: *mut u8, num_blocks: usize)to achieve a performance that is comparable with.apply_keystream()on AVX2... unless.apply_keystream()'s performance also increases by 5-7%. The RNG could still benefit from using a pointer though.Cons:
Here's a link to
v0.8.1for reference. I will need it if I will be adding the functionality back:https://github.com/RustCrypto/stream-ciphers/blob/338c078d731692fba3b8256e45de2c3e334d46d8/chacha20/src/backend.rs