CryptoEngine

Struct CryptoEngine 

Source
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>

Source

pub fn new(aes: A, sha: S) -> Self

Create a new engine from algorithm providers.

Source

pub fn derive_pairwise_keys(&self, shared_secret: &SharedSecret) -> PairwiseKeys

Derive stable pairwise encryption and MIC keys from a shared secret.

Source

pub fn derive_channel_id(&self, channel_key: &ChannelKey) -> ChannelId

Derive the channel identifier from a raw channel key.

Source

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.

Source

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.

Source

pub fn derive_channel_keys( &self, channel_key: &ChannelKey, ) -> DerivedChannelKeys

Derive multicast transport keys and the channel identifier.

Source

pub fn derive_blind_keys( &self, pairwise: &PairwiseKeys, channel: &DerivedChannelKeys, ) -> PairwiseKeys

Combine pairwise and channel keys for blind-unicast payload protection.

Source

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.

Source

pub fn seal_packet( &self, packet: &mut UnsealedPacket<'_>, keys: &PairwiseKeys, ) -> Result<usize, CryptoError>

Seal a unicast or multicast packet in place.

Source

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.

Source

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.

Source

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.

Source

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 of full_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.

Source

pub fn cmac_state(&self, key: &[u8; 16]) -> CmacState<A::Cipher>

Create a reusable incremental CMAC state.

Source

pub fn aes_cmac(&self, key: &[u8; 16], data: &[&[u8]]) -> [u8; 16]

Convenience wrapper for AES-CMAC over concatenated slices.

Source

pub fn aes_ctr(&self, key: &[u8; 16], iv: &[u8; 16], data: &mut [u8])

Apply AES-CTR using iv as the initial counter block.

Source

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]).

Source

pub fn hkdf(&self, ikm: &[u8], salt: &[u8], info: &[u8], okm: &mut [u8])

Run HKDF-SHA256 and write the output into okm.

Auto Trait Implementations§

§

impl<A, S> Freeze for CryptoEngine<A, S>
where A: Freeze, S: Freeze,

§

impl<A, S> RefUnwindSafe for CryptoEngine<A, S>

§

impl<A, S> Send for CryptoEngine<A, S>
where A: Send, S: Send,

§

impl<A, S> Sync for CryptoEngine<A, S>
where A: Sync, S: Sync,

§

impl<A, S> Unpin for CryptoEngine<A, S>
where A: Unpin, S: Unpin,

§

impl<A, S> UnwindSafe for CryptoEngine<A, S>
where A: UnwindSafe, S: UnwindSafe,

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.