aboutsummaryrefslogtreecommitdiffstats
path: root/src/libcryptobox/CMakeLists.txt
blob: ecd729d6a0c00f9fb1e7b6152f13e4a2a5dc88d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
INCLUDE(FindArch.cmake)
INCLUDE(AsmOp.cmake)

TARGET_ARCHITECTURE(ARCH)

SET(CHACHASRC ${CMAKE_CURRENT_SOURCE_DIR}/chacha20/chacha.c 
	${CMAKE_CURRENT_SOURCE_DIR}/chacha20/ref.c)
SET(POLYSRC ${CMAKE_CURRENT_SOURCE_DIR}/poly1305/poly1305.c)
SET(SIPHASHSRC ${CMAKE_CURRENT_SOURCE_DIR}/siphash/siphash.c
	${CMAKE_CURRENT_SOURCE_DIR}/siphash/ref.c)

# For now we support only x86_64 architecture with optimizations
IF(${ARCH} STREQUAL "x86_64")
	ASM_OP(HAVE_AVX2 "vpaddq %ymm0, %ymm0, %ymm0" "avx2")
	ASM_OP(HAVE_AVX "vpaddq %xmm0, %xmm0, %xmm0" "avx")
	ASM_OP(HAVE_SSE2 "pmuludq %xmm0, %xmm0" "sse2")
	ASM_OP(HAVE_SSE3 "lddqu 0(%esi), %xmm0" "sse3")
	ASM_OP(HAVE_SSSE3 "pshufb %xmm0, %xmm0" "ssse3")
	ASM_OP(HAVE_SSE41 "pblendw \$0, %xmm0, %xmm0" "sse41")
	
	ASM_OP(HAVE_SLASHMACRO "
	.macro TEST1 op
	\\op %eax, %eax
	.endm
	TEST1 xorl
	" "slash macro convention")
	
	ASM_OP(HAVE_DOLLARMACRO "
	.macro TEST1 op
	$0 %eax, %eax
	.endm
	TEST1 xorl
	" "dollar macro convention")
	
	SET(CURVESRC ${CMAKE_CURRENT_SOURCE_DIR}/curve25519/curve25519-donna-c64.c)
	SET(POLYSRC ${POLYSRC} ${CMAKE_CURRENT_SOURCE_DIR}/poly1305/ref-64.c)
ELSEIF(${ARCH} STREQUAL "i386")
	SET(POLYSRC ${POLYSRC} ${CMAKE_CURRENT_SOURCE_DIR}/poly1305/ref-32.c)
	SET(CURVESRC ${CMAKE_CURRENT_SOURCE_DIR}/curve25519/curve25519-donna.c)
ELSE()
	SET(CURVESRC ${CMAKE_CURRENT_SOURCE_DIR}/curve25519/ref.c)
	SET(POLYSRC ${POLYSRC} ${CMAKE_CURRENT_SOURCE_DIR}/poly1305/ref-32.c)
ENDIF()

IF(HAVE_AVX2)
	SET(CHACHASRC ${CHACHASRC} ${CMAKE_CURRENT_SOURCE_DIR}/chacha20/avx2.S)
	SET(POLYSRC ${POLYSRC} ${CMAKE_CURRENT_SOURCE_DIR}/poly1305/avx2.S)
ENDIF(HAVE_AVX2)
IF(HAVE_AVX)
	SET(CHACHASRC ${CHACHASRC} ${CMAKE_CURRENT_SOURCE_DIR}/chacha20/avx.S)
	SET(POLYSRC ${POLYSRC} ${CMAKE_CURRENT_SOURCE_DIR}/poly1305/avx.S)
ENDIF(HAVE_AVX)
IF(HAVE_SSE2)
	SET(CHACHASRC ${CHACHASRC} ${CMAKE_CURRENT_SOURCE_DIR}/chacha20/sse2.S)
	SET(POLYSRC ${POLYSRC} ${CMAKE_CURRENT_SOURCE_DIR}/poly1305/sse2.S)
ENDIF(HAVE_SSE2)
IF(HAVE_SSE41)
	SET(SIPHASHSRC ${SIPHASHSRC} ${CMAKE_CURRENT_SOURCE_DIR}/siphash/sse41.S)
ENDIF(HAVE_SSE41)

CONFIGURE_FILE(platform_config.h.in platform_config.h)
INCLUDE_DIRECTORIES("${CMAKE_CURRENT_BINARY_DIR}")
SET(LIBCRYPTOBOXSRC ${CMAKE_CURRENT_SOURCE_DIR}/cryptobox.c)

SET(RSPAMD_CRYPTOBOX ${LIBCRYPTOBOXSRC} ${CHACHASRC} ${POLYSRC} ${SIPHASHSRC}
	${CURVESRC} PARENT_SCOPE)