Skip to content

Commit dbe2801

Browse files
Update SecureApplet.md
1 parent 6c3c104 commit dbe2801

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

docs/SecureApplet.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Example: `B0B20000` -> returns 65 bytes with static public key of the card, for
4040

4141
## Establish secure channel
4242

43-
For secure communication we need to establish shared secrets. For this we use ECDH key agreement. We use `AES_CBC` for encryption with `M2` padding (add `0x8000..00` to round to 16-byte blocks). HMAC-SHA256 is used for authentication and applied to the ciphertext (encrypt-then-hmac).
43+
For secure communication we need to establish shared secrets. For this we use ECDH key agreement. We use `AES_CBC` for encryption with `M2` padding (add `0x8000..00` to round to 16-byte blocks). Truncated to 14 bytes HMAC-SHA256 is used for authentication and applied to the ciphertext (encrypt-then-hmac).
4444

4545
There are 3 different modes you can use - `ss`, `es` and `ee`.
4646
- In `ss` mode both card and host use static public keys and 32-byte random nonces. Shared secret is derived as `sha256(ecdh(s,s) | host_nonce | card_nonce)`.
@@ -60,39 +60,39 @@ If you are out of sync for some reason just re-establish secure channel. If `iv`
6060

6161
## Establish secure channel in SS mode
6262

63-
Returns `< 32-byte card nonce > | HMAC-SHA256(card_key, data) | ECDSA_SIGNATURE`.
63+
Returns `< 32-byte card nonce > | <14 byte HMAC-SHA256(card_key, data)> | ECDSA_SIGNATURE`.
6464

6565
| Field | Value |
6666
| ------ | ---------------------------------------- |
6767
| CLA | `0xB0` |
6868
| INS | `0xB3` |
6969
| P0, P1 | ignored, use for example `0x00` for both |
7070
| DATA | `<host_pubkey><host_nonce>`: 65-byte public key of the host serialized in uncompressed form followed by the 32-byte host nonce |
71-
| RETURN | `SW`: `0x9000`, `DATA`: `< 32-byte card nonce > | HMAC-SHA256(card_key, data) | ECDSA_SIGNATURE` |
71+
| RETURN | `SW`: `0x9000`, `DATA`: `< 32-byte card nonce > | < 14 byte HMAC-SHA256(card_key, data)> | ECDSA_SIGNATURE` |
7272

7373
## Establish secure channel in ES mode
7474

75-
Returns `< 32-byte card nonce > | HMAC-SHA256(card_key, data) | ECDSA_SIGNATURE`.
75+
Returns `< 32-byte card nonce > | < 14 byte HMAC-SHA256(card_key, data)> | ECDSA_SIGNATURE`.
7676

7777
| Field | Value |
7878
| ------ | ---------------------------------------- |
7979
| CLA | `0xB0` |
8080
| INS | `0xB4` |
8181
| P0, P1 | ignored, use for example `0x00` for both |
8282
| DATA | 65-byte public key of the host serialized in uncompressed form |
83-
| RETURN | `SW`: `0x9000`, `DATA`: `< 32-byte card nonce > | HMAC-SHA256(card_key, data) | ECDSA_SIGNATURE` |
83+
| RETURN | `SW`: `0x9000`, `DATA`: `< 32-byte card nonce > | < 14 byte HMAC-SHA256(card_key, data)> | ECDSA_SIGNATURE` |
8484

8585
## Establish secure channel in EE mode
8686

87-
Returns `< card ephemeral pubkey > | HMAC-SHA256(card_key, data) | ECDSA_SIG(card_pubkey, data incl HMAC)`.
87+
Returns `< card ephemeral pubkey > | < 14 byte HMAC-SHA256(card_key, data)> | ECDSA_SIG(card_pubkey, data incl HMAC)`.
8888

8989
| Field | Value |
9090
| ------ | ---------------------------------------- |
9191
| CLA | `0xB0` |
9292
| INS | `0xB5` |
9393
| P0, P1 | ignored, use for example `0x00` for both |
9494
| DATA | 65-byte public key of the host serialized in uncompressed form |
95-
| RETURN | `SW`: `0x9000`, `DATA`: 65-byte cards fresh pubkey followed by `HMAC-SHA256(card_key, data)`, then ECDSA signature signing all previous data |
95+
| RETURN | `SW`: `0x9000`, `DATA`: 65-byte cards fresh pubkey followed by `HMAC-SHA256(card_key, data)` (first 14 bytes), then ECDSA signature signing all previous data |
9696

9797
## Secure message
9898

@@ -112,7 +112,7 @@ Message is formed as follows:
112112
- All messages coming from the host should be encrypted using `host_aes_key` and authenticated with `host_mac_key`
113113
- All responces from card are encrypted with `card_aes_key` and authenticated with `card_mac_key`
114114
- `AES-CBC` with `M2` padding (`0x8000...00`) is used to round data to 16-byte AES blocks.
115-
- For authentication we use first `15` bytes of `HMAC-SHA256(key, iv | ciphertext)`
115+
- For authentication we use first `14` bytes of `HMAC-SHA256(key, iv | ciphertext)`
116116
- You need to increase `iv` after every request to the card.
117117

118118
Encrypted packet format: `< ciphertext > < hmac_sha256(key, iv|ciphertext)[:15] >`

0 commit comments

Comments
 (0)