libcrux icon indicating copy to clipboard operation
libcrux copied to clipboard

Turn a `&[u8; N]` into a reference a type that only contains a `[u8; N]` without copying (e.g. key, tag, nonce or ciphertext types)

Open keks opened this issue 7 months ago • 1 comments

Often, all you have as a user is a reference to an array, and you want to use that as a ciphertext or a key or similar. These types are just newtypes around byte arrays, so technically it should be fine to just cast the reference to the other type. Obviously that is unsafe in Rust, so we can't just do that.

Right now, we can just do &byte_array_ref.into(), because the types implement From<[u8;N]> and [u8; N] is Copy, so we don't need to manually clone. This seems like it copies a lot of data, but it is possible that the compiler optimizes that away anyway, so it might not be a problem to begin with.

keks avatar Jul 18 '24 07:07 keks