use another feature to create smaller single algorithm binaries

This commit is contained in:
Bryson Steck 2025-08-14 22:02:37 -06:00
parent 22095ec627
commit 60c2afe39e
Signed by: bryson
SSH key fingerprint: SHA256:XpKABw/nP4z8UVaH+weLaBnEOD86+cVwif+QjuYLGT4
11 changed files with 232 additions and 106 deletions

1
.gitignore vendored
View file

@ -1 +1,2 @@
.vscode/
/target /target

142
Cargo.lock generated
View file

@ -34,22 +34,22 @@ dependencies = [
[[package]] [[package]]
name = "anstyle-query" name = "anstyle-query"
version = "1.1.3" version = "1.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c8bdeb6047d8983be085bab0ba1472e6dc604e7041dbf6fcd5e71523014fae9" checksum = "9e231f6134f61b71076a3eab506c379d4f36122f2af15a9ff04415ea4c3339e2"
dependencies = [ dependencies = [
"windows-sys", "windows-sys 0.60.2",
] ]
[[package]] [[package]]
name = "anstyle-wincon" name = "anstyle-wincon"
version = "3.0.9" version = "3.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "403f75924867bb1033c59fbf0797484329750cfbe3c4325cd33127941fabc882" checksum = "3e0633414522a32ffaac8ac6cc8f748e090c5717661fddeea04219e2344f5f2a"
dependencies = [ dependencies = [
"anstyle", "anstyle",
"once_cell_polyfill", "once_cell_polyfill",
"windows-sys", "windows-sys 0.60.2",
] ]
[[package]] [[package]]
@ -129,9 +129,9 @@ dependencies = [
[[package]] [[package]]
name = "cc" name = "cc"
version = "1.2.31" version = "1.2.32"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3a42d84bb6b69d3a8b3eaacf0d88f179e1929695e1ad012b6cf64d9caaa5fd2" checksum = "2352e5597e9c544d5e6d9c95190d5d27738ade584fa8db0a16e130e5c2b5296e"
dependencies = [ dependencies = [
"shlex", "shlex",
] ]
@ -144,9 +144,9 @@ checksum = "9555578bc9e57714c812a1f84e4fc5b4d21fcb063490c624de019f7464c91268"
[[package]] [[package]]
name = "clap" name = "clap"
version = "4.5.43" version = "4.5.45"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "50fd97c9dc2399518aa331917ac6f274280ec5eb34e555dd291899745c48ec6f" checksum = "1fc0e74a703892159f5ae7d3aac52c8e6c392f5ae5f359c70b5881d60aaac318"
dependencies = [ dependencies = [
"clap_builder", "clap_builder",
"clap_derive", "clap_derive",
@ -154,9 +154,9 @@ dependencies = [
[[package]] [[package]]
name = "clap_builder" name = "clap_builder"
version = "4.5.43" version = "4.5.44"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c35b5830294e1fa0462034af85cc95225a4cb07092c088c55bda3147cfcd8f65" checksum = "b3e7f4214277f3c7aa526a59dd3fbe306a370daee1f8b7b8c987069cd8e888a8"
dependencies = [ dependencies = [
"anstream", "anstream",
"anstyle", "anstyle",
@ -166,9 +166,9 @@ dependencies = [
[[package]] [[package]]
name = "clap_derive" name = "clap_derive"
version = "4.5.41" version = "4.5.45"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ef4f52386a59ca4c860f7393bcf8abd8dfd91ecccc0f774635ff68e92eeef491" checksum = "14cb31bb0a7d536caef2639baa7fad459e15c3144efefa6dbd1c84562c4739f6"
dependencies = [ dependencies = [
"heck", "heck",
"proc-macro2", "proc-macro2",
@ -194,7 +194,7 @@ version = "3.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fde0e0ec90c9dfb3b4b1a0891a7dcd0e2bffde2f7efed5fe7c9bb00e5bfb915e" checksum = "fde0e0ec90c9dfb3b4b1a0891a7dcd0e2bffde2f7efed5fe7c9bb00e5bfb915e"
dependencies = [ dependencies = [
"windows-sys", "windows-sys 0.59.0",
] ]
[[package]] [[package]]
@ -327,9 +327,9 @@ dependencies = [
[[package]] [[package]]
name = "libc" name = "libc"
version = "0.2.174" version = "0.2.175"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1171693293099992e19cddea4e8b849964e9846f4acee11b3948bcc337be8776" checksum = "6a82ae493e598baaea5209805c49bbf2ea7de956d50d7da0da1164f9c6d28543"
[[package]] [[package]]
name = "md-5" name = "md-5"
@ -367,7 +367,7 @@ checksum = "a4895175b425cb1f87721b59f0f286c2092bd4af812243672510e1ac53e2e0ad"
[[package]] [[package]]
name = "picca" name = "picca"
version = "0.5.0" version = "0.6.0"
dependencies = [ dependencies = [
"ascon-hash", "ascon-hash",
"belt-hash", "belt-hash",
@ -408,9 +408,9 @@ dependencies = [
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro2"
version = "1.0.95" version = "1.0.97"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778" checksum = "d61789d7719defeb74ea5fe81f2fdfdbd28a803847077cecce2ff14e1472f6f1"
dependencies = [ dependencies = [
"unicode-ident", "unicode-ident",
] ]
@ -537,9 +537,9 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
[[package]] [[package]]
name = "syn" name = "syn"
version = "2.0.104" version = "2.0.105"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "17b6f705963418cdb9927482fa304bc562ece2fdd4f616084c50b7023b435a40" checksum = "7bc3fcb250e53458e712715cf74285c1f889686520d79294a9ef3bd7aa1fc619"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -594,13 +594,28 @@ dependencies = [
"digest", "digest",
] ]
[[package]]
name = "windows-link"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5e6ad25900d524eaabdbbb96d20b4311e1e7ae1699af4fb28c17ae66c80d798a"
[[package]] [[package]]
name = "windows-sys" name = "windows-sys"
version = "0.59.0" version = "0.59.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b"
dependencies = [ dependencies = [
"windows-targets", "windows-targets 0.52.6",
]
[[package]]
name = "windows-sys"
version = "0.60.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb"
dependencies = [
"windows-targets 0.53.3",
] ]
[[package]] [[package]]
@ -609,14 +624,31 @@ version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
dependencies = [ dependencies = [
"windows_aarch64_gnullvm", "windows_aarch64_gnullvm 0.52.6",
"windows_aarch64_msvc", "windows_aarch64_msvc 0.52.6",
"windows_i686_gnu", "windows_i686_gnu 0.52.6",
"windows_i686_gnullvm", "windows_i686_gnullvm 0.52.6",
"windows_i686_msvc", "windows_i686_msvc 0.52.6",
"windows_x86_64_gnu", "windows_x86_64_gnu 0.52.6",
"windows_x86_64_gnullvm", "windows_x86_64_gnullvm 0.52.6",
"windows_x86_64_msvc", "windows_x86_64_msvc 0.52.6",
]
[[package]]
name = "windows-targets"
version = "0.53.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d5fe6031c4041849d7c496a8ded650796e7b6ecc19df1a431c1a363342e5dc91"
dependencies = [
"windows-link",
"windows_aarch64_gnullvm 0.53.0",
"windows_aarch64_msvc 0.53.0",
"windows_i686_gnu 0.53.0",
"windows_i686_gnullvm 0.53.0",
"windows_i686_msvc 0.53.0",
"windows_x86_64_gnu 0.53.0",
"windows_x86_64_gnullvm 0.53.0",
"windows_x86_64_msvc 0.53.0",
] ]
[[package]] [[package]]
@ -625,48 +657,96 @@ version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.53.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "86b8d5f90ddd19cb4a147a5fa63ca848db3df085e25fee3cc10b39b6eebae764"
[[package]] [[package]]
name = "windows_aarch64_msvc" name = "windows_aarch64_msvc"
version = "0.52.6" version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
[[package]]
name = "windows_aarch64_msvc"
version = "0.53.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c7651a1f62a11b8cbd5e0d42526e55f2c99886c77e007179efff86c2b137e66c"
[[package]] [[package]]
name = "windows_i686_gnu" name = "windows_i686_gnu"
version = "0.52.6" version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b"
[[package]]
name = "windows_i686_gnu"
version = "0.53.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1dc67659d35f387f5f6c479dc4e28f1d4bb90ddd1a5d3da2e5d97b42d6272c3"
[[package]] [[package]]
name = "windows_i686_gnullvm" name = "windows_i686_gnullvm"
version = "0.52.6" version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
[[package]]
name = "windows_i686_gnullvm"
version = "0.53.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ce6ccbdedbf6d6354471319e781c0dfef054c81fbc7cf83f338a4296c0cae11"
[[package]] [[package]]
name = "windows_i686_msvc" name = "windows_i686_msvc"
version = "0.52.6" version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
[[package]]
name = "windows_i686_msvc"
version = "0.53.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "581fee95406bb13382d2f65cd4a908ca7b1e4c2f1917f143ba16efe98a589b5d"
[[package]] [[package]]
name = "windows_x86_64_gnu" name = "windows_x86_64_gnu"
version = "0.52.6" version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
[[package]]
name = "windows_x86_64_gnu"
version = "0.53.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2e55b5ac9ea33f2fc1716d1742db15574fd6fc8dadc51caab1c16a3d3b4190ba"
[[package]] [[package]]
name = "windows_x86_64_gnullvm" name = "windows_x86_64_gnullvm"
version = "0.52.6" version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.53.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0a6e035dd0599267ce1ee132e51c27dd29437f63325753051e71dd9e42406c57"
[[package]] [[package]]
name = "windows_x86_64_msvc" name = "windows_x86_64_msvc"
version = "0.52.6" version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
[[package]]
name = "windows_x86_64_msvc"
version = "0.53.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "271414315aff87387382ec3d271b52d7ae78726f5d44ac98b4f4030c91880486"
[[package]] [[package]]
name = "zerocopy" name = "zerocopy"
version = "0.8.26" version = "0.8.26"

View file

@ -1,17 +1,22 @@
[package] [package]
name = "picca" name = "picca"
version = "0.5.0" version = "0.6.0"
edition = "2024" edition = "2024"
autobins = true autobins = true
[features] [features]
default = [] all = []
all-algorithms = [] single = []
[[bin]] [[bin]]
name = "picca" name = "picca"
path = "src/bin/picca.rs" path = "src/bin/picca.rs"
required-features = ["all-algorithms"] required-features = ["all"]
[profile.release]
opt-level = "z"
lto = true
strip = true
[dependencies] [dependencies]
sha2 = "0.10.9" sha2 = "0.10.9"

View file

@ -13,13 +13,13 @@ default: build-docker build-release doc
# main build # main build
build-release: build-release:
cargo build --release cargo build --release --features single
cargo build --release --bin picca --features all-algorithms cargo build --release --bin picca --features all
# debug build # debug build
build-debug: build-debug:
cargo build cargo build --features single
cargo build --bin picca --features all-algorithms cargo build --bin picca --features all
# build docker images locally # build docker images locally
build-docker: clean build-docker: clean

View file

@ -6,7 +6,7 @@ WORKDIR /usr/src/picca
COPY . . COPY . .
RUN apk upgrade --no-cache && apk add musl-dev RUN apk upgrade --no-cache && apk add musl-dev
RUN cargo install --path . --bin picca --features all-algorithms && cargo clean RUN cargo install --path . --bin picca --features all && cargo clean
FROM alpine:3 AS package FROM alpine:3 AS package

View file

@ -1,6 +1,6 @@
#[quit::main] #[quit::main]
fn main() { fn main() {
let args = picca::Args::parse(); let args = picca::Args::parse();
let algorithm = env!("CARGO_BIN_NAME").replace("sum", ""); let algorithm = args.algorithm;
picca::main!(args, algorithm, false); picca::main!(args, algorithm, false, None);
} }

View file

@ -1,6 +1,9 @@
use picca::core::hashers::hash_sha256;
#[quit::main] #[quit::main]
fn main() { fn main() {
let args = picca::Args::parse(); let args = picca::Args::parse();
let algorithm = env!("CARGO_BIN_NAME").replace("sum", ""); let algorithm = env!("CARGO_BIN_NAME").replace("sum", "");
picca::main!(args, algorithm, true); let hasher = hash_sha256 as fn(Option<File>, Option<String>) -> String;
picca::main!(args, algorithm, true, hasher);
} }

View file

@ -20,7 +20,10 @@ struct ThreadInfo {
quiet: bool, quiet: bool,
thread_id: usize, thread_id: usize,
filenames: Arc<Mutex<VecDeque<PathBuf>>>, filenames: Arc<Mutex<VecDeque<PathBuf>>>,
#[cfg(feature = "all")]
algorithm: Arc<String>, algorithm: Arc<String>,
#[cfg(feature = "single")]
hash_function: fn(Option<File>, Option<String>) -> String,
hash_map: Option<Arc<Mutex<HashMap<PathBuf, String>>>>, hash_map: Option<Arc<Mutex<HashMap<PathBuf, String>>>>,
file_errors: Arc<AtomicI32>, file_errors: Arc<AtomicI32>,
hash_errors: Arc<AtomicI32>, hash_errors: Arc<AtomicI32>,
@ -66,60 +69,10 @@ fn hash(info: ThreadInfo) -> Result<(), String> {
}); });
} }
let res = match &*info.algorithm.as_str() { #[cfg(feature = "all")]
"ascon" => hashers::hash_ascon(file, stdin), let res = hashers::run_algorithm(info.algorithm.to_string(), file, stdin);
"belt" => hashers::hash_belt(file, stdin), #[cfg(feature = "single")]
"blake2b512" => hashers::hash_blake2b512(file, stdin), let res = (info.hash_function)(file, stdin);
"blake2s256" => hashers::hash_blake2s256(file, stdin),
"blake3" => hashers::hash_blake3(file, stdin),
"fsb160" => hashers::hash_fsb160(file, stdin),
"fsb224" => hashers::hash_fsb224(file, stdin),
"fsb256" => hashers::hash_fsb256(file, stdin),
"fsb384" => hashers::hash_fsb384(file, stdin),
"fsb512" => hashers::hash_fsb512(file, stdin),
"gost94" => hashers::hash_gost94(file, stdin),
"groestl224" => hashers::hash_groestl224(file, stdin),
"groestl256" => hashers::hash_groestl256(file, stdin),
"groestl384" => hashers::hash_groestl384(file, stdin),
"groestl512" => hashers::hash_groestl512(file, stdin),
"jh224" => hashers::hash_jh224(file, stdin),
"jh256" => hashers::hash_jh256(file, stdin),
"jh384" => hashers::hash_jh384(file, stdin),
"jh512" => hashers::hash_jh512(file, stdin),
"k12" => hashers::hash_k12(file, stdin),
"md2" => hashers::hash_md2(file, stdin),
"md4" => hashers::hash_md4(file, stdin),
"md5" => hashers::hash_md5(file, stdin),
"ripemd128" => hashers::hash_ripemd128(file, stdin),
"ripemd160" => hashers::hash_ripemd160(file, stdin),
"ripemd256" => hashers::hash_ripemd256(file, stdin),
"ripemd320" => hashers::hash_ripemd320(file, stdin),
"sha1" => hashers::hash_sha1(file, stdin),
"sha224" => hashers::hash_sha224(file, stdin),
"sha256" => hashers::hash_sha256(file, stdin),
"sha384" => hashers::hash_sha384(file, stdin),
"sha512" => hashers::hash_sha512(file, stdin),
"sha3_224" => hashers::hash_sha3_224(file, stdin),
"sha3_256" => hashers::hash_sha3_256(file, stdin),
"sha3_384" => hashers::hash_sha3_384(file, stdin),
"sha3_512" => hashers::hash_sha3_512(file, stdin),
"shabal192" => hashers::hash_shabal192(file, stdin),
"shabal224" => hashers::hash_shabal224(file, stdin),
"shabal256" => hashers::hash_shabal256(file, stdin),
"shabal384" => hashers::hash_shabal384(file, stdin),
"shabal512" => hashers::hash_shabal512(file, stdin),
"shake128" => hashers::hash_shake128(file, stdin),
"shake256" => hashers::hash_shake256(file, stdin),
"skein256" => hashers::hash_skein256(file, stdin),
"skein512" => hashers::hash_skein512(file, stdin),
"skein1024" => hashers::hash_skein1024(file, stdin),
"sm3" => hashers::hash_sm3(file, stdin),
"streebog256" => hashers::hash_streebog256(file, stdin),
"streebog512" => hashers::hash_streebog512(file, stdin),
"tiger" => hashers::hash_tiger(file, stdin),
"whirlpool" => hashers::hash_whirlpool(file, stdin),
_ => panic!("Somehow did not pass a supported algorithm"),
};
match &info.hash_map { match &info.hash_map {
Some(h) => { Some(h) => {
@ -149,10 +102,11 @@ fn hash(info: ThreadInfo) -> Result<(), String> {
pub fn verify( pub fn verify(
cpus: usize, cpus: usize,
algorithm: String, #[cfg(feature = "all")] algorithm: String,
debug: bool, debug: bool,
quiet: bool, quiet: bool,
checksum_files: Vec<PathBuf>, checksum_files: Vec<PathBuf>,
#[cfg(feature = "single")] hash_function: fn(Option<File>, Option<String>) -> String,
) -> ( ) -> (
Vec<JoinHandle<Result<(), std::string::String>>>, Vec<JoinHandle<Result<(), std::string::String>>>,
Arc<AtomicI32>, Arc<AtomicI32>,
@ -198,6 +152,7 @@ pub fn verify(
let safe_fe = Arc::clone(&arc_fe); let safe_fe = Arc::clone(&arc_fe);
let safe_he = Arc::clone(&arc_he); let safe_he = Arc::clone(&arc_he);
let safe_buf = Arc::clone(&arc_buf); let safe_buf = Arc::clone(&arc_buf);
#[cfg(feature = "all")]
let safe_alg = Arc::new(algorithm.clone()); let safe_alg = Arc::new(algorithm.clone());
let safe_hash = Arc::clone(&arc_hash); let safe_hash = Arc::clone(&arc_hash);
handles.push(thread::spawn(move || { handles.push(thread::spawn(move || {
@ -206,7 +161,10 @@ pub fn verify(
quiet, quiet,
thread_id: i, thread_id: i,
filenames: safe_buf, filenames: safe_buf,
#[cfg(feature = "all")]
algorithm: safe_alg, algorithm: safe_alg,
#[cfg(feature = "single")]
hash_function,
hash_map: Some(safe_hash), hash_map: Some(safe_hash),
file_errors: safe_fe, file_errors: safe_fe,
hash_errors: safe_he, hash_errors: safe_he,
@ -220,9 +178,10 @@ pub fn verify(
pub fn generate( pub fn generate(
cpus: usize, cpus: usize,
buffer: VecDeque<PathBuf>, buffer: VecDeque<PathBuf>,
algorithm: String, #[cfg(feature = "all")] algorithm: String,
debug: bool, debug: bool,
quiet: bool, quiet: bool,
#[cfg(feature = "single")] hash_function: fn(Option<File>, Option<String>) -> String,
) -> ( ) -> (
Vec<JoinHandle<Result<(), std::string::String>>>, Vec<JoinHandle<Result<(), std::string::String>>>,
Arc<AtomicI32>, Arc<AtomicI32>,
@ -243,6 +202,7 @@ pub fn generate(
let safe_fe = Arc::clone(&arc_fe); let safe_fe = Arc::clone(&arc_fe);
let safe_he = Arc::clone(&arc_he); let safe_he = Arc::clone(&arc_he);
let safe_buf = Arc::clone(&arc_buf); let safe_buf = Arc::clone(&arc_buf);
#[cfg(feature = "all")]
let safe_alg = Arc::new(algorithm.clone()); let safe_alg = Arc::new(algorithm.clone());
handles.push(thread::spawn(move || { handles.push(thread::spawn(move || {
hash(ThreadInfo { hash(ThreadInfo {
@ -250,7 +210,10 @@ pub fn generate(
quiet, quiet,
thread_id: i, thread_id: i,
filenames: safe_buf, filenames: safe_buf,
#[cfg(feature = "all")]
algorithm: safe_alg, algorithm: safe_alg,
#[cfg(feature = "single")]
hash_function,
hash_map: None, hash_map: None,
file_errors: safe_fe, file_errors: safe_fe,
hash_errors: safe_he, hash_errors: safe_he,

View file

@ -23,6 +23,63 @@ use streebog::{Streebog256, Streebog512};
use tiger::Tiger; use tiger::Tiger;
use whirlpool::Whirlpool; use whirlpool::Whirlpool;
pub fn run_algorithm(algorithm: String, file: Option<File>, stdin: Option<String>) -> String {
return match &*algorithm.as_str() {
"ascon" => hash_ascon(file, stdin),
"belt" => hash_belt(file, stdin),
"blake2b512" => hash_blake2b512(file, stdin),
"blake2s256" => hash_blake2s256(file, stdin),
"blake3" => hash_blake3(file, stdin),
"fsb160" => hash_fsb160(file, stdin),
"fsb224" => hash_fsb224(file, stdin),
"fsb256" => hash_fsb256(file, stdin),
"fsb384" => hash_fsb384(file, stdin),
"fsb512" => hash_fsb512(file, stdin),
"gost94" => hash_gost94(file, stdin),
"groestl224" => hash_groestl224(file, stdin),
"groestl256" => hash_groestl256(file, stdin),
"groestl384" => hash_groestl384(file, stdin),
"groestl512" => hash_groestl512(file, stdin),
"jh224" => hash_jh224(file, stdin),
"jh256" => hash_jh256(file, stdin),
"jh384" => hash_jh384(file, stdin),
"jh512" => hash_jh512(file, stdin),
"k12" => hash_k12(file, stdin),
"md2" => hash_md2(file, stdin),
"md4" => hash_md4(file, stdin),
"md5" => hash_md5(file, stdin),
"ripemd128" => hash_ripemd128(file, stdin),
"ripemd160" => hash_ripemd160(file, stdin),
"ripemd256" => hash_ripemd256(file, stdin),
"ripemd320" => hash_ripemd320(file, stdin),
"sha1" => hash_sha1(file, stdin),
"sha224" => hash_sha224(file, stdin),
"sha256" => hash_sha256(file, stdin),
"sha384" => hash_sha384(file, stdin),
"sha512" => hash_sha512(file, stdin),
"sha3_224" => hash_sha3_224(file, stdin),
"sha3_256" => hash_sha3_256(file, stdin),
"sha3_384" => hash_sha3_384(file, stdin),
"sha3_512" => hash_sha3_512(file, stdin),
"shabal192" => hash_shabal192(file, stdin),
"shabal224" => hash_shabal224(file, stdin),
"shabal256" => hash_shabal256(file, stdin),
"shabal384" => hash_shabal384(file, stdin),
"shabal512" => hash_shabal512(file, stdin),
"shake128" => hash_shake128(file, stdin),
"shake256" => hash_shake256(file, stdin),
"skein256" => hash_skein256(file, stdin),
"skein512" => hash_skein512(file, stdin),
"skein1024" => hash_skein1024(file, stdin),
"sm3" => hash_sm3(file, stdin),
"streebog256" => hash_streebog256(file, stdin),
"streebog512" => hash_streebog512(file, stdin),
"tiger" => hash_tiger(file, stdin),
"whirlpool" => hash_whirlpool(file, stdin),
_ => panic!("Somehow did not pass a supported algorithm"),
};
}
pub fn hash_streebog256(file: Option<File>, stdin: Option<String>) -> String { pub fn hash_streebog256(file: Option<File>, stdin: Option<String>) -> String {
let mut hasher = Streebog256::new(); let mut hasher = Streebog256::new();
if file.is_some() { if file.is_some() {

View file

@ -1,10 +1,9 @@
#[macro_export] #[macro_export]
macro_rules! main { macro_rules! main {
($args: expr, $algorithm: expr, $independent: expr) => { ($args: expr, $algorithm: expr, $independent: expr, $hasher: expr) => {
use clap::Parser; use clap::Parser;
use std::collections::VecDeque; use std::collections::VecDeque;
use std::fs::{self}; use std::fs::{self, File};
use std::path::PathBuf; use std::path::PathBuf;
use std::sync::atomic::Ordering; use std::sync::atomic::Ordering;
use std::thread::available_parallelism; use std::thread::available_parallelism;
@ -25,7 +24,7 @@ macro_rules! main {
}; };
if $args.debug { if $args.debug {
if env!("CARGO_BIN_NAME") != "picca" { if env!("CARGO_BIN_NAME") == "picca" {
message::debug(format!( message::debug(format!(
"Starting picca using algorithm {} with a max of {} threads", "Starting picca using algorithm {} with a max of {} threads",
$algorithm, cpus $algorithm, cpus
@ -52,7 +51,16 @@ macro_rules! main {
let arc_he; let arc_he;
let check_mode = !$args.check.is_empty(); let check_mode = !$args.check.is_empty();
if &$args.check.len() >= &1 { if &$args.check.len() >= &1 {
(handles, arc_fe, arc_he) = picca::core::verify(cpus, $algorithm, $args.debug, $args.quiet, $args.check); (handles, arc_fe, arc_he) = picca::core::verify(
cpus,
#[cfg(feature = "all")]
$algorithm,
$args.debug,
$args.quiet,
$args.check,
#[cfg(feature = "single")]
$hasher,
);
} else { } else {
let mut buffer = VecDeque::new(); let mut buffer = VecDeque::new();
if &$args.files.len() >= &1 { if &$args.files.len() >= &1 {
@ -71,7 +79,16 @@ macro_rules! main {
buffer.push_back(PathBuf::from("-")); buffer.push_back(PathBuf::from("-"));
} }
(handles, arc_fe, arc_he) = picca::core::generate(cpus, buffer, $algorithm, $args.debug, $args.quiet); (handles, arc_fe, arc_he) = picca::core::generate(
cpus,
buffer,
#[cfg(feature = "all")]
$algorithm,
$args.debug,
$args.quiet,
#[cfg(feature = "single")]
$hasher,
);
} }
for handle in handles { for handle in handles {

View file

@ -82,7 +82,7 @@ pub struct Args {
)] )]
pub debug: bool, pub debug: bool,
#[cfg(feature = "all-algorithms")] #[cfg(feature = "all")]
#[arg( #[arg(
short, short,
long, long,