#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "crypto/encryptor.h"
#include <stddef.h>
#include <stdint.h>
#include "base/logging.h"
#include "base/strings/string_util.h"
#include "crypto/openssl_util.h"
#include "crypto/symmetric_key.h"
#include "third_party/boringssl/src/include/openssl/aes.h"
#include "third_party/boringssl/src/include/openssl/evp.h"
namespace crypto {
namespace {
const EVP_CIPHER* GetCipherForKey(const SymmetricKey* key) { … }
}
Encryptor::Encryptor() : … { … }
Encryptor::~Encryptor() = default;
bool Encryptor::Init(const SymmetricKey* key, Mode mode, std::string_view iv) { … }
bool Encryptor::Init(const SymmetricKey* key,
Mode mode,
base::span<const uint8_t> iv) { … }
bool Encryptor::Encrypt(std::string_view plaintext, std::string* ciphertext) { … }
bool Encryptor::Encrypt(base::span<const uint8_t> plaintext,
std::vector<uint8_t>* ciphertext) { … }
bool Encryptor::Decrypt(std::string_view ciphertext, std::string* plaintext) { … }
bool Encryptor::Decrypt(base::span<const uint8_t> ciphertext,
std::vector<uint8_t>* plaintext) { … }
bool Encryptor::SetCounter(std::string_view counter) { … }
bool Encryptor::SetCounter(base::span<const uint8_t> counter) { … }
bool Encryptor::CryptString(bool do_encrypt,
std::string_view input,
std::string* output) { … }
bool Encryptor::CryptBytes(bool do_encrypt,
base::span<const uint8_t> input,
std::vector<uint8_t>* output) { … }
size_t Encryptor::MaxOutput(bool do_encrypt, size_t length) { … }
std::optional<size_t> Encryptor::Crypt(bool do_encrypt,
base::span<const uint8_t> input,
base::span<uint8_t> output) { … }
std::optional<size_t> Encryptor::CryptCTR(bool do_encrypt,
base::span<const uint8_t> input,
base::span<uint8_t> output) { … }
}