Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Postmortem: Incorrect rt-alias-key derivation in FMC #1550

Open
3 of 6 tasks
korran opened this issue May 31, 2024 · 1 comment
Open
3 of 6 tasks

Postmortem: Incorrect rt-alias-key derivation in FMC #1550

korran opened this issue May 31, 2024 · 1 comment
Assignees

Comments

@korran
Copy link
Collaborator

korran commented May 31, 2024

The key derivation done by the FMC (label "rt_alias_cdi") is not conformant with the HMAC-SHA-384 specification. The HMAC computation only includes the first HMAC block, and is missing a second block which includes padding and a length suffix. This is not believed to be a security issue, as (by luck) all measurements are in the first block. If circumstances were slightly different, the consequences to these mistakes could have been a lot worse, so a post-mortem is necessary.

Background

Issue #1520 was filed, noting that the rt-alias public key differed between the RTL and the sw-emulator. This occurred because the driver/hardware was ignoring all blocks except for the first one in the derivation, but the sw-emulator implementation processed all blocks "correctly".

Causes

When consuming keys from the keyvault, the combination of the HMAC peripheral and driver only include the first 128-byte data block in the computation. The multi-block case is decently well tested by driver tests when operating on data and keys supplied and retrieved by the CPU, but when operating with keys supplied by (and result written to) the key-vault, the hardware clears the key after processing the first block, and subsequent blocks are ignored. This behavior was not called out in the hardware spec. I think folks assumed there would never be a need for multi-block HMAC for key derivation; and there wasn't, until somebody tweaked the derivation logic to use HKDF, which expanded the data beyond what would fit in a single block. I believe the systemic root causes are miscommunication between the hardware and firmware teams, and missing validation at several layers of the stack:

  • hardware: missing validation for the multi-block HMAC key-vault use case.

  • hardware spec: missing documentation of how the HMAC/key-vault multi-block usage differed from the non-key-vault usage.

  • firmware: missing multi-block HMAC key-vault driver test case (this is somewhat tricky because the direct results of the computation are kept secret from the CPU)

  • firmware: missing assertion in end-to-end tests to independently derive the rt-alias-key from UDS and measurements and confirm it matched the public key in the cert.

I have confirmed in PR #1528 that reloading the key from the keyvault and reprogramming the destination registers after each block works around this multi-block issue in the driver.

What went well?

  • The ROM was not affected. The smoke-tests independently confirm the derivation of the ROM-generated fmc-alias-key from the UDS and measurements.

What went wrong?

  • Validation at several layers of the stack failed to notice this issue.

Where we got lucky

  • The sw-emulator HMAC implementation diverged from the RTL implementation, and somebody noticed the derivations weren't consistent.

  • The ignored HMAC block doesn't include any actual measurements (it just has padding + length):

    # block 0 (this block included in rt_alias_cdi)
    00000000  00 00 00 01 72 74 5f 61  6c 69 61 73 5f 63 64 69  |....rt_alias_cdi|
    00000010  00 03 91 03 63 1e f7 9d  36 a1 5c 5a 38 07 ca 6a  |....c...6.\Z8..j|
    00000020  71 42 de c4 7e 3c 90 8c  aa 9c 41 2b be 83 71 92  |qB..~<....A+..q.|
    00000030  0a fe a7 2b ed 4d 52 a4  f0 7b c3 bb 7d b6 50 3f  |...+.MR..{..}.P?|
    00000040  7e cb 5a c2 23 45 70 96  84 6a 6c da 09 3a 03 f2  |~.Z.#Ep..jl..:..|
    00000050  78 c5 52 19 5f bb e4 76  26 2b 4d 05 90 60 b5 18  |x.R._..v&+M..`..|
    00000060  28 54 df 20 81 0f a8 fe  59 2a 3c 3c e9 a5 27 bc  |(T. ....Y*<<..'.|
    00000070  27 80 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |'...............|
    # block 1 (this block was skipped)
    00000080  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
    00000090  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
    000000a0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
    000000b0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
    000000c0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
    000000d0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
    000000e0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
    000000f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 07 88  |................|
    

Action Plan

(Do not mark this bug completed until all tasks are complete)

  • Add workaround to driver to support multi-block HMAC with keyvault keys (#1528)
  • Add driver test-case for multi-block keyvault-based HMAC (commit)
  • Add end-to-end test assertion for FMC derivations (commit)
  • Add end-to-end test assertions for runtime/DPE derivations (TBD)
  • Add HMAC/keyvault/multiblock validation test to RTL (TBD)
  • Update hardware specification with keyvault/multiblock usage details (TBD)
@jhand2
Copy link
Collaborator

jhand2 commented Jun 4, 2024

Opened #1552 to track task 4 above

korran added a commit to korran/caliptra-sw that referenced this issue Jun 21, 2024
This fixes chipsalliance#1520 / chipsalliance#1550: HMAC operations larger than a
single block produce the incorrect results when using data or keys from
the keyvault.
jhand2 pushed a commit to korran/caliptra-sw that referenced this issue Jul 1, 2024
This fixes chipsalliance#1520 / chipsalliance#1550: HMAC operations larger than a
single block produce the incorrect results when using data or keys from
the keyvault.
jhand2 pushed a commit that referenced this issue Jul 1, 2024
This fixes #1520 / #1550: HMAC operations larger than a
single block produce the incorrect results when using data or keys from
the keyvault.
nquarton pushed a commit to nquarton/caliptra-sw that referenced this issue Aug 14, 2024
This fixes chipsalliance#1520 / chipsalliance#1550: HMAC operations larger than a
single block produce the incorrect results when using data or keys from
the keyvault.

Add a multi-block hmac384 test that uses the key-vault.

smoke-test: Verify FMC key derivation with independent impl.
JohnTraverAmd pushed a commit that referenced this issue Aug 15, 2024
* Changing SHA384ACC KAT to SHA512 (#1562)

* Changing SHA384ACC KAT to SHA512

- Adding support for SHA512 digest in the SHA acclerator driver
- Enabling support for SHA512 in the SW emulator SHA accelerator

* Renaming sha384acc to sha2_512_384acc

* Adding ECC error checking during waits (#1610)

* [bugfix] hmac384 driver: Reload kv keys for each block.

This fixes #1520 / #1550: HMAC operations larger than a
single block produce the incorrect results when using data or keys from
the keyvault.

Add a multi-block hmac384 test that uses the key-vault.

smoke-test: Verify FMC key derivation with independent impl.

* Updating DPE to fix sporadic test failure

* Updating ROM version to 1.0.3

* Removing publish website step for nightly release

---------

Co-authored-by: Kor Nielsen <[email protected]>
nquarton pushed a commit to nquarton/caliptra-sw that referenced this issue Aug 15, 2024
This fixes chipsalliance#1520 / chipsalliance#1550: HMAC operations larger than a
single block produce the incorrect results when using data or keys from
the keyvault.

Add a multi-block hmac384 test that uses the key-vault.

smoke-test: Verify FMC key derivation with independent impl.
jhand2 pushed a commit that referenced this issue Aug 15, 2024
This fixes #1520 / #1550: HMAC operations larger than a
single block produce the incorrect results when using data or keys from
the keyvault.

Add a multi-block hmac384 test that uses the key-vault.

smoke-test: Verify FMC key derivation with independent impl.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants