diff options
35 files changed, 1250 insertions, 222 deletions
diff --git a/checks/misc.cpp b/checks/misc.cpp index 82b207196..198671451 100644 --- a/checks/misc.cpp +++ b/checks/misc.cpp @@ -25,8 +25,10 @@ void strip(std::string& line) { strip_comments(line); +#if 0 while(line.find(' ') != std::string::npos) line = line.erase(line.find(' '), 1); +#endif while(line.find('\t') != std::string::npos) line = line.erase(line.find('\t'), 1); diff --git a/checks/validate.dat b/checks/validate.dat index 40b246da4..05a9b98bb 100644 --- a/checks/validate.dat +++ b/checks/validate.dat @@ -44906,8 +44906,6 @@ DB892CAFD8387E05B3012C0458A369E62191F5BDC57DD63CE42E945F493C2B42\ 306B8084F3B25E94ABACF08EE155F3621ACC9626EE487C7A7E4667F0377AE4B2:\ 5FD345F57D96137E3463DAD7EEE20492536BC115981050DFCB2AC0FE0B7215C3 - - [Skein-512(264)] 0000000000000000000000000000000000000000000000000000000000000000\ 0000000000000000000000000000000000000000000000000000000000000000\ @@ -58432,6 +58430,27 @@ DB892CAFD8387E05B3012C0458A369E62191F5BDC57DD63CE42E945F493C2B42\ D5FBBB2DDADCD01816C44DEFFBE256535723F5F260A8ABA72332B4025FD5CC5B\ CE5B2DCB4A115FC015817CB1581F205D8C86CF02D5CC7EF52192322FB2C2DEF7\ +[Skein-512(512,20090606 [email protected] BOTAN/test)] +:\ +E6FE2E3E0A2CFDC34B9F4E79CB36CCD9C3A2E0A9BE435B6263E00F4B4642B583\ +30D68F876ACF71D257878E46DE54A9B49245779450EB4C0E005AE74E87C39FD0 + +52A608AB21CCDD8A4457A57EDE782176:\ +FF6E78DB1400B9B7FD29698A5DB3B6A44F843AAE6070DC22330BDCCC72E0E03E\ +4B2D20015A3A45FBCDA50AD6A919AD43F2146BCB22736E8E0CF7F608E8735B1C + +E926AE8B0AF6E53176DBFFCC2A6B88C6BD765F939D3D178A9BDE9EF3AA131C61\ +E31C1E42CDFAF4B4DCDE579A37E150EFBEF5555B4C1CB40439D835A724E2FAE7:\ +21401CEA630E80AE15D0B18CE0404EF5D226CD25EB64698DF922D617E9D605A1\ +85D93C0CE50F2469D23989B1E84C7A5409B86A04EDDE9E00A8F62B908E3F02D5 + +2B6DB7CED8665EBE9DEB080295218426BDAA7C6DA9ADD2088932CDFFBAA1C141\ +29BCCDD70F369EFB149285858D2B1D155D14DE2FDB680A8B027284055182A0CA\ +E275234CC9C92863C1B4AB66F304CF0621CD54565F5BFF461D3B461BD40DF281\ +98E3732501B4860EADD503D26D6E69338F4E0456E9E9BAF3D827AE685FB1D817:\ +5451170D67B0EDEF7874F1A2377A66B00B4AE2DDAF38E0313D05DC2445CC6242\ +23212BC0FBF209C1AF6F8947B0037BE9F61F2D65B0FBC113AF291AB238B51508 + [Skein-512(1032)] 0000000000000000000000000000000000000000000000000000000000000000\ 0000000000000000000000000000000000000000000000000000000000000000\ diff --git a/configure.pl b/configure.pl index 53b7897e5..53200b533 100755 --- a/configure.pl +++ b/configure.pl @@ -38,6 +38,10 @@ my $TRACING = 0; ################################################## my $config = {}; +print STDERR "* WARNING\n" . + "* $0 is deprecated; consider trying configure.py instead\n" . + "* If it works, great. If not, file a bug and continue using $0\n*\n"; + main(); exit; @@ -65,12 +69,12 @@ sub main { $$config{'base-dir'} = $base_dir; $$config{'src-dir'} = File::Spec->catdir($base_dir, 'src'); $$config{'checks-dir'} = File::Spec->catdir($base_dir, 'checks'); - $$config{'doc-dir'} = File::Spec->catdir($base_dir, 'doc'); + $$config{'doc_src_dir'} = File::Spec->catdir($base_dir, 'doc'); $$config{'config-dir'} = File::Spec->catdir($$config{'src-dir'}, 'build-data'); - $$config{'command-line'} = $0 . ' ' . join(' ', @ARGV); + $$config{'command_line'} = $0 . ' ' . join(' ', @ARGV); $$config{'timestamp'} = gmtime; $$config{'user'} = getlogin || getpwuid($<) || ''; $$config{'hostname'} = hostname; @@ -103,12 +107,12 @@ sub main { # Goes into build-specific dirs (maybe) - $$config{'build-dir'} = 'build'; - $$config{'botan-config'} = File::Spec->catfile( - $$config{'build-dir'}, 'botan-config'); + $$config{'build_dir'} = 'build'; + $$config{'botan_config'} = File::Spec->catfile( + $$config{'build_dir'}, 'botan-config'); - $$config{'botan-pkgconfig'} = File::Spec->catfile( - $$config{'build-dir'}, + $$config{'botan_pkgconfig'} = File::Spec->catfile( + $$config{'build_dir'}, 'botan-' . $MAJOR_VERSION . '.' . $MINOR_VERSION . '.pc'); $$config{'makefile'} = 'Makefile'; @@ -116,9 +120,9 @@ sub main { $$config{'lib_prefix'} = ''; if(defined($$config{'with_build_dir'})) { - for my $var ('build-dir', - 'botan-config', - 'botan-pkgconfig', + for my $var ('build_dir', + 'botan_config', + 'botan_pkgconfig', 'makefile', 'check_prefix', 'lib_prefix') @@ -147,12 +151,12 @@ sub main { add_to($config, { 'includedir' => os_info_for($os, 'header_dir'), - 'build_lib' => File::Spec->catdir($$config{'build-dir'}, 'lib'), - 'build_check' => File::Spec->catdir($$config{'build-dir'}, 'checks'), + 'build_lib' => File::Spec->catdir($$config{'build_dir'}, 'lib'), + 'build_check' => File::Spec->catdir($$config{'build_dir'}, 'checks'), 'build_include' => - File::Spec->catdir($$config{'build-dir'}, 'include'), + File::Spec->catdir($$config{'build_dir'}, 'include'), 'build_include_botan' => - File::Spec->catdir($$config{'build-dir'}, 'include', 'botan'), + File::Spec->catdir($$config{'build_dir'}, 'include', 'botan'), 'mp_bits' => find_mp_bits(sort keys %{$$config{'modules'}}), 'mod_libs' => @@ -170,7 +174,7 @@ sub main { load_modules($config); - my @dirs = mkdirs($$config{'build-dir'}, + my @dirs = mkdirs($$config{'build_dir'}, $$config{'build_include'}, $$config{'build_include_botan'}, $$config{'build_lib'}, @@ -183,15 +187,15 @@ sub main { determine_config($config); process_template(File::Spec->catfile($$config{'config-dir'}, 'buildh.in'), - File::Spec->catfile($$config{'build-dir'}, 'build.h'), + File::Spec->catfile($$config{'build_dir'}, 'build.h'), $config); process_template(File::Spec->catfile( $$config{'config-dir'}, 'botan.doxy.in'), - File::Spec->catfile($$config{'doc-dir'}, 'botan.doxy'), + File::Spec->catfile($$config{'doc_src_dir'}, 'botan.doxy'), $config); - $$config{'includes'}{'build.h'} = $$config{'build-dir'}; + $$config{'includes'}{'build.h'} = $$config{'build_dir'}; generate_makefile($config); @@ -1246,11 +1250,11 @@ sub load_modules { push @mod_names, $mod; } - $$config{'mod-list'} = join("\n", @mod_names); + $$config{'mod_list'} = join("\n", @mod_names); my $unaligned_ok = 0; - my $gen_defines = sub { + my $target_os_defines = sub { my @macro_list; my $os = $$config{'os'}; @@ -1263,8 +1267,14 @@ sub load_modules { push @macro_list, '#define BOTAN_TARGET_OS_HAS_' . uc $feature; } - push @macro_list, ""; } + return join("\n", @macro_list); + }; + + $$config{'target_os_defines'} = &$target_os_defines(); + + my $target_cpu_defines = sub { + my @macro_list; my $arch = $$config{'arch'}; if($arch ne 'generic') { @@ -1325,6 +1335,13 @@ sub load_modules { # variable is always set (one or zero) push @macro_list, "#define BOTAN_TARGET_UNALIGNED_LOADSTOR_OK $unaligned_ok"; + return join("\n", @macro_list); + }; + + $$config{'target_cpu_defines'} = &$target_cpu_defines(); + + my $target_compiler_defines = sub { + my @macro_list; if(defined($$config{'tr1'})) { my $tr1 = $$config{'tr1'}; @@ -1340,6 +1357,14 @@ sub load_modules { } } + return join("\n", @macro_list); + }; + + $$config{'target_compiler_defines'} = &$target_compiler_defines(); + + my $gen_defines = sub { + my @macro_list; + my %defines; foreach my $mod (sort keys %{$$config{'modules'}}) { @@ -1363,7 +1388,7 @@ sub load_modules { return join("\n", @macro_list); }; - $$config{'defines'} = &$gen_defines(); + $$config{'module_defines'} = &$gen_defines(); } ################################################## @@ -1468,19 +1493,10 @@ sub process_template { next; } - $contents =~ s/@\{var:$name\}/$val/g; - - unless($val eq 'no' or $val eq 'false') { - $contents =~ s/\@\{if:$name (.*)\}/$1/g; - $contents =~ s/\@\{if:$name (.*) (.*)\}/$1/g; - } else { - $contents =~ s/\@\{if:$name (.*)\}//g; - $contents =~ s/\@\{if:$name (.*) (.*)\}/$2/g; - } + $contents =~ s/\%\{$name\}/$val/g; } - if($contents =~ /@\{var:([a-z_]*)\}/ or - $contents =~ /@\{if:(.*) /) { + if($contents =~ /\%\{([a-z_]*)\}/) { sub summarize { my ($n, $s) = @_; @@ -1661,7 +1677,7 @@ sub get_module_info { read_list($_, $reader, 'libs', sub { my $line = $_[0]; - $line =~ m/^([\w!,]*) -> ([\w,-]*)$/; + $line =~ m/^([\w!,]*) -> ([\w.,-]*)$/; $info{'libs'}{$1} = $2; }); @@ -1726,7 +1742,9 @@ sub get_os_info { $info{'name'} = $name; while($_ = &$reader()) { - match_any_of($_, \%info, 'quoted', 'realname', 'ar_command'); + match_any_of($_, \%info, + 'quoted', 'realname', 'ar_command', + 'install_cmd_data', 'install_cmd_exec'); match_any_of($_, \%info, 'unquoted', 'os_type', @@ -1736,9 +1754,7 @@ sub get_os_info { 'install_root', 'header_dir', 'lib_dir', 'doc_dir', - 'ar_needs_ranlib', - 'install_cmd_data', - 'install_cmd_exec'); + 'ar_needs_ranlib'); read_list($_, $reader, 'aliases', list_push(\@{$info{'aliases'}})); @@ -1823,7 +1839,7 @@ sub write_pkg_config { $$config{'link_to'} = libs('-l', '', 'm', @{$$config{'mod_libs'}}); - my $botan_config = $$config{'botan-config'}; + my $botan_config = $$config{'botan_config'}; process_template( File::Spec->catfile($$config{'config-dir'}, 'botan-config.in'), @@ -1832,7 +1848,7 @@ sub write_pkg_config { process_template( File::Spec->catfile($$config{'config-dir'}, 'botan.pc.in'), - $$config{'botan-pkgconfig'}, $config); + $$config{'botan_pkgconfig'}, $config); delete $$config{'link_to'}; } @@ -2029,10 +2045,10 @@ sub generate_makefile { my ($config) = @_; my $is_in_doc_dir = - sub { -e File::Spec->catfile($$config{'doc-dir'}, $_[0]) }; + sub { -e File::Spec->catfile($$config{'doc_src_dir'}, $_[0]) }; my $docs = file_list(undef, undef, undef, - map_to($$config{'doc-dir'}, + map_to($$config{'doc_src_dir'}, grep { &$is_in_doc_dir($_); } @DOCS)); $docs .= File::Spec->catfile($$config{'base-dir'}, 'readme.txt'); @@ -2085,8 +2101,7 @@ sub generate_makefile { add_to($config, { 'shared' => 'no', - 'link_to' => libs('', '.'.$$config{'static_suffix'}, - @{$$config{'mod_libs'}}), + 'link_to' => libs('', '', '', @{$$config{'mod_libs'}}), }); } diff --git a/configure.py b/configure.py new file mode 100755 index 000000000..f98f59d53 --- /dev/null +++ b/configure.py @@ -0,0 +1,938 @@ +#!/usr/bin/env python + +""" +Configuration program for botan + +CPython version requirements: + 2.5 or higher strongly recommended + 2.4 will work if you install a recent version of Optik + 2.3 untested; might work, might not + +Has not been tested with Jython, IronPython, or PyPy + +(C) 2009 Jack Lloyd +Distributed under the terms of the Botan license +""" + +import os +import os.path +import platform +import re +import shlex +import shutil +import sys + +from optparse import OptionParser, OptionGroup, IndentedHelpFormatter, SUPPRESS_HELP +from string import Template + +from getpass import getuser +from time import ctime + +class BuildConfigurationInformation(object): + def version_major(self): return 1 + def version_minor(self): return 8 + def version_patch(self): return 3 + + def version_so_patch(self): return 2 + + def __init__(self, options, modules): + self.build_dir = os.path.join(options.with_build_dir, 'build') + + self.checkobj_dir = os.path.join(self.build_dir, 'checks') + self.libobj_dir = os.path.join(self.build_dir, 'lib') + + self.include_dir = os.path.join(self.build_dir, 'include') + self.full_include_dir = os.path.join(self.include_dir, 'botan') + + all_files = sum([mod.add for mod in modules], []) + + self.headers = sorted( + [file for file in all_files if file.endswith('.h')]) + + self.sources = sorted(set(all_files) - set(self.headers)) + + self.check_sources = sorted( + [os.path.join('checks', file) for file in + os.listdir('checks') if file.endswith('.cpp')]) + + def doc_files(self): + docs = ['readme.txt'] + + for docfile in ['api.pdf', 'tutorial.pdf', 'fips140.pdf', + 'api.tex', 'tutorial.tex', 'fips140.tex', + 'credits.txt', 'license.txt', 'log.txt', + 'thanks.txt', 'todo.txt', 'pgpkeys.asc']: + filename = os.path.join('doc', docfile) + if os.access(filename, os.R_OK): + docs.append(filename) + return docs + + def version_string(self): + return '%d.%d.%d' % (self.version_major(), + self.version_minor(), + self.version_patch()) + + def soversion_string(self): + return '%d.%d.%d' % (self.version_major(), + self.version_minor(), + self.version_so_patch()) + + def username(self): + return getuser() + + def hostname(self): + return platform.node() + + def timestamp(self): + return ctime() + +""" +Handle command line options +""" +def process_command_line(args): + parser = OptionParser(formatter = + IndentedHelpFormatter(max_help_position = 50)) + + target_group = OptionGroup(parser, "Target options") + + target_group.add_option('--cc', dest='compiler', + help='set the desired build compiler') + target_group.add_option('--os', default=platform.system().lower(), + help='set the target operating system [%default]') + target_group.add_option('--cpu', + help='set the target processor type/model') + target_group.add_option('--with-endian', metavar='ORDER', default=None, + help='override guess of CPU byte order') + + build_group = OptionGroup(parser, "Build options") + + build_group.add_option('--enable-shared', dest='build_shared_lib', + action='store_true', default=True, + help=SUPPRESS_HELP) + build_group.add_option('--disable-shared', dest='build_shared_lib', + action='store_false', + help="disable building a shared library") + + build_group.add_option('--enable-asm', dest='asm_ok', + action='store_true', default=True, + help=SUPPRESS_HELP) + build_group.add_option('--disable-asm', dest='asm_ok', + action='store_false', + help="disallow use of assembler") + + build_group.add_option('--enable-debug', dest='debug_build', + action='store_true', default=False, + help="enable debug build") + build_group.add_option('--disable-debug', dest='debug_build', + action='store_false', help=SUPPRESS_HELP) + + build_group.add_option('--with-tr1-implementation', metavar='WHICH', + dest='with_tr1', default=None, + help='enable TR1 (options: none, system, boost)') + + build_group.add_option('--with-build-dir', + metavar='DIR', default='', + help='setup the build in DIR') + + build_group.add_option('--makefile-style', metavar='STYLE', default=None, + help='choose a makefile style (unix, nmake)') + + build_group.add_option('--with-local-config', + dest='local_config', metavar='FILE', + help='include the contents of FILE into build.h') + + mods_group = OptionGroup(parser, "Module selection") + + mods_group.add_option('--enable-modules', dest='enabled_modules', + metavar='MODS', action='append', default=[], + help='enable specific modules') + mods_group.add_option('--disable-modules', dest='disabled_modules', + metavar='MODS', action='append', default=[], + help='disable specific modules') + + for mod in ['openssl', 'gnump', 'bzip2', 'zlib']: + mods_group.add_option('--with-%s' % (mod), dest='enabled_modules', + action='append_const', const=mod) + + mods_group.add_option('--without-%s' % (mod), dest='disabled_modules', + action='append_const', const=mod, + help=SUPPRESS_HELP) + + install_group = OptionGroup(parser, "Installation options") + + install_group.add_option('--prefix', metavar='DIR', + help='set the base install directory') + install_group.add_option('--docdir', metavar='DIR', + help='set the documentation install directory') + install_group.add_option('--libdir', metavar='DIR', + help='set the library install directory') + install_group.add_option('--includedir', metavar='DIR', + help='set the include file install directory') + + parser.add_option_group(target_group) + parser.add_option_group(build_group) + parser.add_option_group(mods_group) + parser.add_option_group(install_group) + + # These exist only for autoconf compatability (requested by zw for mtn) + compat_with_autoconf_options = [ + 'bindir', + 'datadir', + 'datarootdir', + 'dvidir', + 'exec-prefix', + 'htmldir', + 'infodir', + 'libexecdir', + 'localedir', + 'localstatedir', + 'mandir', + 'oldincludedir', + 'pdfdir', + 'psdir', + 'sbindir', + 'sharedstatedir', + 'sysconfdir' + ] + + for opt in compat_with_autoconf_options: + parser.add_option('--' + opt, help=SUPPRESS_HELP) + + (options, args) = parser.parse_args(args) + + options.enabled_modules = \ + sorted(set(sum([s.split(',') for s in options.enabled_modules], []))) + options.disabled_modules = \ + sorted(set(sum([s.split(',') for s in options.disabled_modules], []))) + + return (options, args) + +""" +Generic lexer function for info.txt and src/build-data files +""" +def lex_me_harder(infofile, to_obj, allowed_groups, name_val_pairs): + + class LexerError(Exception): + def __init__(self, msg, line): + self.msg = msg + self.line = line + + def __str__(self): + return '%s at %s:%d' % (self.msg, infofile, self.line) + + (dirname, basename) = os.path.split(infofile) + + to_obj.lives_in = dirname + if basename == 'info.txt': + (dummy,to_obj.basename) = os.path.split(dirname) + else: + to_obj.basename = basename + + lex = shlex.shlex(open(infofile), infofile, posix=True) + + lex.wordchars += '|:.<>/,-!' # handle various funky chars in info.txt + + for group in allowed_groups: + to_obj.__dict__[group] = [] + for (key,val) in name_val_pairs.iteritems(): + to_obj.__dict__[key] = val + + def lexed_tokens(): # Convert to an interator + token = lex.get_token() + while token != None: + yield token + token = lex.get_token() + + for token in lexed_tokens(): + match = re.match('<(.*)>', token) + + # Check for a grouping + if match is not None: + group = match.group(1) + + if group not in allowed_groups: + raise LexerError('Unknown group "%s"' % (group), lex.lineno) + + end_marker = '</' + group + '>' + + token = lex.get_token() + while token != None and token != end_marker: + to_obj.__dict__[group].append(token) + token = lex.get_token() + elif token in name_val_pairs.keys(): + to_obj.__dict__[token] = lex.get_token() + else: # No match -> error + raise LexerError('Bad token "%s"' % (token), lex.lineno) + +""" +Convert a lex'ed map (from build-data files) from a list to a dict +""" +def force_to_dict(l): + return dict(zip(l[::3],l[2::3])) + +""" +Represents the information about a particular module +""" +class ModuleInfo(object): + def __init__(self, infofile): + + lex_me_harder(infofile, self, + ['add', 'requires', 'os', 'arch', 'cc', 'libs'], + { 'realname': '<UNKNOWN>', + 'load_on': 'request', + 'define': None, + 'modset': None, + 'uses_tr1': 'false', + 'note': '', + 'mp_bits': 0 }) + + # Coerce to more useful types + self.libs = force_to_dict(self.libs) + + def add_dir_name(filename): + if filename.count(':') == 0: + return os.path.join(self.lives_in, filename) + + # modules can request to add files of the form + # MODULE_NAME:FILE_NAME to add a file from another module + # For these, assume other module is always in a + # neighboring directory; this is true for all current uses + return os.path.join(os.path.split(self.lives_in)[0], + *filename.split(':')) + + self.add = map(add_dir_name, self.add) + + self.mp_bits = int(self.mp_bits) + + if self.uses_tr1 == 'yes': + self.uses_tr1 = True + else: + self.uses_tr1 = False + + def __cmp__(self, other): + if self.basename < other.basename: + return -1 + if self.basename == other.basename: + return 0 + return 1 + +class ArchInfo(object): + def __init__(self, infofile): + lex_me_harder(infofile, self, + ['aliases', 'submodels', 'submodel_aliases'], + { 'realname': '<UNKNOWN>', + 'default_submodel': None, + 'endian': None, + 'unaligned': 'no' + }) + + self.submodel_aliases = force_to_dict(self.submodel_aliases) + + if self.unaligned == 'ok': + self.unaligned_ok = 1 + else: + self.unaligned_ok = 0 + + def defines(self, target_submodel, with_endian): + macros = ['TARGET_ARCH_IS_%s' % (self.basename.upper())] + + if self.basename != target_submodel: + macros.append('TARGET_CPU_IS_%s' % (target_submodel.upper())) + + if with_endian: + if with_endian == 'little' or with_endian == 'big': + macros.append('TARGET_CPU_IS_%s_ENDIAN' % (with_endian.upper())) + elif self.endian != None: + macros.append('TARGET_CPU_IS_%s_ENDIAN' % (self.endian.upper())) + + macros.append('TARGET_UNALIGNED_LOADSTORE_OK %d' % (self.unaligned_ok)) + + return macros + +class CompilerInfo(object): + def __init__(self, infofile): + lex_me_harder(infofile, self, + ['so_link_flags', 'mach_opt', 'mach_abi_linking'], + { 'realname': '<UNKNOWN>', + 'binary_name': None, + 'compile_option': '-c ', + 'output_to_option': '-o ', + 'add_include_dir_option': '-I', + 'add_lib_dir_option': '-L', + 'add_lib_option': '-l', + 'lib_opt_flags': '', + 'check_opt_flags': '', + 'debug_flags': '', + 'no_debug_flags': '', + 'shared_flags': '', + 'lang_flags': '', + 'warning_flags': '', + 'dll_import_flags': '', + 'dll_export_flags': '', + 'ar_command': None, + 'makefile_style': '', + 'compiler_has_tr1': False, + }) + + self.so_link_flags = force_to_dict(self.so_link_flags) + self.mach_abi_linking = force_to_dict(self.mach_abi_linking) + + self.mach_opt_flags = {} + + while self.mach_opt != []: + proc = self.mach_opt.pop(0) + if self.mach_opt.pop(0) != '->': + raise Exception('Parsing err in %s mach_opt' % (self.basename)) + + flags = self.mach_opt.pop(0) + regex = '' + + if len(self.mach_opt) > 0 and \ + (len(self.mach_opt) == 1 or self.mach_opt[1] != '->'): + regex = self.mach_opt.pop(0) + + self.mach_opt_flags[proc] = (flags,regex) + + del self.mach_opt + + def mach_abi_link_flags(self, osname, arch, submodel): + + abi_link = set() + for what in ['all', osname, arch, submodel]: + if self.mach_abi_linking.get(what) != None: + abi_link.add(self.mach_abi_linking.get(what)) + + if len(abi_link) == 0: + return '' + return ' ' + ' '.join(abi_link) + + def mach_opts(self, arch, submodel): + + def submodel_fixup(tup): + return tup[0].replace('SUBMODEL', submodel.replace(tup[1], '')) + + if submodel == arch: + return '' + + if submodel in self.mach_opt_flags: + return submodel_fixup(self.mach_opt_flags[submodel]) + if arch in self.mach_opt_flags: + return submodel_fixup(self.mach_opt_flags[arch]) + + return '' + + def so_link_command_for(self, osname): + if osname in self.so_link_flags: + return self.so_link_flags[osname] + return self.so_link_flags['default'] + + def defines(self, with_tr1): + if with_tr1: + if with_tr1 == 'boost': + return ['USE_BOOST_TR1'] + elif with_tr1 == 'system': + return ['USE_STD_TR1'] + elif self.compiler_has_tr1: + return ['USE_STD_TR1'] + + return [] + +class OsInfo(object): + def __init__(self, infofile): + lex_me_harder(infofile, self, + ['aliases', 'target_features', 'supports_shared'], + { 'realname': '<UNKNOWN>', + 'os_type': None, + 'obj_suffix': 'o', + 'so_suffix': 'so', + 'static_suffix': 'a', + 'ar_command': 'ar crs', + 'ar_needs_ranlib': False, + 'install_root': '/usr/local', + 'header_dir': 'include', + 'lib_dir': 'lib', + 'doc_dir': 'share/doc', + 'install_cmd_data': 'install -m 644', + 'install_cmd_exec': 'install -m 755' + }) + + self.ar_needs_ranlib = bool(self.ar_needs_ranlib) + + def ranlib_command(self): + if self.ar_needs_ranlib: + return 'ranlib' + else: + return 'true' # no-op + + def defines(self): + return ['TARGET_OS_IS_%s' % (self.basename.upper())] + \ + ['TARGET_OS_HAS_' + feat.upper() + for feat in self.target_features] + +def canon_processor(archinfo, proc): + for ainfo in archinfo.values(): + if ainfo.basename == proc or proc in ainfo.aliases: + return (ainfo.basename, ainfo.basename) + else: + for sm_alias in ainfo.submodel_aliases: + if re.match(sm_alias, proc) != None: + return (ainfo.basename,ainfo.submodel_aliases[sm_alias]) + for submodel in ainfo.submodels: + if re.match(submodel, proc) != None: + return (ainfo.basename,submodel) + + raise Exception('Unknown or unidentifiable processor "%s"' % (proc)) + +def guess_processor(archinfo): + base_proc = platform.machine() + full_proc = platform.processor() + + full_proc = full_proc.replace(' ', '').lower() + + for junk in ['(tm)', '(r)']: + full_proc = full_proc.replace(junk, '') + + for ainfo in archinfo.values(): + if ainfo.basename == base_proc or base_proc in ainfo.aliases: + base_proc = ainfo.basename + + for sm_alias in ainfo.submodel_aliases: + if re.match(sm_alias, full_proc) != None: + return (base_proc,ainfo.submodel_aliases[sm_alias]) + for submodel in ainfo.submodels: + if re.match(submodel, full_proc) != None: + return (base_proc,submodel) + + # No matches, so just use the base proc type + return (base_proc,base_proc) + +""" +Read a whole file into memory as a string +""" +def slurp_file(filename): + if filename is None: + return '' + return ''.join(open(filename).readlines()) + +""" +Perform template substitution +""" +def process_template(template_file, variables): + class PercentSignTemplate(Template): + delimiter = '%' + + try: + template = PercentSignTemplate(slurp_file(template_file)) + return template.substitute(variables) + except KeyError, e: + raise Exception('Unbound var %s in template %s' % (e, template_file)) + +""" +Create the template variables needed to process the makefile, build.h, etc +""" +def create_template_vars(build_config, options, modules, cc, arch, osinfo): + def make_cpp_macros(macros): + return '\n'.join(['#define BOTAN_' + macro for macro in macros]) + + """ + Figure out what external libraries are needed based on selected modules + """ + def link_to(): + libs = set() + for module in modules: + for (osname,link_to) in module.libs.iteritems(): + if osname == 'all' or osname == osinfo.basename: + libs.add(link_to) + else: + match = re.match('^all!(.*)', osname) + if match is not None: + exceptions = match.group(1).split(',') + if osinfo.basename not in exceptions: + libs.add(link_to) + return sorted(libs) + + def objectfile_list(sources, obj_dir): + for src in sources: + basename = os.path.basename(src) + + for src_suffix in ['.cpp', '.S']: + basename = basename.replace(src_suffix, + '.' + osinfo.obj_suffix) + + yield os.path.join(obj_dir, basename) + + + def choose_mp_bits(): + mp_bits = [mod.mp_bits for mod in modules if mod.mp_bits != 0] + + if mp_bits == []: + return 32 # default + + # Check that settings are consistent across modules + for mp_bit in mp_bits[1:]: + if mp_bit != mp_bits[0]: + raise Exception("Incompatible mp_bits settings found") + + return mp_bits[0] + + """ + Form snippets of makefile for building each source file + """ + def build_commands(sources, obj_dir, flags): + for (obj_file,src) in zip(objectfile_list(sources, obj_dir), sources): + yield '%s: %s\n\t$(CXX) %s%s $(%s_FLAGS) %s$? %s$@\n' % ( + obj_file, src, + cc.add_include_dir_option, + build_config.include_dir, + flags, + cc.compile_option, + cc.output_to_option) + + def makefile_list(items): + return (' '*16).join([item + ' \\\n' for item in items]) + + vars = { + 'version_major': build_config.version_major(), + 'version_minor': build_config.version_minor(), + 'version_patch': build_config.version_patch(), + 'version': build_config.version_string(), + 'so_version': build_config.soversion_string(), + + 'timestamp': build_config.timestamp(), + 'user': build_config.username(), + 'hostname': build_config.hostname(), + 'command_line': ' '.join(sys.argv), + 'local_config': slurp_file(options.local_config), + 'makefile_style': options.makefile_style or cc.makefile_style, + + 'prefix': options.prefix or osinfo.install_root, + 'libdir': options.libdir or osinfo.lib_dir, + 'includedir': options.includedir or osinfo.header_dir, + 'docdir': options.docdir or osinfo.doc_dir, + + 'doc_src_dir': 'doc', + 'build_dir': build_config.build_dir, + + 'os': options.os, + 'arch': options.arch, + 'submodel': options.cpu, + + 'mp_bits': choose_mp_bits(), + + 'cc': cc.binary_name + cc.mach_abi_link_flags(options.os, options.arch, options.cpu), + 'lib_opt': cc.lib_opt_flags, + 'mach_opt': cc.mach_opts(options.arch, options.cpu), + 'check_opt': cc.check_opt_flags, + 'lang_flags': cc.lang_flags, + 'warn_flags': cc.warning_flags, + 'shared_flags': cc.shared_flags, + 'dll_export_flags': cc.dll_export_flags, + + 'so_link': cc.so_link_command_for(osinfo.basename), + + 'link_to': ' '.join([cc.add_lib_option + lib for lib in link_to()]), + + 'module_defines': make_cpp_macros(['HAS_' + m.define + for m in modules if m.define]), + + 'target_os_defines': make_cpp_macros(osinfo.defines()), + 'target_compiler_defines': make_cpp_macros(cc.defines(options.with_tr1)), + 'target_cpu_defines': make_cpp_macros( + arch.defines(options.cpu, options.with_endian)), + + 'include_files': makefile_list(build_config.headers), + + 'lib_objs': makefile_list( + objectfile_list(build_config.sources, + build_config.libobj_dir)), + + 'check_objs': makefile_list( + objectfile_list(build_config.check_sources, + build_config.checkobj_dir)), + + 'lib_build_cmds': '\n'.join( + build_commands(build_config.sources, + build_config.libobj_dir, 'LIB')), + + 'check_build_cmds': '\n'.join( + build_commands(build_config.check_sources, + build_config.checkobj_dir, 'CHECK')), + + 'ar_command': cc.ar_command or osinfo.ar_command, + 'ranlib_command': osinfo.ranlib_command(), + 'install_cmd_exec': osinfo.install_cmd_exec, + 'install_cmd_data': osinfo.install_cmd_data, + + 'check_prefix': '', + 'lib_prefix': '', + + 'static_suffix': osinfo.static_suffix, + 'so_suffix': osinfo.so_suffix, + + 'botan_config': 'botan-config', + 'botan_pkgconfig': 'botan.pc', + + 'doc_files': makefile_list(sorted(build_config.doc_files())), + + 'mod_list': '\n'.join(['%s (%s)' % (m.basename, m.realname) + for m in sorted(modules)]), + } + + # Change settings for out of tree builds + if options.with_build_dir != None: + for var in ['build_dir', + 'botan_config', + 'botan_pkgconfig', + 'check_prefix', + 'lib_prefix']: + vars[var] = os.path.join(options.with_build_dir, vars[var]) + + return vars + +""" +Determine which modules to load based on options, target, etc +""" +def choose_modules_to_use(options, modules): + def enable_module(module, for_dep = False): + # First check options for --enable-modules/--disable-modules + + if module.basename in options.disabled_modules: + return (False, []) + + # If it was specifically requested, skip most tests (trust the user) + if module.basename not in options.enabled_modules: + if module.cc != [] and options.compiler not in module.cc: + return (False, []) + + if module.os != [] and options.os not in module.os: + return (False, []) + + if module.arch != [] and options.arch not in module.arch \ + and options.cpu not in module.arch: + return (False, []) + + if module.load_on == 'dep' and not for_dep: + return (False, []) + elif module.load_on == 'request': + return (False, []) + elif module.load_on == 'asm_ok' and not options.asm_ok: + return (False, []) + + # TR1 checks + if module.uses_tr1: + if options.with_tr1 != 'boost' and options.with_tr1 != 'system': + return (False, []) + + # dependency checks + deps = [] + deps_met = True + for req in module.requires: + for mod in req.split('|'): + (can_enable, deps_of_dep) = enable_module(modules[mod], True) + if can_enable: + deps.append(mod) + deps += deps_of_dep + break + else: + deps_met = False + + if deps_met: + return (True,deps) + else: + return (False, []) + + use_module = {} + for (name,module) in modules.iteritems(): + if use_module.get(name, False): + # already enabled (a dep, most likely) + continue + + (should_use,deps) = enable_module(module) + + use_module[name] = should_use + + if should_use: + for dep in deps: + use_module[dep] = True + + chosen = [] + for (name,useme) in use_module.iteritems(): + if useme: + chosen.append(modules[name]) + + return chosen + +""" +Load the info files about modules, targets, etc +""" +def load_info_files(options): + + def find_files_named(desired_name, in_path): + for (dirpath, dirnames, filenames) in os.walk(in_path): + if desired_name in filenames: + yield os.path.join(dirpath, desired_name) + + modules = dict([(mod.basename, mod) for mod in + [ModuleInfo(info) for info in + find_files_named('info.txt', 'src')]]) + + def list_files_in_build_data(subdir): + for (dirpath, dirnames, filenames) in \ + os.walk(os.path.join(options.build_data, subdir)): + for filename in filenames: + yield os.path.join(dirpath, filename) + + archinfo = dict([(os.path.basename(info), ArchInfo(info)) + for info in list_files_in_build_data('arch')]) + + osinfo = dict([(os.path.basename(info), OsInfo(info)) + for info in list_files_in_build_data('os')]) + + ccinfo = dict([(os.path.basename(info), CompilerInfo(info)) + for info in list_files_in_build_data('cc')]) + + del osinfo['defaults'] # FIXME (remove the file) + + return (modules, archinfo, ccinfo, osinfo) + +""" +Perform the filesystem operations needed to setup the build +""" +def setup_build(build_config, options, template_vars): + try: + shutil.rmtree(build_config.build_dir) + except OSError, e: + pass # directory not found (FIXME: check against errno?) + + for dirs in [build_config.checkobj_dir, + build_config.libobj_dir, + build_config.full_include_dir]: + os.makedirs(dirs) + + pkg_config_file = 'botan-%d.%d.pc' % (build_config.version_major(), + build_config.version_minor()) + + templates_to_proc = { + os.path.join(options.build_data, 'buildh.in'): \ + os.path.join(build_config.build_dir, 'build.h'), + + os.path.join(options.build_data, 'botan-config.in'): \ + os.path.join(build_config.build_dir, 'botan-config'), + + os.path.join(options.build_data, 'botan.pc.in'): \ + os.path.join(build_config.build_dir, pkg_config_file) + } + + def choose_makefile_template(style): + if style == 'nmake': + return 'nmake.in' + elif style == 'unix': + if options.build_shared_lib: + return 'unix_shr.in' + else: + return 'unix.in' + else: + raise Exception('Unknown makefile style "%s"' % (style)) + + makefile_template = os.path.join( + options.makefile_dir, + choose_makefile_template(template_vars['makefile_style'])) + + templates_to_proc[makefile_template] = 'Makefile' + + for (template, sink) in templates_to_proc.items(): + try: + f = open(sink, 'w') + f.write(process_template(template, template_vars)) + finally: + f.close() + + build_config.headers.append( + os.path.join(build_config.build_dir, 'build.h')) + + def portable_symlink(filename, target_dir): + if 'symlink' in os.__dict__: + def count_dirs(dir, accum = 0): + if dir == '': + return accum + (dir,basename) = os.path.split(dir) + return accum + 1 + count_dirs(dir) + + dirs_up = count_dirs(target_dir) + target = os.path.join(os.path.join(*[os.path.pardir]*dirs_up), filename) + os.symlink(target, os.path.join(target_dir, os.path.basename(filename))) + elif 'link' in os.__dict__: + os.link(filename, os.path.join(target_dir, os.path.basename(filename))) + else: + shutil.copy(filename, target_dir) + + for header_file in build_config.headers: + portable_symlink(header_file, build_config.full_include_dir) + +def autoconfig(s): + print s + +def main(argv = None): + if argv is None: + argv = sys.argv + + (options, args) = process_command_line(argv[1:]) + if args != []: + raise Exception('Unhandled option(s) ' + ' '.join(args)) + + options.build_data = os.path.join('src', 'build-data') + options.makefile_dir = os.path.join(options.build_data, 'makefile') + + (modules, archinfo, ccinfo, osinfo) = load_info_files(options) + + if options.compiler is None: + if platform.system().lower() == 'windows': + options.compiler = 'msvc' + else: + options.compiler = 'gcc' + autoconfig('Guessing to use compiler %s' % (options.compiler)) + + if options.compiler not in ccinfo: + raise Exception('Unknown compiler "%s"; available options: %s' % ( + options.compiler, ' '.join(sorted(ccinfo.keys())))) + + if options.os not in osinfo: + raise Exception('Unknown OS "%s"; available options: %s' % ( + options.os, ' '.join(sorted(osinfo.keys())))) + + if options.cpu is None: + (options.arch, options.cpu) = guess_processor(archinfo) + autoconfig('Guessing target processor is a %s/%s' % (options.arch, options.cpu)) + else: + (options.arch, options.cpu) = canon_processor(archinfo, options.cpu) + + if options.with_tr1 == None: + if ccinfo[options.compiler].compiler_has_tr1: + options.with_tr1 = 'system' + else: + options.with_tr1 = 'none' + + modules_to_use = choose_modules_to_use(options, modules) + + build_config = BuildConfigurationInformation(options, modules_to_use) + + template_vars = create_template_vars(build_config, options, + modules_to_use, + ccinfo[options.compiler], + archinfo[options.arch], + osinfo[options.os]) + + # Performs the I/O + setup_build(build_config, options, template_vars) + + autoconfig('Build setup complete') + +if __name__ == '__main__': + try: + sys.exit(main()) + except SystemExit: + pass + except Exception, e: + print >>sys.stderr, e + import traceback + traceback.print_exc(file=sys.stderr) diff --git a/doc/log.txt b/doc/log.txt index f5cdbf745..11424f4af 100644 --- a/doc/log.txt +++ b/doc/log.txt @@ -1,8 +1,14 @@ * 1.8.3-pre, 2009-??-?? - - Add the Skein-512 hash function - - Add XTS mode from IEEE P1619 - - Use a default value for AutoSeeded_RNG::reseed + - Add a new Python configuration script + - Add the Skein-512 SHA-3 candidate hash function + - Add the XTS block cipher mode from IEEE P1619 + - Improve handling of low-entropy situations during PRNG seeding + - Change random device polling to prefer /dev/urandom over /dev/random + - Use an input insensitive implementation of same_mem instead of memcmp + - Correct DataSource::discard_next to return the number of discarded bytes + - Provide a default value for AutoSeeded_RNG::reseed + - Fix Gentoo bug 272242 * 1.8.2, 2009-04-07 - Make entropy polling more flexible and in most cases faster diff --git a/doc/tutorial.tex b/doc/tutorial.tex index ce33e5f9b..21fb9eed9 100644 --- a/doc/tutorial.tex +++ b/doc/tutorial.tex @@ -189,7 +189,7 @@ the first four lines of code from the first example with: SecureVector<byte> the_salt = s2k->current_salt(); // 28 octets == 20 for key + 8 for IV - SecureVector<byte> key_and_IV = s2k->derive_key(28, passphrase); + SecureVector<byte> key_and_IV = s2k->derive_key(28, passphrase).bits_of(); SymmetricKey key(key_and_IV, 20); InitializationVector iv(key_and_IV + 20, 8); diff --git a/src/build-data/arch/ia32 b/src/build-data/arch/ia32 index 9ac41b74b..aafcf9a77 100644 --- a/src/build-data/arch/ia32 +++ b/src/build-data/arch/ia32 @@ -35,6 +35,9 @@ pentiumii -> pentium2 pentium3 -> pentium3 pentiumiii -> pentium3 +x86family5 -> i586 +x86family6 -> i686 + pentiumm -> pentium-m intelpentiumm -> pentium-m diff --git a/src/build-data/botan-config.in b/src/build-data/botan-config.in index 28b494254..f3fa3db94 100644 --- a/src/build-data/botan-config.in +++ b/src/build-data/botan-config.in @@ -2,15 +2,15 @@ # For normal builds: guess_prefix=`dirname \`dirname $0\`` -includedir=@{var:includedir} -libdir=@{var:libdir} +includedir=%{includedir} +libdir=%{libdir} # For workspace builds: #guess_prefix=`dirname $0` #includedir=build/include #libdir= -install_prefix=@{var:prefix} +install_prefix=%{prefix} prefix= usage() @@ -42,7 +42,7 @@ while test $# -gt 0; do echo $prefix ;; --version) - echo @{var:version} + echo %{version} exit 0 ;; --cflags) @@ -54,9 +54,9 @@ while test $# -gt 0; do --libs) if [ $prefix != "/usr" -a $prefix != "/usr/local" ] then - echo -L$prefix/$libdir -lbotan @{var:link_to} + echo -L$prefix/$libdir -lbotan %{link_to} else - echo -lbotan @{var:link_to} + echo -lbotan %{link_to} fi ;; *) diff --git a/src/build-data/botan.doxy.in b/src/build-data/botan.doxy.in index 82796a272..2da5e1244 100644 --- a/src/build-data/botan.doxy.in +++ b/src/build-data/botan.doxy.in @@ -5,7 +5,7 @@ #--------------------------------------------------------------------------- DOXYFILE_ENCODING = UTF-8 PROJECT_NAME = Botan -PROJECT_NUMBER = @{var:version} +PROJECT_NUMBER = %{version} OUTPUT_DIRECTORY = doc/doxygen CREATE_SUBDIRS = NO OUTPUT_LANGUAGE = English diff --git a/src/build-data/botan.pc.in b/src/build-data/botan.pc.in index 6fbf43862..70ed65d70 100644 --- a/src/build-data/botan.pc.in +++ b/src/build-data/botan.pc.in @@ -1,12 +1,12 @@ -prefix=@{var:prefix} +prefix=%{prefix} exec_prefix=${prefix} -libdir=${prefix}/@{var:libdir} +libdir=${prefix}/%{libdir} includedir=${prefix}/include Name: Botan Description: Multi-platform C++ crypto library -Version: @{var:version} +Version: %{version} Libs: -L${libdir} -lbotan -Libs.private: @{var:link_to} +Libs.private: %{link_to} Cflags: -I${includedir} diff --git a/src/build-data/buildh.in b/src/build-data/buildh.in index d49f976fb..e4ab0f44b 100644 --- a/src/build-data/buildh.in +++ b/src/build-data/buildh.in @@ -2,14 +2,14 @@ #ifndef BOTAN_BUILD_CONFIG_H__ #define BOTAN_BUILD_CONFIG_H__ -/* This file was automatically generated @{var:timestamp} UTC */ +/* This file was automatically generated %{timestamp} UTC */ -#define BOTAN_VERSION_MAJOR @{var:version_major} -#define BOTAN_VERSION_MINOR @{var:version_minor} -#define BOTAN_VERSION_PATCH @{var:version_patch} +#define BOTAN_VERSION_MAJOR %{version_major} +#define BOTAN_VERSION_MINOR %{version_minor} +#define BOTAN_VERSION_PATCH %{version_patch} #ifndef BOTAN_DLL - #define BOTAN_DLL @{var:dll_export_flags} + #define BOTAN_DLL %{dll_export_flags} #endif /* Chunk sizes */ @@ -17,7 +17,7 @@ #define BOTAN_MEM_POOL_CHUNK_SIZE 64*1024 /* BigInt toggles */ -#define BOTAN_MP_WORD_BITS @{var:mp_bits} +#define BOTAN_MP_WORD_BITS %{mp_bits} #define BOTAN_KARAT_MUL_THRESHOLD 32 #define BOTAN_KARAT_SQR_THRESHOLD 32 #define BOTAN_PRIVATE_KEY_OP_BLINDING_BITS 64 @@ -37,22 +37,30 @@ #endif /* Target identification and feature test macros */ +%{target_os_defines} -@{var:defines} -@{var:local_config} +%{target_cpu_defines} + +%{target_compiler_defines} + +/* Module definitions */ +%{module_defines} + +/* Local configuration options */ +%{local_config} /* -@{var:user}@@{var:hostname} ran '@{var:command-line}' +%{user}@%{hostname} ran '%{command_line}' Target ------- -Compiler: @{var:cc} @{var:lib_opt} @{var:mach_opt} -Arch: @{var:submodel}/@{var:arch} -OS: @{var:os} +Compiler: %{cc} %{lib_opt} %{mach_opt} +Arch: %{submodel}/%{arch} +OS: %{os} Modules ------- -@{var:mod-list} +%{mod_list} */ #endif diff --git a/src/build-data/makefile/nmake.in b/src/build-data/makefile/nmake.in index b730beab1..34c864e93 100644 --- a/src/build-data/makefile/nmake.in +++ b/src/build-data/makefile/nmake.in @@ -1,40 +1,36 @@ ################################################## # Compiler Options # ################################################## -CXX = @{var:cc} -LIB_OPT = @{var:lib_opt} -CHECK_OPT = @{var:check_opt} -MACH_OPT = @{var:mach_opt} -LANG_FLAGS = @{var:lang_flags} -WARN_FLAGS = @{var:warn_flags} -LINK_TO = @{var:link_to} +CXX = %{cc} +LIB_OPT = %{lib_opt} +CHECK_OPT = %{check_opt} +MACH_OPT = %{mach_opt} +LANG_FLAGS = %{lang_flags} +WARN_FLAGS = %{warn_flags} +LINK_TO = %{link_to} ################################################## # Version Numbers # ################################################## -MAJOR = @{var:version_major} -MINOR = @{var:version_minor} -PATCH = @{var:version_patch} - -VERSION = $(MAJOR).$(MINOR).$(PATCH) +VERSION = %{version} ################################################## # Installation Settings # ################################################## -DESTDIR = @{var:prefix} +DESTDIR = %{prefix} -LIBDIR = $(DESTDIR)\@{var:libdir} -HEADERDIR = $(DESTDIR)\@{var:includedir}\botan -DOCDIR = $(DESTDIR)\@{var:docdir}\Botan-$(VERSION) +LIBDIR = $(DESTDIR)\%{libdir} +HEADERDIR = $(DESTDIR)\%{includedir}\botan +DOCDIR = $(DESTDIR)\%{docdir}\Botan-$(VERSION) ################################################## # Aliases for Common Programs # ################################################## -AR = @{var:ar_command} +AR = %{ar_command} CD = @cd ECHO = @echo -INSTALL = @{var:install_cmd_exec} -INSTALL_CMD = @{var:install_cmd_exec} +INSTALL = %{install_cmd_exec} +INSTALL_CMD = %{install_cmd_exec} MKDIR = @md MKDIR_INSTALL = @md RM = @del /Q @@ -45,13 +41,13 @@ RMDIR = @rmdir ################################################## CHECK = check -DOCS = @{var:doc_files} +DOCS = %{doc_files} -HEADERS = @{var:include_files} +HEADERS = %{include_files} -LIBOBJS = @{var:lib_objs} +LIBOBJS = %{lib_objs} -CHECKOBJS = @{var:check_objs} +CHECKOBJS = %{check_objs} LIB_FLAGS = $(LIB_OPT) $(MACH_OPT) $(LANG_FLAGS) $(WARN_FLAGS) CHECK_FLAGS = $(CHECK_OPT) $(LANG_FLAGS) $(WARN_FLAGS) @@ -59,16 +55,16 @@ CHECK_FLAGS = $(CHECK_OPT) $(LANG_FLAGS) $(WARN_FLAGS) LIBRARIES = $(STATIC_LIB) LIBNAME = libbotan -STATIC_LIB = $(LIBNAME).@{var:static_suffix} +STATIC_LIB = $(LIBNAME).%{static_suffix} all: $(LIBRARIES) ################################################## # Build Commands # ################################################## -@{var:lib_build_cmds} +%{lib_build_cmds} -@{var:check_build_cmds} +%{check_build_cmds} ################################################## # Link Commands # @@ -93,15 +89,15 @@ static: $(STATIC_LIB) # Fake Targets # ################################################## clean: - $(RM) @{var:build-dir}\lib\* @{var:build-dir}\checks\* + $(RM) %{build_dir}\lib\* %{build_dir}\checks\* $(RM) $(LIBRARIES) $(CHECK) distclean: clean - $(RM) @{var:build-dir}\build.h - $(RM) @{var:build-dir}\include\botan\* - $(RMDIR) @{var:build-dir}\include\botan @{var:build-dir}\include - $(RMDIR) @{var:build-dir}\lib @{var:build-dir}\checks - $(RMDIR) @{var:build-dir} + $(RM) %{build_dir}\build.h + $(RM) %{build_dir}\include\botan\* + $(RMDIR) %{build_dir}\include\botan %{build_dir}\include + $(RMDIR) %{build_dir}\lib %{build_dir}\checks + $(RMDIR) %{build_dir} $(RM) Makefile ################################################## diff --git a/src/build-data/makefile/unix.in b/src/build-data/makefile/unix.in index 4025eed29..a48a5a17e 100644 --- a/src/build-data/makefile/unix.in +++ b/src/build-data/makefile/unix.in @@ -1,67 +1,67 @@ ################################################## # Compiler Options # ################################################## -CXX = @{var:cc} -LIB_OPT = @{var:lib_opt} -CHECK_OPT = @{var:check_opt} -MACH_OPT = @{var:mach_opt} -LANG_FLAGS = @{var:lang_flags} -WARN_FLAGS = @{var:warn_flags} -LINK_TO = @{var:link_to} +CXX = %{cc} +LIB_OPT = %{lib_opt} +CHECK_OPT = %{check_opt} +MACH_OPT = %{mach_opt} +LANG_FLAGS = %{lang_flags} +WARN_FLAGS = %{warn_flags} +LINK_TO = %{link_to} ################################################## # Version Numbers # ################################################## -VERSION = @{var:version} +VERSION = %{version} ################################################## # Installation Settings # ################################################## -DESTDIR = @{var:prefix} +DESTDIR = %{prefix} BINDIR = $(DESTDIR)/bin -LIBDIR = $(DESTDIR)/@{var:libdir} -HEADERDIR = $(DESTDIR)/@{var:includedir}/botan -DOCDIR = $(DESTDIR)/@{var:docdir}/Botan-$(VERSION) +LIBDIR = $(DESTDIR)/%{libdir} +HEADERDIR = $(DESTDIR)/%{includedir}/botan +DOCDIR = $(DESTDIR)/%{docdir}/Botan-$(VERSION) PKGCONF_DIR = $(LIBDIR)/pkgconfig -CONFIG_SCRIPT = @{var:botan-config} -PKGCONFIG = @{var:botan-pkgconfig} +CONFIG_SCRIPT = %{botan_config} +PKGCONFIG = %{botan_pkgconfig} ################################################## # Aliases for Common Programs # ################################################## -AR = @{var:ar_command} +AR = %{ar_command} CD = @cd ECHO = @echo -INSTALL_CMD_EXEC = @{var:install_cmd_exec} -INSTALL_CMD_DATA = @{var:install_cmd_data} +INSTALL_CMD_EXEC = %{install_cmd_exec} +INSTALL_CMD_DATA = %{install_cmd_data} LN = ln -fs MKDIR = @mkdir MKDIR_INSTALL = @umask 022; mkdir -p -m 755 -RANLIB = @{var:ranlib_command} +RANLIB = %{ranlib_command} RM = @rm -f RM_R = @rm -rf ################################################## # File Lists # ################################################## -CHECK = @{var:check_prefix}check +CHECK = %{check_prefix}check -DOCS = @{var:doc_files} +DOCS = %{doc_files} -HEADERS = @{var:include_files} +HEADERS = %{include_files} -LIBOBJS = @{var:lib_objs} +LIBOBJS = %{lib_objs} -CHECKOBJS = @{var:check_objs} +CHECKOBJS = %{check_objs} LIB_FLAGS = $(LIB_OPT) $(MACH_OPT) $(LANG_FLAGS) $(WARN_FLAGS) CHECK_FLAGS = $(CHECK_OPT) $(LANG_FLAGS) $(WARN_FLAGS) LIBRARIES = $(STATIC_LIB) -LIBNAME = @{var:lib_prefix}libbotan +LIBNAME = %{lib_prefix}libbotan STATIC_LIB = $(LIBNAME).a all: $(LIBRARIES) @@ -69,9 +69,9 @@ all: $(LIBRARIES) ################################################## # Build Commands # ################################################## -@{var:lib_build_cmds} +%{lib_build_cmds} -@{var:check_build_cmds} +%{check_build_cmds} ################################################## # Link Commands # @@ -92,15 +92,15 @@ $(STATIC_LIB): $(LIBOBJS) static: $(STATIC_LIB) doxygen: - doxygen @{var:doc-dir}/botan.doxy + doxygen %{doc_src_dir}/botan.doxy clean: - $(RM_R) @{var:build-dir}/lib/* @{var:build-dir}/checks/* + $(RM_R) %{build_dir}/lib/* %{build_dir}/checks/* $(RM) $(LIBRARIES) $(SYMLINK) $(CHECK) distclean: clean - $(RM_R) @{var:build-dir} - $(RM_R) @{var:doc-dir}/doxygen @{var:doc-dir}/botan.doxy + $(RM_R) %{build_dir} + $(RM_R) %{doc_src_dir}/doxygen %{doc_src_dir}/botan.doxy $(RM) Makefile $(CONFIG_SCRIPT) $(PKGCONFIG) install: $(LIBRARIES) diff --git a/src/build-data/makefile/unix_shr.in b/src/build-data/makefile/unix_shr.in index fec3a3654..f718d1160 100644 --- a/src/build-data/makefile/unix_shr.in +++ b/src/build-data/makefile/unix_shr.in @@ -1,91 +1,91 @@ ################################################## # Compiler Options # ################################################## -CXX = @{var:cc} -LIB_OPT = @{var:lib_opt} -CHECK_OPT = @{var:check_opt} -MACH_OPT = @{var:mach_opt} -LANG_FLAGS = @{var:lang_flags} -WARN_FLAGS = @{var:warn_flags} -SO_OBJ_FLAGS = @{var:shared_flags} -SO_LINK_CMD = @{var:so_link} -LINK_TO = @{var:link_to} +CXX = %{cc} +LIB_OPT = %{lib_opt} +CHECK_OPT = %{check_opt} +MACH_OPT = %{mach_opt} +LANG_FLAGS = %{lang_flags} +WARN_FLAGS = %{warn_flags} +SO_OBJ_FLAGS = %{shared_flags} +SO_LINK_CMD = %{so_link} +LINK_TO = %{link_to} ################################################## # Version Numbers # ################################################## -VERSION = @{var:version} -SO_VERSION = @{var:so_version} +VERSION = %{version} +SO_VERSION = %{so_version} ################################################## # Installation Settings # ################################################## -DESTDIR = @{var:prefix} +DESTDIR = %{prefix} BINDIR = $(DESTDIR)/bin -LIBDIR = $(DESTDIR)/@{var:libdir} -HEADERDIR = $(DESTDIR)/@{var:includedir}/botan -DOCDIR = $(DESTDIR)/@{var:docdir}/Botan-$(VERSION) +LIBDIR = $(DESTDIR)/%{libdir} +HEADERDIR = $(DESTDIR)/%{includedir}/botan +DOCDIR = $(DESTDIR)/%{docdir}/Botan-$(VERSION) PKGCONF_DIR = $(LIBDIR)/pkgconfig -CONFIG_SCRIPT = @{var:botan-config} -PKGCONFIG = @{var:botan-pkgconfig} +CONFIG_SCRIPT = %{botan_config} +PKGCONFIG = %{botan_pkgconfig} ################################################## # Aliases for Common Programs # ################################################## -AR = @{var:ar_command} +AR = %{ar_command} CD = @cd ECHO = @echo -INSTALL_CMD_EXEC = @{var:install_cmd_exec} -INSTALL_CMD_DATA = @{var:install_cmd_data} +INSTALL_CMD_EXEC = %{install_cmd_exec} +INSTALL_CMD_DATA = %{install_cmd_data} LN = ln -fs MKDIR = @mkdir MKDIR_INSTALL = @umask 022; mkdir -p -m 755 -RANLIB = @{var:ranlib_command} +RANLIB = %{ranlib_command} RM = @rm -f RM_R = @rm -rf ################################################## # File Lists # ################################################## -CHECK = @{var:check_prefix}check +CHECK = %{check_prefix}check -DOCS = @{var:doc_files} +DOCS = %{doc_files} -HEADERS = @{var:include_files} +HEADERS = %{include_files} -LIBOBJS = @{var:lib_objs} +LIBOBJS = %{lib_objs} -CHECKOBJS = @{var:check_objs} +CHECKOBJS = %{check_objs} LIB_FLAGS = $(LIB_OPT) $(MACH_OPT) $(LANG_FLAGS) $(WARN_FLAGS) $(SO_OBJ_FLAGS) CHECK_FLAGS = $(CHECK_OPT) $(LANG_FLAGS) $(WARN_FLAGS) LIBRARIES = $(STATIC_LIB) $(SHARED_LIB) -LIBNAME = @{var:lib_prefix}libbotan +LIBNAME = %{lib_prefix}libbotan STATIC_LIB = $(LIBNAME).a -SHARED_LIB = $(LIBNAME)-$(SO_VERSION).@{var:so_suffix} -SONAME = $(LIBNAME)-$(SO_VERSION).@{var:so_suffix} +SHARED_LIB = $(LIBNAME)-$(SO_VERSION).%{so_suffix} +SONAME = $(LIBNAME)-$(SO_VERSION).%{so_suffix} -SYMLINK = libbotan.@{var:so_suffix} +SYMLINK = libbotan.%{so_suffix} all: $(LIBRARIES) ################################################## # Build Commands # ################################################## -@{var:lib_build_cmds} +%{lib_build_cmds} -@{var:check_build_cmds} +%{check_build_cmds} ################################################## # Link Commands # ################################################## $(CHECK): $(LIBRARIES) $(CHECKOBJS) - $(CXX) $(CHECKOBJS) -L. -lbotan $(LINK_TO) -o $(CHECK) + $(CXX) $(LDFLAGS) $(CHECKOBJS) -o $(CHECK) -L. -lbotan-%{so_version} $(LINK_TO) $(STATIC_LIB): $(LIBOBJS) $(RM) $(STATIC_LIB) @@ -93,7 +93,7 @@ $(STATIC_LIB): $(LIBOBJS) $(RANLIB) $(STATIC_LIB) $(SHARED_LIB): $(LIBOBJS) - $(SO_LINK_CMD) $(LINK_TO) $(LIBOBJS) -o $(SHARED_LIB) + $(SO_LINK_CMD) $(LDFLAGS) $(LIBOBJS) -o $(SHARED_LIB) $(LINK_TO) $(LN) $(SHARED_LIB) $(SYMLINK) ################################################## @@ -106,15 +106,15 @@ static: $(STATIC_LIB) shared: $(SHARED_LIB) doxygen: - doxygen @{var:doc-dir}/botan.doxy + doxygen %{doc_src_dir}/botan.doxy clean: - $(RM_R) @{var:build-dir}/lib/* @{var:build-dir}/checks/* + $(RM_R) %{build_dir}/lib/* %{build_dir}/checks/* $(RM) $(LIBRARIES) $(SYMLINK) $(CHECK) distclean: clean - $(RM_R) @{var:build-dir} - $(RM_R) @{var:doc-dir}/doxygen @{var:doc-dir}/botan.doxy + $(RM_R) %{build_dir} + $(RM_R) %{doc_src_dir}/doxygen %{doc_src_dir}/botan.doxy $(RM) Makefile $(CONFIG_SCRIPT) $(PKGCONFIG) install: $(LIBRARIES) diff --git a/src/build-data/os/darwin b/src/build-data/os/darwin index aa28dc59b..298621216 100644 --- a/src/build-data/os/darwin +++ b/src/build-data/os/darwin @@ -14,13 +14,6 @@ doc_dir doc all </supports_shared> -<arch> -ia32 -amd64 -ppc -ppc64 # g5! -</arch> - <aliases> macosx </aliases> diff --git a/src/build-data/os/defaults b/src/build-data/os/defaults index 88fd82252..5648643a9 100644 --- a/src/build-data/os/defaults +++ b/src/build-data/os/defaults @@ -15,5 +15,5 @@ header_dir include lib_dir lib doc_dir share/doc -install_cmd_data install -m 644 -install_cmd_exec install -m 755 +install_cmd_data "install -m 644" +install_cmd_exec "install -m 755" diff --git a/src/build-data/os/mingw b/src/build-data/os/mingw index 8c41fbc21..eb25017fc 100644 --- a/src/build-data/os/mingw +++ b/src/build-data/os/mingw @@ -13,8 +13,8 @@ header_dir include lib_dir lib doc_dir share/doc -install_cmd_data install -m 644 -install_cmd_exec install -m 755 +install_cmd_data "install -m 644" +install_cmd_exec "install -m 755" <aliases> msys diff --git a/src/build-data/os/windows b/src/build-data/os/windows index 823c60d6c..a04d609b8 100644 --- a/src/build-data/os/windows +++ b/src/build-data/os/windows @@ -9,8 +9,8 @@ static_suffix lib install_root c:\Botan doc_dir docs -install_cmd_data copy -install_cmd_exec copy +install_cmd_data "copy" +install_cmd_exec "copy" <target_features> win32_virtual_lock diff --git a/src/entropy/cryptoapi_rng/info.txt b/src/entropy/cryptoapi_rng/info.txt index 40104664b..643c67d2e 100644 --- a/src/entropy/cryptoapi_rng/info.txt +++ b/src/entropy/cryptoapi_rng/info.txt @@ -17,5 +17,5 @@ cygwin </os> <libs> -windows -> advapi32 +windows -> advapi32.lib </libs> diff --git a/src/entropy/dev_random/es_dev.cpp b/src/entropy/dev_random/es_dev.cpp index 6fcdcbfea..ef3074194 100644 --- a/src/entropy/dev_random/es_dev.cpp +++ b/src/entropy/dev_random/es_dev.cpp @@ -40,8 +40,9 @@ u32bit Device_EntropySource::Device_Reader::get(byte out[], u32bit length, FD_SET(fd, &read_set); struct ::timeval timeout; - timeout.tv_sec = 0; - timeout.tv_usec = ms_wait_time * 1000; + + timeout.tv_sec = (ms_wait_time / 1000); + timeout.tv_usec = (ms_wait_time % 1000) * 1000; if(::select(fd + 1, &read_set, 0, 0, &timeout) < 0) return 0; @@ -103,10 +104,9 @@ Device_EntropySource::~Device_EntropySource() */ void Device_EntropySource::poll(Entropy_Accumulator& accum) { - u32bit go_get = std::min<u32bit>(accum.desired_remaining_bits() / 8, 16); - - u32bit read_wait_ms = go_get / 16; + u32bit go_get = std::min<u32bit>(accum.desired_remaining_bits() / 8, 48); + u32bit read_wait_ms = std::max<u32bit>(go_get, 1000); MemoryRegion<byte>& io_buffer = accum.get_io_buffer(go_get); for(size_t i = 0; i != devices.size(); ++i) diff --git a/src/entropy/win32_stats/info.txt b/src/entropy/win32_stats/info.txt index 825765539..ca7100923 100644 --- a/src/entropy/win32_stats/info.txt +++ b/src/entropy/win32_stats/info.txt @@ -20,5 +20,5 @@ mingw </os> <libs> -windows -> user32 +windows -> user32.lib </libs> diff --git a/src/hash/skein/skein_512.cpp b/src/hash/skein/skein_512.cpp index c8a26ae82..eaef641ed 100644 --- a/src/hash/skein/skein_512.cpp +++ b/src/hash/skein/skein_512.cpp @@ -132,6 +132,7 @@ void initial_block(u64bit H[9], u64bit T[3], u32bit output_bits, { clear_mem(H, 9); + // ASCII("SHA3") followed by version (0x0001) code byte config_str[32] = { 0x53, 0x48, 0x41, 0x33, 0x01, 0x00, 0 }; store_le(output_bits, config_str + 8); @@ -140,6 +141,11 @@ void initial_block(u64bit H[9], u64bit T[3], u32bit output_bits, if(personalization != "") { + /* + This is a limitation of this implementation, and not of the + algorithm specification. Could be fixed relatively easily, but + doesn't seem worth the trouble. + */ if(personalization.length() > 64) throw Invalid_Argument("Skein personalization must be <= 64 bytes"); diff --git a/src/hash/skein/skein_512.h b/src/hash/skein/skein_512.h index 2192767ca..fa558fc0d 100644 --- a/src/hash/skein/skein_512.h +++ b/src/hash/skein/skein_512.h @@ -5,8 +5,8 @@ * Distributed under the terms of the Botan license */ -#ifndef BOTAN_SKEIN_H__ -#define BOTAN_SKEIN_H__ +#ifndef BOTAN_SKEIN_512_H__ +#define BOTAN_SKEIN_512_H__ #include <botan/secmem.h> #include <botan/hash.h> @@ -14,7 +14,7 @@ namespace Botan { -class Skein_512 : public HashFunction +class BOTAN_DLL Skein_512 : public HashFunction { public: Skein_512(u32bit output_bits = 512, diff --git a/src/kdf/kdf.h b/src/kdf/kdf.h index aa6cd94cd..70f636b6c 100644 --- a/src/kdf/kdf.h +++ b/src/kdf/kdf.h @@ -19,17 +19,23 @@ namespace Botan { class BOTAN_DLL KDF { public: - SecureVector<byte> derive_key(u32bit, const MemoryRegion<byte>&, - const std::string& = "") const; - SecureVector<byte> derive_key(u32bit, const MemoryRegion<byte>&, - const MemoryRegion<byte>&) const; - SecureVector<byte> derive_key(u32bit, const MemoryRegion<byte>&, - const byte[], u32bit) const; - - SecureVector<byte> derive_key(u32bit, const byte[], u32bit, - const std::string& = "") const; - SecureVector<byte> derive_key(u32bit, const byte[], u32bit, - const byte[], u32bit) const; + SecureVector<byte> derive_key(u32bit key_len, + const MemoryRegion<byte>& secret, + const std::string& salt = "") const; + SecureVector<byte> derive_key(u32bit key_len, + const MemoryRegion<byte>& secret, + const MemoryRegion<byte>& salt) const; + + SecureVector<byte> derive_key(u32bit key_len, + const MemoryRegion<byte>& secret, + const byte salt[], u32bit salt_len) const; + + SecureVector<byte> derive_key(u32bit key_len, + const byte secret[], u32bit secret_len, + const std::string& salt = "") const; + SecureVector<byte> derive_key(u32bit key_len, + const byte secret[], u32bit secret_len, + const byte salt[], u32bit salt_len) const; virtual ~KDF() {} private: @@ -43,7 +49,9 @@ class BOTAN_DLL KDF class BOTAN_DLL MGF { public: - virtual void mask(const byte[], u32bit, byte[], u32bit) const = 0; + virtual void mask(const byte in[], u32bit in_len, + byte out[], u32bit out_len) const = 0; + virtual ~MGF() {} }; diff --git a/src/math/bigint/mulop_amd64/info.txt b/src/math/bigint/mulop_amd64/info.txt index 670780d9c..0960ac4d6 100644 --- a/src/math/bigint/mulop_amd64/info.txt +++ b/src/math/bigint/mulop_amd64/info.txt @@ -2,7 +2,7 @@ realname "BigInt Multiply-Add (x86-64)" mp_bits 64 -load_on dep +load_on request <add> mp_mulop_amd64.S diff --git a/src/mutex/info.txt b/src/mutex/info.txt new file mode 100644 index 000000000..ff79bf753 --- /dev/null +++ b/src/mutex/info.txt @@ -0,0 +1,9 @@ +realname "Mutex Wrappers" + +define MUTEX_WRAPPERS + +load_on auto + +<add> +mutex.h +</add> diff --git a/src/rng/auto_rng/auto_rng.cpp b/src/rng/auto_rng/auto_rng.cpp index 578047afc..171c83cca 100644 --- a/src/rng/auto_rng/auto_rng.cpp +++ b/src/rng/auto_rng/auto_rng.cpp @@ -93,7 +93,7 @@ void add_entropy_sources(RandomNumberGenerator* rng) #if defined(BOTAN_HAS_ENTROPY_SRC_DEVICE) rng->add_entropy_source( new Device_EntropySource( - split_on("/dev/random:/dev/srandom:/dev/urandom", ':') + split_on("/dev/urandom:/dev/random:/dev/srandom", ':') ) ); #endif diff --git a/src/rng/hmac_rng/hmac_rng.cpp b/src/rng/hmac_rng/hmac_rng.cpp index 757f59037..113489db3 100644 --- a/src/rng/hmac_rng/hmac_rng.cpp +++ b/src/rng/hmac_rng/hmac_rng.cpp @@ -72,12 +72,15 @@ void HMAC_RNG::reseed_with_input(u32bit poll_bits, Entropy_Accumulator_BufferedComputation accum(*extractor, poll_bits); - for(u32bit i = 0; i < entropy_sources.size(); ++i) + if(!entropy_sources.empty()) { - if(accum.polling_goal_achieved()) - break; + u32bit poll_attempt = 0; - entropy_sources[i]->poll(accum); + while(!accum.polling_goal_achieved() && poll_attempt < poll_bits) + { + entropy_sources[poll_attempt % entropy_sources.size()]->poll(accum); + ++poll_attempt; + } } // And now add the user-provided input, if any diff --git a/src/rng/randpool/randpool.cpp b/src/rng/randpool/randpool.cpp index f9e05c246..77a5228c6 100644 --- a/src/rng/randpool/randpool.cpp +++ b/src/rng/randpool/randpool.cpp @@ -105,12 +105,15 @@ void Randpool::reseed(u32bit poll_bits) { Entropy_Accumulator_BufferedComputation accum(*mac, poll_bits); - for(u32bit i = 0; i != entropy_sources.size(); ++i) + if(!entropy_sources.empty()) { - entropy_sources[i]->poll(accum); + u32bit poll_attempt = 0; - if(accum.polling_goal_achieved()) - break; + while(!accum.polling_goal_achieved() && poll_attempt < poll_bits) + { + entropy_sources[poll_attempt % entropy_sources.size()]->poll(accum); + ++poll_attempt; + } } SecureVector<byte> mac_val = mac->final(); diff --git a/src/stream/salsa20/info.txt b/src/stream/salsa20/info.txt index de1683643..db938307b 100644 --- a/src/stream/salsa20/info.txt +++ b/src/stream/salsa20/info.txt @@ -4,6 +4,10 @@ define SALSA20 load_on auto +<requires> +stream +</requires> + <add> salsa20.cpp salsa20.h diff --git a/src/stream/turing/info.txt b/src/stream/turing/info.txt index 95ae2cf48..c251a0a30 100644 --- a/src/stream/turing/info.txt +++ b/src/stream/turing/info.txt @@ -4,6 +4,10 @@ define TURING load_on auto +<requires> +stream +</requires> + <add> tur_tab.cpp turing.cpp diff --git a/src/stream/wid_wake/info.txt b/src/stream/wid_wake/info.txt index 299ebfdd7..94416417e 100644 --- a/src/stream/wid_wake/info.txt +++ b/src/stream/wid_wake/info.txt @@ -4,6 +4,10 @@ define WID_WAKE load_on auto +<requires> +stream +</requires> + <add> wid_wake.cpp wid_wake.h diff --git a/src/timer/win32_query_perf_ctr/info.txt b/src/timer/win32_query_perf_ctr/info.txt index e74259184..4bb1ddb34 100644 --- a/src/timer/win32_query_perf_ctr/info.txt +++ b/src/timer/win32_query_perf_ctr/info.txt @@ -17,7 +17,7 @@ mingw </os> <libs> -windows -> user32 +windows -> user32.lib </libs> <requires> diff --git a/src/utils/data_src.cpp b/src/utils/data_src.cpp index 4164a6dd3..e6387c4ba 100644 --- a/src/utils/data_src.cpp +++ b/src/utils/data_src.cpp @@ -38,7 +38,7 @@ u32bit DataSource::discard_next(u32bit n) u32bit discarded = 0; byte dummy; for(u32bit j = 0; j != n; ++j) - discarded = read_byte(dummy); + discarded += read_byte(dummy); return discarded; } diff --git a/src/utils/mem_ops.h b/src/utils/mem_ops.h index f6557c744..0fcf34ba8 100644 --- a/src/utils/mem_ops.h +++ b/src/utils/mem_ops.h @@ -26,7 +26,14 @@ template<typename T> inline void set_mem(T* ptr, u32bit n, byte val) { std::memset(ptr, val, sizeof(T)*n); } template<typename T> inline bool same_mem(const T* p1, const T* p2, u32bit n) - { return (std::memcmp(p1, p2, sizeof(T)*n) == 0); } + { + bool is_same = true; + + for(u32bit i = 0; i != n; ++i) + is_same &= (p1[i] == p2[i]); + + return is_same; + } } |