Chromium Code Reviews| 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 namespace media { | |
| 11 | |
| 12 // Specification of whether and how the stream is encrypted (in whole or part). | |
| 13 class EncryptionScheme { | |
| 14 public: | |
| 15 // Algorithm and mode used for encryption. | |
| 16 enum CipherMode { | |
| 17 kCipherModeNone, | |
| 18 kCipherModeAesCtr, | |
| 19 kCipherModeAesCbc, | |
| 20 kCipherModeMax = kCipherModeAesCbc | |
| 21 }; | |
| 22 | |
| 23 // V3 of the CENC standard adds pattern encryption, through two new | |
| 24 // protection schemes 'cens' (with AES-CTR) and 'cbcs' (with AES-CBC). | |
| 25 // The pattern applies only to the 'encrypted' part of the frame (as | |
| 26 // defined by the relevant subsample entries), and reduces further the | |
| 27 // actual encryption applied through a repeating pattern of (encrypt:skip) | |
| 28 // 16 byte blocks. For example, in a (1:9) pattern, the first block is | |
| 29 // encrypted, and the next nine are skipped. This pattern is applied | |
| 30 // repeatedly until the end of the last 16-byte block in the subsample. | |
| 31 // Any remaining bytes are left clear. | |
| 32 // If either or both of encrypt_blocks or skip_blocks is 0, pattern | |
| 33 // encryption is disabled. | |
| 34 class PatternSpec { | |
| 35 public: | |
| 36 PatternSpec(); | |
| 37 PatternSpec(uint32_t encrypt_blocks, uint32_t skip_blocks); | |
| 38 ~PatternSpec(); | |
| 39 | |
| 40 bool Matches(const PatternSpec& other) const; | |
| 41 | |
| 42 uint32_t encrypt_blocks() const { return encrypt_blocks_; } | |
| 43 uint32_t skip_blocks() const { return skip_blocks_; } | |
| 44 | |
| 45 bool IsInEffect() const; | |
| 46 | |
| 47 private: | |
| 48 uint32_t encrypt_blocks_; | |
| 49 uint32_t skip_blocks_; | |
| 50 | |
| 51 // Allow copy and assignment. | |
| 52 }; | |
| 53 | |
| 54 EncryptionScheme(); | |
| 55 explicit EncryptionScheme(bool is_encrypted); | |
|
halliwell
2016/01/13 03:29:42
As mentioned in downstream CLs, I don't like calls
dougsteed
2016/02/09 22:58:54
Following our discussion, I added a static functio
| |
| 56 explicit EncryptionScheme(CipherMode mode); | |
| 57 EncryptionScheme(CipherMode mode, const PatternSpec& pattern); | |
| 58 ~EncryptionScheme(); | |
| 59 | |
| 60 void Initialize(CipherMode mode, const PatternSpec& pattern); | |
| 61 bool Matches(const EncryptionScheme& other) const; | |
| 62 | |
| 63 bool is_encrypted() const; | |
| 64 CipherMode mode() const { return mode_; } | |
| 65 const PatternSpec& pattern() const { return pattern_; } | |
| 66 | |
| 67 private: | |
| 68 CipherMode mode_; | |
| 69 PatternSpec pattern_; | |
| 70 | |
| 71 // Allow copy and assignment. | |
| 72 }; | |
| 73 | |
| 74 } // namespace media | |
| 75 | |
| 76 #endif // MEDIA_BASE_ENCRYPTION_SCHEME_H_ | |
| OLD | NEW |