pub struct CryptoEngine<A: AesProvider, S: Sha256Provider> { /* private fields */ }Expand description
UMSH protocol crypto engine.
Implementations§
Source§impl<A: AesProvider, S: Sha256Provider> CryptoEngine<A, S>
impl<A: AesProvider, S: Sha256Provider> CryptoEngine<A, S>
Sourcepub fn derive_pairwise_keys(&self, shared_secret: &SharedSecret) -> PairwiseKeys
pub fn derive_pairwise_keys(&self, shared_secret: &SharedSecret) -> PairwiseKeys
Derive stable pairwise encryption and MIC keys from a shared secret.
Sourcepub fn derive_channel_id(&self, channel_key: &ChannelKey) -> ChannelId
pub fn derive_channel_id(&self, channel_key: &ChannelKey) -> ChannelId
Derive the channel identifier from a raw channel key.
Sourcepub fn derive_channel_tint(&self, channel_key: &ChannelKey) -> [u8; 3]
pub fn derive_channel_tint(&self, channel_key: &ChannelKey) -> [u8; 3]
Derive three bytes for presentation — a deterministic colour a user interface can give a channel.
This is the channel-identifier derivation run one byte longer, so the first two bytes are the channel identifier itself: HKDF-Expand emits a prefix of the same block either way. Nothing on the wire carries the third byte, and nothing depends on it.
Sourcepub fn derive_channel_tag(&self, channel_key: &ChannelKey) -> ChannelTag
pub fn derive_channel_tag(&self, channel_key: &ChannelKey) -> ChannelTag
Derive the channel tag — a local identity wide enough to tell apart two channels whose keys derive the same channel identifier.
Same derivation as the channel identifier, run to sixteen bytes, so the identifier and the presentation tint are prefixes of it.
Sourcepub fn derive_channel_keys(
&self,
channel_key: &ChannelKey,
) -> DerivedChannelKeys
pub fn derive_channel_keys( &self, channel_key: &ChannelKey, ) -> DerivedChannelKeys
Derive multicast transport keys and the channel identifier.
Sourcepub fn derive_blind_keys(
&self,
pairwise: &PairwiseKeys,
channel: &DerivedChannelKeys,
) -> PairwiseKeys
pub fn derive_blind_keys( &self, pairwise: &PairwiseKeys, channel: &DerivedChannelKeys, ) -> PairwiseKeys
Combine pairwise and channel keys for blind-unicast payload protection.
Sourcepub fn derive_named_channel_key(
&self,
name: &str,
) -> Result<ChannelKey, ChannelNameError>
pub fn derive_named_channel_key( &self, name: &str, ) -> Result<ChannelKey, ChannelNameError>
Derive a channel key from a human-readable channel name.
The name is canonicalized first, per the spec (multicast-channels.md
§ Named Channels): it must be ASCII, and ASCII letters are folded to
lowercase before derivation — so Public, public, and PUBLIC all
derive the same key. Non-ASCII names are rejected (UTF-8 case-folding
is deferred by the spec). Names longer than
MAX_CHANNEL_NAME_LEN are rejected as an implementation limit of
the no-alloc canonicalization buffer.
Sourcepub fn seal_packet(
&self,
packet: &mut UnsealedPacket<'_>,
keys: &PairwiseKeys,
) -> Result<usize, CryptoError>
pub fn seal_packet( &self, packet: &mut UnsealedPacket<'_>, keys: &PairwiseKeys, ) -> Result<usize, CryptoError>
Seal a unicast or multicast packet in place.
Sourcepub fn seal_blind_packet(
&self,
packet: &mut UnsealedPacket<'_>,
blind_keys: &PairwiseKeys,
channel_keys: &DerivedChannelKeys,
) -> Result<usize, CryptoError>
pub fn seal_blind_packet( &self, packet: &mut UnsealedPacket<'_>, blind_keys: &PairwiseKeys, channel_keys: &DerivedChannelKeys, ) -> Result<usize, CryptoError>
Seal a blind-unicast packet, including its hidden address block.
Sourcepub fn open_packet(
&self,
buf: &mut [u8],
header: &PacketHeader,
keys: &PairwiseKeys,
) -> Result<Range<usize>, CryptoError>
pub fn open_packet( &self, buf: &mut [u8], header: &PacketHeader, keys: &PairwiseKeys, ) -> Result<Range<usize>, CryptoError>
Verify and, if needed, decrypt a received secure packet in place.
Sourcepub fn decrypt_blind_addr(
&self,
buf: &mut [u8],
header: &PacketHeader,
channel_keys: &DerivedChannelKeys,
) -> Result<(NodeHint, SourceAddrRef), CryptoError>
pub fn decrypt_blind_addr( &self, buf: &mut [u8], header: &PacketHeader, channel_keys: &DerivedChannelKeys, ) -> Result<(NodeHint, SourceAddrRef), CryptoError>
Decrypt the blinded destination/source address block of a blind unicast.
Sourcepub fn compute_ack_trailer(
&self,
full_cmac: &[u8; 16],
k_enc: &[u8; 16],
) -> [u8; 8]
pub fn compute_ack_trailer( &self, full_cmac: &[u8; 16], k_enc: &[u8; 16], ) -> [u8; 8]
Compute the 8-byte MAC ack trailer (ack_mic || ack_tag) from a full
CMAC and k_enc.
The trailer splits into two 4-byte halves:
ack_mic= the first 4 bytes offull_cmac. Because the on-wire MIC is a prefix-truncation of the full CMAC, this equals the first 4 bytes of the acknowledged packet’s on-wire MIC — a public correlation handle any node that received the original packet (including forwarding repeaters) can compute.ack_tag=truncate_4( AES-128-ECB(k_enc, full_cmac) ). A keyed value only the original sender and final destination can produce; it authenticates the standalone ack.
See the spec’s Ack Tag Construction section.
Sourcepub fn cmac_state(&self, key: &[u8; 16]) -> CmacState<A::Cipher>
pub fn cmac_state(&self, key: &[u8; 16]) -> CmacState<A::Cipher>
Create a reusable incremental CMAC state.
Sourcepub fn aes_cmac(&self, key: &[u8; 16], data: &[&[u8]]) -> [u8; 16]
pub fn aes_cmac(&self, key: &[u8; 16], data: &[&[u8]]) -> [u8; 16]
Convenience wrapper for AES-CMAC over concatenated slices.
Sourcepub fn aes_ctr(&self, key: &[u8; 16], iv: &[u8; 16], data: &mut [u8])
pub fn aes_ctr(&self, key: &[u8; 16], iv: &[u8; 16], data: &mut [u8])
Apply AES-CTR using iv as the initial counter block.
Sourcepub fn build_ctr_iv(&self, mic: &[u8], sec_info_bytes: &[u8]) -> [u8; 16]
pub fn build_ctr_iv(&self, mic: &[u8], sec_info_bytes: &[u8]) -> [u8; 16]
Construct the CTR IV from MIC bytes and SECINFO bytes.
With a 16-byte MIC the IV is the MIC alone; shorter MICs are
padded from the SECINFO bytes, so the IV construction of a
received packet must locate SECINFO exactly (see
[sec_info_bytes_range]).