Compare commits

..

No commits in common. "2fc56b6e6e43b1bb8b651de540fde0eeb1b41ff7" and "18b0818ee4c646a5c44e0d8fded2ae69625eab90" have entirely different histories.

3 changed files with 11 additions and 49 deletions

View File

@ -1,24 +0,0 @@
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(())
}

View File

@ -23,7 +23,6 @@ pub fn parse() -> Option<CliArgs> {
let app = App::new(crate_name!())
.version(crate_version!())
.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("OUTPUT").help("<PATH> | \"-\" or empty for stdout"))
.arg(
@ -33,14 +32,14 @@ pub fn parse() -> Option<CliArgs> {
.help(&format!("Encrypt even if {} format is recognized", crate_name!()))
)
.arg(
Arg::with_name("1_password")
Arg::with_name("password")
.short("p")
.long("password")
.value_name("password")
.help("Password used to derive encryption keys")
)
.arg(
Arg::with_name("2_t_cost")
Arg::with_name("t_cost")
.short("i")
.long("iterations")
.value_name("iterations")
@ -48,7 +47,7 @@ pub fn parse() -> Option<CliArgs> {
.default_value("10")
)
.arg(
Arg::with_name("3_m_cost")
Arg::with_name("m_cost")
.short("m")
.long("memory-cost")
.value_name("memory cost")
@ -56,7 +55,7 @@ pub fn parse() -> Option<CliArgs> {
.default_value("4096")
)
.arg(
Arg::with_name("4_parallelism")
Arg::with_name("parallelism")
.short("t")
.long("threads")
.value_name("threads")
@ -83,9 +82,9 @@ pub fn parse() -> Option<CliArgs> {
.get_matches();
let params = {
let t_cost = number(app.value_of("2_t_cost").unwrap())?;
let m_cost = number(app.value_of("3_m_cost").unwrap())?;
let parallelism = number(app.value_of("4_parallelism").unwrap())?;
let t_cost = number(app.value_of("t_cost").unwrap())?;
let m_cost = number(app.value_of("m_cost").unwrap())?;
let parallelism = number(app.value_of("parallelism").unwrap())?;
ArgonParams {
t_cost,
@ -130,7 +129,7 @@ pub fn parse() -> Option<CliArgs> {
})
.unwrap_or_else(|| Some(Box::new(stdout())))?;
let password = match app.value_of("1_password") {
let password = match app.value_of("password") {
Some(s) => s.to_string(),
None => rpassword::read_password_from_tty(Some("Password: ")).unwrap(),
};

View File

@ -1,8 +1,4 @@
use std::{
convert::TryFrom,
fmt::{self, Display, Formatter},
io::{self, Read, Write}
};
use std::{convert::TryFrom, io::{self, Read, Write}};
use num_enum::TryFromPrimitive;
use chacha20::XChaCha20;
use aes::{Aes256Ctr, cipher::{NewCipher, StreamCipher}};
@ -41,22 +37,13 @@ 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)]
pub struct EncryptionParams {
password_salt: [u8; SALT_LEN],
pub argon2: ArgonParams,
argon2: ArgonParams,
hkdf_salt: [u8; SALT_LEN],
nonce: Vec<u8>,
pub cipher: CipherAlgorithm,
cipher: CipherAlgorithm,
}
impl EncryptionParams {