ferogram_crypto/sha.rs
1/*
2 * Copyright (c) 2026 Ankit Chaubey <ankitchaubey.dev@gmail.com>
3 * https://github.com/ankit-chaubey
4 *
5 * Project: ferogram
6 * Website: https://ferogram.dev
7 *
8 * Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
9 * https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
10 * <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
11 * This file may not be copied, modified, or distributed except according
12 * to those terms.
13 */
14
15#[macro_export]
16macro_rules! sha1 {
17 ( $( $x:expr ),+ ) => {{
18 use sha1::{Digest, Sha1};
19 let mut h = Sha1::new();
20 $( h.update($x); )+
21 let out: [u8; 20] = h.finalize().into();
22 out
23 }};
24}
25
26/// Calculate the SHA-256 hash of one or more byte slices concatenated.
27#[macro_export]
28macro_rules! sha256 {
29 ( $( $x:expr ),+ ) => {{
30 use sha2::{Digest, Sha256};
31 let mut h = Sha256::new();
32 $( h.update($x); )+
33 let out: [u8; 32] = h.finalize().into();
34 out
35 }};
36}