#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include <stddef.h>
#include <stdint.h>
#include <string.h>
#include <array>
#include <memory>
#include "base/check_op.h"
#include "base/containers/span.h"
#include "base/numerics/safe_conversions.h"
#include "base/numerics/safe_math.h"
#include "components/webcrypto/algorithms/aes.h"
#include "components/webcrypto/algorithms/util.h"
#include "components/webcrypto/blink_key_handle.h"
#include "components/webcrypto/status.h"
#include "crypto/openssl_util.h"
#include "third_party/abseil-cpp/absl/numeric/int128.h"
#include "third_party/blink/public/platform/web_crypto_algorithm_params.h"
#include "third_party/boringssl/src/include/openssl/aes.h"
#include "third_party/boringssl/src/include/openssl/cipher.h"
namespace webcrypto {
namespace {
const EVP_CIPHER* GetAESCipherByKeyLength(size_t key_length_bytes) { … }
Status AesCtrEncrypt128BitCounter(const EVP_CIPHER* cipher,
base::span<const uint8_t> raw_key,
base::span<const uint8_t> input,
base::span<const uint8_t, 16> counter,
base::span<uint8_t> output) { … }
template <typename T>
T CeilDiv(T a, T b) { … }
absl::uint128 GetCounter(base::span<const uint8_t, 16> counter_block,
unsigned int counter_length_bits) { … }
std::array<uint8_t, AES_BLOCK_SIZE> BlockWithZeroedCounter(
base::span<const uint8_t, AES_BLOCK_SIZE> counter_block,
unsigned int counter_length_bits) { … }
Status AesCtrEncryptDecrypt(const blink::WebCryptoAlgorithm& algorithm,
const blink::WebCryptoKey& key,
base::span<const uint8_t> data,
std::vector<uint8_t>* buffer) { … }
class AesCtrImplementation : public AesAlgorithm { … };
}
std::unique_ptr<AlgorithmImplementation> CreateAesCtrImplementation() { … }
}