Compare commits
2 Commits
18b0818ee4
...
2fc56b6e6e
Author | SHA1 | Date |
---|---|---|
Matéo Duparc | 2fc56b6e6e | |
Matéo Duparc | 7cf87d5fa4 |
|
@ -0,0 +1,24 @@
|
||||||
|
use std::{env, fs::File, io::{self, Read}};
|
||||||
|
use doby::{MAGIC_BYTES, crypto::EncryptionParams};
|
||||||
|
|
||||||
|
fn main() -> io::Result<()> {
|
||||||
|
let args: Vec<String> = env::args().collect();
|
||||||
|
let mut file = File::open(&args[1])?;
|
||||||
|
|
||||||
|
let mut magic_bytes = vec![0; MAGIC_BYTES.len()];
|
||||||
|
file.read(&mut magic_bytes)?;
|
||||||
|
if magic_bytes == MAGIC_BYTES {
|
||||||
|
match EncryptionParams::read(&mut file)? {
|
||||||
|
Some(params) => {
|
||||||
|
println!("Argon2 time cost: {}", params.argon2.t_cost);
|
||||||
|
println!("Argon2 memory cost: {}KB", params.argon2.m_cost);
|
||||||
|
println!("Argon2 parallelism: {}", params.argon2.parallelism);
|
||||||
|
println!("Encryption cihpher: {}", params.cipher);
|
||||||
|
}
|
||||||
|
None => eprintln!("Invalid cipher")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
eprintln!("Doby format not recognized.");
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
17
src/cli.rs
17
src/cli.rs
|
@ -23,6 +23,7 @@ pub fn parse() -> Option<CliArgs> {
|
||||||
let app = App::new(crate_name!())
|
let app = App::new(crate_name!())
|
||||||
.version(crate_version!())
|
.version(crate_version!())
|
||||||
.setting(AppSettings::ColoredHelp)
|
.setting(AppSettings::ColoredHelp)
|
||||||
|
.about("Secure symmetric encryption from the command line.")
|
||||||
.arg(Arg::with_name("INPUT").help("<PATH> | \"-\" or empty for stdin"))
|
.arg(Arg::with_name("INPUT").help("<PATH> | \"-\" or empty for stdin"))
|
||||||
.arg(Arg::with_name("OUTPUT").help("<PATH> | \"-\" or empty for stdout"))
|
.arg(Arg::with_name("OUTPUT").help("<PATH> | \"-\" or empty for stdout"))
|
||||||
.arg(
|
.arg(
|
||||||
|
@ -32,14 +33,14 @@ pub fn parse() -> Option<CliArgs> {
|
||||||
.help(&format!("Encrypt even if {} format is recognized", crate_name!()))
|
.help(&format!("Encrypt even if {} format is recognized", crate_name!()))
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("password")
|
Arg::with_name("1_password")
|
||||||
.short("p")
|
.short("p")
|
||||||
.long("password")
|
.long("password")
|
||||||
.value_name("password")
|
.value_name("password")
|
||||||
.help("Password used to derive encryption keys")
|
.help("Password used to derive encryption keys")
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("t_cost")
|
Arg::with_name("2_t_cost")
|
||||||
.short("i")
|
.short("i")
|
||||||
.long("iterations")
|
.long("iterations")
|
||||||
.value_name("iterations")
|
.value_name("iterations")
|
||||||
|
@ -47,7 +48,7 @@ pub fn parse() -> Option<CliArgs> {
|
||||||
.default_value("10")
|
.default_value("10")
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("m_cost")
|
Arg::with_name("3_m_cost")
|
||||||
.short("m")
|
.short("m")
|
||||||
.long("memory-cost")
|
.long("memory-cost")
|
||||||
.value_name("memory cost")
|
.value_name("memory cost")
|
||||||
|
@ -55,7 +56,7 @@ pub fn parse() -> Option<CliArgs> {
|
||||||
.default_value("4096")
|
.default_value("4096")
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("parallelism")
|
Arg::with_name("4_parallelism")
|
||||||
.short("t")
|
.short("t")
|
||||||
.long("threads")
|
.long("threads")
|
||||||
.value_name("threads")
|
.value_name("threads")
|
||||||
|
@ -82,9 +83,9 @@ pub fn parse() -> Option<CliArgs> {
|
||||||
.get_matches();
|
.get_matches();
|
||||||
|
|
||||||
let params = {
|
let params = {
|
||||||
let t_cost = number(app.value_of("t_cost").unwrap())?;
|
let t_cost = number(app.value_of("2_t_cost").unwrap())?;
|
||||||
let m_cost = number(app.value_of("m_cost").unwrap())?;
|
let m_cost = number(app.value_of("3_m_cost").unwrap())?;
|
||||||
let parallelism = number(app.value_of("parallelism").unwrap())?;
|
let parallelism = number(app.value_of("4_parallelism").unwrap())?;
|
||||||
|
|
||||||
ArgonParams {
|
ArgonParams {
|
||||||
t_cost,
|
t_cost,
|
||||||
|
@ -129,7 +130,7 @@ pub fn parse() -> Option<CliArgs> {
|
||||||
})
|
})
|
||||||
.unwrap_or_else(|| Some(Box::new(stdout())))?;
|
.unwrap_or_else(|| Some(Box::new(stdout())))?;
|
||||||
|
|
||||||
let password = match app.value_of("password") {
|
let password = match app.value_of("1_password") {
|
||||||
Some(s) => s.to_string(),
|
Some(s) => s.to_string(),
|
||||||
None => rpassword::read_password_from_tty(Some("Password: ")).unwrap(),
|
None => rpassword::read_password_from_tty(Some("Password: ")).unwrap(),
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,4 +1,8 @@
|
||||||
use std::{convert::TryFrom, io::{self, Read, Write}};
|
use std::{
|
||||||
|
convert::TryFrom,
|
||||||
|
fmt::{self, Display, Formatter},
|
||||||
|
io::{self, Read, Write}
|
||||||
|
};
|
||||||
use num_enum::TryFromPrimitive;
|
use num_enum::TryFromPrimitive;
|
||||||
use chacha20::XChaCha20;
|
use chacha20::XChaCha20;
|
||||||
use aes::{Aes256Ctr, cipher::{NewCipher, StreamCipher}};
|
use aes::{Aes256Ctr, cipher::{NewCipher, StreamCipher}};
|
||||||
|
@ -37,13 +41,22 @@ impl CipherAlgorithm {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Display for CipherAlgorithm {
|
||||||
|
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
|
||||||
|
f.write_str(match self {
|
||||||
|
CipherAlgorithm::AesCtr => "AES-CTR",
|
||||||
|
CipherAlgorithm::XChaCha20 => "XChaCha20",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq)]
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
pub struct EncryptionParams {
|
pub struct EncryptionParams {
|
||||||
password_salt: [u8; SALT_LEN],
|
password_salt: [u8; SALT_LEN],
|
||||||
argon2: ArgonParams,
|
pub argon2: ArgonParams,
|
||||||
hkdf_salt: [u8; SALT_LEN],
|
hkdf_salt: [u8; SALT_LEN],
|
||||||
nonce: Vec<u8>,
|
nonce: Vec<u8>,
|
||||||
cipher: CipherAlgorithm,
|
pub cipher: CipherAlgorithm,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EncryptionParams {
|
impl EncryptionParams {
|
||||||
|
|
Loading…
Reference in New Issue