#include "components/os_crypt/sync/os_crypt.h"
#include <stddef.h>
#include <algorithm>
#include <iterator>
#include <memory>
#include "base/logging.h"
#include "base/memory/singleton.h"
#include "base/metrics/histogram_functions.h"
#include "base/no_destructor.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/synchronization/lock.h"
#include "base/task/single_thread_task_runner.h"
#include "components/os_crypt/sync/key_storage_config_linux.h"
#include "components/os_crypt/sync/key_storage_linux.h"
#include "crypto/encryptor.h"
#include "crypto/symmetric_key.h"
namespace {
constexpr char kSalt[] = …;
constexpr size_t kDerivedKeySizeInBits = …;
constexpr size_t kEncryptionIterations = …;
constexpr size_t kIVBlockSizeAES128 = …;
constexpr char kObfuscationPrefixV10[] = …;
constexpr char kObfuscationPrefixV11[] = …;
constexpr char kMetricDecryptedWithEmptyKey[] = …;
std::unique_ptr<crypto::SymmetricKey> GenerateEncryptionKey(
const std::string& password) { … }
bool DecryptWith(const std::string& ciphertext,
crypto::SymmetricKey* encryption_key,
std::string* plaintext) { … }
}
namespace OSCrypt {
void SetConfig(std::unique_ptr<os_crypt::Config> config) { … }
bool EncryptString16(const std::u16string& plaintext, std::string* ciphertext) { … }
bool DecryptString16(const std::string& ciphertext, std::u16string* plaintext) { … }
bool EncryptString(const std::string& plaintext, std::string* ciphertext) { … }
bool DecryptString(const std::string& ciphertext, std::string* plaintext) { … }
std::string GetRawEncryptionKey() { … }
void SetRawEncryptionKey(const std::string& key) { … }
bool IsEncryptionAvailable() { … }
void UseMockKeyStorageForTesting(
base::OnceCallback<std::unique_ptr<KeyStorageLinux>()>
storage_provider_factory) { … }
void ClearCacheForTesting() { … }
void SetEncryptionPasswordForTesting(const std::string& password) { … }
}
OSCryptImpl* OSCryptImpl::GetInstance() { … }
OSCryptImpl::OSCryptImpl() = default;
OSCryptImpl::~OSCryptImpl() = default;
bool OSCryptImpl::EncryptString16(const std::u16string& plaintext,
std::string* ciphertext) { … }
bool OSCryptImpl::DecryptString16(const std::string& ciphertext,
std::u16string* plaintext) { … }
bool OSCryptImpl::EncryptString(const std::string& plaintext,
std::string* ciphertext) { … }
bool OSCryptImpl::DecryptString(const std::string& ciphertext,
std::string* plaintext) { … }
void OSCryptImpl::SetConfig(std::unique_ptr<os_crypt::Config> config) { … }
bool OSCryptImpl::IsEncryptionAvailable() { … }
void OSCryptImpl::SetRawEncryptionKey(const std::string& raw_key) { … }
std::string OSCryptImpl::GetRawEncryptionKey() { … }
void OSCryptImpl::ClearCacheForTesting() { … }
void OSCryptImpl::UseMockKeyStorageForTesting(
base::OnceCallback<std::unique_ptr<KeyStorageLinux>()>
storage_provider_factory) { … }
void OSCryptImpl::SetEncryptionPasswordForTesting(const std::string& password) { … }
crypto::SymmetricKey* OSCryptImpl::GetPasswordV10() { … }
crypto::SymmetricKey* OSCryptImpl::GetPasswordV11(bool probe) { … }
base::Lock& OSCryptImpl::GetLock() { … }