#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "components/webcrypto/algorithms/ec.h"
#include <stddef.h>
#include <string_view>
#include <utility>
#include "base/containers/span.h"
#include "components/webcrypto/algorithms/asymmetric_key_util.h"
#include "components/webcrypto/algorithms/util.h"
#include "components/webcrypto/blink_key_handle.h"
#include "components/webcrypto/generate_key_result.h"
#include "components/webcrypto/jwk.h"
#include "components/webcrypto/status.h"
#include "crypto/openssl_util.h"
#include "third_party/blink/public/platform/web_crypto_algorithm_params.h"
#include "third_party/blink/public/platform/web_crypto_key_algorithm.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/ec.h"
#include "third_party/boringssl/src/include/openssl/ec_key.h"
#include "third_party/boringssl/src/include/openssl/evp.h"
#include "third_party/boringssl/src/include/openssl/mem.h"
namespace webcrypto {
namespace {
Status WebCryptoCurveToNid(blink::WebCryptoNamedCurve named_curve, int* nid) { … }
Status NidToWebCryptoCurve(int nid, blink::WebCryptoNamedCurve* named_curve) { … }
struct JwkCrvMapping { … };
const JwkCrvMapping kJwkCrvMappings[] = …;
Status ReadJwkCrv(const JwkReader& jwk,
blink::WebCryptoNamedCurve* named_curve) { … }
Status WebCryptoCurveToJwkCrv(blink::WebCryptoNamedCurve named_curve,
std::string* jwk_crv) { … }
Status VerifyEcKeyAfterSpkiOrPkcs8Import(
EVP_PKEY* pkey,
blink::WebCryptoNamedCurve expected_named_curve) { … }
Status CreateEC_KEY(blink::WebCryptoNamedCurve named_curve,
bssl::UniquePtr<EC_KEY>* ec) { … }
Status WritePaddedBIGNUM(std::string_view member_name,
const BIGNUM* value,
size_t padded_length,
JwkWriter* jwk) { … }
Status ReadPaddedBIGNUM(const JwkReader& jwk,
std::string_view member_name,
size_t expected_length,
bssl::UniquePtr<BIGNUM>* out) { … }
int GetGroupDegreeInBytes(EC_KEY* ec) { … }
Status GetPublicKey(EC_KEY* ec,
bssl::UniquePtr<BIGNUM>* x,
bssl::UniquePtr<BIGNUM>* y) { … }
blink::WebCryptoAlgorithm SynthesizeImportAlgorithmForClone(
const blink::WebCryptoKeyAlgorithm& algorithm) { … }
}
Status EcAlgorithm::GenerateKey(const blink::WebCryptoAlgorithm& algorithm,
bool extractable,
blink::WebCryptoKeyUsageMask combined_usages,
GenerateKeyResult* result) const { … }
Status EcAlgorithm::ImportKey(blink::WebCryptoKeyFormat format,
base::span<const uint8_t> key_data,
const blink::WebCryptoAlgorithm& algorithm,
bool extractable,
blink::WebCryptoKeyUsageMask usages,
blink::WebCryptoKey* key) const { … }
Status EcAlgorithm::ExportKey(blink::WebCryptoKeyFormat format,
const blink::WebCryptoKey& key,
std::vector<uint8_t>* buffer) const { … }
Status EcAlgorithm::ImportKeyRaw(base::span<const uint8_t> key_data,
const blink::WebCryptoAlgorithm& algorithm,
bool extractable,
blink::WebCryptoKeyUsageMask usages,
blink::WebCryptoKey* key) const { … }
Status EcAlgorithm::ImportKeyPkcs8(base::span<const uint8_t> key_data,
const blink::WebCryptoAlgorithm& algorithm,
bool extractable,
blink::WebCryptoKeyUsageMask usages,
blink::WebCryptoKey* key) const { … }
Status EcAlgorithm::ImportKeySpki(base::span<const uint8_t> key_data,
const blink::WebCryptoAlgorithm& algorithm,
bool extractable,
blink::WebCryptoKeyUsageMask usages,
blink::WebCryptoKey* key) const { … }
Status EcAlgorithm::ImportKeyJwk(base::span<const uint8_t> key_data,
const blink::WebCryptoAlgorithm& algorithm,
bool extractable,
blink::WebCryptoKeyUsageMask usages,
blink::WebCryptoKey* key) const { … }
Status EcAlgorithm::ExportKeyRaw(const blink::WebCryptoKey& key,
std::vector<uint8_t>* buffer) const { … }
Status EcAlgorithm::ExportKeyPkcs8(const blink::WebCryptoKey& key,
std::vector<uint8_t>* buffer) const { … }
Status EcAlgorithm::ExportKeySpki(const blink::WebCryptoKey& key,
std::vector<uint8_t>* buffer) const { … }
Status EcAlgorithm::ExportKeyJwk(const blink::WebCryptoKey& key,
std::vector<uint8_t>* buffer) const { … }
Status EcAlgorithm::DeserializeKeyForClone(
const blink::WebCryptoKeyAlgorithm& algorithm,
blink::WebCryptoKeyType type,
bool extractable,
blink::WebCryptoKeyUsageMask usages,
base::span<const uint8_t> key_data,
blink::WebCryptoKey* key) const { … }
}