summaryrefslogtreecommitdiff
path: root/board/cr50/tpm2/rsa.c
Commit message (Collapse)AuthorAgeFilesLines
* cr50: return various error codes for certain TPM2 operationsstabilize-15335.B-cr50_stabVadim Sukhomlinov2023-01-301-1/+1
| | | | | | | | | | | | | | | | | | Adjust error codes to distinguish different places in key generation. BUG=b:262324344 TEST=TCG tests Change-Id: I33ef8b772821ad43cf8af1b33b6b49143eb24aef Signed-off-by: Vadim Sukhomlinov <sukhomlinov@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4199163 Reviewed-by: Vadim Bendebury <vbendeb@chromium.org> Reviewed-by: Andrey Pronin <apronin@chromium.org> Auto-Submit: Vadim Sukhomlinov <sukhomlinov@chromium.org> Code-Coverage: Vadim Sukhomlinov <sukhomlinov@chromium.org> Commit-Queue: Andrey Pronin <apronin@chromium.org> Tested-by: Vadim Sukhomlinov <sukhomlinov@chromium.org> Reviewed-by: Vadim Sukhomlinov <sukhomlinov@chromium.org>
* fix ChromiumOS authors and whitespace warningsMary Ruthven2022-09-131-1/+1
| | | | | | | | | | | BUG=none TEST=none Change-Id: I61b0b0106a43f723ec3bc805eb190aef00bbd05b Signed-off-by: Mary Ruthven <mruthven@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3894391 Reviewed-by: Vadim Bendebury <vbendeb@chromium.org> Commit-Queue: Vadim Bendebury <vbendeb@chromium.org>
* cr50: update RSA public API to block access on FIPS errorsVadim Sukhomlinov2021-10-061-13/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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: provide public crypto API for HMAC/HASH with error reporting.Vadim Sukhomlinov2021-10-021-3/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | To implement FIPS mode for Cr50 we should be able to block access to crypto functions if errors are detected. Historically all HASH/HMAC functions were declared as void with no return type. 1) Split existing functions into public part (data structs, update and final parts) and internal part - unchecked init functions. 2) Introduced new functions to start SHA / HMAC operation which returns status code and block access to crypto in case of FIPS errors. 3) Dcrypto hash algorithms codes updated to match TPM_ALG_ID to simplify adaptation layer and move checks inside Dcrypto module. 4) Updated all uses of API outside FIPS module to check return code and act accordingly. 5) As a side effect RSA can now support SHA384 & SHA512 for signing, board/host mock ups simplified. BUG=b:197893750 TEST=make buildall -j; make BOARD=cr50 CRYPTO_TEST=1; test/tpm_test/tpm_test.py TCG tests ------------------------------ Test Result Summary --------------------- Test executed on: Tue Sep 28 15:23:35 2021 Performed Tests: 248 Passed Tests: 248 Failed Tests: 0 Errors: 0 Warnings: 0 ======================================================================== Signed-off-by: Vadim Sukhomlinov <sukhomlinov@google.com> Change-Id: Ibbc38703496f417cba693c37d39a82a662c3f7ee Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3192137 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: detangle public and internal APIs of FIPS moduleVadim Sukhomlinov2021-09-181-2/+1
| | | | | | | | | | | | | | | | | | | To properly define FIPS module boundary all APIs provided by module to external applications (TPM2, pinweaver, etc) should be identifiable. Shuffle functions between dcrypto.h and internal.h to achieve this goal. Adjust included headers as needed. BUG=b:134594373 TEST=make buildall; TCG tests Signed-off-by: Vadim Sukhomlinov <sukhomlinov@google.com> Change-Id: Ie2679644d62e232a5d5d06f8ed6bf602853ebde2 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3169558 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: add hardened crypto return codes, harden DCRYPTO_equalsVadim Sukhomlinov2021-09-041-5/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 1. Introduce enum dcrypto_result defining DCRYPTO_OK and DCRYPTO_FAIL constants such that they have large Hamming distance, thus becoming more fault-injection resistant. 2. Added value_barrier() and value_barrier_ptr() which prevents compiler from certain optimizations, removal of conditional execution. 3. Added hardened_select_if_zero() primitive which produce branch-less selection between values. 4. Added convenience function dcrypto_ok_if_zero() to convert zero into DCRYPTO_OK. 5. DCRYPTO_equals() implemented in a way that it also checks completion of all iterations in addition to comparing value. This makes it resistant to fault injection which would result in no comparisons made. 6. Updated uses of DCRYPTO_equals() to check for new return code. 7. Few memcmp() replaced with DCRYPTO_equals(). BUG=b:197893750 TEST=make BOARD=cr50 CRYPTO_TEST=1; tests/tpmtest.py in console check that FIPS KAT tests passes. Signed-off-by: Vadim Sukhomlinov <sukhomlinov@google.com> Change-Id: I2a0373e8be97c2d61a2c4743c74614c2ff064a8a Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3125994 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> Auto-Submit: Vadim Sukhomlinov <sukhomlinov@chromium.org>
* cr50: final touches to remove cryptoc dependencystabilize-14163.B-cr50_stabVadim Sukhomlinov2021-08-161-1/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | To implement FIPS module we need to bring many crypto functions in the module boundary. Unfortunately, cryptoc is a third-party library used by dcrypto code in cr50. Cryptoc is also not well-maintained and shared with other projects. While just making local copy of cryptoc would solve an issue, it's suboptimal as prevents from many optimizations and improvements. 1. Clean-up of #include dependencies on cryptoc 2. Build configuration drops linking with cryptoc for cr50 3. Dcrypto SHA512 code updated to compile and partially tested. It is about 4x faster on large messages, and about 620 bytes larger. Added an config option to use Dcrypto version as software, but not enabled. More testing is needed to make sure it's safe and doesn't have unintended interactions with RSA and ECDSA Dcrypto code. BUG=b:138578318 TEST=make BOARD=cr50 CRYPTO_TEST=1; tpm_test Signed-off-by: Vadim Sukhomlinov <sukhomlinov@google.com> Change-Id: I030b60b75daeec9c8ef079017a73345829bf7f0b Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3093093 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: drop cryptoc for SHA1/SHA2 supportstabilize-14150.882.B-cr50_stabstabilize-14150.881.B-cr50_stabstabilize-14150.74.B-cr50_stabstabilize-14150.734.B-cr50_stabstabilize-14150.64.B-cr50_stabstabilize-14150.43.B-cr50_stabstabilize-14150.376.B-cr50_stabrelease-R94-14150.B-cr50_stabrelease-R94-14150.49.B-cr50_stabVadim Sukhomlinov2021-08-121-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | To implement FIPS module we need to bring many crypto functions in the module boundary. Unfortunately, cryptoc is a third-party library used by dcrypto code in cr50. Cryptoc is also not well-maintained and shared with other projects. While just making local copy of cryptoc would solve an issue, it's suboptimal as prevents from many optimizations and improvements. Provided SHA & HMAC implementations from Ti50 project. This provides better performance (500us vs. 670us earlier for HMAC DRBG) and reduce code size. This implementation also enables stack use savings when only specific digest is needed. Earlier SHA512 context was allocated when only SHA256 is needed greatly increasing stack consumption for code using HMAC_DRBG and others. However, it introduce subtle API changes which require handling. As for tests, since core implementation is hardware-independent, make it available for BOARD=host too. Before change (with cryptoc): *** 12368 bytes in flash and 5784 bytes in RAM After: *** 13136 bytes in flash and 5796 bytes in RAM BUG=b:138578318 TEST=make BOARD=cr50 CRYPTO_TEST=1; test/tpm_test/tpmtest.py Signed-off-by: Vadim Sukhomlinov <sukhomlinov@google.com> Change-Id: I2ff5362aee9078ce83dc1f8081943a5101d5f666 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3064201 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: replace dcrypto_memset with always_memsetnagendra modadugu2017-05-151-7/+6
| | | | | | | | | | | | | | | | | | | | | | | always_memset() implements a version of memset that survives compiler optimization. This change replaces instances of the (placeholder) call dcrypto_memset() with always_memset(). Also add a couple of missing memsets and fix related TODOs by replacing memset() with always_memset(). BRANCH=none BUG=none TEST=TCG tests pass Change-Id: I742393852ed5be9f74048eea7244af7be027dd0e Signed-off-by: nagendra modadugu <ngm@google.com> Reviewed-on: https://chromium-review.googlesource.com/501368 Commit-Ready: Nagendra Modadugu <ngm@google.com> Tested-by: Nagendra Modadugu <ngm@google.com> Reviewed-by: Vadim Bendebury <vbendeb@chromium.org> Reviewed-by: Andrey Pronin <apronin@chromium.org>
* CR50: add support for 4k RSA verifynagendra modadugu2017-01-281-17/+98
| | | | | | | | | | | | | | | | | | | | | Add support for verifying messages signed with 4096-bit RSA keys. Such messages may be generated by host side applications. Also update tpmtest.py to test 4k verification. BRANCH=none BUG=none TEST=added new tests to tpmtest.py; TCG tests pass Change-Id: I7450bd710c154c68c030ce176bfe7becbfbcb729 Signed-off-by: nagendra modadugu <ngm@google.com> Reviewed-on: https://chromium-review.googlesource.com/428220 Commit-Ready: Nagendra Modadugu <ngm@google.com> Tested-by: Marius Schilder <mschilder@chromium.org> Tested-by: Nagendra Modadugu <ngm@google.com> Reviewed-by: Marius Schilder <mschilder@chromium.org> Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
* cr50: add support for padding-only RSASSAAndrey Pronin2016-12-221-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Perform PKCS1-padding-only signing for RSASSA if hashing algorithm is TPM_ALG_NULL. This feature is guarded by SUPPORT_PADDING_ONLY_RSASSA macro in tpm2/Implementation.h. BUG=chrome-os-partner:60967 BRANCH=none TEST=On a unowned machine with TPM2: corp enroll, login, install a network certificate (gECC or GMC), then: a) retrieve the public key from the installed certificate LIBCHAPS=`ls /usr/lib**/libchaps.so` CERTID=`pkcs11-tool --module=$LIBCHAPS --slot=1 --type=cert \ -O | grep "ID:" | awk '{print $2}'` pkcs11-tool --module=$LIBCHAPS --slot=1 --id=$CERTID \ --type=cert -r > /tmp/cert openssl x509 -inform der -pubkey -noout -in /tmp/cert > /tmp/pub.key b) sign a sample text using the private key for the certificate and MD5-RSA-PKCS mechanism, not supported by TPM2_Sign command: echo "ABCDEF" > /tmp/1.txt pkcs11-tool --module=$LIBCHAPS --slot=1 --id=$CERTID --sign \ -i /tmp/1.txt -o /tmp/1.sig -m MD5-RSA-PKCS c) verify signature: openssl dgst -md5 -verify /tmp/pub.key \ -signature /tmp/1.sig /tmp/1.txt Step (b) should succeed and step (c) should return "Verified OK". Change-Id: I0d7a11c48cdb04e37748f7255b98e9e023481a96 Signed-off-by: Andrey Pronin <apronin@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/420854 Reviewed-by: Darren Krahn <dkrahn@chromium.org>
* cr50: Initialize variable where it's usedMartin Roth2016-12-161-10/+9
| | | | | | | | | | | | | | | | | | | | The previous code split the initialization of digest_len out into a separate area than were it was used. This confused gcc into thinking that the variable might be uninitialized when it was used later. By putting it all in one area, we save a couple of bytes and make things more plain for the compiler. This does not change the size of any ec.*.flat file. BRANCH=none BUG=none TEST=build succeeds under GCC 4.9.2, 5.3 and 6.2 Change-Id: I1e21a13e3d7f9dc296296db6465ec975187a1cc0 Signed-off-by: Martin Roth <martinroth@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/411407 Reviewed-by: Nagendra Modadugu <ngm@google.com> Reviewed-by: Shawn N <shawnn@chromium.org>
* CR50: add support for SHA-384 & 512 PKCS#1 signaturesnagendra modadugu2016-12-011-0/+6
| | | | | | | | | | | | | | | | | | This change adds support for signing SHA-384 & 512 hashes when using PKCS#1 padding (CR50 does not support SHA-384 & 512 at the moment, the actual hashing is to be done on the host). BRANCH=none BUG=chrome-os-partner:59754 TEST=TCG tests pass Change-Id: I78e774639a7968cbb50e58cdd0bf479e64123630 Signed-off-by: nagendra modadugu <ngm@google.com> Reviewed-on: https://chromium-review.googlesource.com/415218 Commit-Ready: Nagendra Modadugu <ngm@google.com> Tested-by: Nagendra Modadugu <ngm@google.com> Reviewed-by: Andrey Pronin <apronin@chromium.org>
* cr50: Init variable before sending to function that uses itMartin Roth2016-11-161-4/+5
| | | | | | | | | | | | | | | | | | | | | Although the variable "hashing" is not used for PADDING_MODE_NULL or PADDING_MODE_PKCS1, the functions DCRYPTO_rsa_encrypt and DCRYPTO_rsa_decrypt use it for other padding types. Because of this, GCC 5.3 and newer throws warnings when the variable is passed in to those functions without being initialized. To fix this, always initialize the variable, even if it's not going to be used. This does not increase the size of any ec.*.flat file. BRANCH=none BUG=none TEST=build succeeds under GCC 4.9.2, 5.3 and 6.2 Change-Id: Iafaaaed8b05080f70f2b1c2f0dbf1ee22227fd78 Signed-off-by: Martin Roth <martinroth@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/403499 Reviewed-by: Shawn N <shawnn@chromium.org>
* CR50: add a constant time buffer equals implementationnagendra modadugu2016-11-111-3/+3
| | | | | | | | | | | | | | | | | | | | | | Various cryptographic operations leak timing information if comparisons are not executed in constant time. This change adds DCRYPTO_equals(), a constant runtime comparator. Also replace crypto related callsites that used memcmp() as a binary comparator. BUG=none BRANCH=none TEST=tcg tests pass Change-Id: I3d3da3c0524c3a349d60675902d1f2d338ad455f Signed-off-by: nagendra modadugu <ngm@google.com> Reviewed-on: https://chromium-review.googlesource.com/410163 Commit-Ready: Nagendra Modadugu <ngm@google.com> Tested-by: Nagendra Modadugu <ngm@google.com> Reviewed-by: Marius Schilder <mschilder@chromium.org> Reviewed-by: Bill Richardson <wfrichar@chromium.org>
* CR50: use vendor template for RSA endorsement primary keygennagendra modadugu2016-09-161-3/+57
| | | | | | | | | | | | | | | | | | | | | | | | When generating the RSA endorsement primary key, use the CR50 vendor specific template. Doing so generates the RSA key corresponding to the certificate issued at manufacture. Also, always start the RSA key generation counter at 1. Doing so matches the certificate generation process at manufacture; and there is no harm in always starting at 1, since the key generation process remains deterministic. BUG=none BRANCH=none TESTED=generated key matches endorsement cert; checked via attestation_client Change-Id: I6a5c329e99292e32f880c0c5ea364d511cb6ea82 Signed-off-by: nagendra modadugu <ngm@google.com> Reviewed-on: https://chromium-review.googlesource.com/386279 Commit-Ready: Nagendra Modadugu <ngm@google.com> Tested-by: Nagendra Modadugu <ngm@google.com> Tested-by: Andrey Pronin <apronin@chromium.org> Reviewed-by: Bill Richardson <wfrichar@chromium.org>
* CR50: match private key against certs on endorsementnagendra modadugu2016-07-211-12/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | This change updates the ecc and rsa key generation templates. Due to crosbug.com/p/55260 in which the TPMT_PUBLIC template is truncated during personalization, ecc generation requires a workaround. For RSA, allow the standard template to be used even on development builds. BRANCH=none BUG=chrome-os-partner:43025,chrome-os-partner:47524 BUG=chrome-os-partner:50115,chrome-os-partner:55260 TEST=test full personalize + cros_ack verify cert flow Signed-off-by: nagendra modadugu <ngm@google.com> Reviewed-on: https://chromium-review.googlesource.com/360441 Reviewed-by: Vadim Bendebury <vbendeb@chromium.org> Commit-Queue: Vadim Bendebury <vbendeb@chromium.org> Tested-by: Vadim Bendebury <vbendeb@chromium.org> (cherry picked from commit db5a1ca8a40be9bf7e741637cd8d7f15f520ab11) Signed-off-by: Vadim Bendebury <vbendeb@chromium.org> (cherry picked from commit b6620239bb7c4f5900051677f40f161c0a853a94) Change-Id: I1af83f1ec86e7ee4d325a4b7aabe03ce08c4108b Reviewed-on: https://chromium-review.googlesource.com/362142 Reviewed-by: Nagendra Modadugu <ngm@google.com>
* CR50: fix uninitialized buffer size in _cpri__SignRSAnagendra modadugu2016-07-211-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | The TPM2 wrapper library does not initialize the size of an output buffer length prior to calling into cr50/tpm2. This results in arbitrary failures depending on memory layout. Force the buffer length unseen, though this should be fixed in the TPM2 library. BRANCH=none BUG=chrome-os-partner:43025,chrome-os-partner:47524 BUG=chrome-os-partner:50115,chrome-os-partner:55260 TEST=test full personalize + cros_ack verify cert flow TEST=CPCTPM_TC2_2_20_02_03 passes, which was consistently failing Signed-off-by: nagendra modadugu <ngm@google.com> Reviewed-on: https://chromium-review.googlesource.com/360908 Reviewed-by: Vadim Bendebury <vbendeb@chromium.org> (cherry picked from commit 635cb7ada25e76e504087916364e2db08a2133ab) Change-Id: I90e9b4d76986ffa27acc944e48afc2efaadad7cd Reviewed-on: https://chromium-review.googlesource.com/362116 Commit-Ready: Vadim Bendebury <vbendeb@chromium.org> Tested-by: Vadim Bendebury <vbendeb@chromium.org>
* CR50: rename struct BIGNUM -> struct LITE_BIGNUMnagendra modadugu2016-07-211-11/+12
| | | | | | | | | | | | | | | | | | | | | | | | The name BIGNUM collides with a namesake struct in openssl. It would be convenient to write test code that compares results between openssl and dcrypto, hence this rename. Also rename some #defines that conflict with openssl names. CQ-DEPEND=CL:*270476 BRANCH=none BUG=chrome-os-partner:43025,chrome-os-partner:47524,chrome-os-partner:50115 TEST=build succeeds Signed-off-by: nagendra modadugu <ngm@google.com> Reviewed-on: https://chromium-review.googlesource.com/360346 Reviewed-by: Vadim Bendebury <vbendeb@chromium.org> (cherry picked from commit a15b495497728a6b212bd87e92f6ba5ba463f985) Change-Id: Ic53ce805cfcc591c68fbc1ef90ff2f92cec973a6 Signed-off-by: Vadim Bendebury <vbendeb@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/362112 Reviewed-by: Nagendra Modadugu <ngm@google.com>
* CR50: add a golden test for RSA key gen from a fixed seednagendra modadugu2016-06-291-11/+39
| | | | | | | | | | | | | | | | Add a test that verifies RSA keygen from a fixed seed and template from the TCG EK Credential Profile spec. BRANCH=none BUG=chrome-os-partner:43025,chrome-os-partner:47524 TEST=tests under test/tpmtest pass Change-Id: I2f1cfb8460a0497c93079b89b9ff4e031eaff358 Reviewed-on: https://chromium-review.googlesource.com/356561 Commit-Ready: Nagendra Modadugu <ngm@google.com> Tested-by: Nagendra Modadugu <ngm@google.com> Reviewed-by: Marius Schilder <mschilder@chromium.org> Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
* CR50: give ecc and rsa keys distinct derivation templatesnagendra modadugu2016-06-151-2/+20
| | | | | | | | | | | | | | | | | | | This change implements distinct key derivation trees for ECC and RSA key generation. The seed used for derivation is HMAC(primary_seed, ALG), where ALG is either "ECC", or "RSA". BRANCH=none BUG=chrome-os-partner:43025,chrome-os-partner:47524 TEST=all tests in test/tpm_test/tpmtest.py pass Change-Id: Iee85731bdac02b7b1061e9220786bee52dbf6289 Signed-off-by: nagendra modadugu <ngm@google.com> Reviewed-on: https://chromium-review.googlesource.com/351750 Commit-Ready: Nagendra Modadugu <ngm@google.com> Tested-by: Nagendra Modadugu <ngm@google.com> Reviewed-by: Marius Schilder <mschilder@chromium.org> Reviewed-by: Bill Richardson <wfrichar@chromium.org>
* CR50: add a simple ASN.1 parser & certificate verifierstabilize-8447.Bnagendra modadugu2016-06-121-2/+142
| | | | | | | | | | | | | | | | | Add a certificate verifier, so that endorsement certificates may be verified upon installation. Doing so allows for catching certificate errors early. BRANCH=none BUG=chrome-os-partner:43025,chrome-os-partner:47524 TEST=all tests in test/tpm_test/tpmtest.py pass Change-Id: I9339a6bc36e4d82ae875ce774e31848ae983fa1f Signed-off-by: nagendra modadugu <ngm@google.com> Reviewed-on: https://chromium-review.googlesource.com/351031 Commit-Ready: Nagendra Modadugu <ngm@google.com> Tested-by: Nagendra Modadugu <ngm@google.com> Reviewed-by: Bill Richardson <wfrichar@chromium.org>
* CR50: add tests for 1024-bit RSA.nagendra modadugu2016-06-011-7/+80
| | | | | | | | | | | | | | | | | | | | Add tests for RSA-1024, and created partner CRBUG/53893 to track issue discovered with 1024-bit modinv. 1024-bit RSA support being added in preparation for a forthcoming hardware based implementation. BRANCH=none BUG=chrome-os-partner:43025,chrome-os-partner:47524,chrome-os-partner:53893 TEST=all tests in test/tpm_test/tpmtest.py pass Change-Id: I6b5aaeffc9df1cbbe403535fd21cdd377b42c38e Signed-off-by: nagendra modadugu <ngm@google.com> Reviewed-on: https://chromium-review.googlesource.com/348490 Commit-Ready: Nagendra Modadugu <ngm@google.com> Tested-by: Nagendra Modadugu <ngm@google.com> Reviewed-by: Nagendra Modadugu <ngm@google.com> Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
* CR50: increment prime generation counternagendra modadugu2016-05-261-5/+15
| | | | | | | | | | | | | | | | | | The counter used for prime generation should be incremented after each success / failure. Not doing so results in duplicate primes being picked when a label is explicitly specified. BRANCH=none BUG=chrome-os-partner:43025,chrome-os-partner:47524 TEST=all tests in test/tpm_test/tpmtest.py pass Change-Id: Ib2fd0e7fa6255b04946e6d2808e8c67a2199fb55 Signed-off-by: nagendra modadugu <ngm@google.com> Reviewed-on: https://chromium-review.googlesource.com/346056 Commit-Ready: Nagendra Modadugu <ngm@google.com> Tested-by: Nagendra Modadugu <ngm@google.com> Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
* CR50: remove checks on RSA key buffer sizenagendra modadugu2016-05-031-5/+0
| | | | | | | | | | | | | | | | | | | | | | Remove buffer size checks in _cpri__GenerateKeyRSA(). The TPM stack passes in TPM2B buffers that may have the size field uninitialized. Callees are expected to assume that the buffer size is sufficient for the requested operation. BRANCH=none BUG=chrome-os-partner:43025,chrome-os-partner:47524 TEST=TCG test CPCTPM_TC2_2_20_03_02 reliably passes Change-Id: I3d9bc2475b82dfaa9ed1d2617b1c333ff4df409d Signed-off-by: nagendra modadugu <ngm@google.com> Reviewed-on: https://chromium-review.googlesource.com/340883 Commit-Ready: Nagendra Modadugu <ngm@google.com> Tested-by: Nagendra Modadugu <ngm@google.com> Reviewed-by: Bill Richardson <wfrichar@chromium.org> Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
* CR50: add support for RSA key generationnagendra modadugu2016-04-201-4/+146
| | | | | | | | | | | | | | | | | Prime generation uses a sieve to amortize division with small primes. Otherwise this a standard Miller-Rabin implementation. BRANCH=none BUG=chrome-os-partner:43025,chrome-os-partner:47524 TEST=tests under test/tpm2 pass Change-Id: I9f84d1f9c911f6146e4bd80296f75157a191552d Signed-off-by: nagendra modadugu <ngm@google.com> Reviewed-on: https://chromium-review.googlesource.com/335222 Commit-Ready: Nagendra Modadugu <ngm@google.com> Tested-by: Nagendra Modadugu <ngm@google.com> Reviewed-by: Nagendra Modadugu <ngm@google.com>
* CR50: add support for RSA key "testing"nagendra modadugu2016-04-191-1/+162
| | | | | | | | | | | | | | | | | | | | | | Implement _cpri__TestKeyRSA, which computes the modulus and private exponent given a pair of primes, or computes the second prime and private exponent given the modulus and one prime. The _cpri__TestKeyRSA call is used to determine whether the components of an RSA key match each other. BRANCH=none BUG=chrome-os-partner:43025,chrome-os-partner:47524 TEST=tests in test/tpm/tpmtest.py pass Change-Id: I2c68d844f4bab207588cbda5c962b09078519a1a Signed-off-by: nagendra modadugu <ngm@google.com> Reviewed-on: https://chromium-review.googlesource.com/330466 Commit-Ready: Nagendra Modadugu <ngm@google.com> Tested-by: Nagendra Modadugu <ngm@google.com> Reviewed-by: Marius Schilder <mschilder@chromium.org>
* CR50: handle big-endian RSA keysnagendra modadugu2016-04-141-109/+147
| | | | | | | | | | | | | | | | | | | | | | The TPM library serializes RSA keys in big-endian format, while CR50 requires little-endian. Handle endianness by converting from big to little and back to big within the _cpri__* layer. Also modify test code to make copies of static const RSA keys, as these get placed on read-only memory. BRANCH=none BUG=chrome-os-partner:43025,chrome-os-partner:47524,chrome-os-partner:52337 TEST=tests in test/tpm/tpmtest.py pass Change-Id: Id9cfbe8c99ecaeb02744fbc7554cd48a08bab819 Signed-off-by: nagendra modadugu <ngm@google.com> Reviewed-on: https://chromium-review.googlesource.com/331740 Commit-Ready: Nagendra Modadugu <ngm@google.com> Tested-by: Nagendra Modadugu <ngm@google.com> Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
* CR50: add NULL padding support for RSA encrypt/decryptnagendra modadugu2016-03-311-1/+3
| | | | | | | | | | | | | | | | | NULL padding (aka vanilla RSA) support is required by the TPM2 test suite (referred to as TPM_ALG_NULL in the tpm2 source). BRANCH=none BUG=chrome-os-partner:43025,chrome-os-partner:47524 TEST=tests under test/tpm2 pass Change-Id: I9848fad3b44add05a04810ecd178fbad20ae92cc Signed-off-by: nagendra modadugu <ngm@google.com> Reviewed-on: https://chromium-review.googlesource.com/328830 Commit-Ready: Nagendra Modadugu <ngm@google.com> Tested-by: Nagendra Modadugu <ngm@google.com> Reviewed-by: Nagendra Modadugu <ngm@google.com>
* CR50: add support for RSA PKCS1-PSS paddingnagendra modadugu2016-03-301-3/+6
| | | | | | | | | | | | | | | Add support for PSS padding as per RFC 3447. BRANCH=none BUG=chrome-os-partner:43025,chrome-os-partner:47524 TEST=tests under tpm2 pass Change-Id: I14c58394f742daa5de4ec2fbeb7e7f14e54c9fcc Signed-off-by: nagendra modadugu <ngm@google.com> Reviewed-on: https://chromium-review.googlesource.com/328778 Commit-Ready: Nagendra Modadugu <ngm@google.com> Tested-by: Nagendra Modadugu <ngm@google.com> Reviewed-by: Nagendra Modadugu <ngm@google.com>
* CR50: enable the bignum library to handle word un-aligned keysnagendra modadugu2016-02-081-117/+104
| | | | | | | | | | | | | | | | | The TPM2 api does not require keys to be word-aligned, so have the compiler generate alignment-safe reads where necessary. BRANCH=none BUG=chrome-os-partner:43025,chrome-os-partner:47524 TEST=tests under test/tpm2/ pass, more TCG tests pass. Change-Id: I247e29f2bec139ab7ed4010ffb58cdae77ba9e0b Signed-off-by: nagendra modadugu <ngm@google.com> Reviewed-on: https://chromium-review.googlesource.com/326201 Commit-Ready: Nagendra Modadugu <ngm@google.com> Tested-by: Nagendra Modadugu <ngm@google.com> Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
* Initial RSA implementation.stabilize-7821.Bnagendra modadugu2016-01-111-0/+424
Includes support for encrypt / decrypt, and sign / verify; padding schemes OAEP / PKCS1; supporting bignum library. RSA key sizes must be a multiple of 32-bits (with the top bit set). Keying material, input and output buffers are required to be word-aligned. BRANCH=none TEST=added encrypt/decrypt sign/verify tests, compatibility with openssl tested BUG=chrome-os-partner:43025,chrome-os-partner:47524 Change-Id: I6bc324c651e3178bb45bb75ab5935d9bc07efbce Signed-off-by: nagendra modadugu <ngm@google.com> Reviewed-on: https://chromium-review.googlesource.com/316942 Commit-Ready: Marius Schilder <mschilder@chromium.org> Tested-by: Nagendra Modadugu <ngm@google.com> Reviewed-by: Marius Schilder <mschilder@chromium.org>