diff options
author | Jack Lloyd <[email protected]> | 2017-08-31 13:13:00 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2017-08-31 13:13:00 -0400 |
commit | 16af7b986dbf9b04be45cdc075d70f81238269ad (patch) | |
tree | 6eee61aedd20fdbc364cb0f563ab87158eb8f9b9 | |
parent | c1e399ab2988284b431667ad514f6d31a32fea8f (diff) | |
parent | 0c33ef96d779ca781287006e4a55361ee76981a5 (diff) |
Merge GH #1169 Add LLVM bitcode target
-rwxr-xr-x | configure.py | 102 | ||||
-rw-r--r-- | src/build-data/arch/llvm.txt | 1 | ||||
-rw-r--r-- | src/build-data/cc/clang.txt | 9 | ||||
-rw-r--r-- | src/build-data/cc/gcc.txt | 3 | ||||
-rw-r--r-- | src/build-data/makefile/gmake.in | 4 | ||||
-rw-r--r-- | src/build-data/makefile/gmake_fuzzers.in | 4 | ||||
-rw-r--r-- | src/build-data/makefile/header.in | 4 | ||||
-rw-r--r-- | src/build-data/os/llvm.txt | 9 | ||||
-rw-r--r-- | src/cli/cli.h | 41 | ||||
-rw-r--r-- | src/cli/utils.cpp | 109 | ||||
-rw-r--r-- | src/fuzzer/fuzzers.h | 16 | ||||
-rw-r--r-- | src/lib/utils/mutex.h | 2 | ||||
-rw-r--r-- | src/lib/utils/os_utils.cpp | 2 | ||||
-rw-r--r-- | src/tests/main.cpp | 17 |
14 files changed, 200 insertions, 123 deletions
diff --git a/configure.py b/configure.py index 5d79aa012..7c617b919 100755 --- a/configure.py +++ b/configure.py @@ -186,9 +186,11 @@ class BuildPaths(object): # pylint: disable=too-many-instance-attributes if options.build_fuzzers: self.fuzzer_sources = list(find_sources_in(source_paths.src_dir, 'fuzzer')) self.fuzzer_output_dir = os.path.join(self.build_dir, 'fuzzer') + self.fuzzobj_dir = os.path.join(self.build_dir, 'obj', 'fuzzer') else: self.fuzzer_sources = None self.fuzzer_output_dir = None + self.fuzzobj_dir = None def build_dirs(self): out = [ @@ -203,6 +205,7 @@ class BuildPaths(object): # pylint: disable=too-many-instance-attributes if self.doc_output_dir_doxygen: out += [self.doc_output_dir_doxygen] if self.fuzzer_output_dir: + out += [self.fuzzobj_dir] out += [self.fuzzer_output_dir] return out @@ -214,7 +217,7 @@ class BuildPaths(object): # pylint: disable=too-many-instance-attributes elif typ == 'test': return (self.test_sources, self.testobj_dir) elif typ == 'fuzzer': - return (self.fuzzer_sources, self.fuzzer_output_dir) + return (self.fuzzer_sources, self.fuzzobj_dir) else: raise InternalError("Unknown src info type '%s'" % (typ)) @@ -426,7 +429,7 @@ def process_command_line(args): # pylint: disable=too-many-locals build_group.add_option('--build-fuzzers=', dest='build_fuzzers', metavar='TYPE', default=None, - help='Build fuzzers (afl, libfuzzer, test)') + help='Build fuzzers (afl, libfuzzer, klee, test)') build_group.add_option('--with-fuzzer-lib=', metavar='LIB', default=None, dest='fuzzer_lib', help='additionally link in LIB') @@ -1195,10 +1198,10 @@ class CompilerInfo(InfoObject): # pylint: disable=too-many-instance-attributes @staticmethod def _so_link_search(osname, debug_info): + so_link_typ = [osname, 'default'] if debug_info: - return [osname + '-debug', 'default-debug'] - else: - return [osname, 'default'] + so_link_typ = [l + '-debug' for l in so_link_typ] + so_link_typ + return so_link_typ def so_link_command_for(self, osname, options): """ @@ -1727,15 +1730,18 @@ class MakefileListsGenerator(object): return set() + def _fuzzer_bin_list(self, fuzzer_objs, bin_dir): + for obj in fuzzer_objs: + (_, name) = os.path.split(os.path.normpath(obj)) + name = name.replace('.' + self._osinfo.obj_suffix, '') + yield os.path.join(bin_dir, name) + def _objectfile_list(self, sources, obj_dir): + obj_suffix = '.' + self._osinfo.obj_suffix + for src in sources: (directory, filename) = os.path.split(os.path.normpath(src)) - - obj_suffix = '.' + self._osinfo.obj_suffix - parts = directory.split(os.sep) - if 'fuzzer' in parts: - obj_suffix = '' if 'src' in parts: parts = parts[parts.index('src')+2:] @@ -1766,14 +1772,12 @@ class MakefileListsGenerator(object): name = filename name = name.replace('.cpp', obj_suffix) - yield os.path.join(obj_dir, name) - def _build_commands(self, sources, obj_dir, flags): + def _build_commands(self, sources, obj_dir, objects, flags): """ Form snippets of makefile for building each source file """ - includes = self._cc.add_include_dir_option + self._build_paths.include_dir if self._build_paths.external_headers: includes += ' ' + self._cc.add_include_dir_option + self._build_paths.external_include_dir @@ -1782,33 +1786,38 @@ class MakefileListsGenerator(object): is_fuzzer = obj_dir.find('fuzzer') != -1 - if is_fuzzer: - for (obj_file, src) in zip(self._objectfile_list(sources, obj_dir), sources): + for (obj_file, src) in zip(objects, sources): + isa_specific_flags_str = "".join([" %s" % flagset for flagset in sorted(self._isa_specific_flags(src))]) - yield '%s: %s $(LIBRARIES)\n\t$(CXX) %s $(%s_FLAGS) %s -L. -lbotan-2 $(FUZZER_LINKS_TO) %s$@\n' % ( - obj_file, src, includes, flags, src, self._cc.output_to_option) - else: - for (obj_file, src) in zip(self._objectfile_list(sources, obj_dir), sources): - isa_specific_flags_str = "".join([" %s" % flagset for flagset in sorted(self._isa_specific_flags(src))]) + yield '%s: %s\n\t$(CXX)%s $(%s_FLAGS) %s %s %s %s$@\n' % ( + obj_file, src, isa_specific_flags_str, flags, + includes, self._cc.compile_flags, src, self._cc.output_to_option) - yield '%s: %s\n\t$(CXX)%s $(%s_FLAGS) %s %s %s %s$@\n' % ( - obj_file, src, isa_specific_flags_str, flags, - includes, self._cc.compile_flags, src, self._cc.output_to_option) + if is_fuzzer: + fuzz_basename = os.path.basename(obj_file).replace('.' + self._osinfo.obj_suffix, '') + fuzz_bin = self._build_paths.fuzzer_output_dir + yield '%s: %s $(LIBRARIES)\n\t$(FUZZER_LINK_CMD) %s $(FUZZER_LINKS_TO) %s$@\n' % ( + os.path.join(fuzz_bin, fuzz_basename), obj_file, obj_file, self._cc.output_to_option) def generate(self): out = {} - targets = ['lib', 'cli', 'test'] - if self._options.build_fuzzers: - targets += ['fuzzer'] + targets = ['lib', 'cli', 'test'] + \ + (['fuzzer'] if self._options.build_fuzzers else []) for t in targets: - obj_key = '%s_objs' % (t) src_list, src_dir = self._build_paths.src_info(t) src_list.sort() - out[obj_key] = makefile_list(self._objectfile_list(src_list, src_dir)) + objects = sorted(self._objectfile_list(src_list, src_dir)) + + obj_key = '%s_objs' % (t) + out[obj_key] = makefile_list(objects) + + if t == 'fuzzer': + out['fuzzer_bin'] = makefile_list(self._fuzzer_bin_list(objects, self._build_paths.fuzzer_output_dir)) + build_key = '%s_build_cmds' % (t) - out[build_key] = '\n'.join(self._build_commands(src_list, src_dir, t.upper())) + out[build_key] = '\n'.join(self._build_commands(src_list, src_dir, objects, t.upper())) return out @@ -1897,6 +1906,8 @@ def create_template_vars(source_paths, build_config, options, modules, cc, arch, main_executable = os.path.basename(sys.argv[0]) return ' '.join([main_executable] + sys.argv[1:]) + bin_link_cmd = cc.binary_link_command_for(osinfo.basename, options) + external_link_cmd() + variables = { 'version_major': Version.major, 'version_minor': Version.minor, @@ -1938,7 +1949,9 @@ def create_template_vars(source_paths, build_config, options, modules, cc, arch, 'libobj_dir': build_config.libobj_dir, 'cliobj_dir': build_config.cliobj_dir, 'testobj_dir': build_config.testobj_dir, - 'fuzzobj_dir': build_config.fuzzer_output_dir if build_config.fuzzer_output_dir else '', + 'fuzzobj_dir': build_config.fuzzobj_dir, + + 'fuzzer_output_dir': build_config.fuzzer_output_dir if build_config.fuzzer_output_dir else '', 'doc_output_dir': build_config.doc_output_dir, @@ -1966,9 +1979,9 @@ def create_template_vars(source_paths, build_config, options, modules, cc, arch, 'visibility_attribute': cc.gen_visibility_attribute(options), 'lib_link_cmd': cc.so_link_command_for(osinfo.basename, options) + external_link_cmd(), - 'cli_link_cmd': cc.binary_link_command_for(osinfo.basename, options) + external_link_cmd(), - 'test_link_cmd': cc.binary_link_command_for(osinfo.basename, options) + external_link_cmd(), - 'fuzzer_link_cmd': cc.binary_link_command_for(osinfo.basename, options) + external_link_cmd(), + 'cli_link_cmd': bin_link_cmd, + 'test_link_cmd': bin_link_cmd, + 'fuzzer_link_cmd': bin_link_cmd, 'link_to': ' '.join( [cc.add_lib_option + lib for lib in link_to('libs')] + @@ -2056,6 +2069,17 @@ def create_template_vars(source_paths, build_config, options, modules, cc, arch, # This can be made consistent over all platforms in the future variables['libname'] = 'botan-%d' % (Version.major) + if options.os == 'llvm': + # llvm-link doesn't understand -L or -l flags + variables['link_to_botan'] = '%s/lib%s.a' % (variables['out_dir'], variables['libname']) + elif options.compiler == 'msvc': + # Nmake makefiles do something completely different here... + variables['link_to_botan'] = '' + else: + variables['link_to_botan'] = '%s%s %s%s' % ( + cc.add_lib_dir_option, variables['out_dir'], + cc.add_lib_option, variables['libname']) + variables["header_in"] = process_template(os.path.join(source_paths.makefile_dir, 'header.in'), variables) if variables["makefile_style"] == "gmake": @@ -2910,8 +2934,13 @@ def validate_options(options, info_os, info_cc, available_module_policies): raise UserError("--destdir was removed. Use the DESTDIR environment " "variable instead when calling 'make install'") - # Warnings + if options.os == 'llvm' or options.cpu == 'llvm': + if options.compiler != 'clang': + raise UserError('LLVM target requires using Clang') + if options.os != options.cpu: + raise UserError('LLVM target requires both CPU and OS be set to llvm') + # Warnings if options.os == 'windows' and options.compiler == 'gcc': logging.warning('Detected GCC on Windows; use --os=cygwin or --os=mingw?') @@ -3045,12 +3074,15 @@ def main(argv): source_paths = SourcePaths(os.path.dirname(argv[0])) if options.build_fuzzers != None: - if options.build_fuzzers not in ['libfuzzer', 'afl', 'test']: + if options.build_fuzzers not in ['libfuzzer', 'afl', 'klee', 'test']: raise UserError('Bad value to --build-fuzzers') if options.build_fuzzers == 'libfuzzer' and options.fuzzer_lib is None: options.fuzzer_lib = 'Fuzzer' + if options.build_fuzzers == 'klee' and options.os != 'llvm': + raise UserError('Building for KLEE requires targetting LLVM') + info_modules = load_info_files(source_paths.lib_dir, 'Modules', "info.txt", ModuleInfo) info_arch = load_build_data_info_files(source_paths, 'CPU info', 'arch', ArchInfo) info_os = load_build_data_info_files(source_paths, 'OS info', 'os', OsInfo) diff --git a/src/build-data/arch/llvm.txt b/src/build-data/arch/llvm.txt new file mode 100644 index 000000000..3b8c13ffd --- /dev/null +++ b/src/build-data/arch/llvm.txt @@ -0,0 +1 @@ +wordsize 64 diff --git a/src/build-data/cc/clang.txt b/src/build-data/cc/clang.txt index 2afd530d3..865809792 100644 --- a/src/build-data/cc/clang.txt +++ b/src/build-data/cc/clang.txt @@ -31,22 +31,17 @@ makefile_style gmake <so_link_commands> darwin -> "$(CXX) -dynamiclib -fPIC -install_name $(INSTALLED_LIB_DIR)/$(SONAME_ABI) -current_version $(DARWIN_CURRENT_VER) -compatibility_version $(DARWIN_COMPATIBILITY_VER)" -darwin-debug -> "$(CXX) -dynamiclib -fPIC -install_name $(INSTALLED_LIB_DIR)/$(SONAME_ABI) -current_version $(DARWIN_CURRENT_VER) -compatibility_version $(DARWIN_COMPATIBILITY_VER)" # The default works for GNU ld and several other Unix linkers default -> "$(CXX) -shared -fPIC -Wl,-soname,$(SONAME_ABI)" -default-debug -> "$(CXX) -shared -fPIC -Wl,-soname,$(SONAME_ABI)" </so_link_commands> <binary_link_commands> darwin -> "$(LINKER) -headerpad_max_install_names" -darwin-debug -> "$(LINKER) -headerpad_max_install_names" linux -> "$(LINKER) -Wl,-rpath=\$$ORIGIN" -linux-debug -> "$(LINKER) -Wl,-rpath=\$$ORIGIN" freebsd -> "$(LINKER) -Wl,-rpath=\$$ORIGIN" -freebsd-debug -> "$(LINKER) -Wl,-rpath=\$$ORIGIN" default -> "$(LINKER)" -default-debug -> "$(LINKER)" +llvm -> "llvm-link" </binary_link_commands> <isa_flags> @@ -64,6 +59,8 @@ altivec -> "-maltivec" </isa_flags> <mach_opt> +all_llvm -> "-emit-llvm -fno-use-cxa-atexit" + x86_32 -> "-march=SUBMODEL" x86_64 -> "-march=SUBMODEL" nehalem -> "-march=corei7" diff --git a/src/build-data/cc/gcc.txt b/src/build-data/cc/gcc.txt index 5ace1931c..fdada6a3d 100644 --- a/src/build-data/cc/gcc.txt +++ b/src/build-data/cc/gcc.txt @@ -37,7 +37,6 @@ makefile_style gmake <so_link_commands> # The default works for GNU ld and several other Unix linkers default -> "$(CXX) -shared -fPIC -Wl,-soname,$(SONAME_ABI)" -default-debug -> "$(CXX) -shared -fPIC -Wl,-soname,$(SONAME_ABI)" # Darwin, HP-UX and Solaris linkers use different syntax darwin -> "$(CXX) -dynamiclib -fPIC -install_name $(LIBDIR)/$(SONAME_ABI)" @@ -51,9 +50,7 @@ openbsd -> "$(CXX) -shared -fPIC" <binary_link_commands> linux -> "$(LINKER) -Wl,-rpath=\$$ORIGIN" -linux-debug -> "$(LINKER) -Wl,-rpath=\$$ORIGIN" default -> "$(LINKER)" -default-debug -> "$(LINKER)" </binary_link_commands> <isa_flags> diff --git a/src/build-data/makefile/gmake.in b/src/build-data/makefile/gmake.in index 4b4426e5d..70b534503 100644 --- a/src/build-data/makefile/gmake.in +++ b/src/build-data/makefile/gmake.in @@ -38,11 +38,11 @@ cli: $(CLI) tests: $(TEST) $(CLI): $(LIBRARIES) $(CLIOBJS) - $(CLI_LINK_CMD) $(LDFLAGS) $(CLIOBJS) -L%{out_dir} -l%{libname} $(CLI_LINKS_TO) -o $(CLI) + $(CLI_LINK_CMD) $(LDFLAGS) $(CLIOBJS) $(CLI_LINKS_TO) -o $(CLI) $(CLI_POST_LINK_CMD) $(TEST): $(LIBRARIES) $(TESTOBJS) - $(TEST_LINK_CMD) $(LDFLAGS) $(TESTOBJS) -L%{out_dir} -l%{libname} $(TEST_LINKS_TO) -o $(TEST) + $(TEST_LINK_CMD) $(LDFLAGS) $(TESTOBJS) $(TEST_LINKS_TO) -o $(TEST) $(TEST_POST_LINK_CMD) $(STATIC_LIB): $(LIBOBJS) diff --git a/src/build-data/makefile/gmake_fuzzers.in b/src/build-data/makefile/gmake_fuzzers.in index 82fa8b256..62f7cdd29 100644 --- a/src/build-data/makefile/gmake_fuzzers.in +++ b/src/build-data/makefile/gmake_fuzzers.in @@ -2,12 +2,12 @@ # Fuzzer build commands FUZZER_LINK_CMD = %{fuzzer_link_cmd} -FUZZER_LINKS_TO = $(LIB_LINKS_TO) %{fuzzer_libs} +FUZZER_LINKS_TO = %{link_to_botan} $(LIB_LINKS_TO) %{fuzzer_libs} FUZZER_FLAGS = $(CXXFLAGS) $(WARN_FLAGS) %{fuzzer_build_cmds} -FUZZERS=%{fuzzer_objs} +FUZZERS=%{fuzzer_bin} fuzzers: libs $(FUZZERS) diff --git a/src/build-data/makefile/header.in b/src/build-data/makefile/header.in index 1114cf2d6..a63a83f3a 100644 --- a/src/build-data/makefile/header.in +++ b/src/build-data/makefile/header.in @@ -11,8 +11,8 @@ CLI_LINK_CMD = %{cli_link_cmd} TEST_LINK_CMD = %{test_link_cmd} LIB_LINKS_TO = %{link_to} -CLI_LINKS_TO = $(LIB_LINKS_TO) -TEST_LINKS_TO = $(LIB_LINKS_TO) +CLI_LINKS_TO = %{link_to_botan} $(LIB_LINKS_TO) +TEST_LINKS_TO = %{link_to_botan} $(LIB_LINKS_TO) LIB_FLAGS = $(SO_OBJ_FLAGS) $(CXXFLAGS) $(WARN_FLAGS) CLI_FLAGS = $(CXXFLAGS) $(WARN_FLAGS) diff --git a/src/build-data/os/llvm.txt b/src/build-data/os/llvm.txt new file mode 100644 index 000000000..119d641e4 --- /dev/null +++ b/src/build-data/os/llvm.txt @@ -0,0 +1,9 @@ + +obj_suffix bc +building_shared_supported no + +ar_command "llvm-link -o" + +<target_features> +filesystem +</target_features> diff --git a/src/cli/cli.h b/src/cli/cli.h index fcff94870..23cf0ff1c 100644 --- a/src/cli/cli.h +++ b/src/cli/cli.h @@ -11,14 +11,6 @@ #include <botan/parsing.h> #include <botan/rng.h> -#if defined(BOTAN_HAS_AUTO_SEEDING_RNG) - #include <botan/auto_rng.h> -#endif - -#if defined(BOTAN_HAS_SYSTEM_RNG) - #include <botan/system_rng.h> -#endif - #include <fstream> #include <iostream> #include <functional> @@ -30,6 +22,10 @@ namespace Botan_CLI { +/* Declared in utils.cpp */ +std::unique_ptr<Botan::RandomNumberGenerator> +cli_make_rng(const std::string& type, const std::string& hex_drbg_seed); + class CLI_Error : public std::runtime_error { public: @@ -334,11 +330,12 @@ class Command m_spec_opts.insert(std::make_pair("error-output", "")); #if defined(BOTAN_HAS_SYSTEM_RNG) - const auto availableRng = "system"; + const std::string availableRng = "system"; #else - const auto availableRng = "auto"; + const std::string availableRng = "user"; #endif m_spec_opts.insert(std::make_pair("rng-type", availableRng)); + m_spec_opts.insert(std::make_pair("drbg-seed", "")); } /* @@ -493,29 +490,7 @@ class Command { if(m_rng == nullptr) { - const std::string rng_type = get_arg("rng-type"); - - if(rng_type == "system") - { -#if defined(BOTAN_HAS_SYSTEM_RNG) - m_rng.reset(new Botan::System_RNG); -#endif - } - - // TODO --rng-type=drbg - // TODO --drbg-seed=hexstr - - if(rng_type == "auto") - { -#if defined(BOTAN_HAS_AUTO_SEEDING_RNG) - m_rng.reset(new Botan::AutoSeeded_RNG); -#endif - } - - if(!m_rng) - { - throw CLI_Error_Unsupported("rng", rng_type); - } + m_rng = cli_make_rng(get_arg("rng-type"), get_arg("drbg-seed")); } return *m_rng.get(); diff --git a/src/cli/utils.cpp b/src/cli/utils.cpp index 63e0fc7d6..ce461cb65 100644 --- a/src/cli/utils.cpp +++ b/src/cli/utils.cpp @@ -29,6 +29,10 @@ #include <botan/rdrand_rng.h> #endif +#if defined(BOTAN_HAS_HMAC_DRBG) + #include <botan/hmac_drbg.h> +#endif + #if defined(BOTAN_HAS_HTTP_UTIL) #include <botan/http_util.h> #endif @@ -47,6 +51,64 @@ namespace Botan_CLI { +std::unique_ptr<Botan::RandomNumberGenerator> +cli_make_rng(const std::string& rng_type, const std::string& hex_drbg_seed) + { +#if defined(BOTAN_HAS_SYSTEM_RNG) + if(rng_type == "system") + { + return std::unique_ptr<Botan::RandomNumberGenerator>(new Botan::System_RNG); + } +#endif + +#if defined(BOTAN_HAS_RDRAND_RNG) + if(rng_type == "rdrand") + { + if(Botan::CPUID::has_rdrand()) + return std::unique_ptr<Botan::RandomNumberGenerator>(new Botan::RDRAND_RNG); + else + throw CLI_Error("RDRAND instruction not supported on this processor"); + } +#endif + + const std::vector<uint8_t> drbg_seed = Botan::hex_decode(hex_drbg_seed); + +#if defined(BOTAN_HAS_AUTO_SEEDING_RNG) + if(rng_type == "auto" || rng_type == "entropy") + { + std::unique_ptr<Botan::RandomNumberGenerator> rng; + + if(rng_type == "entropy") + rng.reset(new Botan::AutoSeeded_RNG(Botan::Entropy_Sources::global_sources())); + else + rng.reset(new Botan::AutoSeeded_RNG); + + if(drbg_seed.size() > 0) + rng->add_entropy(drbg_seed.data(), drbg_seed.size()); + return rng; + } +#endif + +#if defined(BOTAN_HAS_HMAC_DRBG) + if(rng_type == "drbg") + { + std::unique_ptr<Botan::MessageAuthenticationCode> mac = + Botan::MessageAuthenticationCode::create(BOTAN_AUTO_RNG_HMAC); + std::unique_ptr<Botan::Stateful_RNG> rng(new Botan::HMAC_DRBG(std::move(mac))); + rng->add_entropy(drbg_seed.data(), drbg_seed.size()); + + if(rng->is_seeded() == false) + throw CLI_Error("For " + rng->name() + " a seed of at least " + + std::to_string(rng->security_level()/8) + + " bytes must be provided"); + + return std::unique_ptr<Botan::RandomNumberGenerator>(rng.release()); + } +#endif + + throw CLI_Error_Unsupported("RNG", rng_type); + } + class Config_Info final : public Command { public: @@ -170,49 +232,24 @@ BOTAN_REGISTER_COMMAND("hash", Hash); class RNG final : public Command { public: - RNG() : Command("rng --system --rdrand --entropy *bytes") {} + RNG() : Command("rng --system --rdrand --auto --entropy --drbg --drbg-seed= *bytes") {} void go() override { - std::unique_ptr<Botan::RNG> rng; + std::string type = "auto"; // default - if(flag_set("system")) - { -#if defined(BOTAN_HAS_SYSTEM_RNG) - rng.reset(new Botan::System_RNG); -#else - error_output() << "system_rng disabled in build\n"; - return; -#endif - } - else if(flag_set("rdrand")) + for(std::string flag : { "system", "rdrand", "auto", "entropy", "drbg" }) { -#if defined(BOTAN_HAS_RDRAND_RNG) - rng.reset(new Botan::RDRAND_RNG); -#else - error_output() << "rdrand_rng disabled in build\n"; - return; -#endif - } - else if(flag_set("entropy")) - { -#if defined(BOTAN_HAS_AUTO_SEEDING_RNG) - rng.reset(new Botan::AutoSeeded_RNG(Botan::Entropy_Sources::global_sources())); -#else - error_output() << "auto_rng disabled in build\n"; - return; -#endif - } - else - { -#if defined(BOTAN_HAS_AUTO_SEEDING_RNG) - rng.reset(new Botan::AutoSeeded_RNG); -#else - error_output() << "auto_rng disabled in build\n"; - return; -#endif + if(flag_set(flag)) + { + type = flag; + break; + } } + const std::string drbg_seed = get_arg("drbg-seed"); + std::unique_ptr<Botan::RNG> rng = cli_make_rng(type, drbg_seed); + for(const std::string& req : get_arg_list("bytes")) { output() << Botan::hex_encode(rng->random_vec(Botan::to_u32bit(req))) << "\n"; diff --git a/src/fuzzer/fuzzers.h b/src/fuzzer/fuzzers.h index 2f1b1346d..d0e6b85f5 100644 --- a/src/fuzzer/fuzzers.h +++ b/src/fuzzer/fuzzers.h @@ -90,6 +90,22 @@ int main(int argc, char* argv[]) } } +#elif defined(BOTAN_FUZZER_IS_KLEE) + +#include <klee/klee.h> + +int main(int argc, char* argv[]) + { + LLVMFuzzerInitialize(&argc, &argv); + + uint8_t input[max_fuzzer_input_size] = { 0 }; + klee_make_symbolic(&input, sizeof(input), "input"); + + size_t input_len = klee_range(0, sizeof(input), "input_len"); + + LLVMFuzzerTestOneInput(input, input_len); + } + #endif #endif diff --git a/src/lib/utils/mutex.h b/src/lib/utils/mutex.h index 0daea3148..2aabd2973 100644 --- a/src/lib/utils/mutex.h +++ b/src/lib/utils/mutex.h @@ -21,7 +21,7 @@ typedef std::mutex mutex_type; } -#elif defined(BOTAN_TARGET_OS_TYPE_IS_UNIKERNEL) +#elif defined(BOTAN_TARGET_OS_TYPE_IS_UNIKERNEL) || defined(BOTAN_TARGET_OS_IS_LLVM) // No threads diff --git a/src/lib/utils/os_utils.cpp b/src/lib/utils/os_utils.cpp index e887d6e76..d08e7e040 100644 --- a/src/lib/utils/os_utils.cpp +++ b/src/lib/utils/os_utils.cpp @@ -34,7 +34,7 @@ uint32_t OS::get_process_id() return ::getpid(); #elif defined(BOTAN_TARGET_OS_IS_WINDOWS) || defined(BOTAN_TARGET_OS_IS_MINGW) return ::GetCurrentProcessId(); -#elif defined(BOTAN_TARGET_OS_TYPE_IS_UNIKERNEL) +#elif defined(BOTAN_TARGET_OS_TYPE_IS_UNIKERNEL) || defined(BOTAN_TARGET_OS_IS_LLVM) return 0; // truly no meaningful value #else #error "Missing get_process_id" diff --git a/src/tests/main.cpp b/src/tests/main.cpp index e30c268c0..ae1ad18a7 100644 --- a/src/tests/main.cpp +++ b/src/tests/main.cpp @@ -11,8 +11,6 @@ #include <string> #include <set> #include <deque> -#include <thread> -#include <future> #include <cstdlib> #include <botan/version.h> @@ -35,6 +33,11 @@ #include <botan/internal/openssl.h> #endif +#if defined(BOTAN_TARGET_OS_HAS_THREADS) + #include <thread> + #include <future> +#endif + namespace { class Test_Runner : public Botan_CLI::Command @@ -192,7 +195,12 @@ class Test_Runner : public Botan_CLI::Command std::unique_ptr<Botan::HMAC_DRBG> drbg(new Botan::HMAC_DRBG("SHA-384")); drbg->initialize_with(seed.data(), seed.size()); + +#if defined(BOTAN_TARGET_OS_HAS_THREADS) rng.reset(new Botan::Serialized_RNG(drbg.release())); +#else + rng = std::move(drbg); +#endif #else @@ -323,6 +331,7 @@ class Test_Runner : public Botan_CLI::Command else { +#if defined(BOTAN_TARGET_OS_HAS_THREADS) /* We're not doing this in a particularly nice way, and variance in time is high so commonly we'll 'run dry' by blocking on the first future. But @@ -365,6 +374,10 @@ class Test_Runner : public Botan_CLI::Command out << report_out(fut_results[0].get(), tests_failed, tests_ran) << std::flush; fut_results.pop_front(); } +#else + out << "Threading support disabled\n"; + return 1; +#endif } const uint64_t total_ns = Botan_Tests::Test::timestamp() - start_time; |