• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2021 The Pigweed Authors
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may not
4# use this file except in compliance with the License. You may obtain a copy of
5# the License at
6#
7#     https://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, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations under
13# the License.
14
15load("@rules_cc//cc:cc_library.bzl", "cc_library")
16load("@rules_python//sphinxdocs:sphinx_docs_library.bzl", "sphinx_docs_library")
17load("//pw_build:compatibility.bzl", "host_backend_alias", "incompatible_with_mcu")
18load("//pw_build:pw_facade.bzl", "pw_facade")
19load("//pw_unit_test:pw_cc_test.bzl", "pw_cc_test")
20
21package(
22    default_visibility = ["//visibility:public"],
23    features = ["-layering_check"],
24)
25
26licenses(["notice"])
27
28pw_facade(
29    name = "sha256",
30    hdrs = [
31        "public/pw_crypto/sha256.h",
32    ],
33    backend = ":sha256_backend",
34    strip_include_prefix = "public",
35    deps = [
36        "//pw_bytes",
37        "//pw_log",
38        "//pw_status",
39        "//pw_stream",
40    ],
41)
42
43label_flag(
44    name = "sha256_backend",
45    build_setting_default = ":unspecified_sha256_backend",
46)
47
48host_backend_alias(
49    name = "unspecified_sha256_backend",
50    backend = ":sha256_mbedtls",
51)
52
53cc_library(
54    name = "sha256_mbedtls",
55    srcs = ["sha256_mbedtls.cc"],
56    hdrs = [
57        "public/pw_crypto/sha256_mbedtls.h",
58        "public_overrides/mbedtls/pw_crypto/sha256_backend.h",
59    ],
60    includes = [
61        "public",
62        "public_overrides/mbedtls",
63    ],
64    deps = [
65        ":sha256.facade",
66        "@mbedtls",
67    ],
68)
69
70pw_cc_test(
71    name = "sha256_test",
72    srcs = ["sha256_test.cc"],
73    deps = [":sha256"],
74)
75
76cc_library(
77    name = "sha256_mock",
78    srcs = ["sha256_mock.cc"],
79    hdrs = [
80        "public/pw_crypto/sha256_mock.h",
81        "public_overrides/mock/pw_crypto/sha256_backend.h",
82    ],
83    includes = [
84        "public",
85        "public_overrides/mock",
86    ],
87    deps = [":sha256.facade"],
88)
89
90pw_cc_test(
91    name = "sha256_mock_test",
92    srcs = ["sha256_mock_test.cc"],
93    deps = [":sha256_mock"],
94)
95
96pw_facade(
97    name = "ecdsa",
98    hdrs = [
99        "public/pw_crypto/ecdsa.h",
100    ],
101    backend = ":ecdsa_backend",
102    strip_include_prefix = "public",
103    deps = [
104        "//pw_bytes",
105        "//pw_status",
106    ],
107)
108
109label_flag(
110    name = "ecdsa_backend",
111    build_setting_default = ":unspecified_ecdsa_backend",
112)
113
114host_backend_alias(
115    name = "unspecified_ecdsa_backend",
116    backend = ":ecdsa_mbedtls",
117)
118
119cc_library(
120    name = "ecdsa_mbedtls",
121    srcs = ["ecdsa_mbedtls.cc"],
122    deps = [
123        ":ecdsa.facade",
124        "//pw_function",
125        "//pw_log",
126        "//pw_span:cast",
127        "@mbedtls",
128    ],
129)
130
131pw_cc_test(
132    name = "ecdsa_test",
133    srcs = ["ecdsa_test.cc"],
134    deps = [":ecdsa"],
135)
136
137pw_facade(
138    name = "aes",
139    hdrs = [
140        "public/pw_crypto/aes.h",
141        "public/pw_crypto/aes_backend_defs.h",
142    ],
143    backend = ":aes_backend",
144    includes = ["public"],
145    deps = [
146        "//pw_bytes",
147        "//pw_log",
148        "//pw_status",
149    ],
150)
151
152cc_library(
153    name = "aes_cmac",
154    hdrs = ["public/pw_crypto/aes_cmac.h"],
155    deps = [":aes"],
156)
157
158label_flag(
159    name = "aes_backend",
160    build_setting_default = ":unspecified_aes_backend",
161)
162
163host_backend_alias(
164    name = "unspecified_aes_backend",
165    backend = ":aes_mbedtls",
166)
167
168cc_library(
169    name = "aes_boringssl",
170    srcs = ["aes_boringssl.cc"],
171    hdrs = [
172        "public/pw_crypto/aes_boringssl.h",
173        "public_overrides/boringssl/pw_crypto/aes_backend.h",
174    ],
175    implementation_deps = ["//pw_assert:check"],
176    includes = ["public_overrides/boringssl"],
177    target_compatible_with = incompatible_with_mcu() + select({
178        "@platforms//os:windows": ["@platforms//:incompatible"],
179        "//conditions:default": [],
180    }),
181    deps = [
182        ":aes.facade",
183        "//pw_span:cast",
184        "@boringssl//:crypto",
185    ],
186)
187
188cc_library(
189    name = "aes_mbedtls",
190    srcs = ["aes_mbedtls.cc"],
191    hdrs = [
192        "public/pw_crypto/aes_mbedtls.h",
193        "public_overrides/mbedtls/pw_crypto/aes_backend.h",
194    ],
195    implementation_deps = ["//pw_assert:check"],
196    includes = ["public_overrides/mbedtls"],
197    deps = [
198        ":aes.facade",
199        "@mbedtls",
200    ],
201)
202
203pw_cc_test(
204    name = "aes_test",
205    srcs = [
206        "aes_test.cc",
207    ],
208    deps = [
209        ":aes",
210        ":aes_cmac",
211        "//pw_assert:assert",
212        "//pw_containers:vector",
213    ],
214)
215
216filegroup(
217    name = "doxygen",
218    srcs = [
219        "public/pw_crypto/ecdsa.h",
220        "public/pw_crypto/sha256.h",
221    ],
222)
223
224sphinx_docs_library(
225    name = "docs",
226    srcs = [
227        "docs.rst",
228    ],
229    prefix = "pw_crypto/",
230    target_compatible_with = incompatible_with_mcu(),
231)
232