#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "chrome/browser/enterprise/connectors/device_trust/attestation/browser/crypto_utility.h"
#include "base/containers/span.h"
#include "base/logging.h"
#include "base/strings/string_util.h"
#include "crypto/encryptor.h"
#include "crypto/random.h"
#include "crypto/signature_verifier.h"
#include "crypto/symmetric_key.h"
#include "third_party/boringssl/src/include/openssl/bn.h"
#include "third_party/boringssl/src/include/openssl/bytestring.h"
#include "third_party/boringssl/src/include/openssl/evp.h"
#include "third_party/boringssl/src/include/openssl/hmac.h"
#include "third_party/boringssl/src/include/openssl/mem.h"
#include "third_party/boringssl/src/include/openssl/rsa.h"
#include "third_party/boringssl/src/include/openssl/sha.h"
namespace enterprise_connectors {
namespace CryptoUtility {
namespace {
const unsigned int kWellKnownExponent = …;
const size_t kAesKeySizeBits = …;
const size_t kAesBlockSize = …;
const unsigned char* StringAsConstOpenSSLBuffer(const std::string& s) { … }
unsigned char* StringAsOpenSSLBuffer(std::string* s) { … }
}
bssl::UniquePtr<RSA> GetRSA(const std::string& public_key_modulus_hex) { … }
bool CreatePubKeyFromHex(const std::string& public_key_modulus_hex,
std::vector<uint8_t>& public_key_info) { … }
bool VerifySignatureUsingHexKey(const std::string& public_key_modulus_hex,
const std::string& data,
const std::string& signature) { … }
std::string HmacSha512(const std::string& key, const std::string& data) { … }
bool EncryptWithSeed(const std::string& data,
EncryptedData* encrypted,
std::string& key) { … }
bool WrapKeyOAEP(const std::string& key,
RSA* wrapping_key,
const std::string& wrapping_key_id,
EncryptedData* output) { … }
}
}