From a1c5f7c006b7bb3d5894f132f70ba3bbadfd9d6b Mon Sep 17 00:00:00 2001 From: Nicolas Boichat Date: Thu, 2 Mar 2017 17:56:46 +0800 Subject: vboot_reference: Add support for 3072-bit exponent 3 keys This also adds the required tests (keys, testcases), and some additional tests in vb2_rsa_utility_tests.c that were not added when 2048-bit exponent 3 support was added. BRANCH=none BUG=chromium:684354 TEST=make runtests Change-Id: I56d22302c2254ef500b9d2d290a79d8c8bc39942 Reviewed-on: https://chromium-review.googlesource.com/449060 Commit-Ready: Nicolas Boichat Tested-by: Nicolas Boichat Reviewed-by: Randall Spangler --- firmware/2lib/2rsa.c | 6 ++++ firmware/2lib/2sha_utility.c | 3 ++ firmware/2lib/include/2crypto.h | 4 +++ host/lib21/host_key.c | 3 ++ tests/common.sh | 2 +- tests/futility/test_rwsig.sh | 2 +- tests/rsa_padding_test.h | 1 + tests/testcases/test_file.rsa3072_exp3_sha1.sig | 3 ++ tests/testcases/test_file.rsa3072_exp3_sha256.sig | 4 +++ tests/testcases/test_file.rsa3072_exp3_sha512.sig | Bin 0 -> 384 bytes tests/testkeys/key_rsa3072_exp3.crt | 26 +++++++++++++++ tests/testkeys/key_rsa3072_exp3.keyb | Bin 0 -> 776 bytes tests/testkeys/key_rsa3072_exp3.pem | 39 ++++++++++++++++++++++ tests/testkeys/key_rsa3072_exp3.sha1.vbprivk | Bin 0 -> 1774 bytes tests/testkeys/key_rsa3072_exp3.sha1.vbpubk | Bin 0 -> 808 bytes tests/testkeys/key_rsa3072_exp3.sha256.vbprivk | Bin 0 -> 1774 bytes tests/testkeys/key_rsa3072_exp3.sha256.vbpubk | Bin 0 -> 808 bytes tests/testkeys/key_rsa3072_exp3.sha512.vbprivk | Bin 0 -> 1774 bytes tests/testkeys/key_rsa3072_exp3.sha512.vbpubk | Bin 0 -> 808 bytes tests/vb2_rsa_utility_tests.c | 10 ++++++ utility/dumpRSAPublicKey.c | 2 +- 21 files changed, 102 insertions(+), 3 deletions(-) create mode 100644 tests/testcases/test_file.rsa3072_exp3_sha1.sig create mode 100644 tests/testcases/test_file.rsa3072_exp3_sha256.sig create mode 100644 tests/testcases/test_file.rsa3072_exp3_sha512.sig create mode 100644 tests/testkeys/key_rsa3072_exp3.crt create mode 100644 tests/testkeys/key_rsa3072_exp3.keyb create mode 100644 tests/testkeys/key_rsa3072_exp3.pem create mode 100644 tests/testkeys/key_rsa3072_exp3.sha1.vbprivk create mode 100644 tests/testkeys/key_rsa3072_exp3.sha1.vbpubk create mode 100644 tests/testkeys/key_rsa3072_exp3.sha256.vbprivk create mode 100644 tests/testkeys/key_rsa3072_exp3.sha256.vbpubk create mode 100644 tests/testkeys/key_rsa3072_exp3.sha512.vbprivk create mode 100644 tests/testkeys/key_rsa3072_exp3.sha512.vbpubk diff --git a/firmware/2lib/2rsa.c b/firmware/2lib/2rsa.c index 48e1ec33..c349d4e2 100644 --- a/firmware/2lib/2rsa.c +++ b/firmware/2lib/2rsa.c @@ -197,6 +197,9 @@ static const uint8_t crypto_to_sig[] = { VB2_SIG_RSA2048_EXP3, VB2_SIG_RSA2048_EXP3, VB2_SIG_RSA2048_EXP3, + VB2_SIG_RSA3072_EXP3, + VB2_SIG_RSA3072_EXP3, + VB2_SIG_RSA3072_EXP3, }; /** @@ -224,6 +227,8 @@ uint32_t vb2_rsa_sig_size(enum vb2_signature_algorithm sig_alg) case VB2_SIG_RSA2048: case VB2_SIG_RSA2048_EXP3: return 2048 / 8; + case VB2_SIG_RSA3072_EXP3: + return 3072 / 8; case VB2_SIG_RSA4096: return 4096 / 8; case VB2_SIG_RSA8192: @@ -248,6 +253,7 @@ static uint32_t vb2_rsa_exponent(enum vb2_signature_algorithm sig_alg) case VB2_SIG_RSA8192: return 65537; case VB2_SIG_RSA2048_EXP3: + case VB2_SIG_RSA3072_EXP3: return 3; default: return 0; diff --git a/firmware/2lib/2sha_utility.c b/firmware/2lib/2sha_utility.c index 7193091b..c45606bb 100644 --- a/firmware/2lib/2sha_utility.c +++ b/firmware/2lib/2sha_utility.c @@ -43,6 +43,9 @@ static const uint8_t crypto_to_hash[] = { CTH_SHA1, CTH_SHA256, CTH_SHA512, + CTH_SHA1, + CTH_SHA256, + CTH_SHA512, }; enum vb2_hash_algorithm vb2_crypto_to_hash(uint32_t algorithm) diff --git a/firmware/2lib/include/2crypto.h b/firmware/2lib/include/2crypto.h index a33b5360..e786614c 100644 --- a/firmware/2lib/include/2crypto.h +++ b/firmware/2lib/include/2crypto.h @@ -26,6 +26,9 @@ enum vb2_crypto_algorithm { VB2_ALG_RSA2048_EXP3_SHA1 = 12, VB2_ALG_RSA2048_EXP3_SHA256 = 13, VB2_ALG_RSA2048_EXP3_SHA512 = 14, + VB2_ALG_RSA3072_EXP3_SHA1 = 15, + VB2_ALG_RSA3072_EXP3_SHA256 = 16, + VB2_ALG_RSA3072_EXP3_SHA512 = 17, /* Number of algorithms */ VB2_ALG_COUNT }; @@ -47,6 +50,7 @@ enum vb2_signature_algorithm { VB2_SIG_RSA4096 = 4, VB2_SIG_RSA8192 = 5, VB2_SIG_RSA2048_EXP3 = 6, + VB2_SIG_RSA3072_EXP3 = 7, /* Last index. Don't add anything below. */ VB2_SIG_ALG_COUNT, diff --git a/host/lib21/host_key.c b/host/lib21/host_key.c index be36df71..4f82d10c 100644 --- a/host/lib21/host_key.c +++ b/host/lib21/host_key.c @@ -24,6 +24,7 @@ const struct vb2_text_vs_enum vb2_text_vs_sig[] = { {"RSA4096", VB2_SIG_RSA4096}, {"RSA8192", VB2_SIG_RSA8192}, {"RSA2048EXP3", VB2_SIG_RSA2048_EXP3}, + {"RSA3072EXP3", VB2_SIG_RSA3072_EXP3}, {0, 0} }; @@ -572,6 +573,8 @@ enum vb2_signature_algorithm vb2_rsa_sig_alg(struct rsa_st *rsa) switch (bits) { case 2048: return VB2_SIG_RSA2048_EXP3; + case 3072: + return VB2_SIG_RSA3072_EXP3; } break; case RSA_F4: diff --git a/tests/common.sh b/tests/common.sh index 78a47fa8..8cc1498d 100644 --- a/tests/common.sh +++ b/tests/common.sh @@ -28,7 +28,7 @@ COL_BLUE='\E[34;1m' COL_STOP='\E[0;m' hash_algos=( sha1 sha256 sha512 ) -key_lengths=( 1024 2048 4096 8192 2048_exp3 ) +key_lengths=( 1024 2048 4096 8192 2048_exp3 3072_exp3 ) function happy { echo -e "${COL_GREEN}$*${COL_STOP}" 1>&2 diff --git a/tests/futility/test_rwsig.sh b/tests/futility/test_rwsig.sh index efdb6dbb..846074d9 100755 --- a/tests/futility/test_rwsig.sh +++ b/tests/futility/test_rwsig.sh @@ -12,7 +12,7 @@ cd "$OUTDIR" DATADIR="${SCRIPTDIR}/data" TESTKEYS=${SRCDIR}/tests/testkeys -SIGS="1024 2048 2048_exp3 4096 8192" +SIGS="1024 2048 2048_exp3 3072_exp3 4096 8192" HASHES="SHA1 SHA256 SHA512" set -o pipefail diff --git a/tests/rsa_padding_test.h b/tests/rsa_padding_test.h index 18bccd8c..bf039f5f 100644 --- a/tests/rsa_padding_test.h +++ b/tests/rsa_padding_test.h @@ -14,6 +14,7 @@ #define RSA1024NUMBYTES 128 /* 1024 bit key length */ #define RSA2048NUMBYTES 256 /* 2048 bit key length */ +#define RSA3072NUMBYTES 384 /* 3072 bit key length */ #define RSA4096NUMBYTES 512 /* 4096 bit key length */ #define RSA8192NUMBYTES 1024 /* 8192 bit key length */ diff --git a/tests/testcases/test_file.rsa3072_exp3_sha1.sig b/tests/testcases/test_file.rsa3072_exp3_sha1.sig new file mode 100644 index 00000000..caac8e9a --- /dev/null +++ b/tests/testcases/test_file.rsa3072_exp3_sha1.sig @@ -0,0 +1,3 @@ +F bdm=%ҟ>/m޺zJ Q5Jq%ӣO_^DrIgY;I{ {Mԛ_Y0sOG@ͫۜIʇ?{YC#\ n.bҩv廎8 4@d7U4q@FϦ,YuzT B ߦ`~Ȍuq{[ ^ +pVQW3e ާ82xZISnJVd%pQ+< D+ .\־҉k%$mS_H/倫:C +J<% ÿս"X?Yup_JSX5pk+>+mAˍ @ \ No newline at end of file diff --git a/tests/testcases/test_file.rsa3072_exp3_sha256.sig b/tests/testcases/test_file.rsa3072_exp3_sha256.sig new file mode 100644 index 00000000..67bb39f4 --- /dev/null +++ b/tests/testcases/test_file.rsa3072_exp3_sha256.sig @@ -0,0 +1,4 @@ +>ȴ5/Т/( O\41~vBGK +kM +B'zrjfQ19ԺQҾYF|ddUJf4nQGa]*/j5/јLAwU:qU3+o,./i_IA&5Վ>JZ#6`|8W]kmlP@M8E/J~HEyPՅ&myw#%Kqbw m