Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

implement Zeroize for Scalar and MontgomeryPoint #236

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ clear_on_drop = "=0.2.3"
subtle = { version = "2.0.0-pre.0", default-features = false }
serde = { version = "1.0", optional = true }
packed_simd = { version = "0.3.0", features = ["into_bits"], optional = true }
zeroize = { version = "0.6.0", default-features = false }

[build-dependencies]
rand = { version = "0.6.0", default-features = false }
Expand All @@ -57,9 +58,10 @@ clear_on_drop = "=0.2.3"
subtle = { version = "2.0.0-pre.0", default-features = false }
serde = { version = "1.0", optional = true }
packed_simd = { version = "0.3.0", features = ["into_bits"], optional = true }
zeroize = { version = "0.6.0", default-features = false, features = ["zeroize_derive"] }

[features]
nightly = ["subtle/nightly", "clear_on_drop/nightly"]
nightly = ["subtle/nightly", "clear_on_drop/nightly", "zeroize/nightly"]
default = ["std", "u64_backend"]
std = ["alloc", "subtle/std", "rand/std"]
alloc = []
Expand Down
2 changes: 2 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ extern crate subtle;
#[cfg(all(feature = "nightly", feature = "avx2_backend"))]
extern crate packed_simd;

extern crate zeroize;

use std::env;
use std::fs::File;
use std::io::Write;
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ extern crate serde;
#[cfg(all(test, feature = "serde"))]
extern crate bincode;

extern crate zeroize;

// Internal macros. Must come first!
#[macro_use]
pub(crate) mod macros;
Expand Down
8 changes: 5 additions & 3 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,9 +61,11 @@ 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)]
#[derive(Copy, Clone, Debug, Zeroize)]
pub struct MontgomeryPoint(pub [u8; 32]);

/// Equality of `MontgomeryPoint`s is defined mod p.
Expand Down Expand Up @@ -335,7 +337,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
4 changes: 3 additions & 1 deletion 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 All @@ -180,7 +182,7 @@ type UnpackedScalar = backend::u32::scalar::Scalar32;

/// The `Scalar` struct holds an integer \\(s < 2\^{255} \\) which
/// represents an element of \\(\mathbb Z / \ell\\).
#[derive(Copy, Clone)]
#[derive(Copy, Clone, Zeroize)]
pub struct Scalar {
/// `bytes` is a little-endian byte encoding of an integer representing a scalar modulo the
/// group order.
Expand Down