Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(41)

Side by Side Diff: media/crypto/hmac_aes_decryptor.h

Issue 10535029: Add support for encrypted WebM files as defined in the RFC. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Updated encrypted WebM test data. Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2012 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_CRYPTO_HMAC_AES_DECRYPTOR_H_
6 #define MEDIA_CRYPTO_HMAC_AES_DECRYPTOR_H_
7
8 #include <string>
9
10 #include "base/basictypes.h"
11 #include "base/hash_tables.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "media/base/media_export.h"
14 #include "media/crypto/decryptor.h"
15
16 namespace crypto {
17 class SymmetricKey;
18 }
19
20 namespace media {
21
22 class DecoderBuffer;
23
24 // Checks the integrity of the encrypted data and decrypts the AES encrypted
25 // buffer into an unencrypted buffer.
26 class MEDIA_EXPORT HmacAesDecryptor : public Decryptor {
xhwang 2012/06/14 19:42:27 With the new HmacAesDecryptor, we don't need to ke
ddorwin 2012/06/14 21:41:24 I think we should just keep the name AesDecryptor.
fgalligan1 2012/07/03 22:00:15 The media stack cannot create the same CDM for CEN
27 public:
28 // The size is from the WebM encrypted specification. Current WebM
29 // encrypted request for comments specification is here
30 // http://wiki.webmproject.org/encryption/webm-encryption-rfc.
31 static const int kSha1DigestSize = 20;
32 static const char kHmacSeed[];
33 static const char kEncryptionSeed[];
34
35 HmacAesDecryptor();
36 virtual ~HmacAesDecryptor();
37
38 // Decryptor implementation.
39 // Add a |key_id| and |key| pair to the key system. The key is not limited to
40 // a decryption key. It can be any data that the key system accepts, such as
41 // a license. If multiple calls of this function set different keys for the
42 // same |key_id|, the older key will be replaced by the newer key.
43 virtual void AddKey(const uint8* key_id, int key_id_size,
44 const uint8* key, int key_size) OVERRIDE;
45
46 // Check and Decrypt |input| buffer. The |input| should not be NULL.
47 // Return a DecoderBuffer with the decrypted data if the check and
48 // decryption succeeded. Return NULL if check or decryption failed.
49 // TODO(fgalligan): Do we need to differentiate between a check failure
50 // and a decryption failure?
51 virtual scoped_refptr<DecoderBuffer> Decrypt(
52 const scoped_refptr<DecoderBuffer>& input) OVERRIDE;
53
54 private:
55 // Helper class that manages the HMAC and encryption keys.
56 class HmacEncryptionKeys {
57 public:
58 explicit HmacEncryptionKeys(const std::string& secret);
59 ~HmacEncryptionKeys();
60
61 // Creates the HMAC and encryption key.
62 bool Init();
63
64 std::string hmac_key() { return hmac_key_; }
65 crypto::SymmetricKey* encryption_key() { return encryption_key_.get(); }
66
67 private:
68 // The base secret that is used to derive the HMAC and encryption keys.
69 const std::string secret_;
70
71 // The key used to perform the intergrity check.
72 std::string hmac_key_;
73
74 // The key used to decrypt the data.
75 scoped_ptr<crypto::SymmetricKey> encryption_key_;
76 };
77
78 // KeysMap owns the HmacEncryptionKeys* and must delete them when they are
79 // not needed any more.
80 typedef base::hash_map<std::string, HmacEncryptionKeys*> KeysMap;
81 KeysMap keys_map_;
82
83 DISALLOW_COPY_AND_ASSIGN(HmacAesDecryptor);
84 };
85
86 } // namespace media
87
88 #endif // MEDIA_CRYPTO_HMAC_AES_DECRYPTOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698