tasign 0.2.0

TA ELF signing utilities with CMS/PKCS#7 support
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
//! Hash helpers via mbedtls `Md`.

extern crate alloc;

pub use mbedtls::hash::{Md, Type as MdType};

/// Compute a 32-byte digest with the given hash algorithm.
pub fn digest32(md: MdType, data: &[u8]) -> crate::crypto::Result<[u8; 32]> {
    let mut out = [0u8; 32];
    Md::hash(md, data, &mut out).map_err(map_mbedtls_err)?;
    Ok(out)
}

pub(crate) fn map_mbedtls_err(e: mbedtls::Error) -> crate::crypto::CryptoError {
    crate::crypto::CryptoError::Message(alloc::format!("mbedtls: {e:?}"))
}