Home | History | Annotate | Download | only in crypto
      1 # Copyright (c) 2013 The Chromium Authors. All rights reserved.
      2 # Use of this source code is governed by a BSD-style license that can be
      3 # found in the LICENSE file.
      4 
      5 import("//build/config/crypto.gni")
      6 import("//testing/test.gni")
      7 
      8 component("crypto") {
      9   output_name = "crcrypto"  # Avoid colliding with OpenSSL's libcrypto.
     10   sources = [
     11     "aead.cc",
     12     "aead.h",
     13     "apple_keychain.h",
     14     "apple_keychain_ios.mm",
     15     "apple_keychain_mac.mm",
     16     "auto_cbb.h",
     17     "capi_util.cc",
     18     "capi_util.h",
     19     "crypto_export.h",
     20     "cssm_init.cc",
     21     "cssm_init.h",
     22     "curve25519.cc",
     23     "curve25519.h",
     24     "ec_private_key.cc",
     25     "ec_private_key.h",
     26     "ec_signature_creator.cc",
     27     "ec_signature_creator.h",
     28     "ec_signature_creator_impl.cc",
     29     "ec_signature_creator_impl.h",
     30     "encryptor.cc",
     31     "encryptor.h",
     32     "hkdf.cc",
     33     "hkdf.h",
     34     "hmac.cc",
     35     "hmac.h",
     36     "mac_security_services_lock.cc",
     37     "mac_security_services_lock.h",
     38 
     39     # TODO(brettw) these mocks should be moved to a test_support_crypto target
     40     # if possible.
     41     "mock_apple_keychain.cc",
     42     "mock_apple_keychain.h",
     43     "mock_apple_keychain_ios.cc",
     44     "mock_apple_keychain_mac.cc",
     45     "nss_key_util.cc",
     46     "nss_key_util.h",
     47     "nss_util.cc",
     48     "nss_util.h",
     49     "nss_util_internal.h",
     50     "openssl_bio_string.cc",
     51     "openssl_bio_string.h",
     52     "openssl_util.cc",
     53     "openssl_util.h",
     54     "p224.cc",
     55     "p224.h",
     56     "p224_spake.cc",
     57     "p224_spake.h",
     58     "random.cc",
     59     "random.h",
     60     "rsa_private_key.cc",
     61     "rsa_private_key.h",
     62     "scoped_capi_types.h",
     63     "scoped_nss_types.h",
     64     "secure_hash.cc",
     65     "secure_hash.h",
     66     "secure_util.cc",
     67     "secure_util.h",
     68     "sha2.cc",
     69     "sha2.h",
     70     "signature_creator.cc",
     71     "signature_creator.h",
     72     "signature_verifier.cc",
     73     "signature_verifier.h",
     74     "symmetric_key.cc",
     75     "symmetric_key.h",
     76   ]
     77 
     78   # TODO(jschuh): crbug.com/167187 fix size_t to int truncations.
     79   configs += [ "//build/config/compiler:no_size_t_to_int_warning" ]
     80 
     81   deps = [
     82     ":platform",
     83     "//base",
     84     "//base/third_party/dynamic_annotations",
     85   ]
     86 
     87   if (!is_mac && !is_ios) {
     88     sources -= [
     89       "apple_keychain.h",
     90       "mock_apple_keychain.cc",
     91       "mock_apple_keychain.h",
     92     ]
     93   } else {
     94     libs = [
     95       "CoreFoundation.framework",
     96       "Security.framework",
     97     ]
     98   }
     99 
    100   if (!is_mac) {
    101     sources -= [
    102       "cssm_init.cc",
    103       "cssm_init.h",
    104       "mac_security_services_lock.cc",
    105       "mac_security_services_lock.h",
    106     ]
    107   }
    108   if (!is_win) {
    109     sources -= [
    110       "capi_util.cc",
    111       "capi_util.h",
    112     ]
    113   }
    114 
    115   # Some files are built when NSS is used for the platform certificate library.
    116   if (!use_nss_certs) {
    117     sources -= [
    118       "nss_key_util.cc",
    119       "nss_key_util.h",
    120       "nss_util.cc",
    121       "nss_util.h",
    122       "nss_util_internal.h",
    123     ]
    124   }
    125 
    126   defines = [ "CRYPTO_IMPLEMENTATION" ]
    127 
    128   if (is_nacl) {
    129     deps += [ "//native_client_sdk/src/libraries/nacl_io" ]
    130   }
    131 }
    132 
    133 test("crypto_unittests") {
    134   sources = [
    135     "aead_unittest.cc",
    136     "curve25519_unittest.cc",
    137     "ec_private_key_unittest.cc",
    138     "ec_signature_creator_unittest.cc",
    139     "encryptor_unittest.cc",
    140     "hkdf_unittest.cc",
    141     "hmac_unittest.cc",
    142     "nss_key_util_unittest.cc",
    143     "nss_util_unittest.cc",
    144     "openssl_bio_string_unittest.cc",
    145     "p224_spake_unittest.cc",
    146     "p224_unittest.cc",
    147     "random_unittest.cc",
    148     "rsa_private_key_unittest.cc",
    149     "secure_hash_unittest.cc",
    150     "sha2_unittest.cc",
    151     "signature_creator_unittest.cc",
    152     "signature_verifier_unittest.cc",
    153     "symmetric_key_unittest.cc",
    154   ]
    155 
    156   # Some files are built when NSS is used for the platform certificate library.
    157   if (!use_nss_certs) {
    158     sources -= [
    159       "nss_key_util_unittest.cc",
    160       "nss_util_unittest.cc",
    161     ]
    162   }
    163 
    164   configs += [ "//build/config/compiler:no_size_t_to_int_warning" ]
    165 
    166   deps = [
    167     ":crypto",
    168     ":platform",
    169     ":test_support",
    170     "//base",
    171     "//base/test:run_all_unittests",
    172     "//base/test:test_support",
    173     "//testing/gmock",
    174     "//testing/gtest",
    175   ]
    176 }
    177 
    178 # This has no sources in some cases so can't be a static library.
    179 source_set("test_support") {
    180   testonly = true
    181   sources = []
    182 
    183   if (use_nss_certs) {
    184     sources += [
    185       "scoped_test_nss_db.cc",
    186       "scoped_test_nss_db.h",
    187     ]
    188   }
    189 
    190   if (is_chromeos) {
    191     sources += [
    192       "scoped_test_nss_chromeos_user.cc",
    193       "scoped_test_nss_chromeos_user.h",
    194       "scoped_test_system_nss_key_slot.cc",
    195       "scoped_test_system_nss_key_slot.h",
    196     ]
    197   }
    198 
    199   deps = [
    200     ":crypto",
    201     ":platform",
    202     "//base",
    203   ]
    204 }
    205 
    206 config("platform_config") {
    207   if (use_nss_certs && is_clang) {
    208     # There is a broken header guard in /usr/include/nss/secmod.h:
    209     # https://bugzilla.mozilla.org/show_bug.cgi?id=884072
    210     cflags = [ "-Wno-header-guard" ]
    211   }
    212 }
    213 
    214 # This is a meta-target that forwards to NSS's SSL library or OpenSSL,
    215 # according to the state of the crypto flags. A target just wanting to depend
    216 # on the current SSL library should just depend on this.
    217 group("platform") {
    218   public_deps = [
    219     "//third_party/boringssl",
    220   ]
    221 
    222   # Link in NSS if it is used for the platform certificate library
    223   # (use_nss_certs).
    224   if (use_nss_certs) {
    225     public_configs = [ ":platform_config" ]
    226     public_configs += [ "//third_party/nss:system_nss_no_ssl_config" ]
    227   }
    228 }
    229