diff --git a/src/cmd_decrypt.rs b/src/cmd_decrypt.rs index e5c55a9..655f31a 100644 --- a/src/cmd_decrypt.rs +++ b/src/cmd_decrypt.rs @@ -136,7 +136,8 @@ pub fn decrypt_single(config: &Option, Ok(meta.file_length) } -fn decrypt_file(file_in: &mut File, file_len: u64, file_out: &mut File, key: &[u8], nonce: &[u8], compress: bool) -> XResult { +fn decrypt_file(file_in: &mut File, file_len: u64, file_out: &mut File, + key: &[u8], nonce: &[u8], compress: bool) -> XResult { let mut total_len = 0_u64; let mut buffer = [0u8; 1024 * 8]; let key = opt_result!(key.try_into(), "Key is not 32 bytes: {}"); diff --git a/src/cmd_encrypt.rs b/src/cmd_encrypt.rs index cf0d369..3d8c9d8 100644 --- a/src/cmd_encrypt.rs +++ b/src/cmd_encrypt.rs @@ -11,13 +11,19 @@ use rust_util::{debugging, failure, iff, information, opt_result, simple_error, use rust_util::util_time::UnixEpochTime; use zeroize::Zeroize; -use crate::{util, util_ecdh, util_enc_file, util_p384, util_x25519}; +use crate::{util, util_enc_file, util_p256, util_p384, util_x25519}; use crate::compress::GzStreamEncoder; use crate::config::{TinyEncryptConfig, TinyEncryptConfigEnvelop}; -use crate::consts::{ENC_AES256_GCM_P256, ENC_AES256_GCM_P384, ENC_AES256_GCM_X25519, SALT_COMMENT, TINY_ENC_CONFIG_FILE, TINY_ENC_FILE_EXT}; +use crate::consts::{ + ENC_AES256_GCM_P256, ENC_AES256_GCM_P384, ENC_AES256_GCM_X25519, + SALT_COMMENT, TINY_ENC_CONFIG_FILE, TINY_ENC_FILE_EXT, +}; use crate::crypto_aes::{aes_gcm_encrypt, aes_gcm_encrypt_with_salt}; use crate::crypto_rsa::parse_spki; -use crate::spec::{EncEncryptedMeta, EncMetadata, TINY_ENCRYPT_VERSION_10, TinyEncryptEnvelop, TinyEncryptEnvelopType, TinyEncryptMeta}; +use crate::spec::{ + EncEncryptedMeta, EncMetadata, TINY_ENCRYPT_VERSION_10, + TinyEncryptEnvelop, TinyEncryptEnvelopType, TinyEncryptMeta, +}; use crate::util_process::Progress; use crate::wrap_key::{WrapKey, WrapKeyHeader}; @@ -194,7 +200,8 @@ fn process_compatible_with_1_0(cmd_encrypt: &CmdEncrypt, mut encrypt_meta: TinyE Ok(encrypt_meta) } -fn encrypt_file(file_in: &mut File, file_len: u64, file_out: &mut File, key: &[u8], nonce: &[u8], compress: bool, compress_level: &Option) -> XResult { +fn encrypt_file(file_in: &mut File, file_len: u64, file_out: &mut File, + key: &[u8], nonce: &[u8], compress: bool, compress_level: &Option) -> XResult { let mut total_len = 0_u64; let mut buffer = [0u8; 1024 * 8]; let key = opt_result!(key.try_into(), "Key is not 32 bytes: {}"); @@ -269,7 +276,7 @@ fn encrypt_envelops(key: &[u8], envelops: &[&TinyEncryptConfigEnvelop]) -> XResu fn encrypt_envelop_ecdh(key: &[u8], envelop: &TinyEncryptConfigEnvelop) -> XResult { let public_key_point_hex = &envelop.public_part; - let (shared_secret, ephemeral_spki) = util_ecdh::compute_shared_secret(public_key_point_hex)?; + let (shared_secret, ephemeral_spki) = util_p256::compute_shared_secret(public_key_point_hex)?; encrypt_envelop_shared_secret(key, &shared_secret, &ephemeral_spki, ENC_AES256_GCM_P256, envelop) } diff --git a/src/main.rs b/src/main.rs index 6ccdca7..66cd086 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,7 +14,7 @@ mod util; mod util_process; mod util_piv; mod util_pgp; -mod util_ecdh; +mod util_p256; mod util_p384; mod util_x25519; mod compress; diff --git a/src/util_ecdh.rs b/src/util_p256.rs similarity index 100% rename from src/util_ecdh.rs rename to src/util_p256.rs