diff --git a/CHANGES b/CHANGES index 0f7b77a4..1d093142 100644 --- a/CHANGES +++ b/CHANGES @@ -9,6 +9,19 @@ Changes between 1.1.1 and 3.0.0 [xx XXX xxxx] + *) Added newline escaping functionality to a filename when using openssl dgst. + This output format is to replicate the output format found in the '*sum' + checksum programs. This aims to preserve backward compatibility. + [Matt Eaton, Richard Levitte, and Paul Dale] + + *) Removed the heartbeat message in DTLS feature, as it has very + little usage and doesn't seem to fulfill a valuable purpose. + [Richard Levitte] + + *) Changed the output of 'openssl {digestname} < file' to display the + digest name in its output. + [Richard Levitte] + *) Added a new generic trace API which provides support for enabling instrumentation through trace output. This feature is mainly intended as an aid for developers and is disabled by default. To utilize it, @@ -31,6 +44,12 @@ 'enable-buildtest-c++'. [Richard Levitte] + *) Add Single Step KDF (EVP_KDF_SS) to EVP_KDF. + [Shane Lontis] + + *) Add KMAC to EVP_MAC. + [Shane Lontis] + *) Added property based algorithm implementation selection framework to the core. [Paul Dale] diff --git a/Configurations/00-base-templates.conf b/Configurations/00-base-templates.conf index c92d640c..20298c25 100644 --- a/Configurations/00-base-templates.conf +++ b/Configurations/00-base-templates.conf @@ -241,6 +241,8 @@ my %targets=( aes_asm_src => "aes_core.c aes_cbc.c aes-ia64.s", sha1_asm_src => "sha1-ia64.s sha256-ia64.s sha512-ia64.s", modes_asm_src => "ghash-ia64.s", + chacha_asm_src => "chacha-ia64.S", + poly1305_asm_src=> "asm/poly1305-ia64.S", perlasm_scheme => "void" }, sparcv9_asm => { diff --git a/Configurations/descrip.mms.tmpl b/Configurations/descrip.mms.tmpl index 2f74756d..46f2302f 100644 --- a/Configurations/descrip.mms.tmpl +++ b/Configurations/descrip.mms.tmpl @@ -846,9 +846,15 @@ EOF } sub src2obj { + my $asmext = platform->asmext(); my %args = @_; - my @srcs = map { (my $x = $_) =~ s/\.s$/.asm/; $x } ( @{$args{srcs}} ); + my @srcs = + map { my $x = $_; + (platform->isasm($x) && grep { $x eq $_ } @generated) + ? platform->asm($x) : $x } + ( @{$args{srcs}} ); my $obj = platform->obj($args{obj}); + my $dep = platform->dep($args{obj}); my $deps = join(", -\n\t\t", @srcs, @{$args{deps}}); # Because VMS C isn't very good at combining a /INCLUDE path with @@ -860,26 +866,14 @@ EOF my $forward = dirname($args{srcs}->[0]); my $backward = abs2rel(rel2abs("."), rel2abs($forward)); my $objd = abs2rel(rel2abs(dirname($obj)), rel2abs($forward)); - my $objn = basename($obj, platform->objext()); + my $objn = basename($obj); + my $depd = abs2rel(rel2abs(dirname($dep)), rel2abs($forward)); + my $depn = basename($dep); my $srcs = join(", ", map { abs2rel(rel2abs($_), rel2abs($forward)) } @srcs); my $before = $unified_info{before}->{$obj} || "\@ !"; my $after = $unified_info{after}->{$obj} || "\@ !"; - if ($srcs[0] =~ /\.asm$/) { - my $asflags = { shlib => ' $(LIB_ASFLAGS)', - lib => ' $(LIB_ASFLAGS)', - dso => ' $(DSO_ASFLAGS)', - bin => ' $(BIN_ASFLAGS)' } -> {$args{intent}}; - return <<"EOF"; -$obj : $deps - ${before} - SET DEFAULT $forward - \$(AS) $asflags \$(ASOUTFLAG)${objd}${objn}.OBJ $srcs - SET DEFAULT $backward -EOF - } - my $cflags; if ($args{attrs}->{noinst}) { $cflags = { shlib => '$(NO_INST_LIB_CFLAGS)', @@ -914,37 +908,37 @@ EOF my $incs_on = join("\n\t\@ ", @{$incs_cmds[0]}) || '!'; my $incs_off = join("\n\t\@ ", @{$incs_cmds[1]}) || '!'; - if ($srcs[0] =~ /\.asm$/) { + if ($srcs[0] =~ /\Q${asmext}\E$/) { return <<"EOF"; -$obj.OBJ : $deps +$obj : $deps ${before} SET DEFAULT $forward - \$(AS) $asflags \$(ASOUTFLAG)${objd}${objn}.OBJ $srcs + \$(AS) $asflags \$(ASOUTFLAG)${objd}${objn} $srcs SET DEFAULT $backward ${after} - - PURGE $obj.OBJ + - PURGE $obj EOF } elsif ($srcs[0] =~ /.S$/) { return <<"EOF"; -$obj.OBJ : $deps +$obj : $deps ${before} SET DEFAULT $forward \@ $incs_on \@ extradefines = "$defs" PIPE \$(CPP) ${cflags} $srcs | - \$(PERL) -ne "/^#(\\s*line)?\\s*[0-9]+\\s+""/ or print" - - > ${objd}${objn}.asm + > ${objd}${objn}-asm \@ DELETE/SYMBOL/LOCAL extradefines \@ $incs_off SET DEFAULT $backward ${after} - \$(AS) $asflags \$(ASOUTFLAG)$obj.OBJ $obj.asm - - PURGE $obj.OBJ + \$(AS) $asflags \$(ASOUTFLAG)$obj $obj-asm + - PURGE $obj EOF } my $depbuild = $disabled{makedepend} ? "" - : " /MMS=(FILE=${objd}${objn}.D,TARGET=$obj)"; + : " /MMS=(FILE=${depd}${depn},TARGET=$obj)"; return <<"EOF"; $obj : $deps @@ -952,7 +946,7 @@ $obj : $deps SET DEFAULT $forward \@ $incs_on \@ extradefines = "$defs" - \$(CC) ${cflags}${depbuild} /OBJECT=${objd}${objn}.OBJ /REPOSITORY=$backward $srcs + \$(CC) ${cflags}${depbuild} /OBJECT=${objd}${objn} /REPOSITORY=$backward $srcs \@ DELETE/SYMBOL/LOCAL extradefines \@ $incs_off SET DEFAULT $backward diff --git a/Configurations/windows-makefile.tmpl b/Configurations/windows-makefile.tmpl index 8999d6f1..a1daf7d6 100644 --- a/Configurations/windows-makefile.tmpl +++ b/Configurations/windows-makefile.tmpl @@ -601,8 +601,13 @@ EOF } sub src2obj { + my $asmext = platform->asmext(); my %args = @_; - my @srcs = map { (my $x = $_) =~ s/\.s$/.asm/; $x } ( @{$args{srcs}} ); + my @srcs = + map { my $x = $_; + (platform->isasm($x) && grep { $x eq $_ } @generated) + ? platform->asm($x) : $x } + ( @{$args{srcs}} ); my $srcs = '"'.join('" "', @srcs).'"'; my $deps = '"'.join('" "', @srcs, @{$args{deps}}).'"'; my $incs = join("", map { ' /I "'.$_.'"' } @{$args{incs}}); @@ -630,7 +635,7 @@ EOF } my $obj = platform->obj($args{obj}); my $dep = platform->dep($args{obj}); - if ($srcs[0] =~ /\.asm$/) { + if ($srcs[0] =~ /\Q${asmext}\E$/) { return <<"EOF"; $obj: $deps \$(AS) $asflags \$(ASOUTFLAG)\$\@ $srcs diff --git a/Configure b/Configure index 6b533f46..5aaa6401 100755 --- a/Configure +++ b/Configure @@ -55,7 +55,7 @@ my $usage="Usage: Configure [no- ...] [enable- ...] [-Dxxx] [-lx # [no-]threads [don't] try to create a library that is suitable for # multithreaded applications (default is "threads" if we # know how to do it) -# [no-]shared [don't] try to create shared libraries when supported. +# [no-]shared [don't] try to create shared libraries when supported. # [no-]pic [don't] try to build position independent code when supported. # If disabled, it also disables shared and dynamic-engine. # no-asm do not use assembler @@ -63,8 +63,8 @@ my $usage="Usage: Configure [no- ...] [enable- ...] [-Dxxx] [-lx # will ensure that all methods just return NULL. # no-egd do not compile support for the entropy-gathering daemon APIs # [no-]zlib [don't] compile support for zlib compression. -# zlib-dynamic Like "zlib", but the zlib library is expected to be a shared -# library and will be loaded in run-time by the OpenSSL library. +# zlib-dynamic Like "zlib", but the zlib library is expected to be a shared +# library and will be loaded in run-time by the OpenSSL library. # sctp include SCTP support # enable-weak-ssl-ciphers # Enable weak ciphers that are disabled by default. @@ -91,18 +91,18 @@ my $usage="Usage: Configure [no- ...] [enable- ...] [-Dxxx] [-lx # production quality. # # DEBUG_SAFESTACK use type-safe stacks to enforce type-safety on stack items -# provided to stack calls. Generates unique stack functions for -# each possible stack type. -# BN_LLONG use the type 'long long' in crypto/bn/bn.h -# RC4_CHAR use 'char' instead of 'int' for RC4_INT in crypto/rc4/rc4.h +# provided to stack calls. Generates unique stack functions for +# each possible stack type. +# BN_LLONG use the type 'long long' in crypto/bn/bn.h +# RC4_CHAR use 'char' instead of 'int' for RC4_INT in crypto/rc4/rc4.h # Following are set automatically by this script # -# MD5_ASM use some extra md5 assembler, -# SHA1_ASM use some extra sha1 assembler, must define L_ENDIAN for x86 -# RMD160_ASM use some extra ripemd160 assembler, -# SHA256_ASM sha256_block is implemented in assembler -# SHA512_ASM sha512_block is implemented in assembler -# AES_ASM AES_[en|de]crypt is implemented in assembler +# MD5_ASM use some extra md5 assembler, +# SHA1_ASM use some extra sha1 assembler, must define L_ENDIAN for x86 +# RMD160_ASM use some extra ripemd160 assembler, +# SHA256_ASM sha256_block is implemented in assembler +# SHA512_ASM sha512_block is implemented in assembler +# AES_ASM AES_[en|de]crypt is implemented in assembler # Minimum warning options... any contributions to OpenSSL should at least get # past these. @@ -236,20 +236,20 @@ if (grep /^reconf(igure)?$/, @argvcopy) { die "reconfiguring with other arguments present isn't supported" if scalar @argvcopy > 1; if (-f "./configdata.pm") { - my $file = "./configdata.pm"; - unless (my $return = do $file) { - die "couldn't parse $file: $@" if $@; + my $file = "./configdata.pm"; + unless (my $return = do $file) { + die "couldn't parse $file: $@" if $@; die "couldn't do $file: $!" unless defined $return; die "couldn't run $file" unless $return; - } + } - @argvcopy = defined($configdata::config{perlargv}) ? - @{$configdata::config{perlargv}} : (); - die "Incorrect data to reconfigure, please do a normal configuration\n" - if (grep(/^reconf/,@argvcopy)); - $config{perlenv} = $configdata::config{perlenv} // {}; + @argvcopy = defined($configdata::config{perlargv}) ? + @{$configdata::config{perlargv}} : (); + die "Incorrect data to reconfigure, please do a normal configuration\n" + if (grep(/^reconf/,@argvcopy)); + $config{perlenv} = $configdata::config{perlenv} // {}; } else { - die "Insufficient data to reconfigure, please do a normal configuration\n"; + die "Insufficient data to reconfigure, please do a normal configuration\n"; } } @@ -375,7 +375,6 @@ my @disablables = ( "fuzz-libfuzzer", "fuzz-afl", "gost", - "heartbeats", "idea", "makedepend", "md2", @@ -429,10 +428,10 @@ my @disablables = ( "zlib-dynamic", ); foreach my $proto ((@tls, @dtls)) - { - push(@disablables, $proto); - push(@disablables, "$proto-method") unless $proto eq "tls1_3"; - } + { + push(@disablables, $proto); + push(@disablables, "$proto-method") unless $proto eq "tls1_3"; + } my %deprecated_disablables = ( "ssl2" => undef, @@ -446,53 +445,52 @@ my %deprecated_disablables = ( # All of the following are disabled by default: our %disabled = ( # "what" => "comment" - "asan" => "default", - "buildtest-c++" => "default", - "crypto-mdebug" => "default", - "crypto-mdebug-backtrace" => "default", - "devcryptoeng" => "default", - "ec_nistp_64_gcc_128" => "default", - "egd" => "default", - "external-tests" => "default", - "fuzz-libfuzzer" => "default", - "fuzz-afl" => "default", - "heartbeats" => "default", - "md2" => "default", + "asan" => "default", + "buildtest-c++" => "default", + "crypto-mdebug" => "default", + "crypto-mdebug-backtrace" => "default", + "devcryptoeng" => "default", + "ec_nistp_64_gcc_128" => "default", + "egd" => "default", + "external-tests" => "default", + "fuzz-libfuzzer" => "default", + "fuzz-afl" => "default", + "md2" => "default", "msan" => "default", - "rc5" => "default", - "sctp" => "default", - "ssl-trace" => "default", - "ssl3" => "default", - "ssl3-method" => "default", - "trace" => "default", - "ubsan" => "default", - "unit-test" => "default", - "weak-ssl-ciphers" => "default", - "zlib" => "default", - "zlib-dynamic" => "default", - "ktls" => "default", - ); + "rc5" => "default", + "sctp" => "default", + "ssl-trace" => "default", + "ssl3" => "default", + "ssl3-method" => "default", + "trace" => "default", + "ubsan" => "default", + "unit-test" => "default", + "weak-ssl-ciphers" => "default", + "zlib" => "default", + "zlib-dynamic" => "default", + "ktls" => "default", + ); # Note: => pair form used for aesthetics, not to truly make a hash table my @disable_cascades = ( - # "what" => [ "cascade", ... ] + # "what" => [ "cascade", ... ] sub { $config{processor} eq "386" } - => [ "sse2" ], - "ssl" => [ "ssl3" ], - "ssl3-method" => [ "ssl3" ], - "zlib" => [ "zlib-dynamic" ], - "des" => [ "mdc2" ], - "ec" => [ "ecdsa", "ecdh" ], + => [ "sse2" ], + "ssl" => [ "ssl3" ], + "ssl3-method" => [ "ssl3" ], + "zlib" => [ "zlib-dynamic" ], + "des" => [ "mdc2" ], + "ec" => [ "ecdsa", "ecdh" ], - "dgram" => [ "dtls", "sctp" ], - "sock" => [ "dgram" ], - "dtls" => [ @dtls ], + "dgram" => [ "dtls", "sctp" ], + "sock" => [ "dgram" ], + "dtls" => [ @dtls ], sub { 0 == scalar grep { !$disabled{$_} } @dtls } - => [ "dtls" ], + => [ "dtls" ], - "tls" => [ @tls ], + "tls" => [ @tls ], sub { 0 == scalar grep { !$disabled{$_} } @tls } - => [ "tls" ], + => [ "tls" ], "crypto-mdebug" => [ "crypto-mdebug-backtrace" ], @@ -529,14 +527,14 @@ my @list = (reverse @tls); while ((my $first, my $second) = (shift @list, shift @list)) { last unless @list; push @disable_cascades, ( sub { !$disabled{$first} && $disabled{$second} } - => [ @list ] ); + => [ @list ] ); unshift @list, $second; } my @list = (reverse @dtls); while ((my $first, my $second) = (shift @list, shift @list)) { last unless @list; push @disable_cascades, ( sub { !$disabled{$first} && $disabled{$second} } - => [ @list ] ); + => [ @list ] ); unshift @list, $second; } @@ -642,43 +640,43 @@ my %deprecated_options = (); my @known_seed_sources = qw(getrandom devrandom os egd none rdcpu librandom); my @seed_sources = (); while (@argvcopy) - { - $_ = shift @argvcopy; + { + $_ = shift @argvcopy; - # Support env variable assignments among the options - if (m|^(\w+)=(.+)?$|) - { - $cmdvars{$1} = $2; - # Every time a variable is given as a configuration argument, - # it acts as a reset if the variable. - if (exists $user{$1}) - { - $user{$1} = ref $user{$1} eq "ARRAY" ? [] : undef; - } - #if (exists $useradd{$1}) - # { - # $useradd{$1} = []; - # } - next; - } + # Support env variable assignments among the options + if (m|^(\w+)=(.+)?$|) + { + $cmdvars{$1} = $2; + # Every time a variable is given as a configuration argument, + # it acts as a reset if the variable. + if (exists $user{$1}) + { + $user{$1} = ref $user{$1} eq "ARRAY" ? [] : undef; + } + #if (exists $useradd{$1}) + # { + # $useradd{$1} = []; + # } + next; + } - # VMS is a case insensitive environment, and depending on settings - # out of our control, we may receive options uppercased. Let's - # downcase at least the part before any equal sign. - if ($^O eq "VMS") - { - s/^([^=]*)/lc($1)/e; - } + # VMS is a case insensitive environment, and depending on settings + # out of our control, we may receive options uppercased. Let's + # downcase at least the part before any equal sign. + if ($^O eq "VMS") + { + s/^([^=]*)/lc($1)/e; + } - # some people just can't read the instructions, clang people have to... - s/^-no-(?!integrated-as)/no-/; + # some people just can't read the instructions, clang people have to... + s/^-no-(?!integrated-as)/no-/; - # rewrite some options in "enable-..." form - s /^-?-?shared$/enable-shared/; - s /^sctp$/enable-sctp/; - s /^threads$/enable-threads/; - s /^zlib$/enable-zlib/; - s /^zlib-dynamic$/enable-zlib-dynamic/; + # rewrite some options in "enable-..." form + s /^-?-?shared$/enable-shared/; + s /^sctp$/enable-sctp/; + s /^threads$/enable-threads/; + s /^zlib$/enable-zlib/; + s /^zlib-dynamic$/enable-zlib-dynamic/; if (/^(no|disable|enable)-(.+)$/) { @@ -747,11 +745,11 @@ while (@argvcopy) { $disabled{$1} = "option"; } - # No longer an automatic choice - $auto_threads = 0 if ($1 eq "threads"); - } - elsif (/^enable-(.+)$/) - { + # No longer an automatic choice + $auto_threads = 0 if ($1 eq "threads"); + } + elsif (/^enable-(.+)$/) + { if ($1 eq "static-engine") { $disabled{"dynamic-engine"} = "option"; @@ -764,177 +762,177 @@ while (@argvcopy) { delete $disabled{"zlib"}; } - my $algo = $1; - delete $disabled{$algo}; + my $algo = $1; + delete $disabled{$algo}; - # No longer an automatic choice - $auto_threads = 0 if ($1 eq "threads"); - } - elsif (/^--strict-warnings$/) - { - # Pretend that our strict flags is a C flag, and replace it - # with the proper flags later on - push @{$useradd{CFLAGS}}, '--ossl-strict-warnings'; - push @{$useradd{CXXFLAGS}}, '--ossl-strict-warnings'; - $strict_warnings=1; - } - elsif (/^--debug$/) - { - $config{build_type} = "debug"; - } - elsif (/^--release$/) - { - $config{build_type} = "release"; - } - elsif (/^386$/) - { $config{processor}=386; } - elsif (/^fips$/) - { - die "FIPS mode not supported\n"; - } - elsif (/^rsaref$/) - { - # No RSAref support any more since it's not needed. - # The check for the option is there so scripts aren't - # broken - } - elsif (/^nofipscanistercheck$/) - { - die "FIPS mode not supported\n"; - } - elsif (/^[-+]/) - { - if (/^--prefix=(.*)$/) - { - $config{prefix}=$1; - die "Directory given with --prefix MUST be absolute\n" - unless file_name_is_absolute($config{prefix}); - } - elsif (/^--api=(.*)$/) - { - $config{api}=$1; - } - elsif (/^--libdir=(.*)$/) - { - $config{libdir}=$1; - } - elsif (/^--openssldir=(.*)$/) - { - $config{openssldir}=$1; - } - elsif (/^--with-zlib-lib=(.*)$/) - { - $withargs{zlib_lib}=$1; - } - elsif (/^--with-zlib-include=(.*)$/) - { - $withargs{zlib_include}=$1; - } - elsif (/^--with-fuzzer-lib=(.*)$/) - { - $withargs{fuzzer_lib}=$1; - } - elsif (/^--with-fuzzer-include=(.*)$/) - { - $withargs{fuzzer_include}=$1; - } - elsif (/^--with-rand-seed=(.*)$/) - { - foreach my $x (split(m|,|, $1)) - { - die "Unknown --with-rand-seed choice $x\n" - if ! grep { $x eq $_ } @known_seed_sources; - push @seed_sources, $x; - } + # No longer an automatic choice + $auto_threads = 0 if ($1 eq "threads"); + } + elsif (/^--strict-warnings$/) + { + # Pretend that our strict flags is a C flag, and replace it + # with the proper flags later on + push @{$useradd{CFLAGS}}, '--ossl-strict-warnings'; + push @{$useradd{CXXFLAGS}}, '--ossl-strict-warnings'; + $strict_warnings=1; + } + elsif (/^--debug$/) + { + $config{build_type} = "debug"; + } + elsif (/^--release$/) + { + $config{build_type} = "release"; + } + elsif (/^386$/) + { $config{processor}=386; } + elsif (/^fips$/) + { + die "FIPS mode not supported\n"; + } + elsif (/^rsaref$/) + { + # No RSAref support any more since it's not needed. + # The check for the option is there so scripts aren't + # broken + } + elsif (/^nofipscanistercheck$/) + { + die "FIPS mode not supported\n"; + } + elsif (/^[-+]/) + { + if (/^--prefix=(.*)$/) + { + $config{prefix}=$1; + die "Directory given with --prefix MUST be absolute\n" + unless file_name_is_absolute($config{prefix}); } - elsif (/^--cross-compile-prefix=(.*)$/) - { - $user{CROSS_COMPILE}=$1; - } - elsif (/^--config=(.*)$/) - { - read_config $1; - } - elsif (/^-l(.*)$/) - { - push @{$useradd{LDLIBS}}, $_; - } - elsif (/^-framework$/) - { - push @{$useradd{LDLIBS}}, $_, shift(@argvcopy); - } - elsif (/^-L(.*)$/ or /^-Wl,/) - { - push @{$useradd{LDFLAGS}}, $_; - } - elsif (/^-rpath$/ or /^-R$/) - # -rpath is the OSF1 rpath flag - # -R is the old Solaris rpath flag - { - my $rpath = shift(@argvcopy) || ""; - $rpath .= " " if $rpath ne ""; - push @{$useradd{LDFLAGS}}, $_, $rpath; - } - elsif (/^-static$/) - { - push @{$useradd{LDFLAGS}}, $_; - $disabled{"dso"} = "forced"; - $disabled{"pic"} = "forced"; - $disabled{"shared"} = "forced"; - $disabled{"threads"} = "forced"; - } - elsif (/^-D(.*)$/) - { - push @{$useradd{CPPDEFINES}}, $1; - } - elsif (/^-I(.*)$/) - { - push @{$useradd{CPPINCLUDES}}, $1; - } - elsif (/^-Wp,$/) - { - push @{$useradd{CPPFLAGS}}, $1; - } - else # common if (/^[-+]/), just pass down... - { - $_ =~ s/%([0-9a-f]{1,2})/chr(hex($1))/gei; - push @{$useradd{CFLAGS}}, $_; - push @{$useradd{CXXFLAGS}}, $_; - } - } - else - { - die "target already defined - $target (offending arg: $_)\n" if ($target ne ""); - $target=$_; - } - unless ($_ eq $target || /^no-/ || /^disable-/) - { - # "no-..." follows later after implied deactivations - # have been derived. (Don't take this too seriously, - # we really only write OPTIONS to the Makefile out of - # nostalgia.) + elsif (/^--api=(.*)$/) + { + $config{api}=$1; + } + elsif (/^--libdir=(.*)$/) + { + $config{libdir}=$1; + } + elsif (/^--openssldir=(.*)$/) + { + $config{openssldir}=$1; + } + elsif (/^--with-zlib-lib=(.*)$/) + { + $withargs{zlib_lib}=$1; + } + elsif (/^--with-zlib-include=(.*)$/) + { + $withargs{zlib_include}=$1; + } + elsif (/^--with-fuzzer-lib=(.*)$/) + { + $withargs{fuzzer_lib}=$1; + } + elsif (/^--with-fuzzer-include=(.*)$/) + { + $withargs{fuzzer_include}=$1; + } + elsif (/^--with-rand-seed=(.*)$/) + { + foreach my $x (split(m|,|, $1)) + { + die "Unknown --with-rand-seed choice $x\n" + if ! grep { $x eq $_ } @known_seed_sources; + push @seed_sources, $x; + } + } + elsif (/^--cross-compile-prefix=(.*)$/) + { + $user{CROSS_COMPILE}=$1; + } + elsif (/^--config=(.*)$/) + { + read_config $1; + } + elsif (/^-l(.*)$/) + { + push @{$useradd{LDLIBS}}, $_; + } + elsif (/^-framework$/) + { + push @{$useradd{LDLIBS}}, $_, shift(@argvcopy); + } + elsif (/^-L(.*)$/ or /^-Wl,/) + { + push @{$useradd{LDFLAGS}}, $_; + } + elsif (/^-rpath$/ or /^-R$/) + # -rpath is the OSF1 rpath flag + # -R is the old Solaris rpath flag + { + my $rpath = shift(@argvcopy) || ""; + $rpath .= " " if $rpath ne ""; + push @{$useradd{LDFLAGS}}, $_, $rpath; + } + elsif (/^-static$/) + { + push @{$useradd{LDFLAGS}}, $_; + $disabled{"dso"} = "forced"; + $disabled{"pic"} = "forced"; + $disabled{"shared"} = "forced"; + $disabled{"threads"} = "forced"; + } + elsif (/^-D(.*)$/) + { + push @{$useradd{CPPDEFINES}}, $1; + } + elsif (/^-I(.*)$/) + { + push @{$useradd{CPPINCLUDES}}, $1; + } + elsif (/^-Wp,$/) + { + push @{$useradd{CPPFLAGS}}, $1; + } + else # common if (/^[-+]/), just pass down... + { + $_ =~ s/%([0-9a-f]{1,2})/chr(hex($1))/gei; + push @{$useradd{CFLAGS}}, $_; + push @{$useradd{CXXFLAGS}}, $_; + } + } + else + { + die "target already defined - $target (offending arg: $_)\n" if ($target ne ""); + $target=$_; + } + unless ($_ eq $target || /^no-/ || /^disable-/) + { + # "no-..." follows later after implied deactivations + # have been derived. (Don't take this too seriously, + # we really only write OPTIONS to the Makefile out of + # nostalgia.) - if ($config{options} eq "") - { $config{options} = $_; } - else - { $config{options} .= " ".$_; } - } - } + if ($config{options} eq "") + { $config{options} = $_; } + else + { $config{options} .= " ".$_; } + } + } if (defined($config{api}) && !exists $apitable->{$config{api}}) { - die "***** Unsupported api compatibility level: $config{api}\n", + die "***** Unsupported api compatibility level: $config{api}\n", } if (keys %deprecated_options) - { - warn "***** Deprecated options: ", - join(", ", keys %deprecated_options), "\n"; - } + { + warn "***** Deprecated options: ", + join(", ", keys %deprecated_options), "\n"; + } if (keys %unsupported_options) - { - die "***** Unsupported options: ", - join(", ", keys %unsupported_options), "\n"; - } + { + die "***** Unsupported options: ", + join(", ", keys %unsupported_options), "\n"; + } # If any %useradd entry has been set, we must check that the "make # variables" haven't been set. We start by checking of any %useradd entry @@ -990,7 +988,7 @@ if (grep { /-rpath\b/ } ($user{LDFLAGS} ? @{$user{LDFLAGS}} : ()) && !$disabled{shared} && !($disabled{asan} && $disabled{msan} && $disabled{ubsan})) { die "***** Cannot simultaneously use -rpath, shared libraries, and\n", - "***** any of asan, msan or ubsan\n"; + "***** any of asan, msan or ubsan\n"; } my @tocheckfor = (keys %disabled); @@ -998,12 +996,12 @@ while (@tocheckfor) { my %new_tocheckfor = (); my @cascade_copy = (@disable_cascades); while (@cascade_copy) { - my ($test, $descendents) = (shift @cascade_copy, shift @cascade_copy); - if (ref($test) eq "CODE" ? $test->() : defined($disabled{$test})) { - foreach(grep { !defined($disabled{$_}) } @$descendents) { - $new_tocheckfor{$_} = 1; $disabled{$_} = "forced"; - } - } + my ($test, $descendents) = (shift @cascade_copy, shift @cascade_copy); + if (ref($test) eq "CODE" ? $test->() : defined($disabled{$test})) { + foreach(grep { !defined($disabled{$_}) } @$descendents) { + $new_tocheckfor{$_} = 1; $disabled{$_} = "forced"; + } + } } @tocheckfor = (keys %new_tocheckfor); } @@ -1012,14 +1010,14 @@ our $die = sub { die @_; }; if ($target eq "TABLE") { local $die = sub { warn @_; }; foreach (sort keys %table) { - print_table_entry($_, "TABLE"); + print_table_entry($_, "TABLE"); } exit 0; } if ($target eq "LIST") { foreach (sort keys %table) { - print $_,"\n" unless $table{$_}->{template}; + print $_,"\n" unless $table{$_}->{template}; } exit 0; } @@ -1028,7 +1026,7 @@ if ($target eq "HASH") { local $die = sub { warn @_; }; print "%table = (\n"; foreach (sort keys %table) { - print_table_entry($_, "HASH"); + print_table_entry($_, "HASH"); } exit 0; } @@ -1059,7 +1057,7 @@ _____ } push @{$config{openssl_feature_defines}}, map { (my $x = $_) =~ tr|[\-a-z]|[_A-Z]|; "OPENSSL_RAND_SEED_$x" } - @seed_sources; + @seed_sources; # Backward compatibility? if ($target =~ m/^CygWin32(-.*)$/) { @@ -1073,7 +1071,7 @@ if ($d) { # If we do not find debug-foo in the table, the target is set to foo. if (!$table{$target}) { - $target = $t; + $target = $t; } } @@ -1261,21 +1259,21 @@ foreach my $checker (($builder_platform."-".$target{build_file}."-checker.pm", push @{$config{defines}}, "NDEBUG" if $config{build_type} eq "release"; if ($target =~ /^mingw/ && `$config{CC} --target-help 2>&1` =~ m/-mno-cygwin/m) - { - push @{$config{cflags}}, "-mno-cygwin"; - push @{$config{cxxflags}}, "-mno-cygwin" if $config{CXX}; - push @{$config{shared_ldflag}}, "-mno-cygwin"; - } + { + push @{$config{cflags}}, "-mno-cygwin"; + push @{$config{cxxflags}}, "-mno-cygwin" if $config{CXX}; + push @{$config{shared_ldflag}}, "-mno-cygwin"; + } if ($target =~ /linux.*-mips/ && !$disabled{asm} && !grep { $_ !~ /-m(ips|arch=)/ } (@{$user{CFLAGS}}, @{$useradd{CFLAGS}})) { - # minimally required architecture flags for assembly modules - my $value; - $value = '-mips2' if ($target =~ /mips32/); - $value = '-mips3' if ($target =~ /mips64/); - unshift @{$config{cflags}}, $value; - unshift @{$config{cxxflags}}, $value if $config{CXX}; + # minimally required architecture flags for assembly modules + my $value; + $value = '-mips2' if ($target =~ /mips32/); + $value = '-mips3' if ($target =~ /mips64/); + unshift @{$config{cflags}}, $value; + unshift @{$config{cxxflags}}, $value if $config{CXX}; } # If threads aren't disabled, check how possible they are @@ -1316,13 +1314,13 @@ if (defined($disabled{"deprecated"})) { my $no_shared_warn=0; if ($target{shared_target} eq "") - { - $no_shared_warn = 1 - if (!$disabled{shared} || !$disabled{"dynamic-engine"}); - $disabled{shared} = "no-shared-target"; - $disabled{pic} = $disabled{shared} = $disabled{"dynamic-engine"} = - "no-shared-target"; - } + { + $no_shared_warn = 1 + if (!$disabled{shared} || !$disabled{"dynamic-engine"}); + $disabled{shared} = "no-shared-target"; + $disabled{pic} = $disabled{shared} = $disabled{"dynamic-engine"} = + "no-shared-target"; + } if ($disabled{"dynamic-engine"}) { push @{$config{openssl_feature_defines}}, "OPENSSL_NO_DYNAMIC_ENGINE"; @@ -1361,25 +1359,25 @@ unless ($disabled{"fuzz-libfuzzer"} && $disabled{"fuzz-afl"} # This saves the build files from having to check if ($disabled{pic}) - { - foreach (qw(shared_cflag shared_cxxflag shared_cppflag - shared_defines shared_includes shared_ldflag - module_cflags module_cxxflags module_cppflags - module_defines module_includes module_lflags)) - { - delete $config{$_}; - $target{$_} = ""; - } - } + { + foreach (qw(shared_cflag shared_cxxflag shared_cppflag + shared_defines shared_includes shared_ldflag + module_cflags module_cxxflags module_cppflags + module_defines module_includes module_lflags)) + { + delete $config{$_}; + $target{$_} = ""; + } + } else - { - push @{$config{lib_defines}}, "OPENSSL_PIC"; - } + { + push @{$config{lib_defines}}, "OPENSSL_PIC"; + } if ($target{sys_id} ne "") - { - push @{$config{openssl_sys_defines}}, "OPENSSL_SYS_$target{sys_id}"; - } + { + push @{$config{openssl_sys_defines}}, "OPENSSL_SYS_$target{sys_id}"; + } unless ($disabled{asm}) { $target{cpuid_asm_src}=$table{DEFAULTS}->{cpuid_asm_src} if ($config{processor} eq "386"); @@ -1397,55 +1395,55 @@ unless ($disabled{asm}) { push @{$config{lib_defines}}, "BN_DIV3W" if ($target{bn_asm_src} =~ /-div3w/); if ($target{sha1_asm_src}) { - push @{$config{lib_defines}}, "SHA1_ASM" if ($target{sha1_asm_src} =~ /sx86/ || $target{sha1_asm_src} =~ /sha1/); - push @{$config{lib_defines}}, "SHA256_ASM" if ($target{sha1_asm_src} =~ /sha256/); - push @{$config{lib_defines}}, "SHA512_ASM" if ($target{sha1_asm_src} =~ /sha512/); + push @{$config{lib_defines}}, "SHA1_ASM" if ($target{sha1_asm_src} =~ /sx86/ || $target{sha1_asm_src} =~ /sha1/); + push @{$config{lib_defines}}, "SHA256_ASM" if ($target{sha1_asm_src} =~ /sha256/); + push @{$config{lib_defines}}, "SHA512_ASM" if ($target{sha1_asm_src} =~ /sha512/); } if ($target{keccak1600_asm_src} ne $table{DEFAULTS}->{keccak1600_asm_src}) { - push @{$config{lib_defines}}, "KECCAK1600_ASM"; + push @{$config{lib_defines}}, "KECCAK1600_ASM"; } if ($target{rc4_asm_src} ne $table{DEFAULTS}->{rc4_asm_src}) { - push @{$config{lib_defines}}, "RC4_ASM"; + push @{$config{lib_defines}}, "RC4_ASM"; } if ($target{md5_asm_src}) { - push @{$config{lib_defines}}, "MD5_ASM"; + push @{$config{lib_defines}}, "MD5_ASM"; } $target{cast_asm_src}=$table{DEFAULTS}->{cast_asm_src} unless $disabled{pic}; # CAST assembler is not PIC if ($target{rmd160_asm_src}) { - push @{$config{lib_defines}}, "RMD160_ASM"; + push @{$config{lib_defines}}, "RMD160_ASM"; } if ($target{aes_asm_src}) { - push @{$config{lib_defines}}, "AES_ASM" if ($target{aes_asm_src} =~ m/\baes-/);; - # aes-ctr.fake is not a real file, only indication that assembler - # module implements AES_ctr32_encrypt... - push @{$config{lib_defines}}, "AES_CTR_ASM" if ($target{aes_asm_src} =~ s/\s*aes-ctr\.fake//); - # aes-xts.fake indicates presence of AES_xts_[en|de]crypt... - push @{$config{lib_defines}}, "AES_XTS_ASM" if ($target{aes_asm_src} =~ s/\s*aes-xts\.fake//); - $target{aes_asm_src} =~ s/\s*(vpaes|aesni)-x86\.s//g if ($disabled{sse2}); - push @{$config{lib_defines}}, "VPAES_ASM" if ($target{aes_asm_src} =~ m/vpaes/); - push @{$config{lib_defines}}, "BSAES_ASM" if ($target{aes_asm_src} =~ m/bsaes/); + push @{$config{lib_defines}}, "AES_ASM" if ($target{aes_asm_src} =~ m/\baes-/);; + # aes-ctr.fake is not a real file, only indication that assembler + # module implements AES_ctr32_encrypt... + push @{$config{lib_defines}}, "AES_CTR_ASM" if ($target{aes_asm_src} =~ s/\s*aes-ctr\.fake//); + # aes-xts.fake indicates presence of AES_xts_[en|de]crypt... + push @{$config{lib_defines}}, "AES_XTS_ASM" if ($target{aes_asm_src} =~ s/\s*aes-xts\.fake//); + $target{aes_asm_src} =~ s/\s*(vpaes|aesni)-x86\.s//g if ($disabled{sse2}); + push @{$config{lib_defines}}, "VPAES_ASM" if ($target{aes_asm_src} =~ m/vpaes/); + push @{$config{lib_defines}}, "BSAES_ASM" if ($target{aes_asm_src} =~ m/bsaes/); } if ($target{wp_asm_src} =~ /mmx/) { if ($config{processor} eq "386") { - $target{wp_asm_src}=$table{DEFAULTS}->{wp_asm_src}; - } elsif (!$disabled{"whirlpool"}) { - push @{$config{lib_defines}}, "WHIRLPOOL_ASM"; - } + $target{wp_asm_src}=$table{DEFAULTS}->{wp_asm_src}; + } elsif (!$disabled{"whirlpool"}) { + push @{$config{lib_defines}}, "WHIRLPOOL_ASM"; + } } if ($target{modes_asm_src} =~ /ghash-/) { - push @{$config{lib_defines}}, "GHASH_ASM"; + push @{$config{lib_defines}}, "GHASH_ASM"; } if ($target{ec_asm_src} =~ /ecp_nistz256/) { - push @{$config{lib_defines}}, "ECP_NISTZ256_ASM"; + push @{$config{lib_defines}}, "ECP_NISTZ256_ASM"; } if ($target{ec_asm_src} =~ /x25519/) { - push @{$config{lib_defines}}, "X25519_ASM"; + push @{$config{lib_defines}}, "X25519_ASM"; } if ($target{padlock_asm_src} ne $table{DEFAULTS}->{padlock_asm_src}) { - push @{$config{dso_defines}}, "PADLOCK_ASM"; + push @{$config{dso_defines}}, "PADLOCK_ASM"; } if ($target{poly1305_asm_src} ne "") { - push @{$config{lib_defines}}, "POLY1305_ASM"; + push @{$config{lib_defines}}, "POLY1305_ASM"; } } @@ -1461,7 +1459,7 @@ if (!$disabled{makedepend}) { # functionality is hard coded in the corresponding build files for # cl (Windows) and CC/DECC (VMS). } elsif (($predefined_C{__GNUC__} // -1) >= 3 - && !($predefined_C{__APPLE_CC__} && !$predefined_C{__clang__})) { + && !($predefined_C{__APPLE_CC__} && !$predefined_C{__clang__})) { # We know that GNU C version 3 and up as well as all clang # versions support dependency generation, but Xcode did not # handle $cc -M before clang support (but claims __GNUC__ = 3) @@ -1498,24 +1496,24 @@ if (!$disabled{asm} && !$predefined_C{__MACH__} && $^O ne 'VMS') { # Deal with bn_ops ################################################### -$config{bn_ll} =0; -$config{export_var_as_fn} =0; +$config{bn_ll} =0; +$config{export_var_as_fn} =0; my $def_int="unsigned int"; -$config{rc4_int} =$def_int; +$config{rc4_int} =$def_int; ($config{b64l},$config{b64},$config{b32})=(0,0,1); my $count = 0; foreach (sort split(/\s+/,$target{bn_ops})) { $count++ if /SIXTY_FOUR_BIT|SIXTY_FOUR_BIT_LONG|THIRTY_TWO_BIT/; $config{export_var_as_fn}=1 if $_ eq 'EXPORT_VAR_AS_FN'; - $config{bn_ll}=1 if $_ eq 'BN_LLONG'; - $config{rc4_int}="unsigned char" if $_ eq 'RC4_CHAR'; + $config{bn_ll}=1 if $_ eq 'BN_LLONG'; + $config{rc4_int}="unsigned char" if $_ eq 'RC4_CHAR'; ($config{b64l},$config{b64},$config{b32}) - =(0,1,0) if $_ eq 'SIXTY_FOUR_BIT'; + =(0,1,0) if $_ eq 'SIXTY_FOUR_BIT'; ($config{b64l},$config{b64},$config{b32}) - =(1,0,0) if $_ eq 'SIXTY_FOUR_BIT_LONG'; + =(1,0,0) if $_ eq 'SIXTY_FOUR_BIT_LONG'; ($config{b64l},$config{b64},$config{b32}) - =(0,0,1) if $_ eq 'THIRTY_TWO_BIT'; + =(0,0,1) if $_ eq 'THIRTY_TWO_BIT'; } die "Exactly one of SIXTY_FOUR_BIT|SIXTY_FOUR_BIT_LONG|THIRTY_TWO_BIT can be set in bn_ops\n" if $count > 1; @@ -1536,27 +1534,27 @@ $config{openssl_api_defines} = [ my %strict_warnings_collection=( CFLAGS => [], CXXFLAGS => []); if ($strict_warnings) - { - my $wopt; - my $gccver = $predefined_C{__GNUC__} // -1; - my $gxxver = $predefined_CXX{__GNUC__} // -1; + { + my $wopt; + my $gccver = $predefined_C{__GNUC__} // -1; + my $gxxver = $predefined_CXX{__GNUC__} // -1; - warn "WARNING --strict-warnings requires gcc[>=4] or gcc-alike" + warn "WARNING --strict-warnings requires gcc[>=4] or gcc-alike" unless $gccver >= 4; - warn "WARNING --strict-warnings requires g++[>=4] or g++-alike" + warn "WARNING --strict-warnings requires g++[>=4] or g++-alike" unless $gxxver >= 4; - foreach (qw(CFLAGS CXXFLAGS)) - { - push @{$strict_warnings_collection{$_}}, - @{$gcc_devteam_warn{$_}}; - } - push @{$strict_warnings_collection{CFLAGS}}, - @{$clang_devteam_warn{CFLAGS}} - if (defined($predefined_C{__clang__})); - push @{$strict_warnings_collection{CXXFLAGS}}, - @{$clang_devteam_warn{CXXFLAGS}} - if (defined($predefined_CXX{__clang__})); - } + foreach (qw(CFLAGS CXXFLAGS)) + { + push @{$strict_warnings_collection{$_}}, + @{$gcc_devteam_warn{$_}}; + } + push @{$strict_warnings_collection{CFLAGS}}, + @{$clang_devteam_warn{CFLAGS}} + if (defined($predefined_C{__clang__})); + push @{$strict_warnings_collection{CXXFLAGS}}, + @{$clang_devteam_warn{CXXFLAGS}} + if (defined($predefined_CXX{__clang__})); + } foreach my $idx (qw(CFLAGS CXXFLAGS)) { $useradd{$idx} = [ map { $_ eq '--ossl-strict-warnings' @@ -1566,20 +1564,20 @@ foreach my $idx (qw(CFLAGS CXXFLAGS)) } unless ($disabled{"crypto-mdebug-backtrace"}) - { - foreach my $wopt (split /\s+/, $memleak_devteam_backtrace) - { - push @{$config{cflags}}, $wopt - unless grep { $_ eq $wopt } @{$config{cflags}}; - push @{$config{cxxflags}}, $wopt - if ($config{CXX} - && !grep { $_ eq $wopt } @{$config{cxxflags}}); - } - if ($target =~ /^BSD-/) - { - push @{$config{ex_libs}}, "-lexecinfo"; - } - } + { + foreach my $wopt (split /\s+/, $memleak_devteam_backtrace) + { + push @{$config{cflags}}, $wopt + unless grep { $_ eq $wopt } @{$config{cflags}}; + push @{$config{cxxflags}}, $wopt + if ($config{CXX} + && !grep { $_ eq $wopt } @{$config{cxxflags}}); + } + if ($target =~ /^BSD-/) + { + push @{$config{ex_libs}}, "-lexecinfo"; + } + } unless ($disabled{afalgeng}) { $config{afalgeng}=""; @@ -1685,38 +1683,38 @@ if ($builder eq "unified") { # Store the name of the template file we will build the build file from # in %config. This may be useful for the build file itself. my @build_file_template_names = - ( $builder_platform."-".$target{build_file}.".tmpl", - $target{build_file}.".tmpl" ); + ( $builder_platform."-".$target{build_file}.".tmpl", + $target{build_file}.".tmpl" ); my @build_file_templates = (); # First, look in the user provided directory, if given if (defined env($local_config_envname)) { - @build_file_templates = - map { - if ($^O eq 'VMS') { - # VMS environment variables are logical names, - # which can be used as is - $local_config_envname . ':' . $_; - } else { - catfile(env($local_config_envname), $_); - } - } - @build_file_template_names; + @build_file_templates = + map { + if ($^O eq 'VMS') { + # VMS environment variables are logical names, + # which can be used as is + $local_config_envname . ':' . $_; + } else { + catfile(env($local_config_envname), $_); + } + } + @build_file_template_names; } # Then, look in our standard directory push @build_file_templates, - ( map { cleanfile($srcdir, catfile("Configurations", $_), $blddir) } - @build_file_template_names ); + ( map { cleanfile($srcdir, catfile("Configurations", $_), $blddir) } + @build_file_template_names ); my $build_file_template; for $_ (@build_file_templates) { - $build_file_template = $_; + $build_file_template = $_; last if -f $build_file_template; $build_file_template = undef; } if (!defined $build_file_template) { - die "*** Couldn't find any of:\n", join("\n", @build_file_templates), "\n"; + die "*** Couldn't find any of:\n", join("\n", @build_file_templates), "\n"; } $config{build_file_templates} = [ cleanfile($srcdir, catfile("Configurations", "common0.tmpl"), @@ -2371,11 +2369,11 @@ EOF print OUT "our %config = (\n"; foreach (sort keys %config) { if (ref($config{$_}) eq "ARRAY") { - print OUT " ", $_, " => [ ", join(", ", - map { quotify("perl", $_) } - @{$config{$_}}), " ],\n"; + print OUT " ", $_, " => [ ", join(", ", + map { quotify("perl", $_) } + @{$config{$_}}), " ],\n"; } elsif (ref($config{$_}) eq "HASH") { - print OUT " ", $_, " => {"; + print OUT " ", $_, " => {"; if (scalar keys %{$config{$_}} > 0) { print OUT "\n"; foreach my $key (sort keys %{$config{$_}}) { @@ -2391,7 +2389,7 @@ foreach (sort keys %config) { } print OUT "},\n"; } else { - print OUT " ", $_, " => ", quotify("perl", $config{$_}), ",\n" + print OUT " ", $_, " => ", quotify("perl", $config{$_}), ",\n" } } print OUT <<"EOF"; @@ -2401,11 +2399,11 @@ EOF print OUT "our %target = (\n"; foreach (sort keys %target) { if (ref($target{$_}) eq "ARRAY") { - print OUT " ", $_, " => [ ", join(", ", - map { quotify("perl", $_) } - @{$target{$_}}), " ],\n"; + print OUT " ", $_, " => [ ", join(", ", + map { quotify("perl", $_) } + @{$target{$_}}), " ],\n"; } else { - print OUT " ", $_, " => ", quotify("perl", $target{$_}), ",\n" + print OUT " ", $_, " => ", quotify("perl", $target{$_}), ",\n" } } print OUT <<"EOF"; @@ -2438,11 +2436,11 @@ EOF print OUT "our %withargs = (\n"; foreach (sort keys %withargs) { if (ref($withargs{$_}) eq "ARRAY") { - print OUT " ", $_, " => [ ", join(", ", - map { quotify("perl", $_) } - @{$withargs{$_}}), " ],\n"; + print OUT " ", $_, " => [ ", join(", ", + map { quotify("perl", $_) } + @{$withargs{$_}}), " ],\n"; } else { - print OUT " ", $_, " => ", quotify("perl", $withargs{$_}), ",\n" + print OUT " ", $_, " => ", quotify("perl", $withargs{$_}), ",\n" } } print OUT <<"EOF"; @@ -2669,9 +2667,9 @@ _____ if ($reconf) { if ($verbose) { print 'Reconfiguring with: ', join(' ',@{$config{perlargv}}), "\n"; - foreach (sort keys %{$config{perlenv}}) { - print ' ',$_,' = ',($config{perlenv}->{$_} || ""),"\n"; - } + foreach (sort keys %{$config{perlenv}}) { + print ' ',$_,' = ',($config{perlenv}->{$_} || ""),"\n"; + } } chdir $here; @@ -2866,7 +2864,7 @@ _____ sub asm { my @x = @_; sub { - $disabled{asm} ? () : @x; + $disabled{asm} ? () : @x; } } @@ -2932,29 +2930,29 @@ sub _add { my $found_array = !defined($separator); my @values = - map { - my $res = $_; - while (ref($res) eq "CODE") { - $res = $res->(); - } - if (defined($res)) { - if (ref($res) eq "ARRAY") { - $found_array = 1; - @$res; - } else { - $res; - } - } else { - (); - } + map { + my $res = $_; + while (ref($res) eq "CODE") { + $res = $res->(); + } + if (defined($res)) { + if (ref($res) eq "ARRAY") { + $found_array = 1; + @$res; + } else { + $res; + } + } else { + (); + } } (@_); $add_called = 1; if ($found_array) { - [ @values ]; + [ @values ]; } else { - join($separator, grep { defined($_) && $_ ne "" } @values); + join($separator, grep { defined($_) && $_ ne "" } @values); } } sub add_before { @@ -3004,10 +3002,10 @@ sub read_config { my %targets; { - # Protect certain tables from tampering - local %table = (); + # Protect certain tables from tampering + local %table = (); - %targets = read_eval_file($fname); + %targets = read_eval_file($fname); } my %preexisting = (); foreach (sort keys %targets) { @@ -3023,14 +3021,14 @@ EOF # For each target, check that it's configured with a hash table. foreach (keys %targets) { - if (ref($targets{$_}) ne "HASH") { - if (ref($targets{$_}) eq "") { - warn "Deprecated target configuration for $_, ignoring...\n"; - } else { - warn "Misconfigured target configuration for $_ (should be a hash table), ignoring...\n"; - } - delete $targets{$_}; - } else { + if (ref($targets{$_}) ne "HASH") { + if (ref($targets{$_}) eq "") { + warn "Deprecated target configuration for $_, ignoring...\n"; + } else { + warn "Misconfigured target configuration for $_ (should be a hash table), ignoring...\n"; + } + delete $targets{$_}; + } else { $targets{$_}->{_conf_fname_int} = add([ $fname ]); } } @@ -3049,13 +3047,13 @@ sub resolve_config { # my $extra_checks = defined($ENV{CONFIGURE_EXTRA_CHECKS}); if (grep { $_ eq $target } @breadcrumbs) { - die "inherit_from loop! target backtrace:\n " - ,$target,"\n ",join("\n ", @breadcrumbs),"\n"; + die "inherit_from loop! target backtrace:\n " + ,$target,"\n ",join("\n ", @breadcrumbs),"\n"; } if (!defined($table{$target})) { - warn "Warning! target $target doesn't exist!\n"; - return (); + warn "Warning! target $target doesn't exist!\n"; + return (); } # Recurse through all inheritances. They will be resolved on the # fly, so when this operation is done, they will all just be a @@ -3065,22 +3063,22 @@ sub resolve_config { # this stage is done. my %combined_inheritance = (); if ($table{$target}->{inherit_from}) { - my @inherit_from = - map { ref($_) eq "CODE" ? $_->() : $_ } @{$table{$target}->{inherit_from}}; - foreach (@inherit_from) { - my %inherited_config = resolve_config($_, $target, @breadcrumbs); + my @inherit_from = + map { ref($_) eq "CODE" ? $_->() : $_ } @{$table{$target}->{inherit_from}}; + foreach (@inherit_from) { + my %inherited_config = resolve_config($_, $target, @breadcrumbs); - # 'template' is a marker that's considered private to - # the config that had it. - delete $inherited_config{template}; + # 'template' is a marker that's considered private to + # the config that had it. + delete $inherited_config{template}; - foreach (keys %inherited_config) { - if (!$combined_inheritance{$_}) { - $combined_inheritance{$_} = []; - } - push @{$combined_inheritance{$_}}, $inherited_config{$_}; - } - } + foreach (keys %inherited_config) { + if (!$combined_inheritance{$_}) { + $combined_inheritance{$_} = []; + } + push @{$combined_inheritance{$_}}, $inherited_config{$_}; + } + } } # We won't need inherit_from in this target any more, since we've @@ -3101,14 +3099,14 @@ sub resolve_config { my $default_combiner = add(); my %all_keys = - map { $_ => 1 } (keys %combined_inheritance, - keys %{$table{$target}}); + map { $_ => 1 } (keys %combined_inheritance, + keys %{$table{$target}}); sub process_values { - my $object = shift; - my $inherited = shift; # Always a [ list ] - my $target = shift; - my $entry = shift; + my $object = shift; + my $inherited = shift; # Always a [ list ] + my $target = shift; + my $entry = shift; $add_called = 0; @@ -3133,16 +3131,16 @@ sub resolve_config { foreach (sort keys %all_keys) { my $previous = $combined_inheritance{$_}; - # Current target doesn't have a value for the current key? - # Assign it the default combiner, the rest of this loop body - # will handle it just like any other coderef. - if (!exists $table{$target}->{$_}) { - $table{$target}->{$_} = $default_combiner; - } + # Current target doesn't have a value for the current key? + # Assign it the default combiner, the rest of this loop body + # will handle it just like any other coderef. + if (!exists $table{$target}->{$_}) { + $table{$target}->{$_} = $default_combiner; + } - $table{$target}->{$_} = process_values($table{$target}->{$_}, - $combined_inheritance{$_}, - $target, $_); + $table{$target}->{$_} = process_values($table{$target}->{$_}, + $combined_inheritance{$_}, + $target, $_); unless(defined($table{$target}->{$_})) { delete $table{$target}->{$_}; } @@ -3157,39 +3155,39 @@ sub resolve_config { } sub usage - { - print STDERR $usage; - print STDERR "\npick os/compiler from:\n"; - my $j=0; - my $i; + { + print STDERR $usage; + print STDERR "\npick os/compiler from:\n"; + my $j=0; + my $i; my $k=0; - foreach $i (sort keys %table) - { - next if $table{$i}->{template}; - next if $i =~ /^debug/; - $k += length($i) + 1; - if ($k > 78) - { - print STDERR "\n"; - $k=length($i); - } - print STDERR $i . " "; - } - foreach $i (sort keys %table) - { - next if $table{$i}->{template}; - next if $i !~ /^debug/; - $k += length($i) + 1; - if ($k > 78) - { - print STDERR "\n"; - $k=length($i); - } - print STDERR $i . " "; - } - print STDERR "\n\nNOTE: If in doubt, on Unix-ish systems use './config'.\n"; - exit(1); - } + foreach $i (sort keys %table) + { + next if $table{$i}->{template}; + next if $i =~ /^debug/; + $k += length($i) + 1; + if ($k > 78) + { + print STDERR "\n"; + $k=length($i); + } + print STDERR $i . " "; + } + foreach $i (sort keys %table) + { + next if $table{$i}->{template}; + next if $i !~ /^debug/; + $k += length($i) + 1; + if ($k > 78) + { + print STDERR "\n"; + $k=length($i); + } + print STDERR $i . " "; + } + print STDERR "\n\nNOTE: If in doubt, on Unix-ish systems use './config'.\n"; + exit(1); + } sub run_dofile { @@ -3283,69 +3281,69 @@ sub print_table_entry return if $target{template}; my @sequence = ( - "sys_id", - "cpp", - "cppflags", - "defines", - "includes", - "cc", - "cflags", - "unistd", - "ld", - "lflags", - "loutflag", - "ex_libs", - "bn_ops", - "apps_aux_src", - "cpuid_asm_src", - "uplink_aux_src", - "bn_asm_src", - "ec_asm_src", - "des_asm_src", - "aes_asm_src", - "bf_asm_src", - "md5_asm_src", - "cast_asm_src", - "sha1_asm_src", - "rc4_asm_src", - "rmd160_asm_src", - "rc5_asm_src", - "wp_asm_src", - "cmll_asm_src", - "modes_asm_src", - "padlock_asm_src", - "chacha_asm_src", - "poly1035_asm_src", - "thread_scheme", - "perlasm_scheme", - "dso_scheme", - "shared_target", - "shared_cflag", - "shared_defines", - "shared_ldflag", - "shared_rcflag", - "shared_extension", - "dso_extension", - "obj_extension", - "exe_extension", - "ranlib", - "ar", - "arflags", - "aroutflag", - "rc", - "rcflags", - "rcoutflag", - "mt", - "mtflags", - "mtinflag", - "mtoutflag", - "multilib", - "build_scheme", - ); + "sys_id", + "cpp", + "cppflags", + "defines", + "includes", + "cc", + "cflags", + "unistd", + "ld", + "lflags", + "loutflag", + "ex_libs", + "bn_ops", + "apps_aux_src", + "cpuid_asm_src", + "uplink_aux_src", + "bn_asm_src", + "ec_asm_src", + "des_asm_src", + "aes_asm_src", + "bf_asm_src", + "md5_asm_src", + "cast_asm_src", + "sha1_asm_src", + "rc4_asm_src", + "rmd160_asm_src", + "rc5_asm_src", + "wp_asm_src", + "cmll_asm_src", + "modes_asm_src", + "padlock_asm_src", + "chacha_asm_src", + "poly1035_asm_src", + "thread_scheme", + "perlasm_scheme", + "dso_scheme", + "shared_target", + "shared_cflag", + "shared_defines", + "shared_ldflag", + "shared_rcflag", + "shared_extension", + "dso_extension", + "obj_extension", + "exe_extension", + "ranlib", + "ar", + "arflags", + "aroutflag", + "rc", + "rcflags", + "rcoutflag", + "mt", + "mtflags", + "mtinflag", + "mtoutflag", + "multilib", + "build_scheme", + ); if ($type eq "TABLE") { - print "\n"; - print "*** $now_printing\n"; + print "\n"; + print "*** $now_printing\n"; foreach (@sequence) { if (ref($target{$_}) eq "ARRAY") { printf "\$%-12s = %s\n", $_, join(" ", @{$target{$_}}); @@ -3354,19 +3352,19 @@ sub print_table_entry } } } elsif ($type eq "HASH") { - my $largest = - length((sort { length($a) <=> length($b) } @sequence)[-1]); - print " '$now_printing' => {\n"; - foreach (@sequence) { - if ($target{$_}) { + my $largest = + length((sort { length($a) <=> length($b) } @sequence)[-1]); + print " '$now_printing' => {\n"; + foreach (@sequence) { + if ($target{$_}) { if (ref($target{$_}) eq "ARRAY") { print " '",$_,"'"," " x ($largest - length($_))," => [ ",join(", ", map { "'$_'" } @{$target{$_}})," ],\n"; } else { print " '",$_,"'"," " x ($largest - length($_))," => '",$target{$_},"',\n"; } - } - } - print " },\n"; + } + } + print " },\n"; } } @@ -3414,21 +3412,21 @@ sub absolutedir { sub quotify { my %processors = ( - perl => sub { my $x = shift; - $x =~ s/([\\\$\@"])/\\$1/g; - return '"'.$x.'"'; }, - maybeshell => sub { my $x = shift; - (my $y = $x) =~ s/([\\\"])/\\$1/g; - if ($x ne $y || $x =~ m|\s|) { - return '"'.$y.'"'; - } else { - return $x; - } - }, - ); + perl => sub { my $x = shift; + $x =~ s/([\\\$\@"])/\\$1/g; + return '"'.$x.'"'; }, + maybeshell => sub { my $x = shift; + (my $y = $x) =~ s/([\\\"])/\\$1/g; + if ($x ne $y || $x =~ m|\s|) { + return '"'.$y.'"'; + } else { + return $x; + } + }, + ); my $for = shift; my $processor = - defined($processors{$for}) ? $processors{$for} : sub { shift; }; + defined($processors{$for}) ? $processors{$for} : sub { shift; }; return map { $processor->($_); } @_; } diff --git a/NEWS b/NEWS index c743dbc6..3c38c782 100644 --- a/NEWS +++ b/NEWS @@ -13,6 +13,7 @@ 3.0.0 o Added EVP_MAC, an EVP layer MAC API, and a generic EVP_PKEY to EVP_MAC bridge. + o Removed the heartbeat message in DTLS feature. Major changes between OpenSSL 1.1.1 and OpenSSL 1.1.1a [20 Nov 2018] diff --git a/apps/apps.c b/apps/apps.c index 06b54348..8921c18c 100644 --- a/apps/apps.c +++ b/apps/apps.c @@ -1623,8 +1623,10 @@ X509_NAME *parse_name(const char *cp, long chtype, int canmulti) if (n == NULL) return NULL; work = OPENSSL_strdup(cp); - if (work == NULL) + if (work == NULL) { + BIO_printf(bio_err, "%s: Error copying name input\n", opt_getprog()); goto err; + } while (*cp) { char *bp = work; @@ -1639,7 +1641,7 @@ X509_NAME *parse_name(const char *cp, long chtype, int canmulti) *bp++ = *cp++; if (*cp == '\0') { BIO_printf(bio_err, - "%s: Hit end of string before finding the equals.\n", + "%s: Hit end of string before finding the '='\n", opt_getprog()); goto err; } @@ -1655,8 +1657,8 @@ X509_NAME *parse_name(const char *cp, long chtype, int canmulti) } if (*cp == '\\' && *++cp == '\0') { BIO_printf(bio_err, - "%s: escape character at end of string\n", - opt_getprog()); + "%s: escape character at end of string\n", + opt_getprog()); goto err; } } @@ -1670,7 +1672,7 @@ X509_NAME *parse_name(const char *cp, long chtype, int canmulti) nid = OBJ_txt2nid(typestr); if (nid == NID_undef) { BIO_printf(bio_err, "%s: Skipping unknown attribute \"%s\"\n", - opt_getprog(), typestr); + opt_getprog(), typestr); continue; } if (*valstr == '\0') { @@ -1681,8 +1683,11 @@ X509_NAME *parse_name(const char *cp, long chtype, int canmulti) } if (!X509_NAME_add_entry_by_NID(n, nid, chtype, valstr, strlen((char *)valstr), - -1, ismulti ? -1 : 0)) + -1, ismulti ? -1 : 0)) { + BIO_printf(bio_err, "%s: Error adding name attribute \"/%s=%s\"\n", + opt_getprog(), typestr ,valstr); goto err; + } } OPENSSL_free(work); diff --git a/apps/dgst.c b/apps/dgst.c index 34494a40..7b433385 100644 --- a/apps/dgst.c +++ b/apps/dgst.c @@ -86,6 +86,7 @@ int dgst_main(int argc, char **argv) const EVP_MD *md = NULL, *m; const char *outfile = NULL, *keyfile = NULL, *prog = NULL; const char *sigfile = NULL; + const char *md_name = NULL; OPTION_CHOICE o; int separator = 0, debug = 0, keyform = FORMAT_PEM, siglen = 0; int i, ret = 1, out_bin = -1, want_pub = 0, do_verify = 0; @@ -365,13 +366,15 @@ int dgst_main(int argc, char **argv) BIO_get_md_ctx(bmd, &tctx); md = EVP_MD_CTX_md(tctx); } + if (md != NULL) + md_name = EVP_MD_name(md); if (argc == 0) { BIO_set_fp(in, stdin, BIO_NOCLOSE); ret = do_fp(out, buf, inp, separator, out_bin, sigkey, sigbuf, - siglen, NULL, NULL, "stdin"); + siglen, NULL, md_name, "stdin"); } else { - const char *md_name = NULL, *sig_name = NULL; + const char *sig_name = NULL; if (!out_bin) { if (sigkey != NULL) { const EVP_PKEY_ASN1_METHOD *ameth; @@ -380,8 +383,6 @@ int dgst_main(int argc, char **argv) EVP_PKEY_asn1_get0_info(NULL, NULL, NULL, NULL, &sig_name, ameth); } - if (md != NULL) - md_name = EVP_MD_name(md); } ret = 0; for (i = 0; i < argc; i++) { @@ -413,13 +414,52 @@ int dgst_main(int argc, char **argv) return ret; } +/* + * The newline_escape_filename function performs newline escaping for any + * filename that contains a newline. This function also takes a pointer + * to backslash. The backslash pointer is a flag to indicating whether a newline + * is present in the filename. If a newline is present, the backslash flag is + * set and the output format will contain a backslash at the beginning of the + * digest output. This output format is to replicate the output format found + * in the '*sum' checksum programs. This aims to preserve backward + * compatibility. + */ +static const char *newline_escape_filename(const char *file, int * backslash) +{ + size_t i, e = 0, length = strlen(file), newline_count = 0, mem_len = 0; + char *file_cpy = NULL; + + for (i = 0; i < length; i++) + if (file[i] == '\n') + newline_count++; + + mem_len = length + newline_count + 1; + file_cpy = app_malloc(mem_len, file); + i = 0; + + while(e < length) { + const char c = file[e]; + if (c == '\n') { + file_cpy[i++] = '\\'; + file_cpy[i++] = 'n'; + *backslash = 1; + } else { + file_cpy[i++] = c; + } + e++; + } + file_cpy[i] = '\0'; + return (const char*)file_cpy; +} + + int do_fp(BIO *out, unsigned char *buf, BIO *bp, int sep, int binout, EVP_PKEY *key, unsigned char *sigin, int siglen, const char *sig_name, const char *md_name, const char *file) { size_t len; - int i; + int i, backslash = 0; for (;;) { i = BIO_read(bp, (char *)buf, BUFSIZE); @@ -467,9 +507,16 @@ int do_fp(BIO *out, unsigned char *buf, BIO *bp, int sep, int binout, if (binout) { BIO_write(out, buf, len); } else if (sep == 2) { + file = newline_escape_filename(file, &backslash); + + if (backslash == 1) + BIO_puts(out, "\\"); + for (i = 0; i < (int)len; i++) BIO_printf(out, "%02x", buf[i]); + BIO_printf(out, " *%s\n", file); + OPENSSL_free((char *)file); } else { if (sig_name != NULL) { BIO_puts(out, sig_name); diff --git a/apps/mac.c b/apps/mac.c index a02779b2..946c3c7a 100644 --- a/apps/mac.c +++ b/apps/mac.c @@ -76,8 +76,7 @@ int mac_main(int argc, char **argv) buf = app_malloc(BUFSIZE, "I/O buffer"); while ((o = opt_next()) != OPT_EOF) { switch (o) { - case OPT_EOF: - case OPT_ERR: + default: opthelp: BIO_printf(bio_err, "%s: Use -help for summary.\n", prog); goto err; diff --git a/apps/ocsp.c b/apps/ocsp.c index 09eeb9cf..ddcab4c2 100644 --- a/apps/ocsp.c +++ b/apps/ocsp.c @@ -641,8 +641,10 @@ redo_accept: goto end; } - if (req != NULL && add_nonce) - OCSP_request_add1_nonce(req, NULL, -1); + if (req != NULL && add_nonce) { + if (!OCSP_request_add1_nonce(req, NULL, -1)) + goto end; + } if (signfile != NULL) { if (keyfile == NULL) @@ -1245,7 +1247,10 @@ static void make_ocsp_response(BIO *err, OCSP_RESPONSE **resp, OCSP_REQUEST *req goto end; } } - OCSP_basic_sign_ctx(bs, rcert, mctx, rother, flags); + if (!OCSP_basic_sign_ctx(bs, rcert, mctx, rother, flags)) { + *resp = OCSP_response_create(OCSP_RESPONSE_STATUS_INTERNALERROR, bs); + goto end; + } if (badsig) { const ASN1_OCTET_STRING *sig = OCSP_resp_get0_signature(bs); diff --git a/apps/openssl.c b/apps/openssl.c index 119d3e8f..9c0d933d 100644 --- a/apps/openssl.c +++ b/apps/openssl.c @@ -118,6 +118,8 @@ static char *make_config_name(void) return p; } + +#ifndef OPENSSL_NO_TRACE typedef struct tracedata_st { BIO *bio; unsigned int ingroup:1; @@ -183,6 +185,33 @@ static void cleanup_trace(void) sk_tracedata_pop_free(trace_data_stack, tracedata_free); } +static void setup_trace_category(int category) +{ + BIO *channel; + tracedata *trace_data; + + if (OSSL_trace_enabled(category)) + return; + + channel = BIO_push(BIO_new(apps_bf_prefix()), + dup_bio_err(FORMAT_TEXT)); + trace_data = OPENSSL_zalloc(sizeof(*trace_data)); + + if (trace_data == NULL + || (trace_data->bio = channel) == NULL + || OSSL_trace_set_callback(category, internal_trace_cb, + trace_data) == 0 + || sk_tracedata_push(trace_data_stack, trace_data) == 0) { + + fprintf(stderr, + "warning: unable to setup trace callback for category '%s'.\n", + OSSL_trace_get_category_name(category)); + + OSSL_trace_set_callback(category, NULL, NULL); + BIO_free_all(channel); + } +} + static void setup_trace(const char *str) { char *val; @@ -197,26 +226,15 @@ static void setup_trace(const char *str) for (valp = val; (item = strtok(valp, ",")) != NULL; valp = NULL) { int category = OSSL_trace_get_category_num(item); - if (category >= 0) { - BIO *channel = BIO_push(BIO_new(apps_bf_prefix()), - dup_bio_err(FORMAT_TEXT)); - tracedata *trace_data = OPENSSL_zalloc(sizeof(*trace_data)); - - if (trace_data == NULL - || (trace_data->bio = channel) == NULL - || OSSL_trace_set_callback(category, internal_trace_cb, - trace_data) == 0 - || sk_tracedata_push(trace_data_stack, trace_data) == 0) { - OSSL_trace_set_callback(category, NULL, NULL); - BIO_free_all(channel); - fprintf(stderr, - "warning: unable to setup trace callback for category '%s'.\n", - item); - } + if (category == OSSL_TRACE_CATEGORY_ALL) { + while (++category < OSSL_TRACE_CATEGORY_NUM) + setup_trace_category(category); + break; + } else if (category > 0) { + setup_trace_category(category); } else { fprintf(stderr, - "warning: unknown trace category: '%s'.\n", - item); + "warning: unknown trace category: '%s'.\n", item); } } } @@ -224,6 +242,7 @@ static void setup_trace(const char *str) OPENSSL_free(val); atexit(cleanup_trace); } +#endif /* OPENSSL_NO_TRACE */ int main(int argc, char *argv[]) { @@ -260,7 +279,9 @@ int main(int argc, char *argv[]) */ atexit(destroy_prefix_method); +#ifndef OPENSSL_NO_TRACE setup_trace(getenv("OPENSSL_TRACE")); +#endif p = getenv("OPENSSL_DEBUG_MEMORY"); if (p != NULL && strcmp(p, "on") == 0) @@ -715,8 +736,9 @@ static void list_type(FUNC_TYPE ft, int one) { FUNCTION *fp; int i = 0; - DISPLAY_COLUMNS dc = {0}; + DISPLAY_COLUMNS dc; + memset(&dc, 0, sizeof(dc)); if (!one) calculate_columns(&dc); @@ -922,9 +944,6 @@ static void list_disabled(void) #ifdef OPENSSL_NO_GOST BIO_puts(bio_out, "GOST\n"); #endif -#ifdef OPENSSL_NO_HEARTBEATS - BIO_puts(bio_out, "HEARTBEATS\n"); -#endif #ifdef OPENSSL_NO_IDEA BIO_puts(bio_out, "IDEA\n"); #endif diff --git a/apps/pkeyutl.c b/apps/pkeyutl.c index 0c27589b..7f1e6213 100644 --- a/apps/pkeyutl.c +++ b/apps/pkeyutl.c @@ -13,9 +13,7 @@ #include #include #include -#ifndef OPENSSL_NO_POSIX_IO -# include -#endif +#include #define KEY_NONE 0 #define KEY_PRIVKEY 1 @@ -348,15 +346,12 @@ int pkeyutl_main(int argc, char **argv) if (pkey_op != EVP_PKEY_OP_DERIVE) { in = bio_open_default(infile, 'r', FORMAT_BINARY); -#ifndef OPENSSL_NO_POSIX_IO - if (infile != NULL) - { + if (infile != NULL) { struct stat st; if (stat(infile, &st) == 0 && st.st_size <= INT_MAX) filesize = (int)st.st_size; } -#endif if (in == NULL) goto end; } diff --git a/apps/s_cb.c b/apps/s_cb.c index 705550b6..935ea902 100644 --- a/apps/s_cb.c +++ b/apps/s_cb.c @@ -600,22 +600,6 @@ void msg_cb(int write_p, int version, int content_type, const void *buf, case 23: str_content_type = ", ApplicationData"; break; -#ifndef OPENSSL_NO_HEARTBEATS - case 24: - str_details1 = ", Heartbeat"; - - if (len > 0) { - switch (bp[0]) { - case 1: - str_details1 = ", HeartbeatRequest"; - break; - case 2: - str_details1 = ", HeartbeatResponse"; - break; - } - } - break; -#endif } } @@ -656,7 +640,6 @@ static STRINT_PAIR tlsext_types[] = { {"SRP", TLSEXT_TYPE_srp}, {"signature algorithms", TLSEXT_TYPE_signature_algorithms}, {"use SRTP", TLSEXT_TYPE_use_srtp}, - {"heartbeat", TLSEXT_TYPE_heartbeat}, {"session ticket", TLSEXT_TYPE_session_ticket}, {"renegotiation info", TLSEXT_TYPE_renegotiate}, {"signed certificate timestamps", TLSEXT_TYPE_signed_certificate_timestamp}, @@ -683,6 +666,53 @@ static STRINT_PAIR tlsext_types[] = { {NULL} }; +/* from rfc8446 4.2.3. + gost (https://tools.ietf.org/id/draft-smyshlyaev-tls12-gost-suites-04.html) */ +static STRINT_PAIR signature_tls13_scheme_list[] = { + {"rsa_pkcs1_sha1", 0x0201 /* TLSEXT_SIGALG_rsa_pkcs1_sha1 */}, + {"ecdsa_sha1", 0x0203 /* TLSEXT_SIGALG_ecdsa_sha1 */}, +/* {"rsa_pkcs1_sha224", 0x0301 TLSEXT_SIGALG_rsa_pkcs1_sha224}, not in rfc8446 */ +/* {"ecdsa_sha224", 0x0303 TLSEXT_SIGALG_ecdsa_sha224} not in rfc8446 */ + {"rsa_pkcs1_sha256", 0x0401 /* TLSEXT_SIGALG_rsa_pkcs1_sha256 */}, + {"ecdsa_secp256r1_sha256", 0x0403 /* TLSEXT_SIGALG_ecdsa_secp256r1_sha256 */}, + {"rsa_pkcs1_sha384", 0x0501 /* TLSEXT_SIGALG_rsa_pkcs1_sha384 */}, + {"ecdsa_secp384r1_sha384", 0x0503 /* TLSEXT_SIGALG_ecdsa_secp384r1_sha384 */}, + {"rsa_pkcs1_sha512", 0x0601 /* TLSEXT_SIGALG_rsa_pkcs1_sha512 */}, + {"ecdsa_secp521r1_sha512", 0x0603 /* TLSEXT_SIGALG_ecdsa_secp521r1_sha512 */}, + {"rsa_pss_rsae_sha256", 0x0804 /* TLSEXT_SIGALG_rsa_pss_rsae_sha256 */}, + {"rsa_pss_rsae_sha384", 0x0805 /* TLSEXT_SIGALG_rsa_pss_rsae_sha384 */}, + {"rsa_pss_rsae_sha512", 0x0806 /* TLSEXT_SIGALG_rsa_pss_rsae_sha512 */}, + {"ed25519", 0x0807 /* TLSEXT_SIGALG_ed25519 */}, + {"ed448", 0x0808 /* TLSEXT_SIGALG_ed448 */}, + {"rsa_pss_pss_sha256", 0x0809 /* TLSEXT_SIGALG_rsa_pss_pss_sha256 */}, + {"rsa_pss_pss_sha384", 0x080a /* TLSEXT_SIGALG_rsa_pss_pss_sha384 */}, + {"rsa_pss_pss_sha512", 0x080b /* TLSEXT_SIGALG_rsa_pss_pss_sha512 */}, + {"gostr34102001", 0xeded /* TLSEXT_SIGALG_gostr34102001_gostr3411 */}, + {"gostr34102012_256", 0xeeee /* TLSEXT_SIGALG_gostr34102012_256_gostr34112012_256 */}, + {"gostr34102012_512", 0xefef /* TLSEXT_SIGALG_gostr34102012_512_gostr34112012_512 */}, + {NULL} +}; + +/* from rfc5246 7.4.1.4.1. */ +static STRINT_PAIR signature_tls12_alg_list[] = { + {"anonymous", TLSEXT_signature_anonymous /* 0 */}, + {"RSA", TLSEXT_signature_rsa /* 1 */}, + {"DSA", TLSEXT_signature_dsa /* 2 */}, + {"ECDSA", TLSEXT_signature_ecdsa /* 3 */}, + {NULL} +}; + +/* from rfc5246 7.4.1.4.1. */ +static STRINT_PAIR signature_tls12_hash_list[] = { + {"none", TLSEXT_hash_none /* 0 */}, + {"MD5", TLSEXT_hash_md5 /* 1 */}, + {"SHA1", TLSEXT_hash_sha1 /* 2 */}, + {"SHA224", TLSEXT_hash_sha224 /* 3 */}, + {"SHA256", TLSEXT_hash_sha256 /* 4 */}, + {"SHA384", TLSEXT_hash_sha384 /* 5 */}, + {"SHA512", TLSEXT_hash_sha512 /* 6 */}, + {NULL} +}; + void tlsext_cb(SSL *s, int client_server, int type, const unsigned char *data, int len, void *arg) { @@ -1282,9 +1312,9 @@ static STRINT_PAIR callback_types[] = { {"Supported Curve", SSL_SECOP_CURVE_SUPPORTED}, {"Shared Curve", SSL_SECOP_CURVE_SHARED}, {"Check Curve", SSL_SECOP_CURVE_CHECK}, - {"Supported Signature Algorithm digest", SSL_SECOP_SIGALG_SUPPORTED}, - {"Shared Signature Algorithm digest", SSL_SECOP_SIGALG_SHARED}, - {"Check Signature Algorithm digest", SSL_SECOP_SIGALG_CHECK}, + {"Supported Signature Algorithm", SSL_SECOP_SIGALG_SUPPORTED}, + {"Shared Signature Algorithm", SSL_SECOP_SIGALG_SHARED}, + {"Check Signature Algorithm", SSL_SECOP_SIGALG_CHECK}, {"Signature Algorithm mask", SSL_SECOP_SIGALG_MASK}, {"Certificate chain EE key", SSL_SECOP_EE_KEY}, {"Certificate chain CA key", SSL_SECOP_CA_KEY}, @@ -1304,29 +1334,37 @@ static int security_callback_debug(const SSL *s, const SSL_CTX *ctx, security_debug_ex *sdb = ex; int rv, show_bits = 1, cert_md = 0; const char *nm; + int show_nm; rv = sdb->old_cb(s, ctx, op, bits, nid, other, ex); if (rv == 1 && sdb->verbose < 2) return 1; BIO_puts(sdb->out, "Security callback: "); nm = lookup(op, callback_types, NULL); + show_nm = nm != NULL; switch (op) { case SSL_SECOP_TICKET: case SSL_SECOP_COMPRESSION: show_bits = 0; - nm = NULL; + show_nm = 0; break; case SSL_SECOP_VERSION: BIO_printf(sdb->out, "Version=%s", lookup(nid, ssl_versions, "???")); show_bits = 0; - nm = NULL; + show_nm = 0; break; case SSL_SECOP_CA_MD: case SSL_SECOP_PEER_CA_MD: cert_md = 1; break; + case SSL_SECOP_SIGALG_SUPPORTED: + case SSL_SECOP_SIGALG_SHARED: + case SSL_SECOP_SIGALG_CHECK: + case SSL_SECOP_SIGALG_MASK: + show_nm = 0; + break; } - if (nm != NULL) + if (show_nm) BIO_printf(sdb->out, "%s=", nm); switch (op & SSL_SECOP_OTHER_TYPE) { @@ -1373,27 +1411,28 @@ static int security_callback_debug(const SSL *s, const SSL_CTX *ctx, { const unsigned char *salg = other; const char *sname = NULL; - switch (salg[1]) { - case TLSEXT_signature_anonymous: - sname = "anonymous"; - break; - case TLSEXT_signature_rsa: - sname = "RSA"; - break; - case TLSEXT_signature_dsa: - sname = "DSA"; - break; - case TLSEXT_signature_ecdsa: - sname = "ECDSA"; - break; - } + int raw_sig_code = (salg[0] << 8) + salg[1]; /* always big endian (msb, lsb) */ + /* raw_sig_code: signature_scheme from tls1.3, or signature_and_hash from tls1.2 */ - BIO_puts(sdb->out, OBJ_nid2sn(nid)); - if (sname) - BIO_printf(sdb->out, ", algorithm=%s", sname); + if (nm != NULL) + BIO_printf(sdb->out, "%s", nm); else - BIO_printf(sdb->out, ", algid=%d", salg[1]); - break; + BIO_printf(sdb->out, "s_cb.c:security_callback_debug op=0x%x", op); + + sname = lookup(raw_sig_code, signature_tls13_scheme_list, NULL); + if (sname != NULL) { + BIO_printf(sdb->out, " scheme=%s", sname); + } else { + int alg_code = salg[1]; + int hash_code = salg[0]; + const char *alg_str = lookup(alg_code, signature_tls12_alg_list, NULL); + const char *hash_str = lookup(hash_code, signature_tls12_hash_list, NULL); + + if (alg_str != NULL && hash_str != NULL) + BIO_printf(sdb->out, " digest=%s, algorithm=%s", hash_str, alg_str); + else + BIO_printf(sdb->out, " scheme=unknown(0x%04x)", raw_sig_code); + } } } diff --git a/apps/s_client.c b/apps/s_client.c index 7a41d831..6d7a83f3 100644 --- a/apps/s_client.c +++ b/apps/s_client.c @@ -3111,15 +3111,7 @@ int s_client_main(int argc, char **argv) cbuf[0] == 'K' ? SSL_KEY_UPDATE_REQUESTED : SSL_KEY_UPDATE_NOT_REQUESTED); cbuf_len = 0; - } -#ifndef OPENSSL_NO_HEARTBEATS - else if ((!c_ign_eof) && (cbuf[0] == 'B' && cmdletters)) { - BIO_printf(bio_err, "HEARTBEATING\n"); - SSL_heartbeat(con); - cbuf_len = 0; - } -#endif - else { + } else { cbuf_len = i; cbuf_off = 0; #ifdef CHARSET_EBCDIC diff --git a/apps/s_server.c b/apps/s_server.c index fbbfd6c9..92d4579a 100644 --- a/apps/s_server.c +++ b/apps/s_server.c @@ -2507,14 +2507,6 @@ static int sv_body(int s, int stype, int prot, unsigned char *context) */ goto err; } -#ifndef OPENSSL_NO_HEARTBEATS - if ((buf[0] == 'B') && ((buf[1] == '\n') || (buf[1] == '\r'))) { - BIO_printf(bio_err, "HEARTBEATING\n"); - SSL_heartbeat(con); - i = 0; - continue; - } -#endif if ((buf[0] == 'r') && ((buf[1] == '\n') || (buf[1] == '\r'))) { SSL_renegotiate(con); i = SSL_do_handshake(con); diff --git a/apps/speed.c b/apps/speed.c index 1125f5a0..5674e324 100644 --- a/apps/speed.c +++ b/apps/speed.c @@ -492,30 +492,35 @@ static const OPT_PAIR rsa_choices[] = { static double rsa_results[RSA_NUM][2]; /* 2 ops: sign then verify */ #endif /* OPENSSL_NO_RSA */ -#define R_EC_P160 0 -#define R_EC_P192 1 -#define R_EC_P224 2 -#define R_EC_P256 3 -#define R_EC_P384 4 -#define R_EC_P521 5 -#define R_EC_K163 6 -#define R_EC_K233 7 -#define R_EC_K283 8 -#define R_EC_K409 9 -#define R_EC_K571 10 -#define R_EC_B163 11 -#define R_EC_B233 12 -#define R_EC_B283 13 -#define R_EC_B409 14 -#define R_EC_B571 15 -#define R_EC_BRP256R1 16 -#define R_EC_BRP256T1 17 -#define R_EC_BRP384R1 18 -#define R_EC_BRP384T1 19 -#define R_EC_BRP512R1 20 -#define R_EC_BRP512T1 21 -#define R_EC_X25519 22 -#define R_EC_X448 23 +enum { + R_EC_P160, + R_EC_P192, + R_EC_P224, + R_EC_P256, + R_EC_P384, + R_EC_P521, +#ifndef OPENSSL_NO_EC2M + R_EC_K163, + R_EC_K233, + R_EC_K283, + R_EC_K409, + R_EC_K571, + R_EC_B163, + R_EC_B233, + R_EC_B283, + R_EC_B409, + R_EC_B571, +#endif + R_EC_BRP256R1, + R_EC_BRP256T1, + R_EC_BRP384R1, + R_EC_BRP384T1, + R_EC_BRP512R1, + R_EC_BRP512T1, + R_EC_X25519, + R_EC_X448 +}; + #ifndef OPENSSL_NO_EC static OPT_PAIR ecdsa_choices[] = { {"ecdsap160", R_EC_P160}, @@ -524,6 +529,7 @@ static OPT_PAIR ecdsa_choices[] = { {"ecdsap256", R_EC_P256}, {"ecdsap384", R_EC_P384}, {"ecdsap521", R_EC_P521}, +# ifndef OPENSSL_NO_EC2M {"ecdsak163", R_EC_K163}, {"ecdsak233", R_EC_K233}, {"ecdsak283", R_EC_K283}, @@ -534,6 +540,7 @@ static OPT_PAIR ecdsa_choices[] = { {"ecdsab283", R_EC_B283}, {"ecdsab409", R_EC_B409}, {"ecdsab571", R_EC_B571}, +# endif {"ecdsabrp256r1", R_EC_BRP256R1}, {"ecdsabrp256t1", R_EC_BRP256T1}, {"ecdsabrp384r1", R_EC_BRP384R1}, @@ -552,6 +559,7 @@ static const OPT_PAIR ecdh_choices[] = { {"ecdhp256", R_EC_P256}, {"ecdhp384", R_EC_P384}, {"ecdhp521", R_EC_P521}, +# ifndef OPENSSL_NO_EC2M {"ecdhk163", R_EC_K163}, {"ecdhk233", R_EC_K233}, {"ecdhk283", R_EC_K283}, @@ -562,6 +570,7 @@ static const OPT_PAIR ecdh_choices[] = { {"ecdhb283", R_EC_B283}, {"ecdhb409", R_EC_B409}, {"ecdhb571", R_EC_B571}, +# endif {"ecdhbrp256r1", R_EC_BRP256R1}, {"ecdhbrp256t1", R_EC_BRP256T1}, {"ecdhbrp384r1", R_EC_BRP384R1}, @@ -1524,6 +1533,7 @@ int speed_main(int argc, char **argv) {"nistp256", NID_X9_62_prime256v1, 256}, {"nistp384", NID_secp384r1, 384}, {"nistp521", NID_secp521r1, 521}, +# ifndef OPENSSL_NO_EC2M /* Binary Curves */ {"nistk163", NID_sect163k1, 163}, {"nistk233", NID_sect233k1, 233}, @@ -1535,6 +1545,7 @@ int speed_main(int argc, char **argv) {"nistb283", NID_sect283r1, 283}, {"nistb409", NID_sect409r1, 409}, {"nistb571", NID_sect571r1, 571}, +# endif {"brainpoolP256r1", NID_brainpoolP256r1, 256}, {"brainpoolP256t1", NID_brainpoolP256t1, 256}, {"brainpoolP384r1", NID_brainpoolP384r1, 384}, @@ -2063,6 +2074,7 @@ int speed_main(int argc, char **argv) } } } +# ifndef OPENSSL_NO_EC2M ecdsa_c[R_EC_K163][0] = count / 1000; ecdsa_c[R_EC_K163][1] = count / 1000 / 2; for (i = R_EC_K233; i <= R_EC_K571; i++) { @@ -2091,6 +2103,7 @@ int speed_main(int argc, char **argv) } } } +# endif ecdh_c[R_EC_P160][0] = count / 1000; for (i = R_EC_P192; i <= R_EC_P521; i++) { @@ -2103,6 +2116,7 @@ int speed_main(int argc, char **argv) } } } +# ifndef OPENSSL_NO_EC2M ecdh_c[R_EC_K163][0] = count / 1000; for (i = R_EC_K233; i <= R_EC_K571; i++) { ecdh_c[i][0] = ecdh_c[i - 1][0] / 2; @@ -2125,6 +2139,7 @@ int speed_main(int argc, char **argv) } } } +# endif /* repeated code good to factorize */ ecdh_c[R_EC_BRP256R1][0] = count / 1000; for (i = R_EC_BRP384R1; i <= R_EC_BRP512R1; i += 2) { diff --git a/apps/verify.c b/apps/verify.c index fcd10dd9..67d32762 100644 --- a/apps/verify.c +++ b/apps/verify.c @@ -80,6 +80,7 @@ int verify_main(int argc, char **argv) OPTION_CHOICE o; unsigned char *sm2_id = NULL; size_t sm2_idlen = 0; + int sm2_free = 0; if ((vpm = X509_VERIFY_PARAM_new()) == NULL) goto end; @@ -174,6 +175,7 @@ int verify_main(int argc, char **argv) break; case OPT_SM2HEXID: /* try to parse the input as hex string first */ + sm2_free = 1; sm2_id = OPENSSL_hexstr2buf(opt_arg(), (long *)&sm2_idlen); if (sm2_id == NULL) { BIO_printf(bio_err, "Invalid hex string input\n"); @@ -216,6 +218,8 @@ int verify_main(int argc, char **argv) } end: + if (sm2_free) + OPENSSL_free(sm2_id); X509_VERIFY_PARAM_free(vpm); X509_STORE_free(store); sk_X509_pop_free(untrusted, X509_free); diff --git a/apps/x509.c b/apps/x509.c index e4d5e079..3a5d5612 100644 --- a/apps/x509.c +++ b/apps/x509.c @@ -49,8 +49,8 @@ typedef enum OPTION_choice { OPT_ERR = -1, OPT_EOF = 0, OPT_HELP, OPT_INFORM, OPT_OUTFORM, OPT_KEYFORM, OPT_REQ, OPT_CAFORM, OPT_CAKEYFORM, OPT_SIGOPT, OPT_DAYS, OPT_PASSIN, OPT_EXTFILE, - OPT_EXTENSIONS, OPT_IN, OPT_OUT, OPT_SIGNKEY, OPT_CA, - OPT_CAKEY, OPT_CASERIAL, OPT_SET_SERIAL, OPT_FORCE_PUBKEY, + OPT_EXTENSIONS, OPT_IN, OPT_OUT, OPT_SIGNKEY, OPT_CA, OPT_CAKEY, + OPT_CASERIAL, OPT_SET_SERIAL, OPT_NEW, OPT_FORCE_PUBKEY, OPT_SUBJ, OPT_ADDTRUST, OPT_ADDREJECT, OPT_SETALIAS, OPT_CERTOPT, OPT_NAMEOPT, OPT_C, OPT_EMAIL, OPT_OCSP_URI, OPT_SERIAL, OPT_NEXT_SERIAL, OPT_MODULUS, OPT_PUBKEY, OPT_X509TOREQ, OPT_TEXT, OPT_HASH, @@ -132,7 +132,9 @@ const OPTIONS x509_options[] = { {"CAform", OPT_CAFORM, 'F', "CA format - default PEM"}, {"CAkeyform", OPT_CAKEYFORM, 'f', "CA key format - default PEM"}, {"sigopt", OPT_SIGOPT, 's', "Signature parameter in n:v form"}, + {"new", OPT_NEW, '-', "Generate a certificate from scratch"}, {"force_pubkey", OPT_FORCE_PUBKEY, '<', "Force the key to put inside certificate"}, + {"subj", OPT_SUBJ, 's', "Set or override certificate subject (and issuer)"}, {"next_serial", OPT_NEXT_SERIAL, '-', "Increment current certificate serial number"}, {"clrreject", OPT_CLRREJECT, '-', "Clears all the prohibited or rejected uses of the certificate"}, @@ -158,6 +160,11 @@ int x509_main(int argc, char **argv) BIO *out = NULL; CONF *extconf = NULL; EVP_PKEY *Upkey = NULL, *CApkey = NULL, *fkey = NULL; + int newcert = 0; + char *subj = NULL; + X509_NAME *fsubj = NULL; + const unsigned long chtype = MBSTRING_ASC; + const int multirdn = 0; STACK_OF(ASN1_OBJECT) *trust = NULL, *reject = NULL; STACK_OF(OPENSSL_STRING) *sigopts = NULL; X509 *x = NULL, *xca = NULL; @@ -281,9 +288,15 @@ int x509_main(int argc, char **argv) if ((sno = s2i_ASN1_INTEGER(NULL, opt_arg())) == NULL) goto opthelp; break; + case OPT_NEW: + newcert = 1; + break; case OPT_FORCE_PUBKEY: fkeyfile = opt_arg(); break; + case OPT_SUBJ: + subj = opt_arg(); + break; case OPT_ADDTRUST: if ((objtmp = OBJ_txt2obj(opt_arg(), 0)) == NULL) { BIO_printf(bio_err, @@ -477,18 +490,38 @@ int x509_main(int argc, char **argv) goto end; } + if (newcert && infile != NULL) { + BIO_printf(bio_err, "The -in option must not be used since -new is set\n"); + goto end; + } + if (newcert && fkeyfile == NULL) { + BIO_printf(bio_err, + "The -new option requires a public key to be set using -force_pubkey\n"); + goto end; + } if (fkeyfile != NULL) { fkey = load_pubkey(fkeyfile, keyformat, 0, NULL, e, "Forced key"); if (fkey == NULL) goto end; } - if ((CAkeyfile == NULL) && (CA_flag) && (CAformat == FORMAT_PEM)) { + if (newcert && subj == NULL) { + BIO_printf(bio_err, + "The -new option requires a subject to be set using -subj\n"); + goto end; + } + if (subj != NULL && (fsubj = parse_name(subj, chtype, multirdn)) == NULL) + goto end; + + if (CAkeyfile == NULL && CA_flag && CAformat == FORMAT_PEM) { CAkeyfile = CAfile; - } else if ((CA_flag) && (CAkeyfile == NULL)) { + } else if (CA_flag && CAkeyfile == NULL) { BIO_printf(bio_err, "need to specify a CAkey if using the CA command\n"); goto end; + } else if (!CA_flag && CAkeyfile != NULL) { + BIO_printf(bio_err, + "ignoring -CAkey option since no -CA option is given\n"); } if (extfile != NULL) { @@ -516,10 +549,6 @@ int x509_main(int argc, char **argv) EVP_PKEY *pkey; BIO *in; - if (!sign_flag && !CA_flag) { - BIO_printf(bio_err, "We need a private key to sign with\n"); - goto end; - } in = bio_open_default(infile, 'r', informat); if (in == NULL) goto end; @@ -537,21 +566,30 @@ int x509_main(int argc, char **argv) } i = X509_REQ_verify(req, pkey); if (i < 0) { - BIO_printf(bio_err, "Signature verification error\n"); + BIO_printf(bio_err, "Request self-signature verification error\n"); ERR_print_errors(bio_err); goto end; } if (i == 0) { BIO_printf(bio_err, - "Signature did not match the certificate request\n"); + "Request self-signature did not match the certificate request\n"); goto end; } else { - BIO_printf(bio_err, "Signature ok\n"); + BIO_printf(bio_err, "Request self-signature ok\n"); } print_name(bio_err, "subject=", X509_REQ_get_subject_name(req), get_nameopt()); + } + if (reqfile || newcert) { + X509_NAME *n; + + if (!sign_flag && CAkeyfile == NULL) { + BIO_printf(bio_err, + "We need a private key to sign with, use -signkey or -CAkey or -CA with private key\n"); + goto end; + } if ((x = X509_new()) == NULL) goto end; @@ -567,9 +605,8 @@ int x509_main(int argc, char **argv) goto end; } - if (!X509_set_issuer_name(x, X509_REQ_get_subject_name(req))) - goto end; - if (!X509_set_subject_name(x, X509_REQ_get_subject_name(req))) + n = req == NULL ? fsubj : X509_REQ_get_subject_name(req); + if (!X509_set_issuer_name(x, n) || !X509_set_subject_name(x, n)) goto end; if (!set_cert_times(x, NULL, NULL, days)) goto end; @@ -582,6 +619,8 @@ int x509_main(int argc, char **argv) goto end; if (fkey != NULL && !X509_set_pubkey(x, fkey)) goto end; + if (fsubj != NULL && !X509_set_subject_name(x, fsubj)) + goto end; } if (CA_flag) { @@ -654,7 +693,7 @@ int x509_main(int argc, char **argv) i2a_ASN1_INTEGER(out, ser); ASN1_INTEGER_free(ser); BIO_puts(out, "\n"); - } else if ((email == i) || (ocsp_uri == i)) { + } else if (email == i || ocsp_uri == i) { int j; STACK_OF(OPENSSL_STRING) *emlst; if (email == i) @@ -788,7 +827,7 @@ int x509_main(int argc, char **argv) } /* should be in the library */ - else if ((sign_flag == i) && (x509req == 0)) { + else if (sign_flag == i && x509req == 0) { BIO_printf(bio_err, "Getting Private key\n"); if (Upkey == NULL) { Upkey = load_key(keyfile, keyformat, 0, @@ -890,6 +929,7 @@ int x509_main(int argc, char **argv) NCONF_free(extconf); BIO_free_all(out); X509_STORE_free(ctx); + X509_NAME_free(fsubj); X509_REQ_free(req); X509_free(x); X509_free(xca); diff --git a/build.info b/build.info index bea14418..a0ecb218 100644 --- a/build.info +++ b/build.info @@ -1,6 +1,6 @@ # Note that some of these directories are filtered in Configure. Look for # %skipdir there for further explanations. -SUBDIRS=crypto ssl apps test util tools fuzz engines +SUBDIRS=crypto ssl apps test util tools fuzz engines providers LIBS=libcrypto libssl INCLUDE[libcrypto]=. crypto/include include diff --git a/crypto/aes/asm/aesp8-ppc.pl b/crypto/aes/asm/aesp8-ppc.pl index ce3fae09..44056e31 100755 --- a/crypto/aes/asm/aesp8-ppc.pl +++ b/crypto/aes/asm/aesp8-ppc.pl @@ -1829,7 +1829,7 @@ Lctr32_enc8x_three: stvx_u $out1,$x10,$out stvx_u $out2,$x20,$out addi $out,$out,0x30 - b Lcbc_dec8x_done + b Lctr32_enc8x_done .align 5 Lctr32_enc8x_two: @@ -1841,7 +1841,7 @@ Lctr32_enc8x_two: stvx_u $out0,$x00,$out stvx_u $out1,$x10,$out addi $out,$out,0x20 - b Lcbc_dec8x_done + b Lctr32_enc8x_done .align 5 Lctr32_enc8x_one: diff --git a/crypto/asn1/n_pkey.c b/crypto/asn1/n_pkey.c index 12592d09..71f78f7b 100644 --- a/crypto/asn1/n_pkey.c +++ b/crypto/asn1/n_pkey.c @@ -22,6 +22,12 @@ NON_EMPTY_TRANSLATION_UNIT # ifndef OPENSSL_NO_RC4 +# define ASN1_BROKEN_SEQUENCE(tname) \ + static const ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_BROKEN, 0, 0, 0, 0}; \ + ASN1_SEQUENCE(tname) +# define static_ASN1_BROKEN_SEQUENCE_END(stname) \ + static_ASN1_SEQUENCE_END_ref(stname, stname) + typedef struct netscape_pkey_st { int32_t version; X509_ALGOR *algor; diff --git a/crypto/bn/asm/mips.pl b/crypto/bn/asm/mips.pl index 51a4b5fb..bff624d1 100644 --- a/crypto/bn/asm/mips.pl +++ b/crypto/bn/asm/mips.pl @@ -88,7 +88,7 @@ if ($flavour =~ /64|n32/i) { $SZREG=4; $REG_S="sw"; $REG_L="lw"; - $code=".set mips2\n"; + $code="#if !(defined (__mips_isa_rev) && (__mips_isa_rev >= 6))\n.set mips2\n#endif\n"; } # Below is N32/64 register layout used in the original module. diff --git a/crypto/bn/asm/ppc.pl b/crypto/bn/asm/ppc.pl index f251e8e5..21f69636 100644 --- a/crypto/bn/asm/ppc.pl +++ b/crypto/bn/asm/ppc.pl @@ -258,6 +258,7 @@ $data=<err_stack) ctx->err_stack--; diff --git a/crypto/bn/bn_lib.c b/crypto/bn/bn_lib.c index 6de17c3b..17293ede 100644 --- a/crypto/bn/bn_lib.c +++ b/crypto/bn/bn_lib.c @@ -338,6 +338,8 @@ void BN_swap(BIGNUM *a, BIGNUM *b) void BN_clear(BIGNUM *a) { + if (a == NULL) + return; bn_check_top(a); if (a->d != NULL) OPENSSL_cleanse(a->d, sizeof(*a->d) * a->dmax); diff --git a/crypto/bn/bn_prime.c b/crypto/bn/bn_prime.c index 7a87b97d..2c9f89d9 100644 --- a/crypto/bn/bn_prime.c +++ b/crypto/bn/bn_prime.c @@ -170,8 +170,7 @@ int BN_generate_prime_ex(BIGNUM *ret, int bits, int safe, found = 1; err: OPENSSL_free(mods); - if (ctx != NULL) - BN_CTX_end(ctx); + BN_CTX_end(ctx); BN_CTX_free(ctx); bn_check_top(ret); return found; diff --git a/crypto/build.info b/crypto/build.info index 39cd91ba..535fa35a 100644 --- a/crypto/build.info +++ b/crypto/build.info @@ -9,7 +9,7 @@ SUBDIRS=objects buffer bio stack lhash rand evp asn1 pem x509 x509v3 conf \ LIBS=../libcrypto # The Core -SOURCE[../libcrypto]=provider_core.c core_fetch.c +SOURCE[../libcrypto]=provider_core.c provider_predefined.c core_fetch.c # Central utilities SOURCE[../libcrypto]=\ diff --git a/crypto/chacha/asm/chacha-ia64.pl b/crypto/chacha/asm/chacha-ia64.pl new file mode 100644 index 00000000..dd090603 --- /dev/null +++ b/crypto/chacha/asm/chacha-ia64.pl @@ -0,0 +1,292 @@ +#!/usr/bin/env perl +# +# ==================================================================== +# Written by Andy Polyakov, @dot-asm, initially for use with OpenSSL. +# ==================================================================== +# +# ChaCha20 for Itanium. +# +# March 2019 +# +# Itanium 9xxx, which has pair of shifters, manages to process one byte +# in 9.3 cycles. This aligns perfectly with theoretical estimate. +# On the other hand, pre-9000 CPU has single shifter and each extr/dep +# pairs below takes additional cycle. Then final input->xor->output +# pass runs slower than expected... Overall result is 15.6 cpb, two +# cycles more than theoretical estimate. + +$output = pop; +open STDOUT, ">$output" if $output; + +my @k = map("r$_",(16..31)); +my @x = map("r$_",(38..53)); +my @y = map("r$_",(8..11)); +my @z = map("r$_",(15,35..37)); +my ($out,$inp,$len,$key,$counter) = map("r$_",(32..36)); + +$code.=<<___; +#if defined(_HPUX_SOURCE) +# if !defined(_LP64) +# define ADDP addp4 +# else +# define ADDP add +# endif +#else +# define ADDP add +#endif + +.text + +.global ChaCha20_ctr32# +.proc ChaCha20_ctr32# +.align 32 +ChaCha20_ctr32: + .prologue + .save ar.pfs,r2 +{ .mmi; alloc r2=ar.pfs,5,17,0,0 + ADDP @k[11]=4,$key + .save ar.lc,r3 + mov r3=ar.lc } +{ .mmi; ADDP $key=0,$key + ADDP $counter=0,$counter + .save pr,r14 + mov r14=pr };; + + .body +{ .mlx; ld4 @k[4]=[$key],8 + movl @k[0]=0x61707865 } +{ .mlx; ld4 @k[5]=[@k[11]],8 + movl @k[1]=0x3320646e };; +{ .mlx; ld4 @k[6]=[$key],8 + movl @k[2]=0x79622d32 } +{ .mlx; ld4 @k[7]=[@k[11]],8 + movl @k[3]=0x6b206574 };; +{ .mmi; ld4 @k[8]=[$key],8 + ld4 @k[9]=[@k[11]],8 + add @k[15]=4,$counter };; +{ .mmi; ld4 @k[10]=[$key] + ld4 @k[11]=[@k[11]] + mov @x[0]=@k[0] };; +{ .mmi; ld4 @k[12]=[$counter],8 + ld4 @k[13]=[@k[15]],8 + mov @x[1]=@k[1] };; +{ .mmi; ld4 @k[14]=[$counter] + ld4 @k[15]=[@k[15]] + mov @x[2]=@k[2] } +{ .mmi; mov @x[3]=@k[3] + mov @x[4]=@k[4] + mov @x[5]=@k[5] };; +{ .mmi; mov @x[6]=@k[6] + mov @x[7]=@k[7] + mov @x[8]=@k[8] } +{ .mmi; mov @x[9]=@k[9] + mov @x[10]=@k[10] + mov @x[11]=@k[11] } +{ .mmi; mov @x[12]=@k[12] + mov @x[13]=@k[13] + mov @x[14]=@k[14] };; + +.Loop_outer: +{ .mii; mov @x[15]=@k[15] + mov ar.lc=9 + mov ar.ec=1 } +{ .mmb; cmp.geu p6,p0=64,$len + sub @z[1]=64,$len + brp.loop.imp .Loop_top,.Loop_end-16 };; + +.Loop_top: +___ +sub ROUND { +my ($a0,$b0,$c0,$d0)=@_; +my ($a1,$b1,$c1,$d1)=map(($_&~3)+(($_+1)&3),($a0,$b0,$c0,$d0)); +my ($a2,$b2,$c2,$d2)=map(($_&~3)+(($_+1)&3),($a1,$b1,$c1,$d1)); +my ($a3,$b3,$c3,$d3)=map(($_&~3)+(($_+1)&3),($a2,$b2,$c2,$d2)); + +$code.=<<___; +{ .mmi; add @x[$a0]=@x[$a0],@x[$b0] + add @x[$a1]=@x[$a1],@x[$b1] + add @x[$a2]=@x[$a2],@x[$b2] };; +{ .mmi; add @x[$a3]=@x[$a3],@x[$b3] + xor @x[$d0]=@x[$d0],@x[$a0] + xor @x[$d1]=@x[$d1],@x[$a1] };; +{ .mmi; xor @x[$d2]=@x[$d2],@x[$a2] + xor @x[$d3]=@x[$d3],@x[$a3] + extr.u @y[0]=@x[$d0],16,16 };; +{ .mii; extr.u @y[1]=@x[$d1],16,16 + dep @x[$d0]=@x[$d0],@y[0],16,16 };; +{ .mii; add @x[$c0]=@x[$c0],@x[$d0] + extr.u @y[2]=@x[$d2],16,16 + dep @x[$d1]=@x[$d1],@y[1],16,16 };; +{ .mii; add @x[$c1]=@x[$c1],@x[$d1] + xor @x[$b0]=@x[$b0],@x[$c0] + extr.u @y[3]=@x[$d3],16,16 };; +{ .mii; xor @x[$b1]=@x[$b1],@x[$c1] + dep @x[$d2]=@x[$d2],@y[2],16,16 + dep @x[$d3]=@x[$d3],@y[3],16,16 };; +{ .mmi; add @x[$c2]=@x[$c2],@x[$d2] + add @x[$c3]=@x[$c3],@x[$d3] + extr.u @y[0]=@x[$b0],20,12 };; +{ .mmi; xor @x[$b2]=@x[$b2],@x[$c2] + xor @x[$b3]=@x[$b3],@x[$c3] + dep.z @x[$b0]=@x[$b0],12,20 };; +{ .mii; or @x[$b0]=@x[$b0],@y[0] + extr.u @y[1]=@x[$b1],20,12 + dep.z @x[$b1]=@x[$b1],12,20 };; +{ .mii; add @x[$a0]=@x[$a0],@x[$b0] + extr.u @y[2]=@x[$b2],20,12 + extr.u @y[3]=@x[$b3],20,12 } +{ .mii; or @x[$b1]=@x[$b1],@y[1] + dep.z @x[$b2]=@x[$b2],12,20 + dep.z @x[$b3]=@x[$b3],12,20 };; +{ .mmi; or @x[$b2]=@x[$b2],@y[2] + or @x[$b3]=@x[$b3],@y[3] + add @x[$a1]=@x[$a1],@x[$b1] };; +{ .mmi; add @x[$a2]=@x[$a2],@x[$b2] + add @x[$a3]=@x[$a3],@x[$b3] + xor @x[$d0]=@x[$d0],@x[$a0] };; +{ .mii; xor @x[$d1]=@x[$d1],@x[$a1] + extr.u @y[0]=@x[$d0],24,8 + dep.z @x[$d0]=@x[$d0],8,24 };; +{ .mii; or @x[$d0]=@x[$d0],@y[0] + extr.u @y[1]=@x[$d1],24,8 + dep.z @x[$d1]=@x[$d1],8,24 };; +{ .mmi; or @x[$d1]=@x[$d1],@y[1] + xor @x[$d2]=@x[$d2],@x[$a2] + xor @x[$d3]=@x[$d3],@x[$a3] };; +{ .mii; add @x[$c0]=@x[$c0],@x[$d0] + extr.u @y[2]=@x[$d2],24,8 + dep.z @x[$d2]=@x[$d2],8,24 };; +{ .mii; xor @x[$b0]=@x[$b0],@x[$c0] + extr.u @y[3]=@x[$d3],24,8 + dep.z @x[$d3]=@x[$d3],8,24 };; +{ .mmi; or @x[$d2]=@x[$d2],@y[2] + or @x[$d3]=@x[$d3],@y[3] + extr.u @y[0]=@x[$b0],25,7 };; +{ .mmi; add @x[$c1]=@x[$c1],@x[$d1] + add @x[$c2]=@x[$c2],@x[$d2] + dep.z @x[$b0]=@x[$b0],7,25 };; +{ .mmi; xor @x[$b1]=@x[$b1],@x[$c1] + xor @x[$b2]=@x[$b2],@x[$c2] + add @x[$c3]=@x[$c3],@x[$d3] };; +{ .mii; xor @x[$b3]=@x[$b3],@x[$c3] + extr.u @y[1]=@x[$b1],25,7 + dep.z @x[$b1]=@x[$b1],7,25 };; +{ .mii; or @x[$b0]=@x[$b0],@y[0] + extr.u @y[2]=@x[$b2],25,7 + dep.z @x[$b2]=@x[$b2],7,25 };; +{ .mii; or @x[$b1]=@x[$b1],@y[1] + extr.u @y[3]=@x[$b3],25,7 + dep.z @x[$b3]=@x[$b3],7,25 };; +___ +$code.=<<___ if ($d0 == 12); +{ .mmi; or @x[$b2]=@x[$b2],@y[2] + or @x[$b3]=@x[$b3],@y[3] + mov @z[0]=-1 };; +___ +$code.=<<___ if ($d0 == 15); +{ .mmb; or @x[$b2]=@x[$b2],@y[2] + or @x[$b3]=@x[$b3],@y[3] + br.ctop.sptk .Loop_top };; +___ +} + &ROUND(0, 4, 8, 12); + &ROUND(0, 5, 10, 15); +$code.=<<___; +.Loop_end: + +{ .mmi; add @x[0]=@x[0],@k[0] + add @x[1]=@x[1],@k[1] +(p6) shr.u @z[0]=@z[0],@z[1] } +{ .mmb; add @x[2]=@x[2],@k[2] + add @x[3]=@x[3],@k[3] + clrrrb.pr };; +{ .mmi; add @x[4]=@x[4],@k[4] + add @x[5]=@x[5],@k[5] + add @x[6]=@x[6],@k[6] } +{ .mmi; add @x[7]=@x[7],@k[7] + add @x[8]=@x[8],@k[8] + add @x[9]=@x[9],@k[9] } +{ .mmi; add @x[10]=@x[10],@k[10] + add @x[11]=@x[11],@k[11] + add @x[12]=@x[12],@k[12] } +{ .mmi; add @x[13]=@x[13],@k[13] + add @x[14]=@x[14],@k[14] + add @x[15]=@x[15],@k[15] } +{ .mmi; add @k[12]=1,@k[12] // next counter + mov pr=@z[0],0x1ffff };; + +////////////////////////////////////////////////////////////////// +// Each predicate bit corresponds to byte to be processed. Note +// that p0 is wired to 1, but it works out, because there always +// is at least one byte to process... +{ .mmi; (p0) ld1 @z[0]=[$inp],1 + shr.u @y[1]=@x[0],8 };; +{ .mmi; (p1) ld1 @z[1]=[$inp],1 + (p2) shr.u @y[2]=@x[0],16 };; +{ .mmi; (p2) ld1 @z[2]=[$inp],1 + (p0) xor @z[0]=@z[0],@x[0] + (p3) shr.u @y[3]=@x[0],24 };; +___ +for(my $i0=0; $i0<60; $i0+=4) { +my ($i1, $i2, $i3, $i4, $i5, $i6, $i7) = map($i0+$_,(1..7)); +my $k = $i0/4+1; + +$code.=<<___; +{ .mmi; (p$i3) ld1 @z[3]=[$inp],1 + (p$i0) st1 [$out]=@z[0],1 + (p$i1) xor @z[1]=@z[1],@y[1] };; +{ .mmi; (p$i4) ld1 @z[0]=[$inp],1 + (p$i5) shr.u @y[1]=@x[$k],8 } +{ .mmi; (p$i1) st1 [$out]=@z[1],1 + (p$i2) xor @z[2]=@z[2],@y[2] + (p1) mov @x[$k-1]=@k[$k-1] };; +{ .mfi; (p$i5) ld1 @z[1]=[$inp],1 + (p$i6) shr.u @y[2]=@x[$k],16 } +{ .mfi; (p$i2) st1 [$out]=@z[2],1 + (p$i3) xor @z[3]=@z[3],@y[3] };; +{ .mfi; (p$i6) ld1 @z[2]=[$inp],1 + (p$i7) shr.u @y[3]=@x[$k],24 } +___ +$code.=<<___ if ($i0==0); # p1,p2 are available for reuse in first round +{ .mmi; (p$i3) st1 [$out]=@z[3],1 + (p$i4) xor @z[0]=@z[0],@x[$k] + cmp.ltu p1,p2=64,$len };; +___ +$code.=<<___ if ($i0>0); +{ .mfi; (p$i3) st1 [$out]=@z[3],1 + (p$i4) xor @z[0]=@z[0],@x[$k] };; +___ +} +$code.=<<___; +{ .mmi; (p63) ld1 @z[3]=[$inp],1 + (p60) st1 [$out]=@z[0],1 + (p61) xor @z[1]=@z[1],@y[1] };; +{ .mmi; (p61) st1 [$out]=@z[1],1 + (p62) xor @z[2]=@z[2],@y[2] };; +{ .mmi; (p62) st1 [$out]=@z[2],1 + (p63) xor @z[3]=@z[3],@y[3] + (p2) mov ar.lc=r3 };; +{ .mib; (p63) st1 [$out]=@z[3],1 + (p1) add $len=-64,$len +(p1) br.dptk.many .Loop_outer };; + +{ .mmi; mov @k[4]=0 // wipe key material + mov @k[5]=0 + mov @k[6]=0 } +{ .mmi; mov @k[7]=0 + mov @k[8]=0 + mov @k[9]=0 } +{ .mmi; mov @k[10]=0 + mov @k[11]=0 + mov @k[12]=0 } +{ .mmi; mov @k[13]=0 + mov @k[14]=0 + mov @k[15]=0 } +{ .mib; mov pr=r14,0x1ffff + br.ret.sptk.many b0 };; +.endp ChaCha20_ctr32# +stringz "ChaCha20 for IA64, CRYPTOGAMS by \@dot-asm" +___ + +print $code; +close STDOUT; diff --git a/crypto/chacha/build.info b/crypto/chacha/build.info index bbd9ca8b..a7418265 100644 --- a/crypto/chacha/build.info +++ b/crypto/chacha/build.info @@ -12,3 +12,4 @@ INCLUDE[chacha-armv8.o]=.. INCLUDE[chacha-s390x.o]=.. GENERATE[chacha-c64xplus.S]=asm/chacha-c64xplus.pl $(PERLASM_SCHEME) GENERATE[chacha-s390x.S]=asm/chacha-s390x.pl $(PERLASM_SCHEME) +GENERATE[chacha-ia64.S]=asm/chacha-ia64.pl $(PERLASM_SCHEME) diff --git a/crypto/conf/conf_def.c b/crypto/conf/conf_def.c index 594f7c5e..277e4d64 100644 --- a/crypto/conf/conf_def.c +++ b/crypto/conf/conf_def.c @@ -669,7 +669,7 @@ static int str_copy(CONF *conf, char *section, char **pto, char *from) static BIO *process_include(char *include, OPENSSL_DIR_CTX **dirctx, char **dirpath) { - struct stat st = { 0 }; + struct stat st; BIO *next; if (stat(include, &st) < 0) { diff --git a/crypto/conf/conf_sap.c b/crypto/conf/conf_sap.c index 38621db3..3994a863 100644 --- a/crypto/conf/conf_sap.c +++ b/crypto/conf/conf_sap.c @@ -35,6 +35,7 @@ void OPENSSL_config(const char *appname) memset(&settings, 0, sizeof(settings)); if (appname != NULL) settings.appname = strdup(appname); + settings.flags = DEFAULT_CONF_MFLAGS; OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CONFIG, &settings); } #endif diff --git a/crypto/core_fetch.c b/crypto/core_fetch.c index d2d77665..d38e1325 100644 --- a/crypto/core_fetch.c +++ b/crypto/core_fetch.c @@ -39,25 +39,33 @@ static int ossl_method_construct_this(OSSL_PROVIDER *provider, void *cbdata) data->mcm_data)) == NULL) continue; + /* + * Note regarding putting the method in stores: + * + * we don't need to care if it actually got in or not here. + * If it didn't get in, it will simply not be available when + * ossl_method_construct() tries to get it from the store. + * + * It is *expected* that the put function increments the refcnt + * of the passed method. + */ + if (data->force_store || !no_store) { /* * If we haven't been told not to store, * add to the global store */ - if (!data->mcm->put(data->libctx, NULL, - thismap->property_definition, - method, data->mcm_data)) { - data->mcm->destruct(method); - continue; - } + data->mcm->put(data->libctx, NULL, + thismap->property_definition, + method, data->mcm_data); } - if (!data->mcm->put(data->libctx, data->store, - thismap->property_definition, - method, data->mcm_data)) { - data->mcm->destruct(method); - continue; - } + data->mcm->put(data->libctx, data->store, + thismap->property_definition, + method, data->mcm_data); + + /* refcnt-- because we're dropping the reference */ + data->mcm->destruct(method, data->mcm_data); } return 1; diff --git a/crypto/cpt_err.c b/crypto/cpt_err.c index bf7985ce..3c3265dc 100644 --- a/crypto/cpt_err.c +++ b/crypto/cpt_err.c @@ -57,6 +57,11 @@ static const ERR_STRING_DATA CRYPTO_str_functs[] = { "pkey_poly1305_init"}, {ERR_PACK(ERR_LIB_CRYPTO, CRYPTO_F_PKEY_SIPHASH_INIT, 0), "pkey_siphash_init"}, + {ERR_PACK(ERR_LIB_CRYPTO, CRYPTO_F_PROVIDER_ACTIVATE, 0), + "provider_activate"}, + {ERR_PACK(ERR_LIB_CRYPTO, CRYPTO_F_PROVIDER_NEW, 0), "provider_new"}, + {ERR_PACK(ERR_LIB_CRYPTO, CRYPTO_F_PROVIDER_STORE_NEW, 0), + "provider_store_new"}, {ERR_PACK(ERR_LIB_CRYPTO, CRYPTO_F_SK_RESERVE, 0), "sk_reserve"}, {0, NULL} }; diff --git a/crypto/crmf/crmf_asn.c b/crypto/crmf/crmf_asn.c index d0ab6e95..8810cb43 100644 --- a/crypto/crmf/crmf_asn.c +++ b/crypto/crmf/crmf_asn.c @@ -3,7 +3,7 @@ * Copyright Nokia 2007-2018 * Copyright Siemens AG 2015-2018 * - * Licensed under the OpenSSL license (the "License"). You may not use + * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html diff --git a/crypto/crmf/crmf_err.c b/crypto/crmf/crmf_err.c index f3405b11..62dc6bfc 100644 --- a/crypto/crmf/crmf_err.c +++ b/crypto/crmf/crmf_err.c @@ -2,7 +2,7 @@ * Generated by util/mkerr.pl DO NOT EDIT * Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved. * - * Licensed under the OpenSSL license (the "License"). You may not use + * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html diff --git a/crypto/crmf/crmf_int.h b/crypto/crmf/crmf_int.h index db1547b0..f908eac8 100644 --- a/crypto/crmf/crmf_int.h +++ b/crypto/crmf/crmf_int.h @@ -3,7 +3,7 @@ * Copyright Nokia 2007-2018 * Copyright Siemens AG 2015-2018 * - * Licensed under the OpenSSL license (the "License"). You may not use + * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html diff --git a/crypto/crmf/crmf_lib.c b/crypto/crmf/crmf_lib.c index 49deca75..6a259f96 100644 --- a/crypto/crmf/crmf_lib.c +++ b/crypto/crmf/crmf_lib.c @@ -3,7 +3,7 @@ * Copyright Nokia 2007-2018 * Copyright Siemens AG 2015-2018 * - * Licensed under the OpenSSL license (the "License"). You may not use + * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html diff --git a/crypto/crmf/crmf_pbm.c b/crypto/crmf/crmf_pbm.c index 60d06d4a..09e4ffad 100644 --- a/crypto/crmf/crmf_pbm.c +++ b/crypto/crmf/crmf_pbm.c @@ -3,7 +3,7 @@ * Copyright Nokia 2007-2018 * Copyright Siemens AG 2015-2018 * - * Licensed under the OpenSSL license (the "License"). You may not use + * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html diff --git a/crypto/dh/dh_check.c b/crypto/dh/dh_check.c index 31332cd1..8be2b91a 100644 --- a/crypto/dh/dh_check.c +++ b/crypto/dh/dh_check.c @@ -12,6 +12,8 @@ #include #include "dh_locl.h" +# define DH_NUMBER_ITERATIONS_FOR_PRIME 64 + /*- * Check that p and g are suitable enough * @@ -58,10 +60,8 @@ int DH_check_params(const DH *dh, int *ret) ok = 1; err: - if (ctx != NULL) { - BN_CTX_end(ctx); - BN_CTX_free(ctx); - } + BN_CTX_end(ctx); + BN_CTX_free(ctx); return ok; } @@ -127,7 +127,7 @@ int DH_check(const DH *dh, int *ret) if (!BN_is_one(t1)) *ret |= DH_NOT_SUITABLE_GENERATOR; } - r = BN_is_prime_ex(dh->q, BN_prime_checks, ctx, NULL); + r = BN_is_prime_ex(dh->q, DH_NUMBER_ITERATIONS_FOR_PRIME, ctx, NULL); if (r < 0) goto err; if (!r) @@ -155,7 +155,7 @@ int DH_check(const DH *dh, int *ret) } else *ret |= DH_UNABLE_TO_CHECK_GENERATOR; - r = BN_is_prime_ex(dh->p, BN_prime_checks, ctx, NULL); + r = BN_is_prime_ex(dh->p, DH_NUMBER_ITERATIONS_FOR_PRIME, ctx, NULL); if (r < 0) goto err; if (!r) @@ -163,7 +163,7 @@ int DH_check(const DH *dh, int *ret) else if (!dh->q) { if (!BN_rshift1(t1, dh->p)) goto err; - r = BN_is_prime_ex(t1, BN_prime_checks, ctx, NULL); + r = BN_is_prime_ex(t1, DH_NUMBER_ITERATIONS_FOR_PRIME, ctx, NULL); if (r < 0) goto err; if (!r) @@ -171,10 +171,8 @@ int DH_check(const DH *dh, int *ret) } ok = 1; err: - if (ctx != NULL) { - BN_CTX_end(ctx); - BN_CTX_free(ctx); - } + BN_CTX_end(ctx); + BN_CTX_free(ctx); return ok; } @@ -225,9 +223,7 @@ int DH_check_pub_key(const DH *dh, const BIGNUM *pub_key, int *ret) ok = 1; err: - if (ctx != NULL) { - BN_CTX_end(ctx); - BN_CTX_free(ctx); - } + BN_CTX_end(ctx); + BN_CTX_free(ctx); return ok; } diff --git a/crypto/dh/dh_gen.c b/crypto/dh/dh_gen.c index 4e4aeb39..1e5c7ca2 100644 --- a/crypto/dh/dh_gen.c +++ b/crypto/dh/dh_gen.c @@ -122,9 +122,7 @@ static int dh_builtin_genparams(DH *ret, int prime_len, int generator, ok = 0; } - if (ctx != NULL) { - BN_CTX_end(ctx); - BN_CTX_free(ctx); - } + BN_CTX_end(ctx); + BN_CTX_free(ctx); return ok; } diff --git a/crypto/dh/dh_key.c b/crypto/dh/dh_key.c index 58210fbb..4b0b1f32 100644 --- a/crypto/dh/dh_key.c +++ b/crypto/dh/dh_key.c @@ -205,10 +205,8 @@ static int compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh) ret = BN_bn2bin(tmp, key); err: - if (ctx != NULL) { - BN_CTX_end(ctx); - BN_CTX_free(ctx); - } + BN_CTX_end(ctx); + BN_CTX_free(ctx); return ret; } diff --git a/crypto/dsa/dsa_ameth.c b/crypto/dsa/dsa_ameth.c index f28021d7..756ee744 100644 --- a/crypto/dsa/dsa_ameth.c +++ b/crypto/dsa/dsa_ameth.c @@ -458,6 +458,8 @@ static int dsa_sig_print(BIO *bp, const X509_ALGOR *sigalg, DSA_SIG_free(dsa_sig); return rv; } + if (BIO_puts(bp, "\n") <= 0) + return 0; return X509_signature_dump(bp, sig, indent); } diff --git a/crypto/dsa/dsa_gen.c b/crypto/dsa/dsa_gen.c index 2c42049a..858f1273 100644 --- a/crypto/dsa/dsa_gen.c +++ b/crypto/dsa/dsa_gen.c @@ -292,8 +292,7 @@ int dsa_builtin_paramgen(DSA *ret, size_t bits, size_t qbits, if (seed_out) memcpy(seed_out, seed, qsize); } - if (ctx) - BN_CTX_end(ctx); + BN_CTX_end(ctx); BN_CTX_free(ctx); BN_MONT_CTX_free(mont); return ok; @@ -607,8 +606,7 @@ int dsa_builtin_paramgen2(DSA *ret, size_t L, size_t N, OPENSSL_free(seed); if (seed_out != seed_tmp) OPENSSL_free(seed_tmp); - if (ctx) - BN_CTX_end(ctx); + BN_CTX_end(ctx); BN_CTX_free(ctx); BN_MONT_CTX_free(mont); EVP_MD_CTX_free(mctx); diff --git a/crypto/dso/dso_win32.c b/crypto/dso/dso_win32.c index a86f3fc0..9c779921 100644 --- a/crypto/dso/dso_win32.c +++ b/crypto/dso/dso_win32.c @@ -64,6 +64,7 @@ static DSO_FUNC_TYPE win32_bind_func(DSO *dso, const char *symname); static char *win32_name_converter(DSO *dso, const char *filename); static char *win32_merger(DSO *dso, const char *filespec1, const char *filespec2); +static int win32_pathbyaddr(void *addr, char *path, int sz); static void *win32_globallookup(const char *name); static const char *openssl_strnchr(const char *string, int c, size_t len); @@ -78,7 +79,7 @@ static DSO_METHOD dso_meth_win32 = { win32_merger, NULL, /* init */ NULL, /* finish */ - NULL, /* pathbyaddr */ + win32_pathbyaddr, /* pathbyaddr */ win32_globallookup }; @@ -500,6 +501,111 @@ typedef HANDLE(WINAPI *CREATETOOLHELP32SNAPSHOT) (DWORD, DWORD); typedef BOOL(WINAPI *CLOSETOOLHELP32SNAPSHOT) (HANDLE); typedef BOOL(WINAPI *MODULE32) (HANDLE, MODULEENTRY32 *); +static int win32_pathbyaddr(void *addr, char *path, int sz) +{ + HMODULE dll; + HANDLE hModuleSnap = INVALID_HANDLE_VALUE; + MODULEENTRY32 me32; + CREATETOOLHELP32SNAPSHOT create_snap; + CLOSETOOLHELP32SNAPSHOT close_snap; + MODULE32 module_first, module_next; + + if (addr == NULL) { + union { + int (*f) (void *, char *, int); + void *p; + } t = { + win32_pathbyaddr + }; + addr = t.p; + } + + dll = LoadLibrary(TEXT(DLLNAME)); + if (dll == NULL) { + DSOerr(DSO_F_WIN32_PATHBYADDR, DSO_R_UNSUPPORTED); + return -1; + } + + create_snap = (CREATETOOLHELP32SNAPSHOT) + GetProcAddress(dll, "CreateToolhelp32Snapshot"); + if (create_snap == NULL) { + FreeLibrary(dll); + DSOerr(DSO_F_WIN32_PATHBYADDR, DSO_R_UNSUPPORTED); + return -1; + } + /* We take the rest for granted... */ +# ifdef _WIN32_WCE + close_snap = (CLOSETOOLHELP32SNAPSHOT) + GetProcAddress(dll, "CloseToolhelp32Snapshot"); +# else + close_snap = (CLOSETOOLHELP32SNAPSHOT) CloseHandle; +# endif + module_first = (MODULE32) GetProcAddress(dll, "Module32First"); + module_next = (MODULE32) GetProcAddress(dll, "Module32Next"); + + /* + * Take a snapshot of current process which includes + * list of all involved modules. + */ + hModuleSnap = (*create_snap) (TH32CS_SNAPMODULE, 0); + if (hModuleSnap == INVALID_HANDLE_VALUE) { + FreeLibrary(dll); + DSOerr(DSO_F_WIN32_PATHBYADDR, DSO_R_UNSUPPORTED); + return -1; + } + + me32.dwSize = sizeof(me32); + + if (!(*module_first) (hModuleSnap, &me32)) { + (*close_snap) (hModuleSnap); + FreeLibrary(dll); + DSOerr(DSO_F_WIN32_PATHBYADDR, DSO_R_FAILURE); + return -1; + } + + /* Enumerate the modules to find one which includes me. */ + do { + if ((uintptr_t) addr >= (uintptr_t) me32.modBaseAddr && + (uintptr_t) addr < (uintptr_t) (me32.modBaseAddr + me32.modBaseSize)) { + (*close_snap) (hModuleSnap); + FreeLibrary(dll); +# ifdef _WIN32_WCE +# if _WIN32_WCE >= 101 + return WideCharToMultiByte(CP_ACP, 0, me32.szExePath, -1, + path, sz, NULL, NULL); +# else + { + int i, len = (int)wcslen(me32.szExePath); + if (sz <= 0) + return len + 1; + if (len >= sz) + len = sz - 1; + for (i = 0; i < len; i++) + path[i] = (char)me32.szExePath[i]; + path[len++] = '\0'; + return len; + } +# endif +# else + { + int len = (int)strlen(me32.szExePath); + if (sz <= 0) + return len + 1; + if (len >= sz) + len = sz - 1; + memcpy(path, me32.szExePath, len); + path[len++] = '\0'; + return len; + } +# endif + } + } while ((*module_next) (hModuleSnap, &me32)); + + (*close_snap) (hModuleSnap); + FreeLibrary(dll); + return 0; +} + static void *win32_globallookup(const char *name) { HMODULE dll; diff --git a/crypto/ec/ec2_oct.c b/crypto/ec/ec2_oct.c index 59258392..ca36bb16 100644 --- a/crypto/ec/ec2_oct.c +++ b/crypto/ec/ec2_oct.c @@ -237,7 +237,7 @@ int ec_GF2m_simple_oct2point(const EC_GROUP *group, EC_POINT *point, BN_CTX *ctx) { point_conversion_form_t form; - int y_bit; + int y_bit, m; BN_CTX *new_ctx = NULL; BIGNUM *x, *y, *yxi; size_t field_len, enc_len; @@ -270,7 +270,8 @@ int ec_GF2m_simple_oct2point(const EC_GROUP *group, EC_POINT *point, return EC_POINT_set_to_infinity(group, point); } - field_len = (EC_GROUP_get_degree(group) + 7) / 8; + m = EC_GROUP_get_degree(group); + field_len = (m + 7) / 8; enc_len = (form == POINT_CONVERSION_COMPRESSED) ? 1 + field_len : 1 + 2 * field_len; @@ -295,7 +296,7 @@ int ec_GF2m_simple_oct2point(const EC_GROUP *group, EC_POINT *point, if (!BN_bin2bn(buf + 1, field_len, x)) goto err; - if (BN_ucmp(x, group->field) >= 0) { + if (BN_num_bits(x) > m) { ECerr(EC_F_EC_GF2M_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING); goto err; } @@ -306,7 +307,7 @@ int ec_GF2m_simple_oct2point(const EC_GROUP *group, EC_POINT *point, } else { if (!BN_bin2bn(buf + 1 + field_len, field_len, y)) goto err; - if (BN_ucmp(y, group->field) >= 0) { + if (BN_num_bits(y) > m) { ECerr(EC_F_EC_GF2M_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING); goto err; } diff --git a/crypto/ec/ec2_smpl.c b/crypto/ec/ec2_smpl.c index 7bd2a632..ebd6f21e 100644 --- a/crypto/ec/ec2_smpl.c +++ b/crypto/ec/ec2_smpl.c @@ -204,8 +204,7 @@ int ec_GF2m_simple_group_check_discriminant(const EC_GROUP *group, ret = 1; err: - if (ctx != NULL) - BN_CTX_end(ctx); + BN_CTX_end(ctx); BN_CTX_free(new_ctx); return ret; } diff --git a/crypto/ec/ec_lib.c b/crypto/ec/ec_lib.c index 2623b537..798382ac 100644 --- a/crypto/ec/ec_lib.c +++ b/crypto/ec/ec_lib.c @@ -1079,8 +1079,7 @@ static int ec_field_inverse_mod_ord(const EC_GROUP *group, BIGNUM *r, ret = 1; err: - if (ctx != NULL) - BN_CTX_end(ctx); + BN_CTX_end(ctx); BN_CTX_free(new_ctx); return ret; } diff --git a/crypto/ec/ec_mult.c b/crypto/ec/ec_mult.c index 9b0aac23..755d6440 100644 --- a/crypto/ec/ec_mult.c +++ b/crypto/ec/ec_mult.c @@ -378,7 +378,7 @@ int ec_scalar_mul_ladder(const EC_GROUP *group, EC_POINT *r, err: EC_POINT_free(p); - EC_POINT_free(s); + EC_POINT_clear_free(s); BN_CTX_end(ctx); return ret; @@ -948,8 +948,7 @@ int ec_wNAF_precompute_mult(EC_GROUP *group, BN_CTX *ctx) ret = 1; err: - if (ctx != NULL) - BN_CTX_end(ctx); + BN_CTX_end(ctx); BN_CTX_free(new_ctx); EC_ec_pre_comp_free(pre_comp); if (points) { diff --git a/crypto/ec/ecdh_ossl.c b/crypto/ec/ecdh_ossl.c index 40a564fb..61789f4f 100644 --- a/crypto/ec/ecdh_ossl.c +++ b/crypto/ec/ecdh_ossl.c @@ -112,9 +112,8 @@ int ecdh_simple_compute_key(unsigned char **pout, size_t *poutlen, ret = 1; err: - EC_POINT_free(tmp); - if (ctx) - BN_CTX_end(ctx); + EC_POINT_clear_free(tmp); + BN_CTX_end(ctx); BN_CTX_free(ctx); OPENSSL_free(buf); return ret; diff --git a/crypto/ec/ecp_nistp224.c b/crypto/ec/ecp_nistp224.c index 65396595..e6f095e7 100644 --- a/crypto/ec/ecp_nistp224.c +++ b/crypto/ec/ecp_nistp224.c @@ -676,7 +676,9 @@ static void felem_contract(felem out, const felem in) */ static void felem_neg(felem out, const felem in) { - widefelem tmp = {0}; + widefelem tmp; + + memset(tmp, 0, sizeof(tmp)); felem_diff_128_64(tmp, in); felem_reduce(out, tmp); } diff --git a/crypto/ec/ecp_nistz256.c b/crypto/ec/ecp_nistz256.c index c0772ca2..6a64bc4f 100644 --- a/crypto/ec/ecp_nistz256.c +++ b/crypto/ec/ecp_nistz256.c @@ -888,8 +888,7 @@ __owur static int ecp_nistz256_mult_precompute(EC_GROUP *group, BN_CTX *ctx) ret = 1; err: - if (ctx != NULL) - BN_CTX_end(ctx); + BN_CTX_end(ctx); BN_CTX_free(new_ctx); EC_nistz256_pre_comp_free(pre_comp); diff --git a/crypto/ec/ecp_smpl.c b/crypto/ec/ecp_smpl.c index f80f98a1..2fd2ce46 100644 --- a/crypto/ec/ecp_smpl.c +++ b/crypto/ec/ecp_smpl.c @@ -307,8 +307,7 @@ int ec_GFp_simple_group_check_discriminant(const EC_GROUP *group, BN_CTX *ctx) ret = 1; err: - if (ctx != NULL) - BN_CTX_end(ctx); + BN_CTX_end(ctx); BN_CTX_free(new_ctx); return ret; } @@ -787,8 +786,7 @@ int ec_GFp_simple_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, ret = 1; end: - if (ctx) /* otherwise we already called BN_CTX_end */ - BN_CTX_end(ctx); + BN_CTX_end(ctx); BN_CTX_free(new_ctx); return ret; } diff --git a/crypto/err/err.c b/crypto/err/err.c index 63dcfc35..45488545 100644 --- a/crypto/err/err.c +++ b/crypto/err/err.c @@ -525,8 +525,24 @@ static unsigned long get_error_values(int inc, int top, const char **file, return ERR_R_INTERNAL_ERROR; } + while (es->bottom != es->top) { + if (es->err_flags[es->top] & ERR_FLAG_CLEAR) { + err_clear(es, es->top); + es->top = es->top > 0 ? es->top - 1 : ERR_NUM_ERRORS - 1; + continue; + } + i = (es->bottom + 1) % ERR_NUM_ERRORS; + if (es->err_flags[i] & ERR_FLAG_CLEAR) { + es->bottom = i; + err_clear(es, es->bottom); + continue; + } + break; + } + if (es->bottom == es->top) return 0; + if (top) i = es->top; /* last error */ else @@ -915,25 +931,6 @@ int ERR_clear_last_mark(void) return 1; } -#ifdef UINTPTR_T -# undef UINTPTR_T -#endif -/* - * uintptr_t is the answer, but unfortunately C89, current "least common - * denominator" doesn't define it. Most legacy platforms typedef it anyway, - * so that attempt to fill the gaps means that one would have to identify - * that track these gaps, which would be undesirable. Macro it is... - */ -#if defined(__VMS) && __INITIAL_POINTER_SIZE==64 -/* - * But we can't use size_t on VMS, because it adheres to sizeof(size_t)==4 - * even in 64-bit builds, which means that it won't work as mask. - */ -# define UINTPTR_T unsigned long long -#else -# define UINTPTR_T size_t -#endif - void err_clear_last_constant_time(int clear) { ERR_STATE *es; @@ -945,11 +942,11 @@ void err_clear_last_constant_time(int clear) top = es->top; - es->err_flags[top] &= ~(0 - clear); - es->err_buffer[top] &= ~(0UL - clear); - es->err_file[top] = (const char *)((UINTPTR_T)es->err_file[top] & - ~((UINTPTR_T)0 - clear)); - es->err_line[top] |= 0 - clear; - - es->top = (top + ERR_NUM_ERRORS - clear) % ERR_NUM_ERRORS; + /* + * Flag error as cleared but remove it elsewhere to avoid two errors + * accessing the same error stack location, revealing timing information. + */ + clear = constant_time_select_int(constant_time_eq_int(clear, 0), + 0, ERR_FLAG_CLEAR); + es->err_flags[top] |= clear; } diff --git a/crypto/err/openssl.txt b/crypto/err/openssl.txt index d8c8d714..df8690a1 100644 --- a/crypto/err/openssl.txt +++ b/crypto/err/openssl.txt @@ -396,6 +396,9 @@ CRYPTO_F_OSSL_PROVIDER_NEW:131:ossl_provider_new CRYPTO_F_PKEY_HMAC_INIT:123:pkey_hmac_init CRYPTO_F_PKEY_POLY1305_INIT:124:pkey_poly1305_init CRYPTO_F_PKEY_SIPHASH_INIT:125:pkey_siphash_init +CRYPTO_F_PROVIDER_ACTIVATE:134:provider_activate +CRYPTO_F_PROVIDER_NEW:135:provider_new +CRYPTO_F_PROVIDER_STORE_NEW:136:provider_store_new CRYPTO_F_SK_RESERVE:129:sk_reserve CT_F_CTLOG_NEW:117:CTLOG_new CT_F_CTLOG_NEW_FROM_BASE64:118:CTLOG_new_from_base64 @@ -778,7 +781,9 @@ EVP_F_EVP_CIPHER_PARAM_TO_ASN1:205:EVP_CIPHER_param_to_asn1 EVP_F_EVP_DECRYPTFINAL_EX:101:EVP_DecryptFinal_ex EVP_F_EVP_DECRYPTUPDATE:166:EVP_DecryptUpdate EVP_F_EVP_DIGESTFINALXOF:174:EVP_DigestFinalXOF +EVP_F_EVP_DIGESTFINAL_EX:230:EVP_DigestFinal_ex EVP_F_EVP_DIGESTINIT_EX:128:EVP_DigestInit_ex +EVP_F_EVP_DIGESTUPDATE:231:EVP_DigestUpdate EVP_F_EVP_ENCRYPTDECRYPTUPDATE:219:evp_EncryptDecryptUpdate EVP_F_EVP_ENCRYPTFINAL_EX:127:EVP_EncryptFinal_ex EVP_F_EVP_ENCRYPTUPDATE:167:EVP_EncryptUpdate @@ -898,6 +903,11 @@ KDF_F_PKEY_TLS1_PRF_CTRL_STR:100:pkey_tls1_prf_ctrl_str KDF_F_PKEY_TLS1_PRF_DERIVE:101:pkey_tls1_prf_derive KDF_F_PKEY_TLS1_PRF_INIT:110:pkey_tls1_prf_init KDF_F_SCRYPT_SET_MEMBUF:129:scrypt_set_membuf +KDF_F_SSKDF_CTRL_STR:134:sskdf_ctrl_str +KDF_F_SSKDF_DERIVE:135:sskdf_derive +KDF_F_SSKDF_MAC2CTRL:136:sskdf_mac2ctrl +KDF_F_SSKDF_NEW:137:sskdf_new +KDF_F_SSKDF_SIZE:138:sskdf_size KDF_F_TLS1_PRF_ALG:111:tls1_prf_alg OBJ_F_OBJ_ADD_OBJECT:105:OBJ_add_object OBJ_F_OBJ_ADD_SIGID:107:OBJ_add_sigid @@ -1215,7 +1225,6 @@ SSL_F_DO_DTLS1_WRITE:245:do_dtls1_write SSL_F_DO_SSL3_WRITE:104:do_ssl3_write SSL_F_DTLS1_BUFFER_RECORD:247:dtls1_buffer_record SSL_F_DTLS1_CHECK_TIMEOUT_NUM:318:dtls1_check_timeout_num -SSL_F_DTLS1_HEARTBEAT:305:* SSL_F_DTLS1_HM_FRAGMENT_NEW:623:dtls1_hm_fragment_new SSL_F_DTLS1_PREPROCESS_FRAGMENT:288:dtls1_preprocess_fragment SSL_F_DTLS1_PROCESS_BUFFERED_RECORDS:424:dtls1_process_buffered_records @@ -2348,6 +2357,7 @@ EVP_R_EXPECTING_A_DSA_KEY:129:expecting a dsa key EVP_R_EXPECTING_A_EC_KEY:142:expecting a ec key EVP_R_EXPECTING_A_POLY1305_KEY:164:expecting a poly1305 key EVP_R_EXPECTING_A_SIPHASH_KEY:175:expecting a siphash key +EVP_R_FINAL_ERROR:188:final error EVP_R_FIPS_MODE_NOT_SUPPORTED:167:fips mode not supported EVP_R_GET_RAW_KEY_FAILED:182:get raw key failed EVP_R_ILLEGAL_SCRYPT_PARAMETERS:171:illegal scrypt parameters @@ -2366,6 +2376,7 @@ EVP_R_MEMORY_LIMIT_EXCEEDED:172:memory limit exceeded EVP_R_MESSAGE_DIGEST_IS_NULL:159:message digest is null EVP_R_METHOD_NOT_SUPPORTED:144:method not supported EVP_R_MISSING_PARAMETERS:103:missing parameters +EVP_R_NOT_ABLE_TO_COPY_CTX:190:not able to copy ctx EVP_R_NOT_XOF_OR_INVALID_LENGTH:178:not XOF or invalid length EVP_R_NO_CIPHER_SET:131:no cipher set EVP_R_NO_DEFAULT_DIGEST:158:no default digest @@ -2399,9 +2410,11 @@ EVP_R_UNSUPPORTED_NUMBER_OF_ROUNDS:135:unsupported number of rounds EVP_R_UNSUPPORTED_PRF:125:unsupported prf EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM:118:unsupported private key algorithm EVP_R_UNSUPPORTED_SALT_TYPE:126:unsupported salt type +EVP_R_UPDATE_ERROR:189:update error EVP_R_WRAP_MODE_NOT_ALLOWED:170:wrap mode not allowed EVP_R_WRONG_FINAL_BLOCK_LENGTH:109:wrong final block length KDF_R_INVALID_DIGEST:100:invalid digest +KDF_R_INVALID_MAC_TYPE:116:invalid mac type KDF_R_MISSING_ITERATION_COUNT:109:missing iteration count KDF_R_MISSING_KEY:104:missing key KDF_R_MISSING_MESSAGE_DIGEST:105:missing message digest @@ -2414,6 +2427,7 @@ KDF_R_MISSING_SESSION_ID:113:missing session id KDF_R_MISSING_TYPE:114:missing type KDF_R_MISSING_XCGHASH:115:missing xcghash KDF_R_UNKNOWN_PARAMETER_TYPE:103:unknown parameter type +KDF_R_UNSUPPORTED_MAC_TYPE:117:unsupported mac type KDF_R_VALUE_ERROR:108:value error KDF_R_VALUE_MISSING:102:value missing KDF_R_WRONG_OUTPUT_BUFFER_SIZE:112:wrong output buffer size @@ -2961,8 +2975,6 @@ SSL_R_SSL_SESSION_ID_HAS_BAD_LENGTH:303:ssl session id has bad length SSL_R_SSL_SESSION_ID_TOO_LONG:408:ssl session id too long SSL_R_SSL_SESSION_VERSION_MISMATCH:210:ssl session version mismatch SSL_R_STILL_IN_INIT:121:still in init -SSL_R_TLS_HEARTBEAT_PEER_DOESNT_ACCEPT:365:peer does not accept heartbeats -SSL_R_TLS_HEARTBEAT_PENDING:366:heartbeat request already pending SSL_R_TLS_ILLEGAL_EXPORTER_LABEL:367:tls illegal exporter label SSL_R_TLS_INVALID_ECPOINTFORMAT_LIST:157:tls invalid ecpointformat list SSL_R_TOO_MANY_KEY_UPDATES:132:too many key updates diff --git a/crypto/evp/build.info b/crypto/evp/build.info index 862afa83..10ba3a3c 100644 --- a/crypto/evp/build.info +++ b/crypto/evp/build.info @@ -16,6 +16,10 @@ SOURCE[../../libcrypto]=\ e_chacha20_poly1305.c cmeth_lib.c \ mac_lib.c c_allm.c pkey_mac.c +# New design +SOURCE[../../libcrypto]=\ + evp_fetch.c + INCLUDE[e_aes.o]=.. ../modes INCLUDE[e_aes_cbc_hmac_sha1.o]=../modes INCLUDE[e_aes_cbc_hmac_sha256.o]=../modes diff --git a/crypto/evp/digest.c b/crypto/evp/digest.c index 86be9aec..7b497255 100644 --- a/crypto/evp/digest.c +++ b/crypto/evp/digest.c @@ -13,6 +13,7 @@ #include #include #include "internal/evp_int.h" +#include "internal/provider.h" #include "evp_locl.h" /* This call frees resources associated with the context */ @@ -21,6 +22,24 @@ int EVP_MD_CTX_reset(EVP_MD_CTX *ctx) if (ctx == NULL) return 1; + if (ctx->digest == NULL || ctx->digest->prov == NULL) + goto legacy; + + if (ctx->provctx != NULL) { + if (ctx->digest->freectx != NULL) + ctx->digest->freectx(ctx->provctx); + ctx->provctx = NULL; + EVP_MD_CTX_set_flags(ctx, EVP_MD_CTX_FLAG_CLEANED); + } + + if (ctx->pctx != NULL) + goto legacy; + + return 1; + + /* TODO(3.0): Remove legacy code below */ + legacy: + /* * Don't assume ctx->md_data was cleaned in EVP_Digest_Final, because * sometimes only copies of the context are ever finalised. @@ -53,6 +72,23 @@ EVP_MD_CTX *EVP_MD_CTX_new(void) void EVP_MD_CTX_free(EVP_MD_CTX *ctx) { + if (ctx == NULL) + return; + + if (ctx->digest == NULL || ctx->digest->prov == NULL) + goto legacy; + + EVP_MD_CTX_reset(ctx); + + EVP_MD_meth_free(ctx->fetched_digest); + ctx->fetched_digest = NULL; + ctx->digest = NULL; + + OPENSSL_free(ctx); + return; + + /* TODO(3.0): Remove legacy code below */ + legacy: EVP_MD_CTX_reset(ctx); OPENSSL_free(ctx); } @@ -65,7 +101,12 @@ int EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type) int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl) { + EVP_MD *provmd; + ENGINE *tmpimpl = NULL; + EVP_MD_CTX_clear_flags(ctx, EVP_MD_CTX_FLAG_CLEANED); + + /* TODO(3.0): Legacy work around code below. Remove this */ #ifndef OPENSSL_NO_ENGINE /* * Whether it's nice or not, "Inits" can be used on "Final"'d contexts so @@ -76,6 +117,74 @@ int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl) if (ctx->engine && ctx->digest && (type == NULL || (type->type == ctx->digest->type))) goto skip_to_init; + + if (type != NULL && impl == NULL) + tmpimpl = ENGINE_get_digest_engine(type->type); +#endif + + /* + * If there are engines involved or if we're being used as part of + * EVP_DigestSignInit then we should use legacy handling for now. + */ + if (ctx->engine != NULL + || impl != NULL + || tmpimpl != NULL + || ctx->pctx != NULL + || (ctx->flags & EVP_MD_CTX_FLAG_NO_INIT) != 0) { + if (ctx->digest == ctx->fetched_digest) + ctx->digest = NULL; + EVP_MD_meth_free(ctx->fetched_digest); + ctx->fetched_digest = NULL; + goto legacy; + } + + if (type->prov == NULL) { + switch(type->type) { + case NID_sha256: + break; + default: + goto legacy; + } + } + + if (ctx->digest != NULL && ctx->digest->ctx_size > 0) { + OPENSSL_clear_free(ctx->md_data, ctx->digest->ctx_size); + ctx->md_data = NULL; + } + + /* TODO(3.0): Start of non-legacy code below */ + + if (type->prov == NULL) { + provmd = EVP_MD_fetch(NULL, OBJ_nid2sn(type->type), ""); + if (provmd == NULL) { + EVPerr(EVP_F_EVP_DIGESTINIT_EX, EVP_R_INITIALIZATION_ERROR); + return 0; + } + type = provmd; + EVP_MD_meth_free(ctx->fetched_digest); + ctx->fetched_digest = provmd; + } + + ctx->digest = type; + if (ctx->provctx == NULL) { + ctx->provctx = ctx->digest->newctx(); + if (ctx->provctx == NULL) { + EVPerr(EVP_F_EVP_DIGESTINIT_EX, EVP_R_INITIALIZATION_ERROR); + return 0; + } + } + + if (ctx->digest->dinit == NULL) { + EVPerr(EVP_F_EVP_DIGESTINIT_EX, EVP_R_INITIALIZATION_ERROR); + return 0; + } + + return ctx->digest->dinit(ctx->provctx); + + /* TODO(3.0): Remove legacy code below */ + legacy: + +#ifndef OPENSSL_NO_ENGINE if (type) { /* * Ensure an ENGINE left lying around from last time is cleared (the @@ -90,7 +199,7 @@ int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl) } } else { /* Ask if an ENGINE is reserved for this job */ - impl = ENGINE_get_digest_engine(type->type); + impl = tmpimpl; } if (impl != NULL) { /* There's an ENGINE for this job ... (apparently) */ @@ -150,6 +259,20 @@ int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl) int EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *data, size_t count) { + if (count == 0) + return 1; + + if (ctx->digest == NULL || ctx->digest->prov == NULL) + goto legacy; + + if (ctx->digest->dupdate == NULL) { + EVPerr(EVP_F_EVP_DIGESTUPDATE, EVP_R_UPDATE_ERROR); + return 0; + } + return ctx->digest->dupdate(ctx->provctx, data, count); + + /* TODO(3.0): Remove legacy code below */ + legacy: return ctx->update(ctx, data, count); } @@ -163,14 +286,40 @@ int EVP_DigestFinal(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *size) } /* The caller can assume that this removes any secret data from the context */ -int EVP_DigestFinal_ex(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *size) +int EVP_DigestFinal_ex(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *isize) { int ret; + size_t size = 0; + if (ctx->digest == NULL || ctx->digest->prov == NULL) + goto legacy; + + if (ctx->digest->dfinal == NULL) { + EVPerr(EVP_F_EVP_DIGESTFINAL_EX, EVP_R_FINAL_ERROR); + return 0; + } + + ret = ctx->digest->dfinal(ctx->provctx, md, &size); + + if (isize != NULL) { + if (size <= UINT_MAX) { + *isize = (int)size; + } else { + EVPerr(EVP_F_EVP_DIGESTFINAL_EX, EVP_R_FINAL_ERROR); + ret = 0; + } + } + + EVP_MD_CTX_reset(ctx); + + return ret; + + /* TODO(3.0): Remove legacy code below */ + legacy: OPENSSL_assert(ctx->digest->md_size <= EVP_MAX_MD_SIZE); ret = ctx->digest->final(ctx, md); - if (size != NULL) - *size = ctx->digest->md_size; + if (isize != NULL) + *isize = ctx->digest->md_size; if (ctx->digest->cleanup) { ctx->digest->cleanup(ctx); EVP_MD_CTX_set_flags(ctx, EVP_MD_CTX_FLAG_CLEANED); @@ -209,10 +358,52 @@ int EVP_MD_CTX_copy(EVP_MD_CTX *out, const EVP_MD_CTX *in) int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in) { unsigned char *tmp_buf; - if ((in == NULL) || (in->digest == NULL)) { + + if (in == NULL || in->digest == NULL) { EVPerr(EVP_F_EVP_MD_CTX_COPY_EX, EVP_R_INPUT_NOT_INITIALIZED); return 0; } + + if (in->digest->prov == NULL) + goto legacy; + + if (in->digest->dupctx == NULL) { + EVPerr(EVP_F_EVP_MD_CTX_COPY_EX, EVP_R_NOT_ABLE_TO_COPY_CTX); + return 0; + } + + EVP_MD_CTX_reset(out); + if (out->fetched_digest != NULL) + EVP_MD_meth_free(out->fetched_digest); + *out = *in; + /* NULL out pointers in case of error */ + out->pctx = NULL; + out->provctx = NULL; + + if (in->fetched_digest != NULL) + EVP_MD_upref(in->fetched_digest); + + out->provctx = in->digest->dupctx(in->provctx); + if (out->provctx == NULL) { + EVPerr(EVP_F_EVP_MD_CTX_COPY_EX, EVP_R_NOT_ABLE_TO_COPY_CTX); + return 0; + } + + /* copied EVP_MD_CTX should free the copied EVP_PKEY_CTX */ + EVP_MD_CTX_clear_flags(out, EVP_MD_CTX_FLAG_KEEP_PKEY_CTX); + if (in->pctx != NULL) { + out->pctx = EVP_PKEY_CTX_dup(in->pctx); + if (out->pctx == NULL) { + EVPerr(EVP_F_EVP_MD_CTX_COPY_EX, EVP_R_NOT_ABLE_TO_COPY_CTX); + EVP_MD_CTX_reset(out); + return 0; + } + } + + return 1; + + /* TODO(3.0): Remove legacy code below */ + legacy: #ifndef OPENSSL_NO_ENGINE /* Make sure it's safe to copy a digest context using an ENGINE */ if (in->engine && !ENGINE_init(in->engine)) { @@ -296,3 +487,99 @@ int EVP_MD_CTX_ctrl(EVP_MD_CTX *ctx, int cmd, int p1, void *p2) } return 0; } + +static void *evp_md_from_dispatch(int mdtype, const OSSL_DISPATCH *fns, + OSSL_PROVIDER *prov) +{ + EVP_MD *md = NULL; + int fncnt = 0; + + if ((md = EVP_MD_meth_new(mdtype, NID_undef)) == NULL) + return NULL; + + for (; fns->function_id != 0; fns++) { + switch (fns->function_id) { + case OSSL_FUNC_DIGEST_NEWCTX: + if (md->newctx != NULL) + break; + md->newctx = OSSL_get_OP_digest_newctx(fns); + fncnt++; + break; + case OSSL_FUNC_DIGEST_INIT: + if (md->dinit != NULL) + break; + md->dinit = OSSL_get_OP_digest_init(fns); + fncnt++; + break; + case OSSL_FUNC_DIGEST_UPDDATE: + if (md->dupdate != NULL) + break; + md->dupdate = OSSL_get_OP_digest_update(fns); + fncnt++; + break; + case OSSL_FUNC_DIGEST_FINAL: + if (md->dfinal != NULL) + break; + md->dfinal = OSSL_get_OP_digest_final(fns); + fncnt++; + break; + case OSSL_FUNC_DIGEST_DIGEST: + if (md->digest != NULL) + break; + md->digest = OSSL_get_OP_digest_digest(fns); + /* We don't increment fnct for this as it is stand alone */ + break; + case OSSL_FUNC_DIGEST_FREECTX: + if (md->freectx != NULL) + break; + md->freectx = OSSL_get_OP_digest_freectx(fns); + fncnt++; + break; + case OSSL_FUNC_DIGEST_DUPCTX: + if (md->dupctx != NULL) + break; + md->dupctx = OSSL_get_OP_digest_dupctx(fns); + break; + case OSSL_FUNC_DIGEST_SIZE: + if (md->size != NULL) + break; + md->size = OSSL_get_OP_digest_size(fns); + break; + } + } + if ((fncnt != 0 && fncnt != 5) + || (fncnt == 0 && md->digest == NULL) + || md->size == NULL) { + /* + * In order to be a consistent set of functions we either need the + * whole set of init/update/final etc functions or none of them. + * The "digest" function can standalone. We at least need one way to + * generate digests. + */ + EVP_MD_meth_free(md); + return NULL; + } + md->prov = prov; + if (prov != NULL) + ossl_provider_upref(prov); + + return md; +} + +static int evp_md_upref(void *md) +{ + return EVP_MD_upref(md); +} + +static void evp_md_free(void *md) +{ + EVP_MD_meth_free(md); +} + +EVP_MD *EVP_MD_fetch(OPENSSL_CTX *ctx, const char *algorithm, + const char *properties) +{ + return evp_generic_fetch(ctx, OSSL_OP_DIGEST, algorithm, properties, + evp_md_from_dispatch, evp_md_upref, + evp_md_free); +} diff --git a/crypto/evp/e_aria.c b/crypto/evp/e_aria.c index 1d4ac2a2..88284948 100644 --- a/crypto/evp/e_aria.c +++ b/crypto/evp/e_aria.c @@ -486,6 +486,16 @@ static int aria_gcm_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, return 0; } +static int aria_gcm_cleanup(EVP_CIPHER_CTX *ctx) +{ + EVP_ARIA_GCM_CTX *gctx = EVP_C_DATA(EVP_ARIA_GCM_CTX, ctx); + + if (gctx->iv != EVP_CIPHER_CTX_iv_noconst(ctx)) + OPENSSL_free(gctx->iv); + + return 1; +} + static int aria_ccm_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, const unsigned char *iv, int enc) { @@ -727,6 +737,8 @@ static int aria_ccm_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, } } +#define aria_ccm_cleanup NULL + #define ARIA_AUTH_FLAGS (EVP_CIPH_FLAG_DEFAULT_ASN1 \ | EVP_CIPH_CUSTOM_IV | EVP_CIPH_FLAG_CUSTOM_CIPHER \ | EVP_CIPH_ALWAYS_CALL_INIT | EVP_CIPH_CTRL_INIT \ @@ -739,7 +751,7 @@ static const EVP_CIPHER aria_##keylen##_##mode = { \ ARIA_AUTH_FLAGS|EVP_CIPH_##MODE##_MODE, \ aria_##mode##_init_key, \ aria_##mode##_cipher, \ - NULL, \ + aria_##mode##_cleanup, \ sizeof(EVP_ARIA_##MODE##_CTX), \ NULL,NULL,aria_##mode##_ctrl,NULL }; \ const EVP_CIPHER *EVP_aria_##keylen##_##mode(void) \ diff --git a/crypto/evp/evp_err.c b/crypto/evp/evp_err.c index ef889b0a..068120ef 100644 --- a/crypto/evp/evp_err.c +++ b/crypto/evp/evp_err.c @@ -54,7 +54,9 @@ static const ERR_STRING_DATA EVP_str_functs[] = { "EVP_DecryptFinal_ex"}, {ERR_PACK(ERR_LIB_EVP, EVP_F_EVP_DECRYPTUPDATE, 0), "EVP_DecryptUpdate"}, {ERR_PACK(ERR_LIB_EVP, EVP_F_EVP_DIGESTFINALXOF, 0), "EVP_DigestFinalXOF"}, + {ERR_PACK(ERR_LIB_EVP, EVP_F_EVP_DIGESTFINAL_EX, 0), "EVP_DigestFinal_ex"}, {ERR_PACK(ERR_LIB_EVP, EVP_F_EVP_DIGESTINIT_EX, 0), "EVP_DigestInit_ex"}, + {ERR_PACK(ERR_LIB_EVP, EVP_F_EVP_DIGESTUPDATE, 0), "EVP_DigestUpdate"}, {ERR_PACK(ERR_LIB_EVP, EVP_F_EVP_ENCRYPTDECRYPTUPDATE, 0), "evp_EncryptDecryptUpdate"}, {ERR_PACK(ERR_LIB_EVP, EVP_F_EVP_ENCRYPTFINAL_EX, 0), @@ -219,6 +221,7 @@ static const ERR_STRING_DATA EVP_str_reasons[] = { "expecting a poly1305 key"}, {ERR_PACK(ERR_LIB_EVP, 0, EVP_R_EXPECTING_A_SIPHASH_KEY), "expecting a siphash key"}, + {ERR_PACK(ERR_LIB_EVP, 0, EVP_R_FINAL_ERROR), "final error"}, {ERR_PACK(ERR_LIB_EVP, 0, EVP_R_FIPS_MODE_NOT_SUPPORTED), "fips mode not supported"}, {ERR_PACK(ERR_LIB_EVP, 0, EVP_R_GET_RAW_KEY_FAILED), "get raw key failed"}, @@ -246,6 +249,8 @@ static const ERR_STRING_DATA EVP_str_reasons[] = { {ERR_PACK(ERR_LIB_EVP, 0, EVP_R_METHOD_NOT_SUPPORTED), "method not supported"}, {ERR_PACK(ERR_LIB_EVP, 0, EVP_R_MISSING_PARAMETERS), "missing parameters"}, + {ERR_PACK(ERR_LIB_EVP, 0, EVP_R_NOT_ABLE_TO_COPY_CTX), + "not able to copy ctx"}, {ERR_PACK(ERR_LIB_EVP, 0, EVP_R_NOT_XOF_OR_INVALID_LENGTH), "not XOF or invalid length"}, {ERR_PACK(ERR_LIB_EVP, 0, EVP_R_NO_CIPHER_SET), "no cipher set"}, @@ -293,6 +298,7 @@ static const ERR_STRING_DATA EVP_str_reasons[] = { "unsupported private key algorithm"}, {ERR_PACK(ERR_LIB_EVP, 0, EVP_R_UNSUPPORTED_SALT_TYPE), "unsupported salt type"}, + {ERR_PACK(ERR_LIB_EVP, 0, EVP_R_UPDATE_ERROR), "update error"}, {ERR_PACK(ERR_LIB_EVP, 0, EVP_R_WRAP_MODE_NOT_ALLOWED), "wrap mode not allowed"}, {ERR_PACK(ERR_LIB_EVP, 0, EVP_R_WRONG_FINAL_BLOCK_LENGTH), diff --git a/crypto/evp/evp_fetch.c b/crypto/evp/evp_fetch.c new file mode 100644 index 00000000..e50dd592 --- /dev/null +++ b/crypto/evp/evp_fetch.c @@ -0,0 +1,197 @@ +/* + * Copyright 2019 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the Apache License 2.0 (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#include +#include +#include +#include +#include "internal/cryptlib.h" +#include "internal/thread_once.h" +#include "internal/asn1_int.h" +#include "internal/property.h" +#include "internal/core.h" +#include "internal/evp_int.h" /* evp_locl.h needs it */ +#include "evp_locl.h" + +/* The OpenSSL library context index for the default method store */ +static int default_method_store_index = -1; + +static void default_method_store_free(void *vstore) +{ + ossl_method_store_free(vstore); +} + +static void *default_method_store_new(void) +{ + return ossl_method_store_new(); +} + + +static const OPENSSL_CTX_METHOD default_method_store_method = { + default_method_store_new, + default_method_store_free, +}; + +static int default_method_store_init(void) +{ + default_method_store_index = + openssl_ctx_new_index(&default_method_store_method); + + return default_method_store_index != -1; +} + +static CRYPTO_ONCE default_method_store_init_flag = CRYPTO_ONCE_STATIC_INIT; +DEFINE_RUN_ONCE_STATIC(do_default_method_store_init) +{ + return OPENSSL_init_crypto(0, NULL) + && default_method_store_init(); +} + +/* Data to be passed through ossl_method_construct() */ +struct method_data_st { + const char *name; + int nid; + OSSL_METHOD_CONSTRUCT_METHOD *mcm; + void *(*method_from_dispatch)(int nid, const OSSL_DISPATCH *, + OSSL_PROVIDER *); + int (*refcnt_up_method)(void *method); + void (*destruct_method)(void *method); +}; + +/* + * Generic routines to fetch / create EVP methods with ossl_method_construct() + */ +static void *alloc_tmp_method_store(void) +{ + return ossl_method_store_new(); +} + + static void dealloc_tmp_method_store(void *store) +{ + if (store != NULL) + ossl_method_store_free(store); +} + +static +struct OSSL_METHOD_STORE *get_default_method_store(OPENSSL_CTX *libctx) +{ + if (!RUN_ONCE(&default_method_store_init_flag, + do_default_method_store_init)) + return NULL; + return openssl_ctx_get_data(libctx, default_method_store_index); +} + +static void *get_method_from_store(OPENSSL_CTX *libctx, void *store, + const char *propquery, void *data) +{ + struct method_data_st *methdata = data; + void *method = NULL; + + if (store == NULL + && (store = get_default_method_store(libctx)) == NULL) + return NULL; + + (void)ossl_method_store_fetch(store, methdata->nid, propquery, &method); + + if (method != NULL + && !methdata->refcnt_up_method(method)) { + method = NULL; + } + return method; +} + +static int put_method_in_store(OPENSSL_CTX *libctx, void *store, + const char *propdef, void *method, + void *data) +{ + struct method_data_st *methdata = data; + + if (store == NULL + && (store = get_default_method_store(libctx)) == NULL) + return 0; + + if (methdata->refcnt_up_method(method) + && ossl_method_store_add(store, methdata->nid, propdef, method, + methdata->destruct_method)) + return 1; + return 0; +} + +static void *construct_method(const OSSL_DISPATCH *fns, OSSL_PROVIDER *prov, + void *data) +{ + struct method_data_st *methdata = data; + void *method = NULL; + + if (methdata->nid == NID_undef) { + /* Create a new NID for that name on the fly */ + ASN1_OBJECT tmpobj; + + /* This is the same as OBJ_create() but without requiring a OID */ + tmpobj.nid = OBJ_new_nid(1); + tmpobj.sn = tmpobj.ln = methdata->name; + tmpobj.flags = ASN1_OBJECT_FLAG_DYNAMIC; + tmpobj.length = 0; + tmpobj.data = NULL; + + methdata->nid = OBJ_add_object(&tmpobj); + } + + if (methdata->nid == NID_undef) + return NULL; + + method = methdata->method_from_dispatch(methdata->nid, fns, prov); + if (method == NULL) + return NULL; + return method; +} + +static void destruct_method(void *method, void *data) +{ + struct method_data_st *methdata = data; + + methdata->destruct_method(method); +} + +void *evp_generic_fetch(OPENSSL_CTX *libctx, int operation_id, + const char *algorithm, const char *properties, + void *(*new_method)(int nid, const OSSL_DISPATCH *fns, + OSSL_PROVIDER *prov), + int (*upref_method)(void *), + void (*free_method)(void *)) +{ + int nid = OBJ_sn2nid(algorithm); + void *method = NULL; + + if (nid == NID_undef + || !ossl_method_store_cache_get(NULL, nid, properties, &method)) { + OSSL_METHOD_CONSTRUCT_METHOD mcm = { + alloc_tmp_method_store, + dealloc_tmp_method_store, + get_method_from_store, + put_method_in_store, + construct_method, + destruct_method + }; + struct method_data_st mcmdata; + + mcmdata.nid = nid; + mcmdata.mcm = &mcm; + mcmdata.method_from_dispatch = new_method; + mcmdata.destruct_method = free_method; + mcmdata.refcnt_up_method = upref_method; + mcmdata.destruct_method = free_method; + method = ossl_method_construct(libctx, operation_id, algorithm, + properties, 0 /* !force_cache */, + &mcm, &mcmdata); + ossl_method_store_cache_set(NULL, nid, properties, method); + } + + return method; +} diff --git a/crypto/evp/evp_lib.c b/crypto/evp/evp_lib.c index f0ee6ab6..219ae532 100644 --- a/crypto/evp/evp_lib.c +++ b/crypto/evp/evp_lib.c @@ -12,6 +12,7 @@ #include #include #include "internal/evp_int.h" +#include "internal/provider.h" #include "evp_locl.h" int EVP_CIPHER_param_to_asn1(EVP_CIPHER_CTX *c, ASN1_TYPE *type) @@ -316,6 +317,10 @@ int EVP_MD_size(const EVP_MD *md) EVPerr(EVP_F_EVP_MD_SIZE, EVP_R_MESSAGE_DIGEST_IS_NULL); return -1; } + + if (md->prov != NULL && md->size != NULL) + return (int)md->size(); + return md->md_size; } @@ -331,6 +336,12 @@ EVP_MD *EVP_MD_meth_new(int md_type, int pkey_type) if (md != NULL) { md->type = md_type; md->pkey_type = pkey_type; + md->lock = CRYPTO_THREAD_lock_new(); + if (md->lock == NULL) { + OPENSSL_free(md); + return NULL; + } + md->refcnt = 1; } return md; } @@ -342,9 +353,27 @@ EVP_MD *EVP_MD_meth_dup(const EVP_MD *md) memcpy(to, md, sizeof(*to)); return to; } + +int EVP_MD_upref(EVP_MD *md) +{ + int ref = 0; + + CRYPTO_UP_REF(&md->refcnt, &ref, md->lock); + return 1; +} + void EVP_MD_meth_free(EVP_MD *md) { - OPENSSL_free(md); + if (md != NULL) { + int i; + + CRYPTO_DOWN_REF(&md->refcnt, &i, md->lock); + if (i > 0) + return; + ossl_provider_free(md->prov); + CRYPTO_THREAD_lock_free(md->lock); + OPENSSL_free(md); + } } int EVP_MD_meth_set_input_blocksize(EVP_MD *md, int blocksize) { diff --git a/crypto/evp/evp_locl.h b/crypto/evp/evp_locl.h index 95a9d5c5..936824a8 100644 --- a/crypto/evp/evp_locl.h +++ b/crypto/evp/evp_locl.h @@ -1,5 +1,5 @@ /* - * Copyright 2000-2018 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2000-2019 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -19,6 +19,10 @@ struct evp_md_ctx_st { EVP_PKEY_CTX *pctx; /* Update function: usually copied from EVP_MD */ int (*update) (EVP_MD_CTX *ctx, const void *data, size_t count); + + /* Provider ctx */ + void *provctx; + EVP_MD *fetched_digest; } /* EVP_MD_CTX */ ; struct evp_cipher_ctx_st { @@ -76,3 +80,13 @@ typedef struct evp_pbe_st EVP_PBE_CTL; DEFINE_STACK_OF(EVP_PBE_CTL) int is_partially_overlapping(const void *ptr1, const void *ptr2, int len); + +#include +#include + +void *evp_generic_fetch(OPENSSL_CTX *ctx, int operation_id, + const char *algorithm, const char *properties, + void *(*new_method)(int nid, const OSSL_DISPATCH *fns, + OSSL_PROVIDER *prov), + int (*upref_method)(void *), + void (*free_method)(void *)); diff --git a/crypto/evp/kdf_lib.c b/crypto/evp/kdf_lib.c index 811fe727..de2ab232 100644 --- a/crypto/evp/kdf_lib.c +++ b/crypto/evp/kdf_lib.c @@ -31,6 +31,7 @@ static const EVP_KDF_METHOD *standard_methods[] = { &tls1_prf_kdf_meth, &hkdf_kdf_meth, &sshkdf_kdf_meth, + &ss_kdf_meth }; DECLARE_OBJ_BSEARCH_CMP_FN(const EVP_KDF_METHOD *, const EVP_KDF_METHOD *, diff --git a/crypto/evp/mac_lib.c b/crypto/evp/mac_lib.c index 2f46277b..39efff08 100644 --- a/crypto/evp/mac_lib.c +++ b/crypto/evp/mac_lib.c @@ -82,6 +82,8 @@ int EVP_MAC_init(EVP_MAC_CTX *ctx) int EVP_MAC_update(EVP_MAC_CTX *ctx, const unsigned char *data, size_t datalen) { + if (datalen == 0) + return 1; return ctx->meth->update(ctx->data, data, datalen); } diff --git a/crypto/evp/p_lib.c b/crypto/evp/p_lib.c index 9a882e9e..c6ebfe64 100644 --- a/crypto/evp/p_lib.c +++ b/crypto/evp/p_lib.c @@ -396,6 +396,11 @@ int EVP_PKEY_set1_engine(EVP_PKEY *pkey, ENGINE *e) pkey->pmeth_engine = e; return 1; } + +ENGINE *EVP_PKEY_get0_engine(const EVP_PKEY *pkey) +{ + return pkey->engine; +} #endif int EVP_PKEY_assign(EVP_PKEY *pkey, int type, void *key) { diff --git a/crypto/evp/pbe_scrypt.c b/crypto/evp/pbe_scrypt.c index cad0440e..c0ab238e 100644 --- a/crypto/evp/pbe_scrypt.c +++ b/crypto/evp/pbe_scrypt.c @@ -52,6 +52,10 @@ int EVP_PBE_scrypt(const char *pass, size_t passlen, pass = empty; passlen = 0; } + if (salt == NULL) { + salt = (const unsigned char *)empty; + saltlen = 0; + } if (maxmem == 0) maxmem = SCRYPT_MAX_MEM; diff --git a/crypto/evp/pkey_mac.c b/crypto/evp/pkey_mac.c index 858ca287..fc627f17 100644 --- a/crypto/evp/pkey_mac.c +++ b/crypto/evp/pkey_mac.c @@ -231,9 +231,9 @@ static int pkey_mac_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2) int rv; if ((rv = EVP_MAC_ctrl(hctx->ctx, EVP_MAC_CTRL_SET_ENGINE, - ctx->engine)) < 0 + ctx->engine)) <= 0 || (rv = EVP_MAC_ctrl(hctx->ctx, EVP_MAC_CTRL_SET_CIPHER, - p2)) < 0 + p2)) <= 0 || !(rv = EVP_MAC_init(hctx->ctx))) return rv; } @@ -275,7 +275,7 @@ static int pkey_mac_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2) return 0; break; case MAC_TYPE_MAC: - if (!EVP_MAC_ctrl(hctx->ctx, EVP_MAC_CTRL_SET_KEY, p2, p1)) + if (EVP_MAC_ctrl(hctx->ctx, EVP_MAC_CTRL_SET_KEY, p2, p1) <= 0) return 0; break; default: @@ -296,11 +296,11 @@ static int pkey_mac_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2) (ASN1_OCTET_STRING *)ctx->pkey->pkey.ptr; if ((rv = EVP_MAC_ctrl(hctx->ctx, EVP_MAC_CTRL_SET_ENGINE, - ctx->engine)) < 0 + ctx->engine)) <= 0 || (rv = EVP_MAC_ctrl(hctx->ctx, EVP_MAC_CTRL_SET_MD, - hctx->raw_data.md)) < 0 + hctx->raw_data.md)) <= 0 || (rv = EVP_MAC_ctrl(hctx->ctx, EVP_MAC_CTRL_SET_KEY, - key->data, key->length)) < 0) + key->data, key->length)) <= 0) return rv; } break; diff --git a/crypto/hmac/hmac.c b/crypto/hmac/hmac.c index e78f66a7..5d934e95 100644 --- a/crypto/hmac/hmac.c +++ b/crypto/hmac/hmac.c @@ -35,6 +35,13 @@ int HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int len, return 0; } + /* + * The HMAC construction is not allowed to be used with the + * extendable-output functions (XOF) shake128 and shake256. + */ + if ((EVP_MD_meth_get_flags(md) & EVP_MD_FLAG_XOF) != 0) + return 0; + if (key != NULL) { reset = 1; j = EVP_MD_block_size(md); diff --git a/crypto/include/internal/bn_int.h b/crypto/include/internal/bn_int.h index 514eaeeb..4fcbb145 100644 --- a/crypto/include/internal/bn_int.h +++ b/crypto/include/internal/bn_int.h @@ -110,8 +110,4 @@ int bn_rsa_fips186_4_derive_prime(BIGNUM *Y, BIGNUM *X, const BIGNUM *Xin, const BIGNUM *r1, const BIGNUM *r2, int nlen, const BIGNUM *e, BN_CTX *ctx, BN_GENCB *cb); -#ifdef __cplusplus -} -#endif - #endif diff --git a/crypto/include/internal/evp_int.h b/crypto/include/internal/evp_int.h index e55c1d9e..ab8ce00e 100644 --- a/crypto/include/internal/evp_int.h +++ b/crypto/include/internal/evp_int.h @@ -8,6 +8,7 @@ */ #include +#include #include "internal/refcount.h" /* @@ -169,9 +170,14 @@ extern const EVP_KDF_METHOD scrypt_kdf_meth; extern const EVP_KDF_METHOD tls1_prf_kdf_meth; extern const EVP_KDF_METHOD hkdf_kdf_meth; extern const EVP_KDF_METHOD sshkdf_kdf_meth; +extern const EVP_KDF_METHOD ss_kdf_meth; struct evp_md_st { + /* nid */ int type; + + /* Legacy structure members */ + /* TODO(3.0): Remove these */ int pkey_type; int md_size; unsigned long flags; @@ -184,6 +190,21 @@ struct evp_md_st { int ctx_size; /* how big does the ctx->md_data need to be */ /* control function */ int (*md_ctrl) (EVP_MD_CTX *ctx, int cmd, int p1, void *p2); + + /* New structure members */ + /* TODO(3.0): Remove above comment when legacy has gone */ + OSSL_PROVIDER *prov; + CRYPTO_REF_COUNT refcnt; + CRYPTO_RWLOCK *lock; + OSSL_OP_digest_newctx_fn *newctx; + OSSL_OP_digest_init_fn *dinit; + OSSL_OP_digest_update_fn *dupdate; + OSSL_OP_digest_final_fn *dfinal; + OSSL_OP_digest_digest_fn *digest; + OSSL_OP_digest_freectx_fn *freectx; + OSSL_OP_digest_dupctx_fn *dupctx; + OSSL_OP_digest_size_fn *size; + } /* EVP_MD */ ; struct evp_cipher_st { diff --git a/crypto/include/internal/rand_int.h b/crypto/include/internal/rand_int.h index 5098125f..b7453934 100644 --- a/crypto/include/internal/rand_int.h +++ b/crypto/include/internal/rand_int.h @@ -49,6 +49,14 @@ size_t rand_drbg_get_additional_data(RAND_POOL *pool, unsigned char **pout); void rand_drbg_cleanup_additional_data(RAND_POOL *pool, unsigned char *out); +/* CRNG test entropy filter callbacks. */ +size_t rand_crngt_get_entropy(RAND_DRBG *drbg, + unsigned char **pout, + int entropy, size_t min_len, size_t max_len, + int prediction_resistance); +void rand_crngt_cleanup_entropy(RAND_DRBG *drbg, + unsigned char *out, size_t outlen); + /* * RAND_POOL functions */ diff --git a/crypto/init.c b/crypto/init.c index 12c9d627..dfc5c5f8 100644 --- a/crypto/init.c +++ b/crypto/init.c @@ -163,7 +163,7 @@ DEFINE_RUN_ONCE_STATIC(ossl_init_load_crypto_nodelete) #if !defined(OPENSSL_NO_DSO) \ && !defined(OPENSSL_USE_NODELETE) \ && !defined(OPENSSL_NO_PINSHARED) -# ifdef DSO_WIN32 +# if defined(DSO_WIN32) && !defined(_WIN32_WCE) { HMODULE handle = NULL; BOOL ret; @@ -743,7 +743,7 @@ int OPENSSL_atexit(void (*handler)(void)) } handlersym; handlersym.func = handler; -# ifdef DSO_WIN32 +# if defined(DSO_WIN32) && !defined(_WIN32_WCE) { HMODULE handle = NULL; BOOL ret; diff --git a/crypto/kdf/build.info b/crypto/kdf/build.info index f483c779..52e40a4f 100644 --- a/crypto/kdf/build.info +++ b/crypto/kdf/build.info @@ -1,3 +1,4 @@ LIBS=../../libcrypto SOURCE[../../libcrypto]=\ - tls1_prf.c kdf_err.c kdf_util.c hkdf.c scrypt.c pbkdf2.c sshkdf.c + tls1_prf.c kdf_err.c kdf_util.c hkdf.c scrypt.c pbkdf2.c sshkdf.c \ + sskdf.c diff --git a/crypto/kdf/kdf_err.c b/crypto/kdf/kdf_err.c index a70f5219..84c330fa 100644 --- a/crypto/kdf/kdf_err.c +++ b/crypto/kdf/kdf_err.c @@ -59,12 +59,18 @@ static const ERR_STRING_DATA KDF_str_functs[] = { "pkey_tls1_prf_derive"}, {ERR_PACK(ERR_LIB_KDF, KDF_F_PKEY_TLS1_PRF_INIT, 0), "pkey_tls1_prf_init"}, {ERR_PACK(ERR_LIB_KDF, KDF_F_SCRYPT_SET_MEMBUF, 0), "scrypt_set_membuf"}, + {ERR_PACK(ERR_LIB_KDF, KDF_F_SSKDF_CTRL_STR, 0), "sskdf_ctrl_str"}, + {ERR_PACK(ERR_LIB_KDF, KDF_F_SSKDF_DERIVE, 0), "sskdf_derive"}, + {ERR_PACK(ERR_LIB_KDF, KDF_F_SSKDF_MAC2CTRL, 0), "sskdf_mac2ctrl"}, + {ERR_PACK(ERR_LIB_KDF, KDF_F_SSKDF_NEW, 0), "sskdf_new"}, + {ERR_PACK(ERR_LIB_KDF, KDF_F_SSKDF_SIZE, 0), "sskdf_size"}, {ERR_PACK(ERR_LIB_KDF, KDF_F_TLS1_PRF_ALG, 0), "tls1_prf_alg"}, {0, NULL} }; static const ERR_STRING_DATA KDF_str_reasons[] = { {ERR_PACK(ERR_LIB_KDF, 0, KDF_R_INVALID_DIGEST), "invalid digest"}, + {ERR_PACK(ERR_LIB_KDF, 0, KDF_R_INVALID_MAC_TYPE), "invalid mac type"}, {ERR_PACK(ERR_LIB_KDF, 0, KDF_R_MISSING_ITERATION_COUNT), "missing iteration count"}, {ERR_PACK(ERR_LIB_KDF, 0, KDF_R_MISSING_KEY), "missing key"}, @@ -80,6 +86,8 @@ static const ERR_STRING_DATA KDF_str_reasons[] = { {ERR_PACK(ERR_LIB_KDF, 0, KDF_R_MISSING_XCGHASH), "missing xcghash"}, {ERR_PACK(ERR_LIB_KDF, 0, KDF_R_UNKNOWN_PARAMETER_TYPE), "unknown parameter type"}, + {ERR_PACK(ERR_LIB_KDF, 0, KDF_R_UNSUPPORTED_MAC_TYPE), + "unsupported mac type"}, {ERR_PACK(ERR_LIB_KDF, 0, KDF_R_VALUE_ERROR), "value error"}, {ERR_PACK(ERR_LIB_KDF, 0, KDF_R_VALUE_MISSING), "value missing"}, {ERR_PACK(ERR_LIB_KDF, 0, KDF_R_WRONG_OUTPUT_BUFFER_SIZE), diff --git a/crypto/kdf/sskdf.c b/crypto/kdf/sskdf.c new file mode 100644 index 00000000..89e4e5b4 --- /dev/null +++ b/crypto/kdf/sskdf.c @@ -0,0 +1,484 @@ +/* + * Copyright 2019 The OpenSSL Project Authors. All Rights Reserved. + * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. + * + * Licensed under the Apache License 2.0 (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +/* + * Refer to https://csrc.nist.gov/publications/detail/sp/800-56c/rev-1/final + * Section 4.1. + * + * The Single Step KDF algorithm is given by: + * + * Result(0) = empty bit string (i.e., the null string). + * For i = 1 to reps, do the following: + * Increment counter by 1. + * Result(i) = Result(i – 1) || H(counter || Z || FixedInfo). + * DKM = LeftmostBits(Result(reps), L)) + * + * NOTES: + * Z is a shared secret required to produce the derived key material. + * counter is a 4 byte buffer. + * FixedInfo is a bit string containing context specific data. + * DKM is the output derived key material. + * L is the required size of the DKM. + * reps = [L / H_outputBits] + * H(x) is the auxiliary function that can be either a hash, HMAC or KMAC. + * H_outputBits is the length of the output of the auxiliary function H(x). + * + * Currently there is not a comprehensive list of test vectors for this + * algorithm, especially for H(x) = HMAC and H(x) = KMAC. + * Test vectors for H(x) = Hash are indirectly used by CAVS KAS tests. + */ +#include +#include +#include +#include +#include +#include +#include "internal/cryptlib.h" +#include "internal/evp_int.h" +#include "kdf_local.h" + +struct evp_kdf_impl_st { + const EVP_MAC *mac; /* H(x) = HMAC_hash OR H(x) = KMAC */ + const EVP_MD *md; /* H(x) = hash OR when H(x) = HMAC_hash */ + unsigned char *secret; + size_t secret_len; + unsigned char *info; + size_t info_len; + unsigned char *salt; + size_t salt_len; + size_t out_len; /* optional KMAC parameter */ +}; + +#define SSKDF_MAX_INLEN (1<<30) +#define SSKDF_KMAC128_DEFAULT_SALT_SIZE (168 - 4) +#define SSKDF_KMAC256_DEFAULT_SALT_SIZE (136 - 4) + +/* KMAC uses a Customisation string of 'KDF' */ +static const unsigned char kmac_custom_str[] = { 0x4B, 0x44, 0x46 }; + +/* + * Refer to https://csrc.nist.gov/publications/detail/sp/800-56c/rev-1/final + * Section 4. One-Step Key Derivation using H(x) = hash(x) + */ +static int SSKDF_hash_kdm(const EVP_MD *kdf_md, + const unsigned char *z, size_t z_len, + const unsigned char *info, size_t info_len, + unsigned char *derived_key, size_t derived_key_len) +{ + int ret = 0, hlen; + size_t counter, out_len, len = derived_key_len; + unsigned char c[4]; + unsigned char mac[EVP_MAX_MD_SIZE]; + unsigned char *out = derived_key; + EVP_MD_CTX *ctx = NULL, *ctx_init = NULL; + + if (z_len > SSKDF_MAX_INLEN || info_len > SSKDF_MAX_INLEN + || derived_key_len > SSKDF_MAX_INLEN + || derived_key_len == 0) + return 0; + + hlen = EVP_MD_size(kdf_md); + if (hlen <= 0) + return 0; + out_len = (size_t)hlen; + + ctx = EVP_MD_CTX_create(); + ctx_init = EVP_MD_CTX_create(); + if (ctx == NULL || ctx_init == NULL) + goto end; + + if (!EVP_DigestInit(ctx_init, kdf_md)) + goto end; + + for (counter = 1;; counter++) { + c[0] = (unsigned char)((counter >> 24) & 0xff); + c[1] = (unsigned char)((counter >> 16) & 0xff); + c[2] = (unsigned char)((counter >> 8) & 0xff); + c[3] = (unsigned char)(counter & 0xff); + + if (!(EVP_MD_CTX_copy_ex(ctx, ctx_init) + && EVP_DigestUpdate(ctx, c, sizeof(c)) + && EVP_DigestUpdate(ctx, z, z_len) + && EVP_DigestUpdate(ctx, info, info_len))) + goto end; + if (len >= out_len) { + if (!EVP_DigestFinal_ex(ctx, out, NULL)) + goto end; + out += out_len; + len -= out_len; + if (len == 0) + break; + } else { + if (!EVP_DigestFinal_ex(ctx, mac, NULL)) + goto end; + memcpy(out, mac, len); + break; + } + } + ret = 1; +end: + EVP_MD_CTX_destroy(ctx); + EVP_MD_CTX_destroy(ctx_init); + OPENSSL_cleanse(mac, sizeof(mac)); + return ret; +} + +static int kmac_init(EVP_MAC_CTX *ctx, const unsigned char *custom, + size_t custom_len, size_t kmac_out_len, + size_t derived_key_len, unsigned char **out) +{ + /* Only KMAC has custom data - so return if not KMAC */ + if (custom == NULL) + return 1; + + if (EVP_MAC_ctrl(ctx, EVP_MAC_CTRL_SET_CUSTOM, custom, custom_len) <= 0) + return 0; + + /* By default only do one iteration if kmac_out_len is not specified */ + if (kmac_out_len == 0) + kmac_out_len = derived_key_len; + /* otherwise check the size is valid */ + else if (!(kmac_out_len == derived_key_len + || kmac_out_len == 20 + || kmac_out_len == 28 + || kmac_out_len == 32 + || kmac_out_len == 48 + || kmac_out_len == 64)) + return 0; + + if (EVP_MAC_ctrl(ctx, EVP_MAC_CTRL_SET_SIZE, kmac_out_len) <= 0) + return 0; + + /* + * For kmac the output buffer can be larger than EVP_MAX_MD_SIZE: so + * alloc a buffer for this case. + */ + if (kmac_out_len > EVP_MAX_MD_SIZE) { + *out = OPENSSL_zalloc(kmac_out_len); + if (*out == NULL) + return 0; + } + return 1; +} + +/* + * Refer to https://csrc.nist.gov/publications/detail/sp/800-56c/rev-1/final + * Section 4. One-Step Key Derivation using MAC: i.e either + * H(x) = HMAC-hash(salt, x) OR + * H(x) = KMAC#(salt, x, outbits, CustomString='KDF') + */ +static int SSKDF_mac_kdm(const EVP_MAC *kdf_mac, const EVP_MD *hmac_md, + const unsigned char *kmac_custom, + size_t kmac_custom_len, size_t kmac_out_len, + const unsigned char *salt, size_t salt_len, + const unsigned char *z, size_t z_len, + const unsigned char *info, size_t info_len, + unsigned char *derived_key, size_t derived_key_len) +{ + int ret = 0; + size_t counter, out_len, len; + unsigned char c[4]; + unsigned char mac_buf[EVP_MAX_MD_SIZE]; + unsigned char *out = derived_key; + EVP_MAC_CTX *ctx = NULL, *ctx_init = NULL; + unsigned char *mac = mac_buf, *kmac_buffer = NULL; + + if (z_len > SSKDF_MAX_INLEN || info_len > SSKDF_MAX_INLEN + || derived_key_len > SSKDF_MAX_INLEN + || derived_key_len == 0) + return 0; + + ctx = EVP_MAC_CTX_new(kdf_mac); + ctx_init = EVP_MAC_CTX_new(kdf_mac); + if (ctx == NULL || ctx_init == NULL) + goto end; + if (hmac_md != NULL && + EVP_MAC_ctrl(ctx_init, EVP_MAC_CTRL_SET_MD, hmac_md) <= 0) + goto end; + + if (EVP_MAC_ctrl(ctx_init, EVP_MAC_CTRL_SET_KEY, salt, salt_len) <= 0) + goto end; + + if (!kmac_init(ctx_init, kmac_custom, kmac_custom_len, kmac_out_len, + derived_key_len, &kmac_buffer)) + goto end; + if (kmac_buffer != NULL) + mac = kmac_buffer; + + if (!EVP_MAC_init(ctx_init)) + goto end; + + out_len = EVP_MAC_size(ctx_init); /* output size */ + if (out_len <= 0) + goto end; + len = derived_key_len; + + for (counter = 1;; counter++) { + c[0] = (unsigned char)((counter >> 24) & 0xff); + c[1] = (unsigned char)((counter >> 16) & 0xff); + c[2] = (unsigned char)((counter >> 8) & 0xff); + c[3] = (unsigned char)(counter & 0xff); + + if (!(EVP_MAC_CTX_copy(ctx, ctx_init) + && EVP_MAC_update(ctx, c, sizeof(c)) + && EVP_MAC_update(ctx, z, z_len) + && EVP_MAC_update(ctx, info, info_len))) + goto end; + if (len >= out_len) { + if (!EVP_MAC_final(ctx, out, NULL)) + goto end; + out += out_len; + len -= out_len; + if (len == 0) + break; + } else { + if (!EVP_MAC_final(ctx, mac, NULL)) + goto end; + memcpy(out, mac, len); + break; + } + } + ret = 1; +end: + if (kmac_buffer != NULL) + OPENSSL_clear_free(kmac_buffer, kmac_out_len); + else + OPENSSL_cleanse(mac_buf, sizeof(mac_buf)); + + EVP_MAC_CTX_free(ctx); + EVP_MAC_CTX_free(ctx_init); + return ret; +} + +static EVP_KDF_IMPL *sskdf_new(void) +{ + EVP_KDF_IMPL *impl; + + if ((impl = OPENSSL_zalloc(sizeof(*impl))) == NULL) + KDFerr(KDF_F_SSKDF_NEW, ERR_R_MALLOC_FAILURE); + return impl; +} + +static void sskdf_reset(EVP_KDF_IMPL *impl) +{ + OPENSSL_clear_free(impl->secret, impl->secret_len); + OPENSSL_clear_free(impl->info, impl->info_len); + OPENSSL_clear_free(impl->salt, impl->salt_len); + memset(impl, 0, sizeof(*impl)); +} + +static void sskdf_free(EVP_KDF_IMPL *impl) +{ + sskdf_reset(impl); + OPENSSL_free(impl); +} + +static int sskdf_set_buffer(va_list args, unsigned char **out, size_t *out_len) +{ + const unsigned char *p; + size_t len; + + p = va_arg(args, const unsigned char *); + len = va_arg(args, size_t); + if (len == 0 || p == NULL) + return 1; + + OPENSSL_free(*out); + *out = OPENSSL_memdup(p, len); + if (*out == NULL) + return 0; + + *out_len = len; + return 1; +} + +static int sskdf_ctrl(EVP_KDF_IMPL *impl, int cmd, va_list args) +{ + const EVP_MD *md; + const EVP_MAC *mac; + + switch (cmd) { + case EVP_KDF_CTRL_SET_KEY: + return sskdf_set_buffer(args, &impl->secret, &impl->secret_len); + + case EVP_KDF_CTRL_SET_SSKDF_INFO: + return sskdf_set_buffer(args, &impl->info, &impl->info_len); + + case EVP_KDF_CTRL_SET_MD: + md = va_arg(args, const EVP_MD *); + if (md == NULL) + return 0; + + impl->md = md; + return 1; + + case EVP_KDF_CTRL_SET_MAC: + mac = va_arg(args, const EVP_MAC *); + if (mac == NULL) + return 0; + + impl->mac = mac; + return 1; + + case EVP_KDF_CTRL_SET_SALT: + return sskdf_set_buffer(args, &impl->salt, &impl->salt_len); + + case EVP_KDF_CTRL_SET_MAC_SIZE: + impl->out_len = va_arg(args, size_t); + return 1; + + default: + return -2; + } +} + +/* Pass a mac to a ctrl */ +static int sskdf_mac2ctrl(EVP_KDF_IMPL *impl, + int (*ctrl)(EVP_KDF_IMPL *impl, int cmd, va_list args), + int cmd, const char *mac_name) +{ + const EVP_MAC *mac; + + if (mac_name == NULL || (mac = EVP_get_macbyname(mac_name)) == NULL) { + KDFerr(KDF_F_SSKDF_MAC2CTRL, KDF_R_INVALID_MAC_TYPE); + return 0; + } + return call_ctrl(ctrl, impl, cmd, mac); +} + +static int sskdf_ctrl_str(EVP_KDF_IMPL *impl, const char *type, + const char *value) +{ + if (strcmp(type, "secret") == 0 || strcmp(type, "key") == 0) + return kdf_str2ctrl(impl, sskdf_ctrl, EVP_KDF_CTRL_SET_KEY, + value); + + if (strcmp(type, "hexsecret") == 0 || strcmp(type, "hexkey") == 0) + return kdf_hex2ctrl(impl, sskdf_ctrl, EVP_KDF_CTRL_SET_KEY, + value); + + if (strcmp(type, "info") == 0) + return kdf_str2ctrl(impl, sskdf_ctrl, EVP_KDF_CTRL_SET_SSKDF_INFO, + value); + + if (strcmp(type, "hexinfo") == 0) + return kdf_hex2ctrl(impl, sskdf_ctrl, EVP_KDF_CTRL_SET_SSKDF_INFO, + value); + + if (strcmp(type, "digest") == 0) + return kdf_md2ctrl(impl, sskdf_ctrl, EVP_KDF_CTRL_SET_MD, value); + + if (strcmp(type, "mac") == 0) + return sskdf_mac2ctrl(impl, sskdf_ctrl, EVP_KDF_CTRL_SET_MAC, value); + + if (strcmp(type, "salt") == 0) + return kdf_str2ctrl(impl, sskdf_ctrl, EVP_KDF_CTRL_SET_SALT, value); + + if (strcmp(type, "hexsalt") == 0) + return kdf_hex2ctrl(impl, sskdf_ctrl, EVP_KDF_CTRL_SET_SALT, value); + + + if (strcmp(type, "maclen") == 0) { + int val = atoi(value); + if (val < 0) { + KDFerr(KDF_F_SSKDF_CTRL_STR, KDF_R_VALUE_ERROR); + return 0; + } + return call_ctrl(sskdf_ctrl, impl, EVP_KDF_CTRL_SET_MAC_SIZE, + (size_t)val); + } + return -2; +} + +static size_t sskdf_size(EVP_KDF_IMPL *impl) +{ + int len; + + if (impl->md == NULL) { + KDFerr(KDF_F_SSKDF_SIZE, KDF_R_MISSING_MESSAGE_DIGEST); + return 0; + } + len = EVP_MD_size(impl->md); + return (len <= 0) ? 0 : (size_t)len; +} + +static int sskdf_derive(EVP_KDF_IMPL *impl, unsigned char *key, size_t keylen) +{ + if (impl->secret == NULL) { + KDFerr(KDF_F_SSKDF_DERIVE, KDF_R_MISSING_SECRET); + return 0; + } + + if (impl->mac != NULL) { + /* H(x) = KMAC or H(x) = HMAC */ + int ret; + const unsigned char *custom = NULL; + size_t custom_len = 0; + int nid; + int default_salt_len; + + nid = EVP_MAC_nid(impl->mac); + if (nid == EVP_MAC_HMAC) { + /* H(x) = HMAC(x, salt, hash) */ + if (impl->md == NULL) { + KDFerr(KDF_F_SSKDF_DERIVE, KDF_R_MISSING_MESSAGE_DIGEST); + return 0; + } + default_salt_len = EVP_MD_block_size(impl->md); + if (default_salt_len <= 0) + return 0; + } else if (nid == EVP_MAC_KMAC128 || nid == EVP_MAC_KMAC256) { + /* H(x) = KMACzzz(x, salt, custom) */ + custom = kmac_custom_str; + custom_len = sizeof(kmac_custom_str); + if (nid == EVP_MAC_KMAC128) + default_salt_len = SSKDF_KMAC128_DEFAULT_SALT_SIZE; + else + default_salt_len = SSKDF_KMAC256_DEFAULT_SALT_SIZE; + } else { + KDFerr(KDF_F_SSKDF_DERIVE, KDF_R_UNSUPPORTED_MAC_TYPE); + return 0; + } + /* If no salt is set then use a default_salt of zeros */ + if (impl->salt == NULL || impl->salt_len <= 0) { + impl->salt = OPENSSL_zalloc(default_salt_len); + if (impl->salt == NULL) { + KDFerr(KDF_F_SSKDF_DERIVE, ERR_R_MALLOC_FAILURE); + return 0; + } + impl->salt_len = default_salt_len; + } + ret = SSKDF_mac_kdm(impl->mac, impl->md, + custom, custom_len, impl->out_len, + impl->salt, impl->salt_len, + impl->secret, impl->secret_len, + impl->info, impl->info_len, key, keylen); + return ret; + } else { + /* H(x) = hash */ + if (impl->md == NULL) { + KDFerr(KDF_F_SSKDF_DERIVE, KDF_R_MISSING_MESSAGE_DIGEST); + return 0; + } + return SSKDF_hash_kdm(impl->md, impl->secret, impl->secret_len, + impl->info, impl->info_len, key, keylen); + } +} + +const EVP_KDF_METHOD ss_kdf_meth = { + EVP_KDF_SS, + sskdf_new, + sskdf_free, + sskdf_reset, + sskdf_ctrl, + sskdf_ctrl_str, + sskdf_size, + sskdf_derive +}; diff --git a/crypto/mips_arch.h b/crypto/mips_arch.h index 0ac3bfaa..df4ff7ae 100644 --- a/crypto/mips_arch.h +++ b/crypto/mips_arch.h @@ -11,7 +11,7 @@ # define __MIPS_ARCH_H__ # if (defined(__mips_smartmips) || defined(_MIPS_ARCH_MIPS32R3) || \ - defined(_MIPS_ARCH_MIPS32R5) || defined(_MIPS_ARCH_MIPS32R6)) + defined(_MIPS_ARCH_MIPS32R5) || defined(_MIPS_ARCH_MIPS32R6)) \ && !defined(_MIPS_ARCH_MIPS32R2) # define _MIPS_ARCH_MIPS32R2 # endif diff --git a/crypto/modes/siv128.c b/crypto/modes/siv128.c index 99b11d17..f812d0a7 100644 --- a/crypto/modes/siv128.c +++ b/crypto/modes/siv128.c @@ -166,8 +166,8 @@ int CRYPTO_siv128_init(SIV128_CONTEXT *ctx, const unsigned char *key, int klen, || (ctx->cipher_ctx = EVP_CIPHER_CTX_new()) == NULL || (ctx->mac_ctx_init = EVP_MAC_CTX_new_id(EVP_MAC_CMAC)) == NULL || (ctx->mac_ctx = EVP_MAC_CTX_new_id(EVP_MAC_CMAC)) == NULL - || !EVP_MAC_ctrl(ctx->mac_ctx_init, EVP_MAC_CTRL_SET_CIPHER, cbc) - || !EVP_MAC_ctrl(ctx->mac_ctx_init, EVP_MAC_CTRL_SET_KEY, key, klen) + || EVP_MAC_ctrl(ctx->mac_ctx_init, EVP_MAC_CTRL_SET_CIPHER, cbc) <= 0 + || EVP_MAC_ctrl(ctx->mac_ctx_init, EVP_MAC_CTRL_SET_KEY, key, klen) <= 0 || !EVP_EncryptInit_ex(ctx->cipher_ctx, ctr, NULL, key + klen, NULL) || !EVP_MAC_CTX_copy(ctx->mac_ctx, ctx->mac_ctx_init) || !EVP_MAC_update(ctx->mac_ctx, zero, sizeof(zero)) diff --git a/crypto/objects/obj_dat.h b/crypto/objects/obj_dat.h index 339aaa70..b761ad1e 100644 --- a/crypto/objects/obj_dat.h +++ b/crypto/objects/obj_dat.h @@ -1080,7 +1080,7 @@ static const unsigned char so[7775] = { 0x2A,0x81,0x1C,0xCF,0x55,0x01,0x83,0x75, /* [ 7766] OBJ_SM2_with_SM3 */ }; -#define NUM_NID 1206 +#define NUM_NID 1207 static const ASN1_OBJECT nid_objs[NUM_NID] = { {"UNDEF", "undefined", NID_undef}, {"rsadsi", "RSA Data Security, Inc.", NID_rsadsi, 6, &so[0]}, @@ -2287,10 +2287,11 @@ static const ASN1_OBJECT nid_objs[NUM_NID] = { {"BLAKE2SMAC", "blake2smac", NID_blake2smac}, {"SSHKDF", "sshkdf", NID_sshkdf}, {"SM2-SM3", "SM2-with-SM3", NID_SM2_with_SM3, 8, &so[7766]}, + {"SSKDF", "sskdf", NID_sskdf}, {"ChaCha20-Poly1305-D", "chacha20-poly1305-draft", NID_chacha20_poly1305_draft}, }; -#define NUM_SN 1197 +#define NUM_SN 1198 static const unsigned int sn_objs[NUM_SN] = { 364, /* "AD_DVCS" */ 419, /* "AES-128-CBC" */ @@ -2413,7 +2414,7 @@ static const unsigned int sn_objs[NUM_SN] = { 417, /* "CSPName" */ 1019, /* "ChaCha20" */ 1018, /* "ChaCha20-Poly1305" */ - 1205, /* "ChaCha20-Poly1305-D" */ + 1206, /* "ChaCha20-Poly1305-D" */ 367, /* "CrlID" */ 391, /* "DC" */ 31, /* "DES-CBC" */ @@ -2579,6 +2580,7 @@ static const unsigned int sn_objs[NUM_SN] = { 100, /* "SN" */ 1006, /* "SNILS" */ 1203, /* "SSHKDF" */ + 1205, /* "SSKDF" */ 16, /* "ST" */ 143, /* "SXNetID" */ 1062, /* "SipHash" */ @@ -3491,7 +3493,7 @@ static const unsigned int sn_objs[NUM_SN] = { 1093, /* "x509ExtAdmission" */ }; -#define NUM_LN 1197 +#define NUM_LN 1198 static const unsigned int ln_objs[NUM_LN] = { 363, /* "AD Time Stamping" */ 405, /* "ANSI X9.62" */ @@ -3876,7 +3878,7 @@ static const unsigned int ln_objs[NUM_LN] = { 883, /* "certificateRevocationList" */ 1019, /* "chacha20" */ 1018, /* "chacha20-poly1305" */ - 1205, /* "chacha20-poly1305-draft" */ + 1206, /* "chacha20-poly1305-draft" */ 54, /* "challengePassword" */ 407, /* "characteristic-two-field" */ 395, /* "clearance" */ @@ -4644,6 +4646,7 @@ static const unsigned int ln_objs[NUM_LN] = { 1133, /* "sm4-ecb" */ 1135, /* "sm4-ofb" */ 1203, /* "sshkdf" */ + 1205, /* "sskdf" */ 16, /* "stateOrProvinceName" */ 660, /* "streetAddress" */ 498, /* "subtreeMaximumQuality" */ diff --git a/crypto/objects/obj_mac.num b/crypto/objects/obj_mac.num index 4d3e79d4..03c87d5b 100644 --- a/crypto/objects/obj_mac.num +++ b/crypto/objects/obj_mac.num @@ -1202,4 +1202,5 @@ blake2bmac 1201 blake2smac 1202 sshkdf 1203 SM2_with_SM3 1204 -chacha20_poly1305_draft 1205 +sskdf 1205 +chacha20_poly1305_draft 1206 diff --git a/crypto/objects/objects.txt b/crypto/objects/objects.txt index 2f236c30..2a61f1a2 100644 --- a/crypto/objects/objects.txt +++ b/crypto/objects/objects.txt @@ -1615,6 +1615,9 @@ secg-scheme 14 3 : dhSinglePass-cofactorDH-sha512kdf-scheme # NID for SSHKDF : SSHKDF : sshkdf +# NID for SSKDF + : SSKDF : sskdf + # RFC 4556 1 3 6 1 5 2 3 : id-pkinit id-pkinit 4 : pkInitClientAuth : PKINIT Client Auth diff --git a/crypto/ocsp/ocsp_lib.c b/crypto/ocsp/ocsp_lib.c index 48cde65a..e68513e1 100644 --- a/crypto/ocsp/ocsp_lib.c +++ b/crypto/ocsp/ocsp_lib.c @@ -88,7 +88,7 @@ OCSP_CERTID *OCSP_cert_id_new(const EVP_MD *dgst, return NULL; } -int OCSP_id_issuer_cmp(OCSP_CERTID *a, OCSP_CERTID *b) +int OCSP_id_issuer_cmp(const OCSP_CERTID *a, const OCSP_CERTID *b) { int ret; ret = OBJ_cmp(a->hashAlgorithm.algorithm, b->hashAlgorithm.algorithm); @@ -100,7 +100,7 @@ int OCSP_id_issuer_cmp(OCSP_CERTID *a, OCSP_CERTID *b) return ASN1_OCTET_STRING_cmp(&a->issuerKeyHash, &b->issuerKeyHash); } -int OCSP_id_cmp(OCSP_CERTID *a, OCSP_CERTID *b) +int OCSP_id_cmp(const OCSP_CERTID *a, const OCSP_CERTID *b) { int ret; ret = OCSP_id_issuer_cmp(a, b); diff --git a/crypto/params.c b/crypto/params.c index a53d5134..367b2abd 100644 --- a/crypto/params.c +++ b/crypto/params.c @@ -41,50 +41,22 @@ static OSSL_PARAM ossl_param_construct(const char *key, unsigned int data_type, int OSSL_PARAM_get_int(const OSSL_PARAM *p, int *val) { - if (val == NULL || p == NULL || p->data_type != OSSL_PARAM_INTEGER) - return 0; - - switch (p->data_size) { + switch (sizeof(int)) { case sizeof(int32_t): - if (sizeof(int) >= sizeof(int32_t)) { - *val = (int)*(const int32_t *)p->data; - return 1; - } - break; + return OSSL_PARAM_get_int32(p, (int32_t *)val); case sizeof(int64_t): - if (sizeof(int) >= sizeof(int64_t)) { - *val = (int)*(const int64_t *)p->data; - return 1; - } - break; + return OSSL_PARAM_get_int64(p, (int64_t *)val); } return 0; } int OSSL_PARAM_set_int(const OSSL_PARAM *p, int val) { - if (p == NULL) - return 0; - SET_RETURN_SIZE(p, 0); - if (p->data_type != OSSL_PARAM_INTEGER) - return 0; - - SET_RETURN_SIZE(p, sizeof(int)); /* Minimum expected size */ - switch (p->data_size) { + switch (sizeof(int)) { case sizeof(int32_t): - if (sizeof(int32_t) >= sizeof(int)) { - SET_RETURN_SIZE(p, sizeof(int32_t)); - *(int32_t *)p->data = (int32_t)val; - return 1; - } - break; + return OSSL_PARAM_set_int32(p, (int32_t)val); case sizeof(int64_t): - if (sizeof(int64_t) >= sizeof(int)) { - SET_RETURN_SIZE(p, sizeof(int64_t)); - *(int64_t *)p->data = (int64_t)val; - return 1; - } - break; + return OSSL_PARAM_set_int64(p, (int64_t)val); } return 0; } @@ -97,52 +69,22 @@ OSSL_PARAM OSSL_PARAM_construct_int(const char *key, int *buf, size_t *rsize) int OSSL_PARAM_get_uint(const OSSL_PARAM *p, unsigned int *val) { - if (val == NULL - || p == NULL - || (p->data_type != OSSL_PARAM_UNSIGNED_INTEGER)) - return 0; - - switch (p->data_size) { + switch (sizeof(unsigned int)) { case sizeof(uint32_t): - if (sizeof(unsigned int) >= sizeof(uint32_t)) { - *val = (unsigned int)*(const uint32_t *)p->data; - return 1; - } - break; + return OSSL_PARAM_get_uint32(p, (uint32_t *)val); case sizeof(uint64_t): - if (sizeof(unsigned int) >= sizeof(uint64_t)) { - *val = (unsigned int)*(const uint64_t *)p->data; - return 1; - } - break; + return OSSL_PARAM_get_uint64(p, (uint64_t *)val); } return 0; } int OSSL_PARAM_set_uint(const OSSL_PARAM *p, unsigned int val) { - if (p == NULL) - return 0; - SET_RETURN_SIZE(p, 0); - if (p->data_type != OSSL_PARAM_UNSIGNED_INTEGER) - return 0; - - SET_RETURN_SIZE(p, sizeof(unsigned int)); /* Minimum expected size */ - switch (p->data_size) { + switch (sizeof(unsigned int)) { case sizeof(uint32_t): - if (sizeof(uint32_t) >= sizeof(unsigned int)) { - SET_RETURN_SIZE(p, sizeof(uint32_t)); - *(uint32_t *)p->data = (uint32_t)val; - return 1; - } - break; + return OSSL_PARAM_set_uint32(p, (uint32_t)val); case sizeof(uint64_t): - if (sizeof(uint64_t) >= sizeof(unsigned int)) { - SET_RETURN_SIZE(p, sizeof(uint64_t)); - *(uint64_t *)p->data = (uint64_t)val; - return 1; - } - break; + return OSSL_PARAM_set_uint64(p, (uint64_t)val); } return 0; } @@ -156,49 +98,22 @@ OSSL_PARAM OSSL_PARAM_construct_uint(const char *key, unsigned int *buf, int OSSL_PARAM_get_long(const OSSL_PARAM *p, long int *val) { - if (val == NULL || p == NULL || (p->data_type != OSSL_PARAM_INTEGER)) - return 0; - - switch (p->data_size) { + switch (sizeof(long int)) { case sizeof(int32_t): - if (sizeof(long int) >= sizeof(int32_t)) { - *val = (long int)*(const int32_t *)p->data; - return 1; - } break; + return OSSL_PARAM_get_int32(p, (int32_t *)val); case sizeof(int64_t): - if (sizeof(long int) >= sizeof(int64_t)) { - *val = (long int)*(const int64_t *)p->data; - return 1; - } - break; + return OSSL_PARAM_get_int64(p, (int64_t *)val); } return 0; } int OSSL_PARAM_set_long(const OSSL_PARAM *p, long int val) { - if (p == NULL) - return 0; - SET_RETURN_SIZE(p, 0); - if (p->data_type != OSSL_PARAM_INTEGER) - return 0; - - SET_RETURN_SIZE(p, sizeof(long int)); /* Minimum expected size */ - switch (p->data_size) { + switch (sizeof(long int)) { case sizeof(int32_t): - if (sizeof(int32_t) >= sizeof(long int)) { - SET_RETURN_SIZE(p, sizeof(int32_t)); - *(int32_t *)p->data = (int32_t)val; - return 1; - } - break; + return OSSL_PARAM_set_int32(p, (int32_t)val); case sizeof(int64_t): - if (sizeof(int64_t) >= sizeof(long int)) { - SET_RETURN_SIZE(p, sizeof(int64_t)); - *(int64_t *)p->data = (int64_t)val; - return 1; - } - break; + return OSSL_PARAM_set_int64(p, (int64_t)val); } return 0; } @@ -212,52 +127,22 @@ OSSL_PARAM OSSL_PARAM_construct_long(const char *key, long int *buf, int OSSL_PARAM_get_ulong(const OSSL_PARAM *p, unsigned long int *val) { - if (val == NULL - || p == NULL - || (p->data_type != OSSL_PARAM_UNSIGNED_INTEGER)) - return 0; - - switch (p->data_size) { + switch (sizeof(unsigned long int)) { case sizeof(uint32_t): - if (sizeof(unsigned long int) >= sizeof(uint32_t)) { - *val = (unsigned long int)*(const uint32_t *)p->data; - return 1; - } - break; + return OSSL_PARAM_get_uint32(p, (uint32_t *)val); case sizeof(uint64_t): - if (sizeof(unsigned long int) >= sizeof(uint64_t)) { - *val = (unsigned long int)*(const uint64_t *)p->data; - return 1; - } - break; + return OSSL_PARAM_get_uint64(p, (uint64_t *)val); } return 0; } int OSSL_PARAM_set_ulong(const OSSL_PARAM *p, unsigned long int val) { - if (p == NULL) - return 0; - SET_RETURN_SIZE(p, 0); - if (p->data_type != OSSL_PARAM_UNSIGNED_INTEGER) - return 0; - - SET_RETURN_SIZE(p, sizeof(unsigned long int)); /* Minimum exp size */ - switch (p->data_size) { + switch (sizeof(unsigned long int)) { case sizeof(uint32_t): - if (sizeof(uint32_t) >= sizeof(unsigned long int)) { - SET_RETURN_SIZE(p, sizeof(uint32_t)); - *(uint32_t *)p->data = (uint32_t)val; - return 1; - } - break; + return OSSL_PARAM_set_uint32(p, (uint32_t)val); case sizeof(uint64_t): - if (sizeof(uint64_t) >= sizeof(unsigned long int)) { - SET_RETURN_SIZE(p, sizeof(uint64_t)); - *(uint64_t *)p->data = (uint64_t)val; - return 1; - } - break; + return OSSL_PARAM_set_uint64(p, (uint64_t)val); } return 0; } @@ -437,52 +322,22 @@ OSSL_PARAM OSSL_PARAM_construct_uint64(const char *key, uint64_t *buf, int OSSL_PARAM_get_size_t(const OSSL_PARAM *p, size_t *val) { - if (val == NULL - || p == NULL - || p->data_type != OSSL_PARAM_UNSIGNED_INTEGER) - return 0; - - switch (p->data_size) { + switch (sizeof(size_t)) { case sizeof(uint32_t): - if (sizeof(size_t) >= sizeof(uint32_t)) { - *val = (size_t)*(const uint32_t *)p->data; - return 1; - } - break; + return OSSL_PARAM_get_uint32(p, (uint32_t *)val); case sizeof(uint64_t): - if (sizeof(size_t) >= sizeof(uint64_t)) { - *val = (size_t)*(const uint64_t *)p->data; - return 1; - } - break; + return OSSL_PARAM_get_uint64(p, (uint64_t *)val); } return 0; } int OSSL_PARAM_set_size_t(const OSSL_PARAM *p, size_t val) { - if (p == NULL) - return 0; - SET_RETURN_SIZE(p, 0); - if (p->data_type != OSSL_PARAM_UNSIGNED_INTEGER) - return 0; - - SET_RETURN_SIZE(p, sizeof(size_t)); /* Minimum expected size */ - switch (p->data_size) { + switch (sizeof(size_t)) { case sizeof(uint32_t): - if (sizeof(uint32_t) >= sizeof(size_t)) { - SET_RETURN_SIZE(p, sizeof(uint32_t)); - *(uint32_t *)p->data = (uint32_t)val; - return 1; - } - break; + return OSSL_PARAM_set_uint32(p, (uint32_t)val); case sizeof(uint64_t): - SET_RETURN_SIZE(p, sizeof(uint64_t)); - if (sizeof(uint64_t) >= sizeof(size_t)) { - *(uint64_t *)p->data = (uint64_t)val; - return 1; - } - break; + return OSSL_PARAM_set_uint64(p, (uint64_t)val); } return 0; } diff --git a/crypto/poly1305/asm/poly1305-ia64.S b/crypto/poly1305/asm/poly1305-ia64.S new file mode 100644 index 00000000..54d6454f --- /dev/null +++ b/crypto/poly1305/asm/poly1305-ia64.S @@ -0,0 +1,365 @@ +// ==================================================================== +// Written by Andy Polyakov, @dot-asm, initially for use in the OpenSSL +// project. +// ==================================================================== +// +// Poly1305 for Itanium. +// +// January 2019 +// +// Performance was reported to be ~2.1 cycles per byte on Itanium 2. +// With exception for processors in 95xx family, which have higher +// floating-point instructions' latencies and deliver ~2.6 cpb. +// Comparison to compiler-generated code is not exactly fair, because +// of different radixes. But just for reference, it was observed to be +// >3x faster. Originally it was argued that floating-point base 2^32 +// implementation would be optimal. Upon closer look estimate for below +// integer base 2^64 implementation turned to be approximately same on +// Itanium 2. But floating-point code would be larger, and have higher +// overhead, which would negatively affect small-block performance... + +#if defined(_HPUX_SOURCE) +# if !defined(_LP64) +# define ADDP addp4 +# else +# define ADDP add +# endif +# define RUM rum +# define SUM sum +#else +# define ADDP add +# define RUM nop +# define SUM nop +#endif + +.text +.explicit + +.global poly1305_init# +.proc poly1305_init# +.align 64 +poly1305_init: + .prologue + .save ar.pfs,r2 +{ .mmi; alloc r2=ar.pfs,2,0,0,0 + cmp.eq p6,p7=0,r33 } // key == NULL? +{ .mmi; ADDP r9=8,r32 + ADDP r10=16,r32 + ADDP r32=0,r32 };; + .body +{ .mmi; st8 [r32]=r0,24 // ctx->h0 = 0 + st8 [r9]=r0 // ctx->h1 = 0 +(p7) ADDP r8=0,r33 } +{ .mib; st8 [r10]=r0 // ctx->h2 = 0 +(p6) mov r8=0 +(p6) br.ret.spnt b0 };; + +{ .mmi; ADDP r9=1,r33 + ADDP r10=2,r33 + ADDP r11=3,r33 };; +{ .mmi; ld1 r16=[r8],4 // load key, little-endian + ld1 r17=[r9],4 } +{ .mmi; ld1 r18=[r10],4 + ld1 r19=[r11],4 };; +{ .mmi; ld1 r20=[r8],4 + ld1 r21=[r9],4 } +{ .mmi; ld1 r22=[r10],4 + ld1 r23=[r11],4 + and r19=15,r19 };; +{ .mmi; ld1 r24=[r8],4 + ld1 r25=[r9],4 + and r20=-4,r20 } +{ .mmi; ld1 r26=[r10],4 + ld1 r27=[r11],4 + and r23=15,r23 };; +{ .mmi; ld1 r28=[r8],4 + ld1 r29=[r9],4 + and r24=-4,r24 } +{ .mmi; ld1 r30=[r10],4 + ld1 r31=[r11],4 + and r27=15,r27 };; + +{ .mii; and r28=-4,r28 + dep r16=r17,r16,8,8 + dep r18=r19,r18,8,8 };; +{ .mii; and r31=15,r31 + dep r16=r18,r16,16,16 + dep r20=r21,r20,8,8 };; +{ .mii; dep r16=r20,r16,32,16 + dep r22=r23,r22,8,8 };; +{ .mii; dep r16=r22,r16,48,16 + dep r24=r25,r24,8,8 };; +{ .mii; dep r26=r27,r26,8,8 + dep r28=r29,r28,8,8 };; +{ .mii; dep r24=r26,r24,16,16 + dep r30=r31,r30,8,8 };; +{ .mii; st8 [r32]=r16,8 // ctx->r0 + dep r24=r28,r24,32,16;; + dep r24=r30,r24,48,16 };; +{ .mii; st8 [r32]=r24,8 // ctx->r1 + shr.u r25=r24,2;; + add r25=r25,r24 };; +{ .mib; st8 [r32]=r25 // ctx->s1 + mov r8=0 + br.ret.sptk b0 };; +.endp poly1305_init# + +h0=r17; h1=r18; h2=r19; +i0=r20; i1=r21; +HF0=f8; HF1=f9; HF2=f10; +RF0=f11; RF1=f12; SF1=f13; + +.global poly1305_blocks# +.proc poly1305_blocks# +.align 64 +poly1305_blocks: + .prologue + .save ar.pfs,r2 +{ .mii; alloc r2=ar.pfs,4,1,0,0 + .save ar.lc,r3 + mov r3=ar.lc + .save pr,r36 + mov r36=pr } + + .body +{ .mmi; ADDP r8=0,r32 + ADDP r9=8,r32 + and r29=7,r33 };; +{ .mmi; ld8 h0=[r8],16 + ld8 h1=[r9],16 + and r33=-8,r33 };; +{ .mmi; ld8 h2=[r8],16 + ldf8 RF0=[r9],16 + shr.u r34=r34,4 };; +{ .mmi; ldf8 RF1=[r8],-32 + ldf8 SF1=[r9],-32 + cmp.ltu p16,p17=1,r34 };; +{ .mmi; +(p16) add r34=-2,r34 +(p17) mov r34=0 + ADDP r10=0,r33 } +{ .mii; ADDP r11=8,r33 +(p16) mov ar.ec=2 +(p17) mov ar.ec=1 };; +{ .mib; RUM 1<<1 // go little-endian + mov ar.lc=r34 + brp.loop.imp .Loop,.Lcend-16 } + +{ .mmi; cmp.eq p8,p7=0,r29 + cmp.eq p9,p0=1,r29 + cmp.eq p10,p0=2,r29 } +{ .mmi; cmp.eq p11,p0=3,r29 + cmp.eq p12,p0=4,r29 + cmp.eq p13,p0=5,r29 } +{ .mmi; cmp.eq p14,p0=6,r29 + cmp.eq p15,p0=7,r29 + add r16=16,r10 };; + +{ .mmb; +(p8) ld8 i0=[r10],16 // aligned input +(p8) ld8 i1=[r11],16 +(p8) br.cond.sptk .Loop };; + + // align first block + .pred.rel "mutex",p8,p9,p10,p11,p12,p13,p14,p15 +{ .mmi; (p7) ld8 r14=[r10],24 + (p7) ld8 r15=[r11],24 } + +{ .mii; (p7) ld8 r16=[r16] + nop.i 0;; + (p15) shrp i0=r15,r14,56 } +{ .mii; (p15) shrp i1=r16,r15,56 + (p14) shrp i0=r15,r14,48 } +{ .mii; (p14) shrp i1=r16,r15,48 + (p13) shrp i0=r15,r14,40 } +{ .mii; (p13) shrp i1=r16,r15,40 + (p12) shrp i0=r15,r14,32 } +{ .mii; (p12) shrp i1=r16,r15,32 + (p11) shrp i0=r15,r14,24 } +{ .mii; (p11) shrp i1=r16,r15,24 + (p10) shrp i0=r15,r14,16 } +{ .mii; (p10) shrp i1=r16,r15,16 + (p9) shrp i0=r15,r14,8 } +{ .mii; (p9) shrp i1=r16,r15,8 + mov r14=r16 };; + +.Loop: + .pred.rel "mutex",p8,p9,p10,p11,p12,p13,p14,p15 +{ .mmi; add h0=h0,i0 + add h1=h1,i1 + add h2=h2,r35 };; +{ .mmi; setf.sig HF0=h0 + cmp.ltu p6,p0=h0,i0 + cmp.ltu p7,p0=h1,i1 };; +{ .mmi; (p6) add h1=1,h1;; + setf.sig HF1=h1 + (p6) cmp.eq.or p7,p0=0,h1 };; +{ .mmi; (p7) add h2=1,h2;; + setf.sig HF2=h2 };; + +{ .mfi; (p16) ld8 r15=[r10],16 + xmpy.lu f32=HF0,RF0 } +{ .mfi; (p16) ld8 r16=[r11],16 + xmpy.hu f33=HF0,RF0 } +{ .mfi; xmpy.lu f36=HF0,RF1 } +{ .mfi; xmpy.hu f37=HF0,RF1 };; +{ .mfi; xmpy.lu f34=HF1,SF1 + (p15) shrp i0=r15,r14,56 } +{ .mfi; xmpy.hu f35=HF1,SF1 } +{ .mfi; xmpy.lu f38=HF1,RF0 + (p15) shrp i1=r16,r15,56 } +{ .mfi; xmpy.hu f39=HF1,RF0 } +{ .mfi; xmpy.lu f40=HF2,SF1 + (p14) shrp i0=r15,r14,48 } +{ .mfi; xmpy.lu f41=HF2,RF0 };; + +{ .mmi; getf.sig r22=f32 + getf.sig r23=f33 + (p14) shrp i1=r16,r15,48 } +{ .mmi; getf.sig r24=f34 + getf.sig r25=f35 + (p13) shrp i0=r15,r14,40 } +{ .mmi; getf.sig r26=f36 + getf.sig r27=f37 + (p13) shrp i1=r16,r15,40 } +{ .mmi; getf.sig r28=f38 + getf.sig r29=f39 + (p12) shrp i0=r15,r14,32 } +{ .mmi; getf.sig r30=f40 + getf.sig r31=f41 };; + +{ .mmi; add h0=r22,r24 + add r23=r23,r25 + (p12) shrp i1=r16,r15,32 } +{ .mmi; add h1=r26,r28 + add r27=r27,r29 + (p11) shrp i0=r15,r14,24 };; +{ .mmi; cmp.ltu p6,p0=h0,r24 + cmp.ltu p7,p0=h1,r28 + add r23=r23,r30 };; +{ .mmi; (p6) add r23=1,r23 + (p7) add r27=1,r27 + (p11) shrp i1=r16,r15,24 };; +{ .mmi; add h1=h1,r23;; + cmp.ltu p6,p7=h1,r23 + (p10) shrp i0=r15,r14,16 };; +{ .mmi; (p6) add h2=r31,r27,1 + (p7) add h2=r31,r27 + (p10) shrp i1=r16,r15,16 };; + +{ .mmi; (p8) mov i0=r15 + and r22=-4,h2 + shr.u r23=h2,2 };; +{ .mmi; add r22=r22,r23 + and h2=3,h2 + (p9) shrp i0=r15,r14,8 };; + +{ .mmi; add h0=h0,r22;; + cmp.ltu p6,p0=h0,r22 + (p9) shrp i1=r16,r15,8 };; +{ .mmi; (p8) mov i1=r16 + (p6) cmp.eq.unc p7,p0=-1,h1 + (p6) add h1=1,h1 };; +{ .mmb; (p7) add h2=1,h2 + mov r14=r16 + br.ctop.sptk .Loop };; +.Lcend: + +{ .mii; SUM 1<<1 // back to big-endian + mov ar.lc=r3 };; + +{ .mmi; st8 [r8]=h0,16 + st8 [r9]=h1 + mov pr=r36,0x1ffff };; +{ .mmb; st8 [r8]=h2 + rum 1<<5 + br.ret.sptk b0 };; +.endp poly1305_blocks# + +.global poly1305_emit# +.proc poly1305_emit# +.align 64 +poly1305_emit: + .prologue + .save ar.pfs,r2 +{ .mmi; alloc r2=ar.pfs,3,0,0,0 + ADDP r8=0,r32 + ADDP r9=8,r32 };; + + .body +{ .mmi; ld8 r16=[r8],16 // load hash + ld8 r17=[r9] + ADDP r10=0,r34 };; +{ .mmi; ld8 r18=[r8] + ld4 r24=[r10],8 // load nonce + ADDP r11=4,r34 };; + +{ .mmi; ld4 r25=[r11],8 + ld4 r26=[r10] + add r20=5,r16 };; + +{ .mmi; ld4 r27=[r11] + cmp.ltu p6,p7=r20,r16 + shl r25=r25,32 };; +{ .mmi; +(p6) add r21=1,r17 +(p7) add r21=0,r17 +(p6) cmp.eq.or.andcm p6,p7=-1,r17 };; +{ .mmi; +(p6) add r22=1,r18 +(p7) add r22=0,r18 + shl r27=r27,32 };; +{ .mmi; or r24=r24,r25 + or r26=r26,r27 + cmp.leu p6,p7=4,r22 };; +{ .mmi; +(p6) add r16=r20,r24 +(p7) add r16=r16,r24 +(p6) add r17=r21,r26 };; +{ .mii; +(p7) add r17=r17,r26 + cmp.ltu p6,p7=r16,r24;; +(p6) add r17=1,r17 };; + +{ .mmi; ADDP r8=0,r33 + ADDP r9=4,r33 + shr.u r20=r16,32 } +{ .mmi; ADDP r10=8,r33 + ADDP r11=12,r33 + shr.u r21=r17,32 };; + +{ .mmi; st1 [r8]=r16,1 // write mac, little-endian + st1 [r9]=r20,1 + shr.u r16=r16,8 } +{ .mii; st1 [r10]=r17,1 + shr.u r20=r20,8 + shr.u r17=r17,8 } +{ .mmi; st1 [r11]=r21,1 + shr.u r21=r21,8 };; + +{ .mmi; st1 [r8]=r16,1 + st1 [r9]=r20,1 + shr.u r16=r16,8 } +{ .mii; st1 [r10]=r17,1 + shr.u r20=r20,8 + shr.u r17=r17,8 } +{ .mmi; st1 [r11]=r21,1 + shr.u r21=r21,8 };; + +{ .mmi; st1 [r8]=r16,1 + st1 [r9]=r20,1 + shr.u r16=r16,8 } +{ .mii; st1 [r10]=r17,1 + shr.u r20=r20,8 + shr.u r17=r17,8 } +{ .mmi; st1 [r11]=r21,1 + shr.u r21=r21,8 };; + +{ .mmi; st1 [r8]=r16 + st1 [r9]=r20 } +{ .mmb; st1 [r10]=r17 + st1 [r11]=r21 + br.ret.sptk b0 };; +.endp poly1305_emit# + +stringz "Poly1305 for IA64, CRYPTOGAMS by \@dot-asm" diff --git a/crypto/poly1305/asm/poly1305-s390x.pl b/crypto/poly1305/asm/poly1305-s390x.pl index 390f9eef..ea1c2d82 100755 --- a/crypto/poly1305/asm/poly1305-s390x.pl +++ b/crypto/poly1305/asm/poly1305-s390x.pl @@ -32,10 +32,20 @@ # Copyright IBM Corp. 2019 # Author: Patrick Steuer +# +# January 2019 +# +# Add vector base 2^26 implementation. It's problematic to accurately +# measure performance, because reference system is hardly idle. But +# it's sub-cycle, i.e. less than 1 cycle per processed byte, and it's +# >=20% faster than IBM's submission on long inputs, and much faster on +# short ones, because calculation of key powers is postponed till we +# know that input is long enough to justify the additional overhead. + use strict; use FindBin qw($Bin); use lib "$Bin/../.."; -use perlasm::s390x qw(:DEFAULT :VX AUTOLOAD LABEL); +use perlasm::s390x qw(:DEFAULT :VX AUTOLOAD LABEL INCLUDE); my $flavour = shift; @@ -51,666 +61,98 @@ if ($flavour =~ /3[12]/) { my $output; while (($output=shift) && ($output!~/\w[\w\-]*\.\w+$/)) {} +my $stdframe=16*$SIZE_T+4*8; my $sp="%r15"; -# novx code path ctx layout -# --------------------------------- -# var value base off -# --------------------------------- -# u64 h[3] hash 2^64 0 -# u32 pad[2] -# u64 r[2] key 2^64 32 - -# vx code path ctx layout -# --------------------------------- -# var value base off -# --------------------------------- -# u32 acc1[5] r^2-acc 2^26 0 -# u32 pad -# u32 acc2[5] r-acc 2^26 24 -# u32 pad -# u32 r1[5] r 2^26 48 -# u32 r15[5] 5*r 2^26 68 -# u32 r2[5] r^2 2^26 88 -# u32 r25[5] 5*r^2 2^26 108 -# u32 r4[5] r^4 2^26 128 -# u32 r45[5] 5*r^4 2^26 148 +my ($ctx,$inp,$len,$padbit) = map("%r$_",(2..5)); PERLASM_BEGIN($output); +INCLUDE ("s390x_arch.h"); TEXT (); ################ # static void poly1305_init(void *ctx, const unsigned char key[16]) { -my ($ctx,$key)=map("%r$_",(2..3)); -my ($r0,$r1,$r2)=map("%r$_",(9,11,13)); - -sub MUL_RKEY { # r*=key -my ($d0hi,$d0lo,$d1hi,$d1lo)=map("%r$_",(4..7)); -my ($t0,$t1,$s1)=map("%r$_",(8,10,12)); - - lg ("%r0","32($ctx)"); - lg ("%r1","40($ctx)"); - - srlg ($s1,"%r1",2); - algr ($s1,"%r1"); - - lgr ($d0lo,$r0); - lgr ($d1lo,$r1); - - mlgr ($d0hi,"%r0"); - lgr ($r1,$d1lo); - mlgr ($d1hi,$s1); - - mlgr ($t0,"%r1"); - mlgr ($t1,"%r0"); - - algr ($d0lo,$d1lo); - lgr ($d1lo,$r2); - alcgr ($d0hi,$d1hi); - lghi ($d1hi,0); - - algr ($r1,$r0); - alcgr ($t1,$t0); - - msgr ($d1lo,$s1); - msgr ($r2,"%r0"); - - algr ($r1,$d1lo); - alcgr ($t1,$d1hi); - - algr ($r1,$d0hi); - alcgr ($r2,$t1); - - lghi ($r0,-4); - ngr ($r0,$r2); - srlg ($t0,$r2,2); - algr ($r0,$t0); - lghi ($t1,3); - ngr ($r2,$t1); - - algr ($r0,$d0lo); - alcgr ($r1,$d1hi); - alcgr ($r2,$d1hi); -} - -sub ST_R5R { # store r,5*r -> base 2^26 -my @d=map("%r$_",(4..8)); -my @off=@_; - - lgr (@d[2],$r0); - lr ("%r1",@d[2]); - nilh ("%r1",1023); - lgr (@d[3],$r1); - lr (@d[0],"%r1"); - srlg ("%r1",@d[2],52); - lgr (@d[4],$r2); - srlg ("%r0",@d[2],26); - sll (@d[4],24); - lr (@d[2],@d[3]); - nilh ("%r0",1023); - sll (@d[2],12); - lr (@d[1],"%r0"); - &or (@d[2],"%r1"); - srlg ("%r1",@d[3],40); - nilh (@d[2],1023); - &or (@d[4],"%r1"); - srlg (@d[3],@d[3],14); - nilh (@d[4],1023); - nilh (@d[3],1023); - - stm (@d[0],@d[4],"@off[0]($ctx)"); - mhi (@d[$_],5) for (0..4); - stm (@d[0],@d[4],"@off[1]($ctx)"); -} - GLOBL ("poly1305_init"); TYPE ("poly1305_init","\@function"); ALIGN (16); LABEL ("poly1305_init"); lghi ("%r0",0); lghi ("%r1",-1); - stg ("%r0","0($ctx)"); # zero hash value / acc1 + stg ("%r0","0($ctx)"); # zero hash value stg ("%r0","8($ctx)"); stg ("%r0","16($ctx)"); + st ("%r0","24($ctx)"); # clear is_base2_26 + lgr ("%r5",$ctx); # reassign $ctx + lghi ("%r2",0); -&{$z? \&clgr:\&clr} ($key,"%r0"); - je (".Ldone"); +&{$z? \&clgr:\&clr} ($inp,"%r0"); + je (".Lno_key"); - lrvg ("%r4","0($key)"); # load little-endian key - lrvg ("%r5","8($key)"); + lrvg ("%r2","0($inp)"); # load little-endian key + lrvg ("%r3","8($inp)"); - nihl ("%r1",0xffc0); # 0xffffffc0ffffffff - srlg ("%r0","%r1",4); # 0x0ffffffc0fffffff + nihl ("%r1",0xffc0); # 0xffffffc0ffffffff + srlg ("%r0","%r1",4); # 0x0ffffffc0fffffff srlg ("%r1","%r1",4); - nill ("%r1",0xfffc); # 0x0ffffffc0ffffffc + nill ("%r1",0xfffc); # 0x0ffffffc0ffffffc - ngr ("%r4","%r0"); - ngr ("%r5","%r1"); + ngr ("%r2","%r0"); + ngr ("%r3","%r1"); - stg ("%r4","32($ctx)"); - stg ("%r5","40($ctx)"); + stmg ("%r2","%r3","32(%r5)"); larl ("%r1","OPENSSL_s390xcap_P"); lg ("%r0","16(%r1)"); - tmhh ("%r0",0x4000); # check for vector facility - jz (".Ldone"); - - larl ("%r4","poly1305_blocks_vx"); - larl ("%r5","poly1305_emit_vx"); - -&{$z? \&stmg:\&stm} ("%r6","%r13","6*$SIZE_T($sp)"); -&{$z? \&stmg:\&stm} ("%r4","%r5","4*$z+228($ctx)"); - - lg ($r0,"32($ctx)"); - lg ($r1,"40($ctx)"); - lghi ($r2,0); - - ST_R5R (48,68); # store r,5*r - - MUL_RKEY(); - ST_R5R (88,108); # store r^2,5*r^2 - - MUL_RKEY(); - MUL_RKEY(); - ST_R5R (128,148); # store r^4,5*r^4 - - lghi ("%r0",0); - stg ("%r0","24($ctx)"); # zero acc2 - stg ("%r0","32($ctx)"); - stg ("%r0","40($ctx)"); - -&{$z? \&lmg:\&lm} ("%r6","%r13","6*$SIZE_T($sp)"); + srlg ("%r0","%r0",62); + nill ("%r0",1); # extract vx bit + lcgr ("%r0","%r0"); + larl ("%r1",".Lpoly1305_blocks"); + larl ("%r2",".Lpoly1305_blocks_vx"); + larl ("%r3",".Lpoly1305_emit"); +&{$z? \&xgr:\&xr} ("%r2","%r1"); # select between scalar and vector +&{$z? \&ngr:\&nr} ("%r2","%r0"); +&{$z? \&xgr:\&xr} ("%r2","%r1"); +&{$z? \&stmg:\&stm} ("%r2","%r3","0(%r4)"); lghi ("%r2",1); - br ("%r14"); - -LABEL (".Ldone"); - lghi ("%r2",0); +LABEL (".Lno_key"); br ("%r14"); SIZE ("poly1305_init",".-poly1305_init"); } -# VX CODE PATH -{ -my $frame=8*16; -my @m01=map("%v$_",(0..4)); -my @m23=map("%v$_",(5..9)); -my @tmp=@m23; -my @acc=map("%v$_",(10..14)); -my @r=map("%v$_",(15..19)); -my @r5=map("%v$_",(20..24)); -my $padvec="%v26"; -my $mask4="%v27"; -my @vperm=map("%v$_",(28..30)); -my $mask="%v31"; - -sub REDUCE { - vesrlg (@tmp[0],@acc[0],26); - vesrlg (@tmp[3],@acc[3],26); - vn (@acc[0],@acc[0],$mask); - vn (@acc[3],@acc[3],$mask); - vag (@acc[1],@acc[1],@tmp[0]); # carry 0->1 - vag (@acc[4],@acc[4],@tmp[3]); # carry 3->4 - - vesrlg (@tmp[1],@acc[1],26); - vesrlg (@tmp[4],@acc[4],26); - vn (@acc[1],@acc[1],$mask); - vn (@acc[4],@acc[4],$mask); - veslg (@tmp[0],@tmp[4],2); - vag (@tmp[4],@tmp[4],@tmp[0]); # h[4]*=5 - vag (@acc[2],@acc[2],@tmp[1]); # carry 1->2 - vag (@acc[0],@acc[0],@tmp[4]); # carry 4->0 - - vesrlg (@tmp[2],@acc[2],26); - vesrlg (@tmp[0],@acc[0],26); - vn (@acc[2],@acc[2],$mask); - vn (@acc[0],@acc[0],$mask); - vag (@acc[3],@acc[3],@tmp[2]); # carry 2->3 - vag (@acc[1],@acc[1],@tmp[0]); # carry 0->1 - - vesrlg (@tmp[3],@acc[3],26); - vn (@acc[3],@acc[3],$mask); - vag (@acc[4],@acc[4],@tmp[3]); # carry 3->4 -} - ################ -# static void poly1305_blocks_vx(void *ctx, const unsigned char *inp, -# size_t len, u32 padbit) +# static void poly1305_blocks(void *ctx, const unsigned char *inp, +# size_t len, u32 padbit) { -my ($ctx,$inp,$len) = map("%r$_",(2..4)); -my $padbit="%r0"; - -GLOBL ("poly1305_blocks_vx"); -TYPE ("poly1305_blocks_vx","\@function"); -ALIGN (16); -LABEL ("poly1305_blocks_vx"); -if ($z) { - aghi ($sp,-$frame); - vstm ("%v8","%v15","0($sp)"); -} else { - std ("%f4","16*$SIZE_T+2*8($sp)"); - std ("%f6","16*$SIZE_T+3*8($sp)"); - llgfr ($len,$len); -} - llgfr ($padbit,"%r5"); - vlef (@acc[$_],"4*$_($ctx)",1) for (0..4); # load acc1 - larl ("%r5",".Lconst"); - vlef (@acc[$_],"24+4*$_($ctx)",3) for (0..4); # load acc2 - sllg ($padbit,$padbit,24); - vlm (@vperm[0],$mask,"0(%r5)"); # load vperm ops, mask - vgbm ($mask4,0x0707); - vlvgp ($padvec,$padbit,$padbit); - - srlg ("%r1",$len,6); - ltgr ("%r1","%r1"); - jz (".Lvx_4x_done"); - -ALIGN (16); -LABEL (".Lvx_4x"); - vlm ("%v20","%v23","0($inp)"); # load m0,m1,m2,m3 - - # m01,m23 -> base 2^26 - - vperm (@m01[0],"%v20","%v21",@vperm[0]); - vperm (@m23[0],"%v22","%v23",@vperm[0]); - vperm (@m01[2],"%v20","%v21",@vperm[1]); - vperm (@m23[2],"%v22","%v23",@vperm[1]); - vperm (@m01[4],"%v20","%v21",@vperm[2]); - vperm (@m23[4],"%v22","%v23",@vperm[2]); - - vesrlg (@m01[1],@m01[0],26); - vesrlg (@m23[1],@m23[0],26); - vesrlg (@m01[3],@m01[2],30); - vesrlg (@m23[3],@m23[2],30); - vesrlg (@m01[2],@m01[2],4); - vesrlg (@m23[2],@m23[2],4); - - vn (@m01[4],@m01[4],$mask4); - vn (@m23[4],@m23[4],$mask4); -for (0..3) { - vn (@m01[$_],@m01[$_],$mask); - vn (@m23[$_],@m23[$_],$mask); -} - vaf (@m01[4],@m01[4],$padvec); # pad m01 - vaf (@m23[4],@m23[4],$padvec); # pad m23 - - # acc = acc * r^4 + m01 * r^2 + m23 - - vlrepf (@r5[$_],"4*$_+108($ctx)") for (0..4); # load 5*r^2 - vlrepf (@r[$_],"4*$_+88($ctx)") for (0..4); # load r^2 - - vmalof (@tmp[0],@m01[4],@r5[1],@m23[0]); - vmalof (@tmp[1],@m01[4],@r5[2],@m23[1]); - vmalof (@tmp[2],@m01[4],@r5[3],@m23[2]); - vmalof (@tmp[3],@m01[4],@r5[4],@m23[3]); - vmalof (@tmp[4],@m01[4],@r[0],@m23[4]); - - vmalof (@tmp[0],@m01[3],@r5[2],@tmp[0]); - vmalof (@tmp[1],@m01[3],@r5[3],@tmp[1]); - vmalof (@tmp[2],@m01[3],@r5[4],@tmp[2]); - vmalof (@tmp[3],@m01[3],@r[0],@tmp[3]); - vmalof (@tmp[4],@m01[3],@r[1],@tmp[4]); - - vmalof (@tmp[0],@m01[2],@r5[3],@tmp[0]); - vmalof (@tmp[1],@m01[2],@r5[4],@tmp[1]); - vmalof (@tmp[2],@m01[2],@r[0],@tmp[2]); - vmalof (@tmp[3],@m01[2],@r[1],@tmp[3]); - vmalof (@tmp[4],@m01[2],@r[2],@tmp[4]); - - vmalof (@tmp[0],@m01[1],@r5[4],@tmp[0]); - vmalof (@tmp[1],@m01[1],@r[0],@tmp[1]); - vmalof (@tmp[2],@m01[1],@r[1],@tmp[2]); - vmalof (@tmp[3],@m01[1],@r[2],@tmp[3]); - vmalof (@tmp[4],@m01[1],@r[3],@tmp[4]); - - vmalof (@tmp[0],@m01[0],@r[0],@tmp[0]); - vmalof (@tmp[1],@m01[0],@r[1],@tmp[1]); - vmalof (@tmp[2],@m01[0],@r[2],@tmp[2]); - vmalof (@tmp[3],@m01[0],@r[3],@tmp[3]); - vmalof (@tmp[4],@m01[0],@r[4],@tmp[4]); - - vlrepf (@r5[$_],"4*$_+148($ctx)") for (0..4); # load 5*r^4 - vlrepf (@r[$_],"4*$_+128($ctx)") for (0..4); # load r^4 - - vmalof (@tmp[0],@acc[4],@r5[1],@tmp[0]); - vmalof (@tmp[1],@acc[4],@r5[2],@tmp[1]); - vmalof (@tmp[2],@acc[4],@r5[3],@tmp[2]); - vmalof (@tmp[3],@acc[4],@r5[4],@tmp[3]); - vmalof (@tmp[4],@acc[4],@r[0],@tmp[4]); - - vmalof (@tmp[0],@acc[3],@r5[2],@tmp[0]); - vmalof (@tmp[1],@acc[3],@r5[3],@tmp[1]); - vmalof (@tmp[2],@acc[3],@r5[4],@tmp[2]); - vmalof (@tmp[3],@acc[3],@r[0],@tmp[3]); - vmalof (@tmp[4],@acc[3],@r[1],@tmp[4]); - - vmalof (@tmp[0],@acc[2],@r5[3],@tmp[0]); - vmalof (@tmp[1],@acc[2],@r5[4],@tmp[1]); - vmalof (@tmp[2],@acc[2],@r[0],@tmp[2]); - vmalof (@tmp[3],@acc[2],@r[1],@tmp[3]); - vmalof (@tmp[4],@acc[2],@r[2],@tmp[4]); - - vmalof (@tmp[0],@acc[1],@r5[4],@tmp[0]); - vmalof (@tmp[1],@acc[1],@r[0],@tmp[1]); - vmalof (@tmp[2],@acc[1],@r[1],@tmp[2]); - vmalof (@tmp[3],@acc[1],@r[2],@tmp[3]); - vmalof (@tmp[4],@acc[1],@r[3],@tmp[4]); - - vmalof (@acc[1],@acc[0],@r[1],@tmp[1]); - vmalof (@acc[2],@acc[0],@r[2],@tmp[2]); - vmalof (@acc[3],@acc[0],@r[3],@tmp[3]); - vmalof (@acc[4],@acc[0],@r[4],@tmp[4]); - vmalof (@acc[0],@acc[0],@r[0],@tmp[0]); - - REDUCE (); - - la ($inp,"64($inp)"); - brctg ("%r1",".Lvx_4x"); - -ALIGN (16); -LABEL (".Lvx_4x_done"); - tml ($len,32); - jz (".Lvx_2x_done"); - - vlm ("%v20","%v21","0($inp)"); # load m0,m1 - - # m01 -> base 2^26 - - vperm (@m01[0],"%v20","%v21",@vperm[0]); - vperm (@m01[2],"%v20","%v21",@vperm[1]); - vperm (@m01[4],"%v20","%v21",@vperm[2]); - - vesrlg (@m01[1],@m01[0],26); - vesrlg (@m01[3],@m01[2],30); - vesrlg (@m01[2],@m01[2],4); - - vn (@m01[4],@m01[4],$mask4); - vn (@m01[$_],@m01[$_],$mask) for (0..3); - - vaf (@m01[4],@m01[4],$padvec); # pad m01 - - # acc = acc * r^2+ m01 - - vlrepf (@r5[$_],"4*$_+108($ctx)") for (0..4); # load 5*r^2 - vlrepf (@r[$_],"4*$_+88($ctx)") for (0..4); # load r^2 - - vmalof (@tmp[0],@acc[4],@r5[1],@m01[0]); - vmalof (@tmp[1],@acc[4],@r5[2],@m01[1]); - vmalof (@tmp[2],@acc[4],@r5[3],@m01[2]); - vmalof (@tmp[3],@acc[4],@r5[4],@m01[3]); - vmalof (@tmp[4],@acc[4],@r[0],@m01[4]); - - vmalof (@tmp[0],@acc[3],@r5[2],@tmp[0]); - vmalof (@tmp[1],@acc[3],@r5[3],@tmp[1]); - vmalof (@tmp[2],@acc[3],@r5[4],@tmp[2]); - vmalof (@tmp[3],@acc[3],@r[0],@tmp[3]); - vmalof (@tmp[4],@acc[3],@r[1],@tmp[4]); - - vmalof (@tmp[0],@acc[2],@r5[3],@tmp[0]); - vmalof (@tmp[1],@acc[2],@r5[4],@tmp[1]); - vmalof (@tmp[2],@acc[2],@r[0],@tmp[2]); - vmalof (@tmp[3],@acc[2],@r[1],@tmp[3]); - vmalof (@tmp[4],@acc[2],@r[2],@tmp[4]); - - vmalof (@tmp[0],@acc[1],@r5[4],@tmp[0]); - vmalof (@tmp[1],@acc[1],@r[0],@tmp[1]); - vmalof (@tmp[2],@acc[1],@r[1],@tmp[2]); - vmalof (@tmp[3],@acc[1],@r[2],@tmp[3]); - vmalof (@tmp[4],@acc[1],@r[3],@tmp[4]); - - vmalof (@acc[1],@acc[0],@r[1],@tmp[1]); - vmalof (@acc[2],@acc[0],@r[2],@tmp[2]); - vmalof (@acc[3],@acc[0],@r[3],@tmp[3]); - vmalof (@acc[4],@acc[0],@r[4],@tmp[4]); - vmalof (@acc[0],@acc[0],@r[0],@tmp[0]); - - REDUCE (); - - la ($inp,"32($inp)"); - -ALIGN (16); -LABEL (".Lvx_2x_done"); - tml ($len,16); - jz (".Lvx_done"); - - vleig ($padvec,0,0); - - vzero ("%v20"); - vl ("%v21","0($inp)"); # load m0 - - # m0 -> base 2^26 - - vperm (@m01[0],"%v20","%v21",@vperm[0]); - vperm (@m01[2],"%v20","%v21",@vperm[1]); - vperm (@m01[4],"%v20","%v21",@vperm[2]); - - vesrlg (@m01[1],@m01[0],26); - vesrlg (@m01[3],@m01[2],30); - vesrlg (@m01[2],@m01[2],4); - - vn (@m01[4],@m01[4],$mask4); - vn (@m01[$_],@m01[$_],$mask) for (0..3); - - vaf (@m01[4],@m01[4],$padvec); # pad m0 - - # acc = acc * r + m01 - - vlrepf (@r5[$_],"4*$_+68($ctx)") for (0..4); # load 5*r - vlrepf (@r[$_],"4*$_+48($ctx)") for (0..4); # load r - - vmalof (@tmp[0],@acc[4],@r5[1],@m01[0]); - vmalof (@tmp[1],@acc[4],@r5[2],@m01[1]); - vmalof (@tmp[2],@acc[4],@r5[3],@m01[2]); - vmalof (@tmp[3],@acc[4],@r5[4],@m01[3]); - vmalof (@tmp[4],@acc[4],@r[0],@m01[4]); - - vmalof (@tmp[0],@acc[3],@r5[2],@tmp[0]); - vmalof (@tmp[1],@acc[3],@r5[3],@tmp[1]); - vmalof (@tmp[2],@acc[3],@r5[4],@tmp[2]); - vmalof (@tmp[3],@acc[3],@r[0],@tmp[3]); - vmalof (@tmp[4],@acc[3],@r[1],@tmp[4]); - - vmalof (@tmp[0],@acc[2],@r5[3],@tmp[0]); - vmalof (@tmp[1],@acc[2],@r5[4],@tmp[1]); - vmalof (@tmp[2],@acc[2],@r[0],@tmp[2]); - vmalof (@tmp[3],@acc[2],@r[1],@tmp[3]); - vmalof (@tmp[4],@acc[2],@r[2],@tmp[4]); - - vmalof (@tmp[0],@acc[1],@r5[4],@tmp[0]); - vmalof (@tmp[1],@acc[1],@r[0],@tmp[1]); - vmalof (@tmp[2],@acc[1],@r[1],@tmp[2]); - vmalof (@tmp[3],@acc[1],@r[2],@tmp[3]); - vmalof (@tmp[4],@acc[1],@r[3],@tmp[4]); - - vmalof (@acc[1],@acc[0],@r[1],@tmp[1]); - vmalof (@acc[2],@acc[0],@r[2],@tmp[2]); - vmalof (@acc[3],@acc[0],@r[3],@tmp[3]); - vmalof (@acc[4],@acc[0],@r[4],@tmp[4]); - vmalof (@acc[0],@acc[0],@r[0],@tmp[0]); - - REDUCE (); - -ALIGN (16); -LABEL (".Lvx_done"); - vstef (@acc[$_],"4*$_($ctx)",1) for (0..4); # store acc - vstef (@acc[$_],"24+4*$_($ctx)",3) for (0..4); - -if ($z) { - vlm ("%v8","%v15","0($sp)"); - la ($sp,"$frame($sp)"); -} else { - ld ("%f4","16*$SIZE_T+2*8($sp)"); - ld ("%f6","16*$SIZE_T+3*8($sp)"); -} - br ("%r14"); -SIZE ("poly1305_blocks_vx",".-poly1305_blocks_vx"); -} - -################ -# static void poly1305_emit_vx(void *ctx, unsigned char mac[16], -# const u32 nonce[4]) -{ -my ($ctx,$mac,$nonce) = map("%r$_",(2..4)); - -GLOBL ("poly1305_emit_vx"); -TYPE ("poly1305_emit_vx","\@function"); -ALIGN (16); -LABEL ("poly1305_emit_vx"); -if ($z) { - aghi ($sp,-$frame); - vstm ("%v8","%v15","0($sp)"); -} else { - std ("%f4","16*$SIZE_T+2*8($sp)"); - std ("%f6","16*$SIZE_T+3*8($sp)"); -} - larl ("%r5",".Lconst"); - - vlef (@acc[$_],"4*$_($ctx)",1) for (0..4); # load acc1 - vlef (@acc[$_],"24+4*$_($ctx)",3) for (0..4); # load acc2 - vlef (@r5[$_],"108+4*$_($ctx)",1) for (0..4); # load 5*r^2 - vlef (@r[$_],"88+4*$_($ctx)",1) for (0..4); # load r^2 - vlef (@r5[$_],"68+4*$_($ctx)",3) for (0..4); # load 5*r - vlef (@r[$_],"48+4*$_($ctx)",3) for (0..4); # load r - vl ($mask,"48(%r5)"); # load mask - - # acc = acc1 * r^2 + acc2 * r - - vmlof (@tmp[0],@acc[4],@r5[1]); - vmlof (@tmp[1],@acc[4],@r5[2]); - vmlof (@tmp[2],@acc[4],@r5[3]); - vmlof (@tmp[3],@acc[4],@r5[4]); - vmlof (@tmp[4],@acc[4],@r[0]); - - vmalof (@tmp[0],@acc[3],@r5[2],@tmp[0]); - vmalof (@tmp[1],@acc[3],@r5[3],@tmp[1]); - vmalof (@tmp[2],@acc[3],@r5[4],@tmp[2]); - vmalof (@tmp[3],@acc[3],@r[0],@tmp[3]); - vmalof (@tmp[4],@acc[3],@r[1],@tmp[4]); - - vmalof (@tmp[0],@acc[2],@r5[3],@tmp[0]); - vmalof (@tmp[1],@acc[2],@r5[4],@tmp[1]); - vmalof (@tmp[2],@acc[2],@r[0],@tmp[2]); - vmalof (@tmp[3],@acc[2],@r[1],@tmp[3]); - vmalof (@tmp[4],@acc[2],@r[2],@tmp[4]); - - vmalof (@tmp[0],@acc[1],@r5[4],@tmp[0]); - vmalof (@tmp[1],@acc[1],@r[0],@tmp[1]); - vmalof (@tmp[2],@acc[1],@r[1],@tmp[2]); - vmalof (@tmp[3],@acc[1],@r[2],@tmp[3]); - vmalof (@tmp[4],@acc[1],@r[3],@tmp[4]); - - vmalof (@acc[1],@acc[0],@r[1],@tmp[1]); - vmalof (@acc[2],@acc[0],@r[2],@tmp[2]); - vmalof (@acc[3],@acc[0],@r[3],@tmp[3]); - vmalof (@acc[4],@acc[0],@r[4],@tmp[4]); - vmalof (@acc[0],@acc[0],@r[0],@tmp[0]); - - vzero ("%v27"); - vsumqg (@acc[$_],@acc[$_],"%v27") for (0..4); - - REDUCE (); - - vesrlg (@tmp[1],@acc[1],26); - vn (@acc[1],@acc[1],$mask); - vag (@acc[2],@acc[2],@tmp[1]); # carry 1->2 - - vesrlg (@tmp[2],@acc[2],26); - vn (@acc[2],@acc[2],$mask); - vag (@acc[3],@acc[3],@tmp[2]); # carry 2->3 - - vesrlg (@tmp[3],@acc[3],26); - vn (@acc[3],@acc[3],$mask); - vag (@acc[4],@acc[4],@tmp[3]); # carry 3->4 - - # acc -> base 2^64 - vleib ("%v30",6*8,7); - vleib ("%v29",13*8,7); - vleib ("%v28",3*8,7); - - veslg (@acc[1],@acc[1],26); - veslg (@acc[3],@acc[3],26); - vo (@acc[0],@acc[0],@acc[1]); - vo (@acc[2],@acc[2],@acc[3]); - - veslg (@acc[2],@acc[2],4); - vslb (@acc[2],@acc[2],"%v30"); # <<52 - vo (@acc[0],@acc[0],@acc[2]); - - vslb (@tmp[4],@acc[4],"%v29"); # <<104 - vo (@acc[0],@acc[0],@tmp[4]); - - vsrlb (@acc[1],@acc[4],"%v28"); # >>24 - - # acc %= 2^130-5 - vone ("%v26"); - vleig ("%v27",5,1); - vone ("%v29"); - vleig ("%v26",-4,1); - - vaq (@tmp[0],@acc[0],"%v27"); - vaccq (@tmp[1],@acc[0],"%v27"); - - vaq (@tmp[1],@tmp[1],"%v26"); - vaccq (@tmp[1],@tmp[1],@acc[1]); - - vaq (@tmp[1],@tmp[1],"%v29"); - - vn (@tmp[2],@tmp[1],@acc[0]); - vnc (@tmp[3],@tmp[0],@tmp[1]); - vo (@acc[0],@tmp[2],@tmp[3]); - - # acc += nonce - vl (@vperm[0],"64(%r5)"); - vlef (@tmp[0],"4*$_($nonce)",3-$_) for (0..3); - - vaq (@acc[0],@acc[0],@tmp[0]); - - vperm (@acc[0],@acc[0],@acc[0],@vperm[0]); - vst (@acc[0],"0($mac)"); # store mac - -if ($z) { - vlm ("%v8","%v15","0($sp)"); - la ($sp,"$frame($sp)"); -} else { - ld ("%f4","16*$SIZE_T+2*8($sp)"); - ld ("%f6","16*$SIZE_T+3*8($sp)"); -} - br ("%r14"); -SIZE ("poly1305_emit_vx",".-poly1305_emit_vx"); -} -} - -# NOVX CODE PATH -{ -################ -# static void poly1305_blocks(void *ctx, const unsigned char *inp, size_t len, -# u32 padbit) -{ -my ($ctx,$inp,$len,$padbit) = map("%r$_",(2..5)); - my ($d0hi,$d0lo,$d1hi,$d1lo,$t0,$h0,$t1,$h1,$h2) = map("%r$_",(6..14)); my ($r0,$r1,$s1) = map("%r$_",(0..2)); + GLOBL ("poly1305_blocks"); TYPE ("poly1305_blocks","\@function"); ALIGN (16); LABEL ("poly1305_blocks"); -$z? srlg ($len,$len,4) :srl ($len,4); - lghi ("%r0",0); -&{$z? \&clgr:\&clr} ($len,"%r0"); - je (".Lno_data"); +LABEL (".Lpoly1305_blocks"); +&{$z? \<gr:\<r} ("%r0",$len); + jz (".Lno_data"); &{$z? \&stmg:\&stm} ("%r6","%r14","6*$SIZE_T($sp)"); - llgfr ($padbit,$padbit); # clear upper half, much needed with - # non-64-bit ABI - lg ($r0,"32($ctx)"); # load key - lg ($r1,"40($ctx)"); - - lg ($h0,"0($ctx)"); # load hash value + lg ($h0,"0($ctx)"); # load hash value lg ($h1,"8($ctx)"); lg ($h2,"16($ctx)"); +LABEL (".Lpoly1305_blocks_entry"); +if ($z) { + srlg ($len,$len,4); +} else { + srl ($len,4); +} + llgfr ($padbit,$padbit); # clear upper half, much needed with + # non-64-bit ABI + lg ($r0,"32($ctx)"); # load key + lg ($r1,"40($ctx)"); + &{$z? \&stg:\&st} ($ctx,"2*$SIZE_T($sp)"); # off-load $ctx srlg ($s1,$r1,2); algr ($s1,$r1); # s1 = r1 + r1>>2 @@ -718,21 +160,21 @@ $z? srlg ($len,$len,4) :srl ($len,4); ALIGN (16); LABEL (".Loop"); - lrvg ($d0lo,"0($inp)"); # load little-endian input + lrvg ($d0lo,"0($inp)"); # load little-endian input lrvg ($d1lo,"8($inp)"); la ($inp,"16($inp)"); - algr ($d0lo,$h0); # accumulate input + algr ($d0lo,$h0); # accumulate input alcgr ($d1lo,$h1); + alcgr ($h2,$padbit); lgr ($h0,$d0lo); - mlgr ($d0hi,$r0); # h0*r0 -> $d0hi:$d0lo + mlgr ($d0hi,$r0); # h0*r0 -> $d0hi:$d0lo lgr ($h1,$d1lo); - mlgr ($d1hi,$s1); # h1*5*r1 -> $d1hi:$d1lo + mlgr ($d1hi,$s1); # h1*5*r1 -> $d1hi:$d1lo - mlgr ($t0,$r1); # h0*r1 -> $t0:$h0 - mlgr ($t1,$r0); # h1*r0 -> $t1:$h1 - alcgr ($h2,$padbit); + mlgr ($t0,$r1); # h0*r1 -> $t0:$h0 + mlgr ($t1,$r0); # h1*r0 -> $t1:$h1 algr ($d0lo,$d1lo); lgr ($d1lo,$h2); @@ -742,16 +184,16 @@ LABEL (".Loop"); algr ($h1,$h0); alcgr ($t1,$t0); - msgr ($d1lo,$s1); # h2*s1 - msgr ($h2,$r0); # h2*r0 + msgr ($d1lo,$s1); # h2*s1 + msgr ($h2,$r0); # h2*r0 algr ($h1,$d1lo); - alcgr ($t1,$d1hi); # $d1hi is zero + alcgr ($t1,$d1hi); # $d1hi is zero algr ($h1,$d0hi); alcgr ($h2,$t1); - lghi ($h0,-4); # final reduction step + lghi ($h0,-4); # final reduction step ngr ($h0,$h2); srlg ($t0,$h2,2); algr ($h0,$t0); @@ -759,14 +201,14 @@ LABEL (".Loop"); ngr ($h2,$t1); algr ($h0,$d0lo); - alcgr ($h1,$d1hi); # $d1hi is still zero - alcgr ($h2,$d1hi); # $d1hi is still zero + alcgr ($h1,$d1hi); # $d1hi is still zero + alcgr ($h2,$d1hi); # $d1hi is still zero &{$z? \&brctg:\&brct} ($len,".Loop"); &{$z? \&lg:\&l} ($ctx,"2*$SIZE_T($sp)");# restore $ctx - stg ($h0,"0($ctx)"); # store hash value + stg ($h0,"0($ctx)"); # store hash value stg ($h1,"8($ctx)"); stg ($h2,"16($ctx)"); @@ -776,68 +218,767 @@ LABEL (".Lno_data"); SIZE ("poly1305_blocks",".-poly1305_blocks"); } +################ +# static void poly1305_blocks_vx(void *ctx, const unsigned char *inp, +# size_t len, u32 padbit) +{ +my ($H0, $H1, $H2, $H3, $H4) = map("%v$_",(0..4)); +my ($I0, $I1, $I2, $I3, $I4) = map("%v$_",(5..9)); +my ($R0, $R1, $S1, $R2, $S2) = map("%v$_",(10..14)); +my ($R3, $S3, $R4, $S4) = map("%v$_",(15..18)); +my ($ACC0, $ACC1, $ACC2, $ACC3, $ACC4) = map("%v$_",(19..23)); +my ($T1, $T2, $T3, $T4) = map("%v$_",(24..27)); +my ($mask26,$bswaplo,$bswaphi,$bswapmi) = map("%v$_",(28..31)); + +my ($d2,$d0,$h0,$d1,$h1,$h2)=map("%r$_",(9..14)); + +TYPE ("poly1305_blocks_vx","\@function"); +ALIGN (16); +LABEL ("poly1305_blocks_vx"); +LABEL (".Lpoly1305_blocks_vx"); +&{$z? \&clgfi:\&clfi} ($len,128); + jhe ("__poly1305_blocks_vx"); + +&{$z? \&stmg:\&stm} ("%r6","%r14","6*$SIZE_T($sp)"); + + lg ($d0,"0($ctx)"); + lg ($d1,"8($ctx)"); + lg ($d2,"16($ctx)"); + + llgfr ("%r0",$d0); # base 2^26 -> base 2^64 + srlg ($h0,$d0,32); + llgfr ("%r1",$d1); + srlg ($h1,$d1,32); + srlg ($h2,$d2,32); + + sllg ("%r0","%r0",26); + algr ($h0,"%r0"); + sllg ("%r0",$h1,52); + srlg ($h1,$h1,12); + sllg ("%r1","%r1",14); + algr ($h0,"%r0"); + alcgr ($h1,"%r1"); + sllg ("%r0",$h2,40); + srlg ($h2,$h2,24); + lghi ("%r1",0); + algr ($h1,"%r0"); + alcgr ($h2,"%r1"); + + llgf ("%r0","24($ctx)"); # is_base2_26 + lcgr ("%r0","%r0"); + + xgr ($h0,$d0); # choose between radixes + xgr ($h1,$d1); + xgr ($h2,$d2); + ngr ($h0,"%r0"); + ngr ($h1,"%r0"); + ngr ($h2,"%r0"); + xgr ($h0,$d0); + xgr ($h1,$d1); + xgr ($h2,$d2); + + lhi ("%r0",0); + st ("%r0","24($ctx)"); # clear is_base2_26 + + j (".Lpoly1305_blocks_entry"); +SIZE ("poly1305_blocks_vx",".-poly1305_blocks_vx"); + +TYPE ("__poly1305_mul","\@function"); +ALIGN (16); +LABEL ("__poly1305_mul"); + vmlof ($ACC0,$H0,$R0); + vmlof ($ACC1,$H0,$R1); + vmlof ($ACC2,$H0,$R2); + vmlof ($ACC3,$H0,$R3); + vmlof ($ACC4,$H0,$R4); + + vmalof ($ACC0,$H1,$S4,$ACC0); + vmalof ($ACC1,$H1,$R0,$ACC1); + vmalof ($ACC2,$H1,$R1,$ACC2); + vmalof ($ACC3,$H1,$R2,$ACC3); + vmalof ($ACC4,$H1,$R3,$ACC4); + + vmalof ($ACC0,$H2,$S3,$ACC0); + vmalof ($ACC1,$H2,$S4,$ACC1); + vmalof ($ACC2,$H2,$R0,$ACC2); + vmalof ($ACC3,$H2,$R1,$ACC3); + vmalof ($ACC4,$H2,$R2,$ACC4); + + vmalof ($ACC0,$H3,$S2,$ACC0); + vmalof ($ACC1,$H3,$S3,$ACC1); + vmalof ($ACC2,$H3,$S4,$ACC2); + vmalof ($ACC3,$H3,$R0,$ACC3); + vmalof ($ACC4,$H3,$R1,$ACC4); + + vmalof ($ACC0,$H4,$S1,$ACC0); + vmalof ($ACC1,$H4,$S2,$ACC1); + vmalof ($ACC2,$H4,$S3,$ACC2); + vmalof ($ACC3,$H4,$S4,$ACC3); + vmalof ($ACC4,$H4,$R0,$ACC4); + + ################################################################ + # lazy reduction + + vesrlg ($H4,$ACC3,26); + vesrlg ($H1,$ACC0,26); + vn ($H3,$ACC3,$mask26); + vn ($H0,$ACC0,$mask26); + vag ($H4,$H4,$ACC4); # h3 -> h4 + vag ($H1,$H1,$ACC1); # h0 -> h1 + + vesrlg ($ACC4,$H4,26); + vesrlg ($ACC1,$H1,26); + vn ($H4,$H4,$mask26); + vn ($H1,$H1,$mask26); + vag ($H0,$H0,$ACC4); + vag ($H2,$ACC2,$ACC1); # h1 -> h2 + + veslg ($ACC4,$ACC4,2); # <<2 + vesrlg ($ACC2,$H2,26); + vn ($H2,$H2,$mask26); + vag ($H0,$H0,$ACC4); # h4 -> h0 + vag ($H3,$H3,$ACC2); # h2 -> h3 + + vesrlg ($ACC0,$H0,26); + vesrlg ($ACC3,$H3,26); + vn ($H0,$H0,$mask26); + vn ($H3,$H3,$mask26); + vag ($H1,$H1,$ACC0); # h0 -> h1 + vag ($H4,$H4,$ACC3); # h3 -> h4 + br ("%r14"); +SIZE ("__poly1305_mul",".-__poly1305_mul"); + +TYPE ("__poly1305_blocks_vx","\@function"); +ALIGN (16); +LABEL ("__poly1305_blocks_vx"); +&{$z? \&lgr:\&lr} ("%r0",$sp); +&{$z? \&stmg:\&stm} ("%r10","%r15","10*$SIZE_T($sp)"); +if (!$z) { + std ("%f4","16*$SIZE_T+2*8($sp)"); + std ("%f6","16*$SIZE_T+3*8($sp)"); + ahi ($sp,-$stdframe); + st ("%r0","0($sp)"); # back-chain + + llgfr ($len,$len); # so that srlg works on $len +} else { + aghi ($sp,"-($stdframe+8*8)"); + stg ("%r0","0($sp)"); # back-chain + + std ("%f8","$stdframe+0*8($sp)"); + std ("%f9","$stdframe+1*8($sp)"); + std ("%f10","$stdframe+2*8($sp)"); + std ("%f11","$stdframe+3*8($sp)"); + std ("%f12","$stdframe+4*8($sp)"); + std ("%f13","$stdframe+5*8($sp)"); + std ("%f14","$stdframe+6*8($sp)"); + std ("%f15","$stdframe+7*8($sp)"); +} + larl ("%r1",".Lconst"); + vgmg ($mask26,38,63); + vlm ($bswaplo,$bswapmi,"16(%r1)"); + + < ("%r0","24($ctx)"); # is_base2_26? + jnz (".Lskip_init"); + + lg ($h0,"32($ctx)"); # load key base 2^64 + lg ($h1,"40($ctx)"); + + risbg ($d0,$h0,38,0x80+63,38); # base 2^64 -> 2^26 + srlg ($d1,$h0,52); + risbg ($h0,$h0,38,0x80+63,0); + vlvgg ($R0,$h0,0); + risbg ($d1,$h1,38,51,12); + vlvgg ($R1,$d0,0); + risbg ($d0,$h1,38,63,50); + vlvgg ($R2,$d1,0); + srlg ($d1,$h1,40); + vlvgg ($R3,$d0,0); + vlvgg ($R4,$d1,0); + + veslg ($S1,$R1,2); + veslg ($S2,$R2,2); + veslg ($S3,$R3,2); + veslg ($S4,$R4,2); + vlr ($H0,$R0); + vlr ($H1,$R1); + vlr ($H2,$R2); + vlr ($H3,$R3); + vlr ($H4,$R4); + vag ($S1,$S1,$R1); # * 5 + vag ($S2,$S2,$R2); + vag ($S3,$S3,$R3); + vag ($S4,$S4,$R4); + + brasl ("%r14","__poly1305_mul"); # r^1:- * r^1:- + + vpdi ($R0,$H0,$R0,0); # r^2:r^1 + vpdi ($R1,$H1,$R1,0); + vpdi ($R2,$H2,$R2,0); + vpdi ($R3,$H3,$R3,0); + vpdi ($R4,$H4,$R4,0); + vpdi ($H0,$H0,$H0,0); # r^2:r^2 + vpdi ($H1,$H1,$H1,0); + vpdi ($H2,$H2,$H2,0); + vpdi ($H3,$H3,$H3,0); + vpdi ($H4,$H4,$H4,0); + veslg ($S1,$R1,2); + veslg ($S2,$R2,2); + veslg ($S3,$R3,2); + veslg ($S4,$R4,2); + vag ($S1,$S1,$R1); # * 5 + vag ($S2,$S2,$R2); + vag ($S3,$S3,$R3); + vag ($S4,$S4,$R4); + + brasl ("%r14,__poly1305_mul"); # r^2:r^2 * r^2:r^1 + + vl ($I0,"0(%r1)"); # borrow $I0 + vperm ($R0,$R0,$H0,$I0); # r^2:r^4:r^1:r^3 + vperm ($R1,$R1,$H1,$I0); + vperm ($R2,$R2,$H2,$I0); + vperm ($R3,$R3,$H3,$I0); + vperm ($R4,$R4,$H4,$I0); + veslf ($S1,$R1,2); + veslf ($S2,$R2,2); + veslf ($S3,$R3,2); + veslf ($S4,$R4,2); + vaf ($S1,$S1,$R1); # * 5 + vaf ($S2,$S2,$R2); + vaf ($S3,$S3,$R3); + vaf ($S4,$S4,$R4); + + lg ($h0,"0($ctx)"); # load hash base 2^64 + lg ($h1,"8($ctx)"); + lg ($h2,"16($ctx)"); + + vzero ($H0); + vzero ($H1); + vzero ($H2); + vzero ($H3); + vzero ($H4); + + risbg ($d0,$h0,38,0x80+63,38); # base 2^64 -> 2^26 + srlg ($d1,$h0,52); + risbg ($h0,$h0,38,0x80+63,0); + vlvgg ($H0,$h0,0); + risbg ($d1,$h1,38,51,12); + vlvgg ($H1,$d0,0); + risbg ($d0,$h1,38,63,50); + vlvgg ($H2,$d1,0); + srlg ($d1,$h1,40); + vlvgg ($H3,$d0,0); + risbg ($d1,$h2,37,39,24); + vlvgg ($H4,$d1,0); + + lhi ("%r0",1); + st ("%r0","24($ctx)"); # set is_base2_26 + + vstm ($R0,$S4,"48($ctx)"); # save key schedule base 2^26 + + vpdi ($R0,$R0,$R0,0); # broadcast r^2:r^4 + vpdi ($R1,$R1,$R1,0); + vpdi ($S1,$S1,$S1,0); + vpdi ($R2,$R2,$R2,0); + vpdi ($S2,$S2,$S2,0); + vpdi ($R3,$R3,$R3,0); + vpdi ($S3,$S3,$S3,0); + vpdi ($R4,$R4,$R4,0); + vpdi ($S4,$S4,$S4,0); + + j (".Loaded_hash"); + +ALIGN (16); +LABEL (".Lskip_init"); + vllezf ($H0,"0($ctx)"); # load hash base 2^26 + vllezf ($H1,"4($ctx)"); + vllezf ($H2,"8($ctx)"); + vllezf ($H3,"12($ctx)"); + vllezf ($H4,"16($ctx)"); + + vlrepg ($R0,"0x30($ctx)"); # broadcast r^2:r^4 + vlrepg ($R1,"0x40($ctx)"); + vlrepg ($S1,"0x50($ctx)"); + vlrepg ($R2,"0x60($ctx)"); + vlrepg ($S2,"0x70($ctx)"); + vlrepg ($R3,"0x80($ctx)"); + vlrepg ($S3,"0x90($ctx)"); + vlrepg ($R4,"0xa0($ctx)"); + vlrepg ($S4,"0xb0($ctx)"); + +LABEL (".Loaded_hash"); + vzero ($I1); + vzero ($I3); + + vlm ($T1,$T4,"0x00($inp)"); # load first input block + la ($inp,"0x40($inp)"); + vgmg ($mask26,6,31); + vgmf ($I4,5,5); # padbit<<2 + + vperm ($I0,$T3,$T4,$bswaplo); + vperm ($I2,$T3,$T4,$bswapmi); + vperm ($T3,$T3,$T4,$bswaphi); + + verimg ($I1,$I0,$mask26,6); # >>26 + veslg ($I0,$I0,32); + veslg ($I2,$I2,28); # >>4 + verimg ($I3,$T3,$mask26,18); # >>14 + verimg ($I4,$T3,$mask26,58); # >>38 + vn ($I0,$I0,$mask26); + vn ($I2,$I2,$mask26); + vesrlf ($I4,$I4,2); # >>2 + + vgmg ($mask26,38,63); + vperm ($T3,$T1,$T2,$bswaplo); + vperm ($T4,$T1,$T2,$bswaphi); + vperm ($T2,$T1,$T2,$bswapmi); + + verimg ($I0,$T3,$mask26,0); + verimg ($I1,$T3,$mask26,38); # >>26 + verimg ($I2,$T2,$mask26,60); # >>4 + verimg ($I3,$T4,$mask26,50); # >>14 + vesrlg ($T4,$T4,40); + vo ($I4,$I4,$T4); + + srlg ("%r0",$len,6); +&{$z? \&aghi:\&ahi} ("%r0",-1); + +ALIGN (16); +LABEL (".Loop_vx"); + vmlef ($ACC0,$I0,$R0); + vmlef ($ACC1,$I0,$R1); + vmlef ($ACC2,$I0,$R2); + vmlef ($ACC3,$I0,$R3); + vmlef ($ACC4,$I0,$R4); + + vmalef ($ACC0,$I1,$S4,$ACC0); + vmalef ($ACC1,$I1,$R0,$ACC1); + vmalef ($ACC2,$I1,$R1,$ACC2); + vmalef ($ACC3,$I1,$R2,$ACC3); + vmalef ($ACC4,$I1,$R3,$ACC4); + + vaf ($H2,$H2,$I2); + vaf ($H0,$H0,$I0); + vaf ($H3,$H3,$I3); + vaf ($H1,$H1,$I1); + vaf ($H4,$H4,$I4); + + vmalef ($ACC0,$I2,$S3,$ACC0); + vmalef ($ACC1,$I2,$S4,$ACC1); + vmalef ($ACC2,$I2,$R0,$ACC2); + vmalef ($ACC3,$I2,$R1,$ACC3); + vmalef ($ACC4,$I2,$R2,$ACC4); + + vlm ($T1,$T4,"0x00($inp)"); # load next input block + la ($inp,"0x40($inp)"); + vgmg ($mask26,6,31); + + vmalef ($ACC0,$I3,$S2,$ACC0); + vmalef ($ACC1,$I3,$S3,$ACC1); + vmalef ($ACC2,$I3,$S4,$ACC2); + vmalef ($ACC3,$I3,$R0,$ACC3); + vmalef ($ACC4,$I3,$R1,$ACC4); + + vperm ($I0,$T3,$T4,$bswaplo); + vperm ($I2,$T3,$T4,$bswapmi); + vperm ($T3,$T3,$T4,$bswaphi); + + vmalef ($ACC0,$I4,$S1,$ACC0); + vmalef ($ACC1,$I4,$S2,$ACC1); + vmalef ($ACC2,$I4,$S3,$ACC2); + vmalef ($ACC3,$I4,$S4,$ACC3); + vmalef ($ACC4,$I4,$R0,$ACC4); + + verimg ($I1,$I0,$mask26,6); # >>26 + veslg ($I0,$I0,32); + veslg ($I2,$I2,28); # >>4 + verimg ($I3,$T3,$mask26,18); # >>14 + + vmalof ($ACC0,$H0,$R0,$ACC0); + vmalof ($ACC1,$H0,$R1,$ACC1); + vmalof ($ACC2,$H0,$R2,$ACC2); + vmalof ($ACC3,$H0,$R3,$ACC3); + vmalof ($ACC4,$H0,$R4,$ACC4); + + vgmf ($I4,5,5); # padbit<<2 + verimg ($I4,$T3,$mask26,58); # >>38 + vn ($I0,$I0,$mask26); + vn ($I2,$I2,$mask26); + vesrlf ($I4,$I4,2); # >>2 + + vmalof ($ACC0,$H1,$S4,$ACC0); + vmalof ($ACC1,$H1,$R0,$ACC1); + vmalof ($ACC2,$H1,$R1,$ACC2); + vmalof ($ACC3,$H1,$R2,$ACC3); + vmalof ($ACC4,$H1,$R3,$ACC4); + + vgmg ($mask26,38,63); + vperm ($T3,$T1,$T2,$bswaplo); + vperm ($T4,$T1,$T2,$bswaphi); + vperm ($T2,$T1,$T2,$bswapmi); + + vmalof ($ACC0,$H2,$S3,$ACC0); + vmalof ($ACC1,$H2,$S4,$ACC1); + vmalof ($ACC2,$H2,$R0,$ACC2); + vmalof ($ACC3,$H2,$R1,$ACC3); + vmalof ($ACC4,$H2,$R2,$ACC4); + + verimg ($I0,$T3,$mask26,0); + verimg ($I1,$T3,$mask26,38); # >>26 + verimg ($I2,$T2,$mask26,60); # >>4 + + vmalof ($ACC0,$H3,$S2,$ACC0); + vmalof ($ACC1,$H3,$S3,$ACC1); + vmalof ($ACC2,$H3,$S4,$ACC2); + vmalof ($ACC3,$H3,$R0,$ACC3); + vmalof ($ACC4,$H3,$R1,$ACC4); + + verimg ($I3,$T4,$mask26,50); # >>14 + vesrlg ($T4,$T4,40); + vo ($I4,$I4,$T4); + + vmalof ($ACC0,$H4,$S1,$ACC0); + vmalof ($ACC1,$H4,$S2,$ACC1); + vmalof ($ACC2,$H4,$S3,$ACC2); + vmalof ($ACC3,$H4,$S4,$ACC3); + vmalof ($ACC4,$H4,$R0,$ACC4); + + ################################################################ + # lazy reduction as discussed in "NEON crypto" by D.J. Bernstein + # and P. Schwabe + + vesrlg ($H4,$ACC3,26); + vesrlg ($H1,$ACC0,26); + vn ($H3,$ACC3,$mask26); + vn ($H0,$ACC0,$mask26); + vag ($H4,$H4,$ACC4); # h3 -> h4 + vag ($H1,$H1,$ACC1); # h0 -> h1 + + vesrlg ($ACC4,$H4,26); + vesrlg ($ACC1,$H1,26); + vn ($H4,$H4,$mask26); + vn ($H1,$H1,$mask26); + vag ($H0,$H0,$ACC4); + vag ($H2,$ACC2,$ACC1); # h1 -> h2 + + veslg ($ACC4,$ACC4,2); # <<2 + vesrlg ($ACC2,$H2,26); + vn ($H2,$H2,$mask26); + vag ($H0,$H0,$ACC4); # h4 -> h0 + vag ($H3,$H3,$ACC2); # h2 -> h3 + + vesrlg ($ACC0,$H0,26); + vesrlg ($ACC3,$H3,26); + vn ($H0,$H0,$mask26); + vn ($H3,$H3,$mask26); + vag ($H1,$H1,$ACC0); # h0 -> h1 + vag ($H4,$H4,$ACC3); # h3 -> h4 + +&{$z? \&brctg:\&brct} ("%r0",".Loop_vx"); + + vlm ($R0,$S4,"48($ctx)"); # load all powers + + lghi ("%r0",0x30); +&{$z? \&lcgr:\&lcr} ($len,$len); +&{$z? \&ngr:\&nr} ($len,"%r0"); +&{$z? \&slgr:\&slr} ($inp,$len); + +LABEL (".Last"); + vmlef ($ACC0,$I0,$R0); + vmlef ($ACC1,$I0,$R1); + vmlef ($ACC2,$I0,$R2); + vmlef ($ACC3,$I0,$R3); + vmlef ($ACC4,$I0,$R4); + + vmalef ($ACC0,$I1,$S4,$ACC0); + vmalef ($ACC1,$I1,$R0,$ACC1); + vmalef ($ACC2,$I1,$R1,$ACC2); + vmalef ($ACC3,$I1,$R2,$ACC3); + vmalef ($ACC4,$I1,$R3,$ACC4); + + vaf ($H0,$H0,$I0); + vaf ($H1,$H1,$I1); + vaf ($H2,$H2,$I2); + vaf ($H3,$H3,$I3); + vaf ($H4,$H4,$I4); + + vmalef ($ACC0,$I2,$S3,$ACC0); + vmalef ($ACC1,$I2,$S4,$ACC1); + vmalef ($ACC2,$I2,$R0,$ACC2); + vmalef ($ACC3,$I2,$R1,$ACC3); + vmalef ($ACC4,$I2,$R2,$ACC4); + + vmalef ($ACC0,$I3,$S2,$ACC0); + vmalef ($ACC1,$I3,$S3,$ACC1); + vmalef ($ACC2,$I3,$S4,$ACC2); + vmalef ($ACC3,$I3,$R0,$ACC3); + vmalef ($ACC4,$I3,$R1,$ACC4); + + vmalef ($ACC0,$I4,$S1,$ACC0); + vmalef ($ACC1,$I4,$S2,$ACC1); + vmalef ($ACC2,$I4,$S3,$ACC2); + vmalef ($ACC3,$I4,$S4,$ACC3); + vmalef ($ACC4,$I4,$R0,$ACC4); + + vmalof ($ACC0,$H0,$R0,$ACC0); + vmalof ($ACC1,$H0,$R1,$ACC1); + vmalof ($ACC2,$H0,$R2,$ACC2); + vmalof ($ACC3,$H0,$R3,$ACC3); + vmalof ($ACC4,$H0,$R4,$ACC4); + + vmalof ($ACC0,$H1,$S4,$ACC0); + vmalof ($ACC1,$H1,$R0,$ACC1); + vmalof ($ACC2,$H1,$R1,$ACC2); + vmalof ($ACC3,$H1,$R2,$ACC3); + vmalof ($ACC4,$H1,$R3,$ACC4); + + vmalof ($ACC0,$H2,$S3,$ACC0); + vmalof ($ACC1,$H2,$S4,$ACC1); + vmalof ($ACC2,$H2,$R0,$ACC2); + vmalof ($ACC3,$H2,$R1,$ACC3); + vmalof ($ACC4,$H2,$R2,$ACC4); + + vmalof ($ACC0,$H3,$S2,$ACC0); + vmalof ($ACC1,$H3,$S3,$ACC1); + vmalof ($ACC2,$H3,$S4,$ACC2); + vmalof ($ACC3,$H3,$R0,$ACC3); + vmalof ($ACC4,$H3,$R1,$ACC4); + + vmalof ($ACC0,$H4,$S1,$ACC0); + vmalof ($ACC1,$H4,$S2,$ACC1); + vmalof ($ACC2,$H4,$S3,$ACC2); + vmalof ($ACC3,$H4,$S4,$ACC3); + vmalof ($ACC4,$H4,$R0,$ACC4); + + ################################################################ + # horizontal addition + + vzero ($H0); + vsumqg ($ACC0,$ACC0,$H0); + vsumqg ($ACC1,$ACC1,$H0); + vsumqg ($ACC2,$ACC2,$H0); + vsumqg ($ACC3,$ACC3,$H0); + vsumqg ($ACC4,$ACC4,$H0); + + ################################################################ + # lazy reduction + + vesrlg ($H4,$ACC3,26); + vesrlg ($H1,$ACC0,26); + vn ($H3,$ACC3,$mask26); + vn ($H0,$ACC0,$mask26); + vag ($H4,$H4,$ACC4); # h3 -> h4 + vag ($H1,$H1,$ACC1); # h0 -> h1 + + vesrlg ($ACC4,$H4,26); + vesrlg ($ACC1,$H1,26); + vn ($H4,$H4,$mask26); + vn ($H1,$H1,$mask26); + vag ($H0,$H0,$ACC4); + vag ($H2,$ACC2,$ACC1); # h1 -> h2 + + veslg ($ACC4,$ACC4,2); # <<2 + vesrlg ($ACC2,$H2,26); + vn ($H2,$H2,$mask26); + vag ($H0,$H0,$ACC4); # h4 -> h0 + vag ($H3,$H3,$ACC2); # h2 -> h3 + + vesrlg ($ACC0,$H0,26); + vesrlg ($ACC3,$H3,26); + vn ($H0,$H0,$mask26); + vn ($H3,$H3,$mask26); + vag ($H1,$H1,$ACC0); # h0 -> h1 + vag ($H4,$H4,$ACC3); # h3 -> h4 + +&{$z? \&clgfi:\&clfi} ($len,0); + je (".Ldone"); + + vlm ($T1,$T4,"0x00($inp)"); # load last partial block + vgmg ($mask26,6,31); + vgmf ($I4,5,5); # padbit<<2 + + vperm ($I0,$T3,$T4,$bswaplo); + vperm ($I2,$T3,$T4,$bswapmi); + vperm ($T3,$T3,$T4,$bswaphi); + + vl ($ACC0,"0x30($len,%r1)"); # borrow $ACC0,1 + vl ($ACC1,"0x60($len,%r1)"); + + verimg ($I1,$I0,$mask26,6); # >>26 + veslg ($I0,$I0,32); + veslg ($I2,$I2,28); # >>4 + verimg ($I3,$T3,$mask26,18); # >>14 + verimg ($I4,$T3,$mask26,58); # >>38 + vn ($I0,$I0,$mask26); + vn ($I2,$I2,$mask26); + vesrlf ($I4,$I4,2); # >>2 + + vgmg ($mask26,38,63); + vperm ($T3,$T1,$T2,$bswaplo); + vperm ($T4,$T1,$T2,$bswaphi); + vperm ($T2,$T1,$T2,$bswapmi); + + verimg ($I0,$T3,$mask26,0); + verimg ($I1,$T3,$mask26,38); # >>26 + verimg ($I2,$T2,$mask26,60); # >>4 + verimg ($I3,$T4,$mask26,50); # >>14 + vesrlg ($T4,$T4,40); + vo ($I4,$I4,$T4); + + vperm ($H0,$H0,$H0,$ACC0); # move hash to right lane + vn ($I0,$I0,$ACC1); # mask redundant lane[s] + vperm ($H1,$H1,$H1,$ACC0); + vn ($I1,$I1,$ACC1); + vperm ($H2,$H2,$H2,$ACC0); + vn ($I2,$I2,$ACC1); + vperm ($H3,$H3,$H3,$ACC0); + vn ($I3,$I3,$ACC1); + vperm ($H4,$H4,$H4,$ACC0); + vn ($I4,$I4,$ACC1); + + vaf ($I0,$I0,$H0); # accumulate hash + vzero ($H0); # wipe hash value + vaf ($I1,$I1,$H1); + vzero ($H1); + vaf ($I2,$I2,$H2); + vzero ($H2); + vaf ($I3,$I3,$H3); + vzero ($H3); + vaf ($I4,$I4,$H4); + vzero ($H4); + +&{$z? \&lghi:\&lhi} ($len,0); + j (".Last"); + # I don't bother to tell apart cases when only one multiplication + # pass is sufficient, because I argue that mispredicted branch + # penalties are comparable to overhead of sometimes redundant + # multiplication pass... + +LABEL (".Ldone"); + vstef ($H0,"0($ctx)",3); # store hash base 2^26 + vstef ($H1,"4($ctx)",3); + vstef ($H2,"8($ctx)",3); + vstef ($H3,"12($ctx)",3); + vstef ($H4,"16($ctx)",3); + +if ($z) { + ld ("%f8","$stdframe+0*8($sp)"); + ld ("%f9","$stdframe+1*8($sp)"); + ld ("%f10","$stdframe+2*8($sp)"); + ld ("%f11","$stdframe+3*8($sp)"); + ld ("%f12","$stdframe+4*8($sp)"); + ld ("%f13","$stdframe+5*8($sp)"); + ld ("%f14","$stdframe+6*8($sp)"); + ld ("%f15","$stdframe+7*8($sp)"); +&{$z? \&lmg:\&lm} ("%r10","%r15","$stdframe+8*8+10*$SIZE_T($sp)"); +} else { + ld ("%f4","$stdframe+16*$SIZE_T+2*8($sp)"); + ld ("%f6","$stdframe+16*$SIZE_T+3*8($sp)"); +&{$z? \&lmg:\&lm} ("%r10","%r15","$stdframe+10*$SIZE_T($sp)"); +} + br ("%r14"); +SIZE ("__poly1305_blocks_vx",".-__poly1305_blocks_vx"); +} + ################ # static void poly1305_emit(void *ctx, unsigned char mac[16], # const u32 nonce[4]) { -my ($ctx,$mac,$nonce) = map("%r$_",(2..4)); -my ($h0,$h1,$h2,$d0,$d1)=map("%r$_",(5..9)); +my ($mac,$nonce)=($inp,$len); +my ($h0,$h1,$h2,$d0,$d1,$d2)=map("%r$_",(5..10)); GLOBL ("poly1305_emit"); TYPE ("poly1305_emit","\@function"); ALIGN (16); LABEL ("poly1305_emit"); -&{$z? \&stmg:\&stm} ("%r6","%r9","6*$SIZE_T($sp)"); +LABEL (".Lpoly1305_emit"); +&{$z? \&stmg:\&stm} ("%r6","%r10","6*$SIZE_T($sp)"); - lg ($h0,"0($ctx)"); - lg ($h1,"8($ctx)"); - lg ($h2,"16($ctx)"); + lg ($d0,"0($ctx)"); + lg ($d1,"8($ctx)"); + lg ($d2,"16($ctx)"); + + llgfr ("%r0",$d0); # base 2^26 -> base 2^64 + srlg ($h0,$d0,32); + llgfr ("%r1",$d1); + srlg ($h1,$d1,32); + srlg ($h2,$d2,32); + + sllg ("%r0","%r0",26); + algr ($h0,"%r0"); + sllg ("%r0",$h1,52); + srlg ($h1,$h1,12); + sllg ("%r1","%r1",14); + algr ($h0,"%r0"); + alcgr ($h1,"%r1"); + sllg ("%r0",$h2,40); + srlg ($h2,$h2,24); + lghi ("%r1",0); + algr ($h1,"%r0"); + alcgr ($h2,"%r1"); + + llgf ("%r0","24($ctx)"); # is_base2_26 + lcgr ("%r0","%r0"); + + xgr ($h0,$d0); # choose between radixes + xgr ($h1,$d1); + xgr ($h2,$d2); + ngr ($h0,"%r0"); + ngr ($h1,"%r0"); + ngr ($h2,"%r0"); + xgr ($h0,$d0); + xgr ($h1,$d1); + xgr ($h2,$d2); lghi ("%r0",5); - lghi ("%r1",0); lgr ($d0,$h0); lgr ($d1,$h1); - algr ($h0,"%r0"); # compare to modulus + algr ($h0,"%r0"); # compare to modulus alcgr ($h1,"%r1"); alcgr ($h2,"%r1"); - srlg ($h2,$h2,2); # did it borrow/carry? - slgr ("%r1",$h2); # 0-$h2>>2 - lg ($h2,"0($nonce)"); # load nonce - lghi ("%r0",-1); + srlg ($h2,$h2,2); # did it borrow/carry? + slgr ("%r1",$h2); # 0-$h2>>2 + lg ($d2,"0($nonce)"); # load nonce lg ($ctx,"8($nonce)"); - xgr ("%r0","%r1"); # ~%r1 + xgr ($h0,$d0); + xgr ($h1,$d1); ngr ($h0,"%r1"); - ngr ($d0,"%r0"); ngr ($h1,"%r1"); - ngr ($d1,"%r0"); - ogr ($h0,$d0); - rllg ($d0,$h2,32); # flip nonce words - ogr ($h1,$d1); + xgr ($h0,$d0); + rllg ($d0,$d2,32); # flip nonce words + xgr ($h1,$d1); rllg ($d1,$ctx,32); - algr ($h0,$d0); # accumulate nonce + algr ($h0,$d0); # accumulate nonce alcgr ($h1,$d1); - strvg ($h0,"0($mac)"); # write little-endian result + strvg ($h0,"0($mac)"); # write little-endian result strvg ($h1,"8($mac)"); -&{$z? \&lmg:\&lm} ("%r6","%r9","6*$SIZE_T($sp)"); +&{$z? \&lmg:\&lm} ("%r6","%r10","6*$SIZE_T($sp)"); br ("%r14"); SIZE ("poly1305_emit",".-poly1305_emit"); } -} + ################ -ALIGN (128); +ALIGN (16); LABEL (".Lconst"); -LONG (0x00060504,0x03020100,0x00161514,0x13121110); # vperm op[m[1],m[0]] -LONG (0x000c0b0a,0x09080706,0x001c1b1a,0x19181716); # vperm op[m[3],m[2]] -LONG (0x00000000,0x000f0e0d,0x00000000,0x001f1e1d); # vperm op[ - ,m[4]] -LONG (0x00000000,0x03ffffff,0x00000000,0x03ffffff); # [0,2^26-1,0,2^26-1] -LONG (0x0f0e0d0c,0x0b0a0908,0x07060504,0x03020100); # vperm op endian +LONG (0x04050607,0x14151617,0x0c0d0e0f,0x1c1d1e1f); # merge odd +LONG (0x07060504,0x03020100,0x17161514,0x13121110); # byte swap masks +LONG (0x0f0e0d0c,0x0b0a0908,0x1f1e1d1c,0x1b1a1918); +LONG (0x00000000,0x09080706,0x00000000,0x19181716); + +LONG (0x00000000,0x00000000,0x00000000,0x0c0d0e0f); # magic tail masks +LONG (0x0c0d0e0f,0x00000000,0x00000000,0x00000000); +LONG (0x00000000,0x00000000,0x0c0d0e0f,0x00000000); + +LONG (0xffffffff,0x00000000,0xffffffff,0xffffffff); +LONG (0xffffffff,0x00000000,0xffffffff,0x00000000); +LONG (0x00000000,0x00000000,0xffffffff,0x00000000); + STRING ("\"Poly1305 for s390x, CRYPTOGAMS by \""); PERLASM_END(); diff --git a/crypto/poly1305/build.info b/crypto/poly1305/build.info index de44bb88..60eeeeec 100644 --- a/crypto/poly1305/build.info +++ b/crypto/poly1305/build.info @@ -18,4 +18,5 @@ INCLUDE[poly1305-armv8.o]=.. GENERATE[poly1305-mips.S]=asm/poly1305-mips.pl $(PERLASM_SCHEME) INCLUDE[poly1305-mips.o]=.. GENERATE[poly1305-c64xplus.S]=asm/poly1305-c64xplus.pl $(PERLASM_SCHEME) +INCLUDE[poly1305-s390x.o]=.. GENERATE[poly1305-s390x.S]=asm/poly1305-s390x.pl $(PERLASM_SCHEME) diff --git a/crypto/provider_core.c b/crypto/provider_core.c index 8af5b1f1..7a184a7d 100644 --- a/crypto/provider_core.c +++ b/crypto/provider_core.c @@ -11,9 +11,14 @@ #include #include #include "internal/cryptlib.h" +#include "internal/nelem.h" #include "internal/thread_once.h" #include "internal/provider.h" #include "internal/refcount.h" +#include "provider_local.h" + +static OSSL_PROVIDER *provider_new(const char *name, + OSSL_provider_init_fn *init_function); /*- * Provider Object structure @@ -25,6 +30,7 @@ struct provider_store_st; /* Forward declaration */ struct ossl_provider_st { /* Flag bits */ unsigned int flag_initialized:1; + unsigned int flag_fallback:1; /* OpenSSL library side data */ CRYPTO_REF_COUNT refcnt; @@ -32,6 +38,7 @@ struct ossl_provider_st { char *name; DSO *module; OSSL_provider_init_fn *init_function; + struct provider_store_st *store; /* The store this instance belongs to */ /* Provider side functions */ OSSL_provider_teardown_fn *teardown; @@ -58,6 +65,7 @@ static int ossl_provider_cmp(const OSSL_PROVIDER * const *a, struct provider_store_st { STACK_OF(OSSL_PROVIDER) *providers; CRYPTO_RWLOCK *lock; + unsigned int use_fallbacks:1; }; static int provider_store_index = -1; @@ -75,13 +83,37 @@ static void provider_store_free(void *vstore) static void *provider_store_new(void) { struct provider_store_st *store = OPENSSL_zalloc(sizeof(*store)); + const struct predefined_providers_st *p = NULL; if (store == NULL || (store->providers = sk_OSSL_PROVIDER_new(ossl_provider_cmp)) == NULL || (store->lock = CRYPTO_THREAD_lock_new()) == NULL) { provider_store_free(store); - store = NULL; + return NULL; } + store->use_fallbacks = 1; + + for (p = predefined_providers; p->name != NULL; p++) { + OSSL_PROVIDER *prov = NULL; + + /* + * We use the internal constructor directly here, + * otherwise we get a call loop + */ + prov = provider_new(p->name, p->init); + + if (prov == NULL + || sk_OSSL_PROVIDER_push(store->providers, prov) == 0) { + ossl_provider_free(prov); + provider_store_free(store); + CRYPTOerr(CRYPTO_F_PROVIDER_STORE_NEW, ERR_R_INTERNAL_ERROR); + return NULL; + } + prov->store = store; + if(p->is_fallback) + ossl_provider_set_fallback(prov); + } + return store; } @@ -112,20 +144,6 @@ static struct provider_store_st *get_provider_store(OPENSSL_CTX *libctx) return store; } -/*- - * Provider Object methods - * ======================= - */ - -int ossl_provider_upref(OSSL_PROVIDER *prov) -{ - int ref = 0; - - CRYPTO_UP_REF(&prov->refcnt, &ref, prov->refcnt_lock); - return ref; -} - -/* Finder, constructor and destructor */ OSSL_PROVIDER *ossl_provider_find(OPENSSL_CTX *libctx, const char *name) { struct provider_store_st *store = NULL; @@ -147,6 +165,39 @@ OSSL_PROVIDER *ossl_provider_find(OPENSSL_CTX *libctx, const char *name) return prov; } +/*- + * Provider Object methods + * ======================= + */ + +static OSSL_PROVIDER *provider_new(const char *name, + OSSL_provider_init_fn *init_function) +{ + OSSL_PROVIDER *prov = NULL; + + if ((prov = OPENSSL_zalloc(sizeof(*prov))) == NULL +#ifndef HAVE_ATOMICS + || (prov->refcnt_lock = CRYPTO_THREAD_lock_new()) == NULL +#endif + || !ossl_provider_upref(prov) /* +1 One reference to be returned */ + || (prov->name = OPENSSL_strdup(name)) == NULL) { + ossl_provider_free(prov); + CRYPTOerr(CRYPTO_F_PROVIDER_NEW, ERR_R_MALLOC_FAILURE); + return NULL; + } + + prov->init_function = init_function; + return prov; +} + +int ossl_provider_upref(OSSL_PROVIDER *prov) +{ + int ref = 0; + + CRYPTO_UP_REF(&prov->refcnt, &ref, prov->refcnt_lock); + return ref; +} + OSSL_PROVIDER *ossl_provider_new(OPENSSL_CTX *libctx, const char *name, OSSL_provider_init_fn *init_function) { @@ -164,18 +215,9 @@ OSSL_PROVIDER *ossl_provider_new(OPENSSL_CTX *libctx, const char *name, return NULL; } - if ((prov = OPENSSL_zalloc(sizeof(*prov))) == NULL -#ifndef HAVE_ATOMICS - || (prov->refcnt_lock = CRYPTO_THREAD_lock_new()) == NULL -#endif - || !ossl_provider_upref(prov) /* +1 One reference to be returned */ - || (prov->name = OPENSSL_strdup(name)) == NULL) { - ossl_provider_free(prov); - CRYPTOerr(CRYPTO_F_OSSL_PROVIDER_NEW, ERR_R_MALLOC_FAILURE); + /* provider_new() generates an error, so no need here */ + if ((prov = provider_new(name, init_function)) == NULL) return NULL; - } - - prov->init_function = init_function; CRYPTO_THREAD_write_lock(store->lock); if (!ossl_provider_upref(prov)) { /* +1 One reference for the store */ @@ -185,6 +227,8 @@ OSSL_PROVIDER *ossl_provider_new(OPENSSL_CTX *libctx, const char *name, ossl_provider_free(prov); /* -1 Store reference */ ossl_provider_free(prov); /* -1 Reference that was to be returned */ prov = NULL; + } else { + prov->store = store; } CRYPTO_THREAD_unlock(store->lock); @@ -207,11 +251,13 @@ void ossl_provider_free(OSSL_PROVIDER *prov) CRYPTO_DOWN_REF(&prov->refcnt, &ref, prov->refcnt_lock); /* - * When the refcount drops down to one, there is only one reference, - * the store. + * When the refcount drops below two, the store is the only + * possible reference, or it has already been taken away from + * the store (this may happen if a provider was activated + * because it's a fallback, but isn't currently used) * When that happens, the provider is inactivated. */ - if (ref == 1 && prov->flag_initialized) { + if (ref < 2 && prov->flag_initialized) { if (prov->teardown != NULL) prov->teardown(); prov->flag_initialized = 0; @@ -246,7 +292,12 @@ void ossl_provider_free(OSSL_PROVIDER *prov) */ static const OSSL_DISPATCH *core_dispatch; /* Define further down */ -int ossl_provider_activate(OSSL_PROVIDER *prov) +/* + * Internal version that doesn't affect the store flags, and thereby avoid + * locking. Direct callers must remember to set the store flags when + * appropriate + */ +static int provider_activate(OSSL_PROVIDER *prov) { const OSSL_DISPATCH *provider_dispatch = NULL; @@ -295,7 +346,7 @@ int ossl_provider_activate(OSSL_PROVIDER *prov) if (prov->init_function == NULL || !prov->init_function(prov, core_dispatch, &provider_dispatch)) { - CRYPTOerr(CRYPTO_F_OSSL_PROVIDER_ACTIVATE, ERR_R_INIT_FAIL); + CRYPTOerr(CRYPTO_F_PROVIDER_ACTIVATE, ERR_R_INIT_FAIL); ERR_add_error_data(2, "name=", prov->name); DSO_free(prov->module); prov->module = NULL; @@ -329,6 +380,46 @@ int ossl_provider_activate(OSSL_PROVIDER *prov) return 1; } +int ossl_provider_activate(OSSL_PROVIDER *prov) +{ + if (provider_activate(prov)) { + CRYPTO_THREAD_write_lock(prov->store->lock); + prov->store->use_fallbacks = 0; + CRYPTO_THREAD_unlock(prov->store->lock); + return 1; + } + + return 0; +} + + +static int provider_forall_loaded(struct provider_store_st *store, + int *found_activated, + int (*cb)(OSSL_PROVIDER *provider, + void *cbdata), + void *cbdata) +{ + int i; + int ret = 1; + int num_provs = sk_OSSL_PROVIDER_num(store->providers); + + if (found_activated != NULL) + *found_activated = 0; + for (i = 0; i < num_provs; i++) { + OSSL_PROVIDER *prov = + sk_OSSL_PROVIDER_value(store->providers, i); + + if (prov->flag_initialized) { + if (found_activated != NULL) + *found_activated = 1; + if (!(ret = cb(prov, cbdata))) + break; + } + } + + return ret; +} + int ossl_provider_forall_loaded(OPENSSL_CTX *ctx, int (*cb)(OSSL_PROVIDER *provider, void *cbdata), @@ -339,13 +430,50 @@ int ossl_provider_forall_loaded(OPENSSL_CTX *ctx, struct provider_store_st *store = get_provider_store(ctx); if (store != NULL) { - CRYPTO_THREAD_read_lock(store->lock); - for (i = 0; i < sk_OSSL_PROVIDER_num(store->providers); i++) { - OSSL_PROVIDER *prov = sk_OSSL_PROVIDER_value(store->providers, i); + int found_activated = 0; - if (prov->flag_initialized - && !(ret = cb(prov, cbdata))) - break; + CRYPTO_THREAD_read_lock(store->lock); + ret = provider_forall_loaded(store, &found_activated, cb, cbdata); + + /* + * If there's nothing activated ever in this store, try to activate + * all fallbacks. + */ + if (!found_activated && store->use_fallbacks) { + int num_provs = sk_OSSL_PROVIDER_num(store->providers); + int activated_fallback_count = 0; + + for (i = 0; i < num_provs; i++) { + OSSL_PROVIDER *prov = + sk_OSSL_PROVIDER_value(store->providers, i); + + /* + * Note that we don't care if the activation succeeds or + * not. If it doesn't succeed, then the next loop will + * fail anyway. + */ + if (prov->flag_fallback) { + activated_fallback_count++; + provider_activate(prov); + } + } + + if (activated_fallback_count > 0) { + /* + * We assume that all fallbacks have been added to the store + * before any fallback is activated. + * TODO: We may have to reconsider this, IF we find ourselves + * adding fallbacks after any previous fallback has been + * activated. + */ + store->use_fallbacks = 0; + + /* + * Now that we've activated available fallbacks, try a + * second sweep + */ + ret = provider_forall_loaded(store, NULL, cb, cbdata); + } } CRYPTO_THREAD_unlock(store->lock); } @@ -353,6 +481,16 @@ int ossl_provider_forall_loaded(OPENSSL_CTX *ctx, return ret; } +/* Setters of Provider Object data */ +int ossl_provider_set_fallback(OSSL_PROVIDER *prov) +{ + if (prov == NULL) + return 0; + + prov->flag_fallback = 1; + return 1; +} + /* Getters of Provider Object data */ const char *ossl_provider_name(OSSL_PROVIDER *prov) { diff --git a/crypto/provider_local.h b/crypto/provider_local.h new file mode 100644 index 00000000..e4c649a7 --- /dev/null +++ b/crypto/provider_local.h @@ -0,0 +1,18 @@ +/* + * Copyright 2019 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the Apache License 2.0 (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#include + +struct predefined_providers_st { + const char *name; + OSSL_provider_init_fn *init; + unsigned int is_fallback:1; +}; + +extern const struct predefined_providers_st predefined_providers[]; diff --git a/crypto/provider_predefined.c b/crypto/provider_predefined.c new file mode 100644 index 00000000..d14cd5b9 --- /dev/null +++ b/crypto/provider_predefined.c @@ -0,0 +1,18 @@ +/* + * Copyright 2019 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the Apache License 2.0 (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#include +#include "provider_local.h" + +OSSL_provider_init_fn ossl_default_provider_init; + +const struct predefined_providers_st predefined_providers[] = { + { "default", ossl_default_provider_init, 1 }, + { NULL, NULL, 0 } +}; diff --git a/crypto/rand/build.info b/crypto/rand/build.info index d73326b4..d9c1fb7e 100644 --- a/crypto/rand/build.info +++ b/crypto/rand/build.info @@ -1,6 +1,6 @@ LIBS=../../libcrypto SOURCE[../../libcrypto]=\ - randfile.c rand_lib.c rand_err.c rand_egd.c \ + randfile.c rand_lib.c rand_err.c rand_crng_test.c rand_egd.c \ rand_win.c rand_unix.c rand_vms.c drbg_lib.c drbg_ctr.c \ drbg_hash.c drbg_hmac.c diff --git a/crypto/rand/drbg_lib.c b/crypto/rand/drbg_lib.c index 1944fbf6..4e1e2ea5 100644 --- a/crypto/rand/drbg_lib.c +++ b/crypto/rand/drbg_lib.c @@ -67,7 +67,7 @@ static CRYPTO_THREAD_LOCAL private_drbg; /* NIST SP 800-90A DRBG recommends the use of a personalization string. */ -static const char ossl_pers_string[] = "OpenSSL NIST SP 800-90A DRBG"; +static const char ossl_pers_string[] = DRBG_DEFAULT_PERS_STRING; static CRYPTO_ONCE rand_drbg_init = CRYPTO_ONCE_STATIC_INIT; @@ -241,8 +241,8 @@ static RAND_DRBG *rand_drbg_new(int secure, unsigned int flags, RAND_DRBG *parent) { - RAND_DRBG *drbg = secure ? - OPENSSL_secure_zalloc(sizeof(*drbg)) : OPENSSL_zalloc(sizeof(*drbg)); + RAND_DRBG *drbg = secure ? OPENSSL_secure_zalloc(sizeof(*drbg)) + : OPENSSL_zalloc(sizeof(*drbg)); if (drbg == NULL) { RANDerr(RAND_F_RAND_DRBG_NEW, ERR_R_MALLOC_FAILURE); @@ -254,8 +254,13 @@ static RAND_DRBG *rand_drbg_new(int secure, drbg->parent = parent; if (parent == NULL) { +#ifdef FIPS_MODE + drbg->get_entropy = rand_crngt_get_entropy; + drbg->cleanup_entropy = rand_crngt_cleanup_entropy; +#else drbg->get_entropy = rand_drbg_get_entropy; drbg->cleanup_entropy = rand_drbg_cleanup_entropy; +#endif #ifndef RAND_DRBG_GET_RANDOM_NONCE drbg->get_nonce = rand_drbg_get_nonce; drbg->cleanup_nonce = rand_drbg_cleanup_nonce; diff --git a/crypto/rand/rand_crng_test.c b/crypto/rand/rand_crng_test.c new file mode 100644 index 00000000..74a64ee5 --- /dev/null +++ b/crypto/rand/rand_crng_test.c @@ -0,0 +1,109 @@ +/* + * Copyright 2019 The OpenSSL Project Authors. All Rights Reserved. + * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. + * + * Licensed under the Apache License 2.0 (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +/* + * Implementation of the FIPS 140-2 section 4.9.2 Conditional Tests. + */ + +#include +#include "internal/rand_int.h" +#include "internal/thread_once.h" +#include "rand_lcl.h" + +static RAND_POOL *crngt_pool; +static unsigned char *crngt_prev; + +int (*crngt_get_entropy)(unsigned char *) = &rand_crngt_get_entropy_cb; + +int rand_crngt_get_entropy_cb(unsigned char *buf) +{ + size_t n; + unsigned char *p; + + while ((n = rand_pool_acquire_entropy(crngt_pool)) != 0) + if (n >= CRNGT_BUFSIZ) { + p = rand_pool_detach(crngt_pool); + memcpy(crngt_prev, p, CRNGT_BUFSIZ); + rand_pool_reattach(crngt_pool, p); + return 1; + } + return 0; + +} +void rand_crngt_cleanup(void) +{ + rand_pool_free(crngt_pool); + OPENSSL_secure_free(crngt_prev); + crngt_pool = NULL; + crngt_prev = NULL; +} + +int rand_crngt_init(void) +{ + if ((crngt_pool = rand_pool_new(0, CRNGT_BUFSIZ, CRNGT_BUFSIZ)) == NULL) + return 0; + if ((crngt_prev = OPENSSL_secure_malloc(CRNGT_BUFSIZ)) != NULL + && crngt_get_entropy(crngt_prev)) + return 1; + rand_crngt_cleanup(); + return 0; +} + +static CRYPTO_ONCE rand_crngt_init_flag = CRYPTO_ONCE_STATIC_INIT; +DEFINE_RUN_ONCE_STATIC(do_rand_crngt_init) +{ + return OPENSSL_init_crypto(0, NULL) + && rand_crngt_init() + && OPENSSL_atexit(&rand_crngt_cleanup); +} + +int rand_crngt_single_init(void) +{ + return RUN_ONCE(&rand_crngt_init_flag, do_rand_crngt_init); +} + +size_t rand_crngt_get_entropy(RAND_DRBG *drbg, + unsigned char **pout, + int entropy, size_t min_len, size_t max_len, + int prediction_resistance) +{ + unsigned char buf[CRNGT_BUFSIZ]; + RAND_POOL *pool; + size_t q, r = 0, s, t = 0; + int attempts = 3; + + if (!RUN_ONCE(&rand_crngt_init_flag, do_rand_crngt_init)) + return 0; + + if ((pool = rand_pool_new(entropy, min_len, max_len)) == NULL) + return 0; + + while ((q = rand_pool_bytes_needed(pool, 1)) > 0 && attempts-- > 0) { + s = q > sizeof(buf) ? sizeof(buf) : q; + if (!crngt_get_entropy(buf) + || memcmp(crngt_prev, buf, CRNGT_BUFSIZ) == 0 + || !rand_pool_add(pool, buf, s, s * 8)) + goto err; + memcpy(crngt_prev, buf, CRNGT_BUFSIZ); + t += s; + attempts++; + } + r = t; + *pout = rand_pool_detach(pool); +err: + rand_pool_free(pool); + return r; +} + +void rand_crngt_cleanup_entropy(RAND_DRBG *drbg, + unsigned char *out, size_t outlen) +{ + OPENSSL_secure_clear_free(out, outlen); +} diff --git a/crypto/rand/rand_lcl.h b/crypto/rand/rand_lcl.h index 1b2bd888..d793d282 100644 --- a/crypto/rand/rand_lcl.h +++ b/crypto/rand/rand_lcl.h @@ -33,7 +33,15 @@ # define MASTER_RESEED_TIME_INTERVAL (60*60) /* 1 hour */ # define SLAVE_RESEED_TIME_INTERVAL (7*60) /* 7 minutes */ - +/* + * The number of bytes that constitutes an atomic lump of entropy with respect + * to the FIPS 140-2 section 4.9.2 Conditional Tests. The size is somewhat + * arbitrary, the smaller the value, the less entropy is consumed on first + * read but the higher the probability of the test failing by accident. + * + * The value is in bytes. + */ +#define CRNGT_BUFSIZ 16 /* * Maximum input size for the DRBG (entropy, nonce, personalization string) @@ -44,7 +52,8 @@ */ # define DRBG_MAX_LENGTH INT32_MAX - +/* The default nonce */ +# define DRBG_DEFAULT_PERS_STRING "OpenSSL NIST SP 800-90A DRBG" /* * Maximum allocation size for RANDOM_POOL buffers @@ -321,4 +330,20 @@ int drbg_ctr_init(RAND_DRBG *drbg); int drbg_hash_init(RAND_DRBG *drbg); int drbg_hmac_init(RAND_DRBG *drbg); +/* + * Entropy call back for the FIPS 140-2 section 4.9.2 Conditional Tests. + * These need to be exposed for the unit tests. + */ +int rand_crngt_get_entropy_cb(unsigned char *buf); +extern int (*crngt_get_entropy)(unsigned char *); +int rand_crngt_init(void); +void rand_crngt_cleanup(void); + +/* + * Expose the run once initialisation function for the unit tests because. + * they need to restart from scratch to validate the first block is skipped + * properly. + */ +int rand_crngt_single_init(void); + #endif diff --git a/crypto/rand/rand_lib.c b/crypto/rand/rand_lib.c index 671f215c..a298b751 100644 --- a/crypto/rand/rand_lib.c +++ b/crypto/rand/rand_lib.c @@ -137,7 +137,7 @@ size_t rand_drbg_get_entropy(RAND_DRBG *drbg, size_t entropy_available = 0; RAND_POOL *pool; - if (drbg->parent && drbg->strength > drbg->parent->strength) { + if (drbg->parent != NULL && drbg->strength > drbg->parent->strength) { /* * We currently don't support the algorithm from NIST SP 800-90C * 10.1.2 to use a weaker DRBG as source @@ -155,7 +155,7 @@ size_t rand_drbg_get_entropy(RAND_DRBG *drbg, return 0; } - if (drbg->parent) { + if (drbg->parent != NULL) { size_t bytes_needed = rand_pool_bytes_needed(pool, 1 /*entropy_factor*/); unsigned char *buffer = rand_pool_add_begin(pool, bytes_needed); @@ -235,8 +235,9 @@ size_t rand_drbg_get_nonce(RAND_DRBG *drbg, struct { void * instance; int count; - } data = { 0 }; + } data; + memset(&data, 0, sizeof(data)); pool = rand_pool_new(0, min_len, max_len); if (pool == NULL) return 0; @@ -402,7 +403,7 @@ int RAND_poll(void) } else { /* fill random pool and seed the current legacy RNG */ pool = rand_pool_new(RAND_DRBG_STRENGTH, - RAND_DRBG_STRENGTH / 8, + (RAND_DRBG_STRENGTH + 7) / 8, RAND_POOL_MAX_LENGTH); if (pool == NULL) return 0; @@ -689,7 +690,7 @@ unsigned char *rand_pool_add_begin(RAND_POOL *pool, size_t len) if (pool->buffer == NULL) { RANDerr(RAND_F_RAND_POOL_ADD_BEGIN, ERR_R_INTERNAL_ERROR); - return 0; + return NULL; } return pool->buffer + pool->len; diff --git a/crypto/rand/rand_unix.c b/crypto/rand/rand_unix.c index 39c4e7e7..5d1e0d8b 100644 --- a/crypto/rand/rand_unix.c +++ b/crypto/rand/rand_unix.c @@ -615,7 +615,10 @@ int rand_pool_add_nonce_data(RAND_POOL *pool) pid_t pid; CRYPTO_THREAD_ID tid; uint64_t time; - } data = { 0 }; + } data; + + /* Erase the entire structure including any padding */ + memset(&data, 0, sizeof(data)); /* * Add process id, thread id, and a high resolution timestamp to @@ -634,7 +637,10 @@ int rand_pool_add_additional_data(RAND_POOL *pool) struct { CRYPTO_THREAD_ID tid; uint64_t time; - } data = { 0 }; + } data; + + /* Erase the entire structure including any padding */ + memset(&data, 0, sizeof(data)); /* * Add some noise from the thread id and a high resolution timer. diff --git a/crypto/rand/rand_vms.c b/crypto/rand/rand_vms.c index d35106a3..3f13529d 100644 --- a/crypto/rand/rand_vms.c +++ b/crypto/rand/rand_vms.c @@ -475,7 +475,10 @@ int rand_pool_add_nonce_data(RAND_POOL *pool) pid_t pid; CRYPTO_THREAD_ID tid; uint64_t time; - } data = { 0 }; + } data; + + /* Erase the entire structure including any padding */ + memset(&data, 0, sizeof(data)); /* * Add process id, thread id, and a high resolution timestamp @@ -499,7 +502,10 @@ int rand_pool_add_additional_data(RAND_POOL *pool) struct { CRYPTO_THREAD_ID tid; uint64_t time; - } data = { 0 }; + } data; + + /* Erase the entire structure including any padding */ + memset(&data, 0, sizeof(data)); /* * Add some noise from the thread id and a high resolution timer. diff --git a/crypto/rand/rand_win.c b/crypto/rand/rand_win.c index ceeae379..278aee08 100644 --- a/crypto/rand/rand_win.c +++ b/crypto/rand/rand_win.c @@ -125,7 +125,10 @@ int rand_pool_add_nonce_data(RAND_POOL *pool) DWORD pid; DWORD tid; FILETIME time; - } data = { 0 }; + } data; + + /* Erase the entire structure including any padding */ + memset(&data, 0, sizeof(data)); /* * Add process id, thread id, and a high resolution timestamp to @@ -144,7 +147,10 @@ int rand_pool_add_additional_data(RAND_POOL *pool) struct { DWORD tid; LARGE_INTEGER time; - } data = { 0 }; + } data; + + /* Erase the entire structure including any padding */ + memset(&data, 0, sizeof(data)); /* * Add some noise from the thread id and a high resolution timer. diff --git a/crypto/rand/randfile.c b/crypto/rand/randfile.c index 66cec245..7dde54b1 100644 --- a/crypto/rand/randfile.c +++ b/crypto/rand/randfile.c @@ -254,7 +254,7 @@ const char *RAND_file_name(char *buf, size_t size) size_t len; int use_randfile = 1; -#if defined(_WIN32) && defined(CP_UTF8) +#if defined(_WIN32) && defined(CP_UTF8) && !defined(_WIN32_WCE) DWORD envlen; WCHAR *var; diff --git a/crypto/rsa/rsa_ameth.c b/crypto/rsa/rsa_ameth.c index c6ae8a45..139415e6 100644 --- a/crypto/rsa/rsa_ameth.c +++ b/crypto/rsa/rsa_ameth.c @@ -447,7 +447,7 @@ static int rsa_sig_print(BIO *bp, const X509_ALGOR *sigalg, RSA_PSS_PARAMS_free(pss); if (!rv) return 0; - } else if (!sig && BIO_puts(bp, "\n") <= 0) { + } else if (BIO_puts(bp, "\n") <= 0) { return 0; } if (sig) diff --git a/crypto/rsa/rsa_gen.c b/crypto/rsa/rsa_gen.c index 4bfe3c3a..1611fc86 100644 --- a/crypto/rsa/rsa_gen.c +++ b/crypto/rsa/rsa_gen.c @@ -393,8 +393,7 @@ static int rsa_builtin_keygen(RSA *rsa, int bits, int primes, BIGNUM *e_value, RSAerr(RSA_F_RSA_BUILTIN_KEYGEN, ERR_LIB_BN); ok = 0; } - if (ctx != NULL) - BN_CTX_end(ctx); + BN_CTX_end(ctx); BN_CTX_free(ctx); return ok; #endif /* FIPS_MODE */ diff --git a/crypto/rsa/rsa_oaep.c b/crypto/rsa/rsa_oaep.c index 8fca4fab..9affabb9 100644 --- a/crypto/rsa/rsa_oaep.c +++ b/crypto/rsa/rsa_oaep.c @@ -234,25 +234,25 @@ int RSA_padding_check_PKCS1_OAEP_mgf1(unsigned char *to, int tlen, good &= constant_time_ge(tlen, mlen); /* - * Even though we can't fake result's length, we can pretend copying - * |tlen| bytes where |mlen| bytes would be real. Last |tlen| of |dblen| - * bytes are viewed as circular buffer with start at |tlen|-|mlen'|, - * where |mlen'| is "saturated" |mlen| value. Deducing information - * about failure or |mlen| would take attacker's ability to observe - * memory access pattern with byte granularity *as it occurs*. It - * should be noted that failure is indistinguishable from normal - * operation if |tlen| is fixed by protocol. + * Move the result in-place by |dblen|-|mdlen|-1-|mlen| bytes to the left. + * Then if |good| move |mlen| bytes from |db|+|mdlen|+1 to |to|. + * Otherwise leave |to| unchanged. + * Copy the memory back in a way that does not reveal the size of + * the data being copied via a timing side channel. This requires copying + * parts of the buffer multiple times based on the bits set in the real + * length. Clear bits do a non-copy with identical access pattern. + * The loop below has overall complexity of O(N*log(N)). */ tlen = constant_time_select_int(constant_time_lt(dblen - mdlen - 1, tlen), dblen - mdlen - 1, tlen); - msg_index = constant_time_select_int(good, msg_index, dblen - tlen); - mlen = dblen - msg_index; - for (mask = good, i = 0; i < tlen; i++) { - unsigned int equals = constant_time_eq(msg_index, dblen); - - msg_index -= tlen & equals; /* rewind at EOF */ - mask &= ~equals; /* mask = 0 at EOF */ - to[i] = constant_time_select_8(mask, db[msg_index++], to[i]); + for (msg_index = 1; msg_index < dblen - mdlen - 1; msg_index <<= 1) { + mask = ~constant_time_eq(msg_index & (dblen - mdlen - 1 - mlen), 0); + for (i = mdlen + 1; i < dblen - msg_index; i++) + db[i] = constant_time_select_8(mask, db[i + msg_index], db[i]); + } + for (i = 0; i < tlen; i++) { + mask = good & constant_time_lt(i, mlen); + to[i] = constant_time_select_8(mask, db[i + mdlen + 1], to[i]); } /* diff --git a/crypto/rsa/rsa_ossl.c b/crypto/rsa/rsa_ossl.c index 5f8f39fa..e6876de6 100644 --- a/crypto/rsa/rsa_ossl.c +++ b/crypto/rsa/rsa_ossl.c @@ -148,8 +148,7 @@ static int rsa_ossl_public_encrypt(int flen, const unsigned char *from, */ r = BN_bn2binpad(ret, to, num); err: - if (ctx != NULL) - BN_CTX_end(ctx); + BN_CTX_end(ctx); BN_CTX_free(ctx); OPENSSL_clear_free(buf, num); return r; @@ -354,8 +353,7 @@ static int rsa_ossl_private_encrypt(int flen, const unsigned char *from, */ r = BN_bn2binpad(res, to, num); err: - if (ctx != NULL) - BN_CTX_end(ctx); + BN_CTX_end(ctx); BN_CTX_free(ctx); OPENSSL_clear_free(buf, num); return r; @@ -481,11 +479,10 @@ static int rsa_ossl_private_decrypt(int flen, const unsigned char *from, goto err; } RSAerr(RSA_F_RSA_OSSL_PRIVATE_DECRYPT, RSA_R_PADDING_CHECK_FAILED); - err_clear_last_constant_time(r >= 0); + err_clear_last_constant_time(1 & ~constant_time_msb(r)); err: - if (ctx != NULL) - BN_CTX_end(ctx); + BN_CTX_end(ctx); BN_CTX_free(ctx); OPENSSL_clear_free(buf, num); return r; @@ -581,8 +578,7 @@ static int rsa_ossl_public_decrypt(int flen, const unsigned char *from, RSAerr(RSA_F_RSA_OSSL_PUBLIC_DECRYPT, RSA_R_PADDING_CHECK_FAILED); err: - if (ctx != NULL) - BN_CTX_end(ctx); + BN_CTX_end(ctx); BN_CTX_free(ctx); OPENSSL_clear_free(buf, num); return r; diff --git a/crypto/rsa/rsa_pk1.c b/crypto/rsa/rsa_pk1.c index 58ac992c..ff1ca021 100644 --- a/crypto/rsa/rsa_pk1.c +++ b/crypto/rsa/rsa_pk1.c @@ -226,25 +226,25 @@ int RSA_padding_check_PKCS1_type_2(unsigned char *to, int tlen, good &= constant_time_ge(tlen, mlen); /* - * Even though we can't fake result's length, we can pretend copying - * |tlen| bytes where |mlen| bytes would be real. Last |tlen| of |num| - * bytes are viewed as circular buffer with start at |tlen|-|mlen'|, - * where |mlen'| is "saturated" |mlen| value. Deducing information - * about failure or |mlen| would take attacker's ability to observe - * memory access pattern with byte granularity *as it occurs*. It - * should be noted that failure is indistinguishable from normal - * operation if |tlen| is fixed by protocol. + * Move the result in-place by |num|-11-|mlen| bytes to the left. + * Then if |good| move |mlen| bytes from |em|+11 to |to|. + * Otherwise leave |to| unchanged. + * Copy the memory back in a way that does not reveal the size of + * the data being copied via a timing side channel. This requires copying + * parts of the buffer multiple times based on the bits set in the real + * length. Clear bits do a non-copy with identical access pattern. + * The loop below has overall complexity of O(N*log(N)). */ tlen = constant_time_select_int(constant_time_lt(num - 11, tlen), num - 11, tlen); - msg_index = constant_time_select_int(good, msg_index, num - tlen); - mlen = num - msg_index; - for (mask = good, i = 0; i < tlen; i++) { - unsigned int equals = constant_time_eq(msg_index, num); - - msg_index -= tlen & equals; /* rewind at EOF */ - mask &= ~equals; /* mask = 0 at EOF */ - to[i] = constant_time_select_8(mask, em[msg_index++], to[i]); + for (msg_index = 1; msg_index < num - 11; msg_index <<= 1) { + mask = ~constant_time_eq(msg_index & (num - 11 - mlen), 0); + for (i = 11; i < num - msg_index; i++) + em[i] = constant_time_select_8(mask, em[i + msg_index], em[i]); + } + for (i = 0; i < tlen; i++) { + mask = good & constant_time_lt(i, mlen); + to[i] = constant_time_select_8(mask, em[i + 11], to[i]); } OPENSSL_clear_free(em, num); diff --git a/crypto/rsa/rsa_sp800_56b_gen.c b/crypto/rsa/rsa_sp800_56b_gen.c index 221136bd..50c5bf14 100644 --- a/crypto/rsa/rsa_sp800_56b_gen.c +++ b/crypto/rsa/rsa_sp800_56b_gen.c @@ -71,7 +71,7 @@ int rsa_fips186_4_gen_prob_primes(RSA *rsa, BIGNUM *p1, BIGNUM *p2, if (!rsa_check_public_exponent(e)) { RSAerr(RSA_F_RSA_FIPS186_4_GEN_PROB_PRIMES, RSA_R_PUB_EXPONENT_OUT_OF_RANGE); - goto err; + return 0; } /* (Step 3) Determine strength and check rand generator strength is ok - diff --git a/crypto/rsa/rsa_ssl.c b/crypto/rsa/rsa_ssl.c index 3659d838..16bfe00d 100644 --- a/crypto/rsa/rsa_ssl.c +++ b/crypto/rsa/rsa_ssl.c @@ -141,25 +141,25 @@ int RSA_padding_check_SSLv23(unsigned char *to, int tlen, err = constant_time_select_int(mask | good, err, RSA_R_DATA_TOO_LARGE); /* - * Even though we can't fake result's length, we can pretend copying - * |tlen| bytes where |mlen| bytes would be real. Last |tlen| of |num| - * bytes are viewed as circular buffer with start at |tlen|-|mlen'|, - * where |mlen'| is "saturated" |mlen| value. Deducing information - * about failure or |mlen| would take attacker's ability to observe - * memory access pattern with byte granularity *as it occurs*. It - * should be noted that failure is indistinguishable from normal - * operation if |tlen| is fixed by protocol. + * Move the result in-place by |num|-11-|mlen| bytes to the left. + * Then if |good| move |mlen| bytes from |em|+11 to |to|. + * Otherwise leave |to| unchanged. + * Copy the memory back in a way that does not reveal the size of + * the data being copied via a timing side channel. This requires copying + * parts of the buffer multiple times based on the bits set in the real + * length. Clear bits do a non-copy with identical access pattern. + * The loop below has overall complexity of O(N*log(N)). */ tlen = constant_time_select_int(constant_time_lt(num - 11, tlen), num - 11, tlen); - msg_index = constant_time_select_int(good, msg_index, num - tlen); - mlen = num - msg_index; - for (mask = good, i = 0; i < tlen; i++) { - unsigned int equals = constant_time_eq(msg_index, num); - - msg_index -= tlen & equals; /* rewind at EOF */ - mask &= ~equals; /* mask = 0 at EOF */ - to[i] = constant_time_select_8(mask, em[msg_index++], to[i]); + for (msg_index = 1; msg_index < num - 11; msg_index <<= 1) { + mask = ~constant_time_eq(msg_index & (num - 11 - mlen), 0); + for (i = 11; i < num - msg_index; i++) + em[i] = constant_time_select_8(mask, em[i + msg_index], em[i]); + } + for (i = 0; i < tlen; i++) { + mask = good & constant_time_lt(i, mlen); + to[i] = constant_time_select_8(mask, em[i + 11], to[i]); } OPENSSL_clear_free(em, num); diff --git a/crypto/rsa/rsa_x931g.c b/crypto/rsa/rsa_x931g.c index 16017772..7a52083f 100644 --- a/crypto/rsa/rsa_x931g.c +++ b/crypto/rsa/rsa_x931g.c @@ -133,8 +133,7 @@ int RSA_X931_derive_ex(RSA *rsa, BIGNUM *p1, BIGNUM *p2, BIGNUM *q1, ret = 1; err: - if (ctx) - BN_CTX_end(ctx); + BN_CTX_end(ctx); BN_CTX_free(ctx); BN_CTX_free(ctx2); @@ -188,8 +187,7 @@ int RSA_X931_generate_key_ex(RSA *rsa, int bits, const BIGNUM *e, ok = 1; error: - if (ctx) - BN_CTX_end(ctx); + BN_CTX_end(ctx); BN_CTX_free(ctx); if (ok) diff --git a/crypto/threads_win.c b/crypto/threads_win.c index 47795435..73203834 100644 --- a/crypto/threads_win.c +++ b/crypto/threads_win.c @@ -24,11 +24,15 @@ CRYPTO_RWLOCK *CRYPTO_THREAD_lock_new(void) return NULL; } +#if !defined(_WIN32_WCE) /* 0x400 is the spin count value suggested in the documentation */ if (!InitializeCriticalSectionAndSpinCount(lock, 0x400)) { OPENSSL_free(lock); return NULL; } +#else + InitializeCriticalSection(lock); +#endif return lock; } diff --git a/crypto/trace.c b/crypto/trace.c index 613664c3..efcf8be7 100644 --- a/crypto/trace.c +++ b/crypto/trace.c @@ -119,7 +119,7 @@ struct trace_category_st { #define TRACE_CATEGORY_(name) { #name, OSSL_TRACE_CATEGORY_##name } static const struct trace_category_st trace_categories[] = { - TRACE_CATEGORY_(ANY), + TRACE_CATEGORY_(ALL), TRACE_CATEGORY_(TRACE), TRACE_CATEGORY_(INIT), TRACE_CATEGORY_(TLS), @@ -328,12 +328,11 @@ void ossl_trace_cleanup(void) int OSSL_trace_set_channel(int category, BIO *channel) { #ifndef OPENSSL_NO_TRACE - if (category < 0 || category >= OSSL_TRACE_CATEGORY_NUM - || !set_trace_data(category, SIMPLE_CHANNEL, &channel, NULL, NULL, - trace_attach_cb, trace_detach_cb)) - return 0; + if (category >= 0 && category < OSSL_TRACE_CATEGORY_NUM) + return set_trace_data(category, SIMPLE_CHANNEL, &channel, NULL, NULL, + trace_attach_cb, trace_detach_cb); #endif - return 1; + return 0; } #ifndef OPENSSL_NO_TRACE @@ -367,7 +366,7 @@ int OSSL_trace_set_callback(int category, OSSL_trace_cb callback, void *data) struct trace_data_st *trace_data = NULL; if (category < 0 || category >= OSSL_TRACE_CATEGORY_NUM) - goto err; + return 0; if (callback != NULL) { if ((channel = BIO_new(&trace_method)) == NULL @@ -386,41 +385,34 @@ int OSSL_trace_set_callback(int category, OSSL_trace_cb callback, void *data) trace_attach_w_callback_cb, trace_detach_cb)) goto err; - goto done; + return 1; err: BIO_free(channel); OPENSSL_free(trace_data); - return 0; - done: #endif - return 1; + + return 0; } int OSSL_trace_set_prefix(int category, const char *prefix) { - int rv = 1; - #ifndef OPENSSL_NO_TRACE - if (category >= 0 || category < OSSL_TRACE_CATEGORY_NUM) + if (category >= 0 && category < OSSL_TRACE_CATEGORY_NUM) return set_trace_data(category, 0, NULL, &prefix, NULL, trace_attach_cb, trace_detach_cb); - rv = 0; #endif - return rv; + return 0; } int OSSL_trace_set_suffix(int category, const char *suffix) { - int rv = 1; - #ifndef OPENSSL_NO_TRACE - if (category >= 0 || category < OSSL_TRACE_CATEGORY_NUM) + if (category >= 0 && category < OSSL_TRACE_CATEGORY_NUM) return set_trace_data(category, 0, NULL, NULL, &suffix, trace_attach_cb, trace_detach_cb); - rv = 0; #endif - return rv; + return 0; } #ifndef OPENSSL_NO_TRACE @@ -430,7 +422,7 @@ static int ossl_trace_get_category(int category) return -1; if (trace_channels[category].bio != NULL) return category; - return OSSL_TRACE_CATEGORY_ANY; + return OSSL_TRACE_CATEGORY_ALL; } #endif @@ -439,7 +431,8 @@ int OSSL_trace_enabled(int category) int ret = 0; #ifndef OPENSSL_NO_TRACE category = ossl_trace_get_category(category); - ret = trace_channels[category].bio != NULL; + if (category >= 0) + ret = trace_channels[category].bio != NULL; #endif return ret; } @@ -451,6 +444,9 @@ BIO *OSSL_trace_begin(int category) char *prefix = NULL; category = ossl_trace_get_category(category); + if (category < 0) + return NULL; + channel = trace_channels[category].bio; prefix = trace_channels[category].prefix; diff --git a/crypto/x509/t_x509.c b/crypto/x509/t_x509.c index 29e20939..33672288 100644 --- a/crypto/x509/t_x509.c +++ b/crypto/x509/t_x509.c @@ -284,7 +284,7 @@ int X509_signature_dump(BIO *bp, const ASN1_STRING *sig, int indent) s = sig->data; for (i = 0; i < n; i++) { if ((i % 18) == 0) { - if (BIO_write(bp, "\n", 1) <= 0) + if (i > 0 && BIO_write(bp, "\n", 1) <= 0) return 0; if (BIO_indent(bp, indent, indent) <= 0) return 0; @@ -302,11 +302,14 @@ int X509_signature_print(BIO *bp, const X509_ALGOR *sigalg, const ASN1_STRING *sig) { int sig_nid; - if (BIO_puts(bp, " Signature Algorithm: ") <= 0) + int indent = 4; + if (BIO_printf(bp, "%*sSignature Algorithm: ", indent, "") <= 0) return 0; if (i2a_ASN1_OBJECT(bp, sigalg->algorithm) <= 0) return 0; + if (sig && BIO_printf(bp, "\n%*sSignature Value:", indent, "") <= 0) + return 0; sig_nid = OBJ_obj2nid(sigalg->algorithm); if (sig_nid != NID_undef) { int pkey_nid, dig_nid; @@ -314,13 +317,13 @@ int X509_signature_print(BIO *bp, const X509_ALGOR *sigalg, if (OBJ_find_sigid_algs(sig_nid, &dig_nid, &pkey_nid)) { ameth = EVP_PKEY_asn1_find(NULL, pkey_nid); if (ameth && ameth->sig_print) - return ameth->sig_print(bp, sigalg, sig, 9, 0); + return ameth->sig_print(bp, sigalg, sig, indent + 4, 0); } } - if (sig) - return X509_signature_dump(bp, sig, 9); - else if (BIO_puts(bp, "\n") <= 0) + if (BIO_write(bp, "\n", 1) != 1) return 0; + if (sig) + return X509_signature_dump(bp, sig, indent + 4); return 1; } diff --git a/crypto/x509v3/v3_akey.c b/crypto/x509v3/v3_akey.c index 78218d56..b656b4b5 100644 --- a/crypto/x509v3/v3_akey.c +++ b/crypto/x509v3/v3_akey.c @@ -42,7 +42,7 @@ static STACK_OF(CONF_VALUE) *i2v_AUTHORITY_KEYID(X509V3_EXT_METHOD *method, char *tmp; if (akeyid->keyid) { tmp = OPENSSL_buf2hexstr(akeyid->keyid->data, akeyid->keyid->length); - X509V3_add_value("keyid", tmp, &extlist); + X509V3_add_value((akeyid->issuer || akeyid->serial) ? "keyid" : NULL, tmp, &extlist); OPENSSL_free(tmp); } if (akeyid->issuer) diff --git a/crypto/x509v3/v3_alt.c b/crypto/x509v3/v3_alt.c index 128c68b5..9b627e07 100644 --- a/crypto/x509v3/v3_alt.c +++ b/crypto/x509v3/v3_alt.c @@ -183,7 +183,6 @@ int GENERAL_NAME_print(BIO *out, GENERAL_NAME *gen) BIO_printf(out, ":%X", p[0] << 8 | p[1]); p += 2; } - BIO_puts(out, "\n"); } else { BIO_printf(out, "IP Address:"); break; diff --git a/crypto/x509v3/v3_cpols.c b/crypto/x509v3/v3_cpols.c index bfdaf0ac..595de623 100644 --- a/crypto/x509v3/v3_cpols.c +++ b/crypto/x509v3/v3_cpols.c @@ -403,12 +403,15 @@ static int i2r_certpol(X509V3_EXT_METHOD *method, STACK_OF(POLICYINFO) *pol, POLICYINFO *pinfo; /* First print out the policy OIDs */ for (i = 0; i < sk_POLICYINFO_num(pol); i++) { + if (i > 0) + BIO_puts(out, "\n"); pinfo = sk_POLICYINFO_value(pol, i); BIO_printf(out, "%*sPolicy: ", indent, ""); i2a_ASN1_OBJECT(out, pinfo->policyid); - BIO_puts(out, "\n"); - if (pinfo->qualifiers) + if (pinfo->qualifiers) { + BIO_puts(out, "\n"); print_qualifiers(out, pinfo->qualifiers, indent + 2); + } } return 1; } @@ -419,10 +422,12 @@ static void print_qualifiers(BIO *out, STACK_OF(POLICYQUALINFO) *quals, POLICYQUALINFO *qualinfo; int i; for (i = 0; i < sk_POLICYQUALINFO_num(quals); i++) { + if (i > 0) + BIO_puts(out, "\n"); qualinfo = sk_POLICYQUALINFO_value(quals, i); switch (OBJ_obj2nid(qualinfo->pqualid)) { case NID_id_qt_cps: - BIO_printf(out, "%*sCPS: %s\n", indent, "", + BIO_printf(out, "%*sCPS: %s", indent, "", qualinfo->d.cpsuri->data); break; @@ -435,7 +440,6 @@ static void print_qualifiers(BIO *out, STACK_OF(POLICYQUALINFO) *quals, BIO_printf(out, "%*sUnknown Qualifier: ", indent + 2, ""); i2a_ASN1_OBJECT(out, qualinfo->pqualid); - BIO_puts(out, "\n"); break; } } @@ -467,10 +471,11 @@ static void print_notice(BIO *out, USERNOTICE *notice, int indent) OPENSSL_free(tmp); } } - BIO_puts(out, "\n"); + if (notice->exptext) + BIO_puts(out, "\n"); } if (notice->exptext) - BIO_printf(out, "%*sExplicit Text: %s\n", indent, "", + BIO_printf(out, "%*sExplicit Text: %s", indent, "", notice->exptext->data); } @@ -484,8 +489,10 @@ void X509_POLICY_NODE_print(BIO *out, X509_POLICY_NODE *node, int indent) BIO_puts(out, "\n"); BIO_printf(out, "%*s%s\n", indent + 2, "", node_data_critical(dat) ? "Critical" : "Non Critical"); - if (dat->qualifier_set) + if (dat->qualifier_set) { print_qualifiers(out, dat->qualifier_set, indent + 2); + BIO_puts(out, "\n"); + } else BIO_printf(out, "%*sNo Qualifiers\n", indent + 2, ""); } diff --git a/crypto/x509v3/v3_crld.c b/crypto/x509v3/v3_crld.c index 5d290acb..766bf0e5 100644 --- a/crypto/x509v3/v3_crld.c +++ b/crypto/x509v3/v3_crld.c @@ -410,9 +410,10 @@ static int print_gens(BIO *out, STACK_OF(GENERAL_NAME) *gens, int indent) { int i; for (i = 0; i < sk_GENERAL_NAME_num(gens); i++) { + if (i > 0) + BIO_puts(out, "\n"); BIO_printf(out, "%*s", indent + 2, ""); GENERAL_NAME_print(out, sk_GENERAL_NAME_value(gens, i)); - BIO_puts(out, "\n"); } return 1; } @@ -463,7 +464,8 @@ static int i2r_crldp(const X509V3_EXT_METHOD *method, void *pcrldp, BIO *out, DIST_POINT *point; int i; for (i = 0; i < sk_DIST_POINT_num(crld); i++) { - BIO_puts(out, "\n"); + if (i > 0) + BIO_puts(out, "\n"); point = sk_DIST_POINT_value(crld, i); if (point->distpoint) print_distpoint(out, point->distpoint, indent); diff --git a/crypto/x509v3/v3_ncons.c b/crypto/x509v3/v3_ncons.c index d16c6eeb..9a8ca166 100644 --- a/crypto/x509v3/v3_ncons.c +++ b/crypto/x509v3/v3_ncons.c @@ -158,6 +158,8 @@ static int i2r_NAME_CONSTRAINTS(const X509V3_EXT_METHOD *method, void *a, NAME_CONSTRAINTS *ncons = a; do_i2r_name_constraints(method, ncons->permittedSubtrees, bp, ind, "Permitted"); + if (ncons->permittedSubtrees && ncons->excludedSubtrees) + BIO_puts(bp, "\n"); do_i2r_name_constraints(method, ncons->excludedSubtrees, bp, ind, "Excluded"); return 1; @@ -172,13 +174,14 @@ static int do_i2r_name_constraints(const X509V3_EXT_METHOD *method, if (sk_GENERAL_SUBTREE_num(trees) > 0) BIO_printf(bp, "%*s%s:\n", ind, "", name); for (i = 0; i < sk_GENERAL_SUBTREE_num(trees); i++) { + if (i > 0) + BIO_puts(bp, "\n"); tree = sk_GENERAL_SUBTREE_value(trees, i); BIO_printf(bp, "%*s", ind + 2, ""); if (tree->base->type == GEN_IPADD) print_nc_ipadd(bp, tree->base->d.ip); else GENERAL_NAME_print(bp, tree->base); - BIO_puts(bp, "\n"); } return 1; } diff --git a/crypto/x509v3/v3_pci.c b/crypto/x509v3/v3_pci.c index c0c599bf..856b70d9 100644 --- a/crypto/x509v3/v3_pci.c +++ b/crypto/x509v3/v3_pci.c @@ -75,9 +75,8 @@ static int i2r_pci(X509V3_EXT_METHOD *method, PROXY_CERT_INFO_EXTENSION *pci, BIO_puts(out, "\n"); BIO_printf(out, "%*sPolicy Language: ", indent, ""); i2a_ASN1_OBJECT(out, pci->proxyPolicy->policyLanguage); - BIO_puts(out, "\n"); if (pci->proxyPolicy->policy && pci->proxyPolicy->policy->data) - BIO_printf(out, "%*sPolicy Text: %s\n", indent, "", + BIO_printf(out, "\n%*sPolicy Text: %s", indent, "", pci->proxyPolicy->policy->data); return 1; } diff --git a/crypto/x509v3/v3_prn.c b/crypto/x509v3/v3_prn.c index 24e73a7e..2ef76c1b 100644 --- a/crypto/x509v3/v3_prn.c +++ b/crypto/x509v3/v3_prn.c @@ -34,8 +34,11 @@ void X509V3_EXT_val_prn(BIO *out, STACK_OF(CONF_VALUE) *val, int indent, BIO_puts(out, "\n"); } for (i = 0; i < sk_CONF_VALUE_num(val); i++) { - if (ml) + if (ml) { + if (i > 0) + BIO_printf(out, "\n"); BIO_printf(out, "%*s", indent, ""); + } else if (i > 0) BIO_printf(out, ", "); nval = sk_CONF_VALUE_value(val, i); @@ -59,8 +62,6 @@ void X509V3_EXT_val_prn(BIO *out, STACK_OF(CONF_VALUE) *val, int indent, } } #endif - if (ml) - BIO_puts(out, "\n"); } } diff --git a/doc/internal/man3/evp_generic_fetch.pod b/doc/internal/man3/evp_generic_fetch.pod new file mode 100644 index 00000000..b871cd1f --- /dev/null +++ b/doc/internal/man3/evp_generic_fetch.pod @@ -0,0 +1,232 @@ +=pod + +=head1 NAME + +evp_generic_fetch - generic algorithm fetcher and method creator for EVP + +=head1 SYNOPSIS + + /* Only for EVP source */ + #include "evp_locl.h" + + void *evp_generic_fetch(OPENSSL_CTX *libctx, int operation_id, + const char *algorithm, const char *properties, + void *(*new_method)(int nid, const OSSL_DISPATCH *fns, + OSSL_PROVIDER *prov), + int (*upref_method)(void *), + void (*free_method)(void *)); + +=head1 DESCRIPTION + +evp_generic_fetch() calls ossl_method_construct() with the given +C, C, C, and C and uses +it to create an EVP method with the help of the functions +C, C, and C. + +The three functions are supposed to: + +=over 4 + +=item new_method() + +creates an internal method from function pointers found in the +dispatch table C. + +=item upref_method() + +increments the reference counter for the given method, if there is +one. + +=item free_method() + +frees the given method. + +=back + +=head1 RETURN VALUES + +evp_generic_fetch() returns a method on success, or B on error. + +=head1 EXAMPLES + +This is a short example of the fictitious EVP API and operation called +C. + +To begin with, let's assume something like this in +C: + + #define OSSL_OP_FOO 100 + + #define OSSL_OP_FOO_NEWCTX_FUNC 2001 + #define OSSL_OP_FOO_INIT 2002 + #define OSSL_OP_FOO_OPERATE 2003 + #define OSSL_OP_FOO_CLEANCTX_FUNC 2004 + #define OSSL_OP_FOO_FREECTX_FUNC 2005 + OSSL_CORE_MAKE_FUNC(void *,OP_foo_newctx,(void)) + OSSL_CORE_MAKE_FUNC(int,OP_foo_init,(void *vctx)) + OSSL_CORE_MAKE_FUNC(int,OP_foo_operate,(void *vctx, + unsigned char *out, size_t *out_l, + unsigned char *in, size_t in_l)) + OSSL_CORE_MAKE_FUNC(void,OP_foo_cleanctx,(void *vctx)) + OSSL_CORE_MAKE_FUNC(void,OP_foo_freectx,(void *vctx)) + +And here's the implementation of the FOO method fetcher: + + /* typedef struct evp_foo_st EVP_FOO */ + struct evp_foo_st { + OSSL_PROVIDER *prov; + int nid; + CRYPTO_REF_COUNT refcnt; + OSSL_OP_foo_newctx_fn *newctx; + OSSL_OP_foo_init_fn *init; + OSSL_OP_foo_operate_fn *operate; + OSSL_OP_foo_cleanctx_fn *cleanctx; + OSSL_OP_foo_freectx_fn *freectx; + }; + + /* + * In this example, we have a public method creator and destructor. + * It's not absolutely necessary, but is in the spirit of OpenSSL. + */ + EVP_FOO *EVP_FOO_meth_from_dispatch(int foo_type, const OSSL_DISPATCH *fns, + OSSL_PROVIDER *prov) + { + EVP_FOO *foo = NULL; + + if ((foo = OPENSSL_zalloc(sizeof(*foo))) == NULL) + return NULL; + + for (; fns->function_id != 0; fns++) { + switch (fns->function_id) { + case OSSL_OP_FOO_NEWCTX_FUNC: + foo->newctx = OSSL_get_OP_foo_newctx(fns); + break; + case OSSL_OP_FOO_INIT: + foo->init = OSSL_get_OP_foo_init(fns); + break; + case OSSL_OP_FOO_OPERATE: + foo->operate = OSSL_get_OP_foo_operate(fns); + break; + case OSSL_OP_FOO_CLEANCTX_FUNC: + foo->cleanctx = OSSL_get_OP_foo_cleanctx(fns); + break; + case OSSL_OP_FOO_FREECTX_FUNC: + foo->freectx = OSSL_get_OP_foo_freectx(fns); + break; + } + } + foo->nid = foo_type; + foo->prov = prov; + if (prov) + ossl_provider_upref(prov); + + return foo; + } + + EVP_FOO_meth_free(EVP_FOO *foo) + { + if (foo != NULL) { + OSSL_PROVIDER *prov = foo->prov; + + OPENSSL_free(foo); + ossl_provider_free(prov); + } + } + + static void *foo_from_dispatch(int nid, const OSSL_DISPATCH *fns, + OSSL_PROVIDER *prov) + { + return EVP_FOO_meth_from_dispatch(nid, fns, prov); + } + + static int foo_upref(void *vfoo) + { + EVP_FOO *foo = vfoo; + int ref = 0; + + CRYPTO_UP_REF(&foo->refcnt, &ref, foo_lock); + return 1; + } + + static void foo_free(void *vfoo) + { + EVP_FOO_meth_free(vfoo); + } + + EVP_FOO *EVP_FOO_fetch(OPENSSL_CTX *ctx, + const char *algorithm, + const char *properties) + { + return evp_generic_fetch(ctx, OSSL_OP_FOO, algorithm, properties, + foo_from_dispatch, foo_upref, foo_free); + } + +And finally, the library functions: + + /* typedef struct evp_foo_st EVP_FOO_CTX */ + struct evp_foo_ctx_st { + const EVP_FOO *foo; + void *provctx; /* corresponding provider context */ + }; + + int EVP_FOO_CTX_reset(EVP_FOO_CTX *c) + { + if (c == NULL) + return 1; + if (c->foo != NULL && c->foo->cleanctx != NULL) + c->foo->cleanctx(c->provctx); + return 1; + } + + EVP_FOO_CTX *EVP_FOO_CTX_new(void) + { + return OPENSSL_zalloc(sizeof(EVP_FOO_CTX)); + } + + void EVP_FOO_CTX_free(EVP_FOO_CTX *c) + { + EVP_FOO_CTX_reset(c); + c->foo->freectx(c->provctx); + OPENSSL_free(c); + } + + int EVP_FooInit(EVP_FOO_CTX *c, const EVP_FOO *foo) + { + int ok = 1; + + c->foo = foo; + if (c->provctx == NULL) + c->provctx = c->foo->newctx(); + + ok = c->foo->init(c->provctx); + + return ok; + } + + int EVP_FooOperate(EVP_FOO_CTX *c, unsigned char *out, size_t *outl, + const unsigned char *in, size_t inl) + { + int ok = 1; + + ok = c->foo->update(c->provctx, out, inl, &outl, in, inl); + return ok; + } + +=head1 SEE ALSO + +L + +=head1 HISTORY + +The functions described here were all added in OpenSSL 3.0. + +=head1 COPYRIGHT + +Copyright 2019 The OpenSSL Project Authors. All Rights Reserved. + +Licensed under the Apache License 2.0 (the "License"). You may not use +this file except in compliance with the License. You can obtain a copy +in the file LICENSE in the source distribution or at +L. + +=cut diff --git a/doc/internal/man3/ossl_method_construct.pod b/doc/internal/man3/ossl_method_construct.pod index e91cfcd6..36646354 100644 --- a/doc/internal/man3/ossl_method_construct.pod +++ b/doc/internal/man3/ossl_method_construct.pod @@ -49,6 +49,11 @@ functions given by the sub-system specific method creator through C and the data in C (which is passed by ossl_method_construct()). +This function assumes that the sub-system method creator implements +reference counting and acts accordingly (i.e. it will call the +sub-system destruct() method to decrement the reference count when +appropriate). + =head2 Structures A central part of constructing a sub-system specific method is to give @@ -82,6 +87,8 @@ The method to be looked up should be identified with data from C (which is the C that was passed to ossl_construct_method()) and the provided property query C. +This function is expected to increment the method's reference count. + =item put() Places the C created by the construct() function (see below) @@ -96,6 +103,8 @@ The method should be associated with the given property definition C and any identification data given through C (which is the C that was passed to ossl_construct_method()). +This function is expected to increment the C's reference count. + =item construct() Constructs a sub-system method given a dispatch table C. @@ -106,9 +115,12 @@ is recommended. If such a reference is kept, the I reference counter must be incremented, using ossl_provider_upref(). +This function is expected to set the method's reference count to 1. + =item desctruct() -Destruct the given C. +Decrement the C's reference count, and destruct it when +the reference count reaches zero. =back diff --git a/doc/internal/man3/ossl_provider_new.pod b/doc/internal/man3/ossl_provider_new.pod index 7633e0e2..aa984c93 100644 --- a/doc/internal/man3/ossl_provider_new.pod +++ b/doc/internal/man3/ossl_provider_new.pod @@ -4,7 +4,8 @@ ossl_provider_find, ossl_provider_new, ossl_provider_upref, ossl_provider_free, ossl_provider_add_module_location, -ossl_provider_activate, ossl_provider_forall_loaded, +ossl_provider_set_fallback, ossl_provider_activate, +ossl_provider_forall_loaded, ossl_provider_name, ossl_provider_dso, ossl_provider_module_name, ossl_provider_module_path, ossl_provider_teardown, ossl_provider_get_param_types, @@ -23,6 +24,7 @@ ossl_provider_get_params, ossl_provider_query_operation /* Setters */ int ossl_provider_add_module_location(OSSL_PROVIDER *prov, const char *loc); + int ossl_provider_set_fallback(OSSL_PROVIDER *prov); /* Load and initialize the Provider */ int ossl_provider_activate(OSSL_PROVIDER *prov); @@ -71,7 +73,7 @@ times as ossl_provider_activate() has. ossl_provider_find() finds an existing I in the I store by C. -The I it finds gets it's reference count +The I it finds gets its reference count incremented. ossl_provider_new() creates a new I and stores it in @@ -84,14 +86,20 @@ To indicate a built-in provider, the C argument must point at the provider initialization function for that provider. ossl_provider_free() decrements a I's reference -counter; if it drops to one, the I will be -inactivated (it's teardown function is called) but kept in the store; -if it drops down to zero, the associated module will be unloaded if -one was loaded, and the I will be freed. +counter; if it drops below 2, the I is assumed to +have fallen out of use and will be inactivated (its teardown function +is called); if it drops down to zero, the I is +assumed to have been taken out of the store, and the associated module +will be unloaded if one was loaded, and the I will be +freed. ossl_provider_add_module_location() adds a location to look for a provider module. +ossl_provider_set_fallback() marks an available provider as fallback. +Note that after this call, the I pointer that was +used can simply be dropped, but not freed. + ossl_provider_activate() "activates" the provider for the given I. What "activates" means depends on what type of I it @@ -115,6 +123,8 @@ be located in that module, and called. ossl_provider_forall_loaded() iterates over all the currently "activated" providers, and calls C for each of them. +If no providers have been "activated" yet, it tries to activate all +available fallback providers and tries another iteration. ossl_provider_name() returns the name that was given with ossl_provider_new(). @@ -178,8 +188,8 @@ it has been incremented. ossl_provider_free() doesn't return any value. -ossl_provider_add_module_location() and ossl_provider_activate() -return 1 on success, or 0 on error. +ossl_provider_add_module_location(), ossl_provider_set_fallback() and +ossl_provider_activate() return 1 on success, or 0 on error. ossl_provider_name(), ossl_provider_dso(), ossl_provider_module_name(), and ossl_provider_module_path() return a diff --git a/doc/man1/ca.pod b/doc/man1/ca.pod index d1e5a996..6e90c334 100644 --- a/doc/man1/ca.pod +++ b/doc/man1/ca.pod @@ -51,6 +51,7 @@ B B [B<-engine id>] [B<-subj arg>] [B<-utf8>] +[B<-sigopt nm:v>] [B<-create_serial>] [B<-rand_serial>] [B<-multivalue-rdn>] @@ -134,6 +135,11 @@ The private key to sign requests with. The format of the data in the private key file. The default is PEM. +=item B<-sigopt nm:v> + +Pass options to the signature algorithm during sign or verify operations. +Names and values of these options are algorithm-specific. + =item B<-key password> The password used to encrypt the private key. Since on some @@ -753,7 +759,7 @@ L, L =head1 COPYRIGHT -Copyright 2000-2018 The OpenSSL Project Authors. All Rights Reserved. +Copyright 2000-2019 The OpenSSL Project Authors. All Rights Reserved. Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy diff --git a/doc/man1/dgst.pod b/doc/man1/dgst.pod index c745cfa9..0116a792 100644 --- a/doc/man1/dgst.pod +++ b/doc/man1/dgst.pod @@ -22,6 +22,7 @@ B [B<-verify filename>] [B<-prverify filename>] [B<-signature filename>] +[B<-sigopt nm:v>] [B<-hmac key>] [B<-fips-fingerprint>] [B<-rand file...>] @@ -78,7 +79,8 @@ Output the digest or signature in binary form. =item B<-r> -Output the digest in the "coreutils" format used by programs like B. +Output the digest in the "coreutils" format, including newlines. +Used by programs like B. =item B<-out filename> @@ -235,7 +237,7 @@ The FIPS-related options were removed in OpenSSL 1.1.0. =head1 COPYRIGHT -Copyright 2000-2018 The OpenSSL Project Authors. All Rights Reserved. +Copyright 2000-2019 The OpenSSL Project Authors. All Rights Reserved. Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy diff --git a/doc/man1/pkeyutl.pod b/doc/man1/pkeyutl.pod index 13af3277..033360f4 100644 --- a/doc/man1/pkeyutl.pod +++ b/doc/man1/pkeyutl.pod @@ -296,20 +296,19 @@ value less than the minimum restriction. =head1 DSA ALGORITHM The DSA algorithm supports signing and verification operations only. Currently -there are no additional options other than B. Only the SHA1 -digest can be used and this digest is assumed by default. +there are no additional B<-pkeyopt> options other than B. The SHA1 +digest is assumed by default. =head1 DH ALGORITHM The DH algorithm only supports the derivation operation and no additional -options. +B<-pkeyopt> options. =head1 EC ALGORITHM The EC algorithm supports sign, verify and derive operations. The sign and -verify operations use ECDSA and derive uses ECDH. Currently there are no -additional options other than B. Only the SHA1 digest can be used and -this digest is assumed by default. +verify operations use ECDSA and derive uses ECDH. SHA1 is assumed by default for +the B<-pkeyopt> B option. =head1 X25519 and X448 ALGORITHMS diff --git a/doc/man1/req.pod b/doc/man1/req.pod index 35176270..8f30bd79 100644 --- a/doc/man1/req.pod +++ b/doc/man1/req.pod @@ -46,6 +46,7 @@ B B [B<-reqopt>] [B<-subject>] [B<-subj arg>] +[B<-sigopt nm:v>] [B<-batch>] [B<-verbose>] [B<-engine id>] @@ -82,6 +83,11 @@ This specifies the input filename to read a request from or standard input if this option is not specified. A request is only read if the creation options (B<-new> and B<-newkey>) are not specified. +=item B<-sigopt nm:v> + +Pass options to the signature algorithm during sign or verify operations. +Names and values of these options are algorithm-specific. + =item B<-passin arg> The input file password source. For more information about the format of B @@ -689,7 +695,7 @@ L =head1 COPYRIGHT -Copyright 2000-2018 The OpenSSL Project Authors. All Rights Reserved. +Copyright 2000-2019 The OpenSSL Project Authors. All Rights Reserved. Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy diff --git a/doc/man1/s_client.pod b/doc/man1/s_client.pod index e1a71d17..e42a6ba6 100644 --- a/doc/man1/s_client.pod +++ b/doc/man1/s_client.pod @@ -559,7 +559,7 @@ further information). =item B<-bugs> -There are several known bug in SSL and TLS implementations. Adding this +There are several known bugs in SSL and TLS implementations. Adding this option enables various workarounds. =item B<-comp> @@ -763,10 +763,6 @@ End the current SSL connection and exit. Renegotiate the SSL session (TLSv1.2 and below only). -=item B - -Send a heartbeat message to the server (DTLS only) - =item B Send a key update message to the server (TLSv1.3 only) diff --git a/doc/man1/s_server.pod b/doc/man1/s_server.pod index b15ccdf1..d28feb98 100644 --- a/doc/man1/s_server.pod +++ b/doc/man1/s_server.pod @@ -542,7 +542,7 @@ OpenSSL was built. =item B<-bugs> -There are several known bug in SSL and TLS implementations. Adding this +There are several known bugs in SSL and TLS implementations. Adding this option enables various workarounds. =item B<-no_comp> @@ -783,10 +783,6 @@ cause the client to disconnect due to a protocol violation. Print out some session cache status information. -=item B - -Send a heartbeat message to the client (DTLS only) - =item B Send a key update message to the client (TLSv1.3 only) diff --git a/doc/man1/s_time.pod b/doc/man1/s_time.pod index b5e74ccd..ce626426 100644 --- a/doc/man1/s_time.pod +++ b/doc/man1/s_time.pod @@ -127,7 +127,7 @@ OpenSSL was built. =item B<-bugs> -There are several known bug in SSL and TLS implementations. Adding this +There are several known bugs in SSL and TLS implementations. Adding this option enables various workarounds. =item B<-cipher cipherlist> diff --git a/doc/man1/ts.pod b/doc/man1/ts.pod index 078905a8..38ecffcb 100644 --- a/doc/man1/ts.pod +++ b/doc/man1/ts.pod @@ -262,7 +262,7 @@ specified, the argument is given to the engine as a key identifier. =item B<-I> Signing digest to use. Overrides the B config file -option. (Optional) +option. (Mandatory unless specified in the config file) =item B<-chain> certs_file.pem @@ -460,7 +460,8 @@ command line option. (Optional) =item B Signing digest to use. The same as the -B<-I> command line option. (Optional) +B<-I> command line option. (Mandatory unless specified on the command +line) =item B diff --git a/doc/man1/verify.pod b/doc/man1/verify.pod index 6465fd8b..10fd8486 100644 --- a/doc/man1/verify.pod +++ b/doc/man1/verify.pod @@ -50,6 +50,8 @@ B B [B<-verify_name name>] [B<-x509_strict>] [B<-show_chain>] +[B<-sm2-id string>] +[B<-sm2-hex-id hex-string>] [B<->] [certificates] @@ -316,6 +318,16 @@ Display information about the certificate chain that has been built (if successful). Certificates in the chain that came from the untrusted list will be flagged as "untrusted". +=item B<-sm2-id> + +Specify the ID string to use when verifying an SM2 certificate. The ID string is +required by the SM2 signature algorithm for signing and verification. + +=item B<-sm2-hex-id> + +Specify a binary ID string to use when signing or verifying using an SM2 +certificate. The argument for this option is string of hexadecimal digits. + =item B<-> Indicates the last option. All arguments following this are assumed to be @@ -767,9 +779,11 @@ The B<-show_chain> option was added in OpenSSL 1.1.0. The B<-issuer_checks> option is deprecated as of OpenSSL 1.1.0 and is silently ignored. +The B<-sm2-id> and B<-sm2-hex-id> options were added in OpenSSL 3.0.0. + =head1 COPYRIGHT -Copyright 2000-2017 The OpenSSL Project Authors. All Rights Reserved. +Copyright 2000-2019 The OpenSSL Project Authors. All Rights Reserved. Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy diff --git a/doc/man1/x509.pod b/doc/man1/x509.pod index 251e3f7a..ed03928d 100644 --- a/doc/man1/x509.pod +++ b/doc/man1/x509.pod @@ -52,7 +52,9 @@ B B [B<-CAkey filename>] [B<-CAcreateserial>] [B<-CAserial filename>] +[B<-new>] [B<-force_pubkey filename>] +[B<-subj arg>] [B<-text>] [B<-ext extensions>] [B<-certopt option>] @@ -61,6 +63,7 @@ B B [B<-clrext>] [B<-extfile filename>] [B<-extensions section>] +[B<-sigopt nm:v>] [B<-rand file...>] [B<-writerand file>] [B<-engine id>] @@ -362,6 +365,11 @@ and the end date to a value determined by the B<-days> option. It retains any certificate extensions unless the B<-clrext> option is supplied; this includes, for example, any existing key identifier extensions. +=item B<-sigopt nm:v> + +Pass options to the signature algorithm during sign or verify operations. +Names and values of these options are algorithm-specific. + =item B<-passin arg> The key password source. For more information about the format of B @@ -454,15 +462,39 @@ specified then the extensions should either be contained in the unnamed L manual page for details of the extension section format. +=item B<-new> + +Generate a certificate from scratch, not using an input certificate +or certificate request. So the B<-in> option must not be used in this case. +Instead, the B<-subj> and <-force_pubkey> options need to be given. + =item B<-force_pubkey filename> When a certificate is created set its public key to the key in B instead of the key contained in the input or given with the B<-signkey> option. + This option is useful for creating self-issued certificates that are not self-signed, for instance when the key cannot be used for signing, such as DH. +It can also be used in conjunction with b<-new> and B<-subj> to directly +generate a certificate containing any desired public key. The format of the key file can be specified using the B<-keyform> option. +=item B<-subj arg> + +When a certificate is created set its subject name to the given value. +The arg must be formatted as I. +Keyword characters may be escaped by \ (backslash), and whitespace is retained. +Empty values are permitted, but the corresponding type will not be included +in the certificate. Giving a single I will lead to an empty sequence of RDNs +(a NULL subject DN). + +Unless the B<-CA> option is given the issuer is set to the same value. + +This option can be used in conjunction with the B<-force_pubkey> option +to create a certificate even without providing an input certificate +or certificate request. + =back =head2 Name Options @@ -922,7 +954,7 @@ the old form must have their links rebuilt using B or similar. =head1 COPYRIGHT -Copyright 2000-2018 The OpenSSL Project Authors. All Rights Reserved. +Copyright 2000-2019 The OpenSSL Project Authors. All Rights Reserved. Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy diff --git a/doc/man3/BN_CTX_start.pod b/doc/man3/BN_CTX_start.pod index bf3a8b59..d4780fe9 100644 --- a/doc/man3/BN_CTX_start.pod +++ b/doc/man3/BN_CTX_start.pod @@ -27,6 +27,7 @@ calls must be made before calling any other functions that use the B as an argument. Finally, BN_CTX_end() must be called before returning from the function. +If B is NULL, nothing is done. When BN_CTX_end() is called, the B pointers obtained from BN_CTX_get() become invalid. diff --git a/doc/man3/BN_new.pod b/doc/man3/BN_new.pod index e3800b82..e7269e01 100644 --- a/doc/man3/BN_new.pod +++ b/doc/man3/BN_new.pod @@ -27,6 +27,7 @@ OPENSSL_secure_malloc(3) is used to store the value. BN_clear() is used to destroy sensitive data such as keys when they are no longer needed. It erases the memory used by B and sets it to the value 0. +If B is NULL, nothing is done. BN_free() frees the components of the B, and if it was created by BN_new(), also the structure itself. BN_clear_free() additionally diff --git a/doc/man3/EVP_KDF_CTX.pod b/doc/man3/EVP_KDF_CTX.pod index b01c719c..4ca8d94b 100644 --- a/doc/man3/EVP_KDF_CTX.pod +++ b/doc/man3/EVP_KDF_CTX.pod @@ -135,6 +135,17 @@ EVP_KDF_ctrl_str() type string: "iter" The value string is expected to be a decimal number. +=item B + +This control expects one argument: C + +Some KDF implementations use a MAC as an underlying computation +algorithm, this control sets what the MAC algorithm should be. + +EVP_KDF_ctrl_str() type string: "mac" + +The value string is expected to be the name of a MAC. + =item B This control expects one argument: C @@ -168,6 +179,19 @@ decoded before being passed on as the control value. =back +=item B + +This control expects one argument: C + +Used by implementations that use a MAC with a variable output size (KMAC). For +those KDF implementations that support it, this control sets the MAC output size. + +The default value, if any, is implementation dependent. + +EVP_KDF_ctrl_str() type string: "outlen" + +The value string is expected to be a decimal number. + =item B This control expects one argument: C @@ -204,10 +228,18 @@ supported by the KDF algorithm. =head1 SEE ALSO L +L +L +L +L + +=head1 HISTORY + +This functionality was added to OpenSSL 3.0.0. =head1 COPYRIGHT -Copyright 2018 The OpenSSL Project Authors. All Rights Reserved. +Copyright 2019 The OpenSSL Project Authors. All Rights Reserved. Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy diff --git a/doc/man3/EVP_MAC.pod b/doc/man3/EVP_MAC.pod index 32bf5896..a55d8db2 100644 --- a/doc/man3/EVP_MAC.pod +++ b/doc/man3/EVP_MAC.pod @@ -202,6 +202,9 @@ For MAC implementations that use an underlying computation algorithm, these controls set what the algorithm should be, and the engine that implements the algorithm if needed. +Note that not all algorithms may support all digests. HMAC does not support +variable output length digests such as SHAKE128 or SHAKE256. + B takes one argument: C B takes one argument: C diff --git a/doc/man3/EVP_MD_fetch.pod b/doc/man3/EVP_MD_fetch.pod new file mode 100644 index 00000000..17481089 --- /dev/null +++ b/doc/man3/EVP_MD_fetch.pod @@ -0,0 +1,162 @@ +=pod + +=head1 NAME + +EVP_MD_fetch +- Functions to explicitly fetch algorithm implementations + +=head1 SYNOPSIS + + #include + + EVP_MD *EVP_MD_fetch(OPENSSL_CTX *ctx, const char *algorithm, + const char *properties); + +=head1 DESCRIPTION + +The B object is used for representing a digest method implementation. + +Having obtained a digest implementation as an B type it can be used to +calculate the digest of input data using functions such as +L, L and L. + +Digest implementations may be obtained in one of three ways, i.e. implicit +lookup, explicit lookup or user defined. + +=over 4 + +=item Implicit Lookup + +With implicit lookup an application can use functions such as L, +L or L to obtain an B object. When +used in a function like L the actual implementation to +be used will be fetched implicitly using default search criteria. Typically, +(unless the default search criteria have been changed and/or different providers +have been loaded), this will return an implementation of the appropriate +algorithm from the default provider. + +=item Explicit Lookup + +With explicit lookup an application uses the EVP_MD_fetch() function to obtain +an algorithm implementation. An implementation with the given name and +satisfying the search criteria specified in the B parameter will be +looked for within the available providers and returned. See L +for information about providers. + +=item User defined + +Using the user defined approach an application constructs its own EVP_MD object. +See L for details. + +=back + +The EVP_MD_fetch() function will look for an algorithm within the providers that +have been loaded into the B given in the B parameter. This +parameter may be NULL in which case the default B will be used. See +L and L for further details. + +The B parameter gives the name of the algorithm to be looked up. +Different algorithms can be made available by loading different providers. The +built-in default provider algorithm implementation names are: SHA1, SHA224, +SHA256, SHA384, SHA512, SHA512-224, SHA512-256,SHA3-224, SHA3-256, SHA3-384, +SHA3-512, SHAKE128, SHAKE256, SM3, BLAKE2b512, BLAKE2s256 and MD5-SHA1. + +Additional algorithm implementations may be obtained by loading the "legacy" +provider. The names of these algorithms are: RIPEMD160, MD2, MD4, MD5, MDC2 and +whirlpool. + +The B parameter specifies the search criteria that will be used to +look for an algorithm implementation. Properties are given as a comma delimited +string of name value pairs. In order for an implementation to match, all the +properties in the query string must match those defined for that implementation. +Any properties defined by an implementation but not given in the query string +are ignored. All algorithm implementations in the default provider have the +property "default=yes". All algorithm implementations in the legacy provider have +the property "legacy=yes". All algorithm implementations in the FIPS provider +have the property "fips=yes". In the event that more than one implementation +of the given algorithm name matches the specified properties then an unspecified +one of those implementations may be returned. The B parameter may be +NULL in which case any implementation from the available providers with the +given algorithm name will be returned. + +The return value from a call to EVP_MD_fetch() must be freed by the caller using +L. Note that EVP_MD objects are reference counted. See +L. + +=head1 RETURN VALUES + +EVP_MD_fetch() returns a pointer to the algorithm implementation represented by +an EVP_MD object, or NULL on error. + +=head1 EXAMPLES + +Fetch any available implementation of SHA256 in the default context: + + EVP_MD *md = EVP_MD_fetch(NULL, "SHA256", NULL); + +Fetch an implementation of SHA256 from the default provider in the default +context: + + EVP_MD *md = EVP_MD_fetch(NULL, "SHA256", "default=yes"); + ... + EVP_MD_meth_free(md); + +Fetch an implementation of SHA256 that is not from the default provider in the +default context: + + EVP_MD *md = EVP_MD_fetch(NULL, "SHA256", "default=no"); + ... + EVP_MD_meth_free(md); + +Fetch an implementation of SHA256 from the default provider in the specified +context: + + EVP_MD *md = EVP_MD_fetch(ctx, "SHA256", "default=yes"); + ... + EVP_MD_meth_free(md); + +Load the legacy provider into the default context and then fetch an +implementation of whirlpool from it: + + /* This only needs to be done once - usually at application start up */ + OSSL_PROVIDER *legacy = OSSL_PROVIDER_load(NULL, "legacy"); + + EVP_MD *md = EVP_MD_fetch(NULL, "whirlpool", "legacy=yes"); + ... + EVP_MD_meth_free(md); + +Note that in the above example the property string "legacy=yes" is optional +since, assuming no other providers have been loaded, the only implmentation of +the "whirlpool" algorithm is in the "legacy" provider. Also note that the +default provider should be explicitly loaded if it is required in addition to +other providers: + + /* This only needs to be done once - usually at application start up */ + OSSL_PROVIDER *legacy = OSSL_PROVIDER_load(NULL, "legacy"); + OSSL_PROVIDER *default = OSSL_PROVIDER_load(NULL, "default"); + + EVP_MD *md_whirlpool = EVP_MD_fetch(NULL, "whirlpool", NULL); + EVP_MD *md_sha256 = EVP_MD_fetch(NULL, "SHA256", NULL); + ... + EVP_MD_meth_free(md_whirlpool); + EVP_MD_meth_free(md_sha256); + +=head1 SEE ALSO + +L, L, L, +L, L, L + +=head1 HISTORY + +The functions described here were added in OpenSSL 3.0. + +=head1 COPYRIGHT + +Copyright 2019 The OpenSSL Project Authors. All Rights Reserved. + +Licensed under the Apache License 2.0 (the "License"). You may not use +this file except in compliance with the License. You can obtain a copy +in the file LICENSE in the source distribution or at +L. + +=cut diff --git a/doc/man3/EVP_MD_meth_new.pod b/doc/man3/EVP_MD_meth_new.pod index f4ac92d5..6269a05c 100644 --- a/doc/man3/EVP_MD_meth_new.pod +++ b/doc/man3/EVP_MD_meth_new.pod @@ -11,7 +11,7 @@ EVP_MD_meth_set_ctrl, EVP_MD_meth_get_input_blocksize, EVP_MD_meth_get_result_size, EVP_MD_meth_get_app_datasize, EVP_MD_meth_get_flags, EVP_MD_meth_get_init, EVP_MD_meth_get_update, EVP_MD_meth_get_final, EVP_MD_meth_get_copy, EVP_MD_meth_get_cleanup, -EVP_MD_meth_get_ctrl +EVP_MD_meth_get_ctrl, EVP_MD_upref - Routines to build up EVP_MD methods =head1 SYNOPSIS @@ -54,17 +54,21 @@ EVP_MD_meth_get_ctrl int (*EVP_MD_meth_get_ctrl(const EVP_MD *md))(EVP_MD_CTX *ctx, int cmd, int p1, void *p2); + int EVP_MD_upref(EVP_MD *md); + =head1 DESCRIPTION The B type is a structure for digest method implementation. It can also have associated public/private key signing and verifying routines. -EVP_MD_meth_new() creates a new B structure. +EVP_MD_meth_new() creates a new B structure. Note that B +structures are reference counted. EVP_MD_meth_dup() creates a copy of B. -EVP_MD_meth_free() destroys a B structure. +EVP_MD_meth_free() decrements the reference count for the B structure. +If the reference count drops to 0 then the structure is freed. EVP_MD_meth_set_input_blocksize() sets the internal input block size for the method B to B bytes. @@ -158,6 +162,8 @@ EVP_MD_meth_get_cleanup() and EVP_MD_meth_get_ctrl() are all used to retrieve the method data given with the EVP_MD_meth_set_*() functions above. +EVP_MD_upref() increments the reference count for an EVP_MD structure. + =head1 RETURN VALUES EVP_MD_meth_new() and EVP_MD_meth_dup() return a pointer to a newly @@ -169,6 +175,8 @@ indicated sizes or flags. All other EVP_CIPHER_meth_get_*() functions return pointers to their respective B function. +EVP_MD_upref() returns 1 for success or 0 otherwise. + =head1 SEE ALSO L, L, L @@ -176,7 +184,8 @@ L, L, L =head1 HISTORY The B structure was openly available in OpenSSL before version -1.1. The functions described here were added in OpenSSL 1.1. +1.1. EVP_MD_upref() was added in OpenSSL 3.0. All other functions described +here were added in OpenSSL 1.1. =head1 COPYRIGHT diff --git a/doc/man3/EVP_PKEY_set1_RSA.pod b/doc/man3/EVP_PKEY_set1_RSA.pod index 6363162c..8f4d7f54 100644 --- a/doc/man3/EVP_PKEY_set1_RSA.pod +++ b/doc/man3/EVP_PKEY_set1_RSA.pod @@ -9,7 +9,7 @@ EVP_PKEY_assign_RSA, EVP_PKEY_assign_DSA, EVP_PKEY_assign_DH, EVP_PKEY_assign_EC_KEY, EVP_PKEY_assign_POLY1305, EVP_PKEY_assign_SIPHASH, EVP_PKEY_get0_hmac, EVP_PKEY_get0_poly1305, EVP_PKEY_get0_siphash, EVP_PKEY_type, EVP_PKEY_id, EVP_PKEY_base_id, EVP_PKEY_set_alias_type, -EVP_PKEY_set1_engine - EVP_PKEY assignment functions +EVP_PKEY_set1_engine, EVP_PKEY_get0_engine - EVP_PKEY assignment functions =head1 SYNOPSIS @@ -45,6 +45,7 @@ EVP_PKEY_set1_engine - EVP_PKEY assignment functions int EVP_PKEY_type(int type); int EVP_PKEY_set_alias_type(EVP_PKEY *pkey, int type); + ENGINE *EVP_PKEY_get0_engine(const EVP_PKEY *pkey); int EVP_PKEY_set1_engine(EVP_PKEY *pkey, ENGINE *engine); =head1 DESCRIPTION @@ -81,6 +82,8 @@ often seen in practice. EVP_PKEY_type() returns the underlying type of the NID B. For example EVP_PKEY_type(EVP_PKEY_RSA2) will return B. +EVP_PKEY_get0_engine() returns a reference to the ENGINE handling B. + EVP_PKEY_set1_engine() sets the ENGINE handling B to B. It must be called after the key algorithm and components are set up. If B does not include an B for B an diff --git a/doc/man3/HMAC.pod b/doc/man3/HMAC.pod index 10a72506..a9bcd0e6 100644 --- a/doc/man3/HMAC.pod +++ b/doc/man3/HMAC.pod @@ -63,7 +63,9 @@ If B is NULL, the digest is placed in a static array. The size of the output is placed in B, unless it is B. Note: passing a NULL value for B to use the static array is not thread safe. -B can be EVP_sha1(), EVP_ripemd160() etc. +B is a message digest such as EVP_sha1(), EVP_ripemd160() etc. HMAC does +not support variable output length digests such as EVP_shake128() and +EVP_shake256(). HMAC_CTX_new() creates a new HMAC_CTX in heap memory. diff --git a/doc/man3/OCSP_cert_to_id.pod b/doc/man3/OCSP_cert_to_id.pod index 34b6aeeb..c9c932fc 100644 --- a/doc/man3/OCSP_cert_to_id.pod +++ b/doc/man3/OCSP_cert_to_id.pod @@ -19,8 +19,8 @@ OCSP_id_cmp, OCSP_id_get0_info - OCSP certificate ID utility functions void OCSP_CERTID_free(OCSP_CERTID *id); - int OCSP_id_issuer_cmp(OCSP_CERTID *a, OCSP_CERTID *b); - int OCSP_id_cmp(OCSP_CERTID *a, OCSP_CERTID *b); + int OCSP_id_issuer_cmp(const OCSP_CERTID *a, const OCSP_CERTID *b); + int OCSP_id_cmp(const OCSP_CERTID *a, const OCSP_CERTID *b); int OCSP_id_get0_info(ASN1_OCTET_STRING **piNameHash, ASN1_OBJECT **pmd, ASN1_OCTET_STRING **pikeyHash, diff --git a/doc/man3/OSSL_CRMF_MSG_get0_tmpl.pod b/doc/man3/OSSL_CRMF_MSG_get0_tmpl.pod index fbce7027..0ddfc719 100644 --- a/doc/man3/OSSL_CRMF_MSG_get0_tmpl.pod +++ b/doc/man3/OSSL_CRMF_MSG_get0_tmpl.pod @@ -58,7 +58,7 @@ B Copyright 2007-2018 The OpenSSL Project Authors. All Rights Reserved. -Licensed under the OpenSSL license (the "License"). You may not use +Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at L. diff --git a/doc/man3/OSSL_CRMF_MSG_set1_regCtrl_regToken.pod b/doc/man3/OSSL_CRMF_MSG_set1_regCtrl_regToken.pod index 851bd130..5709b178 100644 --- a/doc/man3/OSSL_CRMF_MSG_set1_regCtrl_regToken.pod +++ b/doc/man3/OSSL_CRMF_MSG_set1_regCtrl_regToken.pod @@ -98,7 +98,7 @@ RFC 4211 Copyright 2007-2018 The OpenSSL Project Authors. All Rights Reserved. -Licensed under the OpenSSL license (the "License"). You may not use +Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at L. diff --git a/doc/man3/OSSL_CRMF_MSG_set1_regInfo_certReq.pod b/doc/man3/OSSL_CRMF_MSG_set1_regInfo_certReq.pod index 9e33a4a2..cad175c0 100644 --- a/doc/man3/OSSL_CRMF_MSG_set1_regInfo_certReq.pod +++ b/doc/man3/OSSL_CRMF_MSG_set1_regInfo_certReq.pod @@ -41,7 +41,7 @@ RFC 4211 Copyright 2007-2018 The OpenSSL Project Authors. All Rights Reserved. -Licensed under the OpenSSL license (the "License"). You may not use +Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at L. diff --git a/doc/man3/OSSL_CRMF_MSG_set_validity.pod b/doc/man3/OSSL_CRMF_MSG_set_validity.pod index b6ea32ea..588c8b7b 100644 --- a/doc/man3/OSSL_CRMF_MSG_set_validity.pod +++ b/doc/man3/OSSL_CRMF_MSG_set_validity.pod @@ -97,7 +97,7 @@ RFC 4211 Copyright 2007-2018 The OpenSSL Project Authors. All Rights Reserved. -Licensed under the OpenSSL license (the "License"). You may not use +Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at L. diff --git a/doc/man3/OSSL_CRMF_pbmp_new.pod b/doc/man3/OSSL_CRMF_pbmp_new.pod index a83209b5..651c4307 100644 --- a/doc/man3/OSSL_CRMF_pbmp_new.pod +++ b/doc/man3/OSSL_CRMF_pbmp_new.pod @@ -70,7 +70,7 @@ RFC 4211 section 4.4 Copyright 2007-2018 The OpenSSL Project Authors. All Rights Reserved. -Licensed under the OpenSSL license (the "License"). You may not use +Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at L. diff --git a/doc/man3/OSSL_PARAM_TYPE.pod b/doc/man3/OSSL_PARAM_TYPE.pod index c4ca37a3..2842eae3 100644 --- a/doc/man3/OSSL_PARAM_TYPE.pod +++ b/doc/man3/OSSL_PARAM_TYPE.pod @@ -272,7 +272,9 @@ This example is for setting parameters on some object: =head2 Example 2 -This example is for requesting parameters on some object: +This example is for requesting parameters on some object, and also +demonstrates that the requestor isn't obligated to request all +available parameters: const char *foo = NULL; size_t foo_l; @@ -289,8 +291,14 @@ could fill in the parameters like this: /* const OSSL_PARAM *params */ - OSSL_PARAM_set_utf8_ptr(OSSL_PARAM_locate(params, "foo"), "foo value"); - OSSL_PARAM_set_utf8_string(OSSL_PARAM_locate(params, "bar"), "bar value"); + const OSSL_PARAM *p; + + if ((p = OSSL_PARAM_locate(params, "foo")) == NULL) + OSSL_PARAM_set_utf8_ptr(p, "foo value"); + if ((p = OSSL_PARAM_locate(params, "bar")) == NULL) + OSSL_PARAM_set_utf8_ptr(p, "bar value"); + if ((p = OSSL_PARAM_locate(params, "cookie")) == NULL) + OSSL_PARAM_set_utf8_ptr(p, "cookie value"); =head1 SEE ALSO diff --git a/doc/man3/OSSL_trace_enabled.pod b/doc/man3/OSSL_trace_enabled.pod index 98e3bd63..e26dee53 100644 --- a/doc/man3/OSSL_trace_enabled.pod +++ b/doc/man3/OSSL_trace_enabled.pod @@ -40,7 +40,7 @@ The tracing output is divided into types which are enabled individually by the application. The tracing types are described in detail in L. -The fallback type C should I be used +The fallback type C should I be used with the functions described here. Tracing for a specific category is enabled if a so called diff --git a/doc/man3/OSSL_trace_set_channel.pod b/doc/man3/OSSL_trace_set_channel.pod index 773a6b10..46e248f4 100644 --- a/doc/man3/OSSL_trace_set_channel.pod +++ b/doc/man3/OSSL_trace_set_channel.pod @@ -178,9 +178,15 @@ Traces BIGNUM context operations. =back -There is also C, which works as a fallback +There is also C, which works as a fallback and can be used to get I trace output. +Note, however, that in this case all trace output will effectively be +associated with the 'ALL' category, which is undesirable if the +application intends to include the category name in the trace output. +In this case it is better to register separate channels for each +trace category instead. + =head1 RETURN VALUES OSSL_trace_set_channel(), OSSL_trace_set_prefix(), diff --git a/doc/man3/X509_get0_sm2_id.pod b/doc/man3/X509_get0_sm2_id.pod new file mode 100644 index 00000000..84da71e8 --- /dev/null +++ b/doc/man3/X509_get0_sm2_id.pod @@ -0,0 +1,43 @@ +=pod + +=head1 NAME + +X509_get0_sm2_id, X509_set_sm2_id - get or set SM2 ID for certificate operations + +=head1 SYNOPSIS + + #include + + ASN1_OCTET_STRING *X509_get0_sm2_id(X509 *x); + void X509_set_sm2_id(X509 *x, ASN1_OCTET_STRING *sm2_id); + +=head1 DESCRIPTION + +X509_get0_sm2_id() gets the ID value of an SM2 certificate B by returning an +B object which should not be freed by the caller. +X509_set_sm2_id() sets the B value to an SM2 certificate B. + +=head1 NOTES + +SM2 signature algorithm requires an ID value when generating and verifying a +signature. The functions described in this manual provide the user with the +ability to set and retrieve the SM2 ID value. + +=head1 RETURN VALUES + +X509_set_sm2_id() does not return a value. + +=head1 SEE ALSO + +L, L + +=head1 COPYRIGHT + +Copyright 2019 The OpenSSL Project Authors. All Rights Reserved. + +Licensed under the Apache License 2.0 (the "License"). You may not use +this file except in compliance with the License. You can obtain a copy +in the file LICENSE in the source distribution or at +L. + +=cut diff --git a/doc/man7/EVP_KDF_SS.pod b/doc/man7/EVP_KDF_SS.pod new file mode 100644 index 00000000..3702ffe6 --- /dev/null +++ b/doc/man7/EVP_KDF_SS.pod @@ -0,0 +1,226 @@ +=pod + +=head1 NAME + +EVP_KDF_SS - The Single Step / One Step EVP_KDF implementation + +=head1 DESCRIPTION + +The EVP_KDF_SS algorithm implements the Single Step key derivation function (SSKDF). +SSKDF derives a key using input such as a shared secret key (that was generated +during the execution of a key establishment scheme) and fixedinfo. +SSKDF is also informally referred to as 'Concat KDF'. + +=head2 Auxilary function + +The implementation uses a selectable auxiliary function H, which can be one of: + +=over 4 + +=item B + +=item B + +=item B + +=back + +Both the HMAC and KMAC implementations set the key using the 'salt' value. +The hash and HMAC also require the digest to be set. + +=head2 Numeric identity + +B is the numeric identity for this implementation; it +can be used with the EVP_KDF_CTX_new_id() function. + +=head2 Supported controls + +The supported controls are: + +=over 4 + +=item B + +=item B + +=item B + +=item B + +These controls work as described in L. + +=item B + +This control expects two arguments: C, C + +The shared secret used for key derivation. This control sets the secret. + +EVP_KDF_ctrl_str() takes two type strings for this control: + +=over 4 + +=item "secret" + +The value string is used as is. + +=item "hexsecret" + +The value string is expected to be a hexadecimal number, which will be +decoded before being passed on as the control value. + +=back + +=item B + +This control expects two arguments: C, C + +An optional value for fixedinfo, also known as otherinfo. This control sets the fixedinfo. + +EVP_KDF_ctrl_str() takes two type strings for this control: + +=over 4 + +=item "info" + +The value string is used as is. + +=item "hexinfo" + +The value string is expected to be a hexadecimal number, which will be +decoded before being passed on as the control value. + +=back + +=back + +=head1 NOTES + +A context for SSKDF can be obtained by calling: + +EVP_KDF_CTX *kctx = EVP_KDF_CTX_new_id(EVP_KDF_SS); + +The output length of an SSKDF is specified via the C +parameter to the L function. + +=head1 EXAMPLE + +This example derives 10 bytes using H(x) = SHA-256, with the secret key "secret" +and fixedinfo value "label": + + EVP_KDF_CTX *kctx; + unsigned char out[10]; + + kctx = EVP_KDF_CTX_new_id(EVP_KDF_SS); + + if (EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_MD, EVP_sha256()) <= 0) { + error("EVP_KDF_CTRL_SET_MD"); + } + if (EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_KEY, "secret", (size_t)6) <= 0) { + error("EVP_KDF_CTRL_SET_KEY"); + } + if (EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_SSKDF_INFO, "label", (size_t)5) <= 0) { + error("EVP_KDF_CTRL_SET_SSKDF_INFO"); + } + if (EVP_KDF_derive(kctx, out, sizeof(out)) <= 0) { + error("EVP_KDF_derive"); + } + + EVP_KDF_CTX_free(kctx); + +=head1 EXAMPLE + +This example derives 10 bytes using H(x) = HMAC(SHA-256), with the secret key "secret", +fixedinfo value "label" and salt "salt": + + EVP_KDF_CTX *kctx; + unsigned char out[10]; + + kctx = EVP_KDF_CTX_new_id(EVP_KDF_SS); + + if (EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_MAC, EVP_get_macbyname("HMAC")) <= 0) { + error("EVP_KDF_CTRL_SET_MAC"); + } + if (EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_MD, EVP_sha256()) <= 0) { + error("EVP_KDF_CTRL_SET_MD"); + } + if (EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_KEY, "secret", (size_t)6) <= 0) { + error("EVP_KDF_CTRL_SET_KEY"); + } + if (EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_SSKDF_INFO, "label", (size_t)5) <= 0) { + error("EVP_KDF_CTRL_SET_SSKDF_INFO"); + } + if (EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_SALT, "salt", (size_t)4) <= 0) { + error("EVP_KDF_CTRL_SET_SALT"); + } + if (EVP_KDF_derive(kctx, out, sizeof(out)) <= 0) { + error("EVP_KDF_derive"); + } + + EVP_KDF_CTX_free(kctx); + +=head1 EXAMPLE + +This example derives 10 bytes using H(x) = KMAC128(x,salt,outlen), with the secret key "secret" +fixedinfo value "label", salt of "salt" and KMAC outlen of 20: + + EVP_KDF_CTX *kctx; + unsigned char out[10]; + + kctx = EVP_KDF_CTX_new_id(EVP_KDF_SS); + + if (EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_MAC, EVP_get_macbyname("KMAC128")) <= 0) { + error("EVP_KDF_CTRL_SET_MAC"); + } + if (EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_MD, EVP_sha256()) <= 0) { + error("EVP_KDF_CTRL_SET_MD"); + } + if (EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_KEY, "secret", (size_t)6) <= 0) { + error("EVP_KDF_CTRL_SET_KEY"); + } + if (EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_SSKDF_INFO, "label", (size_t)5) <= 0) { + error("EVP_KDF_CTRL_SET_SSKDF_INFO"); + } + /* If not specified the salt will be set to a default value */ + if (EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_SALT, "salt", (size_t)4) <= 0) { + error("EVP_KDF_CTRL_SET_SALT"); + } + /* If not specified the default size will be the size of the derived key */ + if (EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_MAC_SIZE, (size_t)20) <= 0) { + error("EVP_KDF_CTRL_SET_MAC_SIZE"); + } + if (EVP_KDF_derive(kctx, out, sizeof(out)) <= 0) { + error("EVP_KDF_derive"); + } + + EVP_KDF_CTX_free(kctx); + + +=head1 CONFORMING TO + +NIST SP800-56Cr1. + +=head1 SEE ALSO + +L, +L, +L, +L, +L, +L, +L + +=head1 HISTORY + +This functionality was added to OpenSSL 3.0.0. + +=head1 COPYRIGHT + +Copyright 2019 The OpenSSL Project Authors. All Rights Reserved. Copyright +(c) 2019, Oracle and/or its affiliates. All rights reserved. + +Licensed under the Apache License 2.0 (the "License"). You may not use +this file except in compliance with the License. You can obtain a copy +in the file LICENSE in the source distribution or at +L. + +=cut diff --git a/engines/e_afalg.c b/engines/e_afalg.c index 19d98d89..c3f622e7 100644 --- a/engines/e_afalg.c +++ b/engines/e_afalg.c @@ -412,7 +412,7 @@ static int afalg_start_cipher_sk(afalg_ctx *actx, const unsigned char *in, size_t inl, const unsigned char *iv, unsigned int enc) { - struct msghdr msg = { 0 }; + struct msghdr msg; struct cmsghdr *cmsg; struct iovec iov; ssize_t sbytes; @@ -421,6 +421,7 @@ static int afalg_start_cipher_sk(afalg_ctx *actx, const unsigned char *in, # endif char cbuf[CMSG_SPACE(ALG_IV_LEN(ALG_AES_IV_LEN)) + CMSG_SPACE(ALG_OP_LEN)]; + memset(&msg, 0, sizeof(msg)); memset(cbuf, 0, sizeof(cbuf)); msg.msg_control = cbuf; msg.msg_controllen = sizeof(cbuf); diff --git a/engines/e_devcrypto.c b/engines/e_devcrypto.c index c0b0d1e8..b1e87096 100644 --- a/engines/e_devcrypto.c +++ b/engines/e_devcrypto.c @@ -353,7 +353,7 @@ static int cipher_ctrl(EVP_CIPHER_CTX *ctx, int type, int p1, void* p2) to_cipher_ctx = (struct cipher_ctx *)EVP_CIPHER_CTX_get_cipher_data(to_ctx); memset(&to_cipher_ctx->sess, 0, sizeof(to_cipher_ctx->sess)); - return cipher_init(to_ctx, cipher_ctx->sess.key, EVP_CIPHER_CTX_iv(ctx), + return cipher_init(to_ctx, (void *)cipher_ctx->sess.key, EVP_CIPHER_CTX_iv(ctx), (cipher_ctx->op == COP_ENCRYPT)); case EVP_CTRL_INIT: diff --git a/include/internal/core.h b/include/internal/core.h index 2f0df376..b395025e 100644 --- a/include/internal/core.h +++ b/include/internal/core.h @@ -41,7 +41,7 @@ typedef struct ossl_method_construct_method_st { void *(*construct)(const OSSL_DISPATCH *fns, OSSL_PROVIDER *prov, void *data); /* Destruct a method */ - void (*destruct)(void *method); + void (*destruct)(void *method, void *data); } OSSL_METHOD_CONSTRUCT_METHOD; void *ossl_method_construct(OPENSSL_CTX *ctx, int operation_id, diff --git a/include/internal/ktls.h b/include/internal/ktls.h index 542acf37..23a0397a 100644 --- a/include/internal/ktls.h +++ b/include/internal/ktls.h @@ -118,12 +118,13 @@ static ossl_inline int ktls_start(int fd, static ossl_inline int ktls_send_ctrl_message(int fd, unsigned char record_type, const void *data, size_t length) { - struct msghdr msg = { 0 }; + struct msghdr msg; int cmsg_len = sizeof(record_type); struct cmsghdr *cmsg; char buf[CMSG_SPACE(cmsg_len)]; struct iovec msg_iov; /* Vector of data to send/receive into */ + memset(&msg, 0, sizeof(msg)); msg.msg_control = buf; msg.msg_controllen = sizeof(buf); cmsg = CMSG_FIRSTHDR(&msg); diff --git a/include/internal/provider.h b/include/internal/provider.h index ac70fcc5..8af20a7c 100644 --- a/include/internal/provider.h +++ b/include/internal/provider.h @@ -34,6 +34,7 @@ void ossl_provider_free(OSSL_PROVIDER *prov); /* Setters */ int ossl_provider_add_module_location(OSSL_PROVIDER *prov, const char *loc); +int ossl_provider_set_fallback(OSSL_PROVIDER *prov); /* * Activate the Provider diff --git a/include/internal/refcount.h b/include/internal/refcount.h index f8b07789..f74f7941 100644 --- a/include/internal/refcount.h +++ b/include/internal/refcount.h @@ -80,7 +80,7 @@ static __inline__ int CRYPTO_DOWN_REF(int *val, int *ret, void *lock) typedef volatile int CRYPTO_REF_COUNT; -# if (defined(_M_ARM) && _M_ARM>=7) || defined(_M_ARM64) +# if (defined(_M_ARM) && _M_ARM>=7 && !defined(_WIN32_WCE)) || defined(_M_ARM64) # include # if defined(_M_ARM64) && !defined(_ARM_BARRIER_ISH) # define _ARM_BARRIER_ISH _ARM64_BARRIER_ISH @@ -100,7 +100,17 @@ static __inline int CRYPTO_DOWN_REF(volatile int *val, int *ret, void *lock) return 1; } # else -# pragma intrinsic(_InterlockedExchangeAdd) +# if !defined(_WIN32_WCE) +# pragma intrinsic(_InterlockedExchangeAdd) +# else +# if _WIN32_WCE >= 0x600 + extern long __cdecl _InterlockedExchangeAdd(long volatile*, long); +# else + // under Windows CE we still have old-style Interlocked* functions + extern long __cdecl InterlockedExchangeAdd(long volatile*, long); +# define _InterlockedExchangeAdd InterlockedExchangeAdd +# endif +# endif static __inline int CRYPTO_UP_REF(volatile int *val, int *ret, void *lock) { diff --git a/include/internal/tsan_assist.h b/include/internal/tsan_assist.h index 5bf30c41..0fd2f3e8 100644 --- a/include/internal/tsan_assist.h +++ b/include/internal/tsan_assist.h @@ -77,7 +77,7 @@ #elif defined(_MSC_VER) && _MSC_VER>=1200 \ && (defined(_M_IX86) || defined(_M_AMD64) || defined(_M_X64) || \ - defined(_M_ARM64) || (defined(_M_ARM) && _M_ARM >= 7)) + defined(_M_ARM64) || (defined(_M_ARM) && _M_ARM >= 7 && !defined(_WIN32_WCE))) /* * There is subtle dependency on /volatile: command-line option. * "ms" implies same semantic as memory_order_acquire for loads and diff --git a/include/openssl/asn1t.h b/include/openssl/asn1t.h index 1a836c9d..8158c41f 100644 --- a/include/openssl/asn1t.h +++ b/include/openssl/asn1t.h @@ -165,10 +165,6 @@ extern "C" { {NULL, ASN1_AFLG_CONST_CB, 0, 0, cb, 0, const_cb}; \ ASN1_SEQUENCE(tname) -# define ASN1_BROKEN_SEQUENCE(tname) \ - static const ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_BROKEN, 0, 0, NULL, 0, NULL}; \ - ASN1_SEQUENCE(tname) - # define ASN1_SEQUENCE_ref(tname, cb) \ static const ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_REFCOUNT, offsetof(tname, references), offsetof(tname, lock), cb, 0, NULL}; \ ASN1_SEQUENCE(tname) @@ -200,9 +196,6 @@ extern "C" { #tname \ ASN1_ITEM_end(tname) -# define ASN1_BROKEN_SEQUENCE_END(stname) ASN1_SEQUENCE_END_ref(stname, stname) -# define static_ASN1_BROKEN_SEQUENCE_END(stname) \ - static_ASN1_SEQUENCE_END_ref(stname, stname) # define ASN1_SEQUENCE_END_enc(stname, tname) ASN1_SEQUENCE_END_ref(stname, tname) diff --git a/include/openssl/core.h b/include/openssl/core.h index 6edcd99b..2855b6d3 100644 --- a/include/openssl/core.h +++ b/include/openssl/core.h @@ -161,7 +161,14 @@ struct ossl_param_st { typedef int (OSSL_provider_init_fn)(const OSSL_PROVIDER *provider, const OSSL_DISPATCH *in, const OSSL_DISPATCH **out); +# ifdef __VMS +# pragma names save +# pragma names uppercase,truncated +# endif extern OSSL_provider_init_fn OSSL_provider_init; +# ifdef __VMS +# pragma names restore +# endif # ifdef __cplusplus } diff --git a/include/openssl/core_names.h b/include/openssl/core_names.h new file mode 100644 index 00000000..be4a6478 --- /dev/null +++ b/include/openssl/core_names.h @@ -0,0 +1,41 @@ +/* + * Copyright 2019 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the Apache License 2.0 (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef OSSL_CORE_NAMES_H +# define OSSL_CORE_NAMES_H + +# ifdef __cplusplus +extern "C" { +# endif + +/* + * Well known parameter names that Providers can define + */ + +/* + * A printable name for this provider + * Type: OSSL_PARAM_UTF8_STRING + */ +#define OSSL_PROV_PARAM_NAME "name" +/* + * A version string for this provider + * Type: OSSL_PARAM_UTF8_STRING + */ +#define OSSL_PROV_PARAM_VERSION "version" +/* + * A string providing provider specific build information + * Type: OSSL_PARAM_UTF8_STRING + */ +#define OSSL_PROV_PARAM_BUILDINFO "buildinfo" + +# ifdef __cplusplus +} +# endif + +#endif diff --git a/include/openssl/core_numbers.h b/include/openssl/core_numbers.h index 7be2a2bb..a7238547 100644 --- a/include/openssl/core_numbers.h +++ b/include/openssl/core_numbers.h @@ -72,6 +72,32 @@ OSSL_CORE_MAKE_FUNC(const OSSL_ALGORITHM *,provider_query_operation, (const OSSL_PROVIDER *, int operation_id, const int *no_store)) +/* Digests */ + +# define OSSL_OP_DIGEST 1 + +# define OSSL_FUNC_DIGEST_NEWCTX 1 +# define OSSL_FUNC_DIGEST_INIT 2 +# define OSSL_FUNC_DIGEST_UPDDATE 3 +# define OSSL_FUNC_DIGEST_FINAL 4 +# define OSSL_FUNC_DIGEST_DIGEST 5 +# define OSSL_FUNC_DIGEST_FREECTX 6 +# define OSSL_FUNC_DIGEST_DUPCTX 7 +# define OSSL_FUNC_DIGEST_SIZE 8 + +OSSL_CORE_MAKE_FUNC(void *, OP_digest_newctx, (void)) +OSSL_CORE_MAKE_FUNC(int, OP_digest_init, (void *vctx)) +OSSL_CORE_MAKE_FUNC(int, OP_digest_update, + (void *, const unsigned char *in, size_t inl)) +OSSL_CORE_MAKE_FUNC(int, OP_digest_final, + (void *, unsigned char *out, size_t *outl)) +OSSL_CORE_MAKE_FUNC(int, OP_digest_digest, + (const unsigned char *in, size_t inl, unsigned char *out, + size_t *out_l)) +OSSL_CORE_MAKE_FUNC(void, OP_digest_cleanctx, (void *vctx)) +OSSL_CORE_MAKE_FUNC(void, OP_digest_freectx, (void *vctx)) +OSSL_CORE_MAKE_FUNC(void *, OP_digest_dupctx, (void *vctx)) +OSSL_CORE_MAKE_FUNC(size_t, OP_digest_size, (void)) # ifdef __cplusplus } diff --git a/include/openssl/crmf.h b/include/openssl/crmf.h index b4221a9e..a265223f 100644 --- a/include/openssl/crmf.h +++ b/include/openssl/crmf.h @@ -3,7 +3,7 @@ * Copyright Nokia 2007-2018 * Copyright Siemens AG 2015-2018 * - * Licensed under the OpenSSL license (the "License"). You may not use + * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html diff --git a/include/openssl/cryptoerr.h b/include/openssl/cryptoerr.h index c27f05c9..b38b272a 100644 --- a/include/openssl/cryptoerr.h +++ b/include/openssl/cryptoerr.h @@ -49,6 +49,9 @@ int ERR_load_CRYPTO_strings(void); # define CRYPTO_F_PKEY_HMAC_INIT 123 # define CRYPTO_F_PKEY_POLY1305_INIT 124 # define CRYPTO_F_PKEY_SIPHASH_INIT 125 +# define CRYPTO_F_PROVIDER_ACTIVATE 134 +# define CRYPTO_F_PROVIDER_NEW 135 +# define CRYPTO_F_PROVIDER_STORE_NEW 136 # define CRYPTO_F_SK_RESERVE 129 /* diff --git a/include/openssl/err.h b/include/openssl/err.h index fded82c4..136b0009 100644 --- a/include/openssl/err.h +++ b/include/openssl/err.h @@ -37,6 +37,7 @@ extern "C" { # define ERR_TXT_STRING 0x02 # define ERR_FLAG_MARK 0x01 +# define ERR_FLAG_CLEAR 0x02 # define ERR_NUM_ERRORS 16 typedef struct err_state_st { diff --git a/include/openssl/evp.h b/include/openssl/evp.h index 125bc1c4..52319cc4 100644 --- a/include/openssl/evp.h +++ b/include/openssl/evp.h @@ -77,6 +77,7 @@ extern "C" { # ifndef EVP_MD EVP_MD *EVP_MD_meth_new(int md_type, int pkey_type); EVP_MD *EVP_MD_meth_dup(const EVP_MD *md); +int EVP_MD_upref(EVP_MD *md); void EVP_MD_meth_free(EVP_MD *md); int EVP_MD_meth_set_input_blocksize(EVP_MD *md, int blocksize); @@ -561,6 +562,9 @@ __owur int EVP_DigestFinal(EVP_MD_CTX *ctx, unsigned char *md, __owur int EVP_DigestFinalXOF(EVP_MD_CTX *ctx, unsigned char *md, size_t len); +__owur EVP_MD *EVP_MD_fetch(OPENSSL_CTX *ctx, const char *algorithm, + const char *properties); + int EVP_read_pw_string(char *buf, int length, const char *prompt, int verify); int EVP_read_pw_string_min(char *buf, int minlen, int maxlen, const char *prompt, int verify); @@ -1056,6 +1060,7 @@ int EVP_PKEY_set_type_str(EVP_PKEY *pkey, const char *str, int len); int EVP_PKEY_set_alias_type(EVP_PKEY *pkey, int type); # ifndef OPENSSL_NO_ENGINE int EVP_PKEY_set1_engine(EVP_PKEY *pkey, ENGINE *e); +ENGINE *EVP_PKEY_get0_engine(const EVP_PKEY *pkey); # endif int EVP_PKEY_assign(EVP_PKEY *pkey, int type, void *key); void *EVP_PKEY_get0(const EVP_PKEY *pkey); diff --git a/include/openssl/evperr.h b/include/openssl/evperr.h index 445d173c..598930af 100644 --- a/include/openssl/evperr.h +++ b/include/openssl/evperr.h @@ -55,7 +55,9 @@ int ERR_load_EVP_strings(void); # define EVP_F_EVP_DECRYPTFINAL_EX 101 # define EVP_F_EVP_DECRYPTUPDATE 166 # define EVP_F_EVP_DIGESTFINALXOF 174 +# define EVP_F_EVP_DIGESTFINAL_EX 230 # define EVP_F_EVP_DIGESTINIT_EX 128 +# define EVP_F_EVP_DIGESTUPDATE 231 # define EVP_F_EVP_ENCRYPTDECRYPTUPDATE 219 # define EVP_F_EVP_ENCRYPTFINAL_EX 127 # define EVP_F_EVP_ENCRYPTUPDATE 167 @@ -170,6 +172,7 @@ int ERR_load_EVP_strings(void); # define EVP_R_EXPECTING_A_EC_KEY 142 # define EVP_R_EXPECTING_A_POLY1305_KEY 164 # define EVP_R_EXPECTING_A_SIPHASH_KEY 175 +# define EVP_R_FINAL_ERROR 188 # define EVP_R_FIPS_MODE_NOT_SUPPORTED 167 # define EVP_R_GET_RAW_KEY_FAILED 182 # define EVP_R_ILLEGAL_SCRYPT_PARAMETERS 171 @@ -188,6 +191,7 @@ int ERR_load_EVP_strings(void); # define EVP_R_MESSAGE_DIGEST_IS_NULL 159 # define EVP_R_METHOD_NOT_SUPPORTED 144 # define EVP_R_MISSING_PARAMETERS 103 +# define EVP_R_NOT_ABLE_TO_COPY_CTX 190 # define EVP_R_NOT_XOF_OR_INVALID_LENGTH 178 # define EVP_R_NO_CIPHER_SET 131 # define EVP_R_NO_DEFAULT_DIGEST 158 @@ -218,6 +222,7 @@ int ERR_load_EVP_strings(void); # define EVP_R_UNSUPPORTED_PRF 125 # define EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM 118 # define EVP_R_UNSUPPORTED_SALT_TYPE 126 +# define EVP_R_UPDATE_ERROR 189 # define EVP_R_WRAP_MODE_NOT_ALLOWED 170 # define EVP_R_WRONG_FINAL_BLOCK_LENGTH 109 diff --git a/include/openssl/kdf.h b/include/openssl/kdf.h index acd94491..3a146628 100644 --- a/include/openssl/kdf.h +++ b/include/openssl/kdf.h @@ -23,6 +23,7 @@ extern "C" { # define EVP_KDF_TLS1_PRF NID_tls1_prf # define EVP_KDF_HKDF NID_hkdf # define EVP_KDF_SSHKDF NID_sshkdf +# define EVP_KDF_SS NID_sskdf EVP_KDF_CTX *EVP_KDF_CTX_new_id(int id); void EVP_KDF_CTX_free(EVP_KDF_CTX *ctx); @@ -53,6 +54,9 @@ int EVP_KDF_derive(EVP_KDF_CTX *ctx, unsigned char *key, size_t keylen); # define EVP_KDF_CTRL_SET_SSHKDF_XCGHASH 0x10 /* unsigned char *, size_t */ # define EVP_KDF_CTRL_SET_SSHKDF_SESSION_ID 0x11 /* unsigned char *, size_t */ # define EVP_KDF_CTRL_SET_SSHKDF_TYPE 0x12 /* int */ +# define EVP_KDF_CTRL_SET_MAC 0x13 /* EVP_MAC * */ +# define EVP_KDF_CTRL_SET_MAC_SIZE 0x14 /* size_t */ +# define EVP_KDF_CTRL_SET_SSKDF_INFO 0x15 /* unsigned char *, size_t */ # define EVP_KDF_HKDF_MODE_EXTRACT_AND_EXPAND 0 # define EVP_KDF_HKDF_MODE_EXTRACT_ONLY 1 diff --git a/include/openssl/kdferr.h b/include/openssl/kdferr.h index 9a1d980d..bad8f13c 100644 --- a/include/openssl/kdferr.h +++ b/include/openssl/kdferr.h @@ -56,12 +56,18 @@ int ERR_load_KDF_strings(void); # define KDF_F_PKEY_TLS1_PRF_DERIVE 101 # define KDF_F_PKEY_TLS1_PRF_INIT 110 # define KDF_F_SCRYPT_SET_MEMBUF 129 +# define KDF_F_SSKDF_CTRL_STR 134 +# define KDF_F_SSKDF_DERIVE 135 +# define KDF_F_SSKDF_MAC2CTRL 136 +# define KDF_F_SSKDF_NEW 137 +# define KDF_F_SSKDF_SIZE 138 # define KDF_F_TLS1_PRF_ALG 111 /* * KDF reason codes. */ # define KDF_R_INVALID_DIGEST 100 +# define KDF_R_INVALID_MAC_TYPE 116 # define KDF_R_MISSING_ITERATION_COUNT 109 # define KDF_R_MISSING_KEY 104 # define KDF_R_MISSING_MESSAGE_DIGEST 105 @@ -74,6 +80,7 @@ int ERR_load_KDF_strings(void); # define KDF_R_MISSING_TYPE 114 # define KDF_R_MISSING_XCGHASH 115 # define KDF_R_UNKNOWN_PARAMETER_TYPE 103 +# define KDF_R_UNSUPPORTED_MAC_TYPE 117 # define KDF_R_VALUE_ERROR 108 # define KDF_R_VALUE_MISSING 102 # define KDF_R_WRONG_OUTPUT_BUFFER_SIZE 112 diff --git a/include/openssl/obj_mac.h b/include/openssl/obj_mac.h index 2ad7e077..6ab0a3bd 100644 --- a/include/openssl/obj_mac.h +++ b/include/openssl/obj_mac.h @@ -4835,7 +4835,7 @@ #define SN_chacha20_poly1305_draft "ChaCha20-Poly1305-D" #define LN_chacha20_poly1305_draft "chacha20-poly1305-draft" -#define NID_chacha20_poly1305_draft 1205 +#define NID_chacha20_poly1305_draft 1206 #define SN_chacha20 "ChaCha20" #define LN_chacha20 "chacha20" @@ -5004,6 +5004,10 @@ #define LN_sshkdf "sshkdf" #define NID_sshkdf 1203 +#define SN_sskdf "SSKDF" +#define LN_sskdf "sskdf" +#define NID_sskdf 1205 + #define SN_id_pkinit "id-pkinit" #define NID_id_pkinit 1031 #define OBJ_id_pkinit 1L,3L,6L,1L,5L,2L,3L diff --git a/include/openssl/ocsp.h b/include/openssl/ocsp.h index 3aba16cc..bce367d9 100644 --- a/include/openssl/ocsp.h +++ b/include/openssl/ocsp.h @@ -229,8 +229,8 @@ int OCSP_request_verify(OCSP_REQUEST *req, STACK_OF(X509) *certs, int OCSP_parse_url(const char *url, char **phost, char **pport, char **ppath, int *pssl); -int OCSP_id_issuer_cmp(OCSP_CERTID *a, OCSP_CERTID *b); -int OCSP_id_cmp(OCSP_CERTID *a, OCSP_CERTID *b); +int OCSP_id_issuer_cmp(const OCSP_CERTID *a, const OCSP_CERTID *b); +int OCSP_id_cmp(const OCSP_CERTID *a, const OCSP_CERTID *b); int OCSP_request_onereq_count(OCSP_REQUEST *req); OCSP_ONEREQ *OCSP_request_onereq_get0(OCSP_REQUEST *req, int i); diff --git a/include/openssl/ssl.h b/include/openssl/ssl.h index fcfc428c..472bc029 100644 --- a/include/openssl/ssl.h +++ b/include/openssl/ssl.h @@ -619,11 +619,6 @@ unsigned long SSL_set_options(SSL *s, unsigned long op); # define SSL_get_secure_renegotiation_support(ssl) \ SSL_ctrl((ssl), SSL_CTRL_GET_RI_SUPPORT, 0, NULL) -# ifndef OPENSSL_NO_HEARTBEATS -# define SSL_heartbeat(ssl) \ - SSL_ctrl((ssl),SSL_CTRL_DTLS_EXT_SEND_HEARTBEAT,0,NULL) -# endif - # define SSL_CTX_set_cert_flags(ctx,op) \ SSL_CTX_ctrl((ctx),SSL_CTRL_CERT_FLAGS,(op),NULL) # define SSL_set_cert_flags(s,op) \ @@ -1264,11 +1259,6 @@ DECLARE_PEM_rw(SSL_SESSION, SSL_SESSION) # define SSL_CTRL_SET_TLS_EXT_SRP_USERNAME 79 # define SSL_CTRL_SET_TLS_EXT_SRP_STRENGTH 80 # define SSL_CTRL_SET_TLS_EXT_SRP_PASSWORD 81 -# ifndef OPENSSL_NO_HEARTBEATS -# define SSL_CTRL_DTLS_EXT_SEND_HEARTBEAT 85 -# define SSL_CTRL_GET_DTLS_EXT_HEARTBEAT_PENDING 86 -# define SSL_CTRL_SET_DTLS_EXT_HEARTBEAT_NO_REQUESTS 87 -# endif # define DTLS_CTRL_GET_TIMEOUT 73 # define DTLS_CTRL_HANDLE_TIMEOUT 74 # define SSL_CTRL_GET_RI_SUPPORT 76 diff --git a/include/openssl/ssl3.h b/include/openssl/ssl3.h index cb0a7929..cf0b51dd 100644 --- a/include/openssl/ssl3.h +++ b/include/openssl/ssl3.h @@ -214,7 +214,6 @@ extern "C" { # define SSL3_RT_ALERT 21 # define SSL3_RT_HANDSHAKE 22 # define SSL3_RT_APPLICATION_DATA 23 -# define DTLS1_RT_HEARTBEAT 24 /* Pseudo content types to indicate additional parameters */ # define TLS1_RT_CRYPTO 0x1000 diff --git a/include/openssl/sslerr.h b/include/openssl/sslerr.h index fac8736d..bef78d6c 100644 --- a/include/openssl/sslerr.h +++ b/include/openssl/sslerr.h @@ -47,7 +47,6 @@ int ERR_load_SSL_strings(void); # define SSL_F_DO_SSL3_WRITE 104 # define SSL_F_DTLS1_BUFFER_RECORD 247 # define SSL_F_DTLS1_CHECK_TIMEOUT_NUM 318 -# define SSL_F_DTLS1_HEARTBEAT 305 # define SSL_F_DTLS1_HM_FRAGMENT_NEW 623 # define SSL_F_DTLS1_PREPROCESS_FRAGMENT 288 # define SSL_F_DTLS1_PROCESS_BUFFERED_RECORDS 424 @@ -722,8 +721,6 @@ int ERR_load_SSL_strings(void); # define SSL_R_TLSV1_CERTIFICATE_UNOBTAINABLE 1111 # define SSL_R_TLSV1_UNRECOGNIZED_NAME 1112 # define SSL_R_TLSV1_UNSUPPORTED_EXTENSION 1110 -# define SSL_R_TLS_HEARTBEAT_PEER_DOESNT_ACCEPT 365 -# define SSL_R_TLS_HEARTBEAT_PENDING 366 # define SSL_R_TLS_ILLEGAL_EXPORTER_LABEL 367 # define SSL_R_TLS_INVALID_ECPOINTFORMAT_LIST 157 # define SSL_R_TOO_MANY_KEY_UPDATES 132 diff --git a/include/openssl/tls1.h b/include/openssl/tls1.h index 4fa1d8a3..5b07fb3c 100644 --- a/include/openssl/tls1.h +++ b/include/openssl/tls1.h @@ -109,9 +109,6 @@ extern "C" { /* ExtensionType value from RFC5764 */ # define TLSEXT_TYPE_use_srtp 14 -/* ExtensionType value from RFC5620 */ -# define TLSEXT_TYPE_heartbeat 15 - /* ExtensionType value from RFC7301 */ # define TLSEXT_TYPE_application_layer_protocol_negotiation 16 @@ -328,35 +325,6 @@ __owur int SSL_check_chain(SSL *s, X509 *x, EVP_PKEY *pk, STACK_OF(X509) *chain) SSL_CTX_callback_ctrl(ssl,SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB,\ (void (*)(void))cb) -# ifndef OPENSSL_NO_HEARTBEATS -# define SSL_DTLSEXT_HB_ENABLED 0x01 -# define SSL_DTLSEXT_HB_DONT_SEND_REQUESTS 0x02 -# define SSL_DTLSEXT_HB_DONT_RECV_REQUESTS 0x04 -# define SSL_get_dtlsext_heartbeat_pending(ssl) \ - SSL_ctrl(ssl,SSL_CTRL_GET_DTLS_EXT_HEARTBEAT_PENDING,0,NULL) -# define SSL_set_dtlsext_heartbeat_no_requests(ssl, arg) \ - SSL_ctrl(ssl,SSL_CTRL_SET_DTLS_EXT_HEARTBEAT_NO_REQUESTS,arg,NULL) - -# if !OPENSSL_API_1_1_0 -# define SSL_CTRL_TLS_EXT_SEND_HEARTBEAT \ - SSL_CTRL_DTLS_EXT_SEND_HEARTBEAT -# define SSL_CTRL_GET_TLS_EXT_HEARTBEAT_PENDING \ - SSL_CTRL_GET_DTLS_EXT_HEARTBEAT_PENDING -# define SSL_CTRL_SET_TLS_EXT_HEARTBEAT_NO_REQUESTS \ - SSL_CTRL_SET_DTLS_EXT_HEARTBEAT_NO_REQUESTS -# define SSL_TLSEXT_HB_ENABLED \ - SSL_DTLSEXT_HB_ENABLED -# define SSL_TLSEXT_HB_DONT_SEND_REQUESTS \ - SSL_DTLSEXT_HB_DONT_SEND_REQUESTS -# define SSL_TLSEXT_HB_DONT_RECV_REQUESTS \ - SSL_DTLSEXT_HB_DONT_RECV_REQUESTS -# define SSL_get_tlsext_heartbeat_pending(ssl) \ - SSL_get_dtlsext_heartbeat_pending(ssl) -# define SSL_set_tlsext_heartbeat_no_requests(ssl, arg) \ - SSL_set_dtlsext_heartbeat_no_requests(ssl,arg) -# endif -# endif - /* PSK ciphersuites from 4279 */ # define TLS1_CK_PSK_WITH_RC4_128_SHA 0x0300008A # define TLS1_CK_PSK_WITH_3DES_EDE_CBC_SHA 0x0300008B diff --git a/include/openssl/trace.h b/include/openssl/trace.h index 767b19fa..48c98ca3 100644 --- a/include/openssl/trace.h +++ b/include/openssl/trace.h @@ -30,9 +30,13 @@ extern "C" { * BIO which sends all trace output it receives to the registered application * callback. * - * The ANY category is used as a fallback category. + * The ALL category can be used as a fallback category to register a single + * channel which receives the output from all categories. However, if the + * application intends to print the trace channel name in the line prefix, + * it is better to register channels for all categories separately. + * (This is how the openssl application does it.) */ -# define OSSL_TRACE_CATEGORY_ANY 0 /* The fallback */ +# define OSSL_TRACE_CATEGORY_ALL 0 /* The fallback */ # define OSSL_TRACE_CATEGORY_TRACE 1 # define OSSL_TRACE_CATEGORY_INIT 2 # define OSSL_TRACE_CATEGORY_TLS 3 diff --git a/providers/build.info b/providers/build.info new file mode 100644 index 00000000..ec4162bd --- /dev/null +++ b/providers/build.info @@ -0,0 +1 @@ +SUBDIRS=common default diff --git a/providers/common/build.info b/providers/common/build.info new file mode 100644 index 00000000..5cb7e438 --- /dev/null +++ b/providers/common/build.info @@ -0,0 +1 @@ +SUBDIRS=digests diff --git a/providers/common/digests/build.info b/providers/common/digests/build.info new file mode 100644 index 00000000..a3c2369f --- /dev/null +++ b/providers/common/digests/build.info @@ -0,0 +1,3 @@ +LIBS=../../../libcrypto +SOURCE[../../../libcrypto]=\ + sha2.c diff --git a/providers/common/digests/sha2.c b/providers/common/digests/sha2.c new file mode 100644 index 00000000..b538ab9c --- /dev/null +++ b/providers/common/digests/sha2.c @@ -0,0 +1,63 @@ +/* + * Copyright 2019 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the Apache License 2.0 (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#include +#include +#include + +static int sha256_final(void *ctx, unsigned char *md, size_t *size) +{ + if (SHA256_Final(md, ctx)) { + *size = SHA256_DIGEST_LENGTH; + return 1; + } + + return 0; +} + +static void *sha256_newctx(void) +{ + SHA256_CTX *ctx = OPENSSL_zalloc(sizeof(*ctx)); + + return ctx; +} + +static void sha256_freectx(void *vctx) +{ + SHA256_CTX *ctx = (SHA256_CTX *)vctx; + + OPENSSL_clear_free(ctx, sizeof(*ctx)); +} + +static void *sha256_dupctx(void *ctx) +{ + SHA256_CTX *in = (SHA256_CTX *)ctx; + SHA256_CTX *ret = OPENSSL_malloc(sizeof(*ret)); + + *ret = *in; + + return ret; +} + +static size_t sha256_size(void) +{ + return SHA256_DIGEST_LENGTH; +} + +extern const OSSL_DISPATCH sha256_functions[]; +const OSSL_DISPATCH sha256_functions[] = { + { OSSL_FUNC_DIGEST_NEWCTX, (void (*)(void))sha256_newctx }, + { OSSL_FUNC_DIGEST_INIT, (void (*)(void))SHA256_Init }, + { OSSL_FUNC_DIGEST_UPDDATE, (void (*)(void))SHA256_Update }, + { OSSL_FUNC_DIGEST_FINAL, (void (*)(void))sha256_final }, + { OSSL_FUNC_DIGEST_FREECTX, (void (*)(void))sha256_freectx }, + { OSSL_FUNC_DIGEST_DUPCTX, (void (*)(void))sha256_dupctx }, + { OSSL_FUNC_DIGEST_SIZE, (void (*)(void))sha256_size }, + { 0, NULL } +}; diff --git a/providers/default/build.info b/providers/default/build.info new file mode 100644 index 00000000..eab90a3e --- /dev/null +++ b/providers/default/build.info @@ -0,0 +1,3 @@ +LIBS=../../libcrypto +SOURCE[../../libcrypto]=\ + defltprov.c diff --git a/providers/default/defltprov.c b/providers/default/defltprov.c new file mode 100644 index 00000000..9b52429b --- /dev/null +++ b/providers/default/defltprov.c @@ -0,0 +1,101 @@ +/* + * Copyright 2019 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the Apache License 2.0 (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#include +#include +#include +#include +#include +#include + +/* Functions provided by the core */ +static OSSL_core_get_param_types_fn *c_get_param_types = NULL; +static OSSL_core_get_params_fn *c_get_params = NULL; + +/* Parameters we provide to the core */ +static const OSSL_ITEM deflt_param_types[] = { + { OSSL_PARAM_UTF8_PTR, OSSL_PROV_PARAM_NAME }, + { OSSL_PARAM_UTF8_PTR, OSSL_PROV_PARAM_VERSION }, + { OSSL_PARAM_UTF8_PTR, OSSL_PROV_PARAM_BUILDINFO }, + { 0, NULL } +}; + +static const OSSL_ITEM *deflt_get_param_types(const OSSL_PROVIDER *prov) +{ + return deflt_param_types; +} + +static int deflt_get_params(const OSSL_PROVIDER *prov, + const OSSL_PARAM params[]) +{ + const OSSL_PARAM *p; + + p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_NAME); + if (p != NULL && !OSSL_PARAM_set_utf8_ptr(p, "OpenSSL Default Provider")) + return 0; + p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_VERSION); + if (p != NULL && !OSSL_PARAM_set_utf8_ptr(p, OPENSSL_VERSION_STR)) + return 0; + p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_BUILDINFO); + if (p != NULL && !OSSL_PARAM_set_utf8_ptr(p, OPENSSL_FULL_VERSION_STR)) + return 0; + + return 1; +} + +extern const OSSL_DISPATCH sha256_functions[]; + +static const OSSL_ALGORITHM deflt_digests[] = { + { "SHA256", "default=yes", sha256_functions }, + { NULL, NULL, NULL } +}; + +static const OSSL_ALGORITHM *deflt_query(OSSL_PROVIDER *prov, + int operation_id, + int *no_cache) +{ + *no_cache = 0; + switch (operation_id) { + case OSSL_OP_DIGEST: + return deflt_digests; + } + return NULL; +} + +/* Functions we provide to the core */ +static const OSSL_DISPATCH deflt_dispatch_table[] = { + { OSSL_FUNC_PROVIDER_GET_PARAM_TYPES, (void (*)(void))deflt_get_param_types }, + { OSSL_FUNC_PROVIDER_GET_PARAMS, (void (*)(void))deflt_get_params }, + { OSSL_FUNC_PROVIDER_QUERY_OPERATION, (void (*)(void))deflt_query }, + { 0, NULL } +}; + +OSSL_provider_init_fn ossl_default_provider_init; + +int ossl_default_provider_init(const OSSL_PROVIDER *provider, + const OSSL_DISPATCH *in, + const OSSL_DISPATCH **out) +{ + for (; in->function_id != 0; in++) { + switch (in->function_id) { + case OSSL_FUNC_CORE_GET_PARAM_TYPES: + c_get_param_types = OSSL_get_core_get_param_types(in); + break; + case OSSL_FUNC_CORE_GET_PARAMS: + c_get_params = OSSL_get_core_get_params(in); + break; + default: + /* Just ignore anything we don't understand */ + break; + } + } + + *out = deflt_dispatch_table; + return 1; +} diff --git a/ssl/record/rec_layer_s3.c b/ssl/record/rec_layer_s3.c index feca76eb..b2122776 100644 --- a/ssl/record/rec_layer_s3.c +++ b/ssl/record/rec_layer_s3.c @@ -1508,9 +1508,9 @@ int ssl3_read_bytes(SSL *s, int type, int *recvd_type, unsigned char *buf, && (s->server || rr->type != SSL3_RT_ALERT)) { /* * If we've got this far and still haven't decided on what version - * we're using then this must be a client side alert we're dealing with - * (we don't allow heartbeats yet). We shouldn't be receiving anything - * other than a ClientHello if we are a server. + * we're using then this must be a client side alert we're dealing + * with. We shouldn't be receiving anything other than a ClientHello + * if we are a server. */ s->version = rr->rec_version; SSLfatal(s, SSL_AD_UNEXPECTED_MESSAGE, SSL_F_SSL3_READ_BYTES, diff --git a/ssl/s3_lib.c b/ssl/s3_lib.c index 5a6c4e7a..e0977286 100644 --- a/ssl/s3_lib.c +++ b/ssl/s3_lib.c @@ -3601,13 +3601,6 @@ long ssl3_ctrl(SSL *s, int cmd, long larg, void *parg) ret = 1; break; -#ifndef OPENSSL_NO_HEARTBEATS - case SSL_CTRL_DTLS_EXT_SEND_HEARTBEAT: - case SSL_CTRL_GET_DTLS_EXT_HEARTBEAT_PENDING: - case SSL_CTRL_SET_DTLS_EXT_HEARTBEAT_NO_REQUESTS: - break; -#endif - case SSL_CTRL_CHAIN: if (larg) return ssl_cert_set1_chain(s, NULL, (STACK_OF(X509) *)parg); diff --git a/ssl/ssl_err.c b/ssl/ssl_err.c index 10836f36..f38ac155 100644 --- a/ssl/ssl_err.c +++ b/ssl/ssl_err.c @@ -48,7 +48,6 @@ static const ERR_STRING_DATA SSL_str_functs[] = { "dtls1_buffer_record"}, {ERR_PACK(ERR_LIB_SSL, SSL_F_DTLS1_CHECK_TIMEOUT_NUM, 0), "dtls1_check_timeout_num"}, - {ERR_PACK(ERR_LIB_SSL, SSL_F_DTLS1_HEARTBEAT, 0), ""}, {ERR_PACK(ERR_LIB_SSL, SSL_F_DTLS1_HM_FRAGMENT_NEW, 0), "dtls1_hm_fragment_new"}, {ERR_PACK(ERR_LIB_SSL, SSL_F_DTLS1_PREPROCESS_FRAGMENT, 0), @@ -1182,10 +1181,6 @@ static const ERR_STRING_DATA SSL_str_reasons[] = { "tlsv1 unrecognized name"}, {ERR_PACK(ERR_LIB_SSL, 0, SSL_R_TLSV1_UNSUPPORTED_EXTENSION), "tlsv1 unsupported extension"}, - {ERR_PACK(ERR_LIB_SSL, 0, SSL_R_TLS_HEARTBEAT_PEER_DOESNT_ACCEPT), - "peer does not accept heartbeats"}, - {ERR_PACK(ERR_LIB_SSL, 0, SSL_R_TLS_HEARTBEAT_PENDING), - "heartbeat request already pending"}, {ERR_PACK(ERR_LIB_SSL, 0, SSL_R_TLS_ILLEGAL_EXPORTER_LABEL), "tls illegal exporter label"}, {ERR_PACK(ERR_LIB_SSL, 0, SSL_R_TLS_INVALID_ECPOINTFORMAT_LIST), diff --git a/ssl/statem/statem_srvr.c b/ssl/statem/statem_srvr.c index f81fe862..4ce62fee 100644 --- a/ssl/statem/statem_srvr.c +++ b/ssl/statem/statem_srvr.c @@ -775,6 +775,10 @@ static ossl_inline int conn_is_closed(void) #if defined(ECONNRESET) case ECONNRESET: return 1; +#endif +#if defined(WSAECONNRESET) + case WSAECONNRESET: + return 1; #endif default: return 0; diff --git a/ssl/t1_trce.c b/ssl/t1_trce.c index 656fefe8..9368baf1 100644 --- a/ssl/t1_trce.c +++ b/ssl/t1_trce.c @@ -468,7 +468,6 @@ static const ssl_trace_tbl ssl_exts_tbl[] = { {TLSEXT_TYPE_srp, "srp"}, {TLSEXT_TYPE_signature_algorithms, "signature_algorithms"}, {TLSEXT_TYPE_use_srtp, "use_srtp"}, - {TLSEXT_TYPE_heartbeat, "tls_heartbeat"}, {TLSEXT_TYPE_application_layer_protocol_negotiation, "application_layer_protocol_negotiation"}, {TLSEXT_TYPE_signed_certificate_timestamp, "signed_certificate_timestamps"}, @@ -783,9 +782,6 @@ static int ssl_print_extension(BIO *bio, int indent, int server, } break; - case TLSEXT_TYPE_heartbeat: - return 0; - case TLSEXT_TYPE_session_ticket: if (extlen != 0) ssl_print_hex(bio, indent + 4, "ticket", ext, extlen); diff --git a/test/README b/test/README index 37722e79..ebe77846 100644 --- a/test/README +++ b/test/README @@ -114,7 +114,7 @@ Generic form of C test executables int observed; observed = function(); /* Call the code under test */ - if (!TEST_int_equal(observed, 2)) /* Check the result is correct */ + if (!TEST_int_eq(observed, 2)) /* Check the result is correct */ goto end; /* Exit on failure - optional */ testresult = 1; /* Mark the test case a success */ diff --git a/test/bn_internal_test.c b/test/bn_internal_test.c index eabeaf8b..cf47e8b7 100644 --- a/test/bn_internal_test.c +++ b/test/bn_internal_test.c @@ -73,8 +73,8 @@ static int test_bn_small_factors(void) for (i = 1; i < NUMPRIMES; i++) { prime_t p = primes[i]; - if (p > 3 && p <= 751) - BN_mul_word(b, p); + if (p > 3 && p <= 751 && !BN_mul_word(b, p)) + goto err; if (p > 751) break; } diff --git a/test/bntest.c b/test/bntest.c index 8c8acb66..976dbf44 100644 --- a/test/bntest.c +++ b/test/bntest.c @@ -160,10 +160,11 @@ static int test_swap(void) || !TEST_ptr(d = BN_new())) goto err; - BN_bntest_rand(a, 1024, 1, 0); - BN_bntest_rand(b, 1024, 1, 0); - BN_copy(c, a); - BN_copy(d, b); + if (!(TEST_true(BN_bntest_rand(a, 1024, 1, 0)) + && TEST_true(BN_bntest_rand(b, 1024, 1, 0)) + && TEST_ptr(BN_copy(c, a)) + && TEST_ptr(BN_copy(d, b)))) + goto err; top = BN_num_bits(a) / BN_BITS2; /* regular swap */ @@ -233,20 +234,21 @@ static int test_sub(void) for (i = 0; i < NUM0 + NUM1; i++) { if (i < NUM1) { - BN_bntest_rand(a, 512, 0, 0); - BN_copy(b, a); - if (!TEST_int_ne(BN_set_bit(a, i), 0)) + if (!(TEST_true(BN_bntest_rand(a, 512, 0, 0))) + && TEST_ptr(BN_copy(b, a)) + && TEST_int_ne(BN_set_bit(a, i), 0) + && TEST_true(BN_add_word(b, i))) goto err; - BN_add_word(b, i); } else { - BN_bntest_rand(b, 400 + i - NUM1, 0, 0); + if (!TEST_true(BN_bntest_rand(b, 400 + i - NUM1, 0, 0))) + goto err; BN_set_negative(a, rand_neg()); BN_set_negative(b, rand_neg()); } - BN_sub(c, a, b); - BN_add(c, c, b); - BN_sub(c, c, a); - if (!TEST_BN_eq_zero(c)) + if (!(TEST_true(BN_sub(c, a, b)) + && TEST_true(BN_add(c, c, b)) + && TEST_true(BN_sub(c, c, a)) + && TEST_BN_eq_zero(c))) goto err; } st = 1; @@ -273,20 +275,23 @@ static int test_div_recip(void) for (i = 0; i < NUM0 + NUM1; i++) { if (i < NUM1) { - BN_bntest_rand(a, 400, 0, 0); - BN_copy(b, a); - BN_lshift(a, a, i); - BN_add_word(a, i); - } else - BN_bntest_rand(b, 50 + 3 * (i - NUM1), 0, 0); + if (!(TEST_true(BN_bntest_rand(a, 400, 0, 0)) + && TEST_ptr(BN_copy(b, a)) + && TEST_true(BN_lshift(a, a, i)) + && TEST_true(BN_add_word(a, i)))) + goto err; + } else { + if (!(TEST_true(BN_bntest_rand(b, 50 + 3 * (i - NUM1), 0, 0)))) + goto err; + } BN_set_negative(a, rand_neg()); BN_set_negative(b, rand_neg()); - BN_RECP_CTX_set(recp, b, ctx); - BN_div_recp(d, c, a, recp, ctx); - BN_mul(e, d, b, ctx); - BN_add(d, e, c); - BN_sub(d, d, a); - if (!TEST_BN_eq_zero(d)) + if (!(TEST_true(BN_RECP_CTX_set(recp, b, ctx)) + && TEST_true(BN_div_recp(d, c, a, recp, ctx)) + && TEST_true(BN_mul(e, d, b, ctx)) + && TEST_true(BN_add(d, e, c)) + && TEST_true(BN_sub(d, d, a)) + && TEST_BN_eq_zero(d))) goto err; } st = 1; @@ -312,15 +317,17 @@ static int test_mod(void) || !TEST_ptr(e = BN_new())) goto err; - BN_bntest_rand(a, 1024, 0, 0); + if (!(TEST_true(BN_bntest_rand(a, 1024, 0, 0)))) + goto err; for (i = 0; i < NUM0; i++) { - BN_bntest_rand(b, 450 + i * 10, 0, 0); + if (!(TEST_true(BN_bntest_rand(b, 450 + i * 10, 0, 0)))) + goto err; BN_set_negative(a, rand_neg()); BN_set_negative(b, rand_neg()); - BN_mod(c, a, b, ctx); - BN_div(d, e, a, b, ctx); - BN_sub(e, e, c); - if (!TEST_BN_eq_zero(e)) + if (!(TEST_true(BN_mod(c, a, b, ctx)) + && TEST_true(BN_div(d, e, a, b, ctx)) + && TEST_true(BN_sub(e, e, c)) + && TEST_BN_eq_zero(e))) goto err; } st = 1; @@ -395,46 +402,52 @@ static int test_modexp_mont5(void) || !TEST_ptr(mont = BN_MONT_CTX_new())) goto err; - BN_bntest_rand(m, 1024, 0, 1); /* must be odd for montgomery */ - /* Zero exponent */ - BN_bntest_rand(a, 1024, 0, 0); + /* must be odd for montgomery */ + if (!(TEST_true(BN_bntest_rand(m, 1024, 0, 1)) + /* Zero exponent */ + && TEST_true(BN_bntest_rand(a, 1024, 0, 0)))) + goto err; BN_zero(p); + if (!TEST_true(BN_mod_exp_mont_consttime(d, a, p, m, ctx, NULL))) goto err; if (!TEST_BN_eq_one(d)) goto err; /* Regression test for carry bug in mulx4x_mont */ - BN_hex2bn(&a, + if (!(TEST_true(BN_hex2bn(&a, "7878787878787878787878787878787878787878787878787878787878787878" "7878787878787878787878787878787878787878787878787878787878787878" "7878787878787878787878787878787878787878787878787878787878787878" - "7878787878787878787878787878787878787878787878787878787878787878"); - BN_hex2bn(&b, + "7878787878787878787878787878787878787878787878787878787878787878")) + && TEST_true(BN_hex2bn(&b, "095D72C08C097BA488C5E439C655A192EAFB6380073D8C2664668EDDB4060744" "E16E57FB4EDB9AE10A0CEFCDC28A894F689A128379DB279D48A2E20849D68593" "9B7803BCF46CEBF5C533FB0DD35B080593DE5472E3FE5DB951B8BFF9B4CB8F03" - "9CC638A5EE8CDD703719F8000E6A9F63BEED5F2FCD52FF293EA05A251BB4AB81"); - BN_hex2bn(&n, + "9CC638A5EE8CDD703719F8000E6A9F63BEED5F2FCD52FF293EA05A251BB4AB81")) + && TEST_true(BN_hex2bn(&n, "D78AF684E71DB0C39CFF4E64FB9DB567132CB9C50CC98009FEB820B26F2DED9B" "91B9B5E2B83AE0AE4EB4E0523CA726BFBE969B89FD754F674CE99118C3F2D1C5" "D81FDC7C54E02B60262B241D53C040E99E45826ECA37A804668E690E1AFC1CA4" - "2C9A15D84D4954425F0B7642FC0BD9D7B24E2618D2DCC9B729D944BADACFDDAF"); - BN_MONT_CTX_set(mont, n, ctx); - BN_mod_mul_montgomery(c, a, b, mont, ctx); - BN_mod_mul_montgomery(d, b, a, mont, ctx); - if (!TEST_BN_eq(c, d)) + "2C9A15D84D4954425F0B7642FC0BD9D7B24E2618D2DCC9B729D944BADACFDDAF")))) + goto err; + + if (!(TEST_true(BN_MONT_CTX_set(mont, n, ctx)) + && TEST_true(BN_mod_mul_montgomery(c, a, b, mont, ctx)) + && TEST_true(BN_mod_mul_montgomery(d, b, a, mont, ctx)) + && TEST_BN_eq(c, d))) goto err; /* Regression test for carry bug in sqr[x]8x_mont */ - parse_bigBN(&n, bn1strings); - parse_bigBN(&a, bn2strings); + if (!(TEST_true(parse_bigBN(&n, bn1strings)) + && TEST_true(parse_bigBN(&a, bn2strings)))) + goto err; BN_free(b); - b = BN_dup(a); - BN_MONT_CTX_set(mont, n, ctx); - BN_mod_mul_montgomery(c, a, a, mont, ctx); - BN_mod_mul_montgomery(d, a, b, mont, ctx); - if (!TEST_BN_eq(c, d)) + if (!(TEST_ptr(b = BN_dup(a)) + && TEST_true(BN_MONT_CTX_set(mont, n, ctx)) + && TEST_true(BN_mod_mul_montgomery(c, a, a, mont, ctx)) + && TEST_true(BN_mod_mul_montgomery(d, a, b, mont, ctx)) + && TEST_BN_eq(c, d))) goto err; /* Regression test for carry bug in bn_sqrx8x_internal */ @@ -470,78 +483,83 @@ static int test_modexp_mont5(void) NULL }; - parse_bigBN(&a, ahex); - parse_bigBN(&n, nhex); + if (!(TEST_true(parse_bigBN(&a, ahex)) + && TEST_true(parse_bigBN(&n, nhex)))) + goto err; } BN_free(b); - b = BN_dup(a); - BN_MONT_CTX_set(mont, n, ctx); + if (!(TEST_ptr(b = BN_dup(a)) + && TEST_true(BN_MONT_CTX_set(mont, n, ctx)))) + goto err; + if (!TEST_true(BN_mod_mul_montgomery(c, a, a, mont, ctx)) || !TEST_true(BN_mod_mul_montgomery(d, a, b, mont, ctx)) || !TEST_BN_eq(c, d)) goto err; /* Regression test for bug in BN_from_montgomery_word */ - BN_hex2bn(&a, + if (!(TEST_true(BN_hex2bn(&a, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" - "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"); - BN_hex2bn(&n, + "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF")) + && TEST_true(BN_hex2bn(&n, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" - "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"); - BN_MONT_CTX_set(mont, n, ctx); - if (!TEST_false(BN_mod_mul_montgomery(d, a, a, mont, ctx))) + "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF")) + && TEST_true(BN_MONT_CTX_set(mont, n, ctx)) + && TEST_false(BN_mod_mul_montgomery(d, a, a, mont, ctx)))) goto err; /* Regression test for bug in rsaz_1024_mul_avx2 */ - BN_hex2bn(&a, + if (!(TEST_true(BN_hex2bn(&a, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" - "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF2020202020DF"); - BN_hex2bn(&b, + "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF2020202020DF")) + && TEST_true(BN_hex2bn(&b, "2020202020202020202020202020202020202020202020202020202020202020" "2020202020202020202020202020202020202020202020202020202020202020" "20202020202020FF202020202020202020202020202020202020202020202020" - "2020202020202020202020202020202020202020202020202020202020202020"); - BN_hex2bn(&n, + "2020202020202020202020202020202020202020202020202020202020202020")) + && TEST_true(BN_hex2bn(&n, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" - "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF2020202020FF"); - BN_MONT_CTX_set(mont, n, ctx); - BN_mod_exp_mont_consttime(c, a, b, n, ctx, mont); - BN_mod_exp_mont(d, a, b, n, ctx, mont); - if (!TEST_BN_eq(c, d)) + "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF2020202020FF")) + && TEST_true(BN_MONT_CTX_set(mont, n, ctx)) + && TEST_true(BN_mod_exp_mont_consttime(c, a, b, n, ctx, mont)) + && TEST_true(BN_mod_exp_mont(d, a, b, n, ctx, mont)) + && TEST_BN_eq(c, d))) goto err; /* * rsaz_1024_mul_avx2 expects fully-reduced inputs. * BN_mod_exp_mont_consttime should reduce the input first. */ - BN_hex2bn(&a, + if (!(TEST_true(BN_hex2bn(&a, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" - "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF2020202020DF"); - BN_hex2bn(&b, + "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF2020202020DF")) + && TEST_true(BN_hex2bn(&b, "1FA53F26F8811C58BE0357897AA5E165693230BC9DF5F01DFA6A2D59229EC69D" "9DE6A89C36E3B6957B22D6FAAD5A3C73AE587B710DBE92E83D3A9A3339A085CB" "B58F508CA4F837924BB52CC1698B7FDC2FD74362456A595A5B58E38E38E38E38" - "E38E38E38E38E38E38E38E38E38E38E38E38E38E38E38E38E38E38E38E38E38E"); - BN_hex2bn(&n, + "E38E38E38E38E38E38E38E38E38E38E38E38E38E38E38E38E38E38E38E38E38E")) + && TEST_true(BN_hex2bn(&n, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" - "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF2020202020DF"); - BN_MONT_CTX_set(mont, n, ctx); - BN_mod_exp_mont_consttime(c, a, b, n, ctx, mont); + "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF2020202020DF")) + && TEST_true(BN_MONT_CTX_set(mont, n, ctx)) + && TEST_true(BN_mod_exp_mont_consttime(c, a, b, n, ctx, mont)))) + goto err; BN_zero(d); if (!TEST_BN_eq(c, d)) goto err; /* Zero input */ - BN_bntest_rand(p, 1024, 0, 0); + if (!TEST_true(BN_bntest_rand(p, 1024, 0, 0))) + goto err; BN_zero(a); if (!TEST_true(BN_mod_exp_mont_consttime(d, a, p, m, ctx, NULL)) || !TEST_BN_eq_zero(d)) @@ -552,8 +570,9 @@ static int test_modexp_mont5(void) * than the modulus m, in order to test the const time precomputation * scattering/gathering. */ - BN_one(a); - BN_MONT_CTX_set(mont, m, ctx); + if (!(TEST_true(BN_one(a)) + && TEST_true(BN_MONT_CTX_set(mont, m, ctx)))) + goto err; if (!TEST_true(BN_from_montgomery(e, a, mont, ctx)) || !TEST_true(BN_mod_exp_mont_consttime(d, e, p, m, ctx, NULL)) || !TEST_true(BN_mod_exp_simple(a, e, p, m, ctx)) @@ -561,10 +580,10 @@ static int test_modexp_mont5(void) goto err; /* Finally, some regular test vectors. */ - BN_bntest_rand(e, 1024, 0, 0); - if (!TEST_true(BN_mod_exp_mont_consttime(d, e, p, m, ctx, NULL)) - || !TEST_true(BN_mod_exp_simple(a, e, p, m, ctx)) - || !TEST_BN_eq(a, d)) + if (!(TEST_true(BN_bntest_rand(e, 1024, 0, 0)) + && TEST_true(BN_mod_exp_mont_consttime(d, e, p, m, ctx, NULL)) + && TEST_true(BN_mod_exp_simple(a, e, p, m, ctx)) + && TEST_BN_eq(a, d))) goto err; st = 1; @@ -594,18 +613,19 @@ static int test_gf2m_add(void) goto err; for (i = 0; i < NUM0; i++) { - BN_rand(a, 512, 0, 0); - BN_copy(b, BN_value_one()); + if (!(TEST_true(BN_rand(a, 512, 0, 0)) + && TEST_ptr(BN_copy(b, BN_value_one())))) + goto err; BN_set_negative(a, rand_neg()); BN_set_negative(b, rand_neg()); - BN_GF2m_add(c, a, b); - /* Test that two added values have the correct parity. */ - if (!TEST_false((BN_is_odd(a) && BN_is_odd(c)) - || (!BN_is_odd(a) && !BN_is_odd(c)))) + if (!(TEST_true(BN_GF2m_add(c, a, b)) + /* Test that two added values have the correct parity. */ + && TEST_false((BN_is_odd(a) && BN_is_odd(c)) + || (!BN_is_odd(a) && !BN_is_odd(c))))) goto err; - BN_GF2m_add(c, c, c); - /* Test that c + c = 0. */ - if (!TEST_BN_eq_zero(c)) + if (!(TEST_true(BN_GF2m_add(c, c, c)) + /* Test that c + c = 0. */ + && TEST_BN_eq_zero(c))) goto err; } st = 1; @@ -629,17 +649,19 @@ static int test_gf2m_mod(void) || !TEST_ptr(e = BN_new())) goto err; - BN_GF2m_arr2poly(p0, b[0]); - BN_GF2m_arr2poly(p1, b[1]); + if (!(TEST_true(BN_GF2m_arr2poly(p0, b[0])) + && TEST_true(BN_GF2m_arr2poly(p1, b[1])))) + goto err; for (i = 0; i < NUM0; i++) { - BN_bntest_rand(a, 1024, 0, 0); + if (!TEST_true(BN_bntest_rand(a, 1024, 0, 0))) + goto err; for (j = 0; j < 2; j++) { - BN_GF2m_mod(c, a, b[j]); - BN_GF2m_add(d, a, c); - BN_GF2m_mod(e, d, b[j]); - /* Test that a + (a mod p) mod p == 0. */ - if (!TEST_BN_eq_zero(e)) + if (!(TEST_true(BN_GF2m_mod(c, a, b[j])) + && TEST_true(BN_GF2m_add(d, a, c)) + && TEST_true(BN_GF2m_mod(e, d, b[j])) + /* Test that a + (a mod p) mod p == 0. */ + && TEST_BN_eq_zero(e))) goto err; } } @@ -671,22 +693,24 @@ static int test_gf2m_mul(void) || !TEST_ptr(h = BN_new())) goto err; - BN_GF2m_arr2poly(p0, b[0]); - BN_GF2m_arr2poly(p1, b[1]); + if (!(TEST_true(BN_GF2m_arr2poly(p0, b[0])) + && TEST_true(BN_GF2m_arr2poly(p1, b[1])))) + goto err; for (i = 0; i < NUM0; i++) { - BN_bntest_rand(a, 1024, 0, 0); - BN_bntest_rand(c, 1024, 0, 0); - BN_bntest_rand(d, 1024, 0, 0); + if (!(TEST_true(BN_bntest_rand(a, 1024, 0, 0)) + && TEST_true(BN_bntest_rand(c, 1024, 0, 0)) + && TEST_true(BN_bntest_rand(d, 1024, 0, 0)))) + goto err; for (j = 0; j < 2; j++) { - BN_GF2m_mod_mul(e, a, c, b[j], ctx); - BN_GF2m_add(f, a, d); - BN_GF2m_mod_mul(g, f, c, b[j], ctx); - BN_GF2m_mod_mul(h, d, c, b[j], ctx); - BN_GF2m_add(f, e, g); - BN_GF2m_add(f, f, h); - /* Test that (a+d)*c = a*c + d*c. */ - if (!TEST_BN_eq_zero(f)) + if (!(TEST_true(BN_GF2m_mod_mul(e, a, c, b[j], ctx)) + && TEST_true(BN_GF2m_add(f, a, d)) + && TEST_true(BN_GF2m_mod_mul(g, f, c, b[j], ctx)) + && TEST_true(BN_GF2m_mod_mul(h, d, c, b[j], ctx)) + && TEST_true(BN_GF2m_add(f, e, g)) + && TEST_true(BN_GF2m_add(f, f, h)) + /* Test that (a+d)*c = a*c + d*c. */ + && TEST_BN_eq_zero(f))) goto err; } } @@ -717,18 +741,20 @@ static int test_gf2m_sqr(void) || !TEST_ptr(d = BN_new())) goto err; - BN_GF2m_arr2poly(p0, b[0]); - BN_GF2m_arr2poly(p1, b[1]); + if (!(TEST_true(BN_GF2m_arr2poly(p0, b[0])) + && TEST_true(BN_GF2m_arr2poly(p1, b[1])))) + goto err; for (i = 0; i < NUM0; i++) { - BN_bntest_rand(a, 1024, 0, 0); + if (!TEST_true(BN_bntest_rand(a, 1024, 0, 0))) + goto err; for (j = 0; j < 2; j++) { - BN_GF2m_mod_sqr(c, a, b[j], ctx); - BN_copy(d, a); - BN_GF2m_mod_mul(d, a, d, b[j], ctx); - BN_GF2m_add(d, c, d); - /* Test that a*a = a^2. */ - if (!TEST_BN_eq_zero(d)) + if (!(TEST_true(BN_GF2m_mod_sqr(c, a, b[j], ctx)) + && TEST_true(BN_copy(d, a)) + && TEST_true(BN_GF2m_mod_mul(d, a, d, b[j], ctx)) + && TEST_true(BN_GF2m_add(d, c, d)) + /* Test that a*a = a^2. */ + && TEST_BN_eq_zero(d))) goto err; } } @@ -754,16 +780,18 @@ static int test_gf2m_modinv(void) || !TEST_ptr(d = BN_new())) goto err; - BN_GF2m_arr2poly(p0, b[0]); - BN_GF2m_arr2poly(p1, b[1]); + if (!(TEST_true(BN_GF2m_arr2poly(p0, b[0])) + && TEST_true(BN_GF2m_arr2poly(p1, b[1])))) + goto err; for (i = 0; i < NUM0; i++) { - BN_bntest_rand(a, 512, 0, 0); + if (!TEST_true(BN_bntest_rand(a, 512, 0, 0))) + goto err; for (j = 0; j < 2; j++) { - BN_GF2m_mod_inv(c, a, b[j], ctx); - BN_GF2m_mod_mul(d, a, c, b[j], ctx); - /* Test that ((1/a)*a) = 1. */ - if (!TEST_BN_eq_one(d)) + if (!(TEST_true(BN_GF2m_mod_inv(c, a, b[j], ctx)) + && TEST_true(BN_GF2m_mod_mul(d, a, c, b[j], ctx)) + /* Test that ((1/a)*a) = 1. */ + && TEST_BN_eq_one(d))) goto err; } } @@ -792,18 +820,20 @@ static int test_gf2m_moddiv(void) || !TEST_ptr(f = BN_new())) goto err; - BN_GF2m_arr2poly(p0, b[0]); - BN_GF2m_arr2poly(p1, b[1]); + if (!(TEST_true(BN_GF2m_arr2poly(p0, b[0])) + && TEST_true(BN_GF2m_arr2poly(p1, b[1])))) + goto err; for (i = 0; i < NUM0; i++) { - BN_bntest_rand(a, 512, 0, 0); - BN_bntest_rand(c, 512, 0, 0); + if (!(TEST_true(BN_bntest_rand(a, 512, 0, 0)) + && TEST_true(BN_bntest_rand(c, 512, 0, 0)))) + goto err; for (j = 0; j < 2; j++) { - BN_GF2m_mod_div(d, a, c, b[j], ctx); - BN_GF2m_mod_mul(e, d, c, b[j], ctx); - BN_GF2m_mod_div(f, a, e, b[j], ctx); - /* Test that ((a/c)*c)/a = 1. */ - if (!TEST_BN_eq_one(f)) + if (!(TEST_true(BN_GF2m_mod_div(d, a, c, b[j], ctx)) + && TEST_true(BN_GF2m_mod_mul(e, d, c, b[j], ctx)) + && TEST_true(BN_GF2m_mod_div(f, a, e, b[j], ctx)) + /* Test that ((a/c)*c)/a = 1. */ + && TEST_BN_eq_one(f))) goto err; } } @@ -834,22 +864,24 @@ static int test_gf2m_modexp(void) || !TEST_ptr(f = BN_new())) goto err; - BN_GF2m_arr2poly(p0, b[0]); - BN_GF2m_arr2poly(p1, b[1]); + if (!(TEST_true(BN_GF2m_arr2poly(p0, b[0])) + && TEST_true(BN_GF2m_arr2poly(p1, b[1])))) + goto err; for (i = 0; i < NUM0; i++) { - BN_bntest_rand(a, 512, 0, 0); - BN_bntest_rand(c, 512, 0, 0); - BN_bntest_rand(d, 512, 0, 0); + if (!(TEST_true(BN_bntest_rand(a, 512, 0, 0)) + && TEST_true(BN_bntest_rand(c, 512, 0, 0)) + && TEST_true(BN_bntest_rand(d, 512, 0, 0)))) + goto err; for (j = 0; j < 2; j++) { - BN_GF2m_mod_exp(e, a, c, b[j], ctx); - BN_GF2m_mod_exp(f, a, d, b[j], ctx); - BN_GF2m_mod_mul(e, e, f, b[j], ctx); - BN_add(f, c, d); - BN_GF2m_mod_exp(f, a, f, b[j], ctx); - BN_GF2m_add(f, e, f); - /* Test that a^(c+d)=a^c*a^d. */ - if (!TEST_BN_eq_zero(f)) + if (!(TEST_true(BN_GF2m_mod_exp(e, a, c, b[j], ctx)) + && TEST_true(BN_GF2m_mod_exp(f, a, d, b[j], ctx)) + && TEST_true(BN_GF2m_mod_mul(e, e, f, b[j], ctx)) + && TEST_true(BN_add(f, c, d)) + && TEST_true(BN_GF2m_mod_exp(f, a, f, b[j], ctx)) + && TEST_true(BN_GF2m_add(f, e, f)) + /* Test that a^(c+d)=a^c*a^d. */ + && TEST_BN_eq_zero(f))) goto err; } } @@ -880,18 +912,21 @@ static int test_gf2m_modsqrt(void) || !TEST_ptr(f = BN_new())) goto err; - BN_GF2m_arr2poly(p0, b[0]); - BN_GF2m_arr2poly(p1, b[1]); + if (!(TEST_true(BN_GF2m_arr2poly(p0, b[0])) + && TEST_true(BN_GF2m_arr2poly(p1, b[1])))) + goto err; for (i = 0; i < NUM0; i++) { - BN_bntest_rand(a, 512, 0, 0); + if (!TEST_true(BN_bntest_rand(a, 512, 0, 0))) + goto err; + for (j = 0; j < 2; j++) { - BN_GF2m_mod(c, a, b[j]); - BN_GF2m_mod_sqrt(d, a, b[j], ctx); - BN_GF2m_mod_sqr(e, d, b[j], ctx); - BN_GF2m_add(f, c, e); - /* Test that d^2 = a, where d = sqrt(a). */ - if (!TEST_BN_eq_zero(f)) + if (!(TEST_true(BN_GF2m_mod(c, a, b[j])) + && TEST_true(BN_GF2m_mod_sqrt(d, a, b[j], ctx)) + && TEST_true(BN_GF2m_mod_sqr(e, d, b[j], ctx)) + && TEST_true(BN_GF2m_add(f, c, e)) + /* Test that d^2 = a, where d = sqrt(a). */ + && TEST_BN_eq_zero(f))) goto err; } } @@ -921,23 +956,26 @@ static int test_gf2m_modsolvequad(void) || !TEST_ptr(e = BN_new())) goto err; - BN_GF2m_arr2poly(p0, b[0]); - BN_GF2m_arr2poly(p1, b[1]); + if (!(TEST_true(BN_GF2m_arr2poly(p0, b[0])) + && TEST_true(BN_GF2m_arr2poly(p1, b[1])))) + goto err; for (i = 0; i < NUM0; i++) { - BN_bntest_rand(a, 512, 0, 0); + if (!TEST_true(BN_bntest_rand(a, 512, 0, 0))) + goto err; for (j = 0; j < 2; j++) { t = BN_GF2m_mod_solve_quad(c, a, b[j], ctx); if (t) { s++; - BN_GF2m_mod_sqr(d, c, b[j], ctx); - BN_GF2m_add(d, c, d); - BN_GF2m_mod(e, a, b[j]); - BN_GF2m_add(e, e, d); - /* - * Test that solution of quadratic c satisfies c^2 + c = a. - */ - if (!TEST_BN_eq_zero(e)) + if (!(TEST_true(BN_GF2m_mod_sqr(d, c, b[j], ctx)) + && TEST_true(BN_GF2m_add(d, c, d)) + && TEST_true(BN_GF2m_mod(e, a, b[j])) + && TEST_true(BN_GF2m_add(e, e, d)) + /* + * Test that solution of quadratic c + * satisfies c^2 + c = a. + */ + && TEST_BN_eq_zero(e))) goto err; } } diff --git a/test/certs/cyrillic.msb b/test/certs/cyrillic.msb index ec58ac9b..a6322d58 100644 --- a/test/certs/cyrillic.msb +++ b/test/certs/cyrillic.msb @@ -36,26 +36,26 @@ Certificate: X509v3 Subject Key Identifier: 11:49:46:19:2A:4E:4D:D1:C8:FB:79:55:3D:81:99:22:EE:34:4F:22 X509v3 Authority Key Identifier: - keyid:11:49:46:19:2A:4E:4D:D1:C8:FB:79:55:3D:81:99:22:EE:34:4F:22 - + 11:49:46:19:2A:4E:4D:D1:C8:FB:79:55:3D:81:99:22:EE:34:4F:22 X509v3 Basic Constraints: CA:TRUE Signature Algorithm: sha256WithRSAEncryption - 04:8f:c3:77:48:06:29:c0:8d:66:2e:6b:48:a3:b3:e0:dd:5b: - 0a:e7:a4:0b:7e:72:91:fc:37:29:7f:81:1e:60:66:7b:ba:94: - 30:f8:c0:79:56:bc:ed:87:88:d9:bd:d8:7b:dc:1b:87:bb:ef: - 15:d0:77:74:59:d7:3f:30:09:71:86:da:d7:d7:50:cb:ef:8f: - 34:26:76:b5:0a:de:d0:ce:ca:40:57:86:ce:13:24:2a:9e:97: - db:5d:3e:73:8c:24:cc:89:84:42:04:45:62:f9:fd:4b:79:b2: - 1b:a0:01:d7:4c:1f:4d:d1:4c:5b:99:0a:27:5e:c9:79:3c:0f: - b7:3c:09:db:32:d6:ca:56:91:32:0d:7f:79:94:bc:bc:a8:ba: - 54:4b:39:6e:2d:9a:21:77:13:f8:b5:62:5d:a8:8c:c8:8d:ec: - 67:6c:14:2d:f6:ce:e6:d3:a6:fa:37:36:5b:31:7a:80:66:83: - 02:64:82:c1:ec:bf:38:8e:49:b0:e5:ec:09:9b:80:16:e4:32: - 91:4e:72:c4:5f:2d:b3:e9:57:b1:00:36:2d:1a:e9:9f:4a:b1: - 1c:d1:ae:fb:15:79:02:0b:14:97:81:ee:42:01:ed:00:58:38: - b2:30:89:f2:89:11:b7:03:7c:16:95:30:eb:32:9c:9f:00:e5: - 22:12:db:7a + Signature Value: + 04:8f:c3:77:48:06:29:c0:8d:66:2e:6b:48:a3:b3:e0:dd:5b: + 0a:e7:a4:0b:7e:72:91:fc:37:29:7f:81:1e:60:66:7b:ba:94: + 30:f8:c0:79:56:bc:ed:87:88:d9:bd:d8:7b:dc:1b:87:bb:ef: + 15:d0:77:74:59:d7:3f:30:09:71:86:da:d7:d7:50:cb:ef:8f: + 34:26:76:b5:0a:de:d0:ce:ca:40:57:86:ce:13:24:2a:9e:97: + db:5d:3e:73:8c:24:cc:89:84:42:04:45:62:f9:fd:4b:79:b2: + 1b:a0:01:d7:4c:1f:4d:d1:4c:5b:99:0a:27:5e:c9:79:3c:0f: + b7:3c:09:db:32:d6:ca:56:91:32:0d:7f:79:94:bc:bc:a8:ba: + 54:4b:39:6e:2d:9a:21:77:13:f8:b5:62:5d:a8:8c:c8:8d:ec: + 67:6c:14:2d:f6:ce:e6:d3:a6:fa:37:36:5b:31:7a:80:66:83: + 02:64:82:c1:ec:bf:38:8e:49:b0:e5:ec:09:9b:80:16:e4:32: + 91:4e:72:c4:5f:2d:b3:e9:57:b1:00:36:2d:1a:e9:9f:4a:b1: + 1c:d1:ae:fb:15:79:02:0b:14:97:81:ee:42:01:ed:00:58:38: + b2:30:89:f2:89:11:b7:03:7c:16:95:30:eb:32:9c:9f:00:e5: + 22:12:db:7a -----BEGIN CERTIFICATE----- MIIEPTCCAyWgAwIBAgIJAL5HPFOmKsA6MA0GCSqGSIb3DQEBCwUAMIG0MQswCQYD VQQGEwJSVTEVMBMGA1UECAwM0JzQvtGB0LrQstCwMRUwEwYDVQQHDAzQnNC+0YHQ diff --git a/test/certs/cyrillic.utf8 b/test/certs/cyrillic.utf8 index 2096e4fb..e9a2df2f 100644 --- a/test/certs/cyrillic.utf8 +++ b/test/certs/cyrillic.utf8 @@ -36,26 +36,26 @@ Certificate: X509v3 Subject Key Identifier: 11:49:46:19:2A:4E:4D:D1:C8:FB:79:55:3D:81:99:22:EE:34:4F:22 X509v3 Authority Key Identifier: - keyid:11:49:46:19:2A:4E:4D:D1:C8:FB:79:55:3D:81:99:22:EE:34:4F:22 - + 11:49:46:19:2A:4E:4D:D1:C8:FB:79:55:3D:81:99:22:EE:34:4F:22 X509v3 Basic Constraints: CA:TRUE Signature Algorithm: sha256WithRSAEncryption - 04:8f:c3:77:48:06:29:c0:8d:66:2e:6b:48:a3:b3:e0:dd:5b: - 0a:e7:a4:0b:7e:72:91:fc:37:29:7f:81:1e:60:66:7b:ba:94: - 30:f8:c0:79:56:bc:ed:87:88:d9:bd:d8:7b:dc:1b:87:bb:ef: - 15:d0:77:74:59:d7:3f:30:09:71:86:da:d7:d7:50:cb:ef:8f: - 34:26:76:b5:0a:de:d0:ce:ca:40:57:86:ce:13:24:2a:9e:97: - db:5d:3e:73:8c:24:cc:89:84:42:04:45:62:f9:fd:4b:79:b2: - 1b:a0:01:d7:4c:1f:4d:d1:4c:5b:99:0a:27:5e:c9:79:3c:0f: - b7:3c:09:db:32:d6:ca:56:91:32:0d:7f:79:94:bc:bc:a8:ba: - 54:4b:39:6e:2d:9a:21:77:13:f8:b5:62:5d:a8:8c:c8:8d:ec: - 67:6c:14:2d:f6:ce:e6:d3:a6:fa:37:36:5b:31:7a:80:66:83: - 02:64:82:c1:ec:bf:38:8e:49:b0:e5:ec:09:9b:80:16:e4:32: - 91:4e:72:c4:5f:2d:b3:e9:57:b1:00:36:2d:1a:e9:9f:4a:b1: - 1c:d1:ae:fb:15:79:02:0b:14:97:81:ee:42:01:ed:00:58:38: - b2:30:89:f2:89:11:b7:03:7c:16:95:30:eb:32:9c:9f:00:e5: - 22:12:db:7a + Signature Value: + 04:8f:c3:77:48:06:29:c0:8d:66:2e:6b:48:a3:b3:e0:dd:5b: + 0a:e7:a4:0b:7e:72:91:fc:37:29:7f:81:1e:60:66:7b:ba:94: + 30:f8:c0:79:56:bc:ed:87:88:d9:bd:d8:7b:dc:1b:87:bb:ef: + 15:d0:77:74:59:d7:3f:30:09:71:86:da:d7:d7:50:cb:ef:8f: + 34:26:76:b5:0a:de:d0:ce:ca:40:57:86:ce:13:24:2a:9e:97: + db:5d:3e:73:8c:24:cc:89:84:42:04:45:62:f9:fd:4b:79:b2: + 1b:a0:01:d7:4c:1f:4d:d1:4c:5b:99:0a:27:5e:c9:79:3c:0f: + b7:3c:09:db:32:d6:ca:56:91:32:0d:7f:79:94:bc:bc:a8:ba: + 54:4b:39:6e:2d:9a:21:77:13:f8:b5:62:5d:a8:8c:c8:8d:ec: + 67:6c:14:2d:f6:ce:e6:d3:a6:fa:37:36:5b:31:7a:80:66:83: + 02:64:82:c1:ec:bf:38:8e:49:b0:e5:ec:09:9b:80:16:e4:32: + 91:4e:72:c4:5f:2d:b3:e9:57:b1:00:36:2d:1a:e9:9f:4a:b1: + 1c:d1:ae:fb:15:79:02:0b:14:97:81:ee:42:01:ed:00:58:38: + b2:30:89:f2:89:11:b7:03:7c:16:95:30:eb:32:9c:9f:00:e5: + 22:12:db:7a -----BEGIN CERTIFICATE----- MIIEPTCCAyWgAwIBAgIJAL5HPFOmKsA6MA0GCSqGSIb3DQEBCwUAMIG0MQswCQYD VQQGEwJSVTEVMBMGA1UECAwM0JzQvtGB0LrQstCwMRUwEwYDVQQHDAzQnNC+0YHQ diff --git a/test/certs/cyrillic_crl.utf8 b/test/certs/cyrillic_crl.utf8 index e55c549d..c36a3fd0 100644 --- a/test/certs/cyrillic_crl.utf8 +++ b/test/certs/cyrillic_crl.utf8 @@ -9,21 +9,22 @@ Certificate Revocation List (CRL): 1 No Revoked Certificates. Signature Algorithm: sha256WithRSAEncryption - 85:e5:e5:fe:d4:13:3f:07:1a:07:53:6f:f7:a5:01:c9:80:f4: - 8a:7a:f3:74:fc:af:dd:6a:21:47:88:99:7b:29:bf:46:0b:02: - 98:d7:80:75:46:f6:cd:da:b5:0f:ff:9f:0c:b7:e6:aa:8e:f6: - ae:7f:5c:81:ce:56:89:41:e2:4a:65:cb:02:98:6f:69:e9:3a: - f5:cb:40:49:5e:1a:ea:e6:40:b4:48:bc:8d:0e:c7:c6:51:37: - ee:c6:7c:26:a3:e7:25:1d:74:54:fa:02:ae:93:e8:74:5a:42: - 4b:d3:6d:99:61:b2:77:f3:0e:7c:f2:4e:0d:4f:70:96:54:77: - 84:db:71:03:0b:6e:b8:a7:de:36:9a:50:c4:ed:e9:fa:33:22: - f5:e7:63:de:2d:df:58:ad:68:aa:e6:23:88:3a:b2:1b:40:b1: - 2b:ab:41:23:c3:1b:c7:1b:db:0c:89:81:54:6b:a5:6b:c2:64: - 5f:db:a9:f2:67:bb:bd:44:a2:43:3f:ea:36:76:5b:70:76:20: - 5a:49:70:b7:42:dd:e9:67:c0:48:7e:ff:e5:f3:59:70:a7:c0: - eb:eb:74:b0:08:82:36:a4:84:69:97:22:02:75:0a:a6:5f:f6: - be:d6:af:24:4e:15:c8:3f:62:b1:f9:7e:3c:83:b5:44:da:8d: - 97:e1:c7:f2 + Signature Value: + 85:e5:e5:fe:d4:13:3f:07:1a:07:53:6f:f7:a5:01:c9:80:f4: + 8a:7a:f3:74:fc:af:dd:6a:21:47:88:99:7b:29:bf:46:0b:02: + 98:d7:80:75:46:f6:cd:da:b5:0f:ff:9f:0c:b7:e6:aa:8e:f6: + ae:7f:5c:81:ce:56:89:41:e2:4a:65:cb:02:98:6f:69:e9:3a: + f5:cb:40:49:5e:1a:ea:e6:40:b4:48:bc:8d:0e:c7:c6:51:37: + ee:c6:7c:26:a3:e7:25:1d:74:54:fa:02:ae:93:e8:74:5a:42: + 4b:d3:6d:99:61:b2:77:f3:0e:7c:f2:4e:0d:4f:70:96:54:77: + 84:db:71:03:0b:6e:b8:a7:de:36:9a:50:c4:ed:e9:fa:33:22: + f5:e7:63:de:2d:df:58:ad:68:aa:e6:23:88:3a:b2:1b:40:b1: + 2b:ab:41:23:c3:1b:c7:1b:db:0c:89:81:54:6b:a5:6b:c2:64: + 5f:db:a9:f2:67:bb:bd:44:a2:43:3f:ea:36:76:5b:70:76:20: + 5a:49:70:b7:42:dd:e9:67:c0:48:7e:ff:e5:f3:59:70:a7:c0: + eb:eb:74:b0:08:82:36:a4:84:69:97:22:02:75:0a:a6:5f:f6: + be:d6:af:24:4e:15:c8:3f:62:b1:f9:7e:3c:83:b5:44:da:8d: + 97:e1:c7:f2 -----BEGIN X509 CRL----- MIIB6DCB0QIBATANBgkqhkiG9w0BAQsFADCBjjELMAkGA1UEBhMCUlUxFTATBgNV BAgMDNCc0L7RgdC60LLQsDELMAkGA1UECgwC0K8xCzAJBgNVBAsMAtCvMSowKAYD diff --git a/test/certs/sm2-ca-cert.pem b/test/certs/sm2-ca-cert.pem new file mode 100644 index 00000000..5677ac6c --- /dev/null +++ b/test/certs/sm2-ca-cert.pem @@ -0,0 +1,14 @@ +-----BEGIN CERTIFICATE----- +MIICJDCCAcqgAwIBAgIJAOlkpDpSrmVbMAoGCCqBHM9VAYN1MGgxCzAJBgNVBAYT +AkNOMQswCQYDVQQIDAJMTjERMA8GA1UEBwwIU2hlbnlhbmcxETAPBgNVBAoMCFRl +c3QgT3JnMRAwDgYDVQQLDAdUZXN0IE9VMRQwEgYDVQQDDAtUZXN0IFNNMiBDQTAe +Fw0xOTAyMTkwNzA1NDhaFw0yMzAzMzAwNzA1NDhaMGgxCzAJBgNVBAYTAkNOMQsw +CQYDVQQIDAJMTjERMA8GA1UEBwwIU2hlbnlhbmcxETAPBgNVBAoMCFRlc3QgT3Jn +MRAwDgYDVQQLDAdUZXN0IE9VMRQwEgYDVQQDDAtUZXN0IFNNMiBDQTBZMBMGByqG +SM49AgEGCCqBHM9VAYItA0IABHRYnqErofBdXPptvvO7+BSVJxcpHuTGnZ+UPrbU +5kVEUMaUnNOeMJZl/vRGimZCm/AkReJmRfnb15ESHR+ssp6jXTBbMB0GA1UdDgQW +BBTFjcWu/zJgSZ5SKUlU5Vx4/0W5dDAfBgNVHSMEGDAWgBTFjcWu/zJgSZ5SKUlU +5Vx4/0W5dDAMBgNVHRMEBTADAQH/MAsGA1UdDwQEAwIBBjAKBggqgRzPVQGDdQNI +ADBFAiEAs6byi1nSQtFELOw/2tQIv5AEsZFR5MJ/oB2ztXzs2LYCIEfIw4xlUH6X +YFhs4RnIa0K9Ng1ebsGPrifYkudwBIk3 +-----END CERTIFICATE----- diff --git a/test/certs/sm2.crt b/test/certs/sm2.pem similarity index 100% rename from test/certs/sm2.crt rename to test/certs/sm2.pem diff --git a/test/clienthellotest.c b/test/clienthellotest.c index 7fdb5bc6..0afad6db 100644 --- a/test/clienthellotest.c +++ b/test/clienthellotest.c @@ -58,7 +58,7 @@ static int test_client_hello(int currtest) BIO *wbio; long len; unsigned char *data; - PACKET pkt = {0}, pkt2 = {0}, pkt3 = {0}; + PACKET pkt, pkt2, pkt3; char *dummytick = "Hello World!"; unsigned int type = 0; int testresult = 0; @@ -71,6 +71,10 @@ static int test_client_hello(int currtest) return 1; #endif + memset(&pkt, 0, sizeof(pkt)); + memset(&pkt2, 0, sizeof(pkt2)); + memset(&pkt3, 0, sizeof(pkt3)); + /* * For each test set up an SSL_CTX and SSL and see what ClientHello gets * produced when we try to connect diff --git a/test/drbgtest.c b/test/drbgtest.c index 362a1d2b..652b93ad 100644 --- a/test/drbgtest.c +++ b/test/drbgtest.c @@ -152,6 +152,31 @@ static size_t kat_nonce(RAND_DRBG *drbg, unsigned char **pout, return t->noncelen; } + /* + * Disable CRNG testing if it is enabled. + * If the DRBG is ready or in an error state, this means an instantiate cycle + * for which the default personalisation string is used. + */ +static int disable_crngt(RAND_DRBG *drbg) +{ + static const char pers[] = DRBG_DEFAULT_PERS_STRING; + const int instantiate = drbg->state != DRBG_UNINITIALISED; + + if (drbg->get_entropy != rand_crngt_get_entropy) + return 1; + + if ((instantiate && !RAND_DRBG_uninstantiate(drbg)) + || !TEST_true(RAND_DRBG_set_callbacks(drbg, &rand_drbg_get_entropy, + &rand_drbg_cleanup_entropy, + &rand_drbg_get_nonce, + &rand_drbg_cleanup_nonce)) + || (instantiate + && !RAND_DRBG_instantiate(drbg, (const unsigned char *)pers, + sizeof(pers) - 1))) + return 0; + return 1; +} + static int uninstantiate(RAND_DRBG *drbg) { int ret = drbg == NULL ? 1 : RAND_DRBG_uninstantiate(drbg); @@ -177,7 +202,8 @@ static int single_kat(DRBG_SELFTEST_DATA *td) if (!TEST_ptr(drbg = RAND_DRBG_new(td->nid, td->flags, NULL))) return 0; if (!TEST_true(RAND_DRBG_set_callbacks(drbg, kat_entropy, NULL, - kat_nonce, NULL))) { + kat_nonce, NULL)) + || !TEST_true(disable_crngt(drbg))) { failures++; goto err; } @@ -295,7 +321,8 @@ static int error_check(DRBG_SELFTEST_DATA *td) unsigned int reseed_counter_tmp; int ret = 0; - if (!TEST_ptr(drbg = RAND_DRBG_new(td->nid, td->flags, NULL))) + if (!TEST_ptr(drbg = RAND_DRBG_new(td->nid, td->flags, NULL)) + || !TEST_true(disable_crngt(drbg))) goto err; /* @@ -708,6 +735,10 @@ static int test_rand_drbg_reseed(void) || !TEST_ptr_eq(private->parent, master)) return 0; + /* Disable CRNG testing for the master DRBG */ + if (!TEST_true(disable_crngt(master))) + return 0; + /* uninstantiate the three global DRBGs */ RAND_DRBG_uninstantiate(private); RAND_DRBG_uninstantiate(public); @@ -928,7 +959,8 @@ static int test_rand_seed(void) size_t rand_buflen; size_t required_seed_buflen = 0; - if (!TEST_ptr(master = RAND_DRBG_get0_master())) + if (!TEST_ptr(master = RAND_DRBG_get0_master()) + || !TEST_true(disable_crngt(master))) return 0; #ifdef OPENSSL_RAND_SEED_NONE @@ -983,7 +1015,8 @@ static int test_multi_set(void) RAND_DRBG *drbg = NULL; /* init drbg with default CTR initializer */ - if (!TEST_ptr(drbg = RAND_DRBG_new(0, 0, NULL))) + if (!TEST_ptr(drbg = RAND_DRBG_new(0, 0, NULL)) + || !TEST_true(disable_crngt(drbg))) goto err; /* change it to use hmac */ if (!TEST_true(RAND_DRBG_set(drbg, NID_sha1, RAND_DRBG_FLAG_HMAC))) @@ -1093,6 +1126,118 @@ static int test_set_defaults(void) && TEST_true(RAND_DRBG_uninstantiate(private)); } +/* + * A list of the FIPS DRGB types. + * Because of the way HMAC DRGBs are implemented, both the NID and flags + * are required. + */ +static const struct s_drgb_types { + int nid; + int flags; +} drgb_types[] = { + { NID_aes_128_ctr, 0 }, + { NID_aes_192_ctr, 0 }, + { NID_aes_256_ctr, 0 }, + { NID_sha1, 0 }, + { NID_sha224, 0 }, + { NID_sha256, 0 }, + { NID_sha384, 0 }, + { NID_sha512, 0 }, + { NID_sha512_224, 0 }, + { NID_sha512_256, 0 }, + { NID_sha3_224, 0 }, + { NID_sha3_256, 0 }, + { NID_sha3_384, 0 }, + { NID_sha3_512, 0 }, + { NID_sha1, RAND_DRBG_FLAG_HMAC }, + { NID_sha224, RAND_DRBG_FLAG_HMAC }, + { NID_sha256, RAND_DRBG_FLAG_HMAC }, + { NID_sha384, RAND_DRBG_FLAG_HMAC }, + { NID_sha512, RAND_DRBG_FLAG_HMAC }, + { NID_sha512_224, RAND_DRBG_FLAG_HMAC }, + { NID_sha512_256, RAND_DRBG_FLAG_HMAC }, + { NID_sha3_224, RAND_DRBG_FLAG_HMAC }, + { NID_sha3_256, RAND_DRBG_FLAG_HMAC }, + { NID_sha3_384, RAND_DRBG_FLAG_HMAC }, + { NID_sha3_512, RAND_DRBG_FLAG_HMAC }, +}; + +/* Six cases for each covers seed sizes up to 32 bytes */ +static const size_t crngt_num_cases = 6; + +static size_t crngt_case, crngt_idx; + +static int crngt_entropy_cb(unsigned char *buf) +{ + size_t i, z; + + if (!TEST_int_lt(crngt_idx, crngt_num_cases)) + return 0; + /* Generate a block of unique data unless this is the duplication point */ + z = crngt_idx++; + if (z > 0 && crngt_case == z) + z--; + for (i = 0; i < CRNGT_BUFSIZ; i++) + buf[i] = (unsigned char)(i + 'A' + z); + return 1; +} + +static int test_crngt(int n) +{ + const struct s_drgb_types *dt = drgb_types + n / crngt_num_cases; + RAND_DRBG *drbg = NULL; + unsigned char buff[100]; + size_t ent; + int res = 0; + int expect; + + if (!TEST_true(rand_crngt_single_init())) + return 0; + rand_crngt_cleanup(); + + if (!TEST_ptr(drbg = RAND_DRBG_new(dt->nid, dt->flags, NULL))) + return 0; + ent = (drbg->min_entropylen + CRNGT_BUFSIZ - 1) / CRNGT_BUFSIZ; + crngt_case = n % crngt_num_cases; + crngt_idx = 0; + crngt_get_entropy = &crngt_entropy_cb; + if (!TEST_true(rand_crngt_init())) + goto err; +#ifndef FIPS_MODE + if (!TEST_true(RAND_DRBG_set_callbacks(drbg, &rand_crngt_get_entropy, + &rand_crngt_cleanup_entropy, + &rand_drbg_get_nonce, + &rand_drbg_cleanup_nonce))) + goto err; +#endif + expect = crngt_case == 0 || crngt_case > ent; + if (!TEST_int_eq(RAND_DRBG_instantiate(drbg, NULL, 0), expect)) + goto err; + if (!expect) + goto fin; + if (!TEST_true(RAND_DRBG_generate(drbg, buff, sizeof(buff), 0, NULL, 0))) + goto err; + + expect = crngt_case == 0 || crngt_case > 2 * ent; + if (!TEST_int_eq(RAND_DRBG_reseed(drbg, NULL, 0, 0), expect)) + goto err; + if (!expect) + goto fin; + if (!TEST_true(RAND_DRBG_generate(drbg, buff, sizeof(buff), 0, NULL, 0))) + goto err; + +fin: + res = 1; +err: + if (!res) + TEST_note("DRBG %zd case %zd block %zd", n / crngt_num_cases, + crngt_case, crngt_idx); + uninstantiate(drbg); + RAND_DRBG_free(drbg); + crngt_get_entropy = &rand_crngt_get_entropy_cb; + return res; +} + int setup_tests(void) { app_data_index = RAND_DRBG_get_ex_new_index(0L, NULL, NULL, NULL, NULL); @@ -1107,5 +1252,6 @@ int setup_tests(void) #if defined(OPENSSL_THREADS) ADD_TEST(test_multi_thread); #endif + ADD_ALL_TESTS(test_crngt, crngt_num_cases * OSSL_NELEM(drgb_types)); return 1; } diff --git a/test/evp_extra_test.c b/test/evp_extra_test.c index eac0c43b..f07ae94a 100644 --- a/test/evp_extra_test.c +++ b/test/evp_extra_test.c @@ -18,6 +18,7 @@ #include #include #include +#include #include "testutil.h" #include "internal/nelem.h" #include "internal/evp_int.h" @@ -509,6 +510,66 @@ static int test_d2i_AutoPrivateKey(int i) } #ifndef OPENSSL_NO_EC + +static const unsigned char ec_public_sect163k1_validxy[] = { + 0x30, 0x40, 0x30, 0x10, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, + 0x01, 0x06, 0x05, 0x2b, 0x81, 0x04, 0x00, 0x01, 0x03, 0x2c, 0x00, 0x04, + 0x02, 0x84, 0x58, 0xa6, 0xd4, 0xa0, 0x35, 0x2b, 0xae, 0xf0, 0xc0, 0x69, + 0x05, 0xcf, 0x2a, 0x50, 0x33, 0xf9, 0xe3, 0x92, 0x79, 0x02, 0xd1, 0x7b, + 0x9f, 0x22, 0x00, 0xf0, 0x3b, 0x0e, 0x5d, 0x2e, 0xb7, 0x23, 0x24, 0xf3, + 0x6a, 0xd8, 0x17, 0x65, 0x41, 0x2f +}; + +static const unsigned char ec_public_sect163k1_badx[] = { + 0x30, 0x40, 0x30, 0x10, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, + 0x01, 0x06, 0x05, 0x2b, 0x81, 0x04, 0x00, 0x01, 0x03, 0x2c, 0x00, 0x04, + 0x0a, 0x84, 0x58, 0xa6, 0xd4, 0xa0, 0x35, 0x2b, 0xae, 0xf0, 0xc0, 0x69, + 0x05, 0xcf, 0x2a, 0x50, 0x33, 0xf9, 0xe3, 0x92, 0xb0, 0x02, 0xd1, 0x7b, + 0x9f, 0x22, 0x00, 0xf0, 0x3b, 0x0e, 0x5d, 0x2e, 0xb7, 0x23, 0x24, 0xf3, + 0x6a, 0xd8, 0x17, 0x65, 0x41, 0x2f +}; + +static const unsigned char ec_public_sect163k1_bady[] = { + 0x30, 0x40, 0x30, 0x10, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, + 0x01, 0x06, 0x05, 0x2b, 0x81, 0x04, 0x00, 0x01, 0x03, 0x2c, 0x00, 0x04, + 0x02, 0x84, 0x58, 0xa6, 0xd4, 0xa0, 0x35, 0x2b, 0xae, 0xf0, 0xc0, 0x69, + 0x05, 0xcf, 0x2a, 0x50, 0x33, 0xf9, 0xe3, 0x92, 0x79, 0x0a, 0xd1, 0x7b, + 0x9f, 0x22, 0x00, 0xf0, 0x3b, 0x0e, 0x5d, 0x2e, 0xb7, 0x23, 0x24, 0xf3, + 0x6a, 0xd8, 0x17, 0x65, 0x41, 0xe6 +}; + +static struct ec_der_pub_keys_st { + const unsigned char *der; + size_t len; + int valid; +} ec_der_pub_keys[] = { + { ec_public_sect163k1_validxy, sizeof(ec_public_sect163k1_validxy), 1 }, + { ec_public_sect163k1_badx, sizeof(ec_public_sect163k1_badx), 0 }, + { ec_public_sect163k1_bady, sizeof(ec_public_sect163k1_bady), 0 }, +}; + +/* + * Tests the range of the decoded EC char2 public point. + * See ec_GF2m_simple_oct2point(). + */ +static int test_invalide_ec_char2_pub_range_decode(int id) +{ + int ret = 0; + BIO *bio = NULL; + EC_KEY *eckey = NULL; + + if (!TEST_ptr(bio = BIO_new_mem_buf(ec_der_pub_keys[id].der, + ec_der_pub_keys[id].len))) + goto err; + eckey = d2i_EC_PUBKEY_bio(bio, NULL); + ret = (ec_der_pub_keys[id].valid && TEST_ptr(eckey)) + || TEST_ptr_null(eckey); +err: + EC_KEY_free(eckey); + BIO_free(bio); + return ret; +} + /* Tests loading a bad key in PKCS8 format */ static int test_EVP_PKCS82PKEY(void) { @@ -1009,6 +1070,106 @@ done: } #endif + +static int calculate_digest(const EVP_MD *md, const char *msg, size_t len, + const unsigned char *exptd) +{ + unsigned char out[SHA256_DIGEST_LENGTH]; + EVP_MD_CTX *ctx; + int ret = 0; + + if (!TEST_ptr(ctx = EVP_MD_CTX_new()) + || !TEST_true(EVP_DigestInit_ex(ctx, md, NULL)) + || !TEST_true(EVP_DigestUpdate(ctx, msg, len)) + || !TEST_true(EVP_DigestFinal_ex(ctx, out, NULL)) + || !TEST_mem_eq(out, SHA256_DIGEST_LENGTH, exptd, + SHA256_DIGEST_LENGTH)) + goto err; + + ret = 1; + err: + EVP_MD_CTX_free(ctx); + return ret; +} +/* + * Test EVP_MD_fetch() + * + * Test 0: Test with the default OPENSSL_CTX + * Test 1: Test with an explicit OPENSSL_CTX + * Test 2: Explicit OPENSSL_CTX with explicit load of default provider + */ +static int test_EVP_MD_fetch(int tst) +{ + OPENSSL_CTX *ctx = NULL; + EVP_MD *md = NULL; + OSSL_PROVIDER *prov = NULL; + int ret = 0; + const char testmsg[] = "Hello world"; + const unsigned char exptd[] = { + 0x27, 0x51, 0x8b, 0xa9, 0x68, 0x30, 0x11, 0xf6, 0xb3, 0x96, 0x07, 0x2c, + 0x05, 0xf6, 0x65, 0x6d, 0x04, 0xf5, 0xfb, 0xc3, 0x78, 0x7c, 0xf9, 0x24, + 0x90, 0xec, 0x60, 0x6e, 0x50, 0x92, 0xe3, 0x26 + }; + + if (tst > 0) { + ctx = OPENSSL_CTX_new(); + if (!TEST_ptr(ctx)) + goto err; + + if (tst == 2) { + prov = OSSL_PROVIDER_load(ctx, "default"); + if (!TEST_ptr(prov)) + goto err; + } + } + + /* Implicit fetching of the MD should produce the expected result */ + if (!TEST_true(calculate_digest(EVP_sha256(), testmsg, sizeof(testmsg), + exptd))) + goto err; + /* + * Test that without loading any providers or specifying any properties we + * can get a sha256 md from the default provider. + */ + if (!TEST_ptr(md = EVP_MD_fetch(ctx, "SHA256", NULL)) + || !TEST_ptr(md) + || !TEST_int_eq(EVP_MD_nid(md), NID_sha256) + || !TEST_true(calculate_digest(md, testmsg, sizeof(testmsg), exptd))) + goto err; + + /* Also test EVP_MD_upref() while we're doing this */ + if (!TEST_true(EVP_MD_upref(md))) + goto err; + /* Ref count should now be 2. Release both */ + EVP_MD_meth_free(md); + EVP_MD_meth_free(md); + md = NULL; + + /* + * We've only loaded the default provider so explicitly asking for a + * non-default implementation should fail. + */ + if (!TEST_ptr_null(md = EVP_MD_fetch(ctx, "SHA256", "default=no"))) + goto err; + + /* Explicitly asking for the default implementation should succeeed */ + if (!TEST_ptr(md = EVP_MD_fetch(ctx, "SHA256", "default=yes")) + || !TEST_int_eq(EVP_MD_nid(md), NID_sha256) + || !TEST_true(calculate_digest(md, testmsg, sizeof(testmsg), exptd))) + goto err; + + EVP_MD_meth_free(md); + md = NULL; + + ret = 1; + + err: + EVP_MD_meth_free(md); + OSSL_PROVIDER_unload(prov); + OPENSSL_CTX_free(ctx); + return ret; +} + int setup_tests(void) { ADD_TEST(test_EVP_DigestSignInit); @@ -1035,6 +1196,9 @@ int setup_tests(void) ADD_TEST(test_HKDF); #ifndef OPENSSL_NO_EC ADD_TEST(test_X509_PUBKEY_inplace); + ADD_ALL_TESTS(test_invalide_ec_char2_pub_range_decode, + OSSL_NELEM(ec_der_pub_keys)); #endif + ADD_ALL_TESTS(test_EVP_MD_fetch, 3); return 1; } diff --git a/test/evp_kdf_test.c b/test/evp_kdf_test.c index 923e9aef..4215fe35 100644 --- a/test/evp_kdf_test.c +++ b/test/evp_kdf_test.c @@ -19,137 +19,76 @@ static int test_kdf_tls1_prf(void) { - int ret = 0; + int ret; EVP_KDF_CTX *kctx; unsigned char out[16]; + const unsigned char expected[sizeof(out)] = { + 0x8e, 0x4d, 0x93, 0x25, 0x30, 0xd7, 0x65, 0xa0, + 0xaa, 0xe9, 0x74, 0xc3, 0x04, 0x73, 0x5e, 0xcc + }; - if ((kctx = EVP_KDF_CTX_new_id(EVP_KDF_TLS1_PRF)) == NULL) { - TEST_error("EVP_KDF_TLS1_PRF"); - goto err; - } - if (EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_MD, EVP_sha256()) <= 0) { - TEST_error("EVP_KDF_CTRL_SET_MD"); - goto err; - } - if (EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_TLS_SECRET, - "secret", (size_t)6) <= 0) { - TEST_error("EVP_KDF_CTRL_SET_TLS_SECRET"); - goto err; - } - if (EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_ADD_TLS_SEED, "seed", (size_t)4) <= 0) { - TEST_error("EVP_KDF_CTRL_ADD_TLS_SEED"); - goto err; - } - if (EVP_KDF_derive(kctx, out, sizeof(out)) <= 0) { - TEST_error("EVP_KDF_derive"); - goto err; - } + ret = TEST_ptr(kctx = EVP_KDF_CTX_new_id(EVP_KDF_TLS1_PRF)) + && TEST_int_gt(EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_MD, EVP_sha256()), + 0) + && TEST_int_gt(EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_TLS_SECRET, + "secret", (size_t)6), 0) + && TEST_int_gt(EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_ADD_TLS_SEED, "seed", + (size_t)4), 0) + && TEST_int_gt(EVP_KDF_derive(kctx, out, sizeof(out)), 0) + && TEST_mem_eq(out, sizeof(out), expected, sizeof(expected)); - { - const unsigned char expected[sizeof(out)] = { - 0x8e, 0x4d, 0x93, 0x25, 0x30, 0xd7, 0x65, 0xa0, - 0xaa, 0xe9, 0x74, 0xc3, 0x04, 0x73, 0x5e, 0xcc - }; - if (!TEST_mem_eq(out, sizeof(out), expected, sizeof(expected))) { - goto err; - } - } - ret = 1; -err: EVP_KDF_CTX_free(kctx); return ret; } static int test_kdf_hkdf(void) { - int ret = 0; + int ret; EVP_KDF_CTX *kctx; unsigned char out[10]; + const unsigned char expected[sizeof(out)] = { + 0x2a, 0xc4, 0x36, 0x9f, 0x52, 0x59, 0x96, 0xf8, 0xde, 0x13 + }; - if ((kctx = EVP_KDF_CTX_new_id(EVP_KDF_HKDF)) == NULL) { - TEST_error("EVP_KDF_HKDF"); - goto err; - } - if (EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_MD, EVP_sha256()) <= 0) { - TEST_error("EVP_KDF_CTRL_SET_MD"); - goto err; - } - if (EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_SALT, "salt", (size_t)4) <= 0) { - TEST_error("EVP_KDF_CTRL_SET_SALT"); - goto err; - } - if (EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_KEY, "secret", (size_t)6) <= 0) { - TEST_error("EVP_KDF_CTRL_SET_KEY"); - goto err; - } - if (EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_ADD_HKDF_INFO, - "label", (size_t)5) <= 0) { - TEST_error("EVP_KDF_CTRL_ADD_HKDF_INFO"); - goto err; - } - if (EVP_KDF_derive(kctx, out, sizeof(out)) <= 0) { - TEST_error("EVP_KDF_derive"); - goto err; - } + ret = TEST_ptr(kctx = EVP_KDF_CTX_new_id(EVP_KDF_HKDF)) + && TEST_int_gt(EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_MD, EVP_sha256()), + 0) + && TEST_int_gt(EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_SALT, "salt", + (size_t)4), 0) + && TEST_int_gt(EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_KEY, "secret", + (size_t)6), 0) + && TEST_int_gt(EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_ADD_HKDF_INFO, + "label", (size_t)5), 0) + && TEST_int_gt(EVP_KDF_derive(kctx, out, sizeof(out)), 0) + && TEST_mem_eq(out, sizeof(out), expected, sizeof(expected)); - { - const unsigned char expected[sizeof(out)] = { - 0x2a, 0xc4, 0x36, 0x9f, 0x52, 0x59, 0x96, 0xf8, 0xde, 0x13 - }; - if (!TEST_mem_eq(out, sizeof(out), expected, sizeof(expected))) { - goto err; - } - } - ret = 1; -err: EVP_KDF_CTX_free(kctx); return ret; } static int test_kdf_pbkdf2(void) { - int ret = 0; + int ret; EVP_KDF_CTX *kctx; unsigned char out[32]; + const unsigned char expected[sizeof(out)] = { + 0xae, 0x4d, 0x0c, 0x95, 0xaf, 0x6b, 0x46, 0xd3, + 0x2d, 0x0a, 0xdf, 0xf9, 0x28, 0xf0, 0x6d, 0xd0, + 0x2a, 0x30, 0x3f, 0x8e, 0xf3, 0xc2, 0x51, 0xdf, + 0xd6, 0xe2, 0xd8, 0x5a, 0x95, 0x47, 0x4c, 0x43 + }; - if ((kctx = EVP_KDF_CTX_new_id(EVP_KDF_PBKDF2)) == NULL) { - TEST_error("EVP_KDF_PBKDF2"); - goto err; - } - if (EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_PASS, "password", (size_t)8) <= 0) { - TEST_error("EVP_KDF_CTRL_SET_PASS"); - goto err; - } - if (EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_SALT, "salt", (size_t)4) <= 0) { - TEST_error("EVP_KDF_CTRL_SET_SALT"); - goto err; - } - if (EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_ITER, 2) <= 0) { - TEST_error("EVP_KDF_CTRL_SET_ITER"); - goto err; - } - if (EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_MD, EVP_sha256()) <= 0) { - TEST_error("EVP_KDF_CTRL_SET_MD"); - goto err; - } - if (EVP_KDF_derive(kctx, out, sizeof(out)) <= 0) { - TEST_error("EVP_KDF_derive"); - goto err; - } + ret = TEST_ptr(kctx = EVP_KDF_CTX_new_id(EVP_KDF_PBKDF2)) + && TEST_int_gt(EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_PASS, "password", + (size_t)8), 0) + && TEST_int_gt(EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_SALT, "salt", + (size_t)4), 0) + && TEST_int_gt(EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_ITER, 2), 0) + && TEST_int_gt(EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_MD, EVP_sha256()), + 0) + && TEST_int_gt(EVP_KDF_derive(kctx, out, sizeof(out)), 0) + && TEST_mem_eq(out, sizeof(out), expected, sizeof(expected)); - { - const unsigned char expected[sizeof(out)] = { - 0xae, 0x4d, 0x0c, 0x95, 0xaf, 0x6b, 0x46, 0xd3, - 0x2d, 0x0a, 0xdf, 0xf9, 0x28, 0xf0, 0x6d, 0xd0, - 0x2a, 0x30, 0x3f, 0x8e, 0xf3, 0xc2, 0x51, 0xdf, - 0xd6, 0xe2, 0xd8, 0x5a, 0x95, 0x47, 0x4c, 0x43 - }; - if (!TEST_mem_eq(out, sizeof(out), expected, sizeof(expected))) { - goto err; - } - } - ret = 1; -err: EVP_KDF_CTX_free(kctx); return ret; } @@ -157,73 +96,162 @@ err: #ifndef OPENSSL_NO_SCRYPT static int test_kdf_scrypt(void) { - int ret = 0; + int ret; EVP_KDF_CTX *kctx; unsigned char out[64]; + const unsigned char expected[sizeof(out)] = { + 0xfd, 0xba, 0xbe, 0x1c, 0x9d, 0x34, 0x72, 0x00, + 0x78, 0x56, 0xe7, 0x19, 0x0d, 0x01, 0xe9, 0xfe, + 0x7c, 0x6a, 0xd7, 0xcb, 0xc8, 0x23, 0x78, 0x30, + 0xe7, 0x73, 0x76, 0x63, 0x4b, 0x37, 0x31, 0x62, + 0x2e, 0xaf, 0x30, 0xd9, 0x2e, 0x22, 0xa3, 0x88, + 0x6f, 0xf1, 0x09, 0x27, 0x9d, 0x98, 0x30, 0xda, + 0xc7, 0x27, 0xaf, 0xb9, 0x4a, 0x83, 0xee, 0x6d, + 0x83, 0x60, 0xcb, 0xdf, 0xa2, 0xcc, 0x06, 0x40 + }; - if ((kctx = EVP_KDF_CTX_new_id(EVP_KDF_SCRYPT)) == NULL) { - TEST_error("EVP_KDF_SCRYPT"); - goto err; - } - if (EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_PASS, "password", (size_t)8) <= 0) { - TEST_error("EVP_KDF_CTRL_SET_PASS"); - goto err; - } - if (EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_SALT, "NaCl", (size_t)4) <= 0) { - TEST_error("EVP_KDF_CTRL_SET_SALT"); - goto err; - } - if (EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_SCRYPT_N, (uint64_t)1024) <= 0) { - TEST_error("EVP_KDF_CTRL_SET_SCRYPT_N"); - goto err; - } - if (EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_SCRYPT_R, (uint32_t)8) <= 0) { - TEST_error("EVP_KDF_CTRL_SET_SCRYPT_R"); - goto err; - } - if (EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_SCRYPT_P, (uint32_t)16) <= 0) { - TEST_error("EVP_KDF_CTRL_SET_SCRYPT_P"); - goto err; - } - if (EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_MAXMEM_BYTES, (uint64_t)16) <= 0) { - TEST_error("EVP_KDF_CTRL_SET_MAXMEM_BYTES"); - goto err; - } - if (EVP_KDF_derive(kctx, out, sizeof(out)) > 0) { - TEST_error("EVP_KDF_derive should have failed"); - goto err; - } - if (EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_MAXMEM_BYTES, - (uint64_t)(10 * 1024 * 1024)) <= 0) { - TEST_error("EVP_KDF_CTRL_SET_MAXMEM_BYTES"); - goto err; - } - if (EVP_KDF_derive(kctx, out, sizeof(out)) <= 0) { - TEST_error("EVP_KDF_derive"); - goto err; - } + ret = TEST_ptr(kctx = EVP_KDF_CTX_new_id(EVP_KDF_SCRYPT)) + && TEST_int_gt(EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_PASS, "password", + (size_t)8), 0) + && TEST_int_gt(EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_SALT, "NaCl", + (size_t)4), 0) + && TEST_int_gt(EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_SCRYPT_N, + (uint64_t)1024), 0) + && TEST_int_gt(EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_SCRYPT_R, + (uint32_t)8), 0) + && TEST_int_gt(EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_SCRYPT_P, + (uint32_t)16), 0) + && TEST_int_gt(EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_MAXMEM_BYTES, + (uint64_t)16), 0) + /* failure test */ + && TEST_int_le(EVP_KDF_derive(kctx, out, sizeof(out)), 0) + && TEST_int_gt(EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_MAXMEM_BYTES, + (uint64_t)(10 * 1024 * 1024)), 0) + && TEST_int_gt(EVP_KDF_derive(kctx, out, sizeof(out)), 0) + && TEST_mem_eq(out, sizeof(out), expected, sizeof(expected)); + + EVP_KDF_CTX_free(kctx); + return ret; +} +#endif /* OPENSSL_NO_SCRYPT */ + +static int test_kdf_ss_hash(void) +{ + int ret; + EVP_KDF_CTX *kctx = NULL; + const unsigned char z[] = { + 0x6d,0xbd,0xc2,0x3f,0x04,0x54,0x88,0xe4,0x06,0x27,0x57,0xb0,0x6b,0x9e, + 0xba,0xe1,0x83,0xfc,0x5a,0x59,0x46,0xd8,0x0d,0xb9,0x3f,0xec,0x6f,0x62, + 0xec,0x07,0xe3,0x72,0x7f,0x01,0x26,0xae,0xd1,0x2c,0xe4,0xb2,0x62,0xf4, + 0x7d,0x48,0xd5,0x42,0x87,0xf8,0x1d,0x47,0x4c,0x7c,0x3b,0x18,0x50,0xe9 + }; + const unsigned char other[] = { + 0xa1,0xb2,0xc3,0xd4,0xe5,0x43,0x41,0x56,0x53,0x69,0x64,0x3c,0x83,0x2e, + 0x98,0x49,0xdc,0xdb,0xa7,0x1e,0x9a,0x31,0x39,0xe6,0x06,0xe0,0x95,0xde, + 0x3c,0x26,0x4a,0x66,0xe9,0x8a,0x16,0x58,0x54,0xcd,0x07,0x98,0x9b,0x1e, + 0xe0,0xec,0x3f,0x8d,0xbe + }; + const unsigned char expected[] = { + 0xa4,0x62,0xde,0x16,0xa8,0x9d,0xe8,0x46,0x6e,0xf5,0x46,0x0b,0x47,0xb8 + }; + unsigned char out[14]; + + ret = TEST_ptr(kctx = EVP_KDF_CTX_new_id(EVP_KDF_SS)) + && TEST_int_gt(EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_MD, EVP_sha224()), + 0) + && TEST_int_gt(EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_KEY, z, sizeof(z)), + 0) + && TEST_int_gt(EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_SSKDF_INFO, other, + sizeof(other)), 0) + && TEST_int_gt(EVP_KDF_derive(kctx, out, sizeof(out)), 0) + && TEST_mem_eq(out, sizeof(out), expected, sizeof(expected)); + + EVP_KDF_CTX_free(kctx); + return ret; +} + +static int test_kdf_ss_hmac(void) +{ + int ret; + EVP_KDF_CTX *kctx; + const EVP_MAC *mac; + + const unsigned char z[] = { + 0xb7,0x4a,0x14,0x9a,0x16,0x15,0x46,0xf8,0xc2,0x0b,0x06,0xac,0x4e,0xd4 + }; + const unsigned char other[] = { + 0x34,0x8a,0x37,0xa2,0x7e,0xf1,0x28,0x2f,0x5f,0x02,0x0d,0xcc + }; + const unsigned char salt[] = { + 0x36,0x38,0x27,0x1c,0xcd,0x68,0xa2,0x5d,0xc2,0x4e,0xcd,0xdd,0x39,0xef, + 0x3f,0x89 + }; + const unsigned char expected[] = { + 0x44,0xf6,0x76,0xe8,0x5c,0x1b,0x1a,0x8b,0xbc,0x3d,0x31,0x92,0x18,0x63, + 0x1c,0xa3 + }; + unsigned char out[16]; + + ret = TEST_ptr(kctx = EVP_KDF_CTX_new_id(EVP_KDF_SS)) + && TEST_ptr(mac = EVP_get_macbyname("HMAC")) + && TEST_int_gt(EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_MAC, mac), 0) + && TEST_int_gt(EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_MD, EVP_sha256()), + 0) + && TEST_int_gt(EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_KEY, z, sizeof(z)), + 0) + && TEST_int_gt(EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_SSKDF_INFO, other, + sizeof(other)), 0) + && TEST_int_gt(EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_SALT, salt, + sizeof(salt)), 0) + && TEST_int_gt(EVP_KDF_derive(kctx, out, sizeof(out)), 0) + && TEST_mem_eq(out, sizeof(out), expected, sizeof(expected)); + + EVP_KDF_CTX_free(kctx); + return ret; +} + +static int test_kdf_ss_kmac(void) +{ + int ret; + EVP_KDF_CTX *kctx; + unsigned char out[64]; + const EVP_MAC *mac; + + const unsigned char z[] = { + 0xb7,0x4a,0x14,0x9a,0x16,0x15,0x46,0xf8,0xc2,0x0b,0x06,0xac,0x4e,0xd4 + }; + const unsigned char other[] = { + 0x34,0x8a,0x37,0xa2,0x7e,0xf1,0x28,0x2f,0x5f,0x02,0x0d,0xcc + }; + const unsigned char salt[] = { + 0x36,0x38,0x27,0x1c,0xcd,0x68,0xa2,0x5d,0xc2,0x4e,0xcd,0xdd,0x39,0xef, + 0x3f,0x89 + }; + const unsigned char expected[] = { + 0xe9,0xc1,0x84,0x53,0xa0,0x62,0xb5,0x3b,0xdb,0xfc,0xbb,0x5a,0x34,0xbd, + 0xb8,0xe5,0xe7,0x07,0xee,0xbb,0x5d,0xd1,0x34,0x42,0x43,0xd8,0xcf,0xc2, + 0xc2,0xe6,0x33,0x2f,0x91,0xbd,0xa5,0x86,0xf3,0x7d,0xe4,0x8a,0x65,0xd4, + 0xc5,0x14,0xfd,0xef,0xaa,0x1e,0x67,0x54,0xf3,0x73,0xd2,0x38,0xe1,0x95, + 0xae,0x15,0x7e,0x1d,0xe8,0x14,0x98,0x03 + }; + + ret = TEST_ptr(kctx = EVP_KDF_CTX_new_id(EVP_KDF_SS)) + && TEST_ptr(mac = EVP_get_macbyname("KMAC128")) + && TEST_int_gt(EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_MAC, mac), 0) + && TEST_int_gt(EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_KEY, z, + sizeof(z)), 0) + && TEST_int_gt(EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_SSKDF_INFO, other, + sizeof(other)), 0) + && TEST_int_gt(EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_SALT, salt, + sizeof(salt)), 0) + && TEST_int_gt(EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_MAC_SIZE, + (size_t)20), 0) + && TEST_int_gt(EVP_KDF_derive(kctx, out, sizeof(out)), 0) + && TEST_mem_eq(out, sizeof(out), expected, sizeof(expected)); - { - const unsigned char expected[sizeof(out)] = { - 0xfd, 0xba, 0xbe, 0x1c, 0x9d, 0x34, 0x72, 0x00, - 0x78, 0x56, 0xe7, 0x19, 0x0d, 0x01, 0xe9, 0xfe, - 0x7c, 0x6a, 0xd7, 0xcb, 0xc8, 0x23, 0x78, 0x30, - 0xe7, 0x73, 0x76, 0x63, 0x4b, 0x37, 0x31, 0x62, - 0x2e, 0xaf, 0x30, 0xd9, 0x2e, 0x22, 0xa3, 0x88, - 0x6f, 0xf1, 0x09, 0x27, 0x9d, 0x98, 0x30, 0xda, - 0xc7, 0x27, 0xaf, 0xb9, 0x4a, 0x83, 0xee, 0x6d, - 0x83, 0x60, 0xcb, 0xdf, 0xa2, 0xcc, 0x06, 0x40 - }; - if (!TEST_mem_eq(out, sizeof(out), expected, sizeof(expected))) { - goto err; - } - } - ret = 1; -err: EVP_KDF_CTX_free(kctx); return ret; } -#endif int setup_tests(void) { @@ -233,5 +261,8 @@ int setup_tests(void) #ifndef OPENSSL_NO_SCRYPT ADD_TEST(test_kdf_scrypt); #endif + ADD_TEST(test_kdf_ss_hash); + ADD_TEST(test_kdf_ss_hmac); + ADD_TEST(test_kdf_ss_kmac); return 1; } diff --git a/test/ossl_test_endian.h b/test/ossl_test_endian.h new file mode 100644 index 00000000..0bcec047 --- /dev/null +++ b/test/ossl_test_endian.h @@ -0,0 +1,22 @@ +/* + * Copyright 2019 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the Apache License 2.0 (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_INTERNAL_ENDIAN_H +# define HEADER_INTERNAL_ENDIAN_H + +# define DECLARE_IS_ENDIAN \ + const union { \ + long one; \ + char little; \ + } ossl_is_endian = { 1 } + +# define IS_LITTLE_ENDIAN (ossl_is_endian.little != 0) +# define IS_BIG_ENDIAN (ossl_is_endian.little == 0) + +#endif diff --git a/test/packettest.c b/test/packettest.c index 81e0449b..41d938a6 100644 --- a/test/packettest.c +++ b/test/packettest.c @@ -350,8 +350,9 @@ static int test_PACKET_get_length_prefixed_1(void) unsigned char buf1[BUF_LEN]; const size_t len = 16; unsigned int i; - PACKET pkt, short_pkt, subpkt = {0}; + PACKET pkt, short_pkt, subpkt; + memset(&subpkt, 0, sizeof(subpkt)); buf1[0] = (unsigned char)len; for (i = 1; i < BUF_LEN; i++) buf1[i] = (i * 2) & 0xff; @@ -374,8 +375,9 @@ static int test_PACKET_get_length_prefixed_2(void) unsigned char buf1[1024]; const size_t len = 516; /* 0x0204 */ unsigned int i; - PACKET pkt, short_pkt, subpkt = {0}; + PACKET pkt, short_pkt, subpkt; + memset(&subpkt, 0, sizeof(subpkt)); for (i = 1; i <= 1024; i++) buf1[i - 1] = (i * 2) & 0xff; @@ -397,8 +399,9 @@ static int test_PACKET_get_length_prefixed_3(void) unsigned char buf1[1024]; const size_t len = 516; /* 0x000204 */ unsigned int i; - PACKET pkt, short_pkt, subpkt = {0}; + PACKET pkt, short_pkt, subpkt; + memset(&subpkt, 0, sizeof(subpkt)); for (i = 0; i < 1024; i++) buf1[i] = (i * 2) & 0xff; @@ -420,8 +423,9 @@ static int test_PACKET_as_length_prefixed_1(void) unsigned char buf1[BUF_LEN]; const size_t len = 16; unsigned int i; - PACKET pkt, exact_pkt, subpkt = {0}; + PACKET pkt, exact_pkt, subpkt; + memset(&subpkt, 0, sizeof(subpkt)); buf1[0] = (unsigned char)len; for (i = 1; i < BUF_LEN; i++) buf1[i] = (i * 2) & 0xff; @@ -443,8 +447,9 @@ static int test_PACKET_as_length_prefixed_2(void) unsigned char buf[1024]; const size_t len = 516; /* 0x0204 */ unsigned int i; - PACKET pkt, exact_pkt, subpkt = {0}; + PACKET pkt, exact_pkt, subpkt; + memset(&subpkt, 0, sizeof(subpkt)); for (i = 1; i <= 1024; i++) buf[i-1] = (i * 2) & 0xff; diff --git a/test/params_api_test.c b/test/params_api_test.c index 77b8af4f..15dfb16f 100644 --- a/test/params_api_test.c +++ b/test/params_api_test.c @@ -11,6 +11,7 @@ #include #include "testutil.h" #include "internal/nelem.h" +#include "ossl_test_endian.h" #include #include @@ -27,20 +28,22 @@ static void swap_copy(unsigned char *out, const void *in, size_t len) static void copy_to_le(unsigned char *out, const void *in, size_t len) { -#ifdef B_ENDIAN - swap_copy(out, in, len); -#else - memcpy(out, in, len); -#endif + DECLARE_IS_ENDIAN; + + if (IS_LITTLE_ENDIAN) + memcpy(out, in, len); + else + swap_copy(out, in, len); } static void copy_be_to_native(unsigned char *out, const void *in, size_t len) { -#ifdef B_ENDIAN - memcpy(out, in, len); -#else - swap_copy(out, in, len); -#endif + DECLARE_IS_ENDIAN; + + if (IS_LITTLE_ENDIAN) + swap_copy(out, in, len); + else + memcpy(out, in, len); } static const struct { @@ -103,12 +106,12 @@ static int test_param_type_extra(const OSSL_PARAM *param, unsigned char *cmp, if (signd) { if (!TEST_true(OSSL_PARAM_set_int32(param, 12345)) || !TEST_true(OSSL_PARAM_get_int64(param, &i64)) - || !TEST_size_t_eq(i64, 12345)) + || !TEST_size_t_eq((size_t)i64, 12345)) return 0; } else { if (!TEST_true(OSSL_PARAM_set_uint32(param, 12345)) || !TEST_true(OSSL_PARAM_get_uint64(param, (uint64_t *)&i64)) - || !TEST_size_t_eq(i64, 12345)) + || !TEST_size_t_eq((size_t)i64, 12345)) return 0; } } @@ -465,7 +468,7 @@ static int test_param_construct(void) OSSL_PARAM params[20]; char buf[100], buf2[100], *bufp, *bufp2; unsigned char ubuf[100]; - void *vp, *vp2; + void *vp, *vpn = NULL, *vp2; OSSL_PARAM *p; const OSSL_PARAM *cp; static const OSSL_PARAM pend = OSSL_PARAM_END; @@ -557,7 +560,6 @@ static int test_param_construct(void) || !TEST_ptr_eq(bufp2, bufp)) goto err; /* OCTET string */ - vp = NULL; if (!TEST_ptr(p = locate(params, "octstr")) || !TEST_true(OSSL_PARAM_set_octet_string(p, "abcdefghi", sizeof("abcdefghi"))) @@ -565,12 +567,11 @@ static int test_param_construct(void) goto err; /* Match the return size to avoid trailing garbage bytes */ p->data_size = *p->return_size; - if (!TEST_true(OSSL_PARAM_get_octet_string(p, &vp, 0, &s)) + if (!TEST_true(OSSL_PARAM_get_octet_string(p, &vpn, 0, &s)) || !TEST_size_t_eq(s, sizeof("abcdefghi")) - || !TEST_mem_eq(vp, sizeof("abcdefghi"), + || !TEST_mem_eq(vpn, sizeof("abcdefghi"), "abcdefghi", sizeof("abcdefghi"))) goto err; - OPENSSL_free(vp); vp = buf2; if (!TEST_true(OSSL_PARAM_get_octet_string(p, &vp, sizeof(buf2), &s)) || !TEST_size_t_eq(s, sizeof("abcdefghi")) @@ -604,6 +605,7 @@ static int test_param_construct(void) goto err; ret = 1; err: + OPENSSL_free(vpn); BN_free(bn); BN_free(bn2); return ret; diff --git a/test/provider_internal_test.c b/test/provider_internal_test.c index ca554b89..7f6bb20e 100644 --- a/test/provider_internal_test.c +++ b/test/provider_internal_test.c @@ -35,9 +35,9 @@ static int test_provider(OSSL_PROVIDER *prov) if (!TEST_ptr(name = ossl_provider_name(prov))) return 0; - snprintf(expected_greeting, sizeof(expected_greeting), - "Hello OpenSSL %.20s, greetings from %s!", - OPENSSL_VERSION_STR, name); + BIO_snprintf(expected_greeting, sizeof(expected_greeting), + "Hello OpenSSL %.20s, greetings from %s!", + OPENSSL_VERSION_STR, name); ret = TEST_true(ossl_provider_activate(prov)) diff --git a/test/provider_test.c b/test/provider_test.c index eefafcf5..cba7cbaa 100644 --- a/test/provider_test.c +++ b/test/provider_test.c @@ -32,9 +32,9 @@ static int test_provider(const char *name) const char *greeting = NULL; char expected_greeting[256]; - snprintf(expected_greeting, sizeof(expected_greeting), - "Hello OpenSSL %.20s, greetings from %s!", - OPENSSL_VERSION_STR, name); + BIO_snprintf(expected_greeting, sizeof(expected_greeting), + "Hello OpenSSL %.20s, greetings from %s!", + OPENSSL_VERSION_STR, name); return TEST_ptr(prov = OSSL_PROVIDER_load(NULL, name)) diff --git a/test/recipes/20-test_pkeyutl.t b/test/recipes/20-test_pkeyutl.t index 21f4e629..5dbed983 100644 --- a/test/recipes/20-test_pkeyutl.t +++ b/test/recipes/20-test_pkeyutl.t @@ -25,14 +25,14 @@ SKIP: { # SM2 ok(run(app(([ 'openssl', 'pkeyutl', '-sign', - '-in', srctop_file('test', 'certs', 'sm2.crt'), + '-in', srctop_file('test', 'certs', 'sm2.pem'), '-inkey', srctop_file('test', 'certs', 'sm2.key'), '-out', 'signature.dat', '-rawin', '-digest', 'sm3', '-pkeyopt', 'sm2_id:someid']))), "Sign a piece of data using SM2"); ok(run(app(([ 'openssl', 'pkeyutl', '-verify', '-certin', - '-in', srctop_file('test', 'certs', 'sm2.crt'), - '-inkey', srctop_file('test', 'certs', 'sm2.crt'), + '-in', srctop_file('test', 'certs', 'sm2.pem'), + '-inkey', srctop_file('test', 'certs', 'sm2.pem'), '-sigfile', 'signature.dat', '-rawin', '-digest', 'sm3', '-pkeyopt', 'sm2_id:someid']))), "Verify an SM2 signature against a piece of data"); diff --git a/test/recipes/25-test_verify.t b/test/recipes/25-test_verify.t index 9ddf2c9c..e4939478 100644 --- a/test/recipes/25-test_verify.t +++ b/test/recipes/25-test_verify.t @@ -27,7 +27,7 @@ sub verify { run(app([@args])); } -plan tests => 135; +plan tests => 137; # Canonical success ok(verify("ee-cert", "sslserver", ["root-cert"], ["ca-cert"]), @@ -373,3 +373,15 @@ SKIP: { "ED25519 signature"); } + +SKIP: { + skip "SM2 is not supported by this OpenSSL build", 1 + if disabled("sm2"); + + # Test '-sm2-id' and '-sm2-hex-id' option + ok(verify("sm2", "any", ["sm2-ca-cert"], [], "-sm2-id", "1234567812345678"), + "SM2 ID test"); + ok(verify("sm2", "any", ["sm2-ca-cert"], [], "-sm2-hex-id", + "31323334353637383132333435363738"), + "SM2 hex ID test"); +} diff --git a/test/recipes/25-test_x509.t b/test/recipes/25-test_x509.t index 0703e087..4780247e 100644 --- a/test/recipes/25-test_x509.t +++ b/test/recipes/25-test_x509.t @@ -11,11 +11,12 @@ use strict; use warnings; use File::Spec; +use OpenSSL::Test::Utils; use OpenSSL::Test qw/:DEFAULT srctop_file/; setup("test_x509"); -plan tests => 9; +plan tests => 10; require_ok(srctop_file('test','recipes','tconversion.pl')); @@ -34,6 +35,29 @@ is(cmp_text($out, srctop_file("test/certs", "cyrillic.utf8")), 0, 'Comparing utf8 output'); unlink $out; +SKIP: { + skip "EC disabled", 1 if disabled("ec"); + + # producing and checking self-issued (but not self-signed) cert + my @path = qw(test certs); + my $subj = "/CN=CA"; # using same DN as in issuer of ee-cert.pem + my $pkey = srctop_file(@path, "ca-key.pem"); # issuer private key + my $pubkey = "ca-pubkey.pem"; # the corresponding issuer public key + # use any (different) key for signing our self-issued cert: + my $signkey = srctop_file(@path, "ee-ecdsa-key.pem"); + my $selfout = "self-issued.out"; + my $testcert = srctop_file(@path, "ee-cert.pem"); + ok(run(app(["openssl", "pkey", "-in", $pkey, "-pubout", "-out", $pubkey])) + && + run(app(["openssl", "x509", "-new", "-force_pubkey", $pubkey, + "-subj", $subj, "-signkey", $signkey, "-out", $selfout])) + && + run(app(["openssl", "verify", "-no_check_time", + "-trusted", $selfout, $testcert]))); + unlink $pubkey; + unlink $selfout; +} + subtest 'x509 -- x.509 v1 certificate' => sub { tconversion("x509", srctop_file("test","testx509.pem")); }; diff --git a/test/recipes/30-test_evp_data/evpciph.txt b/test/recipes/30-test_evp_data/evpciph.txt index 8bf5ac18..c6a117cf 100644 --- a/test/recipes/30-test_evp_data/evpciph.txt +++ b/test/recipes/30-test_evp_data/evpciph.txt @@ -2233,7 +2233,7 @@ IV = 00000000000000000000000000000000 Plaintext = 11111111aaaaaaaa11111111bbbbbbbb11111111cccccccc11111111dddddddd22222222aaaaaaaa22222222bbbbbbbb22222222cccccccc22222222dddddddd33333333aaaaaaaa33333333bbbbbbbb33333333cccccccc33333333dddddddd44444444aaaaaaaa44444444bbbbbbbb44444444cccccccc44444444dddddddd55555555aaaaaaaa55555555bbbbbbbb55555555cccccccc55555555dddddddd Ciphertext = 30026c329666141721178b99c0a1f1b2f06940253f7b3089e2a30ea86aa3c88f5940f05ad7ee41d71347bb7261e348f18360473fdf7d4e7723bffb4411cc13f6cdd89f3bc7b9c768145022c7a74f14d7c305cd012a10f16050c23f1ae5c23f45998d13fbaa041e51619577e0772764896a5d4516d8ffceb3bf7e05f613edd9a60cdcedaff9cfcaf4e00d445a54334f73ab2cad944e51d266548e61c6eb0aa1cd -Title = ARIA GCM test vectors from IETF draft-ietf-avtcore-aria-srtp-10 +Title = ARIA GCM test vectors from RFC8269 Cipher = ARIA-128-GCM Key = e91e5e75da65554a48181f3846349562 @@ -2251,6 +2251,36 @@ Tag = e210d6ced2cf430ff841472915e7ef48 Plaintext = f57af5fd4ae19562976ec57a5a7ad55a5af5c5e5c5fdf5c55ad57a4a7272d57262e9729566ed66e97ac54a4a5a7ad5e15ae5fdd5fd5ac5d56ae56ad5c572d54ae54ac55a956afd6aed5a4ac562957a9516991691d572fd14e97ae962ed7a9f4a955af572e162f57a956666e17ae1f54a95f566d54a66e16e4afd6a9f7ae1c5c55ae5d56afde916c5e94a6ec56695e14afde1148416e94ad57ac5146ed59d1cc5 Ciphertext = 6f9e4bcbc8c85fc0128fb1e4a0a20cb9932ff74581f54fc013dd054b19f99371425b352d97d3f337b90b63d1b082adeeea9d2d7391897d591b985e55fb50cb5350cf7d38dc27dda127c078a149c8eb98083d66363a46e3726af217d3a00275ad5bf772c7610ea4c23006878f0ee69a8397703169a419303f40b72e4573714d19e2697df61e7c7252e5abc6bade876ac4961bfac4d5e867afca351a48aed52822 +Title = ARIA GCM self-generated test vectors + +Cipher = ARIA-128-GCM +Key = e91e5e75da65554a48181f3846349562 +# Shorter than default IV +IV = 0001020304 +AAD = 8008315ebf2e6fe020e8f5eb +Tag = ebaa2645bb154542117ee46031aa176e +Plaintext = f57af5fd4ae19562976ec57a5a7ad55a5af5c5e5c5fdf5c55ad57a4a7272d57262e9729566ed66e97ac54a4a5a7ad5e15ae5fdd5fd5ac5d56ae56ad5c572d54ae54ac55a956afd6aed5a4ac562957a9516991691d572fd14e97ae962ed7a9f4a955af572e162f57a956666e17ae1f54a95f566d54a66e16e4afd6a9f7ae1c5c55ae5d56afde916c5e94a6ec56695e14afde1148416e94ad57ac5146ed59d1cc5 +Ciphertext = 1723ccfc0ed44a12520473cfeb63bc933cd450a943f5f1cba78e19d72f80cc102acc51f2459a06cf6435182b8ddd451f83e13479efe5ec7dfbf16229f4017920fb41457a9b6fe1a401b30b2f332d827ae2f86e962326927c1ed8bfedac1f7a00ddde63bd392a8f28a488ba5974689f8d15b9b1739fb50aae0ff244026ec72064003c621b33ffc8086b0a97eefb70604a2826f6499f6eb12d67a0da03fc8e1482 + +Cipher = ARIA-128-GCM +Key = e91e5e75da65554a48181f3846349562 +# Longer than default IV +IV = 000102030405060708090a0b0c0d0e0f +AAD = 8008315ebf2e6fe020e8f5eb +Tag = 61f7f44c7da3c60195b29ae0b46051a4 +Plaintext = f57af5fd4ae19562976ec57a5a7ad55a5af5c5e5c5fdf5c55ad57a4a7272d57262e9729566ed66e97ac54a4a5a7ad5e15ae5fdd5fd5ac5d56ae56ad5c572d54ae54ac55a956afd6aed5a4ac562957a9516991691d572fd14e97ae962ed7a9f4a955af572e162f57a956666e17ae1f54a95f566d54a66e16e4afd6a9f7ae1c5c55ae5d56afde916c5e94a6ec56695e14afde1148416e94ad57ac5146ed59d1cc5 +Ciphertext = 0d3e98fcaf7a2c4fe9198d66add90d113e5e0ff47598c40a4bf501960d935a4156c9a4d46c9358a608e10a16479a4247c9ab9bb4a02809e3eac3571b832590fe2ca3e2d545741e36282d96c041fc7d39a46ed60214c2c0ec70f27768dfea4f9563b5d5c2ac33b1368a78f2908f5daf942433fec6ab588f09e908e95cc8dfa85d1a0dfd5835dc14e148323230c63eedc99a9ce942214cb3768b97b821d613629f + +Cipher = ARIA-128-GCM +Key = e91e5e75da65554a48181f3846349562 +# Extra long IV +IV = 000102030405060708090a0b0c0d0e0f1011 +AAD = 8008315ebf2e6fe020e8f5eb +Tag = c8b31ab6c2ddccab06b76af4e56e664e +Plaintext = f57af5fd4ae19562976ec57a5a7ad55a5af5c5e5c5fdf5c55ad57a4a7272d57262e9729566ed66e97ac54a4a5a7ad5e15ae5fdd5fd5ac5d56ae56ad5c572d54ae54ac55a956afd6aed5a4ac562957a9516991691d572fd14e97ae962ed7a9f4a955af572e162f57a956666e17ae1f54a95f566d54a66e16e4afd6a9f7ae1c5c55ae5d56afde916c5e94a6ec56695e14afde1148416e94ad57ac5146ed59d1cc5 +Ciphertext = 616a7bce24206501082cef7267c09a4affa54f8f82eb7fb2cdebdcaab4b6ab05c37e891c2d0fc90d15c5fb684247625c8bc0befad86896ae1c8f5a8506954caba4e13df0a0eb23853d4474e7f3b2c57bb398456a24d198e14566bce8a5f8d3bcdb12994d2fdc0f5cf19aeff990c1fe119e01f9fcc86757b1d43a9accf7b2f913c2208a46c1967f403867f89b46ffe96864c63f042265806ea5270e0dddd0e8dd + + Title = ARIA CCM test vectors from IETF draft-ietf-avtcore-aria-srtp-02 # 16-byte Tag diff --git a/test/recipes/30-test_evp_data/evpkdf.txt b/test/recipes/30-test_evp_data/evpkdf.txt index bbaa24f9..b3f2b791 100644 --- a/test/recipes/30-test_evp_data/evpkdf.txt +++ b/test/recipes/30-test_evp_data/evpkdf.txt @@ -1,5 +1,5 @@ # -# Copyright 2001-2018 The OpenSSL Project Authors. All Rights Reserved. +# Copyright 2001-2019 The OpenSSL Project Authors. All Rights Reserved. # # Licensed under the Apache License 2.0 (the "License"). You may not use # this file except in compliance with the License. You can obtain a copy @@ -5286,3 +5286,1091 @@ Ctrl.hexsession_id = hexsession_id:a4ebd45934f56792b5112dcd75a1075fdc889245 Ctrl.type = type:A Output = FF Result = KDF_MISMATCH + +#There are currently no official test vectors for Single Step KDF +#https://github.com/patrickfav/singlestep-kdf/wiki/NIST-SP-800-56C-Rev1:-Non-Official-Test-Vectors +Title = Single Step KDF tests + +KDF = SSKDF +Ctrl.digest = digest:SHA1 +Ctrl.hexsecret = hexsecret:d09a6b1a472f930db4f5e6b967900744 +Ctrl.hexinfo = hexinfo:b117255ab5f1b6b96fc434b0 +Output = b5a3c52e97ae6e8c5069954354eab3c7 + +KDF = SSKDF +Ctrl.digest = digest:SHA1 +Ctrl.hexsecret = hexsecret:343666c0dd34b756e70f759f14c304f5 +Ctrl.hexinfo = hexinfo:722b28448d7eab85491bce09 +Output = 1003b650ddd3f0891a15166db5ec881d + +KDF = SSKDF +Ctrl.digest = digest:SHA1 +Ctrl.hexsecret = hexsecret:b84acf03ab08652dd7f82fa956933261 +Ctrl.hexinfo = hexinfo:3d8773ec068c86053a918565 +Output = 1635dcd1ce698f736831b4badb68ab2b + +KDF = SSKDF +Ctrl.digest = digest:SHA1 +Ctrl.hexsecret = hexsecret:8cc24ca3f1d1a8b34783780b79890430 +Ctrl.hexinfo = hexinfo:f08d4f2d9a8e6d7105c0bc16 +Output = b8e716fb84a420aed4812cd76d9700ee + +KDF = SSKDF +Ctrl.digest = digest:SHA1 +Ctrl.hexsecret = hexsecret:b616905a6f7562cd2689142ce21e42a3 +Ctrl.hexinfo = hexinfo:ead310159a909da87e7b4b40 +Output = 1b9201358c50fe5d5d42907c4a9fce78 + +KDF = SSKDF +Ctrl.digest = digest:SHA1 +Ctrl.hexsecret = hexsecret:3f57fd3fd56199b3eb33890f7ee28180 +Ctrl.hexinfo = hexinfo:7a5056ba4fdb034c7cb6c4fe +Output = e51ebd30a8c4b8449b0fb29d9adc11af + +KDF = SSKDF +Ctrl.digest = digest:SHA1 +Ctrl.hexsecret = hexsecret:fb9fb108d104e9f662d6593fc84cde69 +Ctrl.hexinfo = hexinfo:5faf29211c1bdbf1b2696a7c +Output = 7a3a7e670656e48c390cdd7c51e167e0 + +KDF = SSKDF +Ctrl.digest = digest:SHA1 +Ctrl.hexsecret = hexsecret:237a39981794f4516dccffc3dda28396 +Ctrl.hexinfo = hexinfo:62ed9528d104c241e0f66275 +Output = 0c26fc9e90e1c5c5f943428301682045 + +KDF = SSKDF +Ctrl.digest = digest:SHA1 +Ctrl.hexsecret = hexsecret:b9b6c45f7279218fa09894e06366a3a1 +Ctrl.hexinfo = hexinfo:0f384339670aaed4b89ecb7e +Output = ee5fad414e32fad5d52a2bf61a7f6c72 + +KDF = SSKDF +Ctrl.digest = digest:SHA1 +Ctrl.hexsecret = hexsecret:08b7140e2cd0a4abd79171e4d5a71cad +Ctrl.hexinfo = hexinfo:099211f0d8a2e02dbb5958c0 +Output = 6162f5142e057efafd2c4f2bad5985a1 + +KDF = SSKDF +Ctrl.digest = digest:SHA1 +Ctrl.hexsecret = hexsecret:ebe28edbae5a410b87a479243db3f690 +Ctrl.hexinfo = hexinfo:e60dd8b28228ce5b9be74d3b +Output = b4a2 + +KDF = SSKDF +Ctrl.digest = digest:SHA1 +Ctrl.hexsecret = hexsecret:ebe28edbae5a410b87a479243db3f690 +Ctrl.hexinfo = hexinfo:e60dd8b28228ce5b9be74d3b +Output = b4a23963 + +KDF = SSKDF +Ctrl.digest = digest:SHA1 +Ctrl.hexsecret = hexsecret:ebe28edbae5a410b87a479243db3f690 +Ctrl.hexinfo = hexinfo:e60dd8b28228ce5b9be74d3b +Output = b4a23963e07f + +KDF = SSKDF +Ctrl.digest = digest:SHA1 +Ctrl.hexsecret = hexsecret:ebe28edbae5a410b87a479243db3f690 +Ctrl.hexinfo = hexinfo:e60dd8b28228ce5b9be74d3b +Output = b4a23963e07f4853 + +KDF = SSKDF +Ctrl.digest = digest:SHA1 +Ctrl.hexsecret = hexsecret:ebe28edbae5a410b87a479243db3f690 +Ctrl.hexinfo = hexinfo:e60dd8b28228ce5b9be74d3b +Output = b4a23963e07f485382cb + +KDF = SSKDF +Ctrl.digest = digest:SHA1 +Ctrl.hexsecret = hexsecret:ebe28edbae5a410b87a479243db3f690 +Ctrl.hexinfo = hexinfo:e60dd8b28228ce5b9be74d3b +Output = b4a23963e07f485382cb358a + +KDF = SSKDF +Ctrl.digest = digest:SHA1 +Ctrl.hexsecret = hexsecret:ebe28edbae5a410b87a479243db3f690 +Ctrl.hexinfo = hexinfo:e60dd8b28228ce5b9be74d3b +Output = b4a23963e07f485382cb358a493d + +KDF = SSKDF +Ctrl.digest = digest:SHA1 +Ctrl.hexsecret = hexsecret:ebe28edbae5a410b87a479243db3f690 +Ctrl.hexinfo = hexinfo:e60dd8b28228ce5b9be74d3b +Output = b4a23963e07f485382cb358a493daec1 + +KDF = SSKDF +Ctrl.digest = digest:SHA1 +Ctrl.hexsecret = hexsecret:ebe28edbae5a410b87a479243db3f690 +Ctrl.hexinfo = hexinfo:e60dd8b28228ce5b9be74d3b +Output = b4a23963e07f485382cb358a493daec1759a + +KDF = SSKDF +Ctrl.digest = digest:SHA1 +Ctrl.hexsecret = hexsecret:ebe28edbae5a410b87a479243db3f690 +Ctrl.hexinfo = hexinfo:e60dd8b28228ce5b9be74d3b +Output = b4a23963e07f485382cb358a493daec1759ac704 + +KDF = SSKDF +Ctrl.digest = digest:SHA1 +Ctrl.hexsecret = hexsecret:ebe28edbae5a410b87a479243db3f690 +Ctrl.hexinfo = hexinfo:e60dd8b28228ce5b9be74d3b +Output = b4a23963e07f485382cb358a493daec1759ac7043dbe + +KDF = SSKDF +Ctrl.digest = digest:SHA1 +Ctrl.hexsecret = hexsecret:ebe28edbae5a410b87a479243db3f690 +Ctrl.hexinfo = hexinfo:e60dd8b28228ce5b9be74d3b +Output = b4a23963e07f485382cb358a493daec1759ac7043dbeac37 + +KDF = SSKDF +Ctrl.digest = digest:SHA1 +Ctrl.hexsecret = hexsecret:ebe28edbae5a410b87a479243db3f690 +Ctrl.hexinfo = hexinfo:e60dd8b28228ce5b9be74d3b +Output = b4a23963e07f485382cb358a493daec1759ac7043dbeac37152c + +KDF = SSKDF +Ctrl.digest = digest:SHA1 +Ctrl.hexsecret = hexsecret:ebe28edbae5a410b87a479243db3f690 +Ctrl.hexinfo = hexinfo:e60dd8b28228ce5b9be74d3b +Output = b4a23963e07f485382cb358a493daec1759ac7043dbeac37152c6ddf + +KDF = SSKDF +Ctrl.digest = digest:SHA1 +Ctrl.hexsecret = hexsecret:ebe28edbae5a410b87a479243db3f690 +Ctrl.hexinfo = hexinfo:e60dd8b28228ce5b9be74d3b +Output = b4a23963e07f485382cb358a493daec1759ac7043dbeac37152c6ddf1050 + +KDF = SSKDF +Ctrl.digest = digest:SHA1 +Ctrl.hexsecret = hexsecret:ebe28edbae5a410b87a479243db3f690 +Ctrl.hexinfo = hexinfo:e60dd8b28228ce5b9be74d3b +Output = b4a23963e07f485382cb358a493daec1759ac7043dbeac37152c6ddf105031f0 + +KDF = SSKDF +Ctrl.digest = digest:SHA1 +Ctrl.hexsecret = hexsecret:ebe28edbae5a410b87a479243db3f690 +Ctrl.hexinfo = hexinfo:e60dd8b28228ce5b9be74d3b +Output = b4a23963e07f485382cb358a493daec1759ac7043dbeac37152c6ddf105031f0f239 + +KDF = SSKDF +Ctrl.digest = digest:SHA1 +Ctrl.hexsecret = hexsecret:ebe28edbae5a410b87a479243db3f690 +Ctrl.hexinfo = hexinfo:e60dd8b28228ce5b9be74d3b +Output = b4a23963e07f485382cb358a493daec1759ac7043dbeac37152c6ddf105031f0f239f270 + +KDF = SSKDF +Ctrl.digest = digest:SHA1 +Ctrl.hexsecret = hexsecret:ebe28edbae5a410b87a479243db3f690 +Ctrl.hexinfo = hexinfo:e60dd8b28228ce5b9be74d3b +Output = b4a23963e07f485382cb358a493daec1759ac7043dbeac37152c6ddf105031f0f239f270b7f3 + +KDF = SSKDF +Ctrl.digest = digest:SHA1 +Ctrl.hexsecret = hexsecret:ebe28edbae5a410b87a479243db3f690 +Ctrl.hexinfo = hexinfo:e60dd8b28228ce5b9be74d3b +Output = b4a23963e07f485382cb358a493daec1759ac7043dbeac37152c6ddf105031f0f239f270b7f30616 + +KDF = SSKDF +Ctrl.digest = digest:SHA1 +Ctrl.hexsecret = hexsecret:ebe28edbae5a410b87a479243db3f690 +Ctrl.hexinfo = hexinfo:e60dd8b28228ce5b9be74d3b +Output = b4a23963e07f485382cb358a493daec1759ac7043dbeac37152c6ddf105031f0f239f270b7f30616166f + +KDF = SSKDF +Ctrl.digest = digest:SHA1 +Ctrl.hexsecret = hexsecret:ebe28edbae5a410b87a479243db3f690 +Ctrl.hexinfo = hexinfo:e60dd8b28228ce5b9be74d3b +Output = b4a23963e07f485382cb358a493daec1759ac7043dbeac37152c6ddf105031f0f239f270b7f30616166f10e5 + +KDF = SSKDF +Ctrl.digest = digest:SHA1 +Ctrl.hexsecret = hexsecret:ebe28edbae5a410b87a479243db3f690 +Ctrl.hexinfo = hexinfo:e60dd8b28228ce5b9be74d3b +Output = b4a23963e07f485382cb358a493daec1759ac7043dbeac37152c6ddf105031f0f239f270b7f30616166f10e5d2b4 + +KDF = SSKDF +Ctrl.digest = digest:SHA1 +Ctrl.hexsecret = hexsecret:ebe28edbae5a410b87a479243db3f690 +Ctrl.hexinfo = hexinfo:e60dd8b28228ce5b9be74d3b +Output = b4a23963e07f485382cb358a493daec1759ac7043dbeac37152c6ddf105031f0f239f270b7f30616166f10e5d2b4cb11 + +KDF = SSKDF +Ctrl.digest = digest:SHA1 +Ctrl.hexsecret = hexsecret:ebe28edbae5a410b87a479243db3f690 +Ctrl.hexinfo = hexinfo:e60dd8b28228ce5b9be74d3b +Output = b4a23963e07f485382cb358a493daec1759ac7043dbeac37152c6ddf105031f0f239f270b7f30616166f10e5d2b4cb11ba8b + +KDF = SSKDF +Ctrl.digest = digest:SHA1 +Ctrl.hexsecret = hexsecret:ebe28edbae5a410b87a479243db3f690 +Ctrl.hexinfo = hexinfo:e60dd8b28228ce5b9be74d3b +Output = b4a23963e07f485382cb358a493daec1759ac7043dbeac37152c6ddf105031f0f239f270b7f30616166f10e5d2b4cb11ba8bf4ba + +KDF = SSKDF +Ctrl.digest = digest:SHA1 +Ctrl.hexsecret = hexsecret:ebe28edbae5a410b87a479243db3f690 +Ctrl.hexinfo = hexinfo:e60dd8b28228ce5b9be74d3b +Output = b4a23963e07f485382cb358a493daec1759ac7043dbeac37152c6ddf105031f0f239f270b7f30616166f10e5d2b4cb11ba8bf4ba3f22 + +KDF = SSKDF +Ctrl.digest = digest:SHA1 +Ctrl.hexsecret = hexsecret:ebe28edbae5a410b87a479243db3f690 +Ctrl.hexinfo = hexinfo:e60dd8b28228ce5b9be74d3b +Output = b4a23963e07f485382cb358a493daec1759ac7043dbeac37152c6ddf105031f0f239f270b7f30616166f10e5d2b4cb11ba8bf4ba3f227688 + +KDF = SSKDF +Ctrl.digest = digest:SHA1 +Ctrl.hexsecret = hexsecret:ebe28edbae5a410b87a479243db3f690 +Ctrl.hexinfo = hexinfo:e60dd8b28228ce5b9be74d3b +Output = b4a23963e07f485382cb358a493daec1759ac7043dbeac37152c6ddf105031f0f239f270b7f30616166f10e5d2b4cb11ba8bf4ba3f2276885abf + +KDF = SSKDF +Ctrl.digest = digest:SHA1 +Ctrl.hexsecret = hexsecret:ebe28edbae5a410b87a479243db3f690 +Ctrl.hexinfo = hexinfo:e60dd8b28228ce5b9be74d3b +Output = b4a23963e07f485382cb358a493daec1759ac7043dbeac37152c6ddf105031f0f239f270b7f30616166f10e5d2b4cb11ba8bf4ba3f2276885abfbc3e + +KDF = SSKDF +Ctrl.digest = digest:SHA1 +Ctrl.hexsecret = hexsecret:ebe28edbae5a410b87a479243db3f690 +Ctrl.hexinfo = hexinfo:e60dd8b28228ce5b9be74d3b +Output = b4a23963e07f485382cb358a493daec1759ac7043dbeac37152c6ddf105031f0f239f270b7f30616166f10e5d2b4cb11ba8bf4ba3f2276885abfbc3e811a + +KDF = SSKDF +Ctrl.digest = digest:SHA1 +Ctrl.hexsecret = hexsecret:ebe28edbae5a410b87a479243db3f690 +Ctrl.hexinfo = hexinfo:e60dd8b28228ce5b9be74d3b +Output = b4a23963e07f485382cb358a493daec1759ac7043dbeac37152c6ddf105031f0f239f270b7f30616166f10e5d2b4cb11ba8bf4ba3f2276885abfbc3e811a568d + +KDF = SSKDF +Ctrl.digest = digest:SHA1 +Ctrl.hexsecret = hexsecret:ebe28edbae5a410b87a479243db3f690 +Ctrl.hexinfo = hexinfo:e60dd8b28228ce5b9be74d3b +Output = b4a23963e07f485382cb358a493daec1759ac7043dbeac37152c6ddf105031f0f239f270b7f30616166f10e5d2b4cb11ba8bf4ba3f2276885abfbc3e811a568d480d + +KDF = SSKDF +Ctrl.digest = digest:SHA1 +Ctrl.hexsecret = hexsecret:ebe28edbae5a410b87a479243db3f690 +Ctrl.hexinfo = hexinfo:e60dd8b28228ce5b9be74d3b +Output = b4a23963e07f485382cb358a493daec1759ac7043dbeac37152c6ddf105031f0f239f270b7f30616166f10e5d2b4cb11ba8bf4ba3f2276885abfbc3e811a568d480d9192 + +KDF = SSKDF +Ctrl.digest = digest:SHA1 +Ctrl.hexsecret = hexsecret:d7e6 +Ctrl.hexinfo = hexinfo:0bbe1fa8722023d7c3da4fff +Output = 31e798e9931b612a3ad1b9b1008faa8c + +KDF = SSKDF +Ctrl.digest = digest:SHA1 +Ctrl.hexsecret = hexsecret:4646779d +Ctrl.hexinfo = hexinfo:0bbe1fa8722023d7c3da4fff +Output = 139f68bcca879b490e268e569087d04d + +KDF = SSKDF +Ctrl.digest = digest:SHA1 +Ctrl.hexsecret = hexsecret:d9811c81d4c6 +Ctrl.hexinfo = hexinfo:0bbe1fa8722023d7c3da4fff +Output = 914dc4f09cb633a76e6c389e04c64485 + +KDF = SSKDF +Ctrl.digest = digest:SHA1 +Ctrl.hexsecret = hexsecret:8838f9d99ec46f09 +Ctrl.hexinfo = hexinfo:0bbe1fa8722023d7c3da4fff +Output = 4f07dfb6f7a5bf348689e08b2e29c948 + +KDF = SSKDF +Ctrl.digest = digest:SHA1 +Ctrl.hexsecret = hexsecret:3e0939b33f34e779f30e +Ctrl.hexinfo = hexinfo:0bbe1fa8722023d7c3da4fff +Output = b42c7a98c23be19d1187ff960e87557f + +KDF = SSKDF +Ctrl.digest = digest:SHA1 +Ctrl.hexsecret = hexsecret:f36230cacca4d245d303058c +Ctrl.hexinfo = hexinfo:0bbe1fa8722023d7c3da4fff +Output = 50f2068d8010d355d56c5e34aaffbc67 + +KDF = SSKDF +Ctrl.digest = digest:SHA1 +Ctrl.hexsecret = hexsecret:7005d32c3d4284c73c3aefc70438 +Ctrl.hexinfo = hexinfo:0bbe1fa8722023d7c3da4fff +Output = 66fd712ccf5462bbd41e89041ea7ea26 + +KDF = SSKDF +Ctrl.digest = digest:SHA1 +Ctrl.hexsecret = hexsecret:c01c83150b7734f8dbd6efd6f54d7365 +Ctrl.hexinfo = hexinfo:0bbe1fa8722023d7c3da4fff +Output = 5c5edb0ceda9cd0c7f1f3d9e239c67d5 + +KDF = SSKDF +Ctrl.digest = digest:SHA1 +Ctrl.hexsecret = hexsecret:da69f1dbbebc837480af692e7e9ee6b9 +Ctrl.hexinfo = hexinfo:9949 +Output = 33c83f54ed00fb1bccd2113e88550941 + +KDF = SSKDF +Ctrl.digest = digest:SHA1 +Ctrl.hexsecret = hexsecret:da69f1dbbebc837480af692e7e9ee6b9 +Ctrl.hexinfo = hexinfo:17144da6 +Output = a999c28961424cab35ec06015e8c376a + +KDF = SSKDF +Ctrl.digest = digest:SHA1 +Ctrl.hexsecret = hexsecret:da69f1dbbebc837480af692e7e9ee6b9 +Ctrl.hexinfo = hexinfo:dffdee1062eb +Output = 4101ad50e626ed6f957bff926dfbb7db + +KDF = SSKDF +Ctrl.digest = digest:SHA1 +Ctrl.hexsecret = hexsecret:da69f1dbbebc837480af692e7e9ee6b9 +Ctrl.hexinfo = hexinfo:9f365043e23b4648 +Output = 4d3e4b971b88771f229df9f564984832 + +KDF = SSKDF +Ctrl.digest = digest:SHA1 +Ctrl.hexsecret = hexsecret:da69f1dbbebc837480af692e7e9ee6b9 +Ctrl.hexinfo = hexinfo:a885a0c4567ddc4f96da +Output = bebbc30f5a83df5e9c9b57db33c0c879 + +KDF = SSKDF +Ctrl.digest = digest:SHA1 +Ctrl.hexsecret = hexsecret:da69f1dbbebc837480af692e7e9ee6b9 +Ctrl.hexinfo = hexinfo:c9d86183295bfe4c3d85f0fd +Output = 87c947e45407db63eb94cbaa02d14e94 + +KDF = SSKDF +Ctrl.digest = digest:SHA1 +Ctrl.hexsecret = hexsecret:da69f1dbbebc837480af692e7e9ee6b9 +Ctrl.hexinfo = hexinfo:825fadce46964236a486732c5dad +Output = 192370a85ff78e3c0245129d9b398558 + +KDF = SSKDF +Ctrl.digest = digest:SHA1 +Ctrl.hexsecret = hexsecret:da69f1dbbebc837480af692e7e9ee6b9 +Ctrl.hexinfo = hexinfo:5c0b5eb3ac9f342347d73d7a521723aa +Output = c7b7634fd809383e87c4b1b3e728be56 + +KDF = SSKDF +Ctrl.digest = digest:SHA1 +Ctrl.hexsecret = hexsecret:8d7a4e7d5cf34b3f74873b862aeb33b7 +Output = 6a5594f402f74f69 + +KDF = SSKDF +Ctrl.digest = digest:SHA1 +Ctrl.hexsecret = hexsecret:9b208e7ee1e641fac1dff48fc1beb2d2 +Output = 556ed67e24ac0c7c46cc432da8bdb23c + +KDF = SSKDF +Ctrl.digest = digest:SHA1 +Ctrl.hexsecret = hexsecret:4d2572539fed433211da28c8a0eebac3 +Output = 5a4054c59c5b92814025578f43c1b79fe84968fc284e240b + +KDF = SSKDF +Ctrl.digest = digest:SHA1 +Ctrl.hexsecret = hexsecret:4e1e70c9886819a31bc29a537911add9 +Output = ddbfc440449aab4131c6d8aec08ce1496f2702241d0e27cc155c5c7c3cda75b5 + +KDF = SSKDF +Ctrl.digest = digest:SHA1 +Ctrl.hexsecret = hexsecret:68f144c952528e540c686dc353b766f2 +Output = 59ed66bb6f54a9688a0b891d0b2ea6743621d9e1b5cc098cf3a55e6f864f9af8a95e4d945d2f987f + +KDF = SSKDF +Ctrl.digest = digest:SHA1 +Ctrl.hexsecret = hexsecret:b66c9d507c9f837fbe60b6675fdbf38b +Output = c282787ddf421a72fc88811be81b08d0d6ab66c92d1011974aa58335a6bbbd62e9e982bfae5929865ea1d517247089d2 + +KDF = SSKDF +Ctrl.digest = digest:SHA1 +Ctrl.hexsecret = hexsecret:34e730b49e46c7ed2fb25975a4cccd2d +Output = 39e76e6571cb00740260b9070accbdcc4a492c295cbef33d9e37dac21e5e9d07e0f12dc7063d2172641475d4e08b8e3712fb26a10c8376b8 + +KDF = SSKDF +Ctrl.digest = digest:SHA1 +Ctrl.hexsecret = hexsecret:e340d87e2d7adbc1b95ec2dbdc3b82be +Output = a660c0037a53f76f1e7667043f5869348ad07ac0e272e615ce31f16d4ab90d4b35fe5c370c0010ce79aff45682c6fb8b97f9a05b7d40b5af3c62999a10df9c6d + +KDF = SSKDF +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:afc4e154498d4770aa8365f6903dc83b +Ctrl.hexinfo = hexinfo:662af20379b29d5ef813e655 +Output = f0b80d6ae4c1e19e2105a37024e35dc6 + + +KDF = SSKDF +Ctrl.digest = digest:SHA512 +Ctrl.hexsecret = hexsecret:108cf63318555c787fa578731dd4f037 +Ctrl.hexinfo = hexinfo:53191b1dd3f94d83084d61d6 +Output = 0ad475c1826da3007637970c8b92b993 + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:6ee6c00d70a6cd14bd5a4e8fcfec8386 +Ctrl.hexsalt = hexsalt:532f5131e0a2fecc722f87e5aa2062cb +Ctrl.hexinfo = hexinfo:861aa2886798231259bd0314 +Output = 13479e9a91dd20fdd757d68ffe8869fb + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:cb09b565de1ac27a50289b3704b93afd +Ctrl.hexsalt = hexsalt:d504c1c41a499481ce88695d18ae2e8f +Ctrl.hexinfo = hexinfo:5ed3768c2c7835943a789324 +Output = f081c0255b0cae16edc6ce1d6c9d12bc + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:98f50345fd970639a1b7935f501e1d7c +Ctrl.hexsalt = hexsalt:3691939461247e9f74382ae4ef629b17 +Ctrl.hexinfo = hexinfo:6ddbdb1314663152c3ccc192 +Output = 56f42183ed3e287298dbbecf143f51ac + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:a72b0076221727eca4d3ef8f4d88ac96 +Ctrl.hexsalt = hexsalt:397dc6807de2c1d5ba52e03c4e6c7a19 +Ctrl.hexinfo = hexinfo:12379bd7873a7dbabe894ac8 +Output = 26c0f937e8ca337a859b6c092fe22b9a + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:0b09bf8ebe1e85a049174c521e35be64 +Ctrl.hexsalt = hexsalt:313d29bbeaa5ac9e52278f7619d29d93 +Ctrl.hexinfo = hexinfo:e2ac98de1486959bfc6363c0 +Output = 4bfdf78782a45e2a5858edb851c5783c + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:e907ad4fe811ee047af77e0c4418226a +Ctrl.hexsalt = hexsalt:5000ef57104ca2e86a5fec5883ea4ea8 +Ctrl.hexinfo = hexinfo:c4ee443920f2b7542eee2a24 +Output = 06bfbd9571462c920a5a1b589c765383 + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:608dae15fe8b906d2dc649815bdee148 +Ctrl.hexsalt = hexsalt:742cc5a02a24d09c66fd9da0d0c571f6 +Ctrl.hexinfo = hexinfo:ba60ff781e2756cba07f6524 +Output = 7f7f9e5d8f89a8edd10289f1d690f629 + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:eb39e8dc7c40b906216108e2592bb6cd +Ctrl.hexsalt = hexsalt:af9f612da575c1afc8c4afff4ced34e1 +Ctrl.hexinfo = hexinfo:84b7f0628df0cb22baaa279a +Output = 5202576c69c6276daedf4916de250d19 + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:4bac0c1a963b8cf6933beb2ad191a31e +Ctrl.hexsalt = hexsalt:debd24d71a1a7ae77f7e3aa24d939635 +Ctrl.hexinfo = hexinfo:9e51c8593cec92c89e82439a +Output = ecb9889f9004f80716b56c44910f160c + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:8aa41e3c8076ea01ca6789dd18709a68 +Ctrl.hexsalt = hexsalt:7c9dacc409cde7b05efdae07bd9973db +Ctrl.hexinfo = hexinfo:52651f0f2e858bbfbacb2533 +Output = b8683c9a982e0826d659a1ab77a603d7 + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:02b40d33e3f685aeae677ac344eeaf77 +Ctrl.hexsalt = hexsalt:0ad52c9357c85e4781296a36ca72039c +Ctrl.hexinfo = hexinfo:c67c389580128f18f6cf8592 +Output = be32 + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:02b40d33e3f685aeae677ac344eeaf77 +Ctrl.hexsalt = hexsalt:0ad52c9357c85e4781296a36ca72039c +Ctrl.hexinfo = hexinfo:c67c389580128f18f6cf8592 +Output = be32e7d3 + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:02b40d33e3f685aeae677ac344eeaf77 +Ctrl.hexsalt = hexsalt:0ad52c9357c85e4781296a36ca72039c +Ctrl.hexinfo = hexinfo:c67c389580128f18f6cf8592 +Output = be32e7d306d8 + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:02b40d33e3f685aeae677ac344eeaf77 +Ctrl.hexsalt = hexsalt:0ad52c9357c85e4781296a36ca72039c +Ctrl.hexinfo = hexinfo:c67c389580128f18f6cf8592 +Output = be32e7d306d89102 + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:02b40d33e3f685aeae677ac344eeaf77 +Ctrl.hexsalt = hexsalt:0ad52c9357c85e4781296a36ca72039c +Ctrl.hexinfo = hexinfo:c67c389580128f18f6cf8592 +Output = be32e7d306d891028be0 + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:02b40d33e3f685aeae677ac344eeaf77 +Ctrl.hexsalt = hexsalt:0ad52c9357c85e4781296a36ca72039c +Ctrl.hexinfo = hexinfo:c67c389580128f18f6cf8592 +Output = be32e7d306d891028be088f2 + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:02b40d33e3f685aeae677ac344eeaf77 +Ctrl.hexsalt = hexsalt:0ad52c9357c85e4781296a36ca72039c +Ctrl.hexinfo = hexinfo:c67c389580128f18f6cf8592 +Output = be32e7d306d891028be088f213f9 + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:02b40d33e3f685aeae677ac344eeaf77 +Ctrl.hexsalt = hexsalt:0ad52c9357c85e4781296a36ca72039c +Ctrl.hexinfo = hexinfo:c67c389580128f18f6cf8592 +Output = be32e7d306d891028be088f213f9f947 + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:02b40d33e3f685aeae677ac344eeaf77 +Ctrl.hexsalt = hexsalt:0ad52c9357c85e4781296a36ca72039c +Ctrl.hexinfo = hexinfo:c67c389580128f18f6cf8592 +Output = be32e7d306d891028be088f213f9f947c504 + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:02b40d33e3f685aeae677ac344eeaf77 +Ctrl.hexsalt = hexsalt:0ad52c9357c85e4781296a36ca72039c +Ctrl.hexinfo = hexinfo:c67c389580128f18f6cf8592 +Output = be32e7d306d891028be088f213f9f947c50420d9 + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:02b40d33e3f685aeae677ac344eeaf77 +Ctrl.hexsalt = hexsalt:0ad52c9357c85e4781296a36ca72039c +Ctrl.hexinfo = hexinfo:c67c389580128f18f6cf8592 +Output = be32e7d306d891028be088f213f9f947c50420d9b5a1 + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:02b40d33e3f685aeae677ac344eeaf77 +Ctrl.hexsalt = hexsalt:0ad52c9357c85e4781296a36ca72039c +Ctrl.hexinfo = hexinfo:c67c389580128f18f6cf8592 +Output = be32e7d306d891028be088f213f9f947c50420d9b5a12ca6 + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:02b40d33e3f685aeae677ac344eeaf77 +Ctrl.hexsalt = hexsalt:0ad52c9357c85e4781296a36ca72039c +Ctrl.hexinfo = hexinfo:c67c389580128f18f6cf8592 +Output = be32e7d306d891028be088f213f9f947c50420d9b5a12ca69818 + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:02b40d33e3f685aeae677ac344eeaf77 +Ctrl.hexsalt = hexsalt:0ad52c9357c85e4781296a36ca72039c +Ctrl.hexinfo = hexinfo:c67c389580128f18f6cf8592 +Output = be32e7d306d891028be088f213f9f947c50420d9b5a12ca69818dd99 + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:02b40d33e3f685aeae677ac344eeaf77 +Ctrl.hexsalt = hexsalt:0ad52c9357c85e4781296a36ca72039c +Ctrl.hexinfo = hexinfo:c67c389580128f18f6cf8592 +Output = be32e7d306d891028be088f213f9f947c50420d9b5a12ca69818dd9995de + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:02b40d33e3f685aeae677ac344eeaf77 +Ctrl.hexsalt = hexsalt:0ad52c9357c85e4781296a36ca72039c +Ctrl.hexinfo = hexinfo:c67c389580128f18f6cf8592 +Output = be32e7d306d891028be088f213f9f947c50420d9b5a12ca69818dd9995dedd8e + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:02b40d33e3f685aeae677ac344eeaf77 +Ctrl.hexsalt = hexsalt:0ad52c9357c85e4781296a36ca72039c +Ctrl.hexinfo = hexinfo:c67c389580128f18f6cf8592 +Output = be32e7d306d891028be088f213f9f947c50420d9b5a12ca69818dd9995dedd8e6137 + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:02b40d33e3f685aeae677ac344eeaf77 +Ctrl.hexsalt = hexsalt:0ad52c9357c85e4781296a36ca72039c +Ctrl.hexinfo = hexinfo:c67c389580128f18f6cf8592 +Output = be32e7d306d891028be088f213f9f947c50420d9b5a12ca69818dd9995dedd8e6137c710 + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:02b40d33e3f685aeae677ac344eeaf77 +Ctrl.hexsalt = hexsalt:0ad52c9357c85e4781296a36ca72039c +Ctrl.hexinfo = hexinfo:c67c389580128f18f6cf8592 +Output = be32e7d306d891028be088f213f9f947c50420d9b5a12ca69818dd9995dedd8e6137c7104d67 + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:02b40d33e3f685aeae677ac344eeaf77 +Ctrl.hexsalt = hexsalt:0ad52c9357c85e4781296a36ca72039c +Ctrl.hexinfo = hexinfo:c67c389580128f18f6cf8592 +Output = be32e7d306d891028be088f213f9f947c50420d9b5a12ca69818dd9995dedd8e6137c7104d67f2ca + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:02b40d33e3f685aeae677ac344eeaf77 +Ctrl.hexsalt = hexsalt:0ad52c9357c85e4781296a36ca72039c +Ctrl.hexinfo = hexinfo:c67c389580128f18f6cf8592 +Output = be32e7d306d891028be088f213f9f947c50420d9b5a12ca69818dd9995dedd8e6137c7104d67f2ca9091 + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:02b40d33e3f685aeae677ac344eeaf77 +Ctrl.hexsalt = hexsalt:0ad52c9357c85e4781296a36ca72039c +Ctrl.hexinfo = hexinfo:c67c389580128f18f6cf8592 +Output = be32e7d306d891028be088f213f9f947c50420d9b5a12ca69818dd9995dedd8e6137c7104d67f2ca90915dda + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:02b40d33e3f685aeae677ac344eeaf77 +Ctrl.hexsalt = hexsalt:0ad52c9357c85e4781296a36ca72039c +Ctrl.hexinfo = hexinfo:c67c389580128f18f6cf8592 +Output = be32e7d306d891028be088f213f9f947c50420d9b5a12ca69818dd9995dedd8e6137c7104d67f2ca90915dda0ab6 + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:02b40d33e3f685aeae677ac344eeaf77 +Ctrl.hexsalt = hexsalt:0ad52c9357c85e4781296a36ca72039c +Ctrl.hexinfo = hexinfo:c67c389580128f18f6cf8592 +Output = be32e7d306d891028be088f213f9f947c50420d9b5a12ca69818dd9995dedd8e6137c7104d67f2ca90915dda0ab68af2 + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:02b40d33e3f685aeae677ac344eeaf77 +Ctrl.hexsalt = hexsalt:0ad52c9357c85e4781296a36ca72039c +Ctrl.hexinfo = hexinfo:c67c389580128f18f6cf8592 +Output = be32e7d306d891028be088f213f9f947c50420d9b5a12ca69818dd9995dedd8e6137c7104d67f2ca90915dda0ab68af2f355 + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:02b40d33e3f685aeae677ac344eeaf77 +Ctrl.hexsalt = hexsalt:0ad52c9357c85e4781296a36ca72039c +Ctrl.hexinfo = hexinfo:c67c389580128f18f6cf8592 +Output = be32e7d306d891028be088f213f9f947c50420d9b5a12ca69818dd9995dedd8e6137c7104d67f2ca90915dda0ab68af2f355b904 + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:02b40d33e3f685aeae677ac344eeaf77 +Ctrl.hexsalt = hexsalt:0ad52c9357c85e4781296a36ca72039c +Ctrl.hexinfo = hexinfo:c67c389580128f18f6cf8592 +Output = be32e7d306d891028be088f213f9f947c50420d9b5a12ca69818dd9995dedd8e6137c7104d67f2ca90915dda0ab68af2f355b904f9eb + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:02b40d33e3f685aeae677ac344eeaf77 +Ctrl.hexsalt = hexsalt:0ad52c9357c85e4781296a36ca72039c +Ctrl.hexinfo = hexinfo:c67c389580128f18f6cf8592 +Output = be32e7d306d891028be088f213f9f947c50420d9b5a12ca69818dd9995dedd8e6137c7104d67f2ca90915dda0ab68af2f355b904f9eb0388 + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:02b40d33e3f685aeae677ac344eeaf77 +Ctrl.hexsalt = hexsalt:0ad52c9357c85e4781296a36ca72039c +Ctrl.hexinfo = hexinfo:c67c389580128f18f6cf8592 +Output = be32e7d306d891028be088f213f9f947c50420d9b5a12ca69818dd9995dedd8e6137c7104d67f2ca90915dda0ab68af2f355b904f9eb0388b5b7 + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:02b40d33e3f685aeae677ac344eeaf77 +Ctrl.hexsalt = hexsalt:0ad52c9357c85e4781296a36ca72039c +Ctrl.hexinfo = hexinfo:c67c389580128f18f6cf8592 +Output = be32e7d306d891028be088f213f9f947c50420d9b5a12ca69818dd9995dedd8e6137c7104d67f2ca90915dda0ab68af2f355b904f9eb0388b5b7fe19 + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:02b40d33e3f685aeae677ac344eeaf77 +Ctrl.hexsalt = hexsalt:0ad52c9357c85e4781296a36ca72039c +Ctrl.hexinfo = hexinfo:c67c389580128f18f6cf8592 +Output = be32e7d306d891028be088f213f9f947c50420d9b5a12ca69818dd9995dedd8e6137c7104d67f2ca90915dda0ab68af2f355b904f9eb0388b5b7fe193c95 + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:02b40d33e3f685aeae677ac344eeaf77 +Ctrl.hexsalt = hexsalt:0ad52c9357c85e4781296a36ca72039c +Ctrl.hexinfo = hexinfo:c67c389580128f18f6cf8592 +Output = be32e7d306d891028be088f213f9f947c50420d9b5a12ca69818dd9995dedd8e6137c7104d67f2ca90915dda0ab68af2f355b904f9eb0388b5b7fe193c9546d4 + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:02b40d33e3f685aeae677ac344eeaf77 +Ctrl.hexsalt = hexsalt:0ad52c9357c85e4781296a36ca72039c +Ctrl.hexinfo = hexinfo:c67c389580128f18f6cf8592 +Output = be32e7d306d891028be088f213f9f947c50420d9b5a12ca69818dd9995dedd8e6137c7104d67f2ca90915dda0ab68af2f355b904f9eb0388b5b7fe193c9546d45849 + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:02b40d33e3f685aeae677ac344eeaf77 +Ctrl.hexsalt = hexsalt:0ad52c9357c85e4781296a36ca72039c +Ctrl.hexinfo = hexinfo:c67c389580128f18f6cf8592 +Output = be32e7d306d891028be088f213f9f947c50420d9b5a12ca69818dd9995dedd8e6137c7104d67f2ca90915dda0ab68af2f355b904f9eb0388b5b7fe193c9546d45849133d + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:f4e1 +Ctrl.hexsalt = hexsalt:3638271ccd68a25dc24ecddd39ef3f89 +Ctrl.hexinfo = hexinfo:348a37a27ef1282f5f020dcc +Output = 3f661ec46fcc1e110b88f33ee7dbc308 + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:253554e5 +Ctrl.hexsalt = hexsalt:3638271ccd68a25dc24ecddd39ef3f89 +Ctrl.hexinfo = hexinfo:348a37a27ef1282f5f020dcc +Output = 73ccb357554ca44967d507518262e38d + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:e10d0e0bc95b +Ctrl.hexsalt = hexsalt:3638271ccd68a25dc24ecddd39ef3f89 +Ctrl.hexinfo = hexinfo:348a37a27ef1282f5f020dcc +Output = c4f1cf190980b6777bb35107654b25f9 + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:451f7f2c23c51326 +Ctrl.hexsalt = hexsalt:3638271ccd68a25dc24ecddd39ef3f89 +Ctrl.hexinfo = hexinfo:348a37a27ef1282f5f020dcc +Output = ddb2d7475d00cc65bff6904b4f0b54ba + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:0f27277ee800d6cc5425 +Ctrl.hexsalt = hexsalt:3638271ccd68a25dc24ecddd39ef3f89 +Ctrl.hexinfo = hexinfo:348a37a27ef1282f5f020dcc +Output = 1100a6049ae9d8be01ab3829754cecc2 + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:20438ff1f26390dbc3a1a6d0 +Ctrl.hexsalt = hexsalt:3638271ccd68a25dc24ecddd39ef3f89 +Ctrl.hexinfo = hexinfo:348a37a27ef1282f5f020dcc +Output = 5180382f740444ada597197f98e73e1e + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:b74a149a161546f8c20b06ac4ed4 +Ctrl.hexsalt = hexsalt:3638271ccd68a25dc24ecddd39ef3f89 +Ctrl.hexinfo = hexinfo:348a37a27ef1282f5f020dcc +Output = 44f676e85c1b1a8bbc3d319218631ca3 + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:8aa7df46b8cb3fe47228494f4e116b2c +Ctrl.hexsalt = hexsalt:3638271ccd68a25dc24ecddd39ef3f89 +Ctrl.hexinfo = hexinfo:348a37a27ef1282f5f020dcc +Output = ebb24413855a0a3249960d0de0f4750d + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:a678236b6ac82077b23f73a510c1d0e2 +Ctrl.hexsalt = hexsalt:46ee4f36a4167a09cde5a33b130c6e1c +Ctrl.hexinfo = hexinfo:d851 +Output = 5dbe10ead8f81a81a29072eca4501658 + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:a678236b6ac82077b23f73a510c1d0e2 +Ctrl.hexsalt = hexsalt:46ee4f36a4167a09cde5a33b130c6e1c +Ctrl.hexinfo = hexinfo:b04da03c +Output = 0a08d7616dcbec25a36f1936b82992ca + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:a678236b6ac82077b23f73a510c1d0e2 +Ctrl.hexsalt = hexsalt:46ee4f36a4167a09cde5a33b130c6e1c +Ctrl.hexinfo = hexinfo:f9e8b47eade3 +Output = 84a29697445179b662d85dbc59bf8042 + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:a678236b6ac82077b23f73a510c1d0e2 +Ctrl.hexsalt = hexsalt:46ee4f36a4167a09cde5a33b130c6e1c +Ctrl.hexinfo = hexinfo:5b141bfa54fcf824 +Output = be7660c840644cec84d67d95ba7ebf2d + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:a678236b6ac82077b23f73a510c1d0e2 +Ctrl.hexsalt = hexsalt:46ee4f36a4167a09cde5a33b130c6e1c +Ctrl.hexinfo = hexinfo:736e7ddb856f0ba14744 +Output = e3010b1fbcb02fd8baa8449ac71d0c62 + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:a678236b6ac82077b23f73a510c1d0e2 +Ctrl.hexsalt = hexsalt:46ee4f36a4167a09cde5a33b130c6e1c +Ctrl.hexinfo = hexinfo:c54320ff6e7d1a3b0b3aea00 +Output = df0ac84982999cda676e4cbf707c42f0 + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:a678236b6ac82077b23f73a510c1d0e2 +Ctrl.hexsalt = hexsalt:46ee4f36a4167a09cde5a33b130c6e1c +Ctrl.hexinfo = hexinfo:37ab143e1b4ab61d0294ea8afbc7 +Output = 93eec7f4dda18b7e710dbbd7570ebd13 + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:a678236b6ac82077b23f73a510c1d0e2 +Ctrl.hexsalt = hexsalt:46ee4f36a4167a09cde5a33b130c6e1c +Ctrl.hexinfo = hexinfo:c3146575d2c60981511e700902fc2ac1 +Output = e9125f77d699faa53d5bc48f3fc2f7d0 + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:0031558fddb96e3db2e0496026302055 +Ctrl.hexsalt = hexsalt:1ae1 +Ctrl.hexinfo = hexinfo:97ed3540c7466ab27395fe79 +Output = ddf7eedcd997eca3943d4519aaf414f4 + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:0031558fddb96e3db2e0496026302055 +Ctrl.hexsalt = hexsalt:3bda13b6 +Ctrl.hexinfo = hexinfo:97ed3540c7466ab27395fe79 +Output = ec783ca20501df3cacac5ab4adbc6427 + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:0031558fddb96e3db2e0496026302055 +Ctrl.hexsalt = hexsalt:c792f52e5876 +Ctrl.hexinfo = hexinfo:97ed3540c7466ab27395fe79 +Output = 9303a2562e6f8c418e3fcc081b94bdcf + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:0031558fddb96e3db2e0496026302055 +Ctrl.hexsalt = hexsalt:a9b7a64840d52633 +Ctrl.hexinfo = hexinfo:97ed3540c7466ab27395fe79 +Output = aab6b0dc19bae0dd7fa02391ac3d6ef1 + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:0031558fddb96e3db2e0496026302055 +Ctrl.hexsalt = hexsalt:8f62a3ec15cdf9b3522f +Ctrl.hexinfo = hexinfo:97ed3540c7466ab27395fe79 +Output = 1516d5ed7f46474d250408b0864647cf + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:0031558fddb96e3db2e0496026302055 +Ctrl.hexsalt = hexsalt:55ed67cbdc98ed8e45214704 +Ctrl.hexinfo = hexinfo:97ed3540c7466ab27395fe79 +Output = 38bf96a3d737a84dc10a835d340b6866 + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:0031558fddb96e3db2e0496026302055 +Ctrl.hexsalt = hexsalt:e4946aff3b2ab891b311234c77bc +Ctrl.hexinfo = hexinfo:97ed3540c7466ab27395fe79 +Output = 3ddd870471ff028a63c5f1bacc7e5b5c + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:0031558fddb96e3db2e0496026302055 +Ctrl.hexsalt = hexsalt:91e8378de5348cea41f84c41e8546e34 +Ctrl.hexinfo = hexinfo:97ed3540c7466ab27395fe79 +Output = bf1eb0eab488b2393ad6a1c2eb804381 + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:4ce16564db9615f75d46c6a9837af7ca +Ctrl.hexsalt = hexsalt:6199187690823def2037e0632577c6b1 +Output = 0a102289b16cbf4b + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:2578fe1116e27e3a5e8e935e892e12eb +Ctrl.hexsalt = hexsalt:6199187690823def2037e0632577c6b1 +Output = dd5773998893ad5a93f9819c8e798aab + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:e9dd8bd75f29661e61703346bbf2df47 +Ctrl.hexsalt = hexsalt:6199187690823def2037e0632577c6b1 +Output = 32136643daa64aaac0e2886364f157ba923d7b36ada761eb + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:e4640d3752cf48186a8ad2d7d4a81210 +Ctrl.hexsalt = hexsalt:6199187690823def2037e0632577c6b1 +Output = 6379d59efbe02576663af5efaccb9d063f596a22c8e1fed12cde7cdd7f327e88 + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:3bd9a074a219d62273c3f639659a3ecd +Ctrl.hexsalt = hexsalt:6199187690823def2037e0632577c6b1 +Output = cc45eb2ab80272c1e082b4f167ee4e086f12af3fbd0c812dda5568fea702928999cde3899cffc8a8 + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:2147c0fb1c7587b22fa44ce3bf3d8f5b +Ctrl.hexsalt = hexsalt:6199187690823def2037e0632577c6b1 +Output = 4e3a8827fcdb214686b35bfcc497ca69dccb78d3464aa4af0704ec0fba03c7bb10b9a4e31e27b1b2379a32e46935309c + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:2c2438b6321fed7a9eac200b91b3ac30 +Ctrl.hexsalt = hexsalt:6199187690823def2037e0632577c6b1 +Output = b402fda16e1c2719263be82158972c9080a7bafcbe0a3a6ede3504a3d5c8c0c0e00fe7e5f6bb3afdfa4d661b8fbe4bd7b950cfe0b2443bbd + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:0ffa4c40a822f6e3d86053aefe738eac +Ctrl.hexsalt = hexsalt:6199187690823def2037e0632577c6b1 +Output = 0486d589aa71a603c09120fb76eeab3293eee2dc36a91b23eb954d6703ade8a7b660d920c5a6f7bf3898d0e81fbad3a680b74b33680e0cc6a16aa616d078b256 + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:a801d997ed539ae9aa05d17871eb7fab +Ctrl.hexinfo = hexinfo:03697296e42a6fdbdb24b3ec +Output = 1a5efa3aca87c1f4 + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:e9624e112f9e90e7bf8a749cf37d920c +Ctrl.hexinfo = hexinfo:03697296e42a6fdbdb24b3ec +Output = ee93ca3986cc43516ae4e29fd7a90ef1 + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:a92acdee54a84a4564d4782d47801ec0 +Ctrl.hexinfo = hexinfo:03697296e42a6fdbdb24b3ec +Output = 3116b87eaffaa0cc48a72e6c1574df335d706f7c860b44e9 + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:e60d902e63b1a2bf5dab733cadb47b10 +Ctrl.hexinfo = hexinfo:03697296e42a6fdbdb24b3ec +Output = 3fde6c078dd6dc65aacf62beafa39398d2b3d7cfb4b0ee4807bfc98a15330eef + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:d3b747a1d1584a0fc5aefcd4dd8ef9c3 +Ctrl.hexinfo = hexinfo:03697296e42a6fdbdb24b3ec +Output = 2c4363597d42f9f8736e8050b4a6dd033d7ddac6f7211c4810ef74aff01f101d885767d7ae6f1d7f + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:119559a2c0a8888e9c95b9989a460d97 +Ctrl.hexinfo = hexinfo:03697296e42a6fdbdb24b3ec +Output = 97922585f69adf484930cf22b8378c797694438502fa47e2f19f0fee97ca11451f3bc81a20c1d74964c63ab2d5df1985 + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:807f375266988df5d0ae878efac424fa +Ctrl.hexinfo = hexinfo:03697296e42a6fdbdb24b3ec +Output = ba78ef8ab720fc583bb64581917634fca230876cc344e46b44fe61f3bdab556ee753743b78db4b16c0fcd8f987aebad15d0b7b13a10f6819 + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA256 +Ctrl.hexsecret = hexsecret:f7906f870b256753b5bc3ef408e47e9b +Ctrl.hexinfo = hexinfo:03697296e42a6fdbdb24b3ec +Output = 96bee2ae234f98c285aa970bd54c2e2891febf734bad58a91dc7a97490b6b05fe539f2156ae3acd2e661eced0d59084fda340cd1ba3daa7ca2a550d7b1c19462 + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA512 +Ctrl.hexsecret = hexsecret:73b6e2ede34aae5680e2289e611ffc3a +Ctrl.hexsalt = hexsalt:28df8439747d5a9b502e0838ca6999b2 +Ctrl.hexinfo = hexinfo:232941631fc04dd82f727a51 +Output = b0d36cd7d6b23b48ca6f89901bb784ec + +KDF = SSKDF +Ctrl.mac = mac:HMAC +Ctrl.digest = digest:SHA512 +Ctrl.hexsecret = hexsecret:abb7d7554c0de41cada5826a1f79d76f +Ctrl.hexinfo = hexinfo:a80b9061879365b1669c87a8 +Output = 71e29fff69198eca92f5180bcb281fbdaf409ec7c99ca704b1f56e782d3c4db10cb4158e6634d793a46c13bffb6bdb71a01101936ea9b20f7dbe302558b1356c diff --git a/test/recipes/30-test_evp_data/evpmac.txt b/test/recipes/30-test_evp_data/evpmac.txt index 732c8c4d..ada1ae67 100644 --- a/test/recipes/30-test_evp_data/evpmac.txt +++ b/test/recipes/30-test_evp_data/evpmac.txt @@ -589,6 +589,14 @@ Input = "Sample message for keylen>blocklen" Key = 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f8081828384858687 Output = 5f464f5e5b7848e3885e49b2c385f0694985d0e38966242dc4a5fe3fea4b37d46b65ceced5dcf59438dd840bab22269f0ba7febdb9fcf74602a35666b2a32915 +Title = HMAC self generated tests + +MAC = HMAC +Algorithm = SHAKE128 +Input = "Test that SHAKE128 fails" +Key = 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f +Result = MAC_CTRL_ERROR + Title = CMAC tests (from FIPS module) diff --git a/test/rsa_sp800_56b_test.c b/test/rsa_sp800_56b_test.c index a64f9f2c..89dab09c 100644 --- a/test/rsa_sp800_56b_test.c +++ b/test/rsa_sp800_56b_test.c @@ -290,19 +290,31 @@ static int test_check_private_exponent(void) && TEST_ptr(ctx = BN_CTX_new()) && TEST_ptr(p = BN_new()) && TEST_ptr(q = BN_new()) - && TEST_ptr(e = BN_new()) - && TEST_ptr(d = BN_new()) - && TEST_ptr(n = BN_new()) /* lcm(15-1,17-1) = 14*16 / 2 = 112 */ && TEST_true(BN_set_word(p, 15)) && TEST_true(BN_set_word(q, 17)) + && TEST_true(RSA_set0_factors(key, p, q)); + if (!ret) { + BN_free(p); + BN_free(q); + goto end; + } + + ret = TEST_ptr(e = BN_new()) + && TEST_ptr(d = BN_new()) + && TEST_ptr(n = BN_new()) && TEST_true(BN_set_word(e, 5)) && TEST_true(BN_set_word(d, 157)) && TEST_true(BN_set_word(n, 15*17)) - && TEST_true(RSA_set0_factors(key, p, q)) - && TEST_true(RSA_set0_key(key, n, e, d)) - /* fails since d >= lcm(p-1, q-1) */ - && TEST_false(rsa_check_private_exponent(key, 8, ctx)) + && TEST_true(RSA_set0_key(key, n, e, d)); + if (!ret) { + BN_free(e); + BN_free(d); + BN_free(n); + goto end; + } + /* fails since d >= lcm(p-1, q-1) */ + ret = TEST_false(rsa_check_private_exponent(key, 8, ctx)) && TEST_true(BN_set_word(d, 45)) /* d is correct size and 1 = e.d mod lcm(p-1, q-1) */ && TEST_true(rsa_check_private_exponent(key, 8, ctx)) @@ -314,7 +326,7 @@ static int test_check_private_exponent(void) /* fail if 1 != e.d mod lcm(p-1, q-1) */ && TEST_true(BN_set_word(d, 46)) && TEST_false(rsa_check_private_exponent(key, 8, ctx)); - +end: RSA_free(key); BN_CTX_free(ctx); return ret; @@ -343,8 +355,13 @@ static int test_check_crt_components(void) && TEST_true(BN_set_word(p, P)) && TEST_true(BN_set_word(q, Q)) && TEST_true(BN_set_word(e, E)) - && TEST_true(RSA_set0_factors(key, p, q)) - && TEST_true(rsa_sp800_56b_derive_params_from_pq(key, 8, e, ctx)) + && TEST_true(RSA_set0_factors(key, p, q)); + if (!ret) { + BN_free(p); + BN_free(q); + goto end; + } + ret = TEST_true(rsa_sp800_56b_derive_params_from_pq(key, 8, e, ctx)) && TEST_BN_eq_word(key->n, N) && TEST_BN_eq_word(key->dmp1, DP) && TEST_BN_eq_word(key->dmq1, DQ) @@ -382,7 +399,7 @@ static int test_check_crt_components(void) && TEST_true(BN_set_word(key->iqmp, QINV)) /* check defaults are still valid */ && TEST_true(rsa_check_crt_components(key, ctx)); - +end: BN_free(e); RSA_free(key); BN_CTX_free(ctx); @@ -427,14 +444,25 @@ static int test_invalid_keypair(void) /* load key */ && TEST_ptr(p = bn_load_new(cav_p, sizeof(cav_p))) && TEST_ptr(q = bn_load_new(cav_q, sizeof(cav_q))) - && TEST_ptr(e = bn_load_new(cav_e, sizeof(cav_e))) + && TEST_true(RSA_set0_factors(key, p, q)); + if (!ret) { + BN_free(p); + BN_free(q); + goto end; + } + + ret = TEST_ptr(e = bn_load_new(cav_e, sizeof(cav_e))) && TEST_ptr(n = bn_load_new(cav_n, sizeof(cav_n))) && TEST_ptr(d = bn_load_new(cav_d, sizeof(cav_d))) - && TEST_true(RSA_set0_key(key, n, e, d)) - && TEST_true(RSA_set0_factors(key, p, q)) - + && TEST_true(RSA_set0_key(key, n, e, d)); + if (!ret) { + BN_free(e); + BN_free(n); + BN_free(d); + goto end; + } /* bad strength/key size */ - && TEST_false(rsa_sp800_56b_check_keypair(key, NULL, 100, 2048)) + ret = TEST_false(rsa_sp800_56b_check_keypair(key, NULL, 100, 2048)) && TEST_false(rsa_sp800_56b_check_keypair(key, NULL, 112, 1024)) && TEST_false(rsa_sp800_56b_check_keypair(key, NULL, 128, 2048)) && TEST_false(rsa_sp800_56b_check_keypair(key, NULL, 140, 3072)) @@ -466,7 +494,7 @@ static int test_invalid_keypair(void) && TEST_false(rsa_sp800_56b_check_keypair(key, NULL, -1, 2048)) && TEST_true(BN_add_word(q, 2)) && TEST_true(BN_mul(n, p, q, ctx)); - +end: RSA_free(key); BN_CTX_free(ctx); return ret; @@ -567,16 +595,22 @@ static int test_check_private_key(void) && TEST_ptr(n = bn_load_new(cav_n, sizeof(cav_n))) && TEST_ptr(d = bn_load_new(cav_d, sizeof(cav_d))) && TEST_ptr(e = bn_load_new(cav_e, sizeof(cav_e))) - && TEST_true(RSA_set0_key(key, n, e, d)) - /* check d is in range */ - && TEST_true(rsa_sp800_56b_check_private(key)) + && TEST_true(RSA_set0_key(key, n, e, d)); + if (!ret) { + BN_free(n); + BN_free(e); + BN_free(d); + goto end; + } + /* check d is in range */ + ret = TEST_true(rsa_sp800_56b_check_private(key)) /* check d is too low */ && TEST_true(BN_set_word(d, 0)) && TEST_false(rsa_sp800_56b_check_private(key)) /* check d is too high */ && TEST_ptr(BN_copy(d, n)) && TEST_false(rsa_sp800_56b_check_private(key)); - +end: RSA_free(key); return ret; } @@ -593,9 +627,14 @@ static int test_check_public_key(void) /* load public key */ && TEST_ptr(e = bn_load_new(cav_e, sizeof(cav_e))) && TEST_ptr(n = bn_load_new(cav_n, sizeof(cav_n))) - && TEST_true(RSA_set0_key(key, n, e, NULL)) - /* check public key is valid */ - && TEST_true(rsa_sp800_56b_check_public(key)) + && TEST_true(RSA_set0_key(key, n, e, NULL)); + if (!ret) { + BN_free(e); + BN_free(n); + goto end; + } + /* check public key is valid */ + ret = TEST_true(rsa_sp800_56b_check_public(key)) /* check fail if n is even */ && TEST_true(BN_add_word(n, 1)) && TEST_false(rsa_sp800_56b_check_public(key)) @@ -611,7 +650,7 @@ static int test_check_public_key(void) /* modulus fails composite check */ && TEST_true(BN_add_word(n, 2)) && TEST_false(rsa_sp800_56b_check_public(key)); - +end: RSA_free(key); return ret; } diff --git a/test/servername_test.c b/test/servername_test.c index f84c1870..86d261f3 100644 --- a/test/servername_test.c +++ b/test/servername_test.c @@ -35,10 +35,16 @@ static int get_sni_from_client_hello(BIO *bio, char **sni) { long len; unsigned char *data; - PACKET pkt = {0}, pkt2 = {0}, pkt3 = {0}, pkt4 = {0}, pkt5 = {0}; + PACKET pkt, pkt2, pkt3, pkt4, pkt5; unsigned int servname_type = 0, type = 0; int ret = 0; + memset(&pkt, 0, sizeof(pkt)); + memset(&pkt2, 0, sizeof(pkt2)); + memset(&pkt3, 0, sizeof(pkt3)); + memset(&pkt4, 0, sizeof(pkt4)); + memset(&pkt5, 0, sizeof(pkt5)); + len = BIO_get_mem_data(bio, (char **)&data); if (!TEST_true(PACKET_buf_init(&pkt, data, len)) /* Skip the record header */ diff --git a/test/sslapitest.c b/test/sslapitest.c index 2a4596dc..bccf055f 100644 --- a/test/sslapitest.c +++ b/test/sslapitest.c @@ -306,9 +306,10 @@ static int test_keylog(void) SSL_CTX *cctx = NULL, *sctx = NULL; SSL *clientssl = NULL, *serverssl = NULL; int testresult = 0; - struct sslapitest_log_counts expected = {0}; + struct sslapitest_log_counts expected; /* Clean up logging space */ + memset(&expected, 0, sizeof(expected)); memset(client_log_buffer, 0, sizeof(client_log_buffer)); memset(server_log_buffer, 0, sizeof(server_log_buffer)); client_log_buffer_index = 0; @@ -387,11 +388,12 @@ static int test_keylog_no_master_key(void) SSL *clientssl = NULL, *serverssl = NULL; SSL_SESSION *sess = NULL; int testresult = 0; - struct sslapitest_log_counts expected = {0}; + struct sslapitest_log_counts expected; unsigned char buf[1]; size_t readbytes, written; /* Clean up logging space */ + memset(&expected, 0, sizeof(expected)); memset(client_log_buffer, 0, sizeof(client_log_buffer)); memset(server_log_buffer, 0, sizeof(server_log_buffer)); client_log_buffer_index = 0; @@ -4593,12 +4595,16 @@ static int get_MFL_from_client_hello(BIO *bio, int *mfl_codemfl_code) { long len; unsigned char *data; - PACKET pkt = {0}, pkt2 = {0}, pkt3 = {0}; + PACKET pkt, pkt2, pkt3; unsigned int MFL_code = 0, type = 0; if (!TEST_uint_gt( len = BIO_get_mem_data( bio, (char **) &data ), 0 ) ) goto end; + memset(&pkt, 0, sizeof(pkt)); + memset(&pkt2, 0, sizeof(pkt2)); + memset(&pkt3, 0, sizeof(pkt3)); + if (!TEST_true( PACKET_buf_init( &pkt, data, len ) ) /* Skip the record header */ || !PACKET_forward(&pkt, SSL3_RT_HEADER_LENGTH) diff --git a/util/libcrypto.num b/util/libcrypto.num index 12ebd5ab..8b153624 100644 --- a/util/libcrypto.num +++ b/util/libcrypto.num @@ -4790,4 +4790,7 @@ OSSL_PARAM_get_octet_ptr 4737 3_0_0 EXIST::FUNCTION: OSSL_PARAM_set_octet_ptr 4738 3_0_0 EXIST::FUNCTION: X509_set_sm2_id 4739 3_0_0 EXIST::FUNCTION:SM2 X509_get0_sm2_id 4740 3_0_0 EXIST::FUNCTION:SM2 -EVP_chacha20_poly1305_draft 4741 3_0_0 EXIST::FUNCTION:CHACHA,POLY1305 +EVP_PKEY_get0_engine 4741 3_0_0 EXIST::FUNCTION:ENGINE +EVP_MD_upref 4742 3_0_0 EXIST::FUNCTION: +EVP_MD_fetch 4743 3_0_0 EXIST::FUNCTION: +EVP_chacha20_poly1305_draft 4744 3_0_0 EXIST::FUNCTION:CHACHA,POLY1305