TF-PSA-Crypto#
//third_party/tf_psa_crypto provides Bazel and GN build integration for
TF-PSA-Crypto, the standalone
PSA Certified Crypto API (<psa/crypto.h>) implementation split out from
MbedTLS 4.0. It does not bundle TF-PSA-Crypto source code for downstream
consumers.
Bazel#
Pigweed exposes two label flags in @pigweed//third_party/tf_psa_crypto:
@pigweed//third_party/tf_psa_crypto:psa_cryptoselects the<psa/crypto.h>implementation. It defaults to@pigweed//pw_build:unspecified_backendfor downstream consumers. Pigweed’s own.bazelrcbinds it to the dev-only@tf_psa_cryptorepository declared in//bazel:dev.MODULE.bazel.@pigweed//third_party/tf_psa_crypto:tf_psa_crypto_configselects the compile-time configuration header (TF_PSA_CRYPTO_CONFIG_FILE) when building TF-PSA-Crypto with@pigweed//third_party/tf_psa_crypto:tf_psa_crypto.BUILD.bazel. It defaults to:default_config, which picks:mcu_configon@platforms//os:noneand:host_configon all other platforms. RTOS platforms whose OS constraint is not@platforms//os:none(for example, Zephyr) should overridetf_psa_crypto_configorpsa_cryptoinstead of relying on:host_config.
Use an existing PSA Crypto provider#
If your project already builds a PSA Crypto provider (such as a vendor SDK or
MbedTLS with MBEDTLS_PSA_CRYPTO_C), reuse that target. Point psa_crypto
at it in your platform or .bazelrc:
common --@pigweed//third_party/tf_psa_crypto:psa_crypto=//crypto:psa_crypto
Building TF-PSA-Crypto from a release tarball#
Declare an http_archive for a TF-PSA-Crypto 1.1.2+ release tarball in
MODULE.bazel using Pigweed’s build file template:
http_archive = use_repo_rule(
"@bazel_tools//tools/build_defs/repo:http.bzl",
"http_archive",
)
http_archive(
name = "tf_psa_crypto",
build_file = "@pigweed//third_party/tf_psa_crypto:tf_psa_crypto.BUILD.bazel",
sha256 = "799764c15cebd0d8cc161c71f9601009b2992f471828739fb4d72573b87f8298",
strip_prefix = "tf-psa-crypto-1.1.2",
urls = ["https://github.com/Mbed-TLS/TF-PSA-Crypto/releases/download/tf-psa-crypto-1.1.2/tf-psa-crypto-1.1.2.tar.bz2"],
)
Then bind psa_crypto to that repository in your platform or .bazelrc:
common --@pigweed//third_party/tf_psa_crypto:psa_crypto=@tf_psa_crypto
Supply a custom configuration header#
Define a cc_library that exports your configuration header and sets
TF_PSA_CRYPTO_CONFIG_FILE:
cc_library(
name = "tf_psa_crypto_config",
hdrs = ["my_config/my_tf_psa_crypto_config.h"],
defines = [
"TF_PSA_CRYPTO_CONFIG_FILE='\"my_tf_psa_crypto_config.h\"'",
],
strip_include_prefix = "my_config",
tags = ["noclangtidy"],
)
Custom host configs that enable MBEDTLS_THREADING_PTHREAD on Linux or
MBEDTLS_PSA_BUILTIN_GET_ENTROPY on Windows must add matching linkopts
(-pthread on Linux; -lbcrypt or -DEFAULTLIB:bcrypt.lib on Windows).
Then override tf_psa_crypto_config in your platform or .bazelrc:
common --@pigweed//third_party/tf_psa_crypto:tf_psa_crypto_config=//crypto:tf_psa_crypto_config
GN#
Configure the GN build args declared in
$pw_external_tf_psa_crypto/tf_psa_crypto.gni:
dir_pw_third_party_tf_psa_crypto: Path to a TF-PSA-Crypto 1.1.2 or newer release tarball (or a checkout with generated files such ascore/psa_crypto_driver_wrappers_no_static.cpre-built). A raw git checkout without generated files will not build.pw_third_party_tf_psa_crypto_ALIAS: Label of an existing PSA Crypto build target to alias at$pw_external_tf_psa_crypto. Use this instead ofdir_pw_third_party_tf_psa_cryptoto avoid linking two copies of PSA Crypto.pw_third_party_tf_psa_crypto_CONFIG_HEADER: Path to theTF_PSA_CRYPTO_CONFIG_FILEheader when building fromdir_pw_third_party_tf_psa_crypto. Defaults toconfigs/config_pigweed_host.hon host toolchains andconfigs/config_pigweed.hon target toolchains.
Example gn gen invocation:
gn gen out --args='
dir_pw_third_party_tf_psa_crypto="/path/to/tf-psa-crypto-1.1.2"
'
After configuration, $pw_external_tf_psa_crypto provides the
pw_source_set target $pw_external_tf_psa_crypto:tf_psa_crypto.