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

オープン
#794 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@aviralgarg05 がすでに取り組んでいます。

2026年11月28日 から。

評価

難易度
3/5
見積もり時間
半日
初心者へのやさしさ
65/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
rust
領域
security

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
Rust
スター
678
フォーク
199
平均マージ
1時間 55分
マージ済み PR(30日)
48

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

RustCrypto/RSA のほかの issue

RustCrypto/RSA の issue をすべて見る

似ている issue

Rust の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。