1*f0865ec9SKyle Evansproject('libecc', 'c', 2*f0865ec9SKyle Evans meson_version: '>=1.1.0', 3*f0865ec9SKyle Evans version: run_command('dunamai', 'from', 'git', '--style', 'semver', '--dirty', check: true).stdout().strip(), 4*f0865ec9SKyle Evans default_options: ['c_std=gnu11', 'default_library=static', 'warning_level=3' ], 5*f0865ec9SKyle Evans license: 'BSD-3-Clause OR GPL-2.0-or-later', 6*f0865ec9SKyle Evans license_files: [ 'LICENSE' ], 7*f0865ec9SKyle Evans) 8*f0865ec9SKyle Evans 9*f0865ec9SKyle Evanstop_dir = meson.current_source_dir() 10*f0865ec9SKyle Evans 11*f0865ec9SKyle Evans# dunamai is used for version sync with gconf (in the same way poetry-dynamic-versioning does) 12*f0865ec9SKyle Evanspymod = import('python') 13*f0865ec9SKyle Evanspy3 = pymod.find_installation('python3', modules: ['dunamai']) 14*f0865ec9SKyle Evans 15*f0865ec9SKyle Evans# about libecc 16*f0865ec9SKyle Evans# below file listings should be moved in successive small 'meson.build' file in each subdir, that 17*f0865ec9SKyle Evans# only contains the file listing, replacing them with a lonely 'subdir('src/xxx') instead. 18*f0865ec9SKyle Evans 19*f0865ec9SKyle Evansecc_inc = include_directories('include') 20*f0865ec9SKyle Evanssubdir('include/libecc') 21*f0865ec9SKyle Evans 22*f0865ec9SKyle Evans# module declaration, each module files listing is declare in its own directory 23*f0865ec9SKyle Evanssubdir('src/utils') 24*f0865ec9SKyle Evanssubdir('src/nn') 25*f0865ec9SKyle Evanssubdir('src/fp') 26*f0865ec9SKyle Evanssubdir('src/curves') 27*f0865ec9SKyle Evanssubdir('src/hash') 28*f0865ec9SKyle Evanssubdir('src/sig') 29*f0865ec9SKyle Evanssubdir('src/ecdh') 30*f0865ec9SKyle Evanssubdir('src/external_deps') 31*f0865ec9SKyle Evans 32*f0865ec9SKyle Evans# detect if an external rand source implementation is passed 33*f0865ec9SKyle Evansuse_external_rand_opt = get_option('use_external_rand') 34*f0865ec9SKyle Evansif use_external_rand_opt 35*f0865ec9SKyle Evans rand_src = files(get_option('with_rand_source')) 36*f0865ec9SKyle Evanselse 37*f0865ec9SKyle Evans rand_src = files() 38*f0865ec9SKyle Evansendif 39*f0865ec9SKyle Evans# detect if an external print source implementation is passed 40*f0865ec9SKyle Evansuse_external_print_opt = get_option('use_external_print') 41*f0865ec9SKyle Evansif use_external_print_opt 42*f0865ec9SKyle Evans print_src = files(get_option('with_print_source')) 43*f0865ec9SKyle Evanselse 44*f0865ec9SKyle Evans print_src = files() 45*f0865ec9SKyle Evansendif 46*f0865ec9SKyle Evans# detect if an external time source implementation is passed 47*f0865ec9SKyle Evansuse_external_time_opt = get_option('use_external_time') 48*f0865ec9SKyle Evansif use_external_time_opt 49*f0865ec9SKyle Evans time_src = files(get_option('with_time_source')) 50*f0865ec9SKyle Evanselse 51*f0865ec9SKyle Evans time_src = files() 52*f0865ec9SKyle Evansendif 53*f0865ec9SKyle Evans 54*f0865ec9SKyle Evans 55*f0865ec9SKyle Evans# globally used build args, TODO: to make configurable 56*f0865ec9SKyle Evansbuild_args = [ 57*f0865ec9SKyle Evans '-fno-builtin', 58*f0865ec9SKyle Evans '-D_FORTIFY_SOURCE=2', 59*f0865ec9SKyle Evans '-fstack-protector-strong', 60*f0865ec9SKyle Evans '-DUSE_WARN_UNUSED_RET', 61*f0865ec9SKyle Evans '-ffreestanding' 62*f0865ec9SKyle Evans] 63*f0865ec9SKyle Evans 64*f0865ec9SKyle Evans 65*f0865ec9SKyle Evans# About configurable options, based on makefiles 66*f0865ec9SKyle Evans 67*f0865ec9SKyle Evans# 1. build-relative options first 68*f0865ec9SKyle Evans 69*f0865ec9SKyle Evans# info compilers arguments (such as m32/m64 should be cross-file related. 70*f0865ec9SKyle Evans# just using a different cross-file (event for m32 on m64 arch for e.g. is enough 71*f0865ec9SKyle Evans# to change the behavior 72*f0865ec9SKyle Evanswith_wordsize_opt = get_option('with_wordsize') 73*f0865ec9SKyle Evansif with_wordsize_opt == '16' 74*f0865ec9SKyle Evans build_args += '-DWORDSIZE=16' 75*f0865ec9SKyle Evanselif with_wordsize_opt == '32' 76*f0865ec9SKyle Evans build_args += '-DWORDSIZE=32' 77*f0865ec9SKyle Evanselif with_wordsize_opt == '64' 78*f0865ec9SKyle Evans build_args += '-DWORDSIZE=64' 79*f0865ec9SKyle Evansendif 80*f0865ec9SKyle Evans 81*f0865ec9SKyle Evanswith_stdlib_opt = get_option('with_stdlib') 82*f0865ec9SKyle Evansif with_stdlib_opt 83*f0865ec9SKyle Evans build_args += '-DWITH_STDLIB' 84*f0865ec9SKyle Evansendif 85*f0865ec9SKyle Evans 86*f0865ec9SKyle Evanswith_debug_opt = get_option('with_debug') 87*f0865ec9SKyle Evansif with_debug_opt 88*f0865ec9SKyle Evans build_args += '-DDEBUG' 89*f0865ec9SKyle Evansendif 90*f0865ec9SKyle Evans 91*f0865ec9SKyle Evansuse_cryptofuzz_opt = get_option('use_cryptofuzz') 92*f0865ec9SKyle Evansif use_cryptofuzz_opt 93*f0865ec9SKyle Evans build_args += '-DUSE_CRYPTOFUZZ' 94*f0865ec9SKyle Evansendif 95*f0865ec9SKyle Evans 96*f0865ec9SKyle Evansassert_print_opt = get_option('assert_print') 97*f0865ec9SKyle Evansif assert_print_opt 98*f0865ec9SKyle Evans build_args += '-DUSE_ASSERT_PRINT' 99*f0865ec9SKyle Evansendif 100*f0865ec9SKyle Evans 101*f0865ec9SKyle Evansno_warn_unused_ret_opt = get_option('no_warn_unused_ret') 102*f0865ec9SKyle Evansif not no_warn_unused_ret_opt 103*f0865ec9SKyle Evans build_args += '-DUSE_WARN_UNUSED_RET' 104*f0865ec9SKyle Evansendif 105*f0865ec9SKyle Evans 106*f0865ec9SKyle Evans# 2. security relative options 107*f0865ec9SKyle Evans 108*f0865ec9SKyle Evanswith_sig_blinding_opt = get_option('with_sig_blinding') 109*f0865ec9SKyle Evansif with_sig_blinding_opt 110*f0865ec9SKyle Evans build_args += '-DUSE_SIG_BLINDING' 111*f0865ec9SKyle Evansendif 112*f0865ec9SKyle Evans 113*f0865ec9SKyle Evanswith_complete_formulas_opt = get_option('with_complete_formulas') 114*f0865ec9SKyle Evansif with_complete_formulas_opt 115*f0865ec9SKyle Evans build_args += '-DNO_USE_COMPLETE_FORMULAS' 116*f0865ec9SKyle Evansendif 117*f0865ec9SKyle Evans 118*f0865ec9SKyle Evanswith_double_add_opt = get_option('with_double_add') 119*f0865ec9SKyle Evansif with_double_add_opt == 'true' 120*f0865ec9SKyle Evans build_args += '-DUSE_DOUBLE_ADD_ALWAYS' 121*f0865ec9SKyle Evanselif with_double_add_opt == 'false' 122*f0865ec9SKyle Evans build_args += '-DUSE_MONTY_LADDER' 123*f0865ec9SKyle Evansendif 124*f0865ec9SKyle Evans 125*f0865ec9SKyle Evanswith_monty_ladder_opt = get_option('with_monty_ladder') 126*f0865ec9SKyle Evansif with_monty_ladder_opt == 'true' 127*f0865ec9SKyle Evans build_args += '-DUSE_MONTY_LADDER' 128*f0865ec9SKyle Evanselif with_monty_ladder_opt == 'false' 129*f0865ec9SKyle Evans build_args += '-DUSE_DOUBLE_ADD_ALWAYS' 130*f0865ec9SKyle Evansendif 131*f0865ec9SKyle Evans 132*f0865ec9SKyle Evansassert(not (with_double_add_opt == 'true' and with_monty_ladder_opt == 'true'), 'with_double_add and with_monty_ladder are incompatible options!') 133*f0865ec9SKyle Evans 134*f0865ec9SKyle Evans# 3. crypto engines relative options. It is possible to fully disable all 135*f0865ec9SKyle Evans# engines and manually select which one must be built 136*f0865ec9SKyle Evans 137*f0865ec9SKyle Evanswith_override_ecc_config_opt = get_option('with_override_ecc_config') 138*f0865ec9SKyle Evansif with_override_ecc_config_opt 139*f0865ec9SKyle Evans build_args += '-DWITH_LIBECC_CONFIG_OVERRIDE' 140*f0865ec9SKyle Evansendif 141*f0865ec9SKyle Evans 142*f0865ec9SKyle Evansif with_override_ecc_config_opt 143*f0865ec9SKyle Evans # Handle the asked curves 144*f0865ec9SKyle Evans with_curves_opt = get_option('with_curves') 145*f0865ec9SKyle Evans assert(with_curves_opt.length() != 0, 'You have selected a libecc configuration override with no curve: please select at least one proper curve!') 146*f0865ec9SKyle Evans foreach curve : with_curves_opt 147*f0865ec9SKyle Evans build_args += '-DWITH_CURVE_'+curve.to_upper() 148*f0865ec9SKyle Evans endforeach 149*f0865ec9SKyle Evans # Handle the asked hashes 150*f0865ec9SKyle Evans with_hashes_opt = get_option('with_hashes') 151*f0865ec9SKyle Evans assert(with_hashes_opt.length() != 0, 'You have selected a libecc configuration override with no hash: please select at least one proper hash!') 152*f0865ec9SKyle Evans foreach hash : with_hashes_opt 153*f0865ec9SKyle Evans build_args += '-DWITH_HASH_'+hash.to_upper() 154*f0865ec9SKyle Evans endforeach 155*f0865ec9SKyle Evans # Handle the asked algorithms 156*f0865ec9SKyle Evans with_algs_opt = get_option('with_algs') 157*f0865ec9SKyle Evans assert(with_algs_opt.length() != 0, 'You have selected a libecc configuration override with no algorithm: please select at least one proper algorithm!') 158*f0865ec9SKyle Evans foreach alg : with_algs_opt 159*f0865ec9SKyle Evans build_args += '-DWITH_'+alg.to_upper() 160*f0865ec9SKyle Evans endforeach 161*f0865ec9SKyle Evansendif 162*f0865ec9SKyle Evans 163*f0865ec9SKyle Evans# Small stack handling 164*f0865ec9SKyle Evanswith_small_stack_opt = get_option('with_small_stack') 165*f0865ec9SKyle Evansif with_small_stack_opt 166*f0865ec9SKyle Evans build_args += '-DUSE_SMALL_STACK' 167*f0865ec9SKyle Evansendif 168*f0865ec9SKyle Evansassert(not (with_small_stack_opt and with_sig_eddsa25519_opt), 'Small stack and EdDSA are incompatible options!') 169*f0865ec9SKyle Evansassert(not (with_small_stack_opt and with_sig_eddsa448_opt), 'Small stack and EdDSA are incompatible options!') 170*f0865ec9SKyle Evansassert(not (with_small_stack_opt and with_x25519_opt), 'Small stack and X25519 are incompatible options!') 171*f0865ec9SKyle Evansassert(not (with_small_stack_opt and with_x448_opt), 'Small stack and X448 are incompatible options!') 172*f0865ec9SKyle Evans 173*f0865ec9SKyle Evans 174*f0865ec9SKyle Evans# libecc libraries declaration. For each library, the library itself and the 175*f0865ec9SKyle Evans# corresponding dependency object (includedir and library to link with) is 176*f0865ec9SKyle Evans# also declared 177*f0865ec9SKyle Evans# 178*f0865ec9SKyle Evans# INFO: defaulting to static lib only (see project declaration). 179*f0865ec9SKyle Evans# to build both static and dynamic library, use -Ddefault_library=both option 180*f0865ec9SKyle Evans# 181*f0865ec9SKyle Evanslibarith_lib = library('arith', 182*f0865ec9SKyle Evans sources: [ 183*f0865ec9SKyle Evans fp_mod_src, 184*f0865ec9SKyle Evans nn_mod_src, 185*f0865ec9SKyle Evans rand_src, 186*f0865ec9SKyle Evans print_src, 187*f0865ec9SKyle Evans time_src, 188*f0865ec9SKyle Evans utils_arith_src, 189*f0865ec9SKyle Evans ], 190*f0865ec9SKyle Evans include_directories: ecc_inc, 191*f0865ec9SKyle Evans install : true, 192*f0865ec9SKyle Evans c_args: build_args, 193*f0865ec9SKyle Evans) 194*f0865ec9SKyle Evanslibarith_dep = declare_dependency( 195*f0865ec9SKyle Evans link_with: libarith_lib, 196*f0865ec9SKyle Evans include_directories: ecc_inc, 197*f0865ec9SKyle Evans) 198*f0865ec9SKyle Evans 199*f0865ec9SKyle Evanslibec_lib = library('ecc', 200*f0865ec9SKyle Evans sources: [ 201*f0865ec9SKyle Evans curves_mod_src, 202*f0865ec9SKyle Evans utils_ec_src, 203*f0865ec9SKyle Evans fp_mod_src, 204*f0865ec9SKyle Evans nn_mod_src, 205*f0865ec9SKyle Evans rand_src, 206*f0865ec9SKyle Evans print_src, 207*f0865ec9SKyle Evans time_src, 208*f0865ec9SKyle Evans utils_arith_src 209*f0865ec9SKyle Evans ], 210*f0865ec9SKyle Evans include_directories: ecc_inc, 211*f0865ec9SKyle Evans install : true, 212*f0865ec9SKyle Evans c_args: build_args, 213*f0865ec9SKyle Evans) 214*f0865ec9SKyle Evanslibec_dep = declare_dependency( 215*f0865ec9SKyle Evans link_with: libec_lib, 216*f0865ec9SKyle Evans include_directories: ecc_inc, 217*f0865ec9SKyle Evans) 218*f0865ec9SKyle Evans 219*f0865ec9SKyle Evanslibsign_lib = library('sign', 220*f0865ec9SKyle Evans sources: [ 221*f0865ec9SKyle Evans hash_mod_src, 222*f0865ec9SKyle Evans sig_mod_src, 223*f0865ec9SKyle Evans key_mod_src, 224*f0865ec9SKyle Evans utils_sign_src, 225*f0865ec9SKyle Evans ecdh_mod_src, 226*f0865ec9SKyle Evans curves_mod_src, 227*f0865ec9SKyle Evans utils_ec_src, 228*f0865ec9SKyle Evans fp_mod_src, 229*f0865ec9SKyle Evans nn_mod_src, 230*f0865ec9SKyle Evans rand_src, 231*f0865ec9SKyle Evans print_src, 232*f0865ec9SKyle Evans time_src, 233*f0865ec9SKyle Evans utils_arith_src 234*f0865ec9SKyle Evans ], 235*f0865ec9SKyle Evans include_directories: ecc_inc, 236*f0865ec9SKyle Evans install : true, 237*f0865ec9SKyle Evans c_args: build_args, 238*f0865ec9SKyle Evans) 239*f0865ec9SKyle Evanslibsign_dep = declare_dependency( 240*f0865ec9SKyle Evans link_with: libsign_lib, 241*f0865ec9SKyle Evans include_directories: ecc_inc, 242*f0865ec9SKyle Evans) 243*f0865ec9SKyle Evans 244*f0865ec9SKyle Evans# in order to build native tools that depends on libsign library, we should 245*f0865ec9SKyle Evans# check if the nominal library built has been made native or cross. If 246*f0865ec9SKyle Evans# cross, another build must be made natively for native tooling 247*f0865ec9SKyle Evansif meson.is_cross_build() 248*f0865ec9SKyle Evans native_libsign_lib = library('sign_native', 249*f0865ec9SKyle Evans sources: [ 250*f0865ec9SKyle Evans hash_mod_src, 251*f0865ec9SKyle Evans sig_mod_src, 252*f0865ec9SKyle Evans key_mod_src, 253*f0865ec9SKyle Evans utils_sign_src, 254*f0865ec9SKyle Evans ecdh_mod_src, 255*f0865ec9SKyle Evans curves_mod_src, 256*f0865ec9SKyle Evans utils_ec_src, 257*f0865ec9SKyle Evans fp_mod_src, 258*f0865ec9SKyle Evans nn_mod_src, 259*f0865ec9SKyle Evans rand_src, 260*f0865ec9SKyle Evans print_src, 261*f0865ec9SKyle Evans time_src, 262*f0865ec9SKyle Evans utils_arith_src 263*f0865ec9SKyle Evans ], 264*f0865ec9SKyle Evans include_directories: ecc_inc, 265*f0865ec9SKyle Evans install : false, 266*f0865ec9SKyle Evans c_args: build_args, 267*f0865ec9SKyle Evans native: true, 268*f0865ec9SKyle Evans ) 269*f0865ec9SKyle Evans native_libsign_dep = declare_dependency( 270*f0865ec9SKyle Evans link_with: native_libsign_lib, 271*f0865ec9SKyle Evans include_directories: ecc_inc, 272*f0865ec9SKyle Evans ) 273*f0865ec9SKyle Evanselse 274*f0865ec9SKyle Evans native_libsign_lib = libsign_lib 275*f0865ec9SKyle Evans native_libsign_dep = libsign_dep 276*f0865ec9SKyle Evansendif 277*f0865ec9SKyle Evans 278*f0865ec9SKyle Evans# About tests, see src/tests/meson.build. Enabled with -Dwith_tests=true 279*f0865ec9SKyle Evanswith_tests_opt = get_option('with_tests') 280*f0865ec9SKyle Evansif with_tests_opt 281*f0865ec9SKyle Evans subdir('src/tests') 282*f0865ec9SKyle Evansendif 283