Add a few more checks for "key length" and "iv length".

-------------
Pad key value when crypto_mode is DVB_CSA, so that the key length is always 16 bytes.

-------------
Minor comment and example code update.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=219860612
This commit is contained in:
Widevine Buildbot
2018-11-02 21:27:16 +00:00
parent a30ffdd7c6
commit 477f9fb642
3 changed files with 5 additions and 4 deletions

View File

@@ -14,12 +14,13 @@
#include "media_cas_packager_sdk/public/wv_cas_ecm.h"
#include "media_cas_packager_sdk/public/wv_cas_types.h"
const int kContentIvSize = 16;
const bool kKeyRotationEnabled = true;
const char kEvenKey[] = "even_content_key"; // 16 bytes
const char kCsaEvenKey[] = "12345678"; // 8 bytes
const char kEvenContentIv8Bytes[] = "evencont"; // 8 bytes
const char kEvenContentIv16Bytes[] = "evencontevencont"; // 16 bytes
const char kOddKey[] = "odd_content_key."; // 16 bytes
const char kCsaOddKey[] = "87654321"; // 8 bytes
const char kOddContentIv8Bytes[] = "oddcont."; // 8 bytes
const char kOddContentIv16Bytes[] = "oddcont.oddcont."; // 16 bytes
const char kEntitlementKeyId[] = "ent_key_id......"; // 16 bytes
@@ -28,7 +29,7 @@ const char kEntitlementKey[] = "entitlement_key................."; // 32 bytes
int main(int argc, char **argv) {
widevine::cas::WvCasEcm wv_cas_ecm;
widevine::cas::WvCasStatus status =
wv_cas_ecm.Initialize(kContentIvSize, kKeyRotationEnabled,
wv_cas_ecm.Initialize(/* content_iv_size= */ 8, kKeyRotationEnabled,
widevine::cas::CryptoMode::kDvbCsa);
if (status != widevine::cas::OK) {
std::cerr << "Failed to initialize WV CAS ECM, error: "
@@ -36,8 +37,8 @@ int main(int argc, char **argv) {
<< std::endl;
}
std::string ecm;
status = wv_cas_ecm.GenerateEcm(kEvenKey, kEvenContentIv16Bytes, kOddKey,
kOddContentIv16Bytes, kEntitlementKeyId,
status = wv_cas_ecm.GenerateEcm(kCsaEvenKey, kEvenContentIv8Bytes, kCsaOddKey,
kOddContentIv8Bytes, kEntitlementKeyId,
kEntitlementKey, &ecm);
if (status != widevine::cas::OK) {
std::cerr << "Failed to generate WV CAS ECM, error: "