Skip to main content

crypto_dispatch/algorithms/
sha3.rs

1// SPDX-FileCopyrightText: Copyright © 2026 ReallyMe LLC. All rights reserved
2//
3// SPDX-License-Identifier: Apache-2.0
4
5use crate::traits::HashDigestAlgorithm;
6use crate::AlgorithmError;
7use crypto_core::HashAlgorithm;
8
9/// SHA3-224 hash adapter.
10pub struct Sha3_224Algo;
11
12/// SHA3-384 hash adapter.
13pub struct Sha3_384Algo;
14
15/// SHA3-512 hash adapter.
16pub struct Sha3_512Algo;
17
18impl HashDigestAlgorithm for Sha3_224Algo {
19    const ALG: HashAlgorithm = HashAlgorithm::Sha3_224;
20
21    fn digest(message: &[u8]) -> Result<Vec<u8>, AlgorithmError> {
22        let digest = crypto_sha3::digest_sha3_224(message);
23        Ok(digest.as_bytes().to_vec())
24    }
25}
26
27impl HashDigestAlgorithm for Sha3_384Algo {
28    const ALG: HashAlgorithm = HashAlgorithm::Sha3_384;
29
30    fn digest(message: &[u8]) -> Result<Vec<u8>, AlgorithmError> {
31        let digest = crypto_sha3::digest_sha3_384(message);
32        Ok(digest.as_bytes().to_vec())
33    }
34}
35
36impl HashDigestAlgorithm for Sha3_512Algo {
37    const ALG: HashAlgorithm = HashAlgorithm::Sha3_512;
38
39    fn digest(message: &[u8]) -> Result<Vec<u8>, AlgorithmError> {
40        let digest = crypto_sha3::digest_sha3_512(message);
41        Ok(digest.as_bytes().to_vec())
42    }
43}