Source release 19.2.0

This commit is contained in:
Alex Dale
2024-06-25 14:03:53 -07:00
parent b8bdfccebe
commit cd8256726f
89 changed files with 2747 additions and 35949 deletions

View File

@@ -171,6 +171,104 @@ TEST_P(OEMCryptoEccKeyTest, SerializeAndReloadPublicKey) {
}
}
// Checks that a public and private key can be serialized as a SEC 1
// key point, and that a public key can be reloaded from the key point.
// Uses the default option for point compression.
TEST_P(OEMCryptoEccKeyTest, SerializeAndReloadAsPublicKeySec1KeyPoint) {
auto pub_key = key_->MakePublicKey();
ASSERT_TRUE(pub_key);
const std::vector<uint8_t> key_point_from_priv =
key_->SerializeAsPublicSec1KeyPoint();
ASSERT_FALSE(key_point_from_priv.empty())
<< "Failed to serialize from private key";
const std::vector<uint8_t> key_point_from_pub =
pub_key->SerializeAsSec1KeyPoint();
ASSERT_FALSE(key_point_from_pub.empty())
<< "Failed to serialize from public key";
// Check that both are equal.
EXPECT_EQ(key_point_from_priv, key_point_from_pub);
// Reload new public key from key point data.
auto loaded_key =
EccPublicKey::LoadKeyPoint(key_->curve(), key_point_from_priv);
ASSERT_TRUE(loaded_key) << "Failed to load public key from key point";
const std::vector<uint8_t> key_point_from_loaded =
loaded_key->SerializeAsSec1KeyPoint();
ASSERT_FALSE(key_point_from_loaded.empty())
<< "Failed to serialize from loaded key";
EXPECT_EQ(key_point_from_priv, key_point_from_loaded);
}
// Same as above, except explicitly serializes key point in its
// compressed form.
TEST_P(OEMCryptoEccKeyTest,
SerializeAndReloadAsPublicKeySec1KeyPointCompressed) {
constexpr bool kCompressed = true;
auto pub_key = key_->MakePublicKey();
ASSERT_TRUE(pub_key);
const std::vector<uint8_t> key_point_from_priv =
key_->SerializeAsPublicSec1KeyPoint(kCompressed);
ASSERT_FALSE(key_point_from_priv.empty())
<< "Failed to serialize from private key";
const std::vector<uint8_t> key_point_from_pub =
pub_key->SerializeAsSec1KeyPoint(kCompressed);
ASSERT_FALSE(key_point_from_pub.empty())
<< "Failed to serialize from public key";
// Check that both are equal.
EXPECT_EQ(key_point_from_priv, key_point_from_pub);
// Reload new public key from key point data.
auto loaded_key =
EccPublicKey::LoadKeyPoint(key_->curve(), key_point_from_priv);
ASSERT_TRUE(loaded_key) << "Failed to load public key from key point";
const std::vector<uint8_t> key_point_from_loaded =
loaded_key->SerializeAsSec1KeyPoint(kCompressed);
ASSERT_FALSE(key_point_from_loaded.empty())
<< "Failed to serialize from loaded key";
EXPECT_EQ(key_point_from_priv, key_point_from_loaded);
}
// Same as above, except explicitly serializes key point in its
// uncompressed form.
TEST_P(OEMCryptoEccKeyTest,
SerializeAndReloadAsPublicKeySec1KeyPointUncompressed) {
constexpr bool kUncompressed = false;
auto pub_key = key_->MakePublicKey();
ASSERT_TRUE(pub_key);
const std::vector<uint8_t> key_point_from_priv =
key_->SerializeAsPublicSec1KeyPoint(kUncompressed);
ASSERT_FALSE(key_point_from_priv.empty())
<< "Failed to serialize from private key";
const std::vector<uint8_t> key_point_from_pub =
pub_key->SerializeAsSec1KeyPoint(kUncompressed);
ASSERT_FALSE(key_point_from_pub.empty())
<< "Failed to serialize from public key";
// Check that both are equal.
EXPECT_EQ(key_point_from_priv, key_point_from_pub);
// Reload new public key from key point data.
auto loaded_key =
EccPublicKey::LoadKeyPoint(key_->curve(), key_point_from_priv);
ASSERT_TRUE(loaded_key) << "Failed to load public key from key point";
const std::vector<uint8_t> key_point_from_loaded =
loaded_key->SerializeAsSec1KeyPoint(kUncompressed);
ASSERT_FALSE(key_point_from_loaded.empty())
<< "Failed to serialize from loaded key";
EXPECT_EQ(key_point_from_priv, key_point_from_loaded);
}
// Checks that the ECC signature generating API operates similar to
// existing signature generation functions.
TEST_P(OEMCryptoEccKeyTest, GenerateSignature) {
@@ -194,12 +292,14 @@ TEST_P(OEMCryptoEccKeyTest, GenerateSignature) {
EXPECT_LE(signature_size, key_->SignatureSize());
}
// Checks that ECC signatures can be verified by an ECC public key.
// Checks that ECC signatures (ASN.1 DER encoded ECDSA-Sig-Value) can
// be verified by an ECC public key.
TEST_P(OEMCryptoEccKeyTest, VerifySignature) {
const std::vector<uint8_t> message = RandomData(kMessageSize);
ASSERT_FALSE(message.empty()) << "CdmRandom failed";
const std::vector<uint8_t> signature = key_->GenerateSignature(message);
ASSERT_FALSE(signature.empty());
std::unique_ptr<EccPublicKey> pub_key = key_->MakePublicKey();
ASSERT_TRUE(pub_key);
@@ -217,6 +317,32 @@ TEST_P(OEMCryptoEccKeyTest, VerifySignature) {
pub_key->VerifySignature(message, bad_signature));
}
// Checks that ECC raw signatures (concatinated same-width-big-endian
// encoded signature point values r and s) can be verified by an ECC
// public key.
TEST_P(OEMCryptoEccKeyTest, VerifyRawSignature) {
const std::vector<uint8_t> message = RandomData(kMessageSize);
ASSERT_FALSE(message.empty()) << "CdmRandom failed";
const std::vector<uint8_t> signature = key_->GenerateRawSignature(message);
ASSERT_FALSE(signature.empty());
std::unique_ptr<EccPublicKey> pub_key = key_->MakePublicKey();
ASSERT_TRUE(pub_key);
EXPECT_EQ(OEMCrypto_SUCCESS, pub_key->VerifyRawSignature(message, signature));
// Check with different message.
const std::vector<uint8_t> message_two = RandomData(kMessageSize);
EXPECT_EQ(OEMCrypto_ERROR_SIGNATURE_FAILURE,
pub_key->VerifyRawSignature(message_two, signature));
// Check with bad signature.
const std::vector<uint8_t> bad_signature = RandomData(signature.size());
EXPECT_EQ(OEMCrypto_ERROR_SIGNATURE_FAILURE,
pub_key->VerifyRawSignature(message, bad_signature));
}
// Verifies the session key exchange protocol used by the licensing
// server.
TEST_P(OEMCryptoEccKeyTest, DeriveSessionKey) {