ferogram_crypto/sha.rs
1// Copyright (c) Ankit Chaubey <ankitchaubey.dev@gmail.com>
2// SPDX-License-Identifier: MIT OR Apache-2.0
3//
4// ferogram: async Telegram MTProto client in Rust
5// https://github.com/ankit-chaubey/ferogram
6//
7// Based on layer: https://github.com/ankit-chaubey/layer
8// Follows official Telegram client behaviour (tdesktop, TDLib).
9//
10// If you use or modify this code, keep this notice at the top of your file
11// and include the LICENSE-MIT or LICENSE-APACHE file from this repository:
12// https://github.com/ankit-chaubey/ferogram
13
14/// Calculate the SHA-1 hash of one or more byte slices concatenated.
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}