• 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
15import("//build_overrides/pigweed.gni")
16
17import("$dir_pw_bloat/bloat.gni")
18import("$dir_pw_build/facade.gni")
19import("$dir_pw_build/target_types.gni")
20import("$dir_pw_crypto/backend.gni")
21import("$dir_pw_docgen/docs.gni")
22import("$dir_pw_unit_test/test.gni")
23
24config("default_config") {
25  include_dirs = [ "public" ]
26  visibility = [ ":*" ]
27}
28
29pw_facade("sha256") {
30  backend = pw_crypto_SHA256_BACKEND
31  public_configs = [ ":default_config" ]
32  public = [ "public/pw_crypto/sha256.h" ]
33  public_deps = [
34    "$dir_pw_bytes",
35    "$dir_pw_log",
36    "$dir_pw_status",
37    "$dir_pw_stream",
38  ]
39  deps = [ "$dir_pw_assert" ]
40}
41
42pw_doc_group("docs") {
43  sources = [ "docs.rst" ]
44  report_deps = [ ":size_report" ]
45}
46
47pw_size_diff("size_report") {
48  title = "pw::crypto Size Report"
49  base = "$dir_pw_bloat:bloat_base"
50
51  binaries = []
52
53  if (pw_crypto_SHA256_BACKEND != "") {
54    binaries += [
55      {
56        target = "size_report:sha256_simple"
57        label = "SHA256 ($pw_crypto_SHA256_BACKEND)"
58      },
59    ]
60  }
61
62  if (pw_crypto_ECDSA_BACKEND != "") {
63    binaries += [
64      {
65        target = "size_report:ecdsa_p256_verify"
66        label = "ECDSA P256 Verify ($pw_crypto_ECDSA_BACKEND)"
67      },
68    ]
69  }
70
71  if (binaries == []) {
72    binaries += [
73      {
74        target = "$dir_pw_bloat:bloat_base"
75        label = "No backend is selected."
76      },
77    ]
78  }
79}
80
81pw_test_group("tests") {
82  tests = [
83    ":aes_test",
84    ":sha256_test",
85    ":sha256_mock_test",
86    ":ecdsa_test",
87  ]
88}
89
90# Sha256 tests against the selected real backend.
91pw_test("sha256_test") {
92  enable_if = pw_crypto_SHA256_BACKEND != ""
93  deps = [ ":sha256" ]
94  sources = [ "sha256_test.cc" ]
95}
96
97config("mock_config") {
98  visibility = [ ":*" ]
99  include_dirs = [ "public_overrides/mock" ]
100}
101
102pw_source_set("sha256_mock") {
103  public_configs = [ ":mock_config" ]
104  public = [
105    "public/pw_crypto/sha256_mock.h",
106    "public_overrides/mock/pw_crypto/sha256_backend.h",
107  ]
108  sources = [ "sha256_mock.cc" ]
109  public_deps = [ ":sha256.facade" ]
110}
111
112# Sha256 frontend tests against a mocked backend.
113pw_test("sha256_mock_test") {
114  # Depend on ":sha256.facade" instead of ":sha256" to bypass normal backend
115  # selection via `pw_crypto_SHA256_BACKEND`.
116  deps = [
117    ":sha256.facade",
118    ":sha256_mock",
119  ]
120  sources = [ "sha256_mock_test.cc" ]
121}
122
123config("mbedtls_config") {
124  visibility = [ ":*" ]
125  include_dirs = [ "public_overrides/mbedtls" ]
126}
127
128pw_source_set("sha256_mbedtls") {
129  public_configs = [ ":mbedtls_config" ]
130  public = [
131    "public/pw_crypto/sha256_mbedtls.h",
132    "public_overrides/mbedtls/pw_crypto/sha256_backend.h",
133  ]
134  sources = [ "sha256_mbedtls.cc" ]
135  public_deps = [
136    ":sha256.facade",
137    "$dir_pw_third_party/mbedtls",
138  ]
139}
140
141pw_source_set("sha256_mbedtls_v3") {
142  public_configs = [ ":mbedtls_config" ]
143  public = [
144    "public/pw_crypto/sha256_mbedtls.h",
145    "public_overrides/mbedtls/pw_crypto/sha256_backend.h",
146  ]
147  sources = [ "sha256_mbedtls.cc" ]
148  public_deps = [
149    ":sha256.facade",
150    "$dir_pw_third_party/mbedtls:mbedtls_v3",
151  ]
152}
153
154pw_facade("ecdsa") {
155  backend = pw_crypto_ECDSA_BACKEND
156  public_configs = [ ":default_config" ]
157  public = [ "public/pw_crypto/ecdsa.h" ]
158  public_deps = [
159    "$dir_pw_bytes",
160    "$dir_pw_status",
161  ]
162}
163
164pw_source_set("ecdsa_mbedtls") {
165  sources = [ "ecdsa_mbedtls.cc" ]
166  deps = [
167    "$dir_pw_function",
168    "$dir_pw_log",
169    "$dir_pw_third_party/mbedtls",
170  ]
171  public_deps = [
172    ":ecdsa.facade",
173    "$dir_pw_span:cast",
174  ]
175}
176
177pw_source_set("ecdsa_mbedtls_v3") {
178  sources = [ "ecdsa_mbedtls.cc" ]
179  deps = [
180    "$dir_pw_function",
181    "$dir_pw_log",
182    "$dir_pw_third_party/mbedtls:mbedtls_v3",
183  ]
184  public_deps = [
185    ":ecdsa.facade",
186    "$dir_pw_span:cast",
187  ]
188}
189
190# This test targets the specific backend pointed to by
191# pw_crypto_ECDSA_BACKEND.
192pw_test("ecdsa_test") {
193  enable_if = pw_crypto_ECDSA_BACKEND != ""
194  deps = [ ":ecdsa" ]
195  sources = [ "ecdsa_test.cc" ]
196}
197
198pw_facade("aes") {
199  backend = pw_crypto_AES_BACKEND
200  public_configs = [ ":default_config" ]
201  public = [
202    "public/pw_crypto/aes.h",
203    "public/pw_crypto/aes_backend_defs.h",
204  ]
205  public_deps = [
206    "$dir_pw_bytes",
207    "$dir_pw_log",
208    "$dir_pw_status",
209  ]
210}
211
212pw_source_set("aes_cmac") {
213  public = [ "public/pw_crypto/aes_cmac.h" ]
214  deps = [ ":aes" ]
215}
216
217config("boringssl_config") {
218  visibility = [ ":*" ]
219  include_dirs = [ "public_overrides/boringssl" ]
220}
221
222pw_source_set("aes_boringssl") {
223  public_configs = [ ":boringssl_config" ]
224  sources = [ "aes_boringssl.cc" ]
225  public = [
226    "public/pw_crypto/aes_boringssl.h",
227    "public_overrides/boringssl/pw_crypto/aes_backend.h",
228  ]
229  deps = [ "$dir_pw_assert" ]
230  public_deps = [
231    ":aes.facade",
232    "$dir_pw_span:cast",
233    "$dir_pw_third_party/boringssl",
234  ]
235}
236
237pw_source_set("aes_mbedtls_v3") {
238  public_configs = [ ":mbedtls_config" ]
239  public = [
240    "public/pw_crypto/aes_mbedtls.h",
241    "public_overrides/mbedtls/pw_crypto/aes_backend.h",
242  ]
243  deps = [ "$dir_pw_assert" ]
244  sources = [ "aes_mbedtls.cc" ]
245  public_deps = [
246    ":aes.facade",
247    "$dir_pw_third_party/mbedtls:mbedtls_v3",
248  ]
249}
250
251# This test targets the specific backend pointed to by
252# pw_crypto_AES_BACKEND.
253pw_test("aes_test") {
254  enable_if = pw_crypto_AES_BACKEND != ""
255  deps = [
256    ":aes",
257    ":aes_cmac",
258    "$dir_pw_assert",
259    "$dir_pw_containers:vector",
260  ]
261  sources = [ "aes_test.cc" ]
262}
263