Derive Tor secret key from seed.

This commit is contained in:
Philipp Hoenisch 2021-04-22 16:03:12 +10:00
parent 3a5395d7a5
commit c8e6db24f8
No known key found for this signature in database
GPG Key ID: E5F8E74C672BC666
3 changed files with 11 additions and 0 deletions

1
Cargo.lock generated
View File

@ -3742,6 +3742,7 @@ dependencies = [
"dialoguer", "dialoguer",
"directories-next", "directories-next",
"ecdsa_fun", "ecdsa_fun",
"ed25519-dalek",
"futures", "futures",
"get-port", "get-port",
"hyper 0.14.7", "hyper 0.14.7",

View File

@ -26,6 +26,7 @@ data-encoding = "2.3"
dialoguer = "0.8" dialoguer = "0.8"
directories-next = "2" directories-next = "2"
ecdsa_fun = { git = "https://github.com/LLFourn/secp256kfun", features = ["libsecp_compat", "serde"] } ecdsa_fun = { git = "https://github.com/LLFourn/secp256kfun", features = ["libsecp_compat", "serde"] }
ed25519-dalek = "1"
futures = { version = "0.3", default-features = false } futures = { version = "0.3", default-features = false }
itertools = "0.10" itertools = "0.10"
libp2p = { version = "0.37", default-features = false, features = ["tcp-tokio", "yamux", "mplex", "dns-tokio", "noise", "request-response", "websocket"] } libp2p = { version = "0.37", default-features = false, features = ["tcp-tokio", "yamux", "mplex", "dns-tokio", "noise", "request-response", "websocket"] }

View File

@ -12,6 +12,7 @@ use std::fmt;
use std::fs::{self, File}; use std::fs::{self, File};
use std::io::{self, Write}; use std::io::{self, Write};
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use torut::onion::TorSecretKeyV3;
pub const SEED_LENGTH: usize = 32; pub const SEED_LENGTH: usize = 32;
@ -47,6 +48,14 @@ impl Seed {
identity::Keypair::Ed25519(key.into()) identity::Keypair::Ed25519(key.into())
} }
pub fn derive_torv3_key(&self) -> TorSecretKeyV3 {
let bytes = self.derive(b"TOR").bytes();
let sk = ed25519_dalek::SecretKey::from_bytes(&bytes)
.expect("Failed to create a new extended secret key for Tor.");
let esk = ed25519_dalek::ExpandedSecretKey::from(&sk);
esk.to_bytes().into()
}
pub fn from_file_or_generate(data_dir: &Path) -> Result<Self, Error> { pub fn from_file_or_generate(data_dir: &Path) -> Result<Self, Error> {
let file_path_buf = data_dir.join("seed.pem"); let file_path_buf = data_dir.join("seed.pem");
let file_path = Path::new(&file_path_buf); let file_path = Path::new(&file_path_buf);