mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 12:19:24 +00:00
Use Zeroize for the ViewPair
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
|
use core::ops::Deref;
|
||||||
use std::collections::{HashSet, HashMap};
|
use std::collections::{HashSet, HashMap};
|
||||||
|
|
||||||
use zeroize::{Zeroize, ZeroizeOnDrop};
|
use zeroize::{Zeroize, ZeroizeOnDrop, Zeroizing};
|
||||||
|
|
||||||
use curve25519_dalek::{
|
use curve25519_dalek::{
|
||||||
constants::ED25519_BASEPOINT_TABLE,
|
constants::ED25519_BASEPOINT_TABLE,
|
||||||
@@ -97,11 +98,11 @@ pub(crate) fn commitment_mask(shared_key: Scalar) -> Scalar {
|
|||||||
#[derive(Clone, Zeroize, ZeroizeOnDrop)]
|
#[derive(Clone, Zeroize, ZeroizeOnDrop)]
|
||||||
pub struct ViewPair {
|
pub struct ViewPair {
|
||||||
spend: EdwardsPoint,
|
spend: EdwardsPoint,
|
||||||
view: Scalar,
|
view: Zeroizing<Scalar>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ViewPair {
|
impl ViewPair {
|
||||||
pub fn new(spend: EdwardsPoint, view: Scalar) -> ViewPair {
|
pub fn new(spend: EdwardsPoint, view: Zeroizing<Scalar>) -> ViewPair {
|
||||||
ViewPair { spend, view }
|
ViewPair { spend, view }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,15 +111,15 @@ impl ViewPair {
|
|||||||
return Scalar::zero();
|
return Scalar::zero();
|
||||||
}
|
}
|
||||||
|
|
||||||
hash_to_scalar(
|
hash_to_scalar(&Zeroizing::new(
|
||||||
&[
|
[
|
||||||
b"SubAddr\0".as_ref(),
|
b"SubAddr\0".as_ref(),
|
||||||
&self.view.to_bytes(),
|
Zeroizing::new(self.view.to_bytes()).as_ref(),
|
||||||
&index.0.to_le_bytes(),
|
&index.0.to_le_bytes(),
|
||||||
&index.1.to_le_bytes(),
|
&index.1.to_le_bytes(),
|
||||||
]
|
]
|
||||||
.concat(),
|
.concat(),
|
||||||
)
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -191,7 +192,7 @@ impl Scanner {
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
self.pair.spend,
|
self.pair.spend,
|
||||||
&self.pair.view * &ED25519_BASEPOINT_TABLE,
|
self.pair.view.deref() * &ED25519_BASEPOINT_TABLE,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -214,7 +215,7 @@ impl Scanner {
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
spend,
|
spend,
|
||||||
self.pair.view * spend,
|
self.pair.view.deref() * spend,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
|
use core::ops::Deref;
|
||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
|
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
|
|
||||||
|
use zeroize::Zeroizing;
|
||||||
use rand_core::OsRng;
|
use rand_core::OsRng;
|
||||||
|
|
||||||
use curve25519_dalek::{constants::ED25519_BASEPOINT_TABLE, scalar::Scalar};
|
use curve25519_dalek::{constants::ED25519_BASEPOINT_TABLE, scalar::Scalar};
|
||||||
@@ -17,14 +20,14 @@ use monero_serai::{
|
|||||||
pub fn random_address() -> (Scalar, ViewPair, MoneroAddress) {
|
pub fn random_address() -> (Scalar, ViewPair, MoneroAddress) {
|
||||||
let spend = random_scalar(&mut OsRng);
|
let spend = random_scalar(&mut OsRng);
|
||||||
let spend_pub = &spend * &ED25519_BASEPOINT_TABLE;
|
let spend_pub = &spend * &ED25519_BASEPOINT_TABLE;
|
||||||
let view = random_scalar(&mut OsRng);
|
let view = Zeroizing::new(random_scalar(&mut OsRng));
|
||||||
(
|
(
|
||||||
spend,
|
spend,
|
||||||
ViewPair::new(spend_pub, view),
|
ViewPair::new(spend_pub, view.clone()),
|
||||||
MoneroAddress {
|
MoneroAddress {
|
||||||
meta: AddressMeta::new(Network::Mainnet, AddressType::Standard),
|
meta: AddressMeta::new(Network::Mainnet, AddressType::Standard),
|
||||||
spend: spend_pub,
|
spend: spend_pub,
|
||||||
view: &view * &ED25519_BASEPOINT_TABLE,
|
view: view.deref() * &ED25519_BASEPOINT_TABLE,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -163,7 +166,7 @@ macro_rules! test {
|
|||||||
keys[&1].group_key().0
|
keys[&1].group_key().0
|
||||||
};
|
};
|
||||||
|
|
||||||
let view = ViewPair::new(spend_pub, random_scalar(&mut OsRng));
|
let view = ViewPair::new(spend_pub, Zeroizing::new(random_scalar(&mut OsRng)));
|
||||||
|
|
||||||
let rpc = rpc().await;
|
let rpc = rpc().await;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user