Skip to content

impl Zeroize for BoxedMontyParams - #1338

Closed
baloo wants to merge 1 commit into
RustCrypto:masterfrom
baloo:baloo/push-qmwlxxnxqywl
Closed

impl Zeroize for BoxedMontyParams#1338
baloo wants to merge 1 commit into
RustCrypto:masterfrom
baloo:baloo/push-qmwlxxnxqywl

Conversation

@baloo

@baloo baloo commented Sep 1, 2026

Copy link
Copy Markdown
Member

The intent is to add support for zeroize on RSA's precomputed p_params and q_params.

BoxedMontyParams got placed in an Arc in #1143 but I'm not sure I follow the reason why.

To implement Zeroize, this changes remove the Arc. The content is still placed on the heap (There is an underlying BoxedUint).

The intent is to add support for zeroize on RSA's qinv.

BoxedMontyParams got placed in an Arc in RustCrypto#1143
but I'm not sure I follow the reason why.

To implement Zeroize, this changes remove the Arc. The content is still
placed on the heap (There is an underlying BoxedUint).
@baloo
baloo marked this pull request as draft September 1, 2026 19:27
@baloo

baloo commented Sep 1, 2026

Copy link
Copy Markdown
Member Author

Let's make that a draft until we can figure out the reasoning behind Arc.

@codecov

codecov Bot commented Sep 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.88889% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.05%. Comparing base (0bd622e) to head (d97f947).

Files with missing lines Patch % Lines
src/modular/monty_params.rs 88.88% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1338      +/-   ##
==========================================
- Coverage   91.06%   91.05%   -0.02%     
==========================================
  Files         189      189              
  Lines       22654    22651       -3     
==========================================
- Hits        20630    20624       -6     
- Misses       2024     2027       +3     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tarcieri

tarcieri commented Sep 4, 2026

Copy link
Copy Markdown
Member

Arc prevents the params from being copied every single time a new value is made, incurring a heap allocation for each one. It would incur copies and significantly increase the amount of memory required.

That said we do generally try to make use of in-place operations to avoid heap allocations whenever possible.

See also previous discussion of this in #708

@tarcieri

tarcieri commented Sep 4, 2026

Copy link
Copy Markdown
Member

A potential alternative here could be to expose the equivalent of Arc::into_inner and/or Arc::get_mut for the params, namely BoxedMontyParams is a wrapper for the generic MontyParams.

Someone wanting to write a Zeroize impl as in RSA could do e.g. BoxedMontyParams::get_mut and obtain an Option<&mut MontyParams<_>>, and if they have exclusive access can now use the Zeroize impl on MontyParams.

@tarcieri tarcieri closed this Sep 4, 2026
/// are both chosen at runtime.
#[derive(Clone, Eq, PartialEq)]
pub struct BoxedMontyParams(Arc<MontyParams<crate::uint::boxed::BoxedUint>>);
pub struct BoxedMontyParams(MontyParams<crate::uint::boxed::BoxedUint>);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This defeats the point of having a newtype at all. If we're not using the Arc then this should just be:

Suggested change
pub struct BoxedMontyParams(MontyParams<crate::uint::boxed::BoxedUint>);
pub type BoxedMontyParams = MontyParams<crate::uint::boxed::BoxedUint>;

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