mirror of
https://github.com/saymrwulf/curve25519-dalek-source.git
synced 2026-09-05 20:30:57 +00:00
Clear scalar digits from memory in multiscalar_mult
This commit is contained in:
parent
1d39d2ec6e
commit
98a78d7a58
4 changed files with 17 additions and 4 deletions
|
|
@ -39,6 +39,9 @@ version = "0.6"
|
|||
version = "^0.3"
|
||||
default-features = false
|
||||
|
||||
[dependencies.clear_on_drop]
|
||||
version = "=0.2.3"
|
||||
|
||||
[dependencies.generic-array]
|
||||
# same version that digest depends on
|
||||
version = "^0.8"
|
||||
|
|
@ -55,13 +58,14 @@ rand = "0.3"
|
|||
generic-array = "^0.8"
|
||||
digest = "0.6"
|
||||
arrayref = "0.3.4"
|
||||
clear_on_drop = "=0.2.3"
|
||||
|
||||
[build-dependencies.serde]
|
||||
version = "1.0"
|
||||
optional = true
|
||||
|
||||
[features]
|
||||
nightly = ["radix_51", "subtle/nightly"]
|
||||
nightly = ["radix_51", "subtle/nightly", "clear_on_drop/nightly"]
|
||||
default = ["std"]
|
||||
std = ["rand", "subtle/std"]
|
||||
alloc = []
|
||||
|
|
|
|||
1
build.rs
1
build.rs
|
|
@ -8,6 +8,7 @@ extern crate subtle;
|
|||
extern crate rand;
|
||||
extern crate digest;
|
||||
extern crate generic_array;
|
||||
extern crate clear_on_drop;
|
||||
|
||||
use std::env;
|
||||
use std::fs::File;
|
||||
|
|
|
|||
|
|
@ -235,7 +235,7 @@ impl Equal for ExtendedPoint {
|
|||
// ------------------------------------------------------------------------
|
||||
|
||||
impl ExtendedPoint {
|
||||
/// Convert to a `ProjectiveNielsPoint`
|
||||
/// Convert to a ProjectiveNielsPoint
|
||||
pub(crate) fn to_projective_niels(&self) -> ProjectiveNielsPoint {
|
||||
ProjectiveNielsPoint{
|
||||
Y_plus_X: &self.Y + &self.X,
|
||||
|
|
@ -519,9 +519,15 @@ pub fn multiscalar_mult<'a, 'b, I, J>(scalars: I, points: J) -> ExtendedPoint
|
|||
// s_i = s_{i,0} + s_{i,1}*16^1 + ... + s_{i,63}*16^63,
|
||||
//
|
||||
// with `-8 ≤ s_{i,j} < 8` for `0 ≤ j < 63` and `-8 ≤ s_{i,63} ≤ 8`.
|
||||
let scalar_digits_list: Vec<_> = scalars.into_iter()
|
||||
let scalar_digits_vec: Vec<_> = scalars.into_iter()
|
||||
.map(|c| c.to_radix_16()).collect();
|
||||
|
||||
// This above puts the scalar digits into a heap-allocated Vec.
|
||||
// To ensure that these are erased, pass ownership of the Vec into a
|
||||
// ClearOnDrop wrapper.
|
||||
use clear_on_drop::ClearOnDrop;
|
||||
let scalar_digits = ClearOnDrop::new(scalar_digits_vec);
|
||||
|
||||
// Compute s_1*P_1 + ... + s_n*P_n: since
|
||||
//
|
||||
// s_i*P_i = P_i*(s_{i,0} + s_{i,1}*16^1 + ... + s_{i,63}*16^63)
|
||||
|
|
@ -545,7 +551,7 @@ pub fn multiscalar_mult<'a, 'b, I, J>(scalars: I, points: J) -> ExtendedPoint
|
|||
// XXX this impl makes no effort to be cache-aware; maybe it could be improved?
|
||||
for j in (0..64).rev() {
|
||||
Q = Q.mult_by_pow_2(4);
|
||||
let it = scalar_digits_list.iter().zip(lookup_tables.iter());
|
||||
let it = scalar_digits.iter().zip(lookup_tables.iter());
|
||||
for (s_i, lookup_table_i) in it {
|
||||
// R_i = s_{i,j} * P_i
|
||||
let R_i = select_precomputed_point(s_i[j], lookup_table_i);
|
||||
|
|
|
|||
|
|
@ -47,6 +47,8 @@ extern crate rand;
|
|||
#[cfg(feature = "alloc")]
|
||||
extern crate alloc;
|
||||
|
||||
extern crate clear_on_drop;
|
||||
|
||||
#[cfg(all(test, feature = "bench"))]
|
||||
extern crate test;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue