/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
import { Diagnostic } from "#log/Diagnostic.js";
import { Logger } from "#log/Logger.js";
import { Bytes } from "#util/Bytes.js";
import * as mod from "@noble/curves/abstract/modular.js";
import { p256 } from "@noble/curves/nist.js";
import * as utils from "@noble/curves/utils.js";
import { Entropy } from "../util/Entropy.js";
const ec = {
  p256,
  ...utils,
  ...mod
};
const CRYPTO_ENCRYPT_ALGORITHM = "aes-128-ccm";
const CRYPTO_HASH_ALGORITHM = "sha256";
const CRYPTO_EC_CURVE = "prime256v1";
const CRYPTO_EC_KEY_BYTES = 32;
const CRYPTO_AUTH_TAG_LENGTH = 16;
const CRYPTO_SYMMETRIC_KEY_LENGTH = 16;
const HASH_ALGORITHM_OUTPUT_LENGTHS = {
  "SHA-256": 32,
  "SHA-512": 64,
  "SHA-384": 48,
  "SHA-512/224": 28,
  "SHA-512/256": 32,
  "SHA3-256": 32
};
var HashFipsAlgorithmId = /* @__PURE__ */ ((HashFipsAlgorithmId2) => {
  HashFipsAlgorithmId2[HashFipsAlgorithmId2["SHA-256"] = 1] = "SHA-256";
  HashFipsAlgorithmId2[HashFipsAlgorithmId2["SHA-512"] = 7] = "SHA-512";
  HashFipsAlgorithmId2[HashFipsAlgorithmId2["SHA-384"] = 8] = "SHA-384";
  HashFipsAlgorithmId2[HashFipsAlgorithmId2["SHA-512/224"] = 10] = "SHA-512/224";
  HashFipsAlgorithmId2[HashFipsAlgorithmId2["SHA-512/256"] = 11] = "SHA-512/256";
  HashFipsAlgorithmId2[HashFipsAlgorithmId2["SHA3-256"] = 12] = "SHA3-256";
  return HashFipsAlgorithmId2;
})(HashFipsAlgorithmId || {});
const logger = Logger.get("Crypto");
class Crypto extends Entropy {
  /**
   * Add two EC points on the P-256 curve.
   *
   * @param a - 65-byte uncompressed EC point (04 || x || y)
   * @param b - 65-byte uncompressed EC point (04 || x || y)
   * @returns 65-byte uncompressed EC point
   */
  ecAdd(a, b) {
    return ec.p256.Point.fromBytes(Bytes.of(a)).add(ec.p256.Point.fromBytes(Bytes.of(b))).toBytes(false);
  }
  /**
   * Negate an EC point on the P-256 curve.
   *
   * @param point - 65-byte uncompressed EC point (04 || x || y)
   * @returns 65-byte uncompressed EC point
   */
  ecNegate(point) {
    return ec.p256.Point.fromBytes(Bytes.of(point)).negate().toBytes(false);
  }
  reportUsage(component) {
    const message = ["Using", Diagnostic.strong(this.implementationName), "crypto implementation"];
    if (component) {
      message.push("for", component);
    }
    logger.debug(...message);
  }
}
export {
  CRYPTO_AUTH_TAG_LENGTH,
  CRYPTO_EC_CURVE,
  CRYPTO_EC_KEY_BYTES,
  CRYPTO_ENCRYPT_ALGORITHM,
  CRYPTO_HASH_ALGORITHM,
  CRYPTO_SYMMETRIC_KEY_LENGTH,
  Crypto,
  HASH_ALGORITHM_OUTPUT_LENGTHS,
  HashFipsAlgorithmId,
  ec
};
//# sourceMappingURL=Crypto.js.map
