• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1include_directories(../include)
2
3if(NOT OPENSSL_NO_ASM)
4  if(UNIX)
5    if(${ARCH} STREQUAL "aarch64")
6      # The "armx" Perl scripts look for "64" in the style argument
7      # in order to decide whether to generate 32- or 64-bit asm.
8      if(APPLE)
9        set(PERLASM_STYLE ios64)
10      else()
11        set(PERLASM_STYLE linux64)
12      endif()
13    elseif(${ARCH} STREQUAL "arm")
14      if(APPLE)
15        set(PERLASM_STYLE ios32)
16      else()
17        set(PERLASM_STYLE linux32)
18      endif()
19    elseif(${ARCH} STREQUAL "ppc64le")
20      set(PERLASM_STYLE linux64le)
21    else()
22      if(${ARCH} STREQUAL "x86")
23        set(PERLASM_FLAGS "-fPIC -DOPENSSL_IA32_SSE2")
24      endif()
25      if(APPLE)
26        set(PERLASM_STYLE macosx)
27      else()
28        set(PERLASM_STYLE elf)
29      endif()
30    endif()
31    set(ASM_EXT S)
32    enable_language(ASM)
33    set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -Wa,--noexecstack")
34
35    # Clang's integerated assembler does not support debug symbols.
36    if(NOT CMAKE_ASM_COMPILER_ID MATCHES "Clang")
37      set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -Wa,-g")
38    endif()
39
40    # CMake does not add -isysroot and -arch flags to assembly.
41    if(APPLE)
42      if(CMAKE_OSX_SYSROOT)
43        set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -isysroot \"${CMAKE_OSX_SYSROOT}\"")
44      endif()
45      foreach(arch ${CMAKE_OSX_ARCHITECTURES})
46        set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -arch ${arch}")
47      endforeach()
48    endif()
49  else()
50    if(${ARCH} STREQUAL "x86_64")
51      set(PERLASM_STYLE nasm)
52    else()
53      set(PERLASM_STYLE win32n)
54      set(PERLASM_FLAGS "-DOPENSSL_IA32_SSE2")
55    endif()
56    set(CMAKE_ASM_NASM_FLAGS "${CMAKE_ASM_NASM_FLAGS} -gcv8")
57
58    # On Windows, we use the NASM output, specifically built with Yasm.
59    set(ASM_EXT asm)
60    enable_language(ASM_NASM)
61  endif()
62endif()
63
64function(perlasm dest src)
65  get_filename_component(dir ${dest} DIRECTORY)
66  if ("${dir}" STREQUAL "")
67    set(dir ".")
68  endif()
69
70  add_custom_command(
71    OUTPUT ${dest}
72    COMMAND ${CMAKE_COMMAND} -E make_directory ${dir}
73    COMMAND ${PERL_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/${src} ${PERLASM_STYLE} ${PERLASM_FLAGS} ${ARGN} ${dest}
74    DEPENDS
75    ${src}
76    ${PROJECT_SOURCE_DIR}/crypto/perlasm/arm-xlate.pl
77    ${PROJECT_SOURCE_DIR}/crypto/perlasm/ppc-xlate.pl
78    ${PROJECT_SOURCE_DIR}/crypto/perlasm/x86_64-xlate.pl
79    ${PROJECT_SOURCE_DIR}/crypto/perlasm/x86asm.pl
80    ${PROJECT_SOURCE_DIR}/crypto/perlasm/x86gas.pl
81    ${PROJECT_SOURCE_DIR}/crypto/perlasm/x86masm.pl
82    ${PROJECT_SOURCE_DIR}/crypto/perlasm/x86nasm.pl
83    WORKING_DIRECTORY .
84  )
85endfunction()
86
87add_subdirectory(fipsmodule)
88add_subdirectory(test)
89
90if(FIPS_DELOCATE OR FIPS_SHARED)
91  SET_SOURCE_FILES_PROPERTIES(fipsmodule/bcm.o PROPERTIES EXTERNAL_OBJECT true)
92  SET_SOURCE_FILES_PROPERTIES(fipsmodule/bcm.o PROPERTIES GENERATED true)
93
94  set(
95    CRYPTO_FIPS_OBJECTS
96
97    fipsmodule/bcm.o
98  )
99endif()
100
101if(${ARCH} STREQUAL "arm")
102  set(
103    CRYPTO_ARCH_SOURCES
104
105    chacha/chacha-armv4.${ASM_EXT}
106    curve25519/asm/x25519-asm-arm.S
107    poly1305/poly1305_arm_asm.S
108    test/trampoline-armv4.${ASM_EXT}
109  )
110endif()
111
112if(${ARCH} STREQUAL "aarch64")
113  set(
114    CRYPTO_ARCH_SOURCES
115
116    chacha/chacha-armv8.${ASM_EXT}
117    test/trampoline-armv8.${ASM_EXT}
118  )
119endif()
120
121if(${ARCH} STREQUAL "x86")
122  set(
123    CRYPTO_ARCH_SOURCES
124
125    chacha/chacha-x86.${ASM_EXT}
126    test/trampoline-x86.${ASM_EXT}
127  )
128endif()
129
130if(${ARCH} STREQUAL "x86_64")
131  set(
132    CRYPTO_ARCH_SOURCES
133
134    chacha/chacha-x86_64.${ASM_EXT}
135    cipher_extra/aes128gcmsiv-x86_64.${ASM_EXT}
136    cipher_extra/chacha20_poly1305_x86_64.${ASM_EXT}
137    hrss/asm/poly_rq_mul.S
138    test/trampoline-x86_64.${ASM_EXT}
139  )
140endif()
141
142perlasm(chacha/chacha-armv4.${ASM_EXT} chacha/asm/chacha-armv4.pl)
143perlasm(chacha/chacha-armv8.${ASM_EXT} chacha/asm/chacha-armv8.pl)
144perlasm(chacha/chacha-x86.${ASM_EXT} chacha/asm/chacha-x86.pl)
145perlasm(chacha/chacha-x86_64.${ASM_EXT} chacha/asm/chacha-x86_64.pl)
146perlasm(cipher_extra/aes128gcmsiv-x86_64.${ASM_EXT} cipher_extra/asm/aes128gcmsiv-x86_64.pl)
147perlasm(cipher_extra/chacha20_poly1305_x86_64.${ASM_EXT} cipher_extra/asm/chacha20_poly1305_x86_64.pl)
148perlasm(test/trampoline-armv4.${ASM_EXT} test/asm/trampoline-armv4.pl)
149perlasm(test/trampoline-armv8.${ASM_EXT} test/asm/trampoline-armv8.pl)
150perlasm(test/trampoline-x86.${ASM_EXT} test/asm/trampoline-x86.pl)
151perlasm(test/trampoline-x86_64.${ASM_EXT} test/asm/trampoline-x86_64.pl)
152
153add_custom_command(
154  OUTPUT err_data.c
155  COMMAND ${GO_EXECUTABLE} run err_data_generate.go > ${CMAKE_CURRENT_BINARY_DIR}/err_data.c
156  DEPENDS
157  err/err_data_generate.go
158  err/asn1.errordata
159  err/bio.errordata
160  err/bn.errordata
161  err/cipher.errordata
162  err/conf.errordata
163  err/dh.errordata
164  err/digest.errordata
165  err/dsa.errordata
166  err/ecdh.errordata
167  err/ecdsa.errordata
168  err/ec.errordata
169  err/engine.errordata
170  err/evp.errordata
171  err/hkdf.errordata
172  err/obj.errordata
173  err/pem.errordata
174  err/pkcs7.errordata
175  err/pkcs8.errordata
176  err/rsa.errordata
177  err/ssl.errordata
178  err/x509.errordata
179  err/x509v3.errordata
180  WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/err
181)
182
183add_library(
184  crypto
185
186  asn1/a_bitstr.c
187  asn1/a_bool.c
188  asn1/a_d2i_fp.c
189  asn1/a_dup.c
190  asn1/a_enum.c
191  asn1/a_gentm.c
192  asn1/a_i2d_fp.c
193  asn1/a_int.c
194  asn1/a_mbstr.c
195  asn1/a_object.c
196  asn1/a_octet.c
197  asn1/a_print.c
198  asn1/a_strnid.c
199  asn1/a_time.c
200  asn1/a_type.c
201  asn1/a_utctm.c
202  asn1/a_utf8.c
203  asn1/asn1_lib.c
204  asn1/asn1_par.c
205  asn1/asn_pack.c
206  asn1/f_enum.c
207  asn1/f_int.c
208  asn1/f_string.c
209  asn1/tasn_dec.c
210  asn1/tasn_enc.c
211  asn1/tasn_fre.c
212  asn1/tasn_new.c
213  asn1/tasn_typ.c
214  asn1/tasn_utl.c
215  asn1/time_support.c
216  base64/base64.c
217  bio/bio.c
218  bio/bio_mem.c
219  bio/connect.c
220  bio/fd.c
221  bio/file.c
222  bio/hexdump.c
223  bio/pair.c
224  bio/printf.c
225  bio/socket.c
226  bio/socket_helper.c
227  bn_extra/bn_asn1.c
228  bn_extra/convert.c
229  buf/buf.c
230  bytestring/asn1_compat.c
231  bytestring/ber.c
232  bytestring/cbb.c
233  bytestring/cbs.c
234  bytestring/unicode.c
235  chacha/chacha.c
236  cipher_extra/cipher_extra.c
237  cipher_extra/derive_key.c
238  cipher_extra/e_aesccm.c
239  cipher_extra/e_aesctrhmac.c
240  cipher_extra/e_aesgcmsiv.c
241  cipher_extra/e_chacha20poly1305.c
242  cipher_extra/e_null.c
243  cipher_extra/e_rc2.c
244  cipher_extra/e_rc4.c
245  cipher_extra/e_tls.c
246  cipher_extra/tls_cbc.c
247  cmac/cmac.c
248  conf/conf.c
249  cpu-aarch64-fuchsia.c
250  cpu-aarch64-linux.c
251  cpu-arm-linux.c
252  cpu-arm.c
253  cpu-intel.c
254  cpu-ppc64le.c
255  crypto.c
256  curve25519/spake25519.c
257  dh/dh.c
258  dh/params.c
259  dh/check.c
260  dh/dh_asn1.c
261  digest_extra/digest_extra.c
262  dsa/dsa.c
263  dsa/dsa_asn1.c
264  ecdh_extra/ecdh_extra.c
265  ecdsa_extra/ecdsa_asn1.c
266  ec_extra/ec_asn1.c
267  ec_extra/ec_derive.c
268  err/err.c
269  err_data.c
270  engine/engine.c
271  evp/digestsign.c
272  evp/evp.c
273  evp/evp_asn1.c
274  evp/evp_ctx.c
275  evp/p_dsa_asn1.c
276  evp/p_ec.c
277  evp/p_ec_asn1.c
278  evp/p_ed25519.c
279  evp/p_ed25519_asn1.c
280  evp/p_rsa.c
281  evp/p_rsa_asn1.c
282  evp/p_x25519.c
283  evp/p_x25519_asn1.c
284  evp/pbkdf.c
285  evp/print.c
286  evp/scrypt.c
287  evp/sign.c
288  ex_data.c
289  hkdf/hkdf.c
290  hrss/hrss.c
291  lhash/lhash.c
292  mem.c
293  obj/obj.c
294  obj/obj_xref.c
295  pem/pem_all.c
296  pem/pem_info.c
297  pem/pem_lib.c
298  pem/pem_oth.c
299  pem/pem_pk8.c
300  pem/pem_pkey.c
301  pem/pem_x509.c
302  pem/pem_xaux.c
303  pkcs7/pkcs7.c
304  pkcs7/pkcs7_x509.c
305  pkcs8/pkcs8.c
306  pkcs8/pkcs8_x509.c
307  pkcs8/p5_pbev2.c
308  poly1305/poly1305.c
309  poly1305/poly1305_arm.c
310  poly1305/poly1305_vec.c
311  pool/pool.c
312  rand_extra/deterministic.c
313  rand_extra/forkunsafe.c
314  rand_extra/fuchsia.c
315  rand_extra/rand_extra.c
316  rand_extra/windows.c
317  rc4/rc4.c
318  refcount_c11.c
319  refcount_lock.c
320  rsa_extra/rsa_asn1.c
321  rsa_extra/rsa_print.c
322  stack/stack.c
323  siphash/siphash.c
324  thread.c
325  thread_none.c
326  thread_pthread.c
327  thread_win.c
328  x509/a_digest.c
329  x509/a_sign.c
330  x509/a_strex.c
331  x509/a_verify.c
332  x509/algorithm.c
333  x509/asn1_gen.c
334  x509/by_dir.c
335  x509/by_file.c
336  x509/i2d_pr.c
337  x509/rsa_pss.c
338  x509/t_crl.c
339  x509/t_req.c
340  x509/t_x509.c
341  x509/t_x509a.c
342  x509/x509.c
343  x509/x509_att.c
344  x509/x509_cmp.c
345  x509/x509_d2.c
346  x509/x509_def.c
347  x509/x509_ext.c
348  x509/x509_lu.c
349  x509/x509_obj.c
350  x509/x509_r2x.c
351  x509/x509_req.c
352  x509/x509_set.c
353  x509/x509_trs.c
354  x509/x509_txt.c
355  x509/x509_v3.c
356  x509/x509_vfy.c
357  x509/x509_vpm.c
358  x509/x509cset.c
359  x509/x509name.c
360  x509/x509rset.c
361  x509/x509spki.c
362  x509/x_algor.c
363  x509/x_all.c
364  x509/x_attrib.c
365  x509/x_crl.c
366  x509/x_exten.c
367  x509/x_info.c
368  x509/x_name.c
369  x509/x_pkey.c
370  x509/x_pubkey.c
371  x509/x_req.c
372  x509/x_sig.c
373  x509/x_spki.c
374  x509/x_val.c
375  x509/x_x509.c
376  x509/x_x509a.c
377  x509v3/pcy_cache.c
378  x509v3/pcy_data.c
379  x509v3/pcy_lib.c
380  x509v3/pcy_map.c
381  x509v3/pcy_node.c
382  x509v3/pcy_tree.c
383  x509v3/v3_akey.c
384  x509v3/v3_akeya.c
385  x509v3/v3_alt.c
386  x509v3/v3_bcons.c
387  x509v3/v3_bitst.c
388  x509v3/v3_conf.c
389  x509v3/v3_cpols.c
390  x509v3/v3_crld.c
391  x509v3/v3_enum.c
392  x509v3/v3_extku.c
393  x509v3/v3_genn.c
394  x509v3/v3_ia5.c
395  x509v3/v3_info.c
396  x509v3/v3_int.c
397  x509v3/v3_lib.c
398  x509v3/v3_ncons.c
399  x509v3/v3_ocsp.c
400  x509v3/v3_pci.c
401  x509v3/v3_pcia.c
402  x509v3/v3_pcons.c
403  x509v3/v3_pku.c
404  x509v3/v3_pmaps.c
405  x509v3/v3_prn.c
406  x509v3/v3_purp.c
407  x509v3/v3_skey.c
408  x509v3/v3_sxnet.c
409  x509v3/v3_utl.c
410  ../third_party/fiat/curve25519.c
411
412  $<TARGET_OBJECTS:fipsmodule>
413
414  ${CRYPTO_ARCH_SOURCES}
415  ${CRYPTO_FIPS_OBJECTS}
416)
417
418if(FIPS_SHARED)
419  set(EXTRA_INJECT_HASH_ARGS)
420  if(ANDROID)
421    set(EXTRA_INJECT_HASH_ARGS "-sha256")
422  endif()
423  # Rewrite libcrypto.so to inject the correct module hash value. This assumes
424  # UNIX-style library naming, but we only support FIPS mode on Linux anyway.
425  add_custom_command(
426    TARGET crypto POST_BUILD
427    COMMAND ${GO_EXECUTABLE} run
428    ${CMAKE_CURRENT_SOURCE_DIR}/../util/fipstools/inject_hash/inject_hash.go
429    -o libcrypto.so -in-object libcrypto.so ${EXTRA_INJECT_HASH_ARGS}
430    # The DEPENDS argument to a POST_BUILD rule appears to be ignored. Thus
431    # go_executable isn't used (as it doesn't get built), but we list this
432    # dependency anyway in case it starts working in some CMake version.
433    DEPENDS ../util/fipstools/inject_hash/inject_hash.go
434    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
435  )
436endif()
437
438add_dependencies(crypto global_target)
439
440if(FIPS_DELOCATE OR FIPS_SHARED)
441  add_dependencies(crypto bcm_o_target)
442endif()
443
444SET_TARGET_PROPERTIES(crypto PROPERTIES LINKER_LANGUAGE C)
445
446if(NOT MSVC AND NOT ANDROID)
447  target_link_libraries(crypto pthread)
448endif()
449
450# Every target depends on crypto, so we add libcxx as a dependency here to
451# simplify injecting it everywhere.
452if(USE_CUSTOM_LIBCXX)
453  target_link_libraries(crypto libcxx)
454endif()
455
456# urandom_test is a separate binary because it needs to be able to observe the
457# PRNG initialisation, which means that it can't have other tests running before
458# it does.
459add_executable(
460  urandom_test
461
462  fipsmodule/rand/urandom_test.cc
463)
464
465target_link_libraries(urandom_test test_support_lib boringssl_gtest crypto)
466
467add_dependencies(urandom_test global_target)
468add_dependencies(all_tests urandom_test)
469
470add_executable(
471  crypto_test
472
473  abi_self_test.cc
474  asn1/asn1_test.cc
475  base64/base64_test.cc
476  buf/buf_test.cc
477  bio/bio_test.cc
478  bytestring/bytestring_test.cc
479  chacha/chacha_test.cc
480  cipher_extra/aead_test.cc
481  cipher_extra/cipher_test.cc
482  cmac/cmac_test.cc
483  compiler_test.cc
484  constant_time_test.cc
485  cpu-arm-linux_test.cc
486  curve25519/ed25519_test.cc
487  curve25519/spake25519_test.cc
488  curve25519/x25519_test.cc
489  ecdh_extra/ecdh_test.cc
490  dh/dh_test.cc
491  digest_extra/digest_test.cc
492  dsa/dsa_test.cc
493  err/err_test.cc
494  evp/evp_extra_test.cc
495  evp/evp_test.cc
496  evp/pbkdf_test.cc
497  evp/scrypt_test.cc
498  fipsmodule/aes/aes_test.cc
499  fipsmodule/bn/bn_test.cc
500  fipsmodule/ec/ec_test.cc
501  fipsmodule/ec/p256-x86_64_test.cc
502  fipsmodule/ecdsa/ecdsa_test.cc
503  fipsmodule/md5/md5_test.cc
504  fipsmodule/modes/gcm_test.cc
505  fipsmodule/rand/ctrdrbg_test.cc
506  fipsmodule/sha/sha_test.cc
507  hkdf/hkdf_test.cc
508  hmac_extra/hmac_test.cc
509  hrss/hrss_test.cc
510  impl_dispatch_test.cc
511  lhash/lhash_test.cc
512  obj/obj_test.cc
513  pem/pem_test.cc
514  pkcs7/pkcs7_test.cc
515  pkcs8/pkcs8_test.cc
516  pkcs8/pkcs12_test.cc
517  poly1305/poly1305_test.cc
518  pool/pool_test.cc
519  rand_extra/rand_test.cc
520  refcount_test.cc
521  rsa_extra/rsa_test.cc
522  self_test.cc
523  stack/stack_test.cc
524  siphash/siphash_test.cc
525  test/file_test_gtest.cc
526  thread_test.cc
527  x509/x509_test.cc
528  x509/x509_time_test.cc
529  x509v3/tab_test.cc
530  x509v3/v3name_test.cc
531
532  $<TARGET_OBJECTS:crypto_test_data>
533  $<TARGET_OBJECTS:boringssl_gtest_main>
534)
535
536add_dependencies(crypto_test global_target)
537
538target_link_libraries(crypto_test test_support_lib boringssl_gtest crypto)
539if(WIN32)
540  target_link_libraries(crypto_test ws2_32)
541endif()
542add_dependencies(all_tests crypto_test)
543