(1) Change wv_cas_ecm to allow 16 bytes of content_iv
(2) Remove "wrapping_iv" parameters from wv_cas_ecm (3) Internally derive "wrapping_iv"s and "key_id"s (4) Add an example binary for demo the usage of wv_cas_ecm ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=218209010
This commit is contained in:
@@ -30,6 +30,9 @@ const size_t kSigningKeySizeBytes = 32;
|
||||
const char kIvMasterKey[] = "1234567890123456";
|
||||
const char kIvLabel[] = "IV_ENCRYPTION";
|
||||
const int kIvSizeBits = 128;
|
||||
const char kKeyIdMasterKey[] = "0123456789abcdef";
|
||||
const char kKeyIdLabel[] = "KEY_ID_ENCRYPTION";
|
||||
const int kKeyIdSizeBits = 128;
|
||||
const char kGroupKeyLabel[] = "GROUP_ENCRYPTION";
|
||||
// TODO(user): This is a temporary key for development. Replace this with
|
||||
// a real group master key in keystore.
|
||||
@@ -137,6 +140,11 @@ std::string DeriveIv(absl::string_view context) {
|
||||
return DeriveKey(kIvMasterKey, kIvLabel, context, kIvSizeBits);
|
||||
}
|
||||
|
||||
// Derives a key ID from the provided info.
|
||||
std::string DeriveKeyId(absl::string_view context) {
|
||||
return DeriveKey(kKeyIdMasterKey, kKeyIdLabel, context, kKeyIdSizeBits);
|
||||
}
|
||||
|
||||
std::string DeriveGroupSessionKey(absl::string_view context,
|
||||
const uint32_t size_bits) {
|
||||
return DeriveKey(kPhonyGroupMasterKey, kGroupKeyLabel, context, size_bits);
|
||||
|
||||
@@ -49,6 +49,9 @@ std::string DeriveKey(absl::string_view key, absl::string_view label,
|
||||
// Derives an IV from the provided |context|.
|
||||
std::string DeriveIv(absl::string_view context);
|
||||
|
||||
// Derives a key ID from the provided |context|.
|
||||
std::string DeriveKeyId(absl::string_view context);
|
||||
|
||||
// Helper function to derive a key using the group master key and context.
|
||||
std::string DeriveGroupSessionKey(absl::string_view context, const uint32_t size_bits);
|
||||
|
||||
|
||||
@@ -198,6 +198,21 @@ TEST(CryptoUtilTest, DeriveIv) {
|
||||
}
|
||||
}
|
||||
|
||||
TEST(CryptoUtilTest, DeriveKeyId) {
|
||||
// First value in the pair is the context, second value is the expected id.
|
||||
std::pair<std::string, std::string> context_id_pairs[] = {
|
||||
{"1234567890123456", "a3c4a8c0d0e24e96f38f492254186a9d"},
|
||||
{"0987654321098765", "084fc6bece9688ccce6b1672d9b47e22"}};
|
||||
for (const auto& context_id_pair : context_id_pairs) {
|
||||
SCOPED_TRACE(absl::StrCat("test case:", context_id_pair.first));
|
||||
EXPECT_EQ(context_id_pair.second,
|
||||
absl::BytesToHexString(DeriveKeyId(context_id_pair.first)));
|
||||
// Repeat same call to verify derivied result is repeatable.
|
||||
EXPECT_EQ(context_id_pair.second,
|
||||
absl::BytesToHexString(DeriveKeyId(context_id_pair.first)));
|
||||
}
|
||||
}
|
||||
|
||||
TEST(CryptoUtilTest, Verify4CCEncryptionIDFromBadString) {
|
||||
uint32_t cc_code;
|
||||
ASSERT_FALSE(FourCCEncryptionSchemeIDFromString("garbage", &cc_code));
|
||||
|
||||
Reference in New Issue
Block a user