//! BLAKE2b wrappers for Handshake's two output sizes. //! //! - 256-bit: transaction hashes, sighash preimage hash. Uses the SDK's `Blake2b_256`. //! - 160-bit: P2WPKH witness program (pubkey hash). Implemented locally because //! the SDK only ships Blake2b_{256,384,512}; we mirror the SDK's `impl_hash!` //! pattern with the cxlib syscall configured for a 160-bit digest. use ledger_device_sdk::hash::{blake2::Blake2b_256, HashInit}; use ledger_secure_sdk_sys::{cx_blake2b_init_no_throw, cx_blake2b_t, cx_hash_t}; pub fn blake2b_256(data: &[u8]) -> [u8; 32] { let mut h = Blake2b_256::new(); let mut out = [0u8; 32]; let _ = h.hash(data, &mut out); out } #[derive(Default)] #[allow(non_camel_case_types)] pub struct Blake2b_160 { ctx: cx_blake2b_t, } impl HashInit for Blake2b_160 { fn as_ctx_mut(&mut self) -> &mut cx_hash_t { &mut self.ctx.header } fn as_ctx(&self) -> &cx_hash_t { &self.ctx.header } fn new() -> Self { let mut h: Self = Default::default(); let _ = unsafe { cx_blake2b_init_no_throw(&mut h.ctx, 160) }; h } fn reset(&mut self) { let _ = unsafe { cx_blake2b_init_no_throw(&mut self.ctx, 160) }; } } pub fn blake2b_160(data: &[u8]) -> [u8; 20] { let mut h = Blake2b_160::new(); let mut out = [0u8; 20]; let _ = h.hash(data, &mut out); out }