Skip to content

Commit cfe2cf8

Browse files
pks-tgitster
authored andcommitted
meson: make the CSPRNG backend configurable
The CSPRNG backend is not configurable in Meson and isn't quite discoverable, either. Make it configurable and add the actual backend used to the summary. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5d5004f commit cfe2cf8

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

meson.build

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1325,6 +1325,7 @@ if not meson.is_cross_build() and fs.exists('/dev/tty')
13251325
libgit_c_args += '-DHAVE_DEV_TTY'
13261326
endif
13271327

1328+
csprng_backend = get_option('csprng_backend')
13281329
https_backend = get_option('https_backend')
13291330
sha1_backend = get_option('sha1_backend')
13301331
sha1_unsafe_backend = get_option('sha1_unsafe_backend')
@@ -1336,7 +1337,7 @@ if https_backend == 'auto' and security_framework.found()
13361337
https_backend = 'CommonCrypto'
13371338
endif
13381339

1339-
openssl_required = 'openssl' in [https_backend, sha1_backend, sha1_unsafe_backend, sha256_backend]
1340+
openssl_required = 'openssl' in [csprng_backend, https_backend, sha1_backend, sha1_unsafe_backend, sha256_backend]
13401341
openssl = dependency('openssl', required: openssl_required, default_options: ['default_library=static'])
13411342
if https_backend == 'auto' and openssl.found()
13421343
https_backend = 'openssl'
@@ -1421,18 +1422,28 @@ else
14211422
error('Unhandled SHA256 backend ' + sha256_backend)
14221423
endif
14231424

1424-
if compiler.has_header_symbol('stdlib.h', 'arc4random_buf')
1425+
if csprng_backend in ['auto', 'arc4random'] and compiler.has_header_symbol('stdlib.h', 'arc4random_buf', required: csprng_backend == 'arc4random')
14251426
libgit_c_args += '-DHAVE_ARC4RANDOM'
1426-
elif compiler.has_header_symbol('bsd/stdlib.h', 'arc4random_buf')
1427+
csprng_backend = 'arc4random'
1428+
elif csprng_backend in ['auto', 'arc4random_bsd'] and compiler.has_header_symbol('bsd/stdlib.h', 'arc4random_buf', required: csprng_backend == 'arc4random_bsd')
14271429
libgit_c_args += '-DHAVE_ARC4RANDOM_BSD'
1428-
elif compiler.has_function('getrandom', prefix: '#include <sys/random.h>')
1430+
csprng_backend = 'arc4random_bsd'
1431+
elif csprng_backend in ['auto', 'getrandom'] and compiler.has_function('getrandom', prefix: '#include <sys/random.h>', required: csprng_backend == 'getrandom')
14291432
libgit_c_args += '-DHAVE_GETRANDOM'
1430-
elif compiler.has_function('getentropy', prefix: '#include <unistd.h>')
1433+
csprng_backend = 'getrandom'
1434+
elif csprng_backend in ['auto', 'getentropy'] and compiler.has_function('getentropy', prefix: '#include <unistd.h>', required: csprng_backend == 'getentropy')
14311435
libgit_c_args += '-DHAVE_GETENTROPY'
1432-
elif compiler.has_function('RtlGenRandom', prefix: '#include <windows.h>\n#include <ntsecapi.h>')
1436+
csprng_backend = 'getentropy'
1437+
elif csprng_backend in ['auto', 'rtlgenrandom'] and compiler.has_function('RtlGenRandom', prefix: '#include <windows.h>\n#include <ntsecapi.h>', required: csprng_backend == 'rtlgenrandom')
14331438
libgit_c_args += '-DHAVE_RTLGENRANDOM'
1434-
elif openssl.found()
1439+
csprng_backend = 'rtlgenrandom'
1440+
elif csprng_backend in ['auto', 'openssl'] and openssl.found()
14351441
libgit_c_args += '-DHAVE_OPENSSL_CSPRNG'
1442+
csprng_backend = 'openssl'
1443+
elif csprng_backend in ['auto', 'urandom']
1444+
csprng_backend = 'urandom'
1445+
else
1446+
error('Unsupported CSPRNG backend: ' + csprng_backend)
14361447
endif
14371448

14381449
if get_option('runtime_prefix')
@@ -1969,6 +1980,7 @@ summary({
19691980
}, section: 'Auto-detected features')
19701981

19711982
summary({
1983+
'csprng': csprng_backend,
19721984
'https': https_backend,
19731985
'sha1': sha1_backend,
19741986
'sha1_unsafe': sha1_unsafe_backend,

meson_options.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ option('regex', type: 'feature', value: 'auto',
4747
description: 'Use the system-provided regex library instead of the bundled one.')
4848

4949
# Backends.
50+
option('csprng_backend', type: 'combo', value: 'auto', choices: ['auto', 'arc4random', 'arc4random_bsd', 'getrandom', 'getentropy', 'rtlgenrandom', 'openssl', 'urandom'],
51+
description: 'The backend to use for generating cryptographically-secure pseudo-random numbers.')
5052
option('https_backend', type: 'combo', value: 'auto', choices: ['auto', 'openssl', 'CommonCrypto', 'none'],
5153
description: 'The HTTPS backend to use when connecting to remotes.')
5254
option('sha1_backend', type: 'combo', choices: ['openssl', 'block', 'sha1dc', 'CommonCrypto'], value: 'sha1dc',

0 commit comments

Comments
 (0)