summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCaveh Jalali <caveh@google.com>2017-08-19 12:25:42 +0800
committerchrome-bot <chrome-bot@chromium.org>2017-08-24 01:25:50 -0700
commita9cbc267362c71005790cf5b7ca6a8f8d864cea0 (patch)
treecf8349b2dff4fa1510bdac07f31772434451bce2
parentb2b3970923b7971acf78b11d5678ddc3a3a23521 (diff)
downloadvboot-a9cbc267362c71005790cf5b7ca6a8f8d864cea0.tar.gz
tests: Add support for exponent 3 keys
BRANCH=none BUG=b:64854892 TEST=make runlongtests Change-Id: I827ce47b68339dc4df7f84b26a0b6643af27037b Signed-off-by: Caveh Jalali <caveh@google.com> Reviewed-on: https://chromium-review.googlesource.com/628176 Commit-Ready: Nicolas Boichat <drinkcat@chromium.org> Tested-by: Nicolas Boichat <drinkcat@chromium.org>
-rw-r--r--host/lib21/host_key.c36
-rw-r--r--host/lib21/include/host_key2.h8
-rw-r--r--tests/vb20_common2_tests.c13
-rw-r--r--tests/vb20_common3_tests.c19
-rw-r--r--tests/vb21_common2_tests.c12
5 files changed, 65 insertions, 23 deletions
diff --git a/host/lib21/host_key.c b/host/lib21/host_key.c
index c0235b3b..2066a223 100644
--- a/host/lib21/host_key.c
+++ b/host/lib21/host_key.c
@@ -49,6 +49,34 @@ const struct vb2_text_vs_enum vb2_text_vs_crypto[] = {
{"RSA8192 SHA1", VB2_ALG_RSA8192_SHA1},
{"RSA8192 SHA256", VB2_ALG_RSA8192_SHA256},
{"RSA8192 SHA512", VB2_ALG_RSA8192_SHA512},
+ {"RSA2048 EXP3 SHA1", VB2_ALG_RSA2048_EXP3_SHA1},
+ {"RSA2048 EXP3 SHA256", VB2_ALG_RSA2048_EXP3_SHA256},
+ {"RSA2048 EXP3 SHA512", VB2_ALG_RSA2048_EXP3_SHA512},
+ {"RSA3072 EXP3 SHA1", VB2_ALG_RSA3072_EXP3_SHA1},
+ {"RSA3072 EXP3 SHA256", VB2_ALG_RSA3072_EXP3_SHA256},
+ {"RSA3072 EXP3 SHA512", VB2_ALG_RSA3072_EXP3_SHA512},
+ {0, 0}
+};
+
+const struct vb2_text_vs_enum vb2_file_vs_crypto[] = {
+ {"rsa1024", VB2_ALG_RSA1024_SHA1},
+ {"rsa1024", VB2_ALG_RSA1024_SHA256},
+ {"rsa1024", VB2_ALG_RSA1024_SHA512},
+ {"rsa2048", VB2_ALG_RSA2048_SHA1},
+ {"rsa2048", VB2_ALG_RSA2048_SHA256},
+ {"rsa2048", VB2_ALG_RSA2048_SHA512},
+ {"rsa4096", VB2_ALG_RSA4096_SHA1},
+ {"rsa4096", VB2_ALG_RSA4096_SHA256},
+ {"rsa4096", VB2_ALG_RSA4096_SHA512},
+ {"rsa8192", VB2_ALG_RSA8192_SHA1},
+ {"rsa8192", VB2_ALG_RSA8192_SHA256},
+ {"rsa8192", VB2_ALG_RSA8192_SHA512},
+ {"rsa2048_exp3", VB2_ALG_RSA2048_EXP3_SHA1},
+ {"rsa2048_exp3", VB2_ALG_RSA2048_EXP3_SHA256},
+ {"rsa2048_exp3", VB2_ALG_RSA2048_EXP3_SHA512},
+ {"rsa3072_exp3", VB2_ALG_RSA3072_EXP3_SHA1},
+ {"rsa3072_exp3", VB2_ALG_RSA3072_EXP3_SHA256},
+ {"rsa3072_exp3", VB2_ALG_RSA3072_EXP3_SHA512},
{0, 0}
};
@@ -88,6 +116,14 @@ const char *vb2_get_crypto_algorithm_name(enum vb2_crypto_algorithm alg)
return entry ? entry->name : VB2_INVALID_ALG_NAME;
}
+const char *vb2_get_crypto_algorithm_file(enum vb2_crypto_algorithm alg)
+{
+ const struct vb2_text_vs_enum *entry =
+ vb2_lookup_by_num(vb2_file_vs_crypto, alg);
+
+ return entry ? entry->name : VB2_INVALID_ALG_NAME;
+}
+
void vb2_private_key_free(struct vb2_private_key *key)
{
if (!key)
diff --git a/host/lib21/include/host_key2.h b/host/lib21/include/host_key2.h
index f786ec9f..5ce41c06 100644
--- a/host/lib21/include/host_key2.h
+++ b/host/lib21/include/host_key2.h
@@ -75,6 +75,14 @@ const char *vb2_get_sig_algorithm_name(enum vb2_signature_algorithm sig_alg);
const char *vb2_get_crypto_algorithm_name(enum vb2_crypto_algorithm alg);
/**
+ * Return the name of a crypto algorithm.
+ *
+ * @param alg Crypto algorithm to look up
+ * @return The corresponding stem filename, or VB2_INVALID_ALG_NAME if no match.
+ */
+const char *vb2_get_crypto_algorithm_file(enum vb2_crypto_algorithm alg);
+
+/**
* Free a private key.
*
* @param key Key containing internal data to free.
diff --git a/tests/vb20_common2_tests.c b/tests/vb20_common2_tests.c
index 61e28d1a..2dea3172 100644
--- a/tests/vb20_common2_tests.c
+++ b/tests/vb20_common2_tests.c
@@ -142,9 +142,6 @@ static void test_verify_data(const struct vb2_packed_key *key1,
int test_algorithm(int key_algorithm, const char *keys_dir)
{
char filename[1024];
- int rsa_bits = 8 * vb2_rsa_sig_size(
- vb2_crypto_to_signature(key_algorithm));
-
struct vb2_private_key *private_key = NULL;
struct vb2_signature *sig = NULL;
struct vb2_packed_key *key1 = NULL;
@@ -154,16 +151,18 @@ int test_algorithm(int key_algorithm, const char *keys_dir)
printf("***Testing algorithm: %s\n",
vb2_get_crypto_algorithm_name(key_algorithm));
- snprintf(filename, sizeof(filename),
- "%s/key_rsa%d.pem", keys_dir, rsa_bits);
+ snprintf(filename, sizeof(filename), "%s/key_%s.pem",
+ keys_dir,
+ vb2_get_crypto_algorithm_file(key_algorithm));
private_key = vb2_read_private_key_pem(filename, key_algorithm);
if (!private_key) {
fprintf(stderr, "Error reading private_key: %s\n", filename);
goto cleanup_algorithm;
}
- snprintf(filename, sizeof(filename),
- "%s/key_rsa%d.keyb", keys_dir, rsa_bits);
+ snprintf(filename, sizeof(filename), "%s/key_%s.keyb",
+ keys_dir,
+ vb2_get_crypto_algorithm_file(key_algorithm));
key1 = vb2_read_packed_keyb(filename, key_algorithm, 1);
if (!key1) {
fprintf(stderr, "Error reading public_key: %s\n", filename);
diff --git a/tests/vb20_common3_tests.c b/tests/vb20_common3_tests.c
index b5ad1ebe..5533124a 100644
--- a/tests/vb20_common3_tests.c
+++ b/tests/vb20_common3_tests.c
@@ -513,10 +513,6 @@ int test_permutation(int signing_key_algorithm, int data_key_algorithm,
const char *keys_dir)
{
char filename[1024];
- int signing_rsa_len = 8 * vb2_rsa_sig_size(
- vb2_crypto_to_signature(signing_key_algorithm));
- int data_rsa_len = 8 * vb2_rsa_sig_size(
- vb2_crypto_to_signature(data_key_algorithm));
int retval = 1;
struct vb2_private_key *signing_private_key = NULL;
@@ -528,8 +524,9 @@ int test_permutation(int signing_key_algorithm, int data_key_algorithm,
printf("***With data key algorithm: %s\n",
vb2_get_crypto_algorithm_name(data_key_algorithm));
- snprintf(filename, sizeof(filename),
- "%s/key_rsa%d.pem", keys_dir, signing_rsa_len);
+ snprintf(filename, sizeof(filename), "%s/key_%s.pem",
+ keys_dir,
+ vb2_get_crypto_algorithm_file(signing_key_algorithm));
signing_private_key =
vb2_read_private_key_pem(filename, signing_key_algorithm);
if (!signing_private_key) {
@@ -538,8 +535,9 @@ int test_permutation(int signing_key_algorithm, int data_key_algorithm,
goto cleanup_permutation;
}
- snprintf(filename, sizeof(filename),
- "%s/key_rsa%d.keyb", keys_dir, signing_rsa_len);
+ snprintf(filename, sizeof(filename), "%s/key_%s.keyb",
+ keys_dir,
+ vb2_get_crypto_algorithm_file(signing_key_algorithm));
signing_public_key =
vb2_read_packed_keyb(filename, signing_key_algorithm, 1);
if (!signing_public_key) {
@@ -548,8 +546,9 @@ int test_permutation(int signing_key_algorithm, int data_key_algorithm,
goto cleanup_permutation;
}
- snprintf(filename, sizeof(filename),
- "%s/key_rsa%d.keyb", keys_dir, data_rsa_len);
+ snprintf(filename, sizeof(filename), "%s/key_%s.keyb",
+ keys_dir,
+ vb2_get_crypto_algorithm_file(data_key_algorithm));
data_public_key =
vb2_read_packed_keyb(filename, data_key_algorithm, 1);
if (!data_public_key) {
diff --git a/tests/vb21_common2_tests.c b/tests/vb21_common2_tests.c
index b121fa5a..7f1aefa2 100644
--- a/tests/vb21_common2_tests.c
+++ b/tests/vb21_common2_tests.c
@@ -239,8 +239,6 @@ static void test_verify_data(const struct vb2_public_key *pubk_orig,
int test_algorithm(int key_algorithm, const char *keys_dir)
{
char filename[1024];
- int rsa_bits = 8 * vb2_rsa_sig_size(
- vb2_crypto_to_signature(key_algorithm));
enum vb2_signature_algorithm sig_alg =
vb2_crypto_to_signature(key_algorithm);
@@ -254,16 +252,18 @@ int test_algorithm(int key_algorithm, const char *keys_dir)
printf("***Testing algorithm: %s\n",
vb2_get_crypto_algorithm_name(key_algorithm));
- snprintf(filename, sizeof(filename),
- "%s/key_rsa%d.pem", keys_dir, rsa_bits);
+ snprintf(filename, sizeof(filename), "%s/key_%s.pem",
+ keys_dir,
+ vb2_get_crypto_algorithm_file(key_algorithm));
TEST_SUCC(vb2_private_key_read_pem(&prik, filename),
"Read private key");
prik->hash_alg = hash_alg;
prik->sig_alg = sig_alg;
vb2_private_key_set_desc(prik, "private key");
- snprintf(filename, sizeof(filename),
- "%s/key_rsa%d.keyb", keys_dir, rsa_bits);
+ snprintf(filename, sizeof(filename), "%s/key_%s.keyb",
+ keys_dir,
+ vb2_get_crypto_algorithm_file(key_algorithm));
TEST_SUCC(vb2_public_key_read_keyb(&pubk, filename),
"Read public key");
pubk->hash_alg = hash_alg;