Test import of a EC P-521 key.

am: 2bd3e23f3c

Change-Id: I8bb9337a2f8d85f0cddc885b67fd4d388d166077
This commit is contained in:
Shawn Willden 2017-06-22 23:54:31 +00:00 committed by android-build-merger
commit d31b9dffda

View file

@ -247,7 +247,8 @@ string bin2hex(const hidl_vec<uint8_t>& data) {
return retval;
}
string rsa_key = hex2str("30820275020100300d06092a864886f70d01010105000482025f3082025b"
string rsa_key = hex2str(
"30820275020100300d06092a864886f70d01010105000482025f3082025b"
"02010002818100c6095409047d8634812d5a218176e45c41d60a75b13901"
"f234226cffe776521c5a77b9e389417b71c0b6a44d13afe4e4a2805d46c9"
"da2935adb1ff0c1f24ea06e62b20d776430a4d435157233c6f916783c30e"
@ -270,12 +271,24 @@ string rsa_key = hex2str("30820275020100300d06092a864886f70d01010105000482025f30
"d5f33645e8ed8b4a1cb3cc4a1d67987399f2a09f5b3fb68c88d5e5d90ac3"
"3492d6");
string ec_key = hex2str("308187020100301306072a8648ce3d020106082a8648ce3d030107046d30"
string ec_256_key = hex2str(
"308187020100301306072a8648ce3d020106082a8648ce3d030107046d30"
"6b0201010420737c2ecd7b8d1940bf2930aa9b4ed3ff941eed09366bc032"
"99986481f3a4d859a14403420004bf85d7720d07c25461683bc648b4778a"
"9a14dd8a024e3bdd8c7ddd9ab2b528bbc7aa1b51f14ebbbb0bd0ce21bcc4"
"1c6eb00083cf3376d11fd44949e0b2183bfe");
string ec_521_key = hex2str(
"3081EE020100301006072A8648CE3D020106052B810400230481D63081D3"
"02010104420011458C586DB5DAA92AFAB03F4FE46AA9D9C3CE9A9B7A006A"
"8384BEC4C78E8E9D18D7D08B5BCFA0E53C75B064AD51C449BAE0258D54B9"
"4B1E885DED08ED4FB25CE9A1818903818600040149EC11C6DF0FA122C6A9"
"AFD9754A4FA9513A627CA329E349535A5629875A8ADFBE27DCB932C05198"
"6377108D054C28C6F39B6F2C9AF81802F9F326B842FF2E5F3C00AB7635CF"
"B36157FC0882D574A10D839C1A0C049DC5E0D775E2EE50671A208431BB45"
"E78E70BEFE930DB34818EE4D5C26259F5C6B8E28A652950F9F88D7B4B2C9"
"D9");
struct RSA_Delete {
void operator()(RSA* p) { RSA_free(p); }
};
@ -2385,14 +2398,14 @@ TEST_F(ImportKeyTest, RsaPublicExponentMismatch) {
/*
* ImportKeyTest.EcdsaSuccess
*
* Verifies that importing and using an ECDSA key pair works correctly.
* Verifies that importing and using an ECDSA P-256 key pair works correctly.
*/
TEST_F(ImportKeyTest, EcdsaSuccess) {
ASSERT_EQ(ErrorCode::OK, ImportKey(AuthorizationSetBuilder()
.Authorization(TAG_NO_AUTH_REQUIRED)
.EcdsaSigningKey(256)
.Digest(Digest::SHA_2_256),
KeyFormat::PKCS8, ec_key))
KeyFormat::PKCS8, ec_256_key))
<< "(Possibly b/33945114)";
CheckKm0CryptoParam(TAG_ALGORITHM, Algorithm::EC);
@ -2408,6 +2421,32 @@ TEST_F(ImportKeyTest, EcdsaSuccess) {
VerifyMessage(message, signature, params);
}
/*
* ImportKeyTest.Ecdsa521Success
*
* Verifies that importing and using an ECDSA P-521 key pair works correctly.
*/
TEST_F(ImportKeyTest, Ecdsa521Success) {
ASSERT_EQ(ErrorCode::OK, ImportKey(AuthorizationSetBuilder()
.Authorization(TAG_NO_AUTH_REQUIRED)
.EcdsaSigningKey(521)
.Digest(Digest::SHA_2_256),
KeyFormat::PKCS8, ec_521_key))
<< "(Possibly b/33945114)";
CheckKm0CryptoParam(TAG_ALGORITHM, Algorithm::EC);
CheckKm0CryptoParam(TAG_KEY_SIZE, 521U);
CheckKm1CryptoParam(TAG_DIGEST, Digest::SHA_2_256);
CheckKm2CryptoParam(TAG_EC_CURVE, EcCurve::P_521);
CheckOrigin();
string message(32, 'a');
auto params = AuthorizationSetBuilder().Digest(Digest::SHA_2_256);
string signature = SignMessage(message, params);
VerifyMessage(message, signature, params);
}
/*
* ImportKeyTest.EcdsaSizeMismatch
*
@ -2419,7 +2458,7 @@ TEST_F(ImportKeyTest, EcdsaSizeMismatch) {
ImportKey(AuthorizationSetBuilder()
.EcdsaSigningKey(224 /* Doesn't match key */)
.Digest(Digest::NONE),
KeyFormat::PKCS8, ec_key));
KeyFormat::PKCS8, ec_256_key));
}
/*
@ -2438,7 +2477,7 @@ TEST_F(ImportKeyTest, EcdsaCurveMismatch) {
ImportKey(AuthorizationSetBuilder()
.EcdsaSigningKey(EcCurve::P_224 /* Doesn't match key */)
.Digest(Digest::NONE),
KeyFormat::PKCS8, ec_key))
KeyFormat::PKCS8, ec_256_key))
<< "(Possibly b/36233241)";
}