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

View file

@ -12,6 +12,7 @@ use std::fmt;
use std::fs::{self, File};
use std::io::{self, Write};
use std::path::{Path, PathBuf};
use torut::onion::TorSecretKeyV3;
pub const SEED_LENGTH: usize = 32;
@ -47,6 +48,14 @@ impl Seed {
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> {
let file_path_buf = data_dir.join("seed.pem");
let file_path = Path::new(&file_path_buf);