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

add array support for secrecy #1239

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tzilist
Copy link

@tzilist tzilist commented Oct 10, 2024

We have some code where we are using fixed length arrays and would like for those to remain secret. This PR adds the ability to do the following

struct MySecret {
  // normal secret box
  inner_regular: SecretBox<[u8; 32]>,
  // helper type
  inner_with_helper_type: SecretArray<u8, 32>,
}

Adds the ability to use [S; N] as a secret. Notably, CloneableSecret was not implemented for [S; N]

Adds a new helper type called SecretArray that is just SecretBox<[S; N]>

@@ -258,6 +275,8 @@ impl CloneableSecret for u64 {}
impl CloneableSecret for u128 {}
impl CloneableSecret for usize {}

impl<const N: usize, T> CloneableSecret for [T; N] where T: CloneableSecret {}
Copy link
Member

Choose a reason for hiding this comment

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

I opened #1245 with just this since it's uncontroversial

Comment on lines +216 to +224
impl<S, const N: usize> From<[S; N]> for SecretArray<S, N>
where
S: Zeroize,
[S; N]: Zeroize,
{
fn from(array: [S; N]) -> Self {
Self::from(Box::new(array))
}
}
Copy link
Member

Choose a reason for hiding this comment

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

This has various issues which are a little bit concerning:

  • it's moving the array instead of taking a reference, which may make a copy
  • it's sidestepping the constructors which otherwise exist for SecretBox which go out of the way to avoid leaving copies on the stack

The big difference between this and SecretSlice/SecretString is those types are ultimately heap-backed.

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.

2 participants