pub struct SecurityContext {
pub security_control: u8,
pub encryption_key: Vec<u8>,
pub authentication_key: Vec<u8>,
pub system_title: Vec<u8>,
pub invocation_counter: u32,
last_peer_ic: u32,
ic_valid: bool,
}Expand description
The security material and parameters for one ciphering operation.
Fields§
§security_control: u8Security control byte (SC).
encryption_key: Vec<u8>Block cipher (encryption) key, 16 or 32 octets.
authentication_key: Vec<u8>Authentication key (AK), used in the additional authenticated data.
system_title: Vec<u8>System title, 8 octets (forms the IV together with the IC).
invocation_counter: u32Invocation counter (IC).
last_peer_ic: u32The last invocation counter accepted from the peer, for replay
rejection. Set by for_suite; updated by the *_unprotect functions.
ic_valid: boolWhether last_peer_ic holds a value yet (false until the first
successful unprotect).
Implementations§
Source§impl SecurityContext
impl SecurityContext
Sourcepub fn for_suite(
policy: SecurityPolicy,
suite: SecuritySuite,
encryption_key: Vec<u8>,
authentication_key: Vec<u8>,
system_title: Vec<u8>,
invocation_counter: u32,
) -> Result<SecurityContext, CipherError>
pub fn for_suite( policy: SecurityPolicy, suite: SecuritySuite, encryption_key: Vec<u8>, authentication_key: Vec<u8>, system_title: Vec<u8>, invocation_counter: u32, ) -> Result<SecurityContext, CipherError>
Builds a context for a given protection level and security suite, validating that the encryption key length matches the suite (16 octets for suites 0/1, 32 for suite 2) and deriving the security control byte from the policy and the suite id.
Sourcefn check_replay(&self, ic: u32) -> Result<(), CipherError>
fn check_replay(&self, ic: u32) -> Result<(), CipherError>
Checks the received invocation counter against the last one accepted from this peer, rejecting a replayed or reordered-backward APDU before any decryption is attempted (IEC 62056-5-3: the IC must increase monotonically per peer).
Sourcefn accept_peer_ic(&mut self, ic: u32)
fn accept_peer_ic(&mut self, ic: u32)
Records ic as the last invocation counter accepted from the peer,
after a successful unprotect.
Sourcefn check_send_ic(&self) -> Result<(), CipherError>
fn check_send_ic(&self) -> Result<(), CipherError>
Rejects protecting an APDU once the invocation counter has reached its maximum value: it must never wrap back to a smaller value, per IEC 62056-5-3. Re-keying (a fresh IC) is required past this point.
Sourcepub fn key_rotation_needed(&self) -> bool
pub fn key_rotation_needed(&self) -> bool
Advisory check for the host: true once the invocation counter is
within 1000 of overflow, signalling that the keys should be rotated
(a fresh system-title/key pair resets the counter) before
CipherError::InvocationCounterExhausted starts rejecting sends.
fn authentication(&self) -> bool
fn encryption(&self) -> bool
fn iv(&self) -> Result<[u8; 12], CipherError>
Trait Implementations§
Source§impl Clone for SecurityContext
impl Clone for SecurityContext
Source§fn clone(&self) -> SecurityContext
fn clone(&self) -> SecurityContext
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more