Currently, when we call something like crypto::cbox::cbox, we do the following heap allocations:
Allocate a vector to hold the message + padding
Allocate a vector to hold the ciphertext + padding
Allocate and return a vector to hold the ciphertext without padding
We could cut this down to a single allocation for these sorts of functions, a single vector for the ciphertext output, by using some custom types. The idea is that we could wrap a vector that already has the padding allocated, then just let people use that type like a normal vector, hiding the zero-padding internally.
Two new types we could use for this would be:
Message
Ciphertext
(final names TBD)
We'd need to basically emulate the standard vector interface, and make sure to have functions like as_slice() and as_slice_mut() so people can pass them into e.g. file reading functions without any extra overhead.
Currently, when we call something like
crypto::cbox::cbox
, we do the following heap allocations:We could cut this down to a single allocation for these sorts of functions, a single vector for the ciphertext output, by using some custom types. The idea is that we could wrap a vector that already has the padding allocated, then just let people use that type like a normal vector, hiding the zero-padding internally.
Two new types we could use for this would be:
(final names TBD)
We'd need to basically emulate the standard vector interface, and make sure to have functions like
as_slice()
andas_slice_mut()
so people can pass them into e.g. file reading functions without any extra overhead.