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_report("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 ":sha256_test", 84 ":sha256_mock_test", 85 ":ecdsa_test", 86 ] 87} 88 89# Sha256 tests against the selected real backend. 90pw_test("sha256_test") { 91 enable_if = pw_crypto_SHA256_BACKEND != "" 92 deps = [ ":sha256" ] 93 sources = [ "sha256_test.cc" ] 94} 95 96config("mock_config") { 97 visibility = [ ":*" ] 98 include_dirs = [ "public_overrides/mock" ] 99} 100 101pw_source_set("sha256_mock") { 102 public_configs = [ ":mock_config" ] 103 public = [ 104 "public/pw_crypto/sha256_mock.h", 105 "public_overrides/mock/pw_crypto/sha256_backend.h", 106 ] 107 sources = [ "sha256_mock.cc" ] 108 public_deps = [ ":sha256.facade" ] 109} 110 111# Sha256 frontend tests against a mocked backend. 112pw_test("sha256_mock_test") { 113 # Depend on ":sha256.facade" instead of ":sha256" to bypass normal backend 114 # selection via `pw_crypto_SHA256_BACKEND`. 115 deps = [ 116 ":sha256.facade", 117 ":sha256_mock", 118 ] 119 sources = [ "sha256_mock_test.cc" ] 120} 121 122config("mbedtls_config") { 123 visibility = [ ":*" ] 124 include_dirs = [ "public_overrides/mbedtls" ] 125} 126 127pw_source_set("sha256_mbedtls") { 128 public_configs = [ ":mbedtls_config" ] 129 public = [ 130 "public/pw_crypto/sha256_mbedtls.h", 131 "public_overrides/mbedtls/pw_crypto/sha256_backend.h", 132 ] 133 sources = [ "sha256_mbedtls.cc" ] 134 public_deps = [ 135 ":sha256.facade", 136 "$dir_pw_third_party/mbedtls", 137 ] 138} 139 140config("boringssl_config") { 141 visibility = [ ":*" ] 142 include_dirs = [ "public_overrides/boringssl" ] 143} 144 145pw_source_set("sha256_boringssl") { 146 public_configs = [ ":boringssl_config" ] 147 public = [ 148 "public/pw_crypto/sha256_boringssl.h", 149 "public_overrides/boringssl/pw_crypto/sha256_backend.h", 150 ] 151 sources = [ "sha256_boringssl.cc" ] 152 public_deps = [ 153 ":sha256.facade", 154 "$dir_pw_third_party/boringssl", 155 ] 156} 157 158pw_facade("ecdsa") { 159 backend = pw_crypto_ECDSA_BACKEND 160 public_configs = [ ":default_config" ] 161 public = [ "public/pw_crypto/ecdsa.h" ] 162 public_deps = [ 163 "$dir_pw_bytes", 164 "$dir_pw_status", 165 ] 166} 167 168pw_source_set("ecdsa_mbedtls") { 169 sources = [ "ecdsa_mbedtls.cc" ] 170 deps = [ 171 "$dir_pw_function", 172 "$dir_pw_log", 173 "$dir_pw_third_party/mbedtls", 174 ] 175 public_deps = [ ":ecdsa.facade" ] 176} 177 178pw_source_set("ecdsa_boringssl") { 179 sources = [ "ecdsa_boringssl.cc" ] 180 deps = [ 181 "$dir_pw_log", 182 "$dir_pw_third_party/boringssl", 183 ] 184 public_deps = [ ":ecdsa.facade" ] 185} 186 187pw_source_set("ecdsa_uecc") { 188 sources = [ "ecdsa_uecc.cc" ] 189 deps = [ 190 "$dir_pw_log", 191 "$dir_pw_third_party/micro_ecc", 192 ] 193 public_deps = [ ":ecdsa.facade" ] 194} 195 196pw_test("ecdsa_test") { 197 enable_if = pw_crypto_ECDSA_BACKEND != "" 198 deps = [ ":ecdsa" ] 199 sources = [ "ecdsa_test.cc" ] 200} 201