static_dh_ecdh/digest.rs
1// #![allow(warnings)]
2
3use sha2::{Sha256, Sha384, Digest};
4
5use core::convert::TryInto;
6
7
8/// A struct representing a SHA256 Digest instance
9pub struct SHA256Digest;
10
11impl SHA256Digest {
12 /// Computes the SHA256 digest of a slice of bytes.
13 pub fn digest(&self, data: &[u8]) -> [u8; 32] {
14 let sha256: [u8; 32] = Sha256::digest(data).as_slice().try_into().unwrap();
15 sha256
16 }
17
18 /// Returns the length of SHA256 Digest
19 pub fn get_length() -> u8 {
20 0x20
21 }
22
23 /// Returns the Hash algorithm id. This is used to identify the hashing algorithm in HIPv2
24 pub fn get_alg_id() -> u8 {
25 0x1
26 }
27}
28
29/// A struct representing a SHA384 Digest instance
30pub struct SHA384Digest;
31
32impl SHA384Digest {
33 /// Computes the SHA384 digest of a slice of bytes.
34 pub fn digest(&self, data: &[u8]) -> [u8; 48] {
35 let sha384: [u8; 48] = Sha384::digest(data).as_slice().try_into().unwrap();
36 sha384
37 }
38
39 /// Returns the length of SHA384 Digest
40 pub fn get_length(&self) -> u8 {
41 0x30
42 }
43
44 /// Returns the Hash algorithm id. This is used to identify the hashing algorithm in HIPv2
45 pub fn get_alg_id() -> u8 {
46 0x2
47 }
48}