mirror of
https://github.com/saymrwulf/curve25519-dalek-source.git
synced 2026-09-08 21:00:40 +00:00
add clear_on_drop to toml & add secret key type
This commit is contained in:
parent
909b44a502
commit
bd13f0728f
3 changed files with 30 additions and 1 deletions
|
|
@ -27,6 +27,9 @@ default-features = false
|
||||||
default-features = false
|
default-features = false
|
||||||
version = "0.2"
|
version = "0.2"
|
||||||
|
|
||||||
|
[dependencies.clear_on_drop]
|
||||||
|
version = "0.2"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
criterion = "0.2"
|
criterion = "0.2"
|
||||||
rand = "0.5"
|
rand = "0.5"
|
||||||
|
|
@ -38,6 +41,6 @@ harness = false
|
||||||
[features]
|
[features]
|
||||||
default = ["std", "nightly", "u64_backend"]
|
default = ["std", "nightly", "u64_backend"]
|
||||||
std = ["curve25519-dalek/std"]
|
std = ["curve25519-dalek/std"]
|
||||||
nightly = ["curve25519-dalek/nightly"]
|
nightly = ["curve25519-dalek/nightly", "clear_on_drop/nightly"]
|
||||||
u64_backend = ["curve25519-dalek/u64_backend"]
|
u64_backend = ["curve25519-dalek/u64_backend"]
|
||||||
u32_backend = ["curve25519-dalek/u32_backend"]
|
u32_backend = ["curve25519-dalek/u32_backend"]
|
||||||
|
|
|
||||||
|
|
@ -126,6 +126,8 @@
|
||||||
#![cfg_attr(feature = "bench", feature(test))]
|
#![cfg_attr(feature = "bench", feature(test))]
|
||||||
#![deny(missing_docs)]
|
#![deny(missing_docs)]
|
||||||
|
|
||||||
|
extern crate clear_on_drop;
|
||||||
|
|
||||||
extern crate curve25519_dalek;
|
extern crate curve25519_dalek;
|
||||||
|
|
||||||
extern crate rand_core;
|
extern crate rand_core;
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,10 @@
|
||||||
//! This implements x25519 key exchange as specified by Mike Hamburg
|
//! This implements x25519 key exchange as specified by Mike Hamburg
|
||||||
//! and Adam Langley in [RFC7748](https://tools.ietf.org/html/rfc7748).
|
//! and Adam Langley in [RFC7748](https://tools.ietf.org/html/rfc7748).
|
||||||
|
|
||||||
|
use core::fmt::{Debug};
|
||||||
|
|
||||||
|
use clear_on_drop::clear::Clear;
|
||||||
|
|
||||||
use curve25519_dalek::constants::ED25519_BASEPOINT_TABLE;
|
use curve25519_dalek::constants::ED25519_BASEPOINT_TABLE;
|
||||||
use curve25519_dalek::montgomery::MontgomeryPoint;
|
use curve25519_dalek::montgomery::MontgomeryPoint;
|
||||||
use curve25519_dalek::scalar::Scalar;
|
use curve25519_dalek::scalar::Scalar;
|
||||||
|
|
@ -19,6 +23,26 @@ use curve25519_dalek::scalar::Scalar;
|
||||||
use rand_core::RngCore;
|
use rand_core::RngCore;
|
||||||
use rand_core::CryptoRng;
|
use rand_core::CryptoRng;
|
||||||
|
|
||||||
|
/// The length of a curve25519 EdDSA `SecretKey`, in bytes.
|
||||||
|
pub const SECRET_KEY_LENGTH: usize = 32;
|
||||||
|
|
||||||
|
/// An EdDSA secret key.
|
||||||
|
#[repr(C)]
|
||||||
|
#[derive(Default)] // we derive Default in order to use the clear() method in Drop
|
||||||
|
pub struct SecretKey(pub (crate) [u8; SECRET_KEY_LENGTH]);
|
||||||
|
|
||||||
|
impl Debug for SecretKey {
|
||||||
|
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
|
||||||
|
write!(f, "SecretKey: {:?}", &self.0[..])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Overwrite secret key material with null bytes when it goes out of scope.
|
||||||
|
impl Drop for SecretKey {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
self.0.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
/// "Decode" a scalar from a 32-byte array.
|
/// "Decode" a scalar from a 32-byte array.
|
||||||
///
|
///
|
||||||
/// By "decode" here, what is really meant is applying key clamping by twiddling
|
/// By "decode" here, what is really meant is applying key clamping by twiddling
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue