2013-09-24 01:35:40 +00:00
|
|
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2017-12-20 00:56:36 +00:00
|
|
|
#ifndef PACKAGER_MEDIA_BASE_DECRYPT_CONFIG_H_
|
|
|
|
#define PACKAGER_MEDIA_BASE_DECRYPT_CONFIG_H_
|
2013-09-24 01:35:40 +00:00
|
|
|
|
2014-09-30 23:52:58 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
|
2013-09-24 01:35:40 +00:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2016-08-17 17:41:40 +00:00
|
|
|
#include "packager/base/macros.h"
|
2016-04-08 18:41:17 +00:00
|
|
|
#include "packager/media/base/fourccs.h"
|
2013-09-24 01:35:40 +00:00
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
namespace shaka {
|
2013-09-24 01:35:40 +00:00
|
|
|
namespace media {
|
|
|
|
|
2014-01-24 18:46:46 +00:00
|
|
|
/// The Common Encryption spec provides for subsample encryption, where portions
|
|
|
|
/// of a sample are not encrypted. A SubsampleEntry specifies the number of
|
|
|
|
/// clear and encrypted bytes in each subsample. For decryption, all of the
|
|
|
|
/// encrypted bytes in a sample should be considered a single logical stream,
|
|
|
|
/// regardless of how they are divided into subsamples, and the clear bytes
|
|
|
|
/// should not be considered as part of decryption. This is logically equivalent
|
2014-08-25 22:51:19 +00:00
|
|
|
/// to concatenating all @a cipher_bytes portions of subsamples, decrypting that
|
2014-01-24 18:46:46 +00:00
|
|
|
/// result, and then copying each byte from the decrypted block over the
|
|
|
|
/// corresponding encrypted byte.
|
2013-09-24 01:35:40 +00:00
|
|
|
struct SubsampleEntry {
|
2016-02-03 22:13:57 +00:00
|
|
|
SubsampleEntry()
|
|
|
|
: clear_bytes(0), cipher_bytes(0) {}
|
|
|
|
SubsampleEntry(uint16_t clear_bytes, uint32_t cipher_bytes)
|
|
|
|
: clear_bytes(clear_bytes), cipher_bytes(cipher_bytes) {}
|
|
|
|
|
2014-09-30 21:52:21 +00:00
|
|
|
uint16_t clear_bytes;
|
|
|
|
uint32_t cipher_bytes;
|
2013-09-24 01:35:40 +00:00
|
|
|
};
|
|
|
|
|
2014-01-24 18:46:46 +00:00
|
|
|
/// Contains all the information that a decryptor needs to decrypt a media
|
|
|
|
/// sample.
|
2013-09-24 04:17:12 +00:00
|
|
|
class DecryptConfig {
|
2013-09-24 01:35:40 +00:00
|
|
|
public:
|
2014-01-24 18:46:46 +00:00
|
|
|
/// Keys are always 128 bits.
|
2013-11-27 02:23:30 +00:00
|
|
|
static const size_t kDecryptionKeySize = 16;
|
2013-09-24 01:35:40 +00:00
|
|
|
|
2016-04-08 18:41:17 +00:00
|
|
|
/// Create a 'cenc' decrypt config.
|
2014-01-24 18:46:46 +00:00
|
|
|
/// @param key_id is the ID that references the decryption key.
|
|
|
|
/// @param iv is the initialization vector defined by the encryptor.
|
|
|
|
/// @param subsamples defines the clear and encrypted portions of the sample
|
|
|
|
/// as described in SubsampleEntry. A decrypted buffer will be equal
|
|
|
|
/// in size to the sum of the subsample sizes.
|
2016-04-08 18:41:17 +00:00
|
|
|
DecryptConfig(const std::vector<uint8_t>& key_id,
|
|
|
|
const std::vector<uint8_t>& iv,
|
|
|
|
const std::vector<SubsampleEntry>& subsamples);
|
|
|
|
|
|
|
|
/// Create a general decrypt config with possible pattern-based encryption.
|
|
|
|
/// @param key_id is the ID that references the decryption key.
|
|
|
|
/// @param iv is the initialization vector defined by the encryptor.
|
|
|
|
/// @param subsamples defines the clear and encrypted portions of the sample
|
|
|
|
/// as described in SubsampleEntry. A decrypted buffer will be equal
|
|
|
|
/// in size to the sum of the subsample sizes.
|
|
|
|
/// @param protection_scheme specifies the protection scheme: 'cenc', 'cens',
|
|
|
|
/// 'cbc1', 'cbcs'.
|
2016-04-06 00:28:09 +00:00
|
|
|
/// @param crypt_byte_block indicates number of encrypted blocks (16-byte) in
|
|
|
|
/// pattern based encryption, 'cens' and 'cbcs'. Ignored otherwise.
|
|
|
|
/// @param skip_byte_block indicates number of unencrypted blocks (16-byte)
|
|
|
|
/// in pattern based encryption, 'cens' and 'cbcs'. Ignored otherwise.
|
2014-09-30 21:52:21 +00:00
|
|
|
DecryptConfig(const std::vector<uint8_t>& key_id,
|
|
|
|
const std::vector<uint8_t>& iv,
|
2016-03-17 17:03:19 +00:00
|
|
|
const std::vector<SubsampleEntry>& subsamples,
|
2016-04-06 00:28:09 +00:00
|
|
|
FourCC protection_scheme,
|
|
|
|
uint8_t crypt_byte_block,
|
|
|
|
uint8_t skip_byte_block);
|
2016-04-08 18:41:17 +00:00
|
|
|
|
2013-09-24 01:35:40 +00:00
|
|
|
~DecryptConfig();
|
|
|
|
|
2017-02-02 18:28:29 +00:00
|
|
|
/// @param clear_bytes is the size of clear bytes in the subsample to be
|
|
|
|
/// added.
|
|
|
|
/// @param cipher_bytes is the size of cipher bytes in the subsample to be
|
|
|
|
/// added.
|
|
|
|
void AddSubsample(uint16_t clear_bytes, uint32_t cipher_bytes) {
|
|
|
|
subsamples_.emplace_back(clear_bytes, cipher_bytes);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// @return The total size of subsamples.
|
|
|
|
size_t GetTotalSizeOfSubsamples() const;
|
|
|
|
|
2014-09-30 21:52:21 +00:00
|
|
|
const std::vector<uint8_t>& key_id() const { return key_id_; }
|
|
|
|
const std::vector<uint8_t>& iv() const { return iv_; }
|
2013-09-24 01:35:40 +00:00
|
|
|
const std::vector<SubsampleEntry>& subsamples() const { return subsamples_; }
|
2016-04-08 18:41:17 +00:00
|
|
|
FourCC protection_scheme() const { return protection_scheme_; }
|
2016-04-06 00:28:09 +00:00
|
|
|
uint8_t crypt_byte_block() const { return crypt_byte_block_; }
|
|
|
|
uint8_t skip_byte_block() const { return skip_byte_block_; }
|
2013-09-24 01:35:40 +00:00
|
|
|
|
|
|
|
private:
|
2014-09-30 21:52:21 +00:00
|
|
|
const std::vector<uint8_t> key_id_;
|
2013-09-24 01:35:40 +00:00
|
|
|
|
|
|
|
// Initialization vector.
|
2014-09-30 21:52:21 +00:00
|
|
|
const std::vector<uint8_t> iv_;
|
2013-09-24 01:35:40 +00:00
|
|
|
|
|
|
|
// Subsample information. May be empty for some formats, meaning entire frame
|
|
|
|
// (less data ignored by data_offset_) is encrypted.
|
2017-02-02 18:28:29 +00:00
|
|
|
std::vector<SubsampleEntry> subsamples_;
|
2013-09-24 01:35:40 +00:00
|
|
|
|
2016-04-08 18:41:17 +00:00
|
|
|
const FourCC protection_scheme_;
|
2016-04-06 00:28:09 +00:00
|
|
|
// For pattern-based protection schemes, like CENS and CBCS.
|
|
|
|
const uint8_t crypt_byte_block_;
|
|
|
|
const uint8_t skip_byte_block_;
|
2016-03-17 17:03:19 +00:00
|
|
|
|
2013-09-24 01:35:40 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(DecryptConfig);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace media
|
2016-05-20 21:19:33 +00:00
|
|
|
} // namespace shaka
|
2013-09-24 01:35:40 +00:00
|
|
|
|
2017-12-20 00:56:36 +00:00
|
|
|
#endif // PACKAGER_MEDIA_BASE_DECRYPT_CONFIG_H_
|