ed25519-dalek: hide secret in SigningKey
's Debug
impl (#592)
Uses `finish_non_exhaustive` in lieu of printing the `secret_key` component of a `SigningKey`, only showing the corresponding `verifying_key` field which can be used to identify the public key. Closes #591
This commit is contained in:
parent
f4cd43f606
commit
78a86f1c49
@ -9,6 +9,8 @@
|
|||||||
|
|
||||||
//! ed25519 signing keys.
|
//! ed25519 signing keys.
|
||||||
|
|
||||||
|
use core::fmt::Debug;
|
||||||
|
|
||||||
#[cfg(feature = "pkcs8")]
|
#[cfg(feature = "pkcs8")]
|
||||||
use ed25519::pkcs8;
|
use ed25519::pkcs8;
|
||||||
|
|
||||||
@ -58,7 +60,7 @@ pub type SecretKey = [u8; SECRET_KEY_LENGTH];
|
|||||||
// Invariant: `verifying_key` is always the public key of
|
// Invariant: `verifying_key` is always the public key of
|
||||||
// `secret_key`. This prevents the signing function oracle attack
|
// `secret_key`. This prevents the signing function oracle attack
|
||||||
// described in https://github.com/MystenLabs/ed25519-unsafe-libs
|
// described in https://github.com/MystenLabs/ed25519-unsafe-libs
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone)]
|
||||||
pub struct SigningKey {
|
pub struct SigningKey {
|
||||||
/// The secret half of this signing key.
|
/// The secret half of this signing key.
|
||||||
pub(crate) secret_key: SecretKey,
|
pub(crate) secret_key: SecretKey,
|
||||||
@ -507,6 +509,14 @@ impl AsRef<VerifyingKey> for SigningKey {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Debug for SigningKey {
|
||||||
|
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
|
||||||
|
f.debug_struct("SigningKey")
|
||||||
|
.field("verifying_key", &self.verifying_key)
|
||||||
|
.finish_non_exhaustive() // avoids printing `secret_key`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl KeypairRef for SigningKey {
|
impl KeypairRef for SigningKey {
|
||||||
type VerifyingKey = VerifyingKey;
|
type VerifyingKey = VerifyingKey;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user