CR50: add NULL padding support for RSA encrypt/decrypt

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>
This commit is contained in:
nagendra modadugu
2016-02-19 15:21:45 -08:00
committed by chrome-bot
parent 70378b86b4
commit 7aa42e2ba9
4 changed files with 42 additions and 5 deletions

View File

@@ -26,7 +26,8 @@ _RSA_PADDING = {
'PKCS1-SSA': 0x14,
'PKCS1-ES': 0x15,
'PKCS1-PSS': 0x16,
'OAEP': 0x17
'OAEP': 0x17,
'NULL': 0x10,
}
@@ -110,6 +111,7 @@ _ENCRYPT_INPUTS = (
('OAEP', 'SHA256', 768),
('PKCS1-ES', 'NONE', 768),
('PKCS1-ES', 'NONE', 2048),
('NULL', 'NONE', 768),
)
@@ -135,6 +137,14 @@ def _encrypt_tests(tpm):
key_len, ciphertext)
wrapped_response = tpm.command(tpm.wrap_ext_command(subcmd.RSA, cmd))
plaintext = tpm.unwrap_ext_response(subcmd.RSA, wrapped_response)
if padding == 'NULL':
# Check for leading zeros.
if reduce(lambda x, y: x | y,
map(ord, plaintext[:len(plaintext) - len(msg)])):
raise subcmd.TpmTestError('%s error:%s%s' % (
test_name, utils.hex_dump(msg), utils.hex_dump(plaintext)))
else:
plaintext = plaintext[len(plaintext) - len(msg):]
if msg != plaintext:
raise subcmd.TpmTestError('%s error:%s%s' % (
test_name, utils.hex_dump(msg), utils.hex_dump(plaintext)))