Commit ea3b6c19 authored by Chris Mumford's avatar Chris Mumford Committed by Commit Bot

SymmetricKey::GetRawKey/key are now const methods.

instance and should have been const. Making this change also allowed
for several other methods to pass const SymmetricKey pointers where
previously they were non-const.

SymmetricKey: :GetRawKey() and SymmetricKey::key() did not modify the
Change-Id: I937e477f91870a1026c2c0aaf767a2e7d5e0ed42
Reviewed-on: https://chromium-review.googlesource.com/529746Reviewed-by: default avatarAdam Langley <agl@chromium.org>
Reviewed-by: default avatarLuke Halliwell <halliwell@chromium.org>
Reviewed-by: default avatarXiaohan Wang <xhwang@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Chris Mumford <cmumford@chromium.org>
Cr-Commit-Position: refs/heads/master@{#478693}
parent 049b2a86
...@@ -75,7 +75,7 @@ std::unique_ptr<crypto::SymmetricKey> CryptohomeTokenEncryptor::PassphraseToKey( ...@@ -75,7 +75,7 @@ std::unique_ptr<crypto::SymmetricKey> CryptohomeTokenEncryptor::PassphraseToKey(
} }
std::string CryptohomeTokenEncryptor::EncryptTokenWithKey( std::string CryptohomeTokenEncryptor::EncryptTokenWithKey(
crypto::SymmetricKey* key, const crypto::SymmetricKey* key,
const std::string& salt, const std::string& salt,
const std::string& token) { const std::string& token) {
crypto::Encryptor encryptor; crypto::Encryptor encryptor;
...@@ -97,7 +97,7 @@ std::string CryptohomeTokenEncryptor::EncryptTokenWithKey( ...@@ -97,7 +97,7 @@ std::string CryptohomeTokenEncryptor::EncryptTokenWithKey(
} }
std::string CryptohomeTokenEncryptor::DecryptTokenWithKey( std::string CryptohomeTokenEncryptor::DecryptTokenWithKey(
crypto::SymmetricKey* key, const crypto::SymmetricKey* key,
const std::string& salt, const std::string& salt,
const std::string& encrypted_token_hex) { const std::string& encrypted_token_hex) {
std::vector<uint8_t> encrypted_token_bytes; std::vector<uint8_t> encrypted_token_bytes;
......
...@@ -52,12 +52,12 @@ class CryptohomeTokenEncryptor : public TokenEncryptor { ...@@ -52,12 +52,12 @@ class CryptohomeTokenEncryptor : public TokenEncryptor {
const std::string& salt); const std::string& salt);
// Encrypts (AES) the token given |key| and |salt|. // Encrypts (AES) the token given |key| and |salt|.
std::string EncryptTokenWithKey(crypto::SymmetricKey* key, std::string EncryptTokenWithKey(const crypto::SymmetricKey* key,
const std::string& salt, const std::string& salt,
const std::string& token); const std::string& token);
// Decrypts (AES) hex encoded encrypted token given |key| and |salt|. // Decrypts (AES) hex encoded encrypted token given |key| and |salt|.
std::string DecryptTokenWithKey(crypto::SymmetricKey* key, std::string DecryptTokenWithKey(const crypto::SymmetricKey* key,
const std::string& salt, const std::string& salt,
const std::string& encrypted_token_hex); const std::string& encrypted_token_hex);
......
...@@ -20,7 +20,7 @@ namespace chromecast { ...@@ -20,7 +20,7 @@ namespace chromecast {
namespace media { namespace media {
DecryptContextImplClearKey::DecryptContextImplClearKey( DecryptContextImplClearKey::DecryptContextImplClearKey(
crypto::SymmetricKey* key) const crypto::SymmetricKey* key)
: DecryptContextImpl(KEY_SYSTEM_CLEAR_KEY), key_(key) { : DecryptContextImpl(KEY_SYSTEM_CLEAR_KEY), key_(key) {
CHECK(key); CHECK(key);
} }
......
...@@ -22,7 +22,7 @@ namespace media { ...@@ -22,7 +22,7 @@ namespace media {
class DecryptContextImplClearKey : public DecryptContextImpl { class DecryptContextImplClearKey : public DecryptContextImpl {
public: public:
// Note: DecryptContextClearKey does not take ownership of |key|. // Note: DecryptContextClearKey does not take ownership of |key|.
explicit DecryptContextImplClearKey(crypto::SymmetricKey* key); explicit DecryptContextImplClearKey(const crypto::SymmetricKey* key);
~DecryptContextImplClearKey() override; ~DecryptContextImplClearKey() override;
// DecryptContextImpl implementation. // DecryptContextImpl implementation.
...@@ -37,7 +37,7 @@ class DecryptContextImplClearKey : public DecryptContextImpl { ...@@ -37,7 +37,7 @@ class DecryptContextImplClearKey : public DecryptContextImpl {
bool DoDecrypt(CastDecoderBuffer* buffer, bool DoDecrypt(CastDecoderBuffer* buffer,
uint8_t* output, uint8_t* output,
size_t data_offset); size_t data_offset);
crypto::SymmetricKey* const key_; const crypto::SymmetricKey* const key_;
DISALLOW_COPY_AND_ASSIGN(DecryptContextImplClearKey); DISALLOW_COPY_AND_ASSIGN(DecryptContextImplClearKey);
}; };
......
...@@ -19,7 +19,7 @@ namespace crypto { ...@@ -19,7 +19,7 @@ namespace crypto {
namespace { namespace {
const EVP_CIPHER* GetCipherForKey(SymmetricKey* key) { const EVP_CIPHER* GetCipherForKey(const SymmetricKey* key) {
switch (key->key().length()) { switch (key->key().length()) {
case 16: return EVP_aes_128_cbc(); case 16: return EVP_aes_128_cbc();
case 32: return EVP_aes_256_cbc(); case 32: return EVP_aes_256_cbc();
...@@ -90,7 +90,7 @@ Encryptor::Encryptor() : key_(nullptr), mode_(CBC) {} ...@@ -90,7 +90,7 @@ Encryptor::Encryptor() : key_(nullptr), mode_(CBC) {}
Encryptor::~Encryptor() { Encryptor::~Encryptor() {
} }
bool Encryptor::Init(SymmetricKey* key, bool Encryptor::Init(const SymmetricKey* key,
Mode mode, Mode mode,
const base::StringPiece& iv) { const base::StringPiece& iv) {
DCHECK(key); DCHECK(key);
......
...@@ -58,7 +58,7 @@ class CRYPTO_EXPORT Encryptor { ...@@ -58,7 +58,7 @@ class CRYPTO_EXPORT Encryptor {
// //
// If |mode| is CBC, |iv| must not be empty; if it is CTR, then |iv| must be // If |mode| is CBC, |iv| must not be empty; if it is CTR, then |iv| must be
// empty. // empty.
bool Init(SymmetricKey* key, Mode mode, const base::StringPiece& iv); bool Init(const SymmetricKey* key, Mode mode, const base::StringPiece& iv);
// Encrypts |plaintext| into |ciphertext|. |plaintext| may only be empty if // Encrypts |plaintext| into |ciphertext|. |plaintext| may only be empty if
// the mode is CBC. // the mode is CBC.
...@@ -84,7 +84,7 @@ class CRYPTO_EXPORT Encryptor { ...@@ -84,7 +84,7 @@ class CRYPTO_EXPORT Encryptor {
// TODO(albertb): Support streaming encryption. // TODO(albertb): Support streaming encryption.
private: private:
SymmetricKey* key_; const SymmetricKey* key_;
Mode mode_; Mode mode_;
std::unique_ptr<Counter> counter_; std::unique_ptr<Counter> counter_;
......
...@@ -49,7 +49,7 @@ bool HMAC::Init(const unsigned char* key, size_t key_length) { ...@@ -49,7 +49,7 @@ bool HMAC::Init(const unsigned char* key, size_t key_length) {
return true; return true;
} }
bool HMAC::Init(SymmetricKey* key) { bool HMAC::Init(const SymmetricKey* key) {
std::string raw_key; std::string raw_key;
bool result = key->GetRawKey(&raw_key) && Init(raw_key); bool result = key->GetRawKey(&raw_key) && Init(raw_key);
// Zero out key copy. This might get optimized away, but one can hope. // Zero out key copy. This might get optimized away, but one can hope.
......
...@@ -53,7 +53,7 @@ class CRYPTO_EXPORT HMAC { ...@@ -53,7 +53,7 @@ class CRYPTO_EXPORT HMAC {
// Initializes this instance using |key|. Call Init // Initializes this instance using |key|. Call Init
// only once. It returns false on the second or later calls. // only once. It returns false on the second or later calls.
bool Init(SymmetricKey* key) WARN_UNUSED_RESULT; bool Init(const SymmetricKey* key) WARN_UNUSED_RESULT;
// Initializes this instance using |key|. Call Init only once. It returns // Initializes this instance using |key|. Call Init only once. It returns
// false on the second or later calls. // false on the second or later calls.
......
...@@ -100,7 +100,7 @@ std::unique_ptr<SymmetricKey> SymmetricKey::Import(Algorithm algorithm, ...@@ -100,7 +100,7 @@ std::unique_ptr<SymmetricKey> SymmetricKey::Import(Algorithm algorithm,
return key; return key;
} }
bool SymmetricKey::GetRawKey(std::string* raw_key) { bool SymmetricKey::GetRawKey(std::string* raw_key) const {
*raw_key = key_; *raw_key = key_;
return true; return true;
} }
......
...@@ -55,12 +55,12 @@ class CRYPTO_EXPORT SymmetricKey { ...@@ -55,12 +55,12 @@ class CRYPTO_EXPORT SymmetricKey {
static std::unique_ptr<SymmetricKey> Import(Algorithm algorithm, static std::unique_ptr<SymmetricKey> Import(Algorithm algorithm,
const std::string& raw_key); const std::string& raw_key);
const std::string& key() { return key_; } const std::string& key() const { return key_; }
// Extracts the raw key from the platform specific data. // Extracts the raw key from the platform specific data.
// Warning: |raw_key| holds the raw key as bytes and thus must be handled // Warning: |raw_key| holds the raw key as bytes and thus must be handled
// carefully. // carefully.
bool GetRawKey(std::string* raw_key); bool GetRawKey(std::string* raw_key) const;
private: private:
SymmetricKey(); SymmetricKey();
......
...@@ -172,8 +172,9 @@ static void CopySubsamples(const std::vector<SubsampleEntry>& subsamples, ...@@ -172,8 +172,9 @@ static void CopySubsamples(const std::vector<SubsampleEntry>& subsamples,
// Decrypts |input| using |key|. Returns a DecoderBuffer with the decrypted // Decrypts |input| using |key|. Returns a DecoderBuffer with the decrypted
// data if decryption succeeded or NULL if decryption failed. // data if decryption succeeded or NULL if decryption failed.
static scoped_refptr<DecoderBuffer> DecryptData(const DecoderBuffer& input, static scoped_refptr<DecoderBuffer> DecryptData(
crypto::SymmetricKey* key) { const DecoderBuffer& input,
const crypto::SymmetricKey* key) {
CHECK(input.data_size()); CHECK(input.data_size());
CHECK(input.decrypt_config()); CHECK(input.decrypt_config());
CHECK(key); CHECK(key);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment