xref: /aosp_15_r20/system/security/keystore2/src/crypto/Android.bp (revision e1997b9af69e3155ead6e072d106a0077849ffba)
1// Copyright 2020, The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package {
16    // See: http://go/android-license-faq
17    // A large-scale-change added 'default_applicable_licenses' to import
18    // all of the 'license_kinds' from "system_security_license"
19    // to get the below license kinds:
20    //   SPDX-license-identifier-Apache-2.0
21    default_applicable_licenses: ["system_security_license"],
22}
23
24rust_library {
25    name: "libkeystore2_crypto_rust",
26    crate_name: "keystore2_crypto",
27    srcs: ["lib.rs"],
28    rustlibs: [
29        "libkeystore2_crypto_bindgen",
30        "liblog_rust",
31        "libnix",
32        "libthiserror",
33    ],
34    shared_libs: [
35        "libcrypto",
36        "libkeystore2_crypto",
37    ],
38    vendor_available: true,
39    apex_available: [
40        "//apex_available:platform",
41        "com.android.virt",
42    ],
43}
44
45cc_library {
46    name: "libkeystore2_crypto",
47    srcs: [
48        "certificate_utils.cpp",
49        "crypto.cpp",
50    ],
51    export_include_dirs: ["include"],
52    shared_libs: [
53        "libcrypto",
54        "liblog",
55    ],
56    vendor_available: true,
57    apex_available: [
58        "//apex_available:platform",
59        "com.android.virt",
60    ],
61}
62
63rust_bindgen {
64    name: "libkeystore2_crypto_bindgen",
65    wrapper_src: "crypto.hpp",
66    crate_name: "keystore2_crypto_bindgen",
67    source_stem: "bindings",
68    host_supported: true,
69    vendor_available: true,
70    shared_libs: ["libcrypto"],
71    bindgen_flags: [
72        "--allowlist-function=AES_gcm_decrypt",
73        "--allowlist-function=AES_gcm_encrypt",
74        "--allowlist-function=CreateKeyId",
75        "--allowlist-function=ECDHComputeKey",
76        "--allowlist-function=ECKEYGenerateKey",
77        "--allowlist-function=ECKEYMarshalPrivateKey",
78        "--allowlist-function=ECKEYParsePrivateKey",
79        "--allowlist-function=ECPOINTOct2Point",
80        "--allowlist-function=ECPOINTPoint2Oct",
81        "--allowlist-function=EC_KEY_free",
82        "--allowlist-function=EC_KEY_get0_public_key",
83        "--allowlist-function=EC_POINT_free",
84        "--allowlist-function=HKDFExpand",
85        "--allowlist-function=HKDFExtract",
86        "--allowlist-function=PBKDF2",
87        "--allowlist-function=extractSubjectFromCertificate",
88        "--allowlist-function=hmacSha256",
89        "--allowlist-function=randomBytes",
90        "--allowlist-type=EC_KEY",
91        "--allowlist-type=EC_POINT",
92        "--allowlist-var=EC_MAX_BYTES",
93        "--allowlist-var=EVP_MAX_MD_SIZE",
94    ],
95    cflags: ["-DBORINGSSL_NO_CXX"],
96    apex_available: [
97        "//apex_available:platform",
98        "com.android.virt",
99    ],
100}
101
102rust_test {
103    name: "keystore2_crypto_test_rust",
104    crate_name: "keystore2_crypto_test_rust",
105    srcs: ["lib.rs"],
106    test_suites: ["general-tests"],
107    auto_gen_config: true,
108    rustlibs: [
109        "libkeystore2_crypto_bindgen",
110        "liblog_rust",
111        "libnix",
112        "libthiserror",
113    ],
114    static_libs: [
115        "libkeystore2_crypto",
116    ],
117    shared_libs: [
118        "libc++",
119        "libcrypto",
120        "liblog",
121    ],
122}
123
124cc_test {
125    name: "keystore2_crypto_test",
126    cflags: [
127        "-Wall",
128        "-Werror",
129        "-Wextra",
130    ],
131    srcs: [
132        "tests/certificate_utils_test.cpp",
133        "tests/gtest_main.cpp",
134    ],
135    test_suites: ["general-tests"],
136    static_libs: [
137        "libkeystore2_crypto",
138    ],
139    shared_libs: [
140        "libcrypto",
141    ],
142}
143
144rust_test {
145    name: "libkeystore2_crypto_bindgen_test",
146    srcs: [":libkeystore2_crypto_bindgen"],
147    crate_name: "keystore2_crypto_bindgen_test",
148    test_suites: ["general-tests"],
149    auto_gen_config: true,
150    clippy_lints: "none",
151    lints: "none",
152    apex_available: [
153        "//apex_available:platform",
154        "com.android.virt",
155    ],
156}
157