Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: ensure Debug implementations do not leak private info #480

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions src/key.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use alloc::vec::Vec;
use core::fmt;
use core::hash::{Hash, Hasher};

use crypto_bigint::modular::{BoxedMontyForm, BoxedMontyParams};
use crypto_bigint::{BoxedUint, Integer, NonZero, Odd};
use rand_core::CryptoRngCore;
Expand Down Expand Up @@ -55,7 +57,7 @@ impl Hash for RsaPublicKey {
}

/// Represents a whole RSA key, public and private parts.
#[derive(Debug, Clone)]
#[derive(Clone)]
pub struct RsaPrivateKey {
/// Public components of the private key.
pubkey_components: RsaPublicKey,
Expand All @@ -67,6 +69,22 @@ pub struct RsaPrivateKey {
pub(crate) precomputed: Option<PrecomputedValues>,
}

impl fmt::Debug for RsaPrivateKey {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let precomputed = if self.precomputed.is_some() {
"Some(...)"
} else {
"None"
};
f.debug_struct("RsaPrivateKey")
.field("pubkey_components", &self.pubkey_components)
.field("d", &"...")
.field("primes", &"&[...]")
.field("precomputed", &precomputed)
.finish()
}
}

impl Eq for RsaPrivateKey {}
impl PartialEq for RsaPrivateKey {
#[inline]
Expand Down Expand Up @@ -101,7 +119,7 @@ impl Drop for RsaPrivateKey {

impl ZeroizeOnDrop for RsaPrivateKey {}

#[derive(Debug, Clone)]
#[derive(Clone)]
pub(crate) struct PrecomputedValues {
/// D mod (P-1)
pub(crate) dp: BoxedUint,
Expand Down