Skip to main content

Module service

Module service 

Source
Expand description

High-level crypto service exposed to the USB layer.

This is where the actual workflow logic lives: PIN session management, PIN/PUK verification with counter accounting, sign orchestration on top of Nonce + Sign, and public-key retrieval.

The service is generic over both the HAL (so it can run against a real ATECC over I2C or against a MockHal in tests) and the Clock (so tests can drive time deterministically).

§Channel discipline

Every public method on CryptoService is responsible for opening and closing the chip channel(s) it needs.

  • For a single-shot chip command (e.g. read one counter), the method opens a channel, runs the command, closes the channel.
  • For a multi-step chip workflow that shares volatile state (Nonce + Sign, Nonce + GenDig + Write), the method opens one channel that spans the whole sequence, so TempKey stays alive across the steps.
  • For workflows that combine several independent chip commands (e.g. read counter, then CheckMac, then read counter again), the method may either keep one channel open for the whole flow or open one per command. The choice is documented per method when it matters; the default is to open one per logical step for clarity.

The PIN “session” referred to elsewhere in this crate is unrelated to the chip channel. It is the host-side authentication window that says “the user has typed a valid PIN recently”. See Session.

Structs§

CryptoService
High-level crypto orchestrator.
DeviceInfo
Returned by CryptoService::info.
PinStatus
Returned by CryptoService::get_pin_status.

Constants§

CHIP_SERIAL_LEN 🔒
Length of the chip serial number, in bytes, as read from the config zone.

Functions§

can_write_block_in_one_transfer 🔒
Whether the chip accepts a single 32-byte Write for the whole block.
retries_remaining 🔒
Compute how many CheckMac attempts remain before the next batch threshold is hit.
writable_words_in_block 🔒
Set of word offsets (within a 32-byte config-zone block) that the chip’s Write command accepts in 4-byte mode.

Type Aliases§

PublicKey 🔒
64-byte raw public key returned by GenKey.
ServiceResult 🔒
Convenience alias for the service’s result type.
Signature 🔒
64-byte raw R || S ECDSA signature returned by Sign.