# Copyright (c) 2020 Project CHIP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import("//build_overrides/build.gni")
import("//build_overrides/chip.gni")
import("//build_overrides/nlassert.gni")

import("${chip_root}/build/chip/buildconfig_header.gni")

import("crypto.gni")

if (chip_crypto == "") {
  if (current_os == "android" || current_os == "freertos" ||
      current_os == "zephyr" || current_os == "mbed" || current_os == "webos" ||
      current_os == "cmsis-rtos") {
    chip_crypto = "mbedtls"
  } else if (current_os == "mac" || current_os == "ios") {
    chip_crypto = "boringssl"
  } else {
    chip_crypto = "openssl"
  }
}

assert(
    chip_crypto == "mbedtls" || chip_crypto == "psa" ||
        chip_crypto == "openssl" || chip_crypto == "boringssl" ||
        chip_crypto == "platform",
    "Please select a valid crypto implementation: mbedtls, psa, openssl, boringssl, platform")

buildconfig_header("crypto_buildconfig") {
  header = "CryptoBuildConfig.h"
  header_dir = "crypto"

  chip_crypto_mbedtls = chip_crypto == "mbedtls"
  chip_crypto_psa = chip_crypto == "psa"
  chip_crypto_openssl = chip_crypto == "openssl"
  chip_crypto_boringssl = chip_crypto == "boringssl"
  chip_crypto_platform = chip_crypto == "platform"

  defines = [
    "CHIP_CRYPTO_MBEDTLS=${chip_crypto_mbedtls}",
    "CHIP_CRYPTO_PSA=${chip_crypto_psa}",
    "CHIP_CRYPTO_PSA_SPAKE2P=${chip_crypto_psa_spake2p}",
    "CHIP_CRYPTO_OPENSSL=${chip_crypto_openssl}",
    "CHIP_CRYPTO_BORINGSSL=${chip_crypto_boringssl}",
    "CHIP_CRYPTO_PLATFORM=${chip_crypto_platform}",
  ]
}

source_set("public_headers") {
  sources = [
    "CHIPCryptoPAL.h",
    "OperationalKeystore.h",
    "SessionKeystore.h",
  ]

  public_deps = [
    ":crypto_buildconfig",
    "${chip_root}/src/app/icd/server:icd-server-config",
    "${chip_root}/src/lib/asn1",
    "${chip_root}/src/lib/core",
    "${chip_root}/src/lib/core:types",
    "${chip_root}/src/lib/support",
    "${nlassert_root}:nlassert",
  ]
}

if (chip_crypto == "openssl") {
  import("${build_root}/config/linux/pkg_config.gni")

  pkg_config("openssl_config") {
    packages = [ "openssl" ]
  }

  source_set("cryptopal_openssl") {
    sources = [ "CHIPCryptoPALOpenSSL.cpp" ]
    public_configs = [ ":openssl_config" ]
    public_deps = [ ":public_headers" ]
  }
} else if (chip_crypto == "boringssl") {
  import("${chip_root}/build_overrides/boringssl.gni")

  source_set("cryptopal_boringssl") {
    # BoringSSL is close enough to OpenSSL that it uses same PAL, with minor #ifdef differences
    sources = [ "CHIPCryptoPALOpenSSL.cpp" ]
    public_deps = [
      ":public_headers",
      "${boringssl_root}:boringssl",
    ]
  }
} else if (chip_crypto == "mbedtls") {
  import("//build_overrides/mbedtls.gni")

  source_set("cryptopal_mbedtls") {
    sources = [
      "CHIPCryptoPALmbedTLS.cpp",
      "CHIPCryptoPALmbedTLS.h",
      "CHIPCryptoPALmbedTLSCert.cpp",
    ]
    public_deps = [ ":public_headers" ]

    if (!chip_external_mbedtls) {
      public_deps += [ "${mbedtls_root}:mbedtls" ]
    }
  }
} else if (chip_crypto == "psa") {
  import("//build_overrides/mbedtls.gni")

  source_set("cryptopal_psa") {
    sources = [
      "CHIPCryptoPALPSA.cpp",
      "CHIPCryptoPALPSA.h",
      "CHIPCryptoPALmbedTLS.h",
      "CHIPCryptoPALmbedTLSCert.cpp",
    ]
    public_deps = [ ":public_headers" ]

    if (!chip_external_mbedtls) {
      public_deps += [ "${mbedtls_root}:mbedtls" ]
    }
  }
}

static_library("crypto") {
  output_name = "libChipCrypto"

  sources = [
    "CHIPCryptoPAL.cpp",
    "DefaultSessionKeystore.h",
    "PersistentStorageOperationalKeystore.cpp",
    "PersistentStorageOperationalKeystore.h",
    "RandUtils.cpp",
    "RandUtils.h",
  ]

  if (chip_crypto == "psa") {
    sources += [
      "PSAOperationalKeystore.cpp",
      "PSAOperationalKeystore.h",
      "PSASessionKeystore.cpp",
      "PSASessionKeystore.h",
    ]
  } else {
    sources += [
      "RawKeySessionKeystore.cpp",
      "RawKeySessionKeystore.h",
    ]
  }

  if (chip_crypto_psa_spake2p) {
    sources += [
      "PSASpake2p.cpp",
      "PSASpake2p.h",
    ]
  }

  public_configs = []

  cflags = [ "-Wconversion" ]

  public_deps = [ ":public_headers" ]

  if (chip_crypto == "mbedtls") {
    public_deps += [ ":cryptopal_mbedtls" ]
  } else if (chip_crypto == "psa") {
    public_deps += [ ":cryptopal_psa" ]
  } else if (chip_crypto == "openssl") {
    public_deps += [ ":cryptopal_openssl" ]
  } else if (chip_crypto == "boringssl") {
    public_deps += [ ":cryptopal_boringssl" ]
  } else if (chip_crypto == "platform") {
    # Platform implementation is responsible for bringing their
    # own implementation and dependencies
  } else {
    assert(false, "Invalid CHIP crypto")
  }
}
