ssh/algorithm/mac/
hmac_sha1.rs1use crate::algorithm::mac::Mac;
2use ring::hmac;
3use ring::hmac::{Context, Tag};
4
5const BSIZE: usize = 20;
6
7pub(super) struct HMacSha1;
8
9impl Mac for HMacSha1 {
10 fn sign(&self, ik: &[u8], sequence_num: u32, buf: &[u8]) -> Tag {
11 let ik = &ik[..BSIZE];
12 let key = hmac::Key::new(hmac::HMAC_SHA1_FOR_LEGACY_USE_ONLY, ik);
13 let mut c = Context::with_key(&key);
14 c.update(sequence_num.to_be_bytes().as_slice());
15 c.update(buf);
16 c.sign()
17 }
18
19 fn new() -> Self
20 where
21 Self: Sized,
22 {
23 HMacSha1
24 }
25
26 fn bsize(&self) -> usize {
27 BSIZE
28 }
29}