diff options
author | nagendra modadugu <ngm@google.com> | 2016-03-04 14:38:15 -0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2016-04-19 21:13:07 -0700 |
commit | c864a9785804a5e2e5cb2a7cbc4bb7fb993aa52a (patch) | |
tree | ae40fc6b41061eb348ae06d5ba97810f178ae1d9 /test/tpm_test | |
parent | 7e9245fde47860f0f1503c140d66a26a7860197f (diff) | |
download | chrome-ec-c864a9785804a5e2e5cb2a7cbc4bb7fb993aa52a.tar.gz |
CR50: add support for RSA key "testing"
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>
Diffstat (limited to 'test/tpm_test')
-rw-r--r-- | test/tpm_test/rsa_test.py | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/test/tpm_test/rsa_test.py b/test/tpm_test/rsa_test.py index 2a751d3ee7..14982d5380 100644 --- a/test/tpm_test/rsa_test.py +++ b/test/tpm_test/rsa_test.py @@ -17,7 +17,8 @@ _RSA_OPCODES = { 'DECRYPT': 0x01, 'SIGN': 0x02, 'VERIFY': 0x03, - 'KEYGEN': 0x04 + 'KEYGEN': 0x04, + 'KEYTEST': 0x05, } @@ -102,6 +103,13 @@ def _verify_cmd(padding, hashing, key_len, sig, msg): ml=struct.pack('>H', sig_len), msg=sig, dl=struct.pack('>H', digest_len), dig=digest) +def _keytest_cmd(key_len): + op = _RSA_OPCODES['KEYTEST'] + return _RSA_CMD_FORMAT.format(o=op, p=0, h=_HASH['NONE'], + kl=struct.pack('>H', key_len), + ml=struct.pack('>H', 0), msg='', + dl='', dig='') + # # TEST VECTORS. @@ -122,6 +130,10 @@ _SIGN_INPUTS = ( ('PKCS1-PSS', 'SHA256', 768), ) +_KEYTEST_INPUTS = ( + (768,), + (2048,), +) def _encrypt_tests(tpm): msg = 'Hello CR50!' @@ -172,6 +184,21 @@ def _sign_tests(tpm): print('%sSUCCESS: %s' % (utils.cursor_back(), test_name)) +def _keytest_tests(tpm): + for data in _KEYTEST_INPUTS: + key_len, = data + test_name = 'RSA-KEYTEST:%d' % data + cmd = _keytest_cmd(key_len) + wrapped_response = tpm.command(tpm.wrap_ext_command(subcmd.RSA, cmd)) + valid = tpm.unwrap_ext_response(subcmd.RSA, wrapped_response) + expected = '\x01' + if valid != expected: + raise subcmd.TpmTestError('%s error:%s%s' % ( + test_name, utils.hex_dump(valid), utils.hex_dump(expected))) + print('%sSUCCESS: %s' % (utils.cursor_back(), test_name)) + + def rsa_test(tpm): _encrypt_tests(tpm) _sign_tests(tpm) + _keytest_tests(tpm) |