mirror of
https://github.com/saymrwulf/curve25519-dalek-source.git
synced 2026-09-04 20:24:10 +00:00
Implement Zeroize for points as the identity element.
This commit is contained in:
parent
5482c76d16
commit
4a1fc3c66e
3 changed files with 28 additions and 11 deletions
|
|
@ -48,7 +48,7 @@ serde = { version = "1.0", default-features = false, optional = true, features =
|
|||
# The original packed_simd package was orphaned, see
|
||||
# https://github.com/rust-lang/packed_simd/issues/303#issuecomment-701361161
|
||||
packed_simd = { version = "0.3.4", package = "packed_simd_2", features = ["into_bits"], optional = true }
|
||||
zeroize = { version = "1", default-features = false, features = ["zeroize_derive"] }
|
||||
zeroize = { version = "1", default-features = false }
|
||||
|
||||
[features]
|
||||
nightly = ["subtle/nightly"]
|
||||
|
|
|
|||
|
|
@ -152,7 +152,7 @@ use backend::vector::scalar_mul;
|
|||
///
|
||||
/// The first 255 bits of a `CompressedEdwardsY` represent the
|
||||
/// \\(y\\)-coordinate. The high bit of the 32nd byte gives the sign of \\(x\\).
|
||||
#[derive(Copy, Clone, Eq, PartialEq, Hash, Zeroize)]
|
||||
#[derive(Copy, Clone, Eq, PartialEq, Hash)]
|
||||
pub struct CompressedEdwardsY(pub [u8; 32]);
|
||||
|
||||
impl ConstantTimeEq for CompressedEdwardsY {
|
||||
|
|
@ -309,7 +309,7 @@ impl<'de> Deserialize<'de> for CompressedEdwardsY {
|
|||
// ------------------------------------------------------------------------
|
||||
|
||||
/// An `EdwardsPoint` represents a point on the Edwards form of Curve25519.
|
||||
#[derive(Copy, Clone, Zeroize)]
|
||||
#[derive(Copy, Clone)]
|
||||
#[allow(missing_docs)]
|
||||
pub struct EdwardsPoint {
|
||||
pub(crate) X: FieldElement,
|
||||
|
|
@ -369,6 +369,28 @@ impl Default for EdwardsPoint {
|
|||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Zeroize implementations for wiping points from memory
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
impl Zeroize for CompressedEdwardsY {
|
||||
/// Reset this `CompressedEdwardsY` to the compressed form of the identity element.
|
||||
fn zeroize(&mut self) {
|
||||
self.0.zeroize();
|
||||
self.0[0] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
impl Zeroize for EdwardsPoint {
|
||||
/// Reset this `CompressedEdwardsPoint` to the identity element.
|
||||
fn zeroize(&mut self) {
|
||||
self.X.zeroize();
|
||||
self.Y = FieldElement::one();
|
||||
self.Z = FieldElement::one();
|
||||
self.T.zeroize();
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Validity checks (for debugging, not CT)
|
||||
// ------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -202,8 +202,6 @@ use backend::serial::scalar_mul;
|
|||
))]
|
||||
use backend::vector::scalar_mul;
|
||||
|
||||
use zeroize::Zeroize;
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Compressed points
|
||||
// ------------------------------------------------------------------------
|
||||
|
|
@ -212,7 +210,7 @@ use zeroize::Zeroize;
|
|||
///
|
||||
/// The Ristretto encoding is canonical, so two points are equal if and
|
||||
/// only if their encodings are equal.
|
||||
#[derive(Copy, Clone, Eq, PartialEq, Hash, Zeroize)]
|
||||
#[derive(Copy, Clone, Eq, PartialEq, Hash)]
|
||||
pub struct CompressedRistretto(pub [u8; 32]);
|
||||
|
||||
impl ConstantTimeEq for CompressedRistretto {
|
||||
|
|
@ -438,7 +436,7 @@ impl<'de> Deserialize<'de> for CompressedRistretto {
|
|||
/// operations on `RistrettoPoint`s are exactly as fast as operations on
|
||||
/// `EdwardsPoint`s.
|
||||
///
|
||||
#[derive(Copy, Clone, Zeroize)]
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct RistrettoPoint(pub(crate) EdwardsPoint);
|
||||
|
||||
impl RistrettoPoint {
|
||||
|
|
@ -1094,10 +1092,7 @@ impl Zeroize for CompressedRistretto {
|
|||
|
||||
impl Zeroize for RistrettoPoint {
|
||||
fn zeroize(&mut self) {
|
||||
self.0.X.zeroize();
|
||||
self.0.Y.zeroize();
|
||||
self.0.Z.zeroize();
|
||||
self.0.T.zeroize();
|
||||
self.0.zeroize();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue