crypto/symmetric_key: remove
Delete crypto::SymmetricKey and its tests. This change also removes a few remaining includes of its header files. Fixed: 370724578 Change-Id: I9764215c4a27b3f012251b9354dae897dafc0d20 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6397925 Reviewed-by: Haihan Chen <haihan@google.com> Reviewed-by: Fergal Daly <fergal@chromium.org> Commit-Queue: Elly FJ <ellyjones@chromium.org> Cr-Commit-Position: refs/heads/main@{#1438762}
This commit is contained in:
parent
70c60f3967
commit
68001ec8bc
components/enterprise/obfuscation/core
content/browser/cache_storage
crypto
device/fido/mac
@ -17,7 +17,6 @@
|
||||
#include "crypto/aead.h"
|
||||
#include "crypto/hkdf.h"
|
||||
#include "crypto/random.h"
|
||||
#include "crypto/symmetric_key.h"
|
||||
|
||||
namespace enterprise_obfuscation {
|
||||
|
||||
|
@ -48,7 +48,6 @@
|
||||
#include "content/browser/cache_storage/cache_storage_scheduler.h"
|
||||
#include "content/browser/cache_storage/cache_storage_trace_utils.h"
|
||||
#include "content/common/background_fetch/background_fetch_types.h"
|
||||
#include "crypto/symmetric_key.h"
|
||||
#include "net/base/directory_lister.h"
|
||||
#include "net/base/net_errors.h"
|
||||
#include "storage/browser/blob/blob_storage_context.h"
|
||||
@ -58,7 +57,6 @@
|
||||
|
||||
using blink::mojom::CacheStorageError;
|
||||
using blink::mojom::StorageType;
|
||||
using crypto::SymmetricKey;
|
||||
|
||||
namespace content {
|
||||
|
||||
|
@ -44,7 +44,6 @@
|
||||
#include "content/browser/cache_storage/cache_storage_trace_utils.h"
|
||||
#include "content/common/background_fetch/background_fetch_types.h"
|
||||
#include "crypto/hmac.h"
|
||||
#include "crypto/symmetric_key.h"
|
||||
#include "mojo/public/cpp/bindings/remote.h"
|
||||
#include "net/base/completion_repeating_callback.h"
|
||||
#include "net/base/io_buffer.h"
|
||||
|
@ -53,7 +53,6 @@
|
||||
#include "content/public/test/browser_task_environment.h"
|
||||
#include "content/public/test/test_browser_context.h"
|
||||
#include "content/public/test/test_utils.h"
|
||||
#include "crypto/symmetric_key.h"
|
||||
#include "mojo/public/cpp/bindings/remote.h"
|
||||
#include "mojo/public/cpp/bindings/self_owned_receiver.h"
|
||||
#include "mojo/public/cpp/system/data_pipe.h"
|
||||
|
@ -59,8 +59,6 @@ component("crypto") {
|
||||
"signature_verifier.h",
|
||||
"subtle_passkey.cc",
|
||||
"subtle_passkey.h",
|
||||
"symmetric_key.cc",
|
||||
"symmetric_key.h",
|
||||
"unexportable_key.cc",
|
||||
"unexportable_key.h",
|
||||
"unexportable_key_metrics.cc",
|
||||
@ -187,7 +185,6 @@ test("crypto_unittests") {
|
||||
"sha2_unittest.cc",
|
||||
"signature_creator_unittest.cc",
|
||||
"signature_verifier_unittest.cc",
|
||||
"symmetric_key_unittest.cc",
|
||||
"unexportable_key_unittest.cc",
|
||||
]
|
||||
|
||||
|
@ -20,7 +20,6 @@
|
||||
#include "base/stl_util.h"
|
||||
#include "crypto/openssl_util.h"
|
||||
#include "crypto/secure_util.h"
|
||||
#include "crypto/symmetric_key.h"
|
||||
#include "third_party/boringssl/src/include/openssl/hmac.h"
|
||||
|
||||
namespace crypto {
|
||||
@ -55,10 +54,6 @@ bool HMAC::Init(const unsigned char* key, size_t key_length) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool HMAC::Init(const SymmetricKey* key) {
|
||||
return Init(key->key());
|
||||
}
|
||||
|
||||
bool HMAC::Sign(std::string_view data,
|
||||
unsigned char* digest,
|
||||
size_t digest_length) const {
|
||||
|
@ -22,9 +22,6 @@
|
||||
|
||||
namespace crypto {
|
||||
|
||||
// Simplify the interface and reduce includes by abstracting out the internals.
|
||||
class SymmetricKey;
|
||||
|
||||
// TODO(https://issues.chromium.org/issues/374334448): Rework this interface and
|
||||
// delete much of it.
|
||||
class CRYPTO_EXPORT HMAC {
|
||||
@ -59,10 +56,6 @@ class CRYPTO_EXPORT HMAC {
|
||||
// Init() may fail.
|
||||
[[nodiscard]] bool Init(const unsigned char* key, size_t key_length);
|
||||
|
||||
// Initializes this instance using |key|. Call Init
|
||||
// only once. It returns false on the second or later calls.
|
||||
[[nodiscard]] bool Init(const SymmetricKey* key);
|
||||
|
||||
// Initializes this instance using |key|. Call Init only once. It returns
|
||||
// false on the second or later calls.
|
||||
[[nodiscard]] bool Init(std::string_view key) {
|
||||
|
@ -5,9 +5,9 @@
|
||||
#ifndef CRYPTO_KDF_H_
|
||||
#define CRYPTO_KDF_H_
|
||||
|
||||
#include "base/containers/span.h"
|
||||
#include "crypto/crypto_export.h"
|
||||
#include "crypto/subtle_passkey.h"
|
||||
#include "crypto/symmetric_key.h"
|
||||
|
||||
namespace crypto::kdf {
|
||||
|
||||
|
@ -1,64 +0,0 @@
|
||||
// Copyright 2011 The Chromium Authors
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "crypto/symmetric_key.h"
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <utility>
|
||||
|
||||
#include "crypto/openssl_util.h"
|
||||
#include "crypto/random.h"
|
||||
|
||||
namespace crypto {
|
||||
|
||||
namespace {
|
||||
|
||||
bool IsValidKeySize(size_t key_size_in_bytes) {
|
||||
// Nobody should ever be using other symmetric key sizes without consulting
|
||||
// with CRYPTO_OWNERS first, who can modify this check if need be.
|
||||
return key_size_in_bytes == 16 || key_size_in_bytes == 32;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
SymmetricKey::SymmetricKey(base::span<const uint8_t> key_bytes)
|
||||
: key_(base::as_string_view(key_bytes)) {}
|
||||
|
||||
SymmetricKey::SymmetricKey(const SymmetricKey& other) = default;
|
||||
SymmetricKey& SymmetricKey::operator=(const SymmetricKey& other) = default;
|
||||
|
||||
SymmetricKey::~SymmetricKey() {
|
||||
std::fill(key_.begin(), key_.end(), '\0'); // Zero out the confidential key.
|
||||
}
|
||||
|
||||
// static
|
||||
std::unique_ptr<SymmetricKey> SymmetricKey::GenerateRandomKey(
|
||||
Algorithm,
|
||||
size_t key_size_in_bits) {
|
||||
return std::make_unique<SymmetricKey>(RandomKey(key_size_in_bits));
|
||||
}
|
||||
|
||||
// static
|
||||
SymmetricKey SymmetricKey::RandomKey(size_t key_size_in_bits) {
|
||||
CHECK(!(key_size_in_bits % 8));
|
||||
|
||||
const size_t key_size_in_bytes = key_size_in_bits / 8;
|
||||
CHECK(IsValidKeySize(key_size_in_bytes));
|
||||
|
||||
return SymmetricKey(crypto::RandBytesAsVector(key_size_in_bytes));
|
||||
}
|
||||
|
||||
// static
|
||||
std::unique_ptr<SymmetricKey> SymmetricKey::Import(Algorithm,
|
||||
const std::string& raw_key) {
|
||||
if (!IsValidKeySize(raw_key.size())) {
|
||||
return nullptr;
|
||||
}
|
||||
return std::make_unique<SymmetricKey>(base::as_byte_span(raw_key));
|
||||
}
|
||||
|
||||
} // namespace crypto
|
@ -1,73 +0,0 @@
|
||||
// Copyright 2012 The Chromium Authors
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef CRYPTO_SYMMETRIC_KEY_H_
|
||||
#define CRYPTO_SYMMETRIC_KEY_H_
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "base/containers/span.h"
|
||||
#include "build/build_config.h"
|
||||
#include "crypto/crypto_export.h"
|
||||
|
||||
namespace crypto {
|
||||
|
||||
// A SymmetricKey is an array of bytes which is used for symmetric cryptography
|
||||
// (encryption only).
|
||||
//
|
||||
// This whole type is deprecated: prefer to use raw std::array<uint8_t>,
|
||||
// std::vector<uint8_t>, or base::span<uint8_t> instead. This type has no
|
||||
// behavior or particular meaning.
|
||||
//
|
||||
// TODO(https://issues.chromium.org/issues/370724578): get rid of this.
|
||||
class CRYPTO_EXPORT SymmetricKey {
|
||||
public:
|
||||
// Defines the algorithm that a key will be used with.
|
||||
enum Algorithm {
|
||||
AES,
|
||||
};
|
||||
|
||||
SymmetricKey() = delete;
|
||||
|
||||
// Wrap the given span of bytes as a SymmetricKey.
|
||||
explicit SymmetricKey(base::span<const uint8_t> key_bytes);
|
||||
virtual ~SymmetricKey();
|
||||
|
||||
SymmetricKey(const SymmetricKey&);
|
||||
SymmetricKey& operator=(const SymmetricKey&);
|
||||
|
||||
// Generates a random key suitable to be used with |algorithm| and of
|
||||
// |key_size_in_bits| bits. |key_size_in_bits| must be a multiple of 8.
|
||||
//
|
||||
// Deprecated: use the value version below that does not take an algorithm.
|
||||
static std::unique_ptr<SymmetricKey> GenerateRandomKey(
|
||||
Algorithm algorithm,
|
||||
size_t key_size_in_bits);
|
||||
|
||||
static SymmetricKey RandomKey(size_t key_size_in_bits);
|
||||
|
||||
// Imports an array of key bytes in |raw_key|. The raw key must be of a valid
|
||||
// size - see IsValidKeySize() in the source for details, although in general
|
||||
// you should not need to choose key sizes yourself. Returns nullptr if the
|
||||
// key is not of valid size.
|
||||
//
|
||||
// Deprecated: use the regular constructor that accepts a span of bytes, and
|
||||
// validate that the key is of whatever length your client code expects before
|
||||
// doing so.
|
||||
static std::unique_ptr<SymmetricKey> Import(Algorithm algorithm,
|
||||
const std::string& raw_key);
|
||||
|
||||
// Returns the internal key storage.
|
||||
const std::string& key() const { return key_; }
|
||||
|
||||
private:
|
||||
std::string key_;
|
||||
};
|
||||
|
||||
} // namespace crypto
|
||||
|
||||
#endif // CRYPTO_SYMMETRIC_KEY_H_
|
@ -1,39 +0,0 @@
|
||||
// Copyright 2011 The Chromium Authors
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "crypto/symmetric_key.h"
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "base/strings/string_number_conversions.h"
|
||||
#include "base/strings/string_util.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
|
||||
TEST(SymmetricKeyTest, GenerateRandomKey) {
|
||||
std::unique_ptr<crypto::SymmetricKey> key(
|
||||
crypto::SymmetricKey::GenerateRandomKey(crypto::SymmetricKey::AES, 256));
|
||||
ASSERT_TRUE(key);
|
||||
EXPECT_EQ(32U, key->key().size());
|
||||
|
||||
// Do it again and check that the keys are different.
|
||||
// (Note: this has a one-in-10^77 chance of failure!)
|
||||
std::unique_ptr<crypto::SymmetricKey> key2(
|
||||
crypto::SymmetricKey::GenerateRandomKey(crypto::SymmetricKey::AES, 256));
|
||||
ASSERT_TRUE(key2);
|
||||
EXPECT_EQ(32U, key2->key().size());
|
||||
EXPECT_NE(key->key(), key2->key());
|
||||
}
|
||||
|
||||
TEST(SymmetricKeyTest, ImportGeneratedKey) {
|
||||
std::unique_ptr<crypto::SymmetricKey> key1(
|
||||
crypto::SymmetricKey::GenerateRandomKey(crypto::SymmetricKey::AES, 256));
|
||||
ASSERT_TRUE(key1);
|
||||
|
||||
std::unique_ptr<crypto::SymmetricKey> key2(
|
||||
crypto::SymmetricKey::Import(crypto::SymmetricKey::AES, key1->key()));
|
||||
ASSERT_TRUE(key2);
|
||||
|
||||
EXPECT_EQ(key1->key(), key2->key());
|
||||
}
|
@ -18,7 +18,6 @@
|
||||
#include "base/feature_list.h"
|
||||
#include "crypto/aead.h"
|
||||
#include "crypto/hmac.h"
|
||||
#include "crypto/symmetric_key.h"
|
||||
#include "device/fido/features.h"
|
||||
|
||||
namespace device {
|
||||
|
Loading…
x
Reference in New Issue
Block a user