summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornagendra modadugu <ngm@google.com>2016-04-13 23:49:12 -0700
committerchrome-bot <chrome-bot@chromium.org>2016-04-14 17:28:25 -0700
commitd08dade97485fb5aaaaad33f9cfb5cb446a25cd8 (patch)
tree0650e0107c213f2058a5de62d74e870b087e865f
parent2fb8d2772cdb2d78019d0e27fceaeb7b0a608f78 (diff)
downloadchrome-ec-d08dade97485fb5aaaaad33f9cfb5cb446a25cd8.tar.gz
CR50: handle big-endian RSA keys
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>
-rw-r--r--board/cr50/tpm2/rsa.c256
1 files changed, 147 insertions, 109 deletions
diff --git a/board/cr50/tpm2/rsa.c b/board/cr50/tpm2/rsa.c
index 6345b70309..2e7ccd8208 100644
--- a/board/cr50/tpm2/rsa.c
+++ b/board/cr50/tpm2/rsa.c
@@ -9,6 +9,11 @@
#include <assert.h>
+static void reverse_tpm2b(TPM2B *b)
+{
+ reverse(b->buffer, b->size);
+}
+
static int check_key(const RSA_KEY *key)
{
if (key->publicKey->size & 0x3)
@@ -71,20 +76,26 @@ CRYPT_RESULT _cpri__EncryptRSA(uint32_t *out_len, uint8_t *out,
struct RSA rsa;
enum padding_mode padding;
enum hashing_mode hashing;
+ int result;
if (!check_key(key))
return CRYPT_FAIL;
if (!check_encrypt_params(padding_alg, hash_alg, &padding, &hashing))
return CRYPT_FAIL;
+ reverse_tpm2b(key->publicKey);
rsa.e = key->exponent;
rsa.N.dmax = key->publicKey->size / sizeof(uint32_t);
rsa.N.d = (struct access_helper *) &key->publicKey->buffer;
rsa.d.dmax = 0;
rsa.d.d = NULL;
- if (DCRYPTO_rsa_encrypt(&rsa, out, out_len, in, in_len, padding,
- hashing, label))
+ result = DCRYPTO_rsa_encrypt(&rsa, out, out_len, in, in_len, padding,
+ hashing, label);
+
+ reverse_tpm2b(key->publicKey);
+
+ if (result)
return CRYPT_SUCCESS;
else
return CRYPT_FAIL;
@@ -98,20 +109,29 @@ CRYPT_RESULT _cpri__DecryptRSA(uint32_t *out_len, uint8_t *out,
struct RSA rsa;
enum padding_mode padding;
enum hashing_mode hashing;
+ int result;
if (!check_key(key))
return CRYPT_FAIL;
if (!check_encrypt_params(padding_alg, hash_alg, &padding, &hashing))
return CRYPT_FAIL;
+ reverse_tpm2b(key->publicKey);
+ reverse_tpm2b(key->privateKey);
+
rsa.e = key->exponent;
rsa.N.dmax = key->publicKey->size / sizeof(uint32_t);
rsa.N.d = (struct access_helper *) &key->publicKey->buffer;
rsa.d.dmax = key->privateKey->size / sizeof(uint32_t);
rsa.d.d = (struct access_helper *) &key->privateKey->buffer;
- if (DCRYPTO_rsa_decrypt(&rsa, out, out_len, in, in_len, padding,
- hashing, label))
+ result = DCRYPTO_rsa_decrypt(&rsa, out, out_len, in, in_len, padding,
+ hashing, label);
+
+ reverse_tpm2b(key->publicKey);
+ reverse_tpm2b(key->privateKey);
+
+ if (result)
return CRYPT_SUCCESS;
else
return CRYPT_FAIL;
@@ -124,19 +144,29 @@ CRYPT_RESULT _cpri__SignRSA(uint32_t *out_len, uint8_t *out,
struct RSA rsa;
enum padding_mode padding;
enum hashing_mode hashing;
+ int result;
if (!check_key(key))
return CRYPT_FAIL;
if (!check_sign_params(padding_alg, hash_alg, &padding, &hashing))
return CRYPT_FAIL;
+ reverse_tpm2b(key->publicKey);
+ reverse_tpm2b(key->privateKey);
+
rsa.e = key->exponent;
rsa.N.dmax = key->publicKey->size / sizeof(uint32_t);
rsa.N.d = (struct access_helper *) &key->publicKey->buffer;
rsa.d.dmax = key->privateKey->size / sizeof(uint32_t);
rsa.d.d = (struct access_helper *) &key->privateKey->buffer;
- if (DCRYPTO_rsa_sign(&rsa, out, out_len, in, in_len, padding, hashing))
+ result = DCRYPTO_rsa_sign(&rsa, out, out_len, in, in_len,
+ padding, hashing);
+
+ reverse_tpm2b(key->publicKey);
+ reverse_tpm2b(key->privateKey);
+
+ if (result)
return CRYPT_SUCCESS;
else
return CRYPT_FAIL;
@@ -150,20 +180,27 @@ CRYPT_RESULT _cpri__ValidateSignatureRSA(
struct RSA rsa;
enum padding_mode padding;
enum hashing_mode hashing;
+ int result;
if (!check_key(key))
return CRYPT_FAIL;
if (!check_sign_params(padding_alg, hash_alg, &padding, &hashing))
return CRYPT_FAIL;
+ reverse_tpm2b(key->publicKey);
+
rsa.e = key->exponent;
rsa.N.dmax = key->publicKey->size / sizeof(uint32_t);
rsa.N.d = (struct access_helper *) &key->publicKey->buffer;
rsa.d.dmax = 0;
rsa.d.d = NULL;
- if (DCRYPTO_rsa_verify(&rsa, digest, digest_len, sig, sig_len,
- padding, hashing))
+ result = DCRYPTO_rsa_verify(&rsa, digest, digest_len, sig, sig_len,
+ padding, hashing);
+
+ reverse_tpm2b(key->publicKey);
+
+ if (result)
return CRYPT_SUCCESS;
else
return CRYPT_FAIL;
@@ -183,123 +220,116 @@ enum {
static const TPM2B_PUBLIC_KEY_RSA RSA_768_N = {
.t = {96, {
- 0x69, 0x85, 0x39, 0x2d, 0x78, 0x2b, 0x90, 0x75,
- 0xe1, 0x7c, 0xc1, 0x7b, 0xbd, 0x5b, 0xdd, 0xfd,
- 0x00, 0x36, 0xf7, 0x38, 0x74, 0x33, 0x2b, 0xa8,
- 0x53, 0x89, 0x10, 0xa7, 0x2d, 0x3c, 0xe6, 0x00,
- 0xa3, 0xe5, 0x8b, 0x5f, 0xed, 0x77, 0x32, 0xc0,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*) &RSA_768_D.b
-};
-static const RSA_KEY RSA_2048 = {
- 65537, (TPM2B *) &RSA_2048_N.b, (TPM2B *) &RSA_2048_D.b
-};
-
#define MAX_MSG_BYTES RSA_MAX_BYTES
static void rsa_command_handler(void *cmd_body,
@@ -316,7 +346,9 @@ static void rsa_command_handler(void *cmd_body,
uint16_t digest_len;
uint8_t digest[SHA_DIGEST_MAX_BYTES];
uint8_t *out = (uint8_t *) cmd_body;
- RSA_KEY *key;
+ TPM2B_PUBLIC_KEY_RSA N;
+ TPM2B_PUBLIC_KEY_RSA d;
+ RSA_KEY key;
uint32_t *response_size = (uint32_t *) response_size_out;
assert(sizeof(size_t) == sizeof(uint32_t));
@@ -360,43 +392,49 @@ static void rsa_command_handler(void *cmd_body,
memcpy(digest, cmd, digest_len);
}
+ /* Make copies of N, and d, as const data is immutable. */
switch (key_len) {
case 768:
- key = (RSA_KEY *) &RSA_768;
+ N = RSA_768_N;
+ d = RSA_768_D;
break;
case 2048:
- key = (RSA_KEY *) &RSA_2048;
+ N = RSA_2048_N;
+ d = RSA_2048_D;
break;
default:
*response_size = 0;
return;
}
+ key.exponent = 65537;
+ key.publicKey = &N.b;
+ key.privateKey = &d.b;
switch (op) {
case TEST_RSA_ENCRYPT:
if (_cpri__EncryptRSA(
- response_size, out, key,
+ response_size, out, &key,
padding_alg, in_len, in, hashing_alg, "")
!= CRYPT_SUCCESS)
*response_size = 0;
return;
case TEST_RSA_DECRYPT:
if (_cpri__DecryptRSA(
- response_size, out, key,
+ response_size, out, &key,
padding_alg, in_len, in, hashing_alg, "")
!= CRYPT_SUCCESS)
*response_size = 0;
return;
case TEST_RSA_SIGN:
if (_cpri__SignRSA(
- response_size, out, key,
+ response_size, out, &key,
padding_alg, hashing_alg, in_len, in)
!= CRYPT_SUCCESS)
*response_size = 0;
return;
case TEST_RSA_VERIFY:
if (_cpri__ValidateSignatureRSA(
- key, padding_alg, hashing_alg, digest_len,
+ &key, padding_alg, hashing_alg, digest_len,
digest, in_len, in, 0)
!= CRYPT_SUCCESS) {
*response_size = 0;