Skip to main content

Module rmac_session

Module rmac_session 

Source
Expand description

BEGIN / END R-MAC SESSION (CLA 80, INS 7A / 78) — SCP02 response integrity.

These frame an SCP02 R-MAC session: BEGIN R-MAC SESSION tells the card to start appending an R-MAC to each response, and END R-MAC SESSION retrieves (and optionally ends) the accumulated R-MAC. They build the plaintext C-APDU only; the session/backend applies CLA | 0x04 + C-MAC afterwards (the commands must themselves be sent inside the secure channel).

Coding (GPCS v2.3.1 Appendix E; the parameter tables mirror Amendment D §7.x for SCP03, and are cross-checked byte-for-byte against the skythen/scp02 Go reference, beginRMACSession/EndRMACSession):

  • BEGIN: INS 0x7A, P1 0x10 (each response carries an R-MAC — for SCP02 which has no response encryption, 0x30/R-ENC does not apply), P2 0x00. The data field is an LV-coded ‘data’ element (len ‖ data). The card does not interpret ‘data’ but folds it into the R-MAC, letting the host inject a challenge; the LV total is ≤ 25 bytes, so data is 1..=24 bytes.
  • END: INS 0x78, P1 0x00, P2 0x03 (end the session and return the R-MAC) or 0x01 (return the current R-MAC without ending). No data field; Le = 00 requests the 8-byte R-MAC in the response.

Functions§

begin_rmac_session
Build a BEGIN R-MAC SESSION (CLA 80, INS 7A) plaintext C-APDU.
end_rmac_session
Build an END R-MAC SESSION (CLA 80, INS 78) plaintext C-APDU. end_session selects P2 0x03 (end and return the R-MAC) vs 0x01 (return only). The response returns the 8-byte R-MAC, so Le = 00 is present.