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

Use SecretBox for all secret values #144

Merged
merged 26 commits into from
Sep 30, 2024

Conversation

dvdplm
Copy link
Contributor

@dvdplm dvdplm commented Aug 23, 2024

Wrap more secrets in SecretBox.

Keeping this PR as a draft, given it depends on a pre-release candidate for secrecy (see this issue).

When crypto-bigint v0.6 is released we can address one more TODO (this one).

Fixes #77

Copy link

codecov bot commented Aug 26, 2024

Codecov Report

Attention: Patch coverage is 96.92308% with 6 lines in your changes missing coverage. Please review.

Project coverage is 90.88%. Comparing base (9f9a0c4) to head (66b313f).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
synedrion/src/cggmp21/protocols/signing.rs 0.00% 3 Missing ⚠️
synedrion/src/cggmp21/protocols/presigning.rs 93.54% 2 Missing ⚠️
synedrion/src/paillier/params.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #144      +/-   ##
==========================================
+ Coverage   90.72%   90.88%   +0.15%     
==========================================
  Files          44       45       +1     
  Lines        8066     8162      +96     
==========================================
+ Hits         7318     7418     +100     
+ Misses        748      744       -4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@dvdplm dvdplm marked this pull request as ready for review September 5, 2024 22:46
@dvdplm dvdplm marked this pull request as draft September 5, 2024 22:47
@dvdplm dvdplm marked this pull request as ready for review September 6, 2024 14:28
@@ -542,14 +555,17 @@ impl<P: SchemeParams, I: Debug + Clone + Ord + Serialize> FinalizableToNextRound
let cap_delta = cap_gamma * self.context.k;

let alpha_sum: Signed<_> = payloads.values().map(|p| p.alpha).sum();
let beta_sum: Signed<_> = artifacts.values().map(|p| p.beta).sum();
let beta_sum: Signed<_> = artifacts.values().map(|p| p.beta.expose_secret()).sum();
Copy link
Member

Choose a reason for hiding this comment

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

I wonder how far should we go to protect the secrets? In this sum, for example, the safest way to do it is to actually write out an explicit loop mutating the sum inside a SecretBox.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I have the same concern and a poor intuition for what "good enough" means here.

By explicit loop, do you mean something like this?

       let beta_sum =
            artifacts
                .values()
                .fold(SecretBox::new(Box::new(Signed::default())), |mut sum, p| {
                    *sum.expose_secret_mut() = sum.expose_secret().add(p.beta.expose_secret());
                    sum
                });

In this case here I'm not so sure it's worth it. One line below we'd expose_secret again to add beta_sum to delta. But perhaps delta is a secret too? 😱


let p_rem_mod = p_rem_half.to_mod(self.precomputed_mod_p());
let q_rem_mod = q_rem_half.to_mod(self.precomputed_mod_q());

// TODO (#77): zeroize intermediate values
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps they can be wrapped in SecretBox so that we can let RAII do its job? Or would that make too much boilerplate?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it would be very noisy and difficult to read.

I wonder if a macro could help us to be able to say, dunno, secrets_containing_block! { /* lots of secret calculations here, intermediate values included */ } and write normal code inside the block and be sure that everything inside will be zeroized and return values will be SecretBoxed.

Could be a rather big undertaking though.

@fjarri
Copy link
Member

fjarri commented Sep 26, 2024

I think this one should go in next, could you rebase it to master?

)
}

pub fn commit_wide(
&self,
secret: &Signed<P::WideUint>,
// TODO(dp): @reviewers Question unrelated to the PR, just something I noticed: Why is the
Copy link
Member

Choose a reason for hiding this comment

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

I guess it's just a naming issue. Technically, this method is commit_wide_secret_wide_randomizer(), and the next one is commit_normal_secret_xwide_randomizer(). These are just overrides for the same operations with different types of arguments. This could be made more straightforward if #60 is fixed.

@fjarri fjarri merged commit 6a38f1f into entropyxyz:master Sep 30, 2024
6 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Sep 30, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add zeroization to secret values
2 participants