ytls_rustcrypto/hmac/
hmac_sha384.rs

1//! yTLS RustCrypto HMAC SHA384
2
3use hmac::{Hmac, KeyInit, Mac};
4use sha2::{Digest, Sha384};
5use ytls_traits::CryptoSha384HmacProcessor;
6
7/// RustCrypto Sha384Hmac
8#[derive(Clone)]
9pub struct Sha384Hmac {
10    hmac: Hmac<Sha384>,
11}
12
13impl Sha384Hmac {
14    pub fn sha384_hmac_init_with_key(key: &[u8; 48]) -> Self {
15        // SAFETY: Safe to unwrap with fixed legth key
16        let hmac = Hmac::<Sha384>::new_from_slice(key).unwrap();
17
18        Sha384Hmac { hmac }
19    }
20}
21
22impl CryptoSha384HmacProcessor for Sha384Hmac {
23    fn hmac_sha384_update(&mut self, d: &[u8]) -> () {
24        self.hmac.update(d)
25    }
26    fn hmac_sha384_fork(&self) -> Self {
27        self.clone()
28    }
29    fn hmac_sha384_finalize(self) -> [u8; 48] {
30        self.hmac.finalize().into_bytes().into()
31    }
32}