Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User managed secret-memory #45

Open
koraa opened this issue Aug 13, 2023 · 1 comment
Open

User managed secret-memory #45

koraa opened this issue Aug 13, 2023 · 1 comment

Comments

@koraa
Copy link

koraa commented Aug 13, 2023

One of the goals in Rosenpass was to allow using custom allocators for secret memory. Right now we are using sodium_malloc/sodium_free for instance.

Due to the reliance on a C library (libsodium) this is not a perfect choice, but allowing user-managed memory is still useful to comprehensively support features like zeroization.

In Rosenpass we opt for a low-level solution, passing all memory as slices:

pub trait KEM {
    const SK_LEN: usize;
    const PK_LEN: usize;
    const CT_LEN: usize;
    const SHK_LEN: usize;

    fn keygen(sk: &mut [u8], pk: &mut [u8]) -> Result<(), RosenpassError>;
    fn encaps(shk: &mut [u8], ct: &mut [u8], pk: &[u8]) -> Result<(), RosenpassError>;
    fn decaps(shk: &mut [u8], sk: &[u8], ct: &[u8]) -> Result<(), RosenpassError>;
}

A more comprehensive solution might involve the use of a custom allocation.

We should figure out a way to enable user-controlled secret allocation in HPKE!

@rozbb
Copy link
Owner

rozbb commented Aug 21, 2023

This is a great point, thank you. I think a reasonable way to go about this is to change the KEM API to take mutable refs to the output slice, as you suggest. It's not as clean, but I don't see a better way at the moment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants