PrecomputedValues::zeroize skips qinv (and BoxedMontyForm::zeroize skips its prime p params)

Đang mở
#794 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@aviralgarg05 đang làm issue này rồi.

Từ ngày 28/11/2026.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
Nửa ngày
Mức phù hợp với người mới
65/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
rust
Lĩnh vực
security

Hướng nghiên cứu

Start in src/private_key.rs:114-120 at PrecomputedValues and its Zeroize impl, then trace every use of qinv to see what a type change would affect. Read BoxedMontyForm::zeroize and BoxedMontyParams in crypto-bigint 0.7.11 to understand why the parameters survive; compare storing qinv as a BoxedUint. Done means dropping a PrivateKey wipes the inverse and any owned p parameters, with RSA tests still passing.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

In rsa 0.10.0, PrecomputedValues::zeroize (src/private_key.rs:114-120) wipes p, q, dp, and dq, but omits qinv:

pub(crate) struct PrecomputedValues {
    pub(crate) p: SecretPrime,
    pub(crate) q: SecretPrime,
    pub(crate) dp: BoxedUint,
    pub(crate) dq: BoxedUint,
    pub(crate) qinv: BoxedMontyForm,
}

impl Zeroize for PrecomputedValues {
    fn zeroize(&mut self) {
        self.p.zeroize();
        self.q.zeroize();
        self.dp.zeroize();
        self.dq.zeroize();
    }
}

When a PrivateKey is dropped, $q^{-1} \bmod p$ remains unzeroized in freed heap memory.

Adding self.qinv.zeroize() alone does not wipe the associated parameters either. In crypto-bigint 0.7.11 (src/modular/boxed_monty_form.rs:229-235), BoxedMontyForm::zeroize wipes montgomery_form and skips params:

/// NOTE: This zeroizes the value, but _not_ the associated parameters!
#[cfg(feature = "zeroize")]
impl Zeroize for BoxedMontyForm {
    fn zeroize(&mut self) {
        self.montgomery_form.zeroize();
    }
}

Because qinv is constructed with p_params (BoxedMontyForm::new clones BoxedMontyParams for the secret prime p), and BoxedMontyParams does not zeroize on drop, a separate copy of p (along with one, r2, and mod_inv) is also freed without being wiped. Storing qinv as a BoxedUint (or zeroizing owned BoxedMontyForm parameters on drop) would clear both.

Ngôn ngữ chính
Rust
Star
678
Fork
199
Merge trung bình
1 giờ 55 phút
Pull request đã merge (30 ngày)
48

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của RustCrypto/RSA

Tất cả issue của RustCrypto/RSA

Issue tương tự

Thêm issue về Rust

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.