summaryrefslogtreecommitdiff
path: root/board
Commit message (Collapse)AuthorAgeFilesLines
* cr50: preserve ordely nv spaces over TPM resetstabilize-quickfix-14526.91.B-cr50_stabstabilize-14528.B-cr50_stabstabilize-14526.89.B-cr50_stabstabilize-14526.84.B-cr50_stabstabilize-14526.73.B-cr50_stabstabilize-14526.67.B-cr50_stabstabilize-14526.57.B-cr50_stabrelease-R100-14526.B-cr50_stabAndrey Pronin2022-02-162-0/+18
| | | | | | | | | | | | | | | | | | This CL in case of unorderly TPM reset that doesn't also reset GSC preserves RAM-backed values of orderly nv indices. BUG=b:201101365 TEST=1) create an orderly counter 2) increment it 3) trigger EC reset 4) verify that the counter value was preserved Cq-Depend: chromium:3417937 Change-Id: I799183ad06584055d025c2acf5f83ff2ded32d39 Signed-off-by: Andrey Pronin <apronin@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3418122 Reviewed-by: Vadim Bendebury <vbendeb@chromium.org> Commit-Queue: Mary Ruthven <mruthven@chromium.org>
* cr50: update FIPS module based on operational testing findingsstabilize-14498.B-cr50_stabstabilize-14496.B-cr50_stabfirmware-brya-14505.B-cr50_stabfirmware-brya-14505.71.B-cr50_stabVadim Sukhomlinov2022-01-315-22/+43
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 1. ECDSA pair-wise consistency test failure wasn't updating FIPS status. Added new failure bit FIPS_FATAL_ECDSA_PWCT. 2. ECDSA KAT was only simulating error in verify, but not in sign. Split 'fips ecdsa' into 'fips ecver' and 'fips ecsign'. 3. Added a way to introduce self-integrity error by not updating FIPS module digest with 'FIPS_BREAK=1' during build. 4. Added reporting of FIPS module digest. BUG=b:134594373 TEST=make CRYPTO_TEST=1; in ccd test: fips pwct; tpm_test.py should fail; fips should print error. - fips ecver; fips test reports ECDSA error fips ecsign; fips test reports ECDSA error - FIPS module digest is printed - FIPS_BREAK=1 make CRYPTO_TEST=1 produce build with zero digest reporint FIPS self-integrity error. Signed-off-by: Vadim Sukhomlinov <sukhomlinov@google.com> Change-Id: Ib0a92c118f07a76e4b52eaf9b011ff4f73a02c61 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3425998 Reviewed-by: Vadim Sukhomlinov <sukhomlinov@chromium.org> Tested-by: Vadim Sukhomlinov <sukhomlinov@chromium.org> Reviewed-by: Mary Ruthven <mruthven@chromium.org> Commit-Queue: Vadim Sukhomlinov <sukhomlinov@chromium.org>
* add vendor command to disable deep sleepMary Ruthven2022-01-263-1/+72
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add a vendor command to disable deep sleep the next time TPM_RST_L is asserted. Normally cr50 enters deep sleep whenever TPM_RST_L is asserted. New boards want to disable deep sleep during certain power states. This vendor command allows the AP to disable deep sleep for the next suspend cycle. When deep sleep is disabled, cr50 modifies TPM_RST_L to be WAKE_HIGH and sets it back to WAKE_LOW after TPM_RST_L is deasserted, so TPM_RST_L doesn't constantly wake cr50 from regular sleep. This uses 248 bytes BUG=b:214479456 TEST=manual # Check G3 resume works ok. # Disable Deep Sleep from the AP. The vendor command is 59 # (0x3b) trunks_send --raw 80010000000c20000000003b ccdstate DS Dis: on AP > shutdown -P now ... [454.992733 Block DS] ccdstate DS Dis: on pinmux 40060018: DIOM3 0 IN WAKE_HIGH idle idle action: sleep # Verify cr50 starts cycling through sleep spinner at two ticks # a second. EC > powerbtn # check the cr50 console ... A�UART on] 10/ 1 [102.484012 Missed edge] [102.484352 deferred_tpm_rst_isr] [102.484580 AP on] [102.484779 set TPM wake] [102.484981 tpm_reset_request(0, 0)] [102.485279 tpm_reset_now(0)] [547.928375 AP on] [547.928615 set TPM wake] pinmux 40060018: DIOM3 0 IN WAKE_LOW # Disable Deep Sleep from the AP. The vendor command is 59 # (0x3b) trunks_send --raw 80010000000c20000000003b ccdstate DS Dis: on ecrst pulse ... [602.638427 AP on] [547.928615 set TPM wake] [602.638668 tpm_reset_request(0, 0)] ... ccdstate DS Dis: off # Check S3 resume works ok. # Use AP commands to enter S3 AP > trunks_send --raw 80010000000c20000000003b AP > echo deep > /sys/power/mem_sleep AP > echo mem > /sys/power/state 10\ 1 [243.409412 dis DS] 1|[249.536811 tpm_rst_asserted] [250.537197 AP off] [250.537631 Block DS] # Wake the AP with a power button press from the EC EC > powerbtn # verify cr50 prints "Missed edge", but the device resumes ok. 1/ 10- 1 [270.112655 Missed edge] [270.113037 deferred_tpm_rst_isr] [270.113315 AP on] [270.113529 set TPM wake] [270.113712 tpm_reset_request(0, 0)] [270.114013 tpm_reset_now(0)] [270.116996 tpm_init] tpm_manufactured: manufactured [270.118301 tpm_reset_now: done] [270.156967 PinWeaver: Loading Tree!] [270.189353 Skipping commit] Change-Id: I96049a9d38b5c66acad9c73628f588f4cf6b2b3f Signed-off-by: Mary Ruthven <mruthven@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3406587 Reviewed-by: Vadim Bendebury <vbendeb@chromium.org> Commit-Queue: Vadim Bendebury <vbendeb@chromium.org>
* cr50: make strap errors louderMary Ruthven2022-01-251-4/+4
| | | | | | | | | | | | | | | | | | | | | Add "ERROR" and some exclamation points to make invalid strap messages more noticeable. BUG=b:214550629 TEST=look at invalid strap error messages on red board. strap pin readings: a1:3 a9:1 a6:1 a12:3 [0.005569 WARN Ambiguous strap cfg. Use spi based on old brdprop.] [0.006675 get_properties: ERROR NO TABLE ENTRY!!! cfg: 0x7 prop: 0x1] strap pin readings: a1:3 a9:1 a6:1 a12:3 [0.005649 get_properties: ERROR INVALID STRAP PINS!!! cfg 0xd7 prop 0x42 Change-Id: Ie1e29fd4152a2b3f984989e37b771339895e6a0e Signed-off-by: Mary Ruthven <mruthven@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3390071 Reviewed-by: Douglas Anderson <dianders@chromium.org> Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
* H1_RED_BOARD: unconditionally use red board brdpropstabilize-wristpin-14469.59.B-cr50_stabstabilize-14477.B-cr50_stabstabilize-14469.9.B-cr50_stabstabilize-14469.8.B-cr50_stabstabilize-14469.58.B-cr50_stabstabilize-14469.41.B-cr50_stabrelease-R99-14469.B-cr50_stabMary Ruthven2022-01-151-5/+5
| | | | | | | | | | BUG=none TEST=cr50 uses red board straps after power-on and hard resets. Change-Id: I0ee4a48a3e8661565dede1f7686cf6b2e1181914 Signed-off-by: Mary Ruthven <mruthven@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3386406 Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
* brdprop: log invalid and ambiguous eventsMary Ruthven2022-01-151-0/+46
| | | | | | | | | | | | | | | | Log brdprop errors in flog, so the team can track brdprop errors from the AP without grepping through cr50 logs. BUG=b:214550629 TEST=flash on red board. Verify invalid strap events are logged. enable closed-loop-reset on the red board. Verify "ambiguous" strap logs are ignored. Change-Id: Ibea73fb19119fa81ed3652c5d68e430cdbae9fa5 Signed-off-by: Mary Ruthven <mruthven@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3386405 Reviewed-by: Vadim Bendebury <vbendeb@chromium.org> Commit-Queue: Vadim Bendebury <vbendeb@chromium.org>
* cr50: fix FIPS behavior with resume from deep sleepVadim Sukhomlinov2022-01-071-6/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | We do FIPS power-on test on cold boot only and only redo it on wake from sleep if there was an error earlier. However, when waking we didn't set FIPS mode flags properly causing incorrect reporting of not-approved mode while there are no errors. On the other side, some nvmem code which doesn't use FIPS crypto was calling crypto_enabled() before FIPS power-on tests where completed, which caused failure of load_ec_hash when it was present. Adjust behavior of crypto_enabled to only check for lack of FIPS errors, but not completion of power-on tests. This way we unblock nvmem init code early in the boot, while still block access if any FIPS errors happens later. BUG=none TEST=make; in CCD - try idle d Signed-off-by: Vadim Sukhomlinov <sukhomlinov@google.com> Change-Id: Ibae3654cc1289fef439f9e03cb90170f3377f0da Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3373465 Reviewed-by: Andrey Pronin <apronin@chromium.org> Commit-Queue: Andrey Pronin <apronin@chromium.org> Tested-by: Andrey Pronin <apronin@chromium.org> Reviewed-by: Vadim Sukhomlinov <sukhomlinov@chromium.org> Commit-Queue: Vadim Sukhomlinov <sukhomlinov@chromium.org> Tested-by: Vadim Sukhomlinov <sukhomlinov@chromium.org> Auto-Submit: Vadim Sukhomlinov <sukhomlinov@chromium.org>
* cr50: reduce TRNG use during RSA prime checkstabilize-14438.B-cr50_stabVadim Sukhomlinov2021-12-301-6/+37
| | | | | | | | | | | | | | | | | | | | It seems we have relatively high number of devices with slow TRNG, mostly Octopus and Grunt platforms. To mitigate potential issues reduce load on TRNG during witness generation in prime number check, relying on already generated random from DRBG. BUG=b:211648605 TEST=test/tpm_test/tpm_test.py - checking RSA key gen and that deterministic key gen is not affected. Signed-off-by: Vadim Sukhomlinov <sukhomlinov@google.com> Change-Id: Id661ad4191321b761c25a5c1fc3bda10336feff9 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3361250 Reviewed-by: Vadim Sukhomlinov <sukhomlinov@chromium.org> Tested-by: Vadim Sukhomlinov <sukhomlinov@chromium.org> Reviewed-by: Andrey Pronin <apronin@chromium.org> Commit-Queue: Vadim Sukhomlinov <sukhomlinov@chromium.org> Auto-Submit: Vadim Sukhomlinov <sukhomlinov@chromium.org>
* cr50: update TRNG resetsVadim Sukhomlinov2021-12-301-6/+12
| | | | | | | | | | | | | | | | | | | It seems we have relatively high number of devices with slow TRNG, mostly Octopus and Grunt platforms. To mitigate potential issues increased TRNG reset counts from 8 to 16 to give a chance to recover, and updated recording of TRNG stall to record only first occurrence of stall per 32-bit. BUG=b:211648605 TEST=test/tpm_test/nist_entropy.sh - loads TRNG Signed-off-by: Vadim Sukhomlinov <sukhomlinov@google.com> Change-Id: I11d0e9ca2955894b2ed95dbfbf71ad8ff153c53e Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3358466 Reviewed-by: Vadim Sukhomlinov <sukhomlinov@chromium.org> Tested-by: Vadim Sukhomlinov <sukhomlinov@chromium.org> Reviewed-by: Andrey Pronin <apronin@chromium.org> Commit-Queue: Vadim Sukhomlinov <sukhomlinov@chromium.org>
* cr50: improve g2f implementationVadim Sukhomlinov2021-12-293-21/+29
| | | | | | | | | | | | | | | | | | | | | | | | | Replace int to size_t in DCRYPTO_x509_* functions to indicate that returned value is actually a size. Replaced int to enum dcrypto_result and removed arithmetic on enum in DCRYPTO_x509_gen_u2f_cert_name() to make code clear. Added intermediate variable certificate_len in GetG2fCert to make logic clear. However, virtual nvmem requires further refactoring to replace void with size_t to escalate errors if any. Added check that G2F certificate is not all zeroes in tpm_test.py BUG=b:212517336 TEST=test/tpm_test.py Signed-off-by: Vadim Sukhomlinov <sukhomlinov@google.com> Change-Id: I5ee4567219f43dd3c7e7ef7d260b446732c5c22d Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3361100 Reviewed-by: Vadim Sukhomlinov <sukhomlinov@chromium.org> Tested-by: Vadim Sukhomlinov <sukhomlinov@chromium.org> Reviewed-by: Andrey Pronin <apronin@chromium.org> Commit-Queue: Vadim Sukhomlinov <sukhomlinov@chromium.org>
* cr50: Fix x509_gen_u2f_cert_nameHoward Yang2021-12-291-1/+1
| | | | | | | | | | | | | | | | | Logical error introduced in crrev.com/c/3179708 that causes x509 gen u2f cert failed. Fix the incorrect interpretation of the `result` variable in an `if` statement. BUG=b:211820657 TEST=make buildall -j TEST=manual test, u2fd get g2f certificate doesn't fail anymore Change-Id: I37aaa5946c43896458c93a67352b5f2d92a1965a Signed-off-by: Howard Yang <hcyang@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3360325 Reviewed-by: Vadim Sukhomlinov <sukhomlinov@chromium.org> Commit-Queue: Vadim Sukhomlinov <sukhomlinov@chromium.org> Tested-by: Vadim Sukhomlinov <sukhomlinov@chromium.org>
* cr50: fix g2f certificate retrievalVadim Sukhomlinov2021-12-281-1/+1
| | | | | | | | | | | | | | | | | Logical error was introduced in crrev.com/c/3119223 which resulted in failing attempts to read G2F certificate from virtual nvmem. This CL fixes it and adds a test for this command. BUG=b:211820657 TEST=make BOARD=cr50; test/tpm_test/tpm_test.py Signed-off-by: Vadim Sukhomlinov <sukhomlinov@google.com> Change-Id: I3c46e9e050d5084dbac1b0a7c3d7e378987a3759 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3359755 Reviewed-by: Vadim Sukhomlinov <sukhomlinov@chromium.org> Tested-by: Vadim Sukhomlinov <sukhomlinov@chromium.org> Reviewed-by: Mary Ruthven <mruthven@chromium.org> Commit-Queue: Vadim Sukhomlinov <sukhomlinov@chromium.org>
* CRYPTO_TEST: modify the hash_command_handler print statementsstabilize-14411.B-cr50_stabMary Ruthven2021-12-171-8/+8
| | | | | | | | | | | | | | Modify the hash_command_handler print statements, so it's easy to tell the difference between firmware and hardware hash commands with the console output. BUG=b:210879337 TEST=make -j BOARD=cr50 CRYPTO_TEST=1 Change-Id: I0fca79c102cd284b564fe6ca8464c22c1629e2a0 Signed-off-by: Mary Ruthven <mruthven@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3345983 Reviewed-by: Vadim Sukhomlinov <sukhomlinov@chromium.org>
* H1_RED_BOARD: modify get_propertiesMary Ruthven2021-12-151-4/+5
| | | | | | | | | | | | | Only default to SPI and PLT_RST when no valid properties are found. BUG=b:210760012 TEST=make clobber ; make -j BOARD=cr50 CRYPTO_TEST=1 H1_RED_BOARD=1 Change-Id: Ic2842bc305322deb5fdc43e1d3487d499e9cb23b Signed-off-by: Mary Ruthven <mruthven@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3341778 Reviewed-by: Vadim Sukhomlinov <sukhomlinov@chromium.org> Commit-Queue: Vadim Sukhomlinov <sukhomlinov@chromium.org>
* ap_ro_integrity_check: call keep_ec_in_reset in do_ap_ro_checkstabilize-14385.B-cr50_stabfactory-kukui-14374.B-cr50_stabMary Ruthven2021-11-291-72/+1
| | | | | | | | | | | | | | | | | | Move the keep_ec_in_reset call into do_ap_ro_check, so AP RO verification will hold the EC in reset when it's triggered from the AP. This change removes the ap_ro_verification_failed_ variable, so all of the AP RO verification is included in ap_ro_info. ap_ro_ver_state isn't needed anymore, so this CL removes it. BUG=b:207545621 TEST=make clobber ; make buildall -j Change-Id: Id0b2e04b042d48f2b8a9dae021e762369ca5f3eb Signed-off-by: Mary Ruthven <mruthven@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3300174 Reviewed-by: Vadim Bendebury <vbendeb@chromium.org> Commit-Queue: Vadim Bendebury <vbendeb@chromium.org>
* ap_ro_verification: update test root key hashVadim Bendebury2021-11-231-6/+4
| | | | | | | | | | | | | | | AP RO verification test keys in vboot_reverence have been updated, by crrev.com/c/3297447, this patch brings the root public key payload hash in sync. BUG=b:141191727 TEST=built a Cr50 image for guybrush and used it to verify AP RO hash signed with the new test key. Signed-off-by: Vadim Bendebury <vbendeb@chromium.org> Change-Id: I121d3738db28e473e2bfd1f8fcf8c7681bad1ddd Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3298880 Reviewed-by: Mary Ruthven <mruthven@chromium.org>
* coil: replace non-inclusive terms with "placeholder"Mary Ruthven2021-11-191-5/+5
| | | | | | | | | | BUG=b:173227629 TEST=make buildall -j Change-Id: I2b203dfe45416aa3b632f6f788d14264b08f44e0 Signed-off-by: Mary Ruthven <mruthven@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3293252 Reviewed-by: Vadim Sukhomlinov <sukhomlinov@chromium.org>
* coil: replace non-inclusive terms with "validity"Mary Ruthven2021-11-194-5/+5
| | | | | | | | | | BUG=b:173227629 TEST=make buildall -j Change-Id: Iaf8028984cc58cc4108907fdba4ea4b38c43cf70 Signed-off-by: Mary Ruthven <mruthven@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3293250 Reviewed-by: Vadim Sukhomlinov <sukhomlinov@chromium.org>
* remove bdsMary Ruthven2021-11-105-145/+0
| | | | | | | | | | | | Remove bds and set cr50 as the default board BUG=b:200823466 TEST=make buildall -j ; make runtests Change-Id: I4fad3b3f903ab7aed0d4baec36aee4b426cb1cb3 Signed-off-by: Mary Ruthven <mruthven@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3273183 Reviewed-by: Vadim Sukhomlinov <sukhomlinov@chromium.org>
* cr50: adjust FIPS tests based on feedback from security reviewVadim Sukhomlinov2021-11-102-17/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | 1. Ignore self-integrity error only for CRYPTO_TEST=1 2. Adjust logic around FIPS_MODE_ACTIVE flag with test reruns during simulation. This flag should be set if no FIPS errors detected. Existing logic never reset this bit in case of errors and didn't update it in case of test reruns. BUG=b:138578318 TEST=make BOARD=cr50 CRYPTO_TEST=1 in ccd: fips test fips sha fips test - should display error code 0x40000010 ChromeOS is booting fine. Signed-off-by: Vadim Sukhomlinov <sukhomlinov@google.com> Change-Id: Ifddb7d091954737ad7db86afccc199069143fa06 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3261382 Reviewed-by: Vadim Sukhomlinov <sukhomlinov@chromium.org> Reviewed-by: Mary Ruthven <mruthven@chromium.org> Reviewed-by: Vadim Bendebury <vbendeb@chromium.org> Tested-by: Vadim Sukhomlinov <sukhomlinov@chromium.org> Auto-Submit: Vadim Sukhomlinov <sukhomlinov@chromium.org> Commit-Queue: Mary Ruthven <mruthven@chromium.org> Commit-Queue: Vadim Sukhomlinov <sukhomlinov@chromium.org>
* cr50: adjust shared memory for CRYPTO_TEST=1 buildstabilize-14333.B-cr50_stabstabilize-14324.72.B-cr50_stabstabilize-14324.62.B-cr50_stabstabilize-14324.41.B-cr50_stabstabilize-14324.13.B-cr50_stabstabilize-14321.B-cr50_stabrelease-R97-14324.B-cr50_stabVadim Sukhomlinov2021-10-281-0/+5
| | | | | | | | | | | | | | | | | | | | Fixing build error arm-eabi/bin/ld: Not enough space for shared memory. collect2: error: ld returned 1 exit status make: *** [Makefile.rules:472: build/cr50/RW/ec.RW.elf] Error 1 Crypto tests doesn't use much shared memory, but allocate more data statically. BUG=None TEST=make BOARD=cr50 CRYPTO_TEST=1 U2F_TEST=1 Signed-off-by: Vadim Sukhomlinov <sukhomlinov@google.com> Change-Id: Id0e01481c9fd481955c11b5d7ef63251585cfe48 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3251702 Reviewed-by: Vadim Sukhomlinov <sukhomlinov@chromium.org> Reviewed-by: Vadim Bendebury <vbendeb@chromium.org> Tested-by: Vadim Sukhomlinov <sukhomlinov@chromium.org> Commit-Queue: Vadim Sukhomlinov <sukhomlinov@chromium.org>
* factory_mode: add 0.3.22 to guc versionsMary Ruthven2021-10-211-8/+8
| | | | | | | | | | | | | | | | Cr50 is getting new CCD capabilities. The GUC image won't have them. This change adds 0.3.22 to the versions, so cr50 will set all capabilities including the new ones to Always after the first update in the factory. BUG=none TEST=cr50 prints the GUC message if 0.0.22, 0.0.13, or 0.3.22 are in the inactive region. It doesn't with 0.5.51 Change-Id: Idc8d7b8a0687d36f59aaad31cd5ce026ab351a7d Signed-off-by: Mary Ruthven <mruthven@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3237199 Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
* usb_spi_v2: read full PDU into a bufferVadim Bendebury2021-10-191-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Certain test configurations present a problem for the raiden protocol V2 implementation on the Cr50 side, which result in random SPI read failures. While the issue is still being investigated this patch offers a workaround, where SPI and USB transactions are not overlaid, the driver first reads the entire requested number of bytes into a buffer, and then sends them to the host in multiple USB packets. Since buffer memory can not be permanently dedicated to the driver, it uses dynamic allocation to acquire the buffer. The allocation could fail, for instance when the flashrom operation is requested soon after startup and heap memory is used for NVMEM compaction. If the allocation fails, the driver sends an error packet to the host, and the host requests to restart the response. To be able to restart the response the driver now stores the request. With some instrumentation, measurements taken on reading of 200 2040 byte blocks have shown that memory was held by this driver for 94% of the duration. To address the case when flashrom session is interrupted mid PDU transfer, do not wait for the transmit queue to become available for more than 500 ms. In case the queue gets stuck return without waiting any more, this will make sure the allocated buffer is freed. BUG=b:196820680 TEST=successfully ran hundreds of cycles of read, and read and write on the setup which exhibits the problem without this patch on pretty much every read attempt. The slow down caused by this change is pretty small: average of five attempts to read 16MB of SPI flash on guybrush device take 50.560s before this change and 51.267s after this change, which is a 1.7% slowdown. Signed-off-by: Vadim Bendebury <vbendeb@chromium.org> Change-Id: I82c98f912a8763b7e242dad48997a8d2ffbaf29a Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3188568 Reviewed-by: Mary Ruthven <mruthven@chromium.org> Reviewed-by: Andrey Pronin <apronin@chromium.org>
* cr50: better cleaning of residual data in case of U2F failuresVadim Sukhomlinov2021-10-191-53/+55
| | | | | | | | | | | | | | | | | | | | | | | | | u2f_generate() may return partially initialized key handle in case of ECDSA error, and u2f_sign() and u2f_attest() may return garbage in the signature. While error codes are properly handled by the callers, it is better to implement defense in depth and clean all residual data. This is also helpful for FIPS testing demo when actual zeroes are more convincing than just error codes. Example is proposed method for ECDSA pair-wise consistency testing, when injection of error in PWCT should result in clearly visible error status. BUG=b:198219806 TEST=make BOARD=cr50 CRYPTO_TEST=1 U2F_TEST=1 fips pwct u2f_test - should return zero in key handle, public key and signatures. Signed-off-by: Vadim Sukhomlinov <sukhomlinov@google.com> Change-Id: I7ad0c69563a215aade00d495c0623f6c6e00b755 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3224360 Reviewed-by: Vadim Sukhomlinov <sukhomlinov@chromium.org> Reviewed-by: Andrey Pronin <apronin@chromium.org> Tested-by: Vadim Sukhomlinov <sukhomlinov@chromium.org> Commit-Queue: Vadim Sukhomlinov <sukhomlinov@chromium.org>
* ap_ro_verification: rework to match the new GVD layoutVadim Bendebury2021-10-191-4/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | As a result of further discussion GVD layout has been changed to include signature and root key headers in the GVD header. This patch makes modification to accommodate the new header structure. BUG=b:141191727 TEST=A guybrush RO image created in vboot reference tree as follows: build/futility/futility vbutil_keyblock --pack ~/tmp/packed \ --datapubkey tests/devkeys/firmware_data_key.vbpubk \ --signprivate tests/devkeys/kernel_subkey.vbprivk build/futility/futility gscvd --outfile ~/tmp/guybrush-signed \ -R 818100:10000,f00000:100,f80000:2000,f8c000:1000 \ -k ~/tmp/packed -p tests/devkeys/firmware_data_key.vbprivk \ -b 5a5a4352 -r tests/devkeys/kernel_subkey.vbpubk \ ~/tmp/image-guybrush.serial.bin A guybrush device was programmed with ~/tmp/guybrush-signed, and AP RO verification was attempted by pressing the appropriate button combination, GVD verification succeeded. Generate a signed image again, using an incorrect Board ID value, try verification, observe failure due to incorrect Board ID. Signed-off-by: Vadim Bendebury <vbendeb@chromium.org> Change-Id: I4da753649eef6e10353619e0f7af19d2f6846b75 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3224808 Reviewed-by: Andrey Pronin <apronin@chromium.org> Reviewed-by: Vadim Sukhomlinov <sukhomlinov@chromium.org>
* cr50: update ECDSA pair-wise consistency test to alter key, not messageVadim Sukhomlinov2021-10-181-4/+12
| | | | | | | | | | | | | | | | | | | | Intent of pair-wise consistency test is to ensure that private key matches the public key, so update what we change when simulating error. BUG=b:198219806 TEST=make BOARD=cr50 CRYPTO_TEST=1 U2F_TEST=1; u2f_test; passes fips pwct u2f_test; fails on u2f_generate, u2f_sign and u2f_attest. Signed-off-by: Vadim Sukhomlinov <sukhomlinov@google.com> Change-Id: I35de5608184fc9f28db4912f2b62795d53d48f43 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3229800 Reviewed-by: Vadim Sukhomlinov <sukhomlinov@chromium.org> Reviewed-by: Vadim Bendebury <vbendeb@chromium.org> Reviewed-by: Andrey Pronin <apronin@chromium.org> Tested-by: Vadim Sukhomlinov <sukhomlinov@chromium.org> Commit-Queue: Vadim Sukhomlinov <sukhomlinov@chromium.org>
* cr50: update TRNG health tests cut off values for new entropy estimateVadim Sukhomlinov2021-10-162-25/+40
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Once all H1 Entropy tests completed at different environmental points our entropy estimate changed to value 0.77. Also we decided to use alpha = 2^-39 vs. 2^-40. This requires change of RCT and APT cutoff values. RCT cutoff value changed to compile-time constant computation, added static asserts to make sure it is valid and matches known values. APT cutoff can't be computed at compile time and updated to values matching entropy and alpha. Updated entropy size for instantiation of FIPS DRBG. Reseeding interval is reduced to 1000 from 10000 to make it more non-deterministic. Performance impact is very low - can't even measure it precisely. BUG=b:138577834 TEST=make BOARD=cr50 CRYPTO_TEST=1; tpm_test.py Signed-off-by: Vadim Sukhomlinov <sukhomlinov@google.com> Change-Id: I38735492d072b3d4445fca926524ef1c159627a5 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3223967 Reviewed-by: Vadim Sukhomlinov <sukhomlinov@chromium.org> Reviewed-by: Andrey Pronin <apronin@chromium.org> Tested-by: Vadim Sukhomlinov <sukhomlinov@chromium.org> Auto-Submit: Vadim Sukhomlinov <sukhomlinov@chromium.org> Commit-Queue: Vadim Sukhomlinov <sukhomlinov@chromium.org>
* ccdblock: move IGNORE_SERVO warning to the endMary Ruthven2021-10-151-4/+4
| | | | | | | | | | | | | | | | | Move the IGNORE_SERVO warning to the end of ccdblock output, so it doesn't break up the ports blocked. BUG=none TEST=enable ccdblock EC_CR50_COMM and IGNORE_SERVO. Verify EC_CR50_COMM shows up in the port blocked field. > ccdblock CCD ports blocked: EC_CR50_COMM IGNORE_SERVO WARNING: enabling UART while servo is connected may damage hardware Change-Id: I423f05d3d4c097c2e2fc2fd6db83a8d1f6b410a0 Signed-off-by: Mary Ruthven <mruthven@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3219761 Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
* cr50: add run-time detection of gcc version to support gcc 11.2 LTOVadim Sukhomlinov2021-10-141-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | With planned upgrade to gcc 11.2 we need to make sure it will not fail cr50 build as it will be a reason to revert. gcc 11.2 gives us 1768 b back after TPM2 LTO, but it changes default linker behavior and produce LTO object file during partial link unless -flinker-output=nolto-rel is used. This option however fail 8.3 build. Also, gcc 11.2 introduced new optimization path IPA modref which doesn't play nice with LTO and partial link used together, causing gcc crash. To overcome this issue add -fno-ipa-modref when gcc 11.2 is used. This results in almost no impact on code size. BUG=none TEST=make BOARD=cr50 tested with gcc 8.3 and gcc 11.2 Signed-off-by: Vadim Sukhomlinov <sukhomlinov@google.com> Change-Id: I78a3b3403e84dc4a426dede02b399d9d249ece81 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3218577 Reviewed-by: Vadim Sukhomlinov <sukhomlinov@chromium.org> Reviewed-by: Patrick Georgi <pgeorgi@chromium.org> Reviewed-by: Andrey Pronin <apronin@chromium.org> Tested-by: Vadim Sukhomlinov <sukhomlinov@chromium.org> Commit-Queue: Vadim Sukhomlinov <sukhomlinov@chromium.org>
* cr50: optimize AES/GCM/App cipher implementationVadim Sukhomlinov2021-10-145-153/+189
| | | | | | | | | | | | | | | | | | | | | | | | | | | 1. Introduced AES register structure and replaced register access with accesses to fields. In many cases it reduce code size and number of instructions. 2. Deduplication between AES implementation and App Cipher which use AES engine with key coming from key ladder. Added internal function dcrypto_aes_process() which applies current AES configuration to aligned data in highly optimized manner, same as previous outer_loop and inner_loop() functions. Overall it saves 322 bytes with gcc 8.3 BUG=none TEST=make BOARD=cr50 CRYPTO_TEST=1; test/tpm_test/tpm_test.py In ccd: cipher [to test app_cipher]; TCG Tests. Signed-off-by: Vadim Sukhomlinov <sukhomlinov@google.com> Change-Id: I6551e21e5e8798aa4691cb6ba476d565778cea3d Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3213610 Reviewed-by: Vadim Sukhomlinov <sukhomlinov@chromium.org> Reviewed-by: Andrey Pronin <apronin@chromium.org> Tested-by: Vadim Sukhomlinov <sukhomlinov@chromium.org> Auto-Submit: Vadim Sukhomlinov <sukhomlinov@chromium.org> Commit-Queue: Vadim Sukhomlinov <sukhomlinov@chromium.org>
* cr50: cleanup public API for FIPS moduleVadim Sukhomlinov2021-10-146-206/+213
| | | | | | | | | | | | | | | | | | | Move declarations of AES-GCM, AES-CMAC, ECIES, HKDF and few other functions from dcrypto.h into internal.h. Merge tpm2/hkdf.c into dcrypto/hkdf.c. It contains only function used for testing and HKDF itself is only used for CRYPTO_TEST=1. BUG=b:134594373 TEST=make buildall -j; make BOARD=cr50 CRYPTO_TEST=1 Signed-off-by: Vadim Sukhomlinov <sukhomlinov@google.com> Change-Id: I56c03ff4e8838871cdb28c0d9946c39754d9e054 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3219576 Reviewed-by: Vadim Sukhomlinov <sukhomlinov@chromium.org> Reviewed-by: Andrey Pronin <apronin@chromium.org> Tested-by: Vadim Sukhomlinov <sukhomlinov@chromium.org> Commit-Queue: Andrey Pronin <apronin@chromium.org>
* cr50: add functionality to support FIPS testing by labVadim Sukhomlinov2021-10-133-4/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 1) Add test commands to break all KAT tests [fips hmac/drbg/ecdsa/pwct] 2) To support PWCT demo reduced number of attempts to retrieve valid p256 key candidate to 16. Probability of false negative would be less than 2^-4080 (255*16), but will prevent DoS attack if it consistently fails for real reasons. 3) Fixed HMAC KAT test failure (was bound SHA failure earlier). BUG=b:138576604 TEST=make BOARD=cr50 CRYPTO_TEST=1 U2F_TEST=1 In ccd: fips fips hmac fips test - see FIPS error reboot fips drbg fips test - see FIPS error reboot fips ecdsa fips test - see FIPS error reboot fips pwct u2f_test - see NOT PASSED of u2f_generate/u2f_sign Signed-off-by: Vadim Sukhomlinov <sukhomlinov@google.com> Change-Id: I0a812075bb2436f5823eff446b725f19974a2a31 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3221770 Reviewed-by: Vadim Sukhomlinov <sukhomlinov@chromium.org> Reviewed-by: Andrey Pronin <apronin@chromium.org> Tested-by: Vadim Sukhomlinov <sukhomlinov@chromium.org> Auto-Submit: Vadim Sukhomlinov <sukhomlinov@chromium.org> Commit-Queue: Andrey Pronin <apronin@chromium.org>
* ccdblock: add option to tri-state the EC UARTMary Ruthven2021-10-131-6/+30
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Block EC UART output and EC COMM with 'ccdblock TRISTATE_EC enable'. This removes the EC UART output, prevents EC-EFS2, and removes the pulldown from the EC RX signal. This is used for flashing the EC with c2d2. It's only available when CCD is enabled. BUG=b:202464674 TEST=manual # Disconnect servo. Verify EC tx is disabled and there's no pull # down after tristating the EC > ccdblock TRISTATE_EC enable CCD ports blocked: EC IGNORE_SERVO WARNING: enabling UART while servo is connected may damage hardware EC_CR50_COMM TRISTATE_EC > pinmux ... 400600c8: DIOB5 0 IN 400600d0: DIOB6 16 IN GPIO0_GPIO15 ... > ccdstate ... State flags: UARTAP USBEC+TX CCD ports blocked: EC EC_CR50_COMM TRISTATE_EC ... # Check UART TX is re-enabled after disabling TRISTATE_EC > ccdblock TRISTATE_EC disable CCD ports blocked: (none) > ccdstate ... State flags: UARTAP+TX UARTEC+TX I2C SPI USBEC+TX CCD ports blocked: (none) ... > pinmux ... 400600c8: DIOB5 78 IN UART2_TX 400600d0: DIOB6 16 IN GPIO0_GPIO15 ... # Connect servo, so cr50 disables the EC UART on it's own. # Verify the pulldown is removed after tristating the EC. > ccdstate ... State flags: UARTAP UARTEC USBEC+TX CCD ports blocked: (none) > pinmux ... 400600c8: DIOB5 0 IN PD 400600d0: DIOB6 16 IN GPIO0_GPIO15 ... > ccdblock TRISTATE_EC enable CCD ports blocked: EC EC_CR50_COMM TRISTATE_EC > ccdstate ... State flags: UARTAP USBEC+TX CCD ports blocked: EC EC_CR50_COMM TRISTATE_EC # Check PD is removed from DIOB5 > pinmux ... 400600c8: DIOB5 0 IN 400600d0: DIOB6 16 IN GPIO0_GPIO15 ... # Check PD is re-enabled after disabling TRISTATE_EC > ccdblock TRISTATE_EC disable CCD ports blocked: (none) > ccdstate ... State flags: UARTAP UARTEC USBEC+TX CCD ports blocked: (none) > pinmux ... 400600c8: DIOB5 0 IN PD 400600d0: DIOB6 16 IN GPIO0_GPIO15 Change-Id: I7bde996be3914bd5d625ad99e418f9bd2c0f41d1 Signed-off-by: Mary Ruthven <mruthven@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3219760 Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
* rdd: only enable AP UART if the AP is onMary Ruthven2021-10-131-1/+1
| | | | | | | | | | | | | | | When the AP is off, cr50 doesn't need to enable the AP UART. Having it enabled could cause power leakage if the signals aren't terminated correctly. Check ap_is_on and ap_uart_is_on before enabling the AP UART. BUG=b:136602563 TEST=firmware_Cr50DeviceState Change-Id: I192bdc4caef8cfa0ce6d8a3ca181b16388e35cd4 Signed-off-by: Mary Ruthven <mruthven@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3219756 Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
* cr50: use LTO module for TPM2Vadim Bendebury2021-10-111-20/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In order to reduce code footprint, do not link TPM2 library modules, instead build TPM2 as a single relocatable object module, a collection of library sources compiled and linked with LTO enabled. BUG=b:65253310 TEST=observed code space reduced by 1428 bytes, the bss_libtpm2 section remained practically unchanged: before: *** 5548 bytes in flash and 5652 bytes in RAM still ... 000104d0 B __bss_libtpm2_start 000155d7 B __bss_libtpm2_end after: *** 6976 bytes in flash and 5652 bytes in RAM still ... 000104d0 B __bss_libtpm2_start 000155d4 B __bss_libtpm2_end Verified that the new Cr50 image allows a Chrome OS to successfully boot and restart. Cq-Depend: chromium:3210050 Signed-off-by: Vadim Bendebury <vbendeb@chromium.org> Change-Id: I32335df29a332da115d8af56c157d5ad4189e9b0 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3210510 Reviewed-by: Vadim Sukhomlinov <sukhomlinov@chromium.org> Reviewed-by: Mary Ruthven <mruthven@chromium.org>
* cr50: fix fuzzingVadim Sukhomlinov2021-10-071-8/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | make runfuzztests started to fail once both: https://crrev.com/c/3162473 and https://crrev.com/c/3208916 landed. Clang seems to incorrectly discarding sections it generated for profiling, resulting in: __profc_DCRYPTO_hw_sha256_init' referenced in section .text.compute_hash[compute_hash]' of build/host/cr50_fuzz/libec.a(libec.a.2.o): defined in discarded section `__llvm_prf_cnts[__profd_DCRYPTO_hw_sha256_init]' of build/host/cr50_fuzz/libec.a(libec.a.2.o) __profc_DCRYPTO_hw_sha256_init' referenced in section .text.create_merkle_tree[create_merkle_tree]' of build/host/cr50_fuzz/libec.a(libec.a.2.o): defined in discarded section `__llvm_prf_cnts[__profd_DCRYPTO_hw_sha256_init]' of build/host/cr50_fuzz/libec.a(libec.a.2.o) clang-13: error: linker command failed with exit code 1 (use -v to see invocation) This definition of __always_inline should be useful in other cases, so moving it into common.h. Note, we have to #undef it first, as it is previously defined in system headers. BUG=none TEST=make buildall -j Signed-off-by: Vadim Sukhomlinov <sukhomlinov@google.com> Change-Id: I073b38a68fd43a14dbe92063011c95758030b225 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3213113 Reviewed-by: Vadim Sukhomlinov <sukhomlinov@chromium.org> Reviewed-by: Andrey Pronin <apronin@chromium.org> Tested-by: Vadim Sukhomlinov <sukhomlinov@chromium.org> Commit-Queue: Vadim Sukhomlinov <sukhomlinov@chromium.org>
* cr50: fix make file dependencies for FIPS moduleVadim Sukhomlinov2021-10-071-1/+2
| | | | | | | | | | | | | | | | | | | | | Dependencies for FIPS module were incorrectly set as actual dependency on $(out)/ec_version.h and $(out)/env_config.h instead of order-only dependency, causing rebuild on any change in repository. BUG=b:202225290 TEST=make BOARD=cr50 echo ' ' >> board/cr50/tpm2/rsa.c make BOARD=cr50 should only rebuild tpm2/rsa.c and not dcrypto/* Signed-off-by: Vadim Sukhomlinov <sukhomlinov@google.com> Change-Id: I4d2e8e4a2182ddf850ccfad18e9b517f41594d55 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3208539 Reviewed-by: Vadim Sukhomlinov <sukhomlinov@chromium.org> Reviewed-by: Vadim Bendebury <vbendeb@chromium.org> Tested-by: Vadim Sukhomlinov <sukhomlinov@chromium.org> Commit-Queue: Vadim Sukhomlinov <sukhomlinov@chromium.org>
* cr50: change static inline to __always_inlineVadim Sukhomlinov2021-10-072-73/+76
| | | | | | | | | | | | | | | | | | | | | | | gcc 11.2 changes semantic of how 'static inline' works with LTO, which causes either ODR or missing symbol issues during linking when several objects created by LTO. After several experiments with inline extern inline It seems that using __inline __attribute__(always_inline) is most reliable method. BUG=None TEST=make buildall -j Signed-off-by: Vadim Sukhomlinov <sukhomlinov@google.com> Change-Id: I4d0e8bed00bbc3b3e580c4c610a2f733f2525973 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3208916 Reviewed-by: Vadim Sukhomlinov <sukhomlinov@chromium.org> Reviewed-by: Andrey Pronin <apronin@chromium.org> Tested-by: Vadim Sukhomlinov <sukhomlinov@chromium.org> Commit-Queue: Vadim Sukhomlinov <sukhomlinov@chromium.org>
* cr50: improve toolchainHoward Yang2021-10-071-1/+1
| | | | | | | | | | | | | | Adjust Makefile toolchain setting so that fuzzers can generate coverage mapping correctly and generate debug symbols for source-based coverage report. Also, update gitignore to ignore local vscode settings. BUG=none TEST=make buildall -j Change-Id: I6d5c720895cbb9119c9266df998aa5cc308c1e61 Signed-off-by: Howard Yang <hcyang@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3162473 Reviewed-by: Andrey Pronin <apronin@chromium.org>
* cr50: switch CR50_DEV in FIPS module to branches of CRYPTO_TESTVadim Sukhomlinov2021-10-074-29/+40
| | | | | | | | | | | | | | | | | | | | | | | | Due to limited space available with CR50_DEV=1, move some of crypto related functionality which was under CR50_DEV to branches of CRYPTO_TEST=1, namely: - SELF_TEST=1 to print self-integrity hashes - U2F_VERBOSE=1 to print debug information from U2F key generation. Config options sorted alphabetically in ENV_VARS and in processing order. BUG=None TEST=make BOARD=cr50 CR50_DEV=1 make BOARD=cr50 CRYPTO_TEST=1 SELF_TEST=1 make BOARD=cr50 CRYPTO_TEST=1 U2F_TEST=1 U2F_VERBOSE=1 Signed-off-by: Vadim Sukhomlinov <sukhomlinov@google.com> Change-Id: I66485b2d1fff8c0947aaf31c93348a16101f14b7 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3209647 Reviewed-by: Vadim Sukhomlinov <sukhomlinov@chromium.org> Reviewed-by: Vadim Bendebury <vbendeb@chromium.org> Tested-by: Vadim Sukhomlinov <sukhomlinov@chromium.org> Commit-Queue: Vadim Sukhomlinov <sukhomlinov@chromium.org>
* cr50: switch TRNG register access to use struct instead of GREADVadim Sukhomlinov2021-10-072-25/+65
| | | | | | | | | | | | | | | This allows a bit more efficient code generation. BUG=none TEST=make BOARD=cr50 CRYPTO_TEST=1 RND_TEST=1 Signed-off-by: Vadim Sukhomlinov <sukhomlinov@google.com> Change-Id: Ia92116a9aa4ac7d9f77d207205e712c03722dd95 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3210238 Reviewed-by: Vadim Sukhomlinov <sukhomlinov@chromium.org> Reviewed-by: Andrey Pronin <apronin@chromium.org> Tested-by: Vadim Sukhomlinov <sukhomlinov@chromium.org> Commit-Queue: Vadim Sukhomlinov <sukhomlinov@chromium.org>
* cr50: move bn dcrypto microcode into dcrypto_bn.incVadim Sukhomlinov2021-10-072-1102/+1102
| | | | | | | | | | | | | | | | | To simplify code analysis, move dcrypto's blob into dcrypto_bn.inc similar to p256 code in dcrypto_p256.inc. BUG=none TEST=make BOARD=cr50 CRYPTO_TEST=1; test/tpm_test/tpmtest.py Signed-off-by: Vadim Sukhomlinov <sukhomlinov@google.com> Change-Id: I2ae3a0793bd829c15844d55061952a69a412e2e9 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3210226 Reviewed-by: Vadim Sukhomlinov <sukhomlinov@chromium.org> Reviewed-by: Vadim Bendebury <vbendeb@chromium.org> Reviewed-by: Andrey Pronin <apronin@chromium.org> Tested-by: Vadim Sukhomlinov <sukhomlinov@chromium.org> Commit-Queue: Vadim Sukhomlinov <sukhomlinov@chromium.org>
* cr50: move sha512 dcrypto microcode into dcrypto_sha512.incVadim Sukhomlinov2021-10-072-432/+435
| | | | | | | | | | | | | | | | | | To simplify code analysis, move dcrypto's blob into dcrypto_sha512.inc similar to p256 code in dcrypto_p256.inc. In the process fix minor compiler warning on signed/unsigned compare. BUG=none TEST=make BOARD=cr50 CRYPTO_TEST=1; test/tpm_test/tpmtest.py Signed-off-by: Vadim Sukhomlinov <sukhomlinov@google.com> Change-Id: I4aac81a3b6fa0c055b83f91575f2d37755845e63 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3210229 Reviewed-by: Vadim Sukhomlinov <sukhomlinov@chromium.org> Reviewed-by: Vadim Bendebury <vbendeb@chromium.org> Tested-by: Vadim Sukhomlinov <sukhomlinov@chromium.org> Commit-Queue: Vadim Sukhomlinov <sukhomlinov@chromium.org>
* cr50: add support for v2 of U2F key handle for WebAuthnstabilize-14267.B-cr50_stabVadim Sukhomlinov2021-10-061-75/+197
| | | | | | | | | | | | | | | | | | | Adding v2 of key handle which drops kh_hmac field and use single authorization code for all relevant fields. BUG=b:172971998 TEST=make BOARD=cr50 CRYPTO_TEST=1 U2F_TEST=1; in ccd: u2f_test - unit tests test/tpm_test/tpmtest.py Signed-off-by: Vadim Sukhomlinov <sukhomlinov@google.com> Change-Id: I647ded7a2c157cea91ac48a2ba679def318c1e63 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3199671 Reviewed-by: Vadim Sukhomlinov <sukhomlinov@chromium.org> Reviewed-by: Andrey Pronin <apronin@chromium.org> Tested-by: Vadim Sukhomlinov <sukhomlinov@chromium.org> Auto-Submit: Vadim Sukhomlinov <sukhomlinov@chromium.org> Commit-Queue: Vadim Sukhomlinov <sukhomlinov@chromium.org>
* cr50: switch RSA/big numbers to dynamic buffer allocation for RSA 4KVadim Sukhomlinov2021-10-061-13/+17
| | | | | | | | | | | | | | | | | | Several bn_* function still use static buffer allocation. Switch to dynamic allocation to enable support for RSA 3K/4K. BUG=none TEST=make BOARD=cr50 CRYPTO_TEST=1; test/tpm_test/tpmtest.py ../../build/tpm_test/bn_test TCG tests Signed-off-by: Vadim Sukhomlinov <sukhomlinov@google.com> Change-Id: I150fa99bde89cc486f7ad945b5a312fe7d787fb0 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3207349 Reviewed-by: Vadim Sukhomlinov <sukhomlinov@chromium.org> Reviewed-by: Andrey Pronin <apronin@chromium.org> Tested-by: Vadim Sukhomlinov <sukhomlinov@chromium.org> Commit-Queue: Vadim Sukhomlinov <sukhomlinov@chromium.org>
* cr50: update AES-CMAC implementationVadim Sukhomlinov2021-10-063-118/+135
| | | | | | | | | | | | | | | | | | | | | | | Cr50 doesn't use CMAC, it is not even compiled, however during internal review potential issues with branching on key values were spotted. 1) Fix key expansion to be constant time 2) Switch to enum dcrypto_result 3) Test commands updated to be compatible with FIPS build (use .rodata) 4) Clean up computed tag on stack during verification BUG=None TEST=make BOARD=cr50 CRYPTO_TEST=1 CMAC_TEST=1 in ccd: test_cmac 1 2 3 4 test_cmac_ver 1 2 3 4 Signed-off-by: Vadim Sukhomlinov <sukhomlinov@google.com> Change-Id: Iff9b84dd8fb2baed9152f1ee5c40ef8e4198edd3 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3194972 Reviewed-by: Vadim Sukhomlinov <sukhomlinov@chromium.org> Reviewed-by: Andrey Pronin <apronin@chromium.org> Tested-by: Vadim Sukhomlinov <sukhomlinov@chromium.org> Commit-Queue: Vadim Sukhomlinov <sukhomlinov@chromium.org>
* cr50: update RSA public API to block access on FIPS errorsVadim Sukhomlinov2021-10-069-186/+230
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 1. Switched RSA public and internal functions to use enum dcrypto_result 2. Added checks for FIPS errors. 3. Updated call sites to properly handle result values. BUG=b:197893750 TEST=make BOARD=cr50 CRYPTO_TEST=1; test/tpm_test/tpm_test.py TCG tests: ---------------------- Test Result Summary ----------------------------- Test executed on: Mon Oct 5 18:26:07 2021 Performed Tests: 248 Passed Tests: 248 Failed Tests: 0 Errors: 0 Warnings: 0 ======================================================================== Signed-off-by: Vadim Sukhomlinov <sukhomlinov@google.com> Change-Id: I23d391322e55b541d72388b2a4661991a61dd020 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3207348 Reviewed-by: Vadim Sukhomlinov <sukhomlinov@chromium.org> Reviewed-by: Andrey Pronin <apronin@chromium.org> Commit-Queue: Vadim Sukhomlinov <sukhomlinov@chromium.org> Commit-Queue: Andrey Pronin <apronin@chromium.org> Tested-by: Vadim Sukhomlinov <sukhomlinov@chromium.org>
* cr50: RSA enhancementsVadim Sukhomlinov2021-10-051-59/+68
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | 1.Implemented dynamic stack allocation of big number buffers to support up to RSA 4K for all public APIs. 2. Internal function switched to use enum dcrypto_result 3. Added check that provided exponent is at least odd number (should be prime / co-prime with N). 4. Saving a bit by reusing zero constant. BUG=none TEST=make BOARD=cr50 CRYPTO_TEST=1; test/tpm_test/tpmtest.py TCG tests ---------------------- Test Result Summary ----------------------------- Test executed on: Mon Oct 4 22:46:07 2021 Performed Tests: 248 Passed Tests: 248 Failed Tests: 0 Errors: 0 Warnings: 0 ======================================================================== Signed-off-by: Vadim Sukhomlinov <sukhomlinov@google.com> Change-Id: Id23ebfdc04132de1f26ee0888b00cacdee2eaf43 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3204566 Reviewed-by: Vadim Sukhomlinov <sukhomlinov@chromium.org> Reviewed-by: Vadim Bendebury <vbendeb@chromium.org> Tested-by: Vadim Sukhomlinov <sukhomlinov@chromium.org> Commit-Queue: Vadim Sukhomlinov <sukhomlinov@chromium.org>
* cr50: Update AES public APIsfactory-ambassador-14265.B-cr50_stabVadim Sukhomlinov2021-10-056-49/+102
| | | | | | | | | | | | | | | | | | | | To support FIPS mode we need to block access to crypto in case of errors. 1) Added check for FIPS errors into DCRYPTO_aes_init() 2) Return codes updated to enum dcrypto_result 3) Call sites updated to check for return codes BUG=b:197893750 TEST=make BOARD=cr50 CRYPTO_TEST=1; test/tpm_test/tpmtest.py Signed-off-by: Vadim Sukhomlinov <sukhomlinov@google.com> Change-Id: Id614cc346fe22537e9208196bf1322221a253b0c Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3194985 Reviewed-by: Vadim Sukhomlinov <sukhomlinov@chromium.org> Reviewed-by: Andrey Pronin <apronin@chromium.org> Commit-Queue: Vadim Sukhomlinov <sukhomlinov@chromium.org> Tested-by: Vadim Sukhomlinov <sukhomlinov@chromium.org>
* cr50: fix build with older gcc8.3 until gcc 11.2 lands properlyVadim Sukhomlinov2021-10-051-1/+2
| | | | | | | | | | | | | | | | New options for gcc 11.2 doesn't work on gcc 8.3 since gcc 11.2 update was reverted. BUG=None TEST=make buildall Signed-off-by: Vadim Sukhomlinov <sukhomlinov@google.com> Change-Id: Idf965bab903f2700dd01eb028e2a1aa6dc53e101 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3206474 Reviewed-by: Vadim Sukhomlinov <sukhomlinov@chromium.org> Reviewed-by: Vadim Bendebury <vbendeb@chromium.org> Tested-by: Vadim Sukhomlinov <sukhomlinov@chromium.org> Commit-Queue: Vadim Sukhomlinov <sukhomlinov@chromium.org>