Skip to content

Commit

Permalink
Merge remote-tracking branch 'DebugSteven/zeroize' into feature/236-m…
Browse files Browse the repository at this point in the history
…erge-rebase
  • Loading branch information
isislovecruft committed Oct 28, 2019
2 parents 4cc0afd + ba38904 commit 57f19e0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/montgomery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
//! Montgomery arithmetic works not on the curve itself, but on the
//! \\(u\\)-line, which discards sign information and unifies the curve
//! and its quadratic twist. See [_Montgomery curves and their
//! arithmetic_][costello-smith] by Costello and Smith for more details.
//! arithmetic_][costello-smith] by Costello and Smith for more details.
//!
//! The `MontgomeryPoint` struct contains the affine \\(u\\)-coordinate
//! \\(u\_0(P)\\) of a point \\(P\\) on either the curve or the twist.
Expand Down Expand Up @@ -61,6 +61,8 @@ use subtle::Choice;
use subtle::ConditionallySelectable;
use subtle::ConstantTimeEq;

use zeroize::Zeroize;

/// Holds the \\(u\\)-coordinate of a point on the Montgomery form of
/// Curve25519 or its twist.
#[derive(Copy, Clone, Debug)]
Expand Down Expand Up @@ -91,6 +93,12 @@ impl PartialEq for MontgomeryPoint {

impl Eq for MontgomeryPoint {}

impl Zeroize for MontgomeryPoint {
fn zeroize(&mut self) {
self.0.zeroize();
}
}

impl MontgomeryPoint {
/// View this `MontgomeryPoint` as an array of bytes.
pub fn as_bytes<'a>(&'a self) -> &'a [u8; 32] {
Expand Down Expand Up @@ -357,7 +365,7 @@ mod test {
#[test]
fn montgomery_to_edwards_rejects_twist() {
let one = FieldElement::one();

// u = 2 corresponds to a point on the twist.
let two = MontgomeryPoint((&one+&one).to_bytes());

Expand Down
8 changes: 8 additions & 0 deletions src/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ use subtle::Choice;
use subtle::ConditionallySelectable;
use subtle::ConstantTimeEq;

use zeroize::Zeroize;

use backend;
use constants;

Expand Down Expand Up @@ -522,6 +524,12 @@ impl From<u128> for Scalar {
}
}

impl Zeroize for Scalar {
fn zeroize(&mut self) {
self.bytes.zeroize();
}
}

impl Scalar {
/// Return a `Scalar` chosen uniformly at random using a user-provided RNG.
///
Expand Down

0 comments on commit 57f19e0

Please sign in to comment.