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

Switch to shared memory instead of HSM allocations #156

Closed
wants to merge 1 commit into from

Conversation

rpiasetskyi
Copy link
Contributor

Allocate shared memory on the client side and pass addresses of output parameters to HSM.

Allocate shared memory on the client side and pass addresses of output
parameters to HSM.
Copy link
Contributor

@inorick inorick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks you for this. I only had a nit-pick.

(key, nonce, aad, plaintext)
let tag = pool
.alloc(crate::crypto::chacha20poly1305::TAG_SIZE)
.unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use expect instead.

ciphertext.as_mut_slice(),
) {
Ok(computed_tag) => {
if computed_tag.len() != tag.as_slice().len() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should never happen in practice, right?

@@ -210,3 +221,38 @@ fn encrypt_chachapoly_external_key() {
};
assert_eq!(plaintext.as_slice(), org_plaintext.as_slice())
}

#[test]
fn encrypt_chachapoly_invalid_tag_size() {
Copy link
Contributor

@inorick inorick Aug 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to see this is tested now too.

Self::new(data.as_ptr(), data.len())
}

pub fn as_slice(&self) -> &[u8] {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we find ourselves getting tired of calling as_slice explicitly we can think about implementing the Deref trait for ExternalMemory.

Copy link
Contributor

@SCingolani SCingolani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am still unconvinced about why,
a) Heimlig needs to know about "External" memory, or any other type of memory.
b) Why do we want to use raw pointer + size instead of a slice.

From the point of view of Heimlig, it gets a request with a slice of data associated with that request, no special meaning about where this data is. For In, InOut or Out parameters, we can use the semantics of &[T], and &mut [T]. The lifetimes will "transit" our program from request to response, where we finally drop the slices.

The guarantee of no aliasing of the memory pointed to by the slice is upheld not by Heimlig but by the Host anyway, and in Rust we rely on the borrow checker once we have the slices.

Not using slices for the sake of not having lifetimes seems to me like a misstep, after all, it is the idiomatic way of doing things in Rust! Not using slices because this is somehow special memory, also does not sound to me quite compelling, after all, this current implementation is not doing anything special with the memory anyway.

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

Successfully merging this pull request may close these issues.

3 participants