src/backup/crypt_config.rs: new compute_auth_tag helper

This commit is contained in:
Dietmar Maurer 2019-08-02 08:55:37 +02:00
parent c68d2170d5
commit 93205f942a
1 changed files with 13 additions and 0 deletions

View File

@ -62,6 +62,19 @@ impl CryptConfig {
digest digest
} }
/// Compute authentication tag (hmac/sha256)
///
/// Computes an SHA256 HMAC using some secret data (derived
/// from the secret key) and the provided data.
pub fn compute_auth_tag(&self, data: &[u8]) -> [u8; 32] {
let key = openssl::pkey::PKey::hmac(&self.id_key).unwrap();
let mut signer = openssl::sign::Signer::new(MessageDigest::sha256(), &key).unwrap();
signer.update(data).unwrap();
let mut tag = [0u8; 32];
signer.sign(&mut tag).unwrap();
tag
}
/// Encrypt data using a random 16 byte IV. /// Encrypt data using a random 16 byte IV.
/// ///
/// Writes encrypted data to ``output``, Return the used IV and computed MAC. /// Writes encrypted data to ``output``, Return the used IV and computed MAC.