OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef MEDIA_BASE_ENCRYPTION_SCHEME_H_ |
| 6 #define MEDIA_BASE_ENCRYPTION_SCHEME_H_ |
| 7 |
| 8 #include <stdint.h> |
| 9 |
| 10 #include "media/base/media_export.h" |
| 11 |
| 12 namespace media { |
| 13 |
| 14 // Specification of whether and how the stream is encrypted (in whole or part). |
| 15 class MEDIA_EXPORT EncryptionScheme { |
| 16 public: |
| 17 // Algorithm and mode used for encryption. CIPHER_MODE_UNENCRYPTED indicates |
| 18 // no encryption. |
| 19 enum CipherMode { |
| 20 CIPHER_MODE_UNENCRYPTED, |
| 21 CIPHER_MODE_AES_CTR, |
| 22 CIPHER_MODE_AES_CBC, |
| 23 CIPHER_MODE_MAX = CIPHER_MODE_AES_CBC |
| 24 }; |
| 25 |
| 26 // CENC 3rd Edition adds pattern encryption, through two new protection |
| 27 // schemes: 'cens' (with AES-CTR) and 'cbcs' (with AES-CBC). |
| 28 // The pattern applies independently to each 'encrypted' part of the frame (as |
| 29 // defined by the relevant subsample entries), and reduces further the |
| 30 // actual encryption applied through a repeating pattern of (encrypt:skip) |
| 31 // 16 byte blocks. For example, in a (1:9) pattern, the first block is |
| 32 // encrypted, and the next nine are skipped. This pattern is applied |
| 33 // repeatedly until the end of the last 16-byte block in the subsample. |
| 34 // Any remaining bytes are left clear. |
| 35 // If either of encrypt_blocks or skip_blocks is 0, pattern encryption is |
| 36 // disabled. |
| 37 class Pattern { |
| 38 public: |
| 39 Pattern(); |
| 40 Pattern(uint32_t encrypt_blocks, uint32_t skip_blocks); |
| 41 ~Pattern(); |
| 42 |
| 43 bool Matches(const Pattern& other) const; |
| 44 |
| 45 uint32_t encrypt_blocks() const { return encrypt_blocks_; } |
| 46 uint32_t skip_blocks() const { return skip_blocks_; } |
| 47 |
| 48 bool IsInEffect() const; |
| 49 |
| 50 private: |
| 51 uint32_t encrypt_blocks_ = 0; |
| 52 uint32_t skip_blocks_ = 0; |
| 53 |
| 54 // Allow copy and assignment. |
| 55 }; |
| 56 |
| 57 // The default constructor makes an instance that indicates no encryption. |
| 58 EncryptionScheme(); |
| 59 |
| 60 // This constructor allows specification of the cipher mode with no pattern. |
| 61 explicit EncryptionScheme(CipherMode mode); |
| 62 |
| 63 // This constructor allows specification of the cipher mode and the pattern. |
| 64 EncryptionScheme(CipherMode mode, const Pattern& pattern); |
| 65 ~EncryptionScheme(); |
| 66 |
| 67 bool Matches(const EncryptionScheme& other) const; |
| 68 |
| 69 bool is_encrypted() const { return mode_ != CIPHER_MODE_UNENCRYPTED; } |
| 70 CipherMode mode() const { return mode_; } |
| 71 const Pattern& pattern() const { return pattern_; } |
| 72 |
| 73 private: |
| 74 CipherMode mode_ = CIPHER_MODE_UNENCRYPTED; |
| 75 Pattern pattern_; |
| 76 |
| 77 // Allow copy and assignment. |
| 78 }; |
| 79 |
| 80 } // namespace media |
| 81 |
| 82 #endif // MEDIA_BASE_ENCRYPTION_SCHEME_H_ |
OLD | NEW |