Skip to content

Commit ae735b0

Browse files
author
Steven Noonan
committed
meson: add -Duse_crypto and -Duse_crypto25519 options
Signed-off-by: Steven Noonan <[email protected]>
1 parent b445a0d commit ae735b0

File tree

4 files changed

+40
-20
lines changed

4 files changed

+40
-20
lines changed

.travis/build-meson.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ set -e
77

88
cleanup() {
99
echo "Cleaning up Meson build directories" >&2
10-
rm -rf build-meson
10+
rm -rf build-meson build-meson-ref
1111
}
1212

1313
trap cleanup EXIT
@@ -22,12 +22,15 @@ set -x
2222

2323
# Build lightweight test builds
2424
meson . build-meson ${MESON_ARGS[@]} --buildtype debugoptimized
25+
meson . build-meson-ref ${MESON_ARGS[@]} --buildtype debugoptimized -Duse_crypto25519=Reference
2526

26-
# Build all targets of CMake/meson, ensuring everything can build.
27+
# Build all targets
2728
ninja -v -C build-meson
29+
ninja -v -C build-meson-ref
2830

2931
# Run basic tests
3032
build-meson/tests/test_crypto
33+
build-meson-ref/tests/test_crypto
3134

3235
set +x
3336

meson.build

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ if werror
5151
warn_flags_common += [ '-Werror' ]
5252
endif
5353

54+
use_crypto_25519 = get_option('use_crypto25519')
55+
if use_crypto_25519 == 'Reference'
56+
warn_flags_common += [ '-Wno-unused-function' ]
57+
endif
58+
5459
warn_flags_c = [
5560
'-Wimplicit',
5661
'-Wstrict-prototypes',

meson_options.txt

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,14 @@ option('Werror',
88
value: false,
99
description: 'Enable -Werror flag when compiling')
1010

11-
option('use_bcrypt',
12-
type: 'boolean',
13-
value: false,
14-
description: 'Use BCrypt API for cryptography (encryption/decryption, hashing) on Windows')
11+
option('use_crypto',
12+
type: 'combo',
13+
value: 'OpenSSL',
14+
description: 'Crypto library to use for AES/SHA256',
15+
choices: ['OpenSSL', 'BCrypt'])
16+
17+
option('use_crypto25519',
18+
type: 'combo',
19+
value: 'OpenSSL',
20+
description: 'Crypto library to use for ed25519/curve25519',
21+
choices: ['OpenSSL', 'Reference'])

src/meson.build

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ protoc = generator(protoc_bin,
77
88
arguments : ['-I@CURRENT_SOURCE_DIR@/common', '--proto_path=@CURRENT_SOURCE_DIR@', '--cpp_out=@BUILD_DIR@', '@INPUT@'])
99

10-
use_bcrypt = get_option('use_bcrypt')
10+
use_crypto = get_option('use_crypto')
11+
use_crypto25519 = get_option('use_crypto25519')
1112

12-
if not use_bcrypt
13+
if use_crypto == 'OpenSSL' or use_crypto25519 == 'OpenSSL'
1314
min_libcrypto = dependency('libcrypto', version: '>=1.1.0')
1415
good_libcrypto = dependency('libcrypto', version: '>=1.1.1', required: false)
1516

@@ -19,6 +20,10 @@ if not use_bcrypt
1920
dependencies += [ min_libcrypto ]
2021
endif
2122

23+
if use_crypto25519 == 'OpenSSL' and not good_libcrypto.found()
24+
error('This version of OpenSSL does not support ed25519/curve25519. Please use -Duse_crypto25519=Reference or upgrade OpenSSL to 1.1.1 or later.')
25+
endif
26+
2227
code = '''#include <openssl/evp.h>
2328
int main(int argc, char **argv) {
2429
EVP_MD_CTX_free(NULL);
@@ -83,26 +88,26 @@ sources = [
8388
'vstdlib/strtools.cpp',
8489
]
8590

86-
if use_bcrypt
87-
dependencies += [ c_compiler.find_library('bcrypt') ]
88-
sources += [ 'common/crypto_bcrypt.cpp' ]
89-
cpp_flags += [ '-DED25519_HASH_BCRYPT', '-DSTEAMNETWORKINGSOCKETS_CRYPTO_BCRYPT' ]
90-
else
91+
if use_crypto == 'OpenSSL'
9192
cpp_flags += [ '-DSTEAMNETWORKINGSOCKETS_CRYPTO_VALVEOPENSSL' ]
9293
sources += [
9394
'common/opensslwrapper.cpp',
9495
'common/crypto_openssl.cpp',
9596
]
97+
endif
9698

97-
# Use OpenSSL for 25519 if possible
98-
if good_libcrypto.found()
99-
cpp_flags += [ '-DSTEAMNETWORKINGSOCKETS_CRYPTO_25519_OPENSSL' ]
100-
sources += [ 'common/crypto_25519_openssl.cpp' ]
101-
endif
99+
if use_crypto == 'BCrypt'
100+
dependencies += [ c_compiler.find_library('bcrypt') ]
101+
cpp_flags += [ '-DED25519_HASH_BCRYPT', '-DSTEAMNETWORKINGSOCKETS_CRYPTO_BCRYPT' ]
102+
sources += [ 'common/crypto_bcrypt.cpp' ]
103+
endif
104+
105+
if use_crypto25519 == 'OpenSSL'
106+
cpp_flags += [ '-DSTEAMNETWORKINGSOCKETS_CRYPTO_25519_OPENSSL' ]
107+
sources += [ 'common/crypto_25519_openssl.cpp' ]
102108
endif
103109

104-
# Use reference 25519 crypto implementation?
105-
if use_bcrypt or not good_libcrypto.found()
110+
if use_crypto25519 == 'Reference'
106111
cpp_flags += [ '-DVALVE_CRYPTO_25519_DONNA' ]
107112
sources += [
108113
'common/crypto_25519_donna.cpp',

0 commit comments

Comments
 (0)