pub fn put_key(
p1: u8,
new_kvn: u8,
blocks: &[KeyBlock<'_>; 3],
) -> Result<Capdu, BuildError>Expand description
Build the PUT KEY C-APDU plaintext for a 3-key set.
CLA=84 INS=D8, P1 = p1 (caller passes new_kvn to replace or 0x00 to
add), P2 fixed 0x81 (multiple-key + first KID 0x01). Data =
new_kvn ‖ key_block{ENC,MAC,DEK} (GPCS §11.8.2.3.1).
Per key block:
- SCP03 AES (
key_type == 0x88, GPCS Amendment D v1.1.x §7.2):key_type ‖ block_len ‖ aes_key_len ‖ enc_key ‖ 0x03 ‖ KCV, where the encrypted key value is preceded by the clear AES key length andblock_len = 1 + len(enc_key). (For AES-128 the clear length equals the 16-byte ciphertext length.) Omittingaes_key_lenmakes JCOP / the JCDK simulator reject the command (observed6A88). - SCP02 3DES (
key_type == 0x80):key_type ‖ len(enc_key) ‖ enc_key ‖ 0x03 ‖ KCV— no inner length.
The KCV length is fixed at 3 (crate::limits::KCV_LEN, matching
KeyBlock::kcv: [u8; 3]).
§Errors
Returns BuildError::Overflow if the encoded inputs would exceed the
short-APDU plaintext buffer (CAPDU_MAX).