diff --git a/CHANGES b/CHANGES index 311d6c62..9d712f0d 100644 --- a/CHANGES +++ b/CHANGES @@ -9,6 +9,20 @@ Changes between 1.1.1 and 3.0.0 [xx XXX xxxx] + *) Add keyed BLAKE2 to EVP_MAC. + [Antoine Salon] + + *) Fix a bug in the computation of the endpoint-pair shared secret used + by DTLS over SCTP. This breaks interoperability with older versions + of OpenSSL like OpenSSL 1.1.0 and OpenSSL 1.0.2. There is a runtime + switch SSL_MODE_DTLS_SCTP_LABEL_LENGTH_BUG (off by default) enabling + interoperability with such broken implementations. However, enabling + this switch breaks interoperability with correct implementations. + + *) Fix a use after free bug in d2i_X509_PUBKEY when overwriting a + re-used X509_PUBKEY object if the second PUBKEY is malformed. + [Bernd Edlinger] + *) Move strictness check from EVP_PKEY_asn1_new() to EVP_PKEY_asn1_add0(). [Richard Levitte] @@ -63,7 +77,7 @@ implementations. This includes a generic EVP_PKEY to EVP_MAC bridge, to facilitate the continued use of MACs through raw private keys in functionality such as EVP_DigestSign* and EVP_DigestVerify*. - [Richard Levitte] + [Richard Levitte] *) Deprecate ECDH_KDF_X9_62() and mark its replacement as internal. Users should use the EVP interface instead (EVP_PKEY_CTX_set_ecdh_kdf_type). diff --git a/CONTRIBUTING b/CONTRIBUTING index 639c3cf0..250bbdbf 100644 --- a/CONTRIBUTING +++ b/CONTRIBUTING @@ -57,7 +57,7 @@ guidelines: 7. For user visible changes (API changes, behaviour changes, ...), consider adding a note in CHANGES. This could be a summarising description of the change, and could explain the grander details. - Have a look through existing entries for inspiration. + Have a look through existing entries for inspiration. Please note that this is NOT simply a copy of git-log oneliners. Also note that security fixes get an entry in CHANGES. This file helps users get more in depth information of what comes diff --git a/Configurations/00-base-templates.conf b/Configurations/00-base-templates.conf index eb9feae9..c92d640c 100644 --- a/Configurations/00-base-templates.conf +++ b/Configurations/00-base-templates.conf @@ -305,7 +305,7 @@ my %targets=( sha1_asm_src => "sha1-armv4-large.S sha256-armv4.S sha512-armv4.S", modes_asm_src => "ghash-armv4.S ghashv8-armx.S", chacha_asm_src => "chacha-armv4.S", - poly1305_asm_src=> "poly1305-armv4.S", + poly1305_asm_src=> "poly1305-armv4.S", keccak1600_asm_src => "keccak1600-armv4.S", perlasm_scheme => "void" }, diff --git a/Configurations/10-main.conf b/Configurations/10-main.conf index 054e38c0..859e3d9d 100644 --- a/Configurations/10-main.conf +++ b/Configurations/10-main.conf @@ -1724,6 +1724,8 @@ my %targets = ( asflags => sub { vms_info()->{asflags} }, perlasm_scheme => sub { vms_info()->{perlasm_scheme} }, + disable => add('pinshared'), + apps_aux_src => "vms_term_sock.c", apps_init_src => "vms_decc_init.c", }, diff --git a/Configurations/15-android.conf b/Configurations/15-android.conf index c94da412..7b496a45 100644 --- a/Configurations/15-android.conf +++ b/Configurations/15-android.conf @@ -24,7 +24,8 @@ my $ndk_var; my $ndk; - foreach $ndk_var (qw(ANDROID_NDK_HOME ANDROID_NDK)) { + foreach (qw(ANDROID_NDK_HOME ANDROID_NDK)) { + $ndk_var = $_; $ndk = $ENV{$ndk_var}; last if defined $ndk; } diff --git a/Configurations/50-win-onecore.conf b/Configurations/50-win-onecore.conf index c71d3646..51cb3819 100644 --- a/Configurations/50-win-onecore.conf +++ b/Configurations/50-win-onecore.conf @@ -4,7 +4,7 @@ # Mobile[?] Windows editions. It's a set up "umbrella" libraries that # export subset of Win32 API that are common to all Windows 10 devices. # -# OneCore Configuration temporarly dedicated for console applications +# OneCore Configuration temporarly dedicated for console applications # due to disabled event logging, which is incompatible with one core. # Error messages are provided via standard error only. # TODO: extend error handling to use ETW based eventing diff --git a/Configurations/README b/Configurations/README index c1f80fe4..a106f8c8 100644 --- a/Configurations/README +++ b/Configurations/README @@ -118,7 +118,7 @@ In each table entry, the following keys are significant: ''. This is very rarely needed. shared_extension => File name extension used for shared - libraries. + libraries. obj_extension => File name extension used for object files. On unix, this defaults to ".o" (NOTE: this is here for future use, it's not @@ -413,7 +413,6 @@ variables: LIBS=libsomething ENGINES=libeng SCRIPTS=myhack - EXTRA=file1 file2 Note that the files mentioned for PROGRAMS, LIBS and ENGINES *must* be without extensions. The build file templates will figure them out. @@ -486,48 +485,6 @@ be used in that case: NOTE: GENERATE lines are limited to one command only per GENERATE. -As a last resort, it's possible to have raw build file lines, between -BEGINRAW and ENDRAW lines as follows: - - BEGINRAW[Makefile(unix)] - haha.h: {- $builddir -}/Makefile - echo "/* haha */" > haha.h - ENDRAW[Makefile(unix)] - -The word within square brackets is the build_file configuration item -or the build_file configuration item followed by the second word in the -build_scheme configuration item for the configured target within -parenthesis as shown above. For example, with the following relevant -configuration items: - - build_file => "build.ninja" - build_scheme => [ "unified", "unix" ] - -... these lines will be considered: - - BEGINRAW[build.ninja] - build haha.h: echo "/* haha */" > haha.h - ENDRAW[build.ninja] - - BEGINRAW[build.ninja(unix)] - build hoho.h: echo "/* hoho */" > hoho.h - ENDRAW[build.ninja(unix)] - -Should it be needed because the recipes within a RAW section might -clash with those generated by Configure, it's possible to tell it -not to generate them with the use of OVERRIDES, for example: - - SOURCE[libfoo]=foo.c bar.c - - OVERRIDES=bar.o - BEGINRAW[Makefile(unix)] - bar.o: bar.c - $(CC) $(CFLAGS) -DSPECIAL -c -o $@ $< - ENDRAW[Makefile(unix)] - -See the documentation further up for more information on configuration -items. - Finally, you can have some simple conditional use of the build.info information, looking like this: diff --git a/Configurations/README.design b/Configurations/README.design index c0b05bd5..75c19a68 100644 --- a/Configurations/README.design +++ b/Configurations/README.design @@ -87,7 +87,7 @@ depends on the library 'libssl' to function properly. LIBS=../libcrypto SOURCE[../libcrypto]=aes.c evp.c cversion.c DEPEND[cversion.o]=buildinf.h - + GENERATE[buildinf.h]=../util/mkbuildinf.pl "$(CC) $(CFLAGS)" "$(PLATFORM)" DEPEND[buildinf.h]=../Makefile DEPEND[../util/mkbuildinf.pl]=../util/Foo.pm @@ -102,7 +102,7 @@ show that duplicate information isn't an issue. This build.info file informs us that 'libcrypto' is built from a few source files, 'crypto/aes.c', 'crypto/evp.c' and 'crypto/cversion.c'. It also shows us that building the object file inferred from -'crypto/cversion.c' depends on 'crypto/buildinf.h'. Finally, it +'crypto/cversion.c' depends on 'crypto/buildinf.h'. Finally, it also shows the possibility to declare how some files are generated using some script, in this case a perl script, and how such scripts can be declared to depend on other files, in this case a perl module. @@ -112,9 +112,6 @@ Two things are worth an extra note: 'DEPEND[cversion.o]' mentions an object file. DEPEND indexes is the only location where it's valid to mention them -Lines in 'BEGINRAW'..'ENDRAW' sections must always mention files as -seen from the top directory, no exception. - # ssl/build.info LIBS=../libssl SOURCE[../libssl]=tls.c @@ -153,7 +150,7 @@ information comes down to this: SOURCE[libssl]=ssl/tls.c INCLUDE[libssl]=include DEPEND[libssl]=libcrypto - + PROGRAMS=apps/openssl SOURCE[apps/openssl]=apps/openssl.c INCLUDE[apps/openssl]=. include @@ -168,7 +165,7 @@ information comes down to this: SOURCE[engines/ossltest]=engines/e_ossltest.c DEPEND[engines/ossltest]=libcrypto.a INCLUDE[engines/ossltest]=include - + GENERATE[crypto/buildinf.h]=util/mkbuildinf.pl "$(CC) $(CFLAGS)" "$(PLATFORM)" DEPEND[crypto/buildinf.h]=Makefile DEPEND[util/mkbuildinf.pl]=util/Foo.pm @@ -234,11 +231,6 @@ indexes: programs => a list of programs. These are directly inferred from the PROGRAMS variable in build.info files. - rawlines => a list of build-file lines. These are a direct copy of - the BEGINRAW..ENDRAW lines in build.info files. Note: - only the BEGINRAW..ENDRAW section for the current - platform are copied, the rest are ignored. - scripts => a list of scripts. There are directly inferred from the SCRIPTS variable in build.info files. @@ -352,9 +344,6 @@ section above would be digested into a %unified_info table: [ "apps/openssl", ], - "rawlines" => - [ - ], "sources" => { "apps/openssl" => diff --git a/Configurations/common.tmpl b/Configurations/common.tmpl index 53384c73..a15971ef 100644 --- a/Configurations/common.tmpl +++ b/Configurations/common.tmpl @@ -217,8 +217,4 @@ foreach (@{$unified_info{scripts}}) { doscript($_); } foreach (sort keys %{$unified_info{dirinfo}}) { dodir($_); } - - # Finally, should there be any applicable BEGINRAW/ENDRAW sections, - # they are added here. - $OUT .= $_."\n" foreach @{$unified_info{rawlines}}; -} diff --git a/Configurations/descrip.mms.tmpl b/Configurations/descrip.mms.tmpl index acb59971..ae365c6f 100644 --- a/Configurations/descrip.mms.tmpl +++ b/Configurations/descrip.mms.tmpl @@ -102,9 +102,6 @@ return "$target : build_generated\n\t\pipe \$(MMS) \$(MMSQUALIFIERS) depend && \$(MMS) \$(MMSQUALIFIERS) _$target\n_$target"; } - #use Data::Dumper; - #print STDERR "DEBUG: before:\n", Dumper($unified_info{before}); - #print STDERR "DEBUG: after:\n", Dumper($unified_info{after}); ""; -} PLATFORM={- $config{target} -} @@ -698,7 +695,10 @@ reconfigure reconf : # Depending on shared libraries: # On Windows POSIX layers, we depend on {libname}.dll.a # On Unix platforms, we depend on {shlibname}.so - return map { platform->sharedlib($_) // platform->staticlib($_) } @_; + return map { + { lib => platform->sharedlib($_) // platform->staticlib($_), + attrs => $unified_info{attributes}->{$_} } + } @_; } # Helper function to deal with inclusion directory specs. @@ -968,7 +968,7 @@ EOF @{$args{objs}}; my @deps = compute_lib_depends(@{$args{deps}}); die "More than one symbol vector" if scalar @defs > 1; - my $deps = join(", -\n\t\t", @objs, @defs, @deps); + my $deps = join(", -\n\t\t", @objs, @defs, map { $_->{lib} } @deps); my $shlib_target = $disabled{shared} ? "" : $target{shared_target}; my $translatesyms_pl = abs2rel(rel2abs(catfile($config{sourcedir}, "VMS", "translatesyms.pl")), @@ -982,7 +982,8 @@ EOF "WRITE OPT_FILE \"$x" } @objs). "\""; my $write_opt2 = - join("\n\t", map { my $x = $_ =~ /\[/ ? $_ : "[]".$_; + join("\n\t", map { my $x = $_->{lib} =~ /\[/ + ? $_->{lib} : "[]".$_->{lib}; $x =~ s|(\.EXE)|$1/SHARE|; $x =~ s|(\.OLB)|$1/LIB|; "WRITE OPT_FILE \"$x\"" } @deps) @@ -1015,7 +1016,7 @@ EOF grep { platform->isdef($_) } @{$args{objs}}; my @deps = compute_lib_depends(@{$args{deps}}); - my $deps = join(", -\n\t\t", @objs, @defs, @deps); + my $deps = join(", -\n\t\t", @objs, @defs, map { $_->{lib} } @deps); die "More than one symbol vector" if scalar @defs > 1; my $shlib_target = $disabled{shared} ? "" : $target{shared_target}; # The "[]" hack is because in .OPT files, each line inherits the @@ -1027,7 +1028,8 @@ EOF "WRITE OPT_FILE \"$x" } @objs). "\""; my $write_opt2 = - join("\n\t", map { my $x = $_ =~ /\[/ ? $_ : "[]".$_; + join("\n\t", map { my $x = $_->{lib} =~ /\[/ + ? $_->{lib} : "[]".$_->{lib}; $x =~ s|(\.EXE)|$1/SHARE|; $x =~ s|(\.OLB)|$1/LIB|; "WRITE OPT_FILE \"$x\"" } @deps) @@ -1071,9 +1073,9 @@ EOF @{$args{objs}}; my $objs = join(",", @objs); my @deps = compute_lib_depends(@{$args{deps}}); - my $deps = join(", -\n\t\t", @objs, @deps); + my $deps = join(", -\n\t\t", @objs, map { $_->{lib} } @deps); - my $olb_count = scalar grep(m|\.OLB$|, @deps); + my $olb_count = scalar grep(m|\.OLB$|, map { $_->{lib} } @deps); my $analyse_objs = "@ !"; if ($olb_count > 0) { my $analyse_quals = @@ -1089,16 +1091,22 @@ EOF "\@ WRITE OPT_FILE \"$x" } @objs). "\""; my $write_opt2 = - join("\n\t", map { my @lines = ( - "\ WRITE OPT_FILE \"CASE_SENSITIVE=YES\"" - ); - my $x = $_ =~ /\[/ ? $_ : "[]".$_; + join("\n\t", "WRITE OPT_FILE \"CASE_SENSITIVE=YES\"", + map { my @lines = (); + use Data::Dumper; + my $x = $_->{lib} =~ /\[/ + ? $_->{lib} : "[]".$_->{lib}; if ($x =~ m|\.EXE$|) { push @lines, "\@ WRITE OPT_FILE \"$x/SHARE\""; } elsif ($x =~ m|\.OLB$|) { - (my $l = $x) =~ s/\W/_/g; - push @lines, - "\@ IF nomain THEN WRITE OPT_FILE \"$x/LIB\$(INCLUDE_MAIN_$l)\"", + # Special hack to include the MAIN object + # module explicitly. This will only be done + # if there isn't a 'main' in the program's + # object modules already. + my $main = $_->{attrs}->{has_main} + ? '/INCLUDE=main' : ''; + push @lines, + "\@ IF nomain THEN WRITE OPT_FILE \"$x/LIB$main\"", "\@ IF .NOT. nomain THEN WRITE OPT_FILE \"$x/LIB\"" } @lines diff --git a/Configurations/unix-Makefile.tmpl b/Configurations/unix-Makefile.tmpl index 90f469f3..36286f68 100644 --- a/Configurations/unix-Makefile.tmpl +++ b/Configurations/unix-Makefile.tmpl @@ -800,7 +800,7 @@ errors: include/internal/o_str.h include/internal/err.h include/internal/sslconf.h ); - our @cryptoskipheaders = ( @sslheaders, + our @cryptoskipheaders = ( @sslheaders, qw( include/openssl/conf_api.h include/openssl/ebcdic.h include/openssl/opensslconf.h diff --git a/Configure b/Configure index 53460fe8..8a178dfb 100755 --- a/Configure +++ b/Configure @@ -1713,10 +1713,6 @@ if ($builder eq "unified") { my @libraries = (); my @engines = (); my @scripts = (); - my @extra = (); - my @overrides = (); - my @intermediates = (); - my @rawlines = (); my %attributes = (); my %sources = (); @@ -1806,7 +1802,6 @@ if ($builder eq "unified") { $attributes{$p}->{$ak} = $av; } } - push @programs, @p; } }, qr/^\s*LIBS(?:{([\w=]+(?:\s*,\s*[\w=]+)*)})?\s*=\s*(.*)\s*$/ @@ -1826,7 +1821,6 @@ if ($builder eq "unified") { $attributes{$l}->{$ak} = $av; } } - push @libraries, @l; } }, qr/^\s*ENGINES(?:{([\w=]+(?:\s*,\s*[\w=]+)*)})?\s*=\s*(.*)\s*$/ @@ -1846,7 +1840,6 @@ if ($builder eq "unified") { $attributes{$e}->{$ak} = $av; } } - push @engines, @e; } }, qr/^\s*SCRIPTS(?:{([\w=]+(?:\s*,\s*[\w=]+)*)})?\s*=\s*(.*)\s*$/ @@ -1866,15 +1859,8 @@ if ($builder eq "unified") { $attributes{$s}->{$ak} = $av; } } - push @scripts, @s; } }, - qr/^\s*EXTRA\s*=\s*(.*)\s*$/ - => sub { push @extra, tokenize($1) - if !@skip || $skip[$#skip] > 0 }, - qr/^\s*OVERRIDES\s*=\s*(.*)\s*$/ - => sub { push @overrides, tokenize($1) - if !@skip || $skip[$#skip] > 0 }, qr/^\s*ORDINALS\[((?:\\.|[^\\\]])+)\]\s*=\s*(.*)\s*$/, => sub { push @{$ordinals{$1}}, tokenize($2) @@ -1897,27 +1883,6 @@ if ($builder eq "unified") { qr/^\s*GENERATE\[((?:\\.|[^\\\]])+)\]\s*=\s*(.*)\s*$/ => sub { push @{$generate{$1}}, $2 if !@skip || $skip[$#skip] > 0 }, - qr/^\s*RENAME\[((?:\\.|[^\\\]])+)\]\s*=\s*(.*)\s*$/ - => sub { warn "RENAME is no longer supported\n" }, - qr/^\s*SHARED_NAME\[((?:\\.|[^\\\]])+)\]\s*=\s*(.*)\s*$/ - => sub { warn "SHARED_NAME is no longer supported\n" }, - qr/^\s*BEGINRAW\[((?:\\.|[^\\\]])+)\]\s*$/ - => sub { - my $lineiterator = shift; - my $target_kind = $1; - while (defined $lineiterator->()) { - s|\R$||; - if (/^\s*ENDRAW\[((?:\\.|[^\\\]])+)\]\s*$/) { - die "ENDRAW doesn't match BEGINRAW" - if $1 ne $target_kind; - last; - } - next if @skip && $skip[$#skip] <= 0; - push @rawlines, $_ - if ($target_kind eq $target{build_file} - || $target_kind eq $target{build_file}."(".$builder_platform.")"); - } - }, qr/^\s*(?:#.*)?$/ => sub { }, "OTHERWISE" => sub { die "Something wrong with this line:\n$_\nat $sourced/$f" }, "BEFORE" => sub { @@ -1952,9 +1917,7 @@ EOF my %infos = ( programs => [ @programs ], libraries => [ @libraries ], engines => [ @engines ], - scripts => [ @scripts ], - extra => [ @extra ], - overrides => [ @overrides ] ); + scripts => [ @scripts ] ); foreach my $k (keys %infos) { foreach (@{$infos{$k}}) { my $item = cleanfile($buildd, $_, $blddir); @@ -1963,8 +1926,6 @@ EOF } } - push @{$unified_info{rawlines}}, @rawlines; - # Check that we haven't defined any library as both shared and # explicitly static. That is forbidden. my @doubles = (); @@ -2259,7 +2220,7 @@ EOF ### Make unified_info a bit more efficient # One level structures - foreach (("programs", "libraries", "engines", "scripts", "extra", "overrides")) { + foreach (("programs", "libraries", "engines", "scripts")) { $unified_info{$_} = [ sort keys %{$unified_info{$_}} ]; } # Two level structures diff --git a/INSTALL b/INSTALL index 2fd2235d..11956439 100644 --- a/INSTALL +++ b/INSTALL @@ -973,10 +973,10 @@ * COMPILING existing applications - OpenSSL 1.1.0 hides a number of structures that were previously - open. This includes all internal libssl structures and a number - of EVP types. Accessor functions have been added to allow - controlled access to the structures' data. + Starting with version 1.1.0, OpenSSL hides a number of structures + that were previously open. This includes all internal libssl + structures and a number of EVP types. Accessor functions have + been added to allow controlled access to the structures' data. This means that some software needs to be rewritten to adapt to the new ways of doing things. This often amounts to allocating @@ -1079,7 +1079,7 @@ depend Rebuild the dependencies in the Makefiles. This is a legacy - option that no longer needs to be used in OpenSSL 1.1.0. + option that no longer needs to be used since OpenSSL 1.1.0. install Install all OpenSSL components. diff --git a/NOTES.ANDROID b/NOTES.ANDROID index eeacdade..86459778 100644 --- a/NOTES.ANDROID +++ b/NOTES.ANDROID @@ -26,7 +26,7 @@ you need to set ANDROID_NDK_HOME environment to point at NDK directory as /some/where/android-ndk-. Both variables are significant at both configuration and compilation times. NDK customarily supports multiple - Android API levels, e.g. android-14, android-21, etc. By default latest + Android API levels, e.g. android-14, android-21, etc. By default latest one available is chosen. If you need to target older platform, pass additional -D__ANDROID_API__=N to Configure. N is numeric value of the target platform version. For example, to compile for ICS on ARM with diff --git a/NOTES.DJGPP b/NOTES.DJGPP index bbe63dc1..d43d4e86 100644 --- a/NOTES.DJGPP +++ b/NOTES.DJGPP @@ -1,5 +1,5 @@ - + INSTALLATION ON THE DOS PLATFORM WITH DJGPP ------------------------------------------- @@ -29,7 +29,7 @@ running "./Configure" with appropriate arguments: ./Configure no-threads --prefix=/dev/env/DJDIR DJGPP - + And finally fire up "make". You may run out of DPMI selectors when running in a DOS box under Windows. If so, just close the BASH shell, go back to Windows, and restart BASH. Then run "make" again. diff --git a/NOTES.VMS b/NOTES.VMS index 98def068..d6a336ff 100644 --- a/NOTES.VMS +++ b/NOTES.VMS @@ -42,7 +42,7 @@ for now is to rename the OpenSSL source directory, as follows (please adjust for the actual source directory name you have): - $ rename openssl-1^.1^.0.DIR openssl-1_1_0.DIR + $ rename openssl-1^.1^.0.DIR openssl-1_1_0.DIR About MMS and DCL diff --git a/apps/ct_log_list.cnf b/apps/ct_log_list.cnf index 650aa22d..e643cfdb 100644 --- a/apps/ct_log_list.cnf +++ b/apps/ct_log_list.cnf @@ -2,8 +2,8 @@ # that are to be trusted. # Google's list of logs can be found here: -# www.certificate-transparency.org/known-logs +# www.certificate-transparency.org/known-logs # A Python program to convert the log list to OpenSSL's format can be # found here: -# https://github.com/google/certificate-transparency/blob/master/python/utilities/log_list/print_log_list.py +# https://github.com/google/certificate-transparency/blob/master/python/utilities/log_list/print_log_list.py # Use the "--openssl_output" flag. diff --git a/apps/demoSRP/srp_verifier.txt b/apps/demoSRP/srp_verifier.txt index ccae6292..c2d5c603 100644 --- a/apps/demoSRP/srp_verifier.txt +++ b/apps/demoSRP/srp_verifier.txt @@ -3,4 +3,4 @@ # records starting with a I followed by the g and N values and the id. # The exact values ... you have to dig this out from the source of srp.c # or srp_vfy.c -# The last value of an I is used as the default group for new users. +# The last value of an I is used as the default group for new users. diff --git a/apps/dh1024.pem b/apps/dh1024.pem index f1a5e180..813e8a4a 100644 --- a/apps/dh1024.pem +++ b/apps/dh1024.pem @@ -4,7 +4,7 @@ Sgh5jjQE3e+VGbPNOkMbMCsKbfJfFDdP4TVtbVHCReSFtXZiXn7G9ExC6aY37WsL /1y29Aa37e44a/taiZ+lrp8kEXxLH+ZJKGZR7OZTgf//////////AgEC -----END DH PARAMETERS----- -These are the 1024-bit DH parameters from "Internet Key Exchange +These are the 1024-bit DH parameters from "Internet Key Exchange Protocol Version 2 (IKEv2)": https://tools.ietf.org/html/rfc5996 See https://tools.ietf.org/html/rfc2412 for how they were generated. diff --git a/apps/dh2048.pem b/apps/dh2048.pem index e899f2e0..288a2099 100644 --- a/apps/dh2048.pem +++ b/apps/dh2048.pem @@ -7,8 +7,8 @@ fDKQXkYuNs474553LBgOhgObJ4Oi7Aeij7XFXfBvTFLJ3ivL9pVYFxg5lUl86pVq 5RXSJhiY+gUQFXKOWoqsqmj//////////wIBAg== -----END DH PARAMETERS----- -These are the 2048-bit DH parameters from "More Modular Exponential -(MODP) Diffie-Hellman groups for Internet Key Exchange (IKE)": +These are the 2048-bit DH parameters from "More Modular Exponential +(MODP) Diffie-Hellman groups for Internet Key Exchange (IKE)": https://tools.ietf.org/html/rfc3526 See https://tools.ietf.org/html/rfc2412 for how they were generated. diff --git a/apps/dh4096.pem b/apps/dh4096.pem index adada2b5..08560e12 100644 --- a/apps/dh4096.pem +++ b/apps/dh4096.pem @@ -12,8 +12,8 @@ ARpyPBKnh+bXiHGaEL26WyaZwycYavTiPBqUaDS2FQvaJYPpyirUTOjbu8LbBN6O HNAGkSfVsFqpk7TqmI2P3cGG/7fckKbAj030Nck0BjGZ//////////8CAQI= -----END DH PARAMETERS----- -These are the 4096-bit DH parameters from "More Modular Exponential -(MODP) Diffie-Hellman groups for Internet Key Exchange (IKE)": +These are the 4096-bit DH parameters from "More Modular Exponential +(MODP) Diffie-Hellman groups for Internet Key Exchange (IKE)": https://tools.ietf.org/html/rfc3526 See https://tools.ietf.org/html/rfc2412 for how they were generated. diff --git a/apps/openssl-vms.cnf b/apps/openssl-vms.cnf index 178a0b0f..e64cc9f3 100644 --- a/apps/openssl-vms.cnf +++ b/apps/openssl-vms.cnf @@ -18,7 +18,7 @@ oid_section = new_oids # To use this configuration file with the "-extfile" option of the # "openssl x509" utility, name here the section containing the # X.509v3 extensions to use: -# extensions = +# extensions = # (Alternatively, use a configuration file that has only # X.509v3 extensions in its main [= default] section.) @@ -115,7 +115,7 @@ x509_extensions = v3_ca # The extensions to add to the self signed cert # input_password = secret # output_password = secret -# This sets a mask for permitted string types. There are several options. +# This sets a mask for permitted string types. There are several options. # default: PrintableString, T61String, BMPString. # pkix : PrintableString, BMPString (PKIX recommendation before 2004) # utf8only: only UTF8Strings (PKIX recommendation after 2004). diff --git a/apps/openssl.cnf b/apps/openssl.cnf index 6df2878d..4acca4b0 100644 --- a/apps/openssl.cnf +++ b/apps/openssl.cnf @@ -18,7 +18,7 @@ oid_section = new_oids # To use this configuration file with the "-extfile" option of the # "openssl x509" utility, name here the section containing the # X.509v3 extensions to use: -# extensions = +# extensions = # (Alternatively, use a configuration file that has only # X.509v3 extensions in its main [= default] section.) @@ -115,7 +115,7 @@ x509_extensions = v3_ca # The extensions to add to the self signed cert # input_password = secret # output_password = secret -# This sets a mask for permitted string types. There are several options. +# This sets a mask for permitted string types. There are several options. # default: PrintableString, T61String, BMPString. # pkix : PrintableString, BMPString (PKIX recommendation before 2004) # utf8only: only UTF8Strings (PKIX recommendation after 2004). diff --git a/apps/pkcs12.c b/apps/pkcs12.c index 94d6661c..bf22aeb4 100644 --- a/apps/pkcs12.c +++ b/apps/pkcs12.c @@ -311,6 +311,13 @@ int pkcs12_main(int argc, char **argv) if (cpass != NULL) { mpass = cpass; noprompt = 1; + if (twopass) { + if (export_cert) + BIO_printf(bio_err, "Option -twopass cannot be used with -passout or -password\n"); + else + BIO_printf(bio_err, "Option -twopass cannot be used with -passin or -password\n"); + goto end; + } } else { cpass = pass; mpass = macpass; diff --git a/apps/s_client.c b/apps/s_client.c index 6e06f15f..2a8313d7 100644 --- a/apps/s_client.c +++ b/apps/s_client.c @@ -598,6 +598,7 @@ typedef enum OPTION_choice { #endif OPT_DANE_TLSA_RRDATA, OPT_DANE_EE_NO_NAME, OPT_ENABLE_PHA, + OPT_SCTP_LABEL_BUG, OPT_R_ENUM } OPTION_CHOICE; @@ -754,6 +755,7 @@ const OPTIONS s_client_options[] = { #endif #ifndef OPENSSL_NO_SCTP {"sctp", OPT_SCTP, '-', "Use SCTP"}, + {"sctp_label_bug", OPT_SCTP_LABEL_BUG, '-', "Enable SCTP label length bug"}, #endif #ifndef OPENSSL_NO_SSL_TRACE {"trace", OPT_TRACE, '-', "Show trace output of protocol messages"}, @@ -982,6 +984,9 @@ int s_client_main(int argc, char **argv) #endif char *psksessf = NULL; int enable_pha = 0; +#ifndef OPENSSL_NO_SCTP + int sctp_label_bug = 0; +#endif FD_ZERO(&readfds); FD_ZERO(&writefds); @@ -1333,6 +1338,11 @@ int s_client_main(int argc, char **argv) case OPT_SCTP: #ifndef OPENSSL_NO_SCTP protocol = IPPROTO_SCTP; +#endif + break; + case OPT_SCTP_LABEL_BUG: +#ifndef OPENSSL_NO_SCTP + sctp_label_bug = 1; #endif break; case OPT_TIMEOUT: @@ -1729,6 +1739,11 @@ int s_client_main(int argc, char **argv) } } +#ifndef OPENSSL_NO_SCTP + if (protocol == IPPROTO_SCTP && sctp_label_bug == 1) + SSL_CTX_set_mode(ctx, SSL_MODE_DTLS_SCTP_LABEL_LENGTH_BUG); +#endif + if (min_version != 0 && SSL_CTX_set_min_proto_version(ctx, min_version) == 0) goto end; @@ -2345,7 +2360,7 @@ int s_client_main(int argc, char **argv) BIO_push(fbio, sbio); BIO_printf(fbio, "CONNECT %s HTTP/1.0\r\n", connectstr); - /* + /* * Workaround for broken proxies which would otherwise close * the connection when entering tunnel mode (eg Squid 2.6) */ @@ -3534,7 +3549,7 @@ static char *base64encode (const void *buf, size_t len) i = EVP_EncodeBlock((unsigned char *)out, buf, len); assert(i <= (int)outl); if (i < 0) - *out = '\0'; + *out = '\0'; return out; } diff --git a/apps/s_server.c b/apps/s_server.c index 364f76b3..fbbfd6c9 100644 --- a/apps/s_server.c +++ b/apps/s_server.c @@ -751,7 +751,7 @@ typedef enum OPTION_choice { OPT_CERT2, OPT_KEY2, OPT_NEXTPROTONEG, OPT_ALPN, OPT_SRTP_PROFILES, OPT_KEYMATEXPORT, OPT_KEYMATEXPORTLEN, OPT_KEYLOG_FILE, OPT_MAX_EARLY, OPT_RECV_MAX_EARLY, OPT_EARLY_DATA, - OPT_S_NUM_TICKETS, OPT_ANTI_REPLAY, OPT_NO_ANTI_REPLAY, + OPT_S_NUM_TICKETS, OPT_ANTI_REPLAY, OPT_NO_ANTI_REPLAY, OPT_SCTP_LABEL_BUG, OPT_R_ENUM, OPT_S_ENUM, OPT_V_ENUM, @@ -938,6 +938,7 @@ const OPTIONS s_server_options[] = { #endif #ifndef OPENSSL_NO_SCTP {"sctp", OPT_SCTP, '-', "Use SCTP"}, + {"sctp_label_bug", OPT_SCTP_LABEL_BUG, '-', "Enable SCTP label length bug"}, #endif #ifndef OPENSSL_NO_DH {"no_dhe", OPT_NO_DHE, '-', "Disable ephemeral DH"}, @@ -1047,6 +1048,9 @@ int s_server_main(int argc, char *argv[]) const char *keylog_file = NULL; int max_early_data = -1, recv_max_early_data = -1; char *psksessf = NULL; +#ifndef OPENSSL_NO_SCTP + int sctp_label_bug = 0; +#endif /* Init of few remaining global variables */ local_argc = argc; @@ -1407,7 +1411,7 @@ int s_server_main(int argc, char *argv[]) for (p = psk_key = opt_arg(); *p; p++) { if (isxdigit(_UC(*p))) continue; - BIO_printf(bio_err, "Not a hex number '%s'\n", *argv); + BIO_printf(bio_err, "Not a hex number '%s'\n", psk_key); goto end; } break; @@ -1488,6 +1492,11 @@ int s_server_main(int argc, char *argv[]) case OPT_SCTP: #ifndef OPENSSL_NO_SCTP protocol = IPPROTO_SCTP; +#endif + break; + case OPT_SCTP_LABEL_BUG: +#ifndef OPENSSL_NO_SCTP + sctp_label_bug = 1; #endif break; case OPT_TIMEOUT: @@ -1792,6 +1801,12 @@ int s_server_main(int argc, char *argv[]) goto end; } } + +#ifndef OPENSSL_NO_SCTP + if (protocol == IPPROTO_SCTP && sctp_label_bug == 1) + SSL_CTX_set_mode(ctx, SSL_MODE_DTLS_SCTP_LABEL_LENGTH_BUG); +#endif + if (min_version != 0 && SSL_CTX_set_min_proto_version(ctx, min_version) == 0) goto end; diff --git a/config b/config index 27d2f61a..0755961e 100755 --- a/config +++ b/config @@ -19,7 +19,7 @@ THERE=`dirname $0` # pick up any command line args to config for i do -case "$i" in +case "$i" in -d*) options=$options" --debug";; -t*) DRYRUN="true" VERBOSE="true";; -v*) VERBOSE="true";; @@ -59,7 +59,7 @@ __CNF_LDLIBS= # Now test for ISC and SCO, since it is has a braindamaged uname. # -# We need to work around FreeBSD 1.1.5.1 +# We need to work around FreeBSD 1.1.5.1 ( XREL=`uname -X 2>/dev/null | grep "^Release" | awk '{print $3}'` if [ "x$XREL" != "x" ]; then @@ -363,7 +363,7 @@ esac # At this point we gone through all the one's # we know of: Punt -echo "${MACHINE}-whatever-${SYSTEM}" +echo "${MACHINE}-whatever-${SYSTEM}" exit 0 ) 2>/dev/null | ( @@ -433,7 +433,7 @@ fi CCVER=${CCVER:-0} -# read the output of the embedded GuessOS +# read the output of the embedded GuessOS read GUESSOS echo Operating system: $GUESSOS @@ -732,7 +732,7 @@ case "$GUESSOS" in *-*-[Uu]nix[Ww]are7) if [ "$CC" = "gcc" ]; then OUT="unixware-7-gcc" ; options="$options no-sse2" - else + else OUT="unixware-7" ; options="$options no-sse2" __CNF_CPPFLAGS="$__CNF_CPPFLAGS -D__i386__" fi @@ -793,7 +793,7 @@ case "$GUESSOS" in OUT="aix64-gcc" fi elif [ $OBJECT_MODE -eq 64 ]; then - echo 'Your $OBJECT_MODE was found to be set to 64' + echo 'Your $OBJECT_MODE was found to be set to 64' OUT="aix64-cc" else OUT="aix-cc" @@ -897,7 +897,7 @@ if [ ".$PERL" = . ] ; then exit 1 fi -# run Configure to check to see if we need to specify the +# run Configure to check to see if we need to specify the # compiler for the platform ... in which case we add it on # the end ... otherwise we leave it off @@ -920,7 +920,7 @@ if [ $? = "0" ]; then __CNF_LDFLAGS="'$__CNF_LDFLAGS'" \ __CNF_LDLIBS="'$__CNF_LDLIBS'" \ $PERL $THERE/Configure $OUT $options - fi + fi if [ "$DRYRUN" = "false" ]; then # eval to make sure quoted options, possibly with spaces inside, # are treated right diff --git a/crypto/aes/build.info b/crypto/aes/build.info index 0f048636..1aa7a18d 100644 --- a/crypto/aes/build.info +++ b/crypto/aes/build.info @@ -52,13 +52,4 @@ INCLUDE[bsaes-armv7.o]=.. GENERATE[aes-s390x.S]=asm/aes-s390x.pl $(PERLASM_SCHEME) INCLUDE[aes-s390x.o]=.. -BEGINRAW[Makefile] -##### AES assembler implementations - -# GNU make "catch all" -{- $builddir -}/aes-%.S: {- $sourcedir -}/asm/aes-%.pl - CC="$(CC)" $(PERL) $< $(PERLASM_SCHEME) $@ -{- $builddir -}/bsaes-%.S: {- $sourcedir -}/asm/bsaes-%.pl - CC="$(CC)" $(PERL) $< $(PERLASM_SCHEME) $@ - -ENDRAW[Makefile] +GENERATE[aes-c64xplus.S]=asm/aes-c64xplus.pl $(PERLASM_SCHEME) diff --git a/crypto/asn1/d2i_pu.c b/crypto/asn1/d2i_pu.c index 73093a61..8876878f 100644 --- a/crypto/asn1/d2i_pu.c +++ b/crypto/asn1/d2i_pu.c @@ -32,7 +32,7 @@ EVP_PKEY *d2i_PublicKey(int type, EVP_PKEY **a, const unsigned char **pp, } else ret = *a; - if (!EVP_PKEY_set_type(ret, type)) { + if (type != EVP_PKEY_id(ret) && !EVP_PKEY_set_type(ret, type)) { ASN1err(ASN1_F_D2I_PUBLICKEY, ERR_R_EVP_LIB); goto err; } diff --git a/crypto/blake2/blake2_locl.h b/crypto/blake2/blake2_locl.h index 892a1af1..e8c86dbd 100644 --- a/crypto/blake2/blake2_locl.h +++ b/crypto/blake2/blake2_locl.h @@ -1,5 +1,5 @@ /* - * Copyright 2016-2017 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2016-2018 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 @@ -49,6 +49,7 @@ struct blake2s_ctx_st { uint32_t f[2]; uint8_t buf[BLAKE2S_BLOCKBYTES]; size_t buflen; + size_t outlen; }; struct blake2b_param_st { @@ -73,6 +74,7 @@ struct blake2b_ctx_st { uint64_t f[2]; uint8_t buf[BLAKE2B_BLOCKBYTES]; size_t buflen; + size_t outlen; }; #define BLAKE2B_DIGEST_LENGTH 64 @@ -81,10 +83,29 @@ struct blake2b_ctx_st { typedef struct blake2s_ctx_st BLAKE2S_CTX; typedef struct blake2b_ctx_st BLAKE2B_CTX; -int BLAKE2b_Init(BLAKE2B_CTX *c); +int BLAKE2b_Init(BLAKE2B_CTX *c, const BLAKE2B_PARAM *P); +int BLAKE2b_Init_key(BLAKE2B_CTX *c, const BLAKE2B_PARAM *P, const void *key); int BLAKE2b_Update(BLAKE2B_CTX *c, const void *data, size_t datalen); int BLAKE2b_Final(unsigned char *md, BLAKE2B_CTX *c); -int BLAKE2s_Init(BLAKE2S_CTX *c); +/* + * These setters are internal and do not check the validity of their parameters. + * See blake2b_mac_ctrl for validation logic. + */ + +void blake2b_param_init(BLAKE2B_PARAM *P); +void blake2b_param_set_digest_length(BLAKE2B_PARAM *P, uint8_t outlen); +void blake2b_param_set_key_length(BLAKE2B_PARAM *P, uint8_t keylen); +void blake2b_param_set_personal(BLAKE2B_PARAM *P, const uint8_t *personal, size_t length); +void blake2b_param_set_salt(BLAKE2B_PARAM *P, const uint8_t *salt, size_t length); + +int BLAKE2s_Init(BLAKE2S_CTX *c, const BLAKE2S_PARAM *P); +int BLAKE2s_Init_key(BLAKE2S_CTX *c, const BLAKE2S_PARAM *P, const void *key); int BLAKE2s_Update(BLAKE2S_CTX *c, const void *data, size_t datalen); int BLAKE2s_Final(unsigned char *md, BLAKE2S_CTX *c); + +void blake2s_param_init(BLAKE2S_PARAM *P); +void blake2s_param_set_digest_length(BLAKE2S_PARAM *P, uint8_t outlen); +void blake2s_param_set_key_length(BLAKE2S_PARAM *P, uint8_t keylen); +void blake2s_param_set_personal(BLAKE2S_PARAM *P, const uint8_t *personal, size_t length); +void blake2s_param_set_salt(BLAKE2S_PARAM *P, const uint8_t *salt, size_t length); diff --git a/crypto/blake2/blake2b.c b/crypto/blake2/blake2b.c index d4e53269..73ba0b6b 100644 --- a/crypto/blake2/blake2b.c +++ b/crypto/blake2/blake2b.c @@ -1,5 +1,5 @@ /* - * Copyright 2016-2017 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2016-2018 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 @@ -62,12 +62,14 @@ static ossl_inline void blake2b_init0(BLAKE2B_CTX *S) } } -/* init xors IV with input parameter block */ +/* init xors IV with input parameter block and sets the output length */ static void blake2b_init_param(BLAKE2B_CTX *S, const BLAKE2B_PARAM *P) { size_t i; const uint8_t *p = (const uint8_t *)(P); + blake2b_init0(S); + S->outlen = P->digest_length; /* The param struct is carefully hand packed, and should be 64 bytes on * every platform. */ @@ -78,10 +80,9 @@ static void blake2b_init_param(BLAKE2B_CTX *S, const BLAKE2B_PARAM *P) } } -/* Initialize the hashing context. Always returns 1. */ -int BLAKE2b_Init(BLAKE2B_CTX *c) +/* Initialize the parameter block with default values */ +void blake2b_param_init(BLAKE2B_PARAM *P) { - BLAKE2B_PARAM P[1]; P->digest_length = BLAKE2B_DIGEST_LENGTH; P->key_length = 0; P->fanout = 1; @@ -93,10 +94,60 @@ int BLAKE2b_Init(BLAKE2B_CTX *c) memset(P->reserved, 0, sizeof(P->reserved)); memset(P->salt, 0, sizeof(P->salt)); memset(P->personal, 0, sizeof(P->personal)); +} + +void blake2b_param_set_digest_length(BLAKE2B_PARAM *P, uint8_t outlen) +{ + P->digest_length = outlen; +} + +void blake2b_param_set_key_length(BLAKE2B_PARAM *P, uint8_t keylen) +{ + P->key_length = keylen; +} + +void blake2b_param_set_personal(BLAKE2B_PARAM *P, const uint8_t *personal, size_t len) +{ + memcpy(P->personal, personal, len); + memset(P->personal + len, 0, BLAKE2B_PERSONALBYTES - len); +} + +void blake2b_param_set_salt(BLAKE2B_PARAM *P, const uint8_t *salt, size_t len) +{ + memcpy(P->salt, salt, len); + memset(P->salt + len, 0, BLAKE2B_SALTBYTES - len); +} + +/* + * Initialize the hashing context with the given parameter block. + * Always returns 1. + */ +int BLAKE2b_Init(BLAKE2B_CTX *c, const BLAKE2B_PARAM *P) +{ blake2b_init_param(c, P); return 1; } +/* + * Initialize the hashing context with the given parameter block and key. + * Always returns 1. + */ +int BLAKE2b_Init_key(BLAKE2B_CTX *c, const BLAKE2B_PARAM *P, const void *key) +{ + blake2b_init_param(c, P); + + /* Pad the key to form first data block */ + { + uint8_t block[BLAKE2B_BLOCKBYTES] = {0}; + + memcpy(block, key, P->key_length); + BLAKE2b_Update(c, block, BLAKE2B_BLOCKBYTES); + OPENSSL_cleanse(block, BLAKE2B_BLOCKBYTES); + } + + return 1; +} + /* Permute the state while xoring in the block of data. */ static void blake2b_compress(BLAKE2B_CTX *S, const uint8_t *blocks, @@ -252,17 +303,26 @@ int BLAKE2b_Update(BLAKE2B_CTX *c, const void *data, size_t datalen) */ int BLAKE2b_Final(unsigned char *md, BLAKE2B_CTX *c) { + uint8_t outbuffer[BLAKE2B_OUTBYTES] = {0}; + uint8_t *target = outbuffer; + int iter = (c->outlen + 7) / 8; int i; + /* Avoid writing to the temporary buffer if possible */ + if ((c->outlen % sizeof(c->h[0])) == 0) + target = md; + blake2b_set_lastblock(c); /* Padding */ memset(c->buf + c->buflen, 0, sizeof(c->buf) - c->buflen); blake2b_compress(c, c->buf, c->buflen); - /* Output full hash to message digest */ - for (i = 0; i < 8; ++i) { - store64(md + sizeof(c->h[i]) * i, c->h[i]); - } + /* Output full hash to buffer */ + for (i = 0; i < iter; ++i) + store64(target + sizeof(c->h[i]) * i, c->h[i]); + + if (target != md) + memcpy(md, target, c->outlen); OPENSSL_cleanse(c, sizeof(BLAKE2B_CTX)); return 1; diff --git a/crypto/blake2/blake2b_mac.c b/crypto/blake2/blake2b_mac.c new file mode 100644 index 00000000..71b85178 --- /dev/null +++ b/crypto/blake2/blake2b_mac.c @@ -0,0 +1,190 @@ +/* + * Copyright 2018 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 OPENSSL_NO_BLAKE2 + +# include +# include "blake2_locl.h" +# include "internal/cryptlib.h" +# include "internal/evp_int.h" + +/* typedef EVP_MAC_IMPL */ +struct evp_mac_impl_st { + BLAKE2B_CTX ctx; + BLAKE2B_PARAM params; + unsigned char key[BLAKE2B_KEYBYTES]; +}; + +static EVP_MAC_IMPL *blake2b_mac_new(void) +{ + EVP_MAC_IMPL *macctx = OPENSSL_zalloc(sizeof(*macctx)); + if (macctx != NULL) { + blake2b_param_init(&macctx->params); + /* ctx initialization is deferred to BLAKE2b_Init() */ + } + return macctx; +} + +static void blake2b_mac_free(EVP_MAC_IMPL *macctx) +{ + if (macctx != NULL) { + OPENSSL_cleanse(macctx->key, sizeof(macctx->key)); + OPENSSL_free(macctx); + } +} + +static int blake2b_mac_copy(EVP_MAC_IMPL *dst, EVP_MAC_IMPL *src) +{ + *dst = *src; + return 1; +} + +static int blake2b_mac_init(EVP_MAC_IMPL *macctx) +{ + /* Check key has been set */ + if (macctx->params.key_length == 0) { + EVPerr(EVP_F_BLAKE2B_MAC_INIT, EVP_R_NO_KEY_SET); + return 0; + } + + return BLAKE2b_Init_key(&macctx->ctx, &macctx->params, macctx->key); +} + +static int blake2b_mac_update(EVP_MAC_IMPL *macctx, const unsigned char *data, + size_t datalen) +{ + return BLAKE2b_Update(&macctx->ctx, data, datalen); +} + +static int blake2b_mac_final(EVP_MAC_IMPL *macctx, unsigned char *out) +{ + return BLAKE2b_Final(out, &macctx->ctx); +} + +/* + * ALL Ctrl functions should be set before init(). + */ +static int blake2b_mac_ctrl(EVP_MAC_IMPL *macctx, int cmd, va_list args) +{ + const unsigned char *p; + size_t len; + size_t size; + + switch (cmd) { + case EVP_MAC_CTRL_SET_SIZE: + size = va_arg(args, size_t); + if (size < 1 || size > BLAKE2B_OUTBYTES) { + EVPerr(EVP_F_BLAKE2B_MAC_CTRL, EVP_R_NOT_XOF_OR_INVALID_LENGTH); + return 0; + } + blake2b_param_set_digest_length(&macctx->params, (uint8_t)size); + return 1; + + case EVP_MAC_CTRL_SET_KEY: + p = va_arg(args, const unsigned char *); + len = va_arg(args, size_t); + if (len < 1 || len > BLAKE2B_KEYBYTES) { + EVPerr(EVP_F_BLAKE2B_MAC_CTRL, EVP_R_INVALID_KEY_LENGTH); + return 0; + } + blake2b_param_set_key_length(&macctx->params, (uint8_t)len); + memcpy(macctx->key, p, len); + memset(macctx->key + len, 0, BLAKE2B_KEYBYTES - len); + return 1; + + case EVP_MAC_CTRL_SET_CUSTOM: + p = va_arg(args, const unsigned char *); + len = va_arg(args, size_t); + if (len > BLAKE2B_PERSONALBYTES) { + EVPerr(EVP_F_BLAKE2B_MAC_CTRL, EVP_R_INVALID_CUSTOM_LENGTH); + return 0; + } + blake2b_param_set_personal(&macctx->params, p, len); + return 1; + + case EVP_MAC_CTRL_SET_SALT: + p = va_arg(args, const unsigned char *); + len = va_arg(args, size_t); + if (len > BLAKE2B_SALTBYTES) { + EVPerr(EVP_F_BLAKE2B_MAC_CTRL, EVP_R_INVALID_SALT_LENGTH); + return 0; + } + blake2b_param_set_salt(&macctx->params, p, len); + return 1; + + default: + return -2; + } +} + +static int blake2b_mac_ctrl_int(EVP_MAC_IMPL *macctx, int cmd, ...) +{ + int rv; + va_list args; + + va_start(args, cmd); + rv = blake2b_mac_ctrl(macctx, cmd, args); + va_end(args); + + return rv; +} + +static int blake2b_mac_ctrl_str_cb(void *macctx, int cmd, void *buf, size_t buflen) +{ + return blake2b_mac_ctrl_int(macctx, cmd, buf, buflen); +} + +static int blake2b_mac_ctrl_str(EVP_MAC_IMPL *macctx, const char *type, + const char *value) +{ + if (value == NULL) + return 0; + + if (strcmp(type, "outlen") == 0) + return blake2b_mac_ctrl_int(macctx, EVP_MAC_CTRL_SET_SIZE, (size_t)atoi(value)); + if (strcmp(type, "key") == 0) + return EVP_str2ctrl(blake2b_mac_ctrl_str_cb, macctx, EVP_MAC_CTRL_SET_KEY, + value); + if (strcmp(type, "hexkey") == 0) + return EVP_hex2ctrl(blake2b_mac_ctrl_str_cb, macctx, EVP_MAC_CTRL_SET_KEY, + value); + if (strcmp(type, "custom") == 0) + return EVP_str2ctrl(blake2b_mac_ctrl_str_cb, macctx, EVP_MAC_CTRL_SET_CUSTOM, + value); + if (strcmp(type, "hexcustom") == 0) + return EVP_hex2ctrl(blake2b_mac_ctrl_str_cb, macctx, EVP_MAC_CTRL_SET_CUSTOM, + value); + if (strcmp(type, "salt") == 0) + return EVP_str2ctrl(blake2b_mac_ctrl_str_cb, macctx, EVP_MAC_CTRL_SET_SALT, + value); + if (strcmp(type, "hexsalt") == 0) + return EVP_hex2ctrl(blake2b_mac_ctrl_str_cb, macctx, EVP_MAC_CTRL_SET_SALT, + value); + return -2; +} + +static size_t blake2b_mac_size(EVP_MAC_IMPL *macctx) +{ + return macctx->params.digest_length; +} + +const EVP_MAC blake2b_mac_meth = { + EVP_MAC_BLAKE2B, + blake2b_mac_new, + blake2b_mac_copy, + blake2b_mac_free, + blake2b_mac_size, + blake2b_mac_init, + blake2b_mac_update, + blake2b_mac_final, + blake2b_mac_ctrl, + blake2b_mac_ctrl_str +}; + +#endif diff --git a/crypto/blake2/blake2s.c b/crypto/blake2/blake2s.c index c0f0f266..121f0d1a 100644 --- a/crypto/blake2/blake2s.c +++ b/crypto/blake2/blake2s.c @@ -1,5 +1,5 @@ /* - * Copyright 2016-2017 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2016-2018 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 @@ -58,27 +58,26 @@ static ossl_inline void blake2s_init0(BLAKE2S_CTX *S) } } -/* init2 xors IV with input parameter block */ +/* init xors IV with input parameter block and sets the output length */ static void blake2s_init_param(BLAKE2S_CTX *S, const BLAKE2S_PARAM *P) { - const uint8_t *p = (const uint8_t *)(P); size_t i; + const uint8_t *p = (const uint8_t *)(P); + + blake2s_init0(S); + S->outlen = P->digest_length; /* The param struct is carefully hand packed, and should be 32 bytes on * every platform. */ assert(sizeof(BLAKE2S_PARAM) == 32); - blake2s_init0(S); /* IV XOR ParamBlock */ for (i = 0; i < 8; ++i) { S->h[i] ^= load32(&p[i*4]); } } -/* Initialize the hashing context. Always returns 1. */ -int BLAKE2s_Init(BLAKE2S_CTX *c) +void blake2s_param_init(BLAKE2S_PARAM *P) { - BLAKE2S_PARAM P[1]; - P->digest_length = BLAKE2S_DIGEST_LENGTH; P->key_length = 0; P->fanout = 1; @@ -89,10 +88,59 @@ int BLAKE2s_Init(BLAKE2S_CTX *c) P->inner_length = 0; memset(P->salt, 0, sizeof(P->salt)); memset(P->personal, 0, sizeof(P->personal)); +} + +void blake2s_param_set_digest_length(BLAKE2S_PARAM *P, uint8_t outlen) +{ + P->digest_length = outlen; +} + +void blake2s_param_set_key_length(BLAKE2S_PARAM *P, uint8_t keylen) +{ + P->key_length = keylen; +} + +void blake2s_param_set_personal(BLAKE2S_PARAM *P, const uint8_t *personal, size_t len) +{ + memcpy(P->personal, personal, len); + memset(P->personal + len, 0, BLAKE2S_PERSONALBYTES - len); +} + +void blake2s_param_set_salt(BLAKE2S_PARAM *P, const uint8_t *salt, size_t len) +{ + memcpy(P->salt, salt, len); + memset(P->salt + len, 0, BLAKE2S_SALTBYTES - len);} + +/* + * Initialize the hashing context with the given parameter block. + * Always returns 1. + */ +int BLAKE2s_Init(BLAKE2S_CTX *c, const BLAKE2S_PARAM *P) +{ blake2s_init_param(c, P); return 1; } +/* + * Initialize the hashing context with the given parameter block and key. + * Always returns 1. + */ +int BLAKE2s_Init_key(BLAKE2S_CTX *c, const BLAKE2S_PARAM *P, const void *key) +{ + blake2s_init_param(c, P); + + /* Pad the key to form first data block */ + { + uint8_t block[BLAKE2S_BLOCKBYTES] = {0}; + + memcpy(block, key, P->key_length); + BLAKE2s_Update(c, block, BLAKE2S_BLOCKBYTES); + OPENSSL_cleanse(block, BLAKE2S_BLOCKBYTES); + } + + return 1; +} + /* Permute the state while xoring in the block of data. */ static void blake2s_compress(BLAKE2S_CTX *S, const uint8_t *blocks, @@ -246,17 +294,26 @@ int BLAKE2s_Update(BLAKE2S_CTX *c, const void *data, size_t datalen) */ int BLAKE2s_Final(unsigned char *md, BLAKE2S_CTX *c) { + uint8_t outbuffer[BLAKE2S_OUTBYTES] = {0}; + uint8_t *target = outbuffer; + int iter = (c->outlen + 3) / 4; int i; + /* Avoid writing to the temporary buffer if possible */ + if ((c->outlen % sizeof(c->h[0])) == 0) + target = md; + blake2s_set_lastblock(c); /* Padding */ memset(c->buf + c->buflen, 0, sizeof(c->buf) - c->buflen); blake2s_compress(c, c->buf, c->buflen); - /* Output full hash to temp buffer */ - for (i = 0; i < 8; ++i) { - store32(md + sizeof(c->h[i]) * i, c->h[i]); - } + /* Output full hash to buffer */ + for (i = 0; i < iter; ++i) + store32(target + sizeof(c->h[i]) * i, c->h[i]); + + if (target != md) + memcpy(md, target, c->outlen); OPENSSL_cleanse(c, sizeof(BLAKE2S_CTX)); return 1; diff --git a/crypto/blake2/blake2s_mac.c b/crypto/blake2/blake2s_mac.c new file mode 100644 index 00000000..d40778cb --- /dev/null +++ b/crypto/blake2/blake2s_mac.c @@ -0,0 +1,190 @@ +/* + * Copyright 2018 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 OPENSSL_NO_BLAKE2 + +# include +# include "blake2_locl.h" +# include "internal/cryptlib.h" +# include "internal/evp_int.h" + +/* typedef EVP_MAC_IMPL */ +struct evp_mac_impl_st { + BLAKE2S_CTX ctx; + BLAKE2S_PARAM params; + unsigned char key[BLAKE2S_KEYBYTES]; +}; + +static EVP_MAC_IMPL *blake2s_mac_new(void) +{ + EVP_MAC_IMPL *macctx = OPENSSL_zalloc(sizeof(*macctx)); + if (macctx != NULL) { + blake2s_param_init(&macctx->params); + /* ctx initialization is deferred to BLAKE2s_Init() */ + } + return macctx; +} + +static void blake2s_mac_free(EVP_MAC_IMPL *macctx) +{ + if (macctx != NULL) { + OPENSSL_cleanse(macctx->key, sizeof(macctx->key)); + OPENSSL_free(macctx); + } +} + +static int blake2s_mac_copy(EVP_MAC_IMPL *dst, EVP_MAC_IMPL *src) +{ + *dst = *src; + return 1; +} + +static int blake2s_mac_init(EVP_MAC_IMPL *macctx) +{ + /* Check key has been set */ + if (macctx->params.key_length == 0) { + EVPerr(EVP_F_BLAKE2S_MAC_INIT, EVP_R_NO_KEY_SET); + return 0; + } + + return BLAKE2s_Init_key(&macctx->ctx, &macctx->params, macctx->key); +} + +static int blake2s_mac_update(EVP_MAC_IMPL *macctx, const unsigned char *data, + size_t datalen) +{ + return BLAKE2s_Update(&macctx->ctx, data, datalen); +} + +static int blake2s_mac_final(EVP_MAC_IMPL *macctx, unsigned char *out) +{ + return BLAKE2s_Final(out, &macctx->ctx); +} + +/* + * ALL Ctrl functions should be set before init(). + */ +static int blake2s_mac_ctrl(EVP_MAC_IMPL *macctx, int cmd, va_list args) +{ + const unsigned char *p; + size_t len; + size_t size; + + switch (cmd) { + case EVP_MAC_CTRL_SET_SIZE: + size = va_arg(args, size_t); + if (size < 1 || size > BLAKE2S_OUTBYTES) { + EVPerr(EVP_F_BLAKE2S_MAC_CTRL, EVP_R_NOT_XOF_OR_INVALID_LENGTH); + return 0; + } + blake2s_param_set_digest_length(&macctx->params, (uint8_t)size); + return 1; + + case EVP_MAC_CTRL_SET_KEY: + p = va_arg(args, const unsigned char *); + len = va_arg(args, size_t); + if (len < 1 || len > BLAKE2S_KEYBYTES) { + EVPerr(EVP_F_BLAKE2S_MAC_CTRL, EVP_R_INVALID_KEY_LENGTH); + return 0; + } + blake2s_param_set_key_length(&macctx->params, (uint8_t)len); + memcpy(macctx->key, p, len); + memset(macctx->key + len, 0, BLAKE2S_KEYBYTES - len); + return 1; + + case EVP_MAC_CTRL_SET_CUSTOM: + p = va_arg(args, const unsigned char *); + len = va_arg(args, size_t); + if (len > BLAKE2S_PERSONALBYTES) { + EVPerr(EVP_F_BLAKE2S_MAC_CTRL, EVP_R_INVALID_CUSTOM_LENGTH); + return 0; + } + blake2s_param_set_personal(&macctx->params, p, len); + return 1; + + case EVP_MAC_CTRL_SET_SALT: + p = va_arg(args, const unsigned char *); + len = va_arg(args, size_t); + if (len > BLAKE2S_SALTBYTES) { + EVPerr(EVP_F_BLAKE2S_MAC_CTRL, EVP_R_INVALID_SALT_LENGTH); + return 0; + } + blake2s_param_set_salt(&macctx->params, p, len); + return 1; + + default: + return -2; + } +} + +static int blake2s_mac_ctrl_int(EVP_MAC_IMPL *macctx, int cmd, ...) +{ + int rv; + va_list args; + + va_start(args, cmd); + rv = blake2s_mac_ctrl(macctx, cmd, args); + va_end(args); + + return rv; +} + +static int blake2s_mac_ctrl_str_cb(void *macctx, int cmd, void *buf, size_t buflen) +{ + return blake2s_mac_ctrl_int(macctx, cmd, buf, buflen); +} + +static int blake2s_mac_ctrl_str(EVP_MAC_IMPL *macctx, const char *type, + const char *value) +{ + if (value == NULL) + return 0; + + if (strcmp(type, "outlen") == 0) + return blake2s_mac_ctrl_int(macctx, EVP_MAC_CTRL_SET_SIZE, (size_t)atoi(value)); + if (strcmp(type, "key") == 0) + return EVP_str2ctrl(blake2s_mac_ctrl_str_cb, macctx, EVP_MAC_CTRL_SET_KEY, + value); + if (strcmp(type, "hexkey") == 0) + return EVP_hex2ctrl(blake2s_mac_ctrl_str_cb, macctx, EVP_MAC_CTRL_SET_KEY, + value); + if (strcmp(type, "custom") == 0) + return EVP_str2ctrl(blake2s_mac_ctrl_str_cb, macctx, EVP_MAC_CTRL_SET_CUSTOM, + value); + if (strcmp(type, "hexcustom") == 0) + return EVP_hex2ctrl(blake2s_mac_ctrl_str_cb, macctx, EVP_MAC_CTRL_SET_CUSTOM, + value); + if (strcmp(type, "salt") == 0) + return EVP_str2ctrl(blake2s_mac_ctrl_str_cb, macctx, EVP_MAC_CTRL_SET_SALT, + value); + if (strcmp(type, "hexsalt") == 0) + return EVP_hex2ctrl(blake2s_mac_ctrl_str_cb, macctx, EVP_MAC_CTRL_SET_SALT, + value); + return -2; +} + +static size_t blake2s_mac_size(EVP_MAC_IMPL *macctx) +{ + return macctx->params.digest_length; +} + +const EVP_MAC blake2s_mac_meth = { + EVP_MAC_BLAKE2S, + blake2s_mac_new, + blake2s_mac_copy, + blake2s_mac_free, + blake2s_mac_size, + blake2s_mac_init, + blake2s_mac_update, + blake2s_mac_final, + blake2s_mac_ctrl, + blake2s_mac_ctrl_str +}; + +#endif diff --git a/crypto/blake2/build.info b/crypto/blake2/build.info index 0036f084..ab72ef2a 100644 --- a/crypto/blake2/build.info +++ b/crypto/blake2/build.info @@ -1,3 +1,3 @@ LIBS=../../libcrypto SOURCE[../../libcrypto]=\ - blake2b.c blake2s.c m_blake2b.c m_blake2s.c + blake2b.c blake2s.c blake2b_mac.c blake2s_mac.c m_blake2b.c m_blake2s.c diff --git a/crypto/blake2/m_blake2b.c b/crypto/blake2/m_blake2b.c index a37ab89e..2fb80f8b 100644 --- a/crypto/blake2/m_blake2b.c +++ b/crypto/blake2/m_blake2b.c @@ -1,5 +1,5 @@ /* - * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2016-2018 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 @@ -25,7 +25,9 @@ static int init(EVP_MD_CTX *ctx) { - return BLAKE2b_Init(EVP_MD_CTX_md_data(ctx)); + BLAKE2B_PARAM P; + blake2b_param_init(&P); + return BLAKE2b_Init(EVP_MD_CTX_md_data(ctx), &P); } static int update(EVP_MD_CTX *ctx, const void *data, size_t count) @@ -49,7 +51,7 @@ static const EVP_MD blake2b_md = { NULL, NULL, BLAKE2B_BLOCKBYTES, - sizeof(EVP_MD *) + sizeof(BLAKE2B_CTX), + sizeof(BLAKE2B_CTX), }; const EVP_MD *EVP_blake2b512(void) diff --git a/crypto/blake2/m_blake2s.c b/crypto/blake2/m_blake2s.c index 2c5f42b2..8ff17275 100644 --- a/crypto/blake2/m_blake2s.c +++ b/crypto/blake2/m_blake2s.c @@ -1,5 +1,5 @@ /* - * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2016-2018 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 @@ -25,7 +25,9 @@ static int init(EVP_MD_CTX *ctx) { - return BLAKE2s_Init(EVP_MD_CTX_md_data(ctx)); + BLAKE2S_PARAM P; + blake2s_param_init(&P); + return BLAKE2s_Init(EVP_MD_CTX_md_data(ctx), &P); } static int update(EVP_MD_CTX *ctx, const void *data, size_t count) @@ -49,7 +51,7 @@ static const EVP_MD blake2s_md = { NULL, NULL, BLAKE2S_BLOCKBYTES, - sizeof(EVP_MD *) + sizeof(BLAKE2S_CTX), + sizeof(BLAKE2S_CTX), }; const EVP_MD *EVP_blake2s256(void) diff --git a/crypto/bn/asm/ia64.S b/crypto/bn/asm/ia64.S index f5312a3c..0d64e98c 100644 --- a/crypto/bn/asm/ia64.S +++ b/crypto/bn/asm/ia64.S @@ -47,7 +47,7 @@ // on Itanium2! What to do? Reschedule loops for Itanium2? But then // Itanium would exhibit anti-scalability. So I've chosen to reschedule // for worst latency for every instruction aiming for best *all-round* -// performance. +// performance. // Q. How much faster does it get? // A. Here is the output from 'openssl speed rsa dsa' for vanilla @@ -471,7 +471,7 @@ bn_mul_add_words: .global bn_sqr_words# .proc bn_sqr_words# .align 64 -.skip 32 // makes the loop body aligned at 64-byte boundary +.skip 32 // makes the loop body aligned at 64-byte boundary bn_sqr_words: .prologue .save ar.pfs,r2 diff --git a/crypto/bn/asm/sparcv8plus.S b/crypto/bn/asm/sparcv8plus.S index df41904c..696dc7b5 100644 --- a/crypto/bn/asm/sparcv8plus.S +++ b/crypto/bn/asm/sparcv8plus.S @@ -154,9 +154,9 @@ .register %g2,#scratch .register %g3,#scratch # define FRAME_SIZE -192 -#else +#else # define FRAME_SIZE -96 -#endif +#endif /* * GNU assembler can't stand stuw:-( */ diff --git a/crypto/bn/bn_ctx.c b/crypto/bn/bn_ctx.c index 61348bdf..5106878d 100644 --- a/crypto/bn/bn_ctx.c +++ b/crypto/bn/bn_ctx.c @@ -256,7 +256,7 @@ static int BN_STACK_push(BN_STACK *st, unsigned int idx) unsigned int newsize = st->size ? (st->size * 3 / 2) : BN_CTX_START_FRAMES; unsigned int *newitems; - + if ((newitems = OPENSSL_malloc(sizeof(*newitems) * newsize)) == NULL) { BNerr(BN_F_BN_STACK_PUSH, ERR_R_MALLOC_FAILURE); return 0; @@ -310,7 +310,7 @@ static BIGNUM *BN_POOL_get(BN_POOL *p, int flag) /* Full; allocate a new pool item and link it in. */ if (p->used == p->size) { BN_POOL_ITEM *item; - + if ((item = OPENSSL_malloc(sizeof(*item))) == NULL) { BNerr(BN_F_BN_POOL_GET, ERR_R_MALLOC_FAILURE); return NULL; diff --git a/crypto/build.info b/crypto/build.info index e014e033..5e879ea9 100644 --- a/crypto/build.info +++ b/crypto/build.info @@ -14,9 +14,6 @@ SOURCE[../libcrypto]=\ threads_pthread.c threads_win.c threads_none.c getenv.c \ o_init.c o_fips.c mem_sec.c init.c {- $target{cpuid_asm_src} -} \ {- $target{uplink_aux_src} -} -EXTRA= ../ms/uplink-x86.pl ../ms/uplink.c ../ms/applink.c \ - x86cpuid.pl x86_64cpuid.pl ia64cpuid.S \ - ppccpuid.pl pariscid.pl alphacpuid.pl arm64cpuid.pl armv4cpuid.pl DEPEND[cversion.o]=buildinf.h GENERATE[buildinf.h]=../util/mkbuildinf.pl "$(CC) $(LIB_CFLAGS) $(CPPFLAGS_Q)" "$(PLATFORM)" diff --git a/crypto/chacha/build.info b/crypto/chacha/build.info index e1d61164..bbd9ca8b 100644 --- a/crypto/chacha/build.info +++ b/crypto/chacha/build.info @@ -10,10 +10,5 @@ INCLUDE[chacha-armv4.o]=.. GENERATE[chacha-armv8.S]=asm/chacha-armv8.pl $(PERLASM_SCHEME) INCLUDE[chacha-armv8.o]=.. INCLUDE[chacha-s390x.o]=.. - -BEGINRAW[Makefile(unix)] -##### CHACHA assembler implementations - -{- $builddir -}/chacha-%.S: {- $sourcedir -}/asm/chacha-%.pl - CC="$(CC)" $(PERL) $< $(PERLASM_SCHEME) $@ -ENDRAW[Makefile(unix)] +GENERATE[chacha-c64xplus.S]=asm/chacha-c64xplus.pl $(PERLASM_SCHEME) +GENERATE[chacha-s390x.S]=asm/chacha-s390x.pl $(PERLASM_SCHEME) diff --git a/crypto/cryptlib.c b/crypto/cryptlib.c index 9018358f..6e5e65ea 100644 --- a/crypto/cryptlib.c +++ b/crypto/cryptlib.c @@ -352,9 +352,9 @@ void OPENSSL_showfatal(const char *fmta, ...) /* * TODO: (For non GUI and no std error cases) - * Add event logging feature here. + * Add event logging feature here. */ - + # if !defined(NDEBUG) /* * We are in a situation where we tried to report a critical @@ -393,7 +393,7 @@ void OPENSSL_showfatal(const char *fmta, ...) # endif # else MessageBox(NULL, buf, _T("OpenSSL: FATAL"), MB_OK | MB_ICONERROR); -# endif +# endif } #else void OPENSSL_showfatal(const char *fmta, ...) diff --git a/crypto/des/asm/des_enc.m4 b/crypto/des/asm/des_enc.m4 index 9a17fac6..c6661fe7 100644 --- a/crypto/des/asm/des_enc.m4 +++ b/crypto/des/asm/des_enc.m4 @@ -311,7 +311,7 @@ $4: sll out1, 28, out1 ! rotate xor $1, local1, $1 ! 1 finished, local1 now sbox 7 - ld [global2+local2], local2 ! 2 + ld [global2+local2], local2 ! 2 srl out0, 24, local1 ! 7 or out1, local0, out1 ! rotate @@ -1390,7 +1390,7 @@ DES_ncbc_encrypt: add %o7,global1,global1 sub global1,.PIC.DES_SPtrans-.des_and,out2 - cmp in5, 0 ! enc + cmp in5, 0 ! enc be .ncbc.dec STPTR in4, IVEC diff --git a/crypto/dsa/dsa_pmeth.c b/crypto/dsa/dsa_pmeth.c index 848b673d..0786fc27 100644 --- a/crypto/dsa/dsa_pmeth.c +++ b/crypto/dsa/dsa_pmeth.c @@ -174,9 +174,7 @@ static int pkey_dsa_ctrl_str(EVP_PKEY_CTX *ctx, } if (strcmp(type, "dsa_paramgen_q_bits") == 0) { int qbits = atoi(value); - return EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DSA, EVP_PKEY_OP_PARAMGEN, - EVP_PKEY_CTRL_DSA_PARAMGEN_Q_BITS, qbits, - NULL); + return EVP_PKEY_CTX_set_dsa_paramgen_q_bits(ctx, qbits); } if (strcmp(type, "dsa_paramgen_md") == 0) { const EVP_MD *md = EVP_get_digestbyname(value); @@ -185,9 +183,7 @@ static int pkey_dsa_ctrl_str(EVP_PKEY_CTX *ctx, DSAerr(DSA_F_PKEY_DSA_CTRL_STR, DSA_R_INVALID_DIGEST_TYPE); return 0; } - return EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DSA, EVP_PKEY_OP_PARAMGEN, - EVP_PKEY_CTRL_DSA_PARAMGEN_MD, 0, - (void *)md); + return EVP_PKEY_CTX_set_dsa_paramgen_md(ctx, md); } return -2; } diff --git a/crypto/ec/build.info b/crypto/ec/build.info index a1e673e3..dd1c891e 100644 --- a/crypto/ec/build.info +++ b/crypto/ec/build.info @@ -29,11 +29,6 @@ GENERATE[ecp_nistz256-ppc64.s]=asm/ecp_nistz256-ppc64.pl $(PERLASM_SCHEME) GENERATE[x25519-x86_64.s]=asm/x25519-x86_64.pl $(PERLASM_SCHEME) GENERATE[x25519-ppc64.s]=asm/x25519-ppc64.pl $(PERLASM_SCHEME) -BEGINRAW[Makefile] -{- $builddir -}/ecp_nistz256-%.S: {- $sourcedir -}/asm/ecp_nistz256-%.pl - CC="$(CC)" $(PERL) $< $(PERLASM_SCHEME) $@ -ENDRAW[Makefile] - INCLUDE[curve448/arch_32/f_impl.o]=curve448/arch_32 curve448 INCLUDE[curve448/f_generic.o]=curve448/arch_32 curve448 INCLUDE[curve448/scalar.o]=curve448/arch_32 curve448 diff --git a/crypto/ec/curve448/point_448.h b/crypto/ec/curve448/point_448.h index 02b287c0..1708b57f 100644 --- a/crypto/ec/curve448/point_448.h +++ b/crypto/ec/curve448/point_448.h @@ -116,7 +116,7 @@ void curve448_scalar_encode(unsigned char ser[C448_SCALAR_BYTES], /* * Add two scalars. |a|, |b| and |out| may alias each other. - * + * * a (in): One scalar. * b (in): Another scalar. * out (out): a+b. @@ -135,7 +135,7 @@ void curve448_scalar_sub(curve448_scalar_t out, /* * Multiply two scalars. |a|, |b| and |out| may alias each other. - * + * * a (in): One scalar. * b (in): Another scalar. * out (out): a*b. @@ -145,7 +145,7 @@ void curve448_scalar_mul(curve448_scalar_t out, /* * Halve a scalar. |a| and |out| may alias each other. -* +* * a (in): A scalar. * out (out): a/2. */ @@ -154,7 +154,7 @@ void curve448_scalar_halve(curve448_scalar_t out, const curve448_scalar_t a); /* * Copy a scalar. The scalars may alias each other, in which case this * function does nothing. - * + * * a (in): A scalar. * out (out): Will become a copy of a. */ @@ -183,7 +183,7 @@ static ossl_inline void curve448_point_copy(curve448_point_t a, * * a (in): A point. * b (in): Another point. - * + * * Returns: * C448_TRUE: The points are equal. * C448_FALSE: The points are not equal. @@ -243,7 +243,7 @@ void curve448_point_mul_by_ratio_and_encode_like_x448( /* * RFC 7748 Diffie-Hellman base point scalarmul. This function uses a different * (non-Decaf) encoding. - * + * * out (out): The scaled point base*scalar * scalar (in): The scalar to multiply by. */ @@ -273,7 +273,7 @@ void curve448_precomputed_scalarmul(curve448_point_t scaled, * base2 (in): A second point to be scaled. * scalar2 (in) A second scalar to multiply by. * - * Warning: This function takes variable time, and may leak the scalars used. + * Warning: This function takes variable time, and may leak the scalars used. * It is designed for signature verification. */ void curve448_base_double_scalarmul_non_secret(curve448_point_t combo, diff --git a/crypto/engine/README b/crypto/engine/README index 0050b9e5..c7a5696c 100644 --- a/crypto/engine/README +++ b/crypto/engine/README @@ -26,7 +26,7 @@ algorithm/mode pair are; EVP_EncryptInit(&ctx, cipher, key, iv); [ ... use EVP_EncryptUpdate() and EVP_EncryptFinal() ...] -(ii) indirectly; +(ii) indirectly; OpenSSL_add_all_ciphers(); cipher = EVP_get_cipherbyname("des_cbc"); EVP_EncryptInit(&ctx, cipher, key, iv); diff --git a/crypto/engine/eng_lib.c b/crypto/engine/eng_lib.c index a266a708..be893fe5 100644 --- a/crypto/engine/eng_lib.c +++ b/crypto/engine/eng_lib.c @@ -124,7 +124,7 @@ static int int_cleanup_check(int create) static ENGINE_CLEANUP_ITEM *int_cleanup_item(ENGINE_CLEANUP_CB *cb) { ENGINE_CLEANUP_ITEM *item; - + if ((item = OPENSSL_malloc(sizeof(*item))) == NULL) { ENGINEerr(ENGINE_F_INT_CLEANUP_ITEM, ERR_R_MALLOC_FAILURE); return NULL; diff --git a/crypto/err/openssl.txt b/crypto/err/openssl.txt index 0e133d6e..aaea598b 100644 --- a/crypto/err/openssl.txt +++ b/crypto/err/openssl.txt @@ -730,6 +730,10 @@ EVP_F_ARIA_GCM_CTRL:197:aria_gcm_ctrl EVP_F_ARIA_GCM_INIT_KEY:176:aria_gcm_init_key EVP_F_ARIA_INIT_KEY:185:aria_init_key EVP_F_B64_NEW:198:b64_new +EVP_F_BLAKE2B_MAC_CTRL:220:blake2b_mac_ctrl +EVP_F_BLAKE2B_MAC_INIT:221:blake2b_mac_init +EVP_F_BLAKE2S_MAC_CTRL:222:blake2s_mac_ctrl +EVP_F_BLAKE2S_MAC_INIT:223:blake2s_mac_init EVP_F_CAMELLIA_INIT_KEY:159:camellia_init_key EVP_F_CHACHA20_POLY1305_CTRL:182:chacha20_poly1305_ctrl EVP_F_CMLL_T4_INIT_KEY:179:cmll_t4_init_key @@ -2263,6 +2267,7 @@ EVP_R_INVALID_FIPS_MODE:168:invalid fips mode EVP_R_INVALID_KEY:163:invalid key EVP_R_INVALID_KEY_LENGTH:130:invalid key length EVP_R_INVALID_OPERATION:148:invalid operation +EVP_R_INVALID_SALT_LENGTH:186:invalid salt length EVP_R_KEYGEN_FAILURE:120:keygen failure EVP_R_KEY_SETUP_FAILED:180:key setup failed EVP_R_MEMORY_LIMIT_EXCEEDED:172:memory limit exceeded diff --git a/crypto/evp/c_allm.c b/crypto/evp/c_allm.c index 2cc06942..f5442dfa 100644 --- a/crypto/evp/c_allm.c +++ b/crypto/evp/c_allm.c @@ -12,6 +12,10 @@ void openssl_add_all_macs_int(void) { +#ifndef OPENSSL_NO_BLAKE2 + EVP_add_mac(&blake2b_mac_meth); + EVP_add_mac(&blake2s_mac_meth); +#endif #ifndef OPENSSL_NO_CMAC EVP_add_mac(&cmac_meth); #endif diff --git a/crypto/evp/e_aes.c b/crypto/evp/e_aes.c index 8dc52352..3d2068c8 100644 --- a/crypto/evp/e_aes.c +++ b/crypto/evp/e_aes.c @@ -3081,7 +3081,7 @@ static int aes_gcm_tls_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, if (out != in || len < (EVP_GCM_TLS_EXPLICIT_IV_LEN + EVP_GCM_TLS_TAG_LEN)) return -1; - + /* * Check for too many keys as per FIPS 140-2 IG A.5 "Key/IV Pair Uniqueness * Requirements from SP 800-38D". The requirements is for one party to the diff --git a/crypto/evp/evp_err.c b/crypto/evp/evp_err.c index 14e5ed67..a4dd97b5 100644 --- a/crypto/evp/evp_err.c +++ b/crypto/evp/evp_err.c @@ -27,6 +27,10 @@ static const ERR_STRING_DATA EVP_str_functs[] = { {ERR_PACK(ERR_LIB_EVP, EVP_F_ARIA_GCM_INIT_KEY, 0), "aria_gcm_init_key"}, {ERR_PACK(ERR_LIB_EVP, EVP_F_ARIA_INIT_KEY, 0), "aria_init_key"}, {ERR_PACK(ERR_LIB_EVP, EVP_F_B64_NEW, 0), "b64_new"}, + {ERR_PACK(ERR_LIB_EVP, EVP_F_BLAKE2B_MAC_CTRL, 0), "blake2b_mac_ctrl"}, + {ERR_PACK(ERR_LIB_EVP, EVP_F_BLAKE2B_MAC_INIT, 0), "blake2b_mac_init"}, + {ERR_PACK(ERR_LIB_EVP, EVP_F_BLAKE2S_MAC_CTRL, 0), "blake2s_mac_ctrl"}, + {ERR_PACK(ERR_LIB_EVP, EVP_F_BLAKE2S_MAC_INIT, 0), "blake2s_mac_init"}, {ERR_PACK(ERR_LIB_EVP, EVP_F_CAMELLIA_INIT_KEY, 0), "camellia_init_key"}, {ERR_PACK(ERR_LIB_EVP, EVP_F_CHACHA20_POLY1305_CTRL, 0), "chacha20_poly1305_ctrl"}, @@ -226,6 +230,8 @@ static const ERR_STRING_DATA EVP_str_reasons[] = { {ERR_PACK(ERR_LIB_EVP, 0, EVP_R_INVALID_KEY), "invalid key"}, {ERR_PACK(ERR_LIB_EVP, 0, EVP_R_INVALID_KEY_LENGTH), "invalid key length"}, {ERR_PACK(ERR_LIB_EVP, 0, EVP_R_INVALID_OPERATION), "invalid operation"}, + {ERR_PACK(ERR_LIB_EVP, 0, EVP_R_INVALID_SALT_LENGTH), + "invalid salt length"}, {ERR_PACK(ERR_LIB_EVP, 0, EVP_R_KEYGEN_FAILURE), "keygen failure"}, {ERR_PACK(ERR_LIB_EVP, 0, EVP_R_KEY_SETUP_FAILED), "key setup failed"}, {ERR_PACK(ERR_LIB_EVP, 0, EVP_R_MEMORY_LIMIT_EXCEEDED), diff --git a/crypto/include/internal/evp_int.h b/crypto/include/internal/evp_int.h index 82d1a6bf..189d8aa5 100644 --- a/crypto/include/internal/evp_int.h +++ b/crypto/include/internal/evp_int.h @@ -128,6 +128,8 @@ struct evp_mac_st { int (*ctrl_str) (EVP_MAC_IMPL *macctx, const char *type, const char *value); }; +extern const EVP_MAC blake2b_mac_meth; +extern const EVP_MAC blake2s_mac_meth; extern const EVP_MAC cmac_meth; extern const EVP_MAC gmac_meth; extern const EVP_MAC hmac_meth; diff --git a/crypto/modes/build.info b/crypto/modes/build.info index 1820ab26..f015a4c3 100644 --- a/crypto/modes/build.info +++ b/crypto/modes/build.info @@ -22,9 +22,4 @@ GENERATE[ghashv8-armx.S]=asm/ghashv8-armx.pl $(PERLASM_SCHEME) INCLUDE[ghashv8-armx.o]=.. GENERATE[ghash-s390x.S]=asm/ghash-s390x.pl $(PERLASM_SCHEME) INCLUDE[ghash-s390x.o]=.. - -BEGINRAW[Makefile] -# GNU make "catch all" -{- $builddir -}/ghash-%.S: {- $sourcedir -}/asm/ghash-%.pl - CC="$(CC)" $(PERL) $< $(PERLASM_SCHEME) $@ -ENDRAW[Makefile] +GENERATE[ghash-c64xplus.S]=asm/ghash-c64xplus.pl $(PERLASM_SCHEME) diff --git a/crypto/objects/obj_dat.h b/crypto/objects/obj_dat.h index 550e794f..15c712b2 100644 --- a/crypto/objects/obj_dat.h +++ b/crypto/objects/obj_dat.h @@ -1079,7 +1079,7 @@ static const unsigned char so[7767] = { 0x28,0xCC,0x45,0x03,0x04, /* [ 7761] OBJ_gmac */ }; -#define NUM_NID 1202 +#define NUM_NID 1204 static const ASN1_OBJECT nid_objs[NUM_NID] = { {"UNDEF", "undefined", NID_undef}, {"rsadsi", "RSA Data Security, Inc.", NID_rsadsi, 6, &so[0]}, @@ -2282,10 +2282,12 @@ static const ASN1_OBJECT nid_objs[NUM_NID] = { {"AES-128-SIV", "aes-128-siv", NID_aes_128_siv}, {"AES-192-SIV", "aes-192-siv", NID_aes_192_siv}, {"AES-256-SIV", "aes-256-siv", NID_aes_256_siv}, + {"BLAKE2BMAC", "blake2bmac", NID_blake2bmac}, + {"BLAKE2SMAC", "blake2smac", NID_blake2smac}, {"ChaCha20-Poly1305-D", "chacha20-poly1305-draft", NID_chacha20_poly1305_draft }, }; -#define NUM_SN 1193 +#define NUM_SN 1195 static const unsigned int sn_objs[NUM_SN] = { 364, /* "AD_DVCS" */ 419, /* "AES-128-CBC" */ @@ -2363,6 +2365,8 @@ static const unsigned int sn_objs[NUM_SN] = { 93, /* "BF-CFB" */ 92, /* "BF-ECB" */ 94, /* "BF-OFB" */ + 1201, /* "BLAKE2BMAC" */ + 1202, /* "BLAKE2SMAC" */ 1056, /* "BLAKE2b512" */ 1057, /* "BLAKE2s256" */ 14, /* "C" */ @@ -2406,7 +2410,7 @@ static const unsigned int sn_objs[NUM_SN] = { 417, /* "CSPName" */ 1019, /* "ChaCha20" */ 1018, /* "ChaCha20-Poly1305" */ - 1201, /* "chacha20-poly1305-draft" */ + 1203, /* "chacha20-poly1305-draft" */ 367, /* "CrlID" */ 391, /* "DC" */ 31, /* "DES-CBC" */ @@ -3482,7 +3486,7 @@ static const unsigned int sn_objs[NUM_SN] = { 1093, /* "x509ExtAdmission" */ }; -#define NUM_LN 1193 +#define NUM_LN 1195 static const unsigned int ln_objs[NUM_LN] = { 363, /* "AD Time Stamping" */ 405, /* "ANSI X9.62" */ @@ -3784,7 +3788,9 @@ static const unsigned int ln_objs[NUM_LN] = { 92, /* "bf-ecb" */ 94, /* "bf-ofb" */ 1056, /* "blake2b512" */ + 1201, /* "blake2bmac" */ 1057, /* "blake2s256" */ + 1202, /* "blake2smac" */ 921, /* "brainpoolP160r1" */ 922, /* "brainpoolP160t1" */ 923, /* "brainpoolP192r1" */ @@ -3864,7 +3870,7 @@ static const unsigned int ln_objs[NUM_LN] = { 883, /* "certificateRevocationList" */ 1019, /* "chacha20" */ 1018, /* "chacha20-poly1305" */ - 1201, /* "ChaCha20-Poly1305-D" */ + 1203, /* "ChaCha20-Poly1305-D" */ 54, /* "challengePassword" */ 407, /* "characteristic-two-field" */ 395, /* "clearance" */ diff --git a/crypto/objects/obj_mac.num b/crypto/objects/obj_mac.num index c13c751d..94d033c1 100644 --- a/crypto/objects/obj_mac.num +++ b/crypto/objects/obj_mac.num @@ -1198,4 +1198,6 @@ kmac256 1197 aes_128_siv 1198 aes_192_siv 1199 aes_256_siv 1200 -chacha20_poly1305_draft 1201 +blake2bmac 1201 +blake2smac 1202 +chacha20_poly1305_draft 1203 diff --git a/crypto/objects/objects.txt b/crypto/objects/objects.txt index e5b288d9..21653d9b 100644 --- a/crypto/objects/objects.txt +++ b/crypto/objects/objects.txt @@ -17,7 +17,9 @@ iso 0 9797 3 4 : GMAC : gmac # There are no OIDs for these yet... : KMAC128 : kmac128 : KMAC256 : kmac256 - + : BLAKE2BMAC : blake2bmac + : BLAKE2SMAC : blake2smac + # HMAC OIDs identified-organization 6 1 5 5 8 1 1 : HMAC-MD5 : hmac-md5 identified-organization 6 1 5 5 8 1 2 : HMAC-SHA1 : hmac-sha1 diff --git a/crypto/pem/pem_info.c b/crypto/pem/pem_info.c index bfe1744f..ad1dba3f 100644 --- a/crypto/pem/pem_info.c +++ b/crypto/pem/pem_info.c @@ -297,7 +297,7 @@ int PEM_X509_INFO_write_bio(BIO *bp, X509_INFO *xi, EVP_CIPHER *enc, goto err; } - /* Create the right magic header stuff */ + /* Create the right magic header stuff */ buf[0] = '\0'; PEM_proc_type(buf, PEM_TYPE_ENCRYPTED); PEM_dek_info(buf, objstr, EVP_CIPHER_iv_length(enc), diff --git a/crypto/perlasm/ppc-xlate.pl b/crypto/perlasm/ppc-xlate.pl index 1c972a1e..e52f2f6e 100755 --- a/crypto/perlasm/ppc-xlate.pl +++ b/crypto/perlasm/ppc-xlate.pl @@ -273,6 +273,8 @@ my $mtvrwz = sub { my ($f, $vrt, $ra) = @_; " .long ".sprintf "0x%X",(31<<26)|($vrt<<21)|($ra<<16)|(243<<1)|1; }; +my $lvwzx_u = sub { vsxmem_op(@_, 12); }; # lxsiwzx +my $stvwx_u = sub { vsxmem_op(@_, 140); }; # stxsiwx # PowerISA 3.0 stuff my $maddhdu = sub { vfour(@_,49); }; diff --git a/crypto/poly1305/asm/poly1305-ppc.pl b/crypto/poly1305/asm/poly1305-ppc.pl index e9118ba1..9f15c0d0 100755 --- a/crypto/poly1305/asm/poly1305-ppc.pl +++ b/crypto/poly1305/asm/poly1305-ppc.pl @@ -8,10 +8,10 @@ # # ==================================================================== -# Written by Andy Polyakov for the OpenSSL -# project. The module is, however, dual licensed under OpenSSL and -# CRYPTOGAMS licenses depending on where you obtain it. For further -# details see http://www.openssl.org/~appro/cryptogams/. +# Written by Andy Polyakov, @dot-asm, initially for use in the OpenSSL +# project. The module is dual licensed under OpenSSL and CRYPTOGAMS +# licenses depending on where you obtain it. For further details see +# https://github.com/dot-asm/cryptogams/. # ==================================================================== # # This module implements Poly1305 hash for PowerPC. @@ -44,6 +44,13 @@ # # On side note, Power ISA 2.07 enables vector base 2^26 implementation, # and POWER8 might have capacity to break 1.0 cycle per byte barrier... +# +# January 2019 +# +# ... Unfortunately not:-( Estimate was a projection of ARM result, +# but ARM has vector multiply-n-add instruction, while PowerISA does +# not, not one usable in the context. Improvement is ~40% over -m64 +# result above and is ~1.43 on little-endian systems. $flavour = shift; @@ -99,6 +106,7 @@ $code.=<<___; std r0,0($ctx) # zero hash value std r0,8($ctx) std r0,16($ctx) + stw r0,24($ctx) # clear is_base2_26 $UCMP $inp,r0 beq- Lno_key @@ -140,6 +148,7 @@ Lno_key: .globl .poly1305_blocks .align 4 .poly1305_blocks: +Lpoly1305_blocks: srdi. $len,$len,4 beq- Labort @@ -238,60 +247,120 @@ Labort: .long 0 .byte 0,12,4,1,0x80,5,4,0 .size .poly1305_blocks,.-.poly1305_blocks +___ +{ +my ($h0,$h1,$h2,$h3,$h4,$t0) = map("r$_",(7..12)); +$code.=<<___; .globl .poly1305_emit -.align 4 +.align 5 .poly1305_emit: - ld $h0,0($ctx) # load hash - ld $h1,8($ctx) - ld $h2,16($ctx) - ld $padbit,0($nonce) # load nonce - ld $nonce,8($nonce) + lwz $h0,0($ctx) # load hash value base 2^26 + lwz $h1,4($ctx) + lwz $h2,8($ctx) + lwz $h3,12($ctx) + lwz $h4,16($ctx) + lwz r0,24($ctx) # is_base2_26 - addic $d0,$h0,5 # compare to modulus - addze $d1,$h1 - addze $d2,$h2 + sldi $h1,$h1,26 # base 2^26 -> base 2^64 + sldi $t0,$h2,52 + srdi $h2,$h2,12 + sldi $h3,$h3,14 + add $h0,$h0,$h1 + addc $h0,$h0,$t0 + sldi $t0,$h4,40 + srdi $h4,$h4,24 + adde $h1,$h2,$h3 + addc $h1,$h1,$t0 + addze $h2,$h4 - srdi $mask,$d2,2 # did it carry/borrow? - neg $mask,$mask + ld $h3,0($ctx) # load hash value base 2^64 + ld $h4,8($ctx) + ld $t0,16($ctx) + + neg r0,r0 + xor $h0,$h0,$h3 # choose between radixes + xor $h1,$h1,$h4 + xor $h2,$h2,$t0 + and $h0,$h0,r0 + and $h1,$h1,r0 + and $h2,$h2,r0 + xor $h0,$h0,$h3 + xor $h1,$h1,$h4 + xor $h2,$h2,$t0 + + addic $h3,$h0,5 # compare to modulus + addze $h4,$h1 + addze $t0,$h2 + + srdi $t0,$t0,2 # see if it carried/borrowed + neg $t0,$t0 + + andc $h0,$h0,$t0 + and $h3,$h3,$t0 + andc $h1,$h1,$t0 + and $h4,$h4,$t0 + or $h0,$h0,$h3 + or $h1,$h1,$h4 + + lwz $t0,4($nonce) + lwz $h2,12($nonce) + lwz $h3,0($nonce) + lwz $h4,8($nonce) + + insrdi $h3,$t0,32,0 + insrdi $h4,$h2,32,0 + + addc $h0,$h0,$h3 # accumulate nonce + adde $h1,$h1,$h4 + + addi $ctx,$mac,-1 + addi $mac,$mac,7 + + stbu $h0,1($ctx) # write [little-endian] result + srdi $h0,$h0,8 + stbu $h1,1($mac) + srdi $h1,$h1,8 + + stbu $h0,1($ctx) + srdi $h0,$h0,8 + stbu $h1,1($mac) + srdi $h1,$h1,8 + + stbu $h0,1($ctx) + srdi $h0,$h0,8 + stbu $h1,1($mac) + srdi $h1,$h1,8 + + stbu $h0,1($ctx) + srdi $h0,$h0,8 + stbu $h1,1($mac) + srdi $h1,$h1,8 + + stbu $h0,1($ctx) + srdi $h0,$h0,8 + stbu $h1,1($mac) + srdi $h1,$h1,8 + + stbu $h0,1($ctx) + srdi $h0,$h0,8 + stbu $h1,1($mac) + srdi $h1,$h1,8 + + stbu $h0,1($ctx) + srdi $h0,$h0,8 + stbu $h1,1($mac) + srdi $h1,$h1,8 + + stbu $h0,1($ctx) + stbu $h1,1($mac) - andc $h0,$h0,$mask - and $d0,$d0,$mask - andc $h1,$h1,$mask - and $d1,$d1,$mask - or $h0,$h0,$d0 - or $h1,$h1,$d1 -___ -$code.=<<___ if (!$LITTLE_ENDIAN); - rotldi $padbit,$padbit,32 # flip nonce words - rotldi $nonce,$nonce,32 -___ -$code.=<<___; - addc $h0,$h0,$padbit # accumulate nonce - adde $h1,$h1,$nonce -___ -$code.=<<___ if ($LITTLE_ENDIAN); - std $h0,0($mac) # write result - std $h1,8($mac) -___ -$code.=<<___ if (!$LITTLE_ENDIAN); - extrdi r0,$h0,32,0 - li $d0,4 - stwbrx $h0,0,$mac # write result - extrdi $h0,$h1,32,0 - li $d1,8 - stwbrx r0,$d0,$mac - li $d2,12 - stwbrx $h1,$d1,$mac - stwbrx $h0,$d2,$mac -___ -$code.=<<___; blr .long 0 .byte 0,12,0x14,0,0,0,3,0 .size .poly1305_emit,.-.poly1305_emit ___ - } else { +} } else { ############################################################################### # base 2^32 implementation @@ -309,6 +378,7 @@ $code.=<<___; stw r0,8($ctx) stw r0,12($ctx) stw r0,16($ctx) + stw r0,24($ctx) # clear is_base2_26 $UCMP $inp,r0 beq- Lno_key @@ -353,6 +423,7 @@ Lno_key: .globl .poly1305_blocks .align 4 .poly1305_blocks: +Lpoly1305_blocks: srwi. $len,$len,4 beq- Labort @@ -560,17 +631,389 @@ Labort: .long 0 .byte 0,12,4,1,0x80,18,4,0 .size .poly1305_blocks,.-.poly1305_blocks +___ +{ +my ($h0,$h1,$h2,$h3,$h4,$t0,$t1) = map("r$_",(6..12)); +$code.=<<___; .globl .poly1305_emit -.align 4 +.align 5 .poly1305_emit: - $STU $sp,-$FRAME($sp) + lwz r0,24($ctx) # is_base2_26 + lwz $h0,0($ctx) # load hash value + lwz $h1,4($ctx) + lwz $h2,8($ctx) + lwz $h3,12($ctx) + lwz $h4,16($ctx) + cmplwi r0,0 + beq Lemit_base2_32 + + slwi $t0,$h1,26 # base 2^26 -> base 2^32 + srwi $h1,$h1,6 + slwi $t1,$h2,20 + srwi $h2,$h2,12 + addc $h0,$h0,$t0 + slwi $t0,$h3,14 + srwi $h3,$h3,18 + adde $h1,$h1,$t1 + slwi $t1,$h4,8 + srwi $h4,$h4,24 + adde $h2,$h2,$t0 + adde $h3,$h3,$t1 + addze $h4,$h4 + +Lemit_base2_32: + addic r0,$h0,5 # compare to modulus + addze r0,$h1 + addze r0,$h2 + addze r0,$h3 + addze r0,$h4 + + srwi r0,r0,2 # see if it carried/borrowed + neg r0,r0 + andi. r0,r0,5 + + addc $h0,$h0,r0 + lwz r0,0($nonce) + addze $h1,$h1 + lwz $t0,4($nonce) + addze $h2,$h2 + lwz $t1,8($nonce) + addze $h3,$h3 + lwz $h4,12($nonce) + + addc $h0,$h0,r0 # accumulate nonce + adde $h1,$h1,$t0 + adde $h2,$h2,$t1 + adde $h3,$h3,$h4 + + addi $ctx,$mac,-1 + addi $mac,$mac,7 + + stbu $h0,1($ctx) # write [little-endian] result + srwi $h0,$h0,8 + stbu $h2,1($mac) + srwi $h2,$h2,8 + + stbu $h0,1($ctx) + srwi $h0,$h0,8 + stbu $h2,1($mac) + srwi $h2,$h2,8 + + stbu $h0,1($ctx) + srwi $h0,$h0,8 + stbu $h2,1($mac) + srwi $h2,$h2,8 + + stbu $h0,1($ctx) + stbu $h2,1($mac) + + stbu $h1,1($ctx) + srwi $h1,$h1,8 + stbu $h3,1($mac) + srwi $h3,$h3,8 + + stbu $h1,1($ctx) + srwi $h1,$h1,8 + stbu $h3,1($mac) + srwi $h3,$h3,8 + + stbu $h1,1($ctx) + srwi $h1,$h1,8 + stbu $h3,1($mac) + srwi $h3,$h3,8 + + stbu $h1,1($ctx) + stbu $h3,1($mac) + + blr + .long 0 + .byte 0,12,0x14,0,0,0,3,0 +.size .poly1305_emit,.-.poly1305_emit +___ +} } +{{{ +######################################################################## +# PowerISA 2.07/VSX section # +######################################################################## + +my $LOCALS= 6*$SIZE_T; +my $VSXFRAME = $LOCALS + 6*$SIZE_T; + $VSXFRAME += 128; # local variables + $VSXFRAME += 13*16; # v20-v31 offload + +my $BIG_ENDIAN = ($flavour !~ /le/) ? 4 : 0; + +######################################################################## +# Layout of opaque area is following: +# +# unsigned __int32 h[5]; # current hash value base 2^26 +# unsigned __int32 pad; +# unsigned __int32 is_base2_26, pad; +# unsigned __int64 r[2]; # key value base 2^64 +# struct { unsigned __int32 r^2, r^4, r^1, r^3; } r[9]; +# +# where r^n are base 2^26 digits of powers of multiplier key. There are +# 5 digits, but last four are interleaved with multiples of 5, totalling +# in 9 elements: r0, r1, 5*r1, r2, 5*r2, r3, 5*r3, r4, 5*r4. Order of +# powers is as they appear in register, not memory. + +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) = ($R1, $S1, $R2, $S2); +my ($ACC0, $ACC1, $ACC2, $ACC3, $ACC4) = map("v$_",(15..19)); +my ($T0, $T1, $T2, $T3, $T4) = map("v$_",(20..24)); +my ($_26,$_4,$_40,$_14,$mask26,$padbits,$I2perm) = map("v$_",(25..31)); +my ($x00,$x60,$x70,$x10,$x20,$x30,$x40,$x50) = (0, map("r$_",(7,8,27..31))); +my ($ctx_,$_ctx,$const) = map("r$_",(10..12)); + + if ($flavour =~ /64/) { +############################################################################### +# setup phase of poly1305_blocks_vsx is different on 32- and 64-bit platforms, +# but the base 2^26 computational part is same... + +my ($h0,$h1,$h2,$d0,$d1,$d2, $r0,$r1,$s1, $t0,$t1) = map("r$_",(6..11,27..31)); +my $mask = "r0"; + +$code.=<<___; +.globl .poly1305_blocks_vsx +.align 5 +.poly1305_blocks_vsx: + lwz r7,24($ctx) # is_base2_26 + cmpldi $len,128 + bge __poly1305_blocks_vsx + + neg r0,r7 # is_base2_26 as mask + lwz r7,0($ctx) # load hash base 2^26 + lwz r8,4($ctx) + lwz r9,8($ctx) + lwz r10,12($ctx) + lwz r11,16($ctx) + + sldi r8,r8,26 # base 2^26 -> base 2^64 + sldi r12,r9,52 + add r7,r7,r8 + srdi r9,r9,12 + sldi r10,r10,14 + addc r7,r7,r12 + sldi r8,r11,40 + adde r9,r9,r10 + srdi r11,r11,24 + addc r9,r9,r8 + addze r11,r11 + + ld r8,0($ctx) # load hash base 2^64 + ld r10,8($ctx) + ld r12,16($ctx) + + xor r7,r7,r8 # select between radixes + xor r9,r9,r10 + xor r11,r11,r12 + and r7,r7,r0 + and r9,r9,r0 + and r11,r11,r0 + xor r7,r7,r8 + xor r9,r9,r10 + xor r11,r11,r12 + + li r0,0 + std r7,0($ctx) # store hash base 2^64 + std r9,8($ctx) + std r11,16($ctx) + stw r0,24($ctx) # clear is_base2_26 + + b Lpoly1305_blocks + .long 0 + .byte 0,12,0x14,0,0,0,4,0 +.size .poly1305_blocks_vsx,.-.poly1305_blocks_vsx + +.align 5 +__poly1305_mul: + mulld $d0,$h0,$r0 # h0*r0 + mulhdu $d1,$h0,$r0 + + mulld $t0,$h1,$s1 # h1*5*r1 + mulhdu $t1,$h1,$s1 + addc $d0,$d0,$t0 + adde $d1,$d1,$t1 + + mulld $t0,$h0,$r1 # h0*r1 + mulhdu $d2,$h0,$r1 + addc $d1,$d1,$t0 + addze $d2,$d2 + + mulld $t0,$h1,$r0 # h1*r0 + mulhdu $t1,$h1,$r0 + addc $d1,$d1,$t0 + adde $d2,$d2,$t1 + + mulld $t0,$h2,$s1 # h2*5*r1 + mulld $t1,$h2,$r0 # h2*r0 + addc $d1,$d1,$t0 + adde $d2,$d2,$t1 + + andc $t0,$d2,$mask # final reduction step + and $h2,$d2,$mask + srdi $t1,$t0,2 + add $t0,$t0,$t1 + addc $h0,$d0,$t0 + addze $h1,$d1 + addze $h2,$h2 + + blr + .long 0 + .byte 0,12,0x14,0,0,0,0,0 +.size __poly1305_mul,.-__poly1305_mul + +.align 5 +__poly1305_splat: + extrdi $d0,$h0,26,38 + extrdi $d1,$h0,26,12 + stw $d0,0x00($t1) + + extrdi $d2,$h0,12,0 + slwi $d0,$d1,2 + stw $d1,0x10($t1) + add $d0,$d0,$d1 # * 5 + stw $d0,0x20($t1) + + insrdi $d2,$h1,14,38 + slwi $d0,$d2,2 + stw $d2,0x30($t1) + add $d0,$d0,$d2 # * 5 + stw $d0,0x40($t1) + + extrdi $d1,$h1,26,24 + extrdi $d2,$h1,24,0 + slwi $d0,$d1,2 + stw $d1,0x50($t1) + add $d0,$d0,$d1 # * 5 + stw $d0,0x60($t1) + + insrdi $d2,$h2,3,37 + slwi $d0,$d2,2 + stw $d2,0x70($t1) + add $d0,$d0,$d2 # * 5 + stw $d0,0x80($t1) + + blr + .long 0 + .byte 0,12,0x14,0,0,0,0,0 +.size __poly1305_splat,.-__poly1305_splat + +.align 5 +__poly1305_blocks_vsx: + $STU $sp,-$VSXFRAME($sp) mflr r0 - $PUSH r28,`$FRAME-$SIZE_T*4`($sp) - $PUSH r29,`$FRAME-$SIZE_T*3`($sp) - $PUSH r30,`$FRAME-$SIZE_T*2`($sp) - $PUSH r31,`$FRAME-$SIZE_T*1`($sp) - $PUSH r0,`$FRAME+$LRSAVE`($sp) + li r10,`15+$LOCALS+128` + li r11,`31+$LOCALS+128` + mfspr r12,256 + stvx v20,r10,$sp + addi r10,r10,32 + stvx v21,r11,$sp + addi r11,r11,32 + stvx v22,r10,$sp + addi r10,r10,32 + stvx v23,r10,$sp + addi r10,r10,32 + stvx v24,r11,$sp + addi r11,r11,32 + stvx v25,r10,$sp + addi r10,r10,32 + stvx v26,r10,$sp + addi r10,r10,32 + stvx v27,r11,$sp + addi r11,r11,32 + stvx v28,r10,$sp + addi r10,r10,32 + stvx v29,r11,$sp + addi r11,r11,32 + stvx v30,r10,$sp + stvx v31,r11,$sp + stw r12,`$VSXFRAME-$SIZE_T*5-4`($sp)# save vrsave + li r12,-1 + mtspr 256,r12 # preserve all AltiVec registers + $PUSH r27,`$VSXFRAME-$SIZE_T*5`($sp) + $PUSH r28,`$VSXFRAME-$SIZE_T*4`($sp) + $PUSH r29,`$VSXFRAME-$SIZE_T*3`($sp) + $PUSH r30,`$VSXFRAME-$SIZE_T*2`($sp) + $PUSH r31,`$VSXFRAME-$SIZE_T*1`($sp) + $PUSH r0,`$VSXFRAME+$LRSAVE`($sp) + + bl LPICmeup + + li $x10,0x10 + li $x20,0x20 + li $x30,0x30 + li $x40,0x40 + li $x50,0x50 + lvx_u $mask26,$x00,$const + lvx_u $_26,$x10,$const + lvx_u $_40,$x20,$const + lvx_u $I2perm,$x30,$const + lvx_u $padbits,$x40,$const + + cmplwi r7,0 # is_base2_26? + bne Lskip_init_vsx + + ld $r0,32($ctx) # load key base 2^64 + ld $r1,40($ctx) + srdi $s1,$r1,2 + li $mask,3 + add $s1,$s1,$r1 # s1 = r1 + r1>>2 + + mr $h0,$r0 # "calculate" r^1 + mr $h1,$r1 + li $h2,0 + addi $t1,$ctx,`48+(12^$BIG_ENDIAN)` + bl __poly1305_splat + + bl __poly1305_mul # caclulate r^2 + addi $t1,$ctx,`48+(4^$BIG_ENDIAN)` + bl __poly1305_splat + + bl __poly1305_mul # caclulate r^3 + addi $t1,$ctx,`48+(8^$BIG_ENDIAN)` + bl __poly1305_splat + + bl __poly1305_mul # caclulate r^4 + addi $t1,$ctx,`48+(0^$BIG_ENDIAN)` + bl __poly1305_splat + + ld $h0,0($ctx) # load hash + ld $h1,8($ctx) + ld $h2,16($ctx) + + extrdi $d0,$h0,26,38 # base 2^64 -> base 2^26 + extrdi $d1,$h0,26,12 + extrdi $d2,$h0,12,0 + mtvrwz $H0,$d0 + insrdi $d2,$h1,14,38 + mtvrwz $H1,$d1 + extrdi $d1,$h1,26,24 + mtvrwz $H2,$d2 + extrdi $d2,$h1,24,0 + mtvrwz $H3,$d1 + insrdi $d2,$h2,3,37 + mtvrwz $H4,$d2 +___ + } else { +############################################################################### +# 32-bit initialization + +my ($h0,$h1,$h2,$h3,$h4,$t0,$t1) = map("r$_",(7..11,0,12)); +my ($R3,$S3,$R4,$S4)=($I1,$I2,$I3,$I4); + +$code.=<<___; +.globl .poly1305_blocks_vsx +.align 5 +.poly1305_blocks_vsx: + lwz r7,24($ctx) # is_base2_26 + cmplwi $len,128 + bge __poly1305_blocks_vsx + cmplwi r7,0 + beq Lpoly1305_blocks lwz $h0,0($ctx) # load hash lwz $h1,4($ctx) @@ -578,68 +1021,957 @@ Labort: lwz $h3,12($ctx) lwz $h4,16($ctx) - addic $d0,$h0,5 # compare to modulus - addze $d1,$h1 - addze $d2,$h2 - addze $d3,$h3 - addze $mask,$h4 + slwi $t0,$h1,26 # base 2^26 -> base 2^32 + srwi $h1,$h1,6 + slwi $t1,$h2,20 + srwi $h2,$h2,12 + addc $h0,$h0,$t0 + slwi $t0,$h3,14 + srwi $h3,$h3,18 + adde $h1,$h1,$t1 + slwi $t1,$h4,8 + srwi $h4,$h4,24 + adde $h2,$h2,$t0 + li $t0,0 + adde $h3,$h3,$t1 + addze $h4,$h4 - srwi $mask,$mask,2 # did it carry/borrow? - neg $mask,$mask + stw $h0,0($ctx) # store hash base 2^32 + stw $h1,4($ctx) + stw $h2,8($ctx) + stw $h3,12($ctx) + stw $h4,16($ctx) + stw $t0,24($ctx) # clear is_base2_26 - andc $h0,$h0,$mask - and $d0,$d0,$mask - andc $h1,$h1,$mask - and $d1,$d1,$mask - or $h0,$h0,$d0 - lwz $d0,0($nonce) # load nonce - andc $h2,$h2,$mask - and $d2,$d2,$mask - or $h1,$h1,$d1 - lwz $d1,4($nonce) - andc $h3,$h3,$mask - and $d3,$d3,$mask - or $h2,$h2,$d2 - lwz $d2,8($nonce) - or $h3,$h3,$d3 - lwz $d3,12($nonce) + b Lpoly1305_blocks + .long 0 + .byte 0,12,0x14,0,0,0,4,0 +.size .poly1305_blocks_vsx,.-.poly1305_blocks_vsx + +.align 5 +__poly1305_mul: + vmulouw $ACC0,$H0,$R0 + vmulouw $ACC1,$H1,$R0 + vmulouw $ACC2,$H2,$R0 + vmulouw $ACC3,$H3,$R0 + vmulouw $ACC4,$H4,$R0 + + vmulouw $T0,$H4,$S1 + vaddudm $ACC0,$ACC0,$T0 + vmulouw $T0,$H0,$R1 + vaddudm $ACC1,$ACC1,$T0 + vmulouw $T0,$H1,$R1 + vaddudm $ACC2,$ACC2,$T0 + vmulouw $T0,$H2,$R1 + vaddudm $ACC3,$ACC3,$T0 + vmulouw $T0,$H3,$R1 + vaddudm $ACC4,$ACC4,$T0 + + vmulouw $T0,$H3,$S2 + vaddudm $ACC0,$ACC0,$T0 + vmulouw $T0,$H4,$S2 + vaddudm $ACC1,$ACC1,$T0 + vmulouw $T0,$H0,$R2 + vaddudm $ACC2,$ACC2,$T0 + vmulouw $T0,$H1,$R2 + vaddudm $ACC3,$ACC3,$T0 + vmulouw $T0,$H2,$R2 + vaddudm $ACC4,$ACC4,$T0 + + vmulouw $T0,$H2,$S3 + vaddudm $ACC0,$ACC0,$T0 + vmulouw $T0,$H3,$S3 + vaddudm $ACC1,$ACC1,$T0 + vmulouw $T0,$H4,$S3 + vaddudm $ACC2,$ACC2,$T0 + vmulouw $T0,$H0,$R3 + vaddudm $ACC3,$ACC3,$T0 + vmulouw $T0,$H1,$R3 + vaddudm $ACC4,$ACC4,$T0 + + vmulouw $T0,$H1,$S4 + vaddudm $ACC0,$ACC0,$T0 + vmulouw $T0,$H2,$S4 + vaddudm $ACC1,$ACC1,$T0 + vmulouw $T0,$H3,$S4 + vaddudm $ACC2,$ACC2,$T0 + vmulouw $T0,$H4,$S4 + vaddudm $ACC3,$ACC3,$T0 + vmulouw $T0,$H0,$R4 + vaddudm $ACC4,$ACC4,$T0 + + ################################################################ + # lazy reduction + + vspltisb $T0,2 + vsrd $H4,$ACC3,$_26 + vsrd $H1,$ACC0,$_26 + vand $H3,$ACC3,$mask26 + vand $H0,$ACC0,$mask26 + vaddudm $H4,$H4,$ACC4 # h3 -> h4 + vaddudm $H1,$H1,$ACC1 # h0 -> h1 + + vsrd $ACC4,$H4,$_26 + vsrd $ACC1,$H1,$_26 + vand $H4,$H4,$mask26 + vand $H1,$H1,$mask26 + vaddudm $H0,$H0,$ACC4 + vaddudm $H2,$ACC2,$ACC1 # h1 -> h2 + + vsld $ACC4,$ACC4,$T0 # <<2 + vsrd $ACC2,$H2,$_26 + vand $H2,$H2,$mask26 + vaddudm $H0,$H0,$ACC4 # h4 -> h0 + vaddudm $H3,$H3,$ACC2 # h2 -> h3 + + vsrd $ACC0,$H0,$_26 + vsrd $ACC3,$H3,$_26 + vand $H0,$H0,$mask26 + vand $H3,$H3,$mask26 + vaddudm $H1,$H1,$ACC0 # h0 -> h1 + vaddudm $H4,$H4,$ACC3 # h3 -> h4 - addc $h0,$h0,$d0 # accumulate nonce - adde $h1,$h1,$d1 - adde $h2,$h2,$d2 - adde $h3,$h3,$d3 -___ -$code.=<<___ if ($LITTLE_ENDIAN); - stw $h0,0($mac) # write result - stw $h1,4($mac) - stw $h2,8($mac) - stw $h3,12($mac) -___ -$code.=<<___ if (!$LITTLE_ENDIAN); - li $d1,4 - stwbrx $h0,0,$mac # write result - li $d2,8 - stwbrx $h1,$d1,$mac - li $d3,12 - stwbrx $h2,$d2,$mac - stwbrx $h3,$d3,$mac -___ -$code.=<<___; - $POP r28,`$FRAME-$SIZE_T*4`($sp) - $POP r29,`$FRAME-$SIZE_T*3`($sp) - $POP r30,`$FRAME-$SIZE_T*2`($sp) - $POP r31,`$FRAME-$SIZE_T*1`($sp) - addi $sp,$sp,$FRAME blr .long 0 - .byte 0,12,4,1,0x80,4,3,0 -.size .poly1305_emit,.-.poly1305_emit + .byte 0,12,0x14,0,0,0,0,0 +.size __poly1305_mul,.-__poly1305_mul + +.align 5 +__poly1305_blocks_vsx: + $STU $sp,-$VSXFRAME($sp) + mflr r0 + li r10,`15+$LOCALS+128` + li r11,`31+$LOCALS+128` + mfspr r12,256 + stvx v20,r10,$sp + addi r10,r10,32 + stvx v21,r11,$sp + addi r11,r11,32 + stvx v22,r10,$sp + addi r10,r10,32 + stvx v23,r10,$sp + addi r10,r10,32 + stvx v24,r11,$sp + addi r11,r11,32 + stvx v25,r10,$sp + addi r10,r10,32 + stvx v26,r10,$sp + addi r10,r10,32 + stvx v27,r11,$sp + addi r11,r11,32 + stvx v28,r10,$sp + addi r10,r10,32 + stvx v29,r11,$sp + addi r11,r11,32 + stvx v30,r10,$sp + stvx v31,r11,$sp + stw r12,`$VSXFRAME-$SIZE_T*5-4`($sp)# save vrsave + li r12,-1 + mtspr 256,r12 # preserve all AltiVec registers + $PUSH r27,`$VSXFRAME-$SIZE_T*5`($sp) + $PUSH r28,`$VSXFRAME-$SIZE_T*4`($sp) + $PUSH r29,`$VSXFRAME-$SIZE_T*3`($sp) + $PUSH r30,`$VSXFRAME-$SIZE_T*2`($sp) + $PUSH r31,`$VSXFRAME-$SIZE_T*1`($sp) + $PUSH r0,`$VSXFRAME+$LRSAVE`($sp) + + bl LPICmeup + + li $x10,0x10 + li $x20,0x20 + li $x30,0x30 + li $x40,0x40 + li $x50,0x50 + lvx_u $mask26,$x00,$const + lvx_u $_26,$x10,$const + lvx_u $_40,$x20,$const + lvx_u $I2perm,$x30,$const + lvx_u $padbits,$x40,$const + + cmplwi r7,0 # is_base2_26? + bne Lskip_init_vsx + + lwz $h1,32($ctx) # load key base 2^32 + lwz $h2,36($ctx) + lwz $h3,40($ctx) + lwz $h4,44($ctx) + + extrwi $h0,$h1,26,6 # base 2^32 -> base 2^26 + extrwi $h1,$h1,6,0 + insrwi $h1,$h2,20,6 + extrwi $h2,$h2,12,0 + insrwi $h2,$h3,14,6 + extrwi $h3,$h3,18,0 + insrwi $h3,$h4,8,6 + extrwi $h4,$h4,24,0 + + mtvrwz $R0,$h0 + slwi $h0,$h1,2 + mtvrwz $R1,$h1 + add $h1,$h1,$h0 + mtvrwz $S1,$h1 + slwi $h1,$h2,2 + mtvrwz $R2,$h2 + add $h2,$h2,$h1 + mtvrwz $S2,$h2 + slwi $h2,$h3,2 + mtvrwz $R3,$h3 + add $h3,$h3,$h2 + mtvrwz $S3,$h3 + slwi $h3,$h4,2 + mtvrwz $R4,$h4 + add $h4,$h4,$h3 + mtvrwz $S4,$h4 + + vmr $H0,$R0 + vmr $H1,$R1 + vmr $H2,$R2 + vmr $H3,$R3 + vmr $H4,$R4 + + bl __poly1305_mul # r^1:- * r^1:- + + vpermdi $R0,$H0,$R0,0b00 + vpermdi $R1,$H1,$R1,0b00 + vpermdi $R2,$H2,$R2,0b00 + vpermdi $R3,$H3,$R3,0b00 + vpermdi $R4,$H4,$R4,0b00 + vpermdi $H0,$H0,$H0,0b00 + vpermdi $H1,$H1,$H1,0b00 + vpermdi $H2,$H2,$H2,0b00 + vpermdi $H3,$H3,$H3,0b00 + vpermdi $H4,$H4,$H4,0b00 + vsld $S1,$R1,$T0 # <<2 + vsld $S2,$R2,$T0 + vsld $S3,$R3,$T0 + vsld $S4,$R4,$T0 + vaddudm $S1,$S1,$R1 + vaddudm $S2,$S2,$R2 + vaddudm $S3,$S3,$R3 + vaddudm $S4,$S4,$R4 + + bl __poly1305_mul # r^2:r^2 * r^2:r^1 + + addi $h0,$ctx,0x60 + lwz $h1,0($ctx) # load hash + lwz $h2,4($ctx) + lwz $h3,8($ctx) + lwz $h4,12($ctx) + lwz $t0,16($ctx) + + vmrgow $R0,$R0,$H0 # r^2:r^4:r^1:r^3 + vmrgow $R1,$R1,$H1 + vmrgow $R2,$R2,$H2 + vmrgow $R3,$R3,$H3 + vmrgow $R4,$R4,$H4 + vslw $S1,$R1,$T0 # <<2 + vslw $S2,$R2,$T0 + vslw $S3,$R3,$T0 + vslw $S4,$R4,$T0 + vadduwm $S1,$S1,$R1 + vadduwm $S2,$S2,$R2 + vadduwm $S3,$S3,$R3 + vadduwm $S4,$S4,$R4 + + stvx_u $R0,$x30,$ctx + stvx_u $R1,$x40,$ctx + stvx_u $S1,$x50,$ctx + stvx_u $R2,$x00,$h0 + stvx_u $S2,$x10,$h0 + stvx_u $R3,$x20,$h0 + stvx_u $S3,$x30,$h0 + stvx_u $R4,$x40,$h0 + stvx_u $S4,$x50,$h0 + + extrwi $h0,$h1,26,6 # base 2^32 -> base 2^26 + extrwi $h1,$h1,6,0 + mtvrwz $H0,$h0 + insrwi $h1,$h2,20,6 + extrwi $h2,$h2,12,0 + mtvrwz $H1,$h1 + insrwi $h2,$h3,14,6 + extrwi $h3,$h3,18,0 + mtvrwz $H2,$h2 + insrwi $h3,$h4,8,6 + extrwi $h4,$h4,24,0 + mtvrwz $H3,$h3 + insrwi $h4,$t0,3,5 + mtvrwz $H4,$h4 ___ } $code.=<<___; -.asciz "Poly1305 for PPC, CRYPTOGAMS by " + li r0,1 + stw r0,24($ctx) # set is_base2_26 + b Loaded_vsx + +.align 4 +Lskip_init_vsx: + li $x10,4 + li $x20,8 + li $x30,12 + li $x40,16 + lvwzx_u $H0,$x00,$ctx + lvwzx_u $H1,$x10,$ctx + lvwzx_u $H2,$x20,$ctx + lvwzx_u $H3,$x30,$ctx + lvwzx_u $H4,$x40,$ctx + +Loaded_vsx: + li $x10,0x10 + li $x20,0x20 + li $x30,0x30 + li $x40,0x40 + li $x50,0x50 + li $x60,0x60 + li $x70,0x70 + addi $ctx_,$ctx,64 # &ctx->r[1] + addi $_ctx,$sp,`$LOCALS+15` # &ctx->r[1], r^2:r^4 shadow + + vxor $T0,$T0,$T0 # ensure second half is zero + vpermdi $H0,$H0,$T0,0b00 + vpermdi $H1,$H1,$T0,0b00 + vpermdi $H2,$H2,$T0,0b00 + vpermdi $H3,$H3,$T0,0b00 + vpermdi $H4,$H4,$T0,0b00 + + be?lvx_u $_4,$x50,$const # byte swap mask + lvx_u $T1,$x00,$inp # load first input block + lvx_u $T2,$x10,$inp + lvx_u $T3,$x20,$inp + lvx_u $T4,$x30,$inp + be?vperm $T1,$T1,$T1,$_4 + be?vperm $T2,$T2,$T2,$_4 + be?vperm $T3,$T3,$T3,$_4 + be?vperm $T4,$T4,$T4,$_4 + + vpermdi $I0,$T1,$T2,0b00 # smash input to base 2^26 + vspltisb $_4,4 + vperm $I2,$T1,$T2,$I2perm # 0x...0e0f0001...1e1f1011 + vspltisb $_14,14 + vpermdi $I3,$T1,$T2,0b11 + + vsrd $I1,$I0,$_26 + vsrd $I2,$I2,$_4 + vsrd $I4,$I3,$_40 + vsrd $I3,$I3,$_14 + vand $I0,$I0,$mask26 + vand $I1,$I1,$mask26 + vand $I2,$I2,$mask26 + vand $I3,$I3,$mask26 + + vpermdi $T1,$T3,$T4,0b00 + vperm $T2,$T3,$T4,$I2perm # 0x...0e0f0001...1e1f1011 + vpermdi $T3,$T3,$T4,0b11 + + vsrd $T0,$T1,$_26 + vsrd $T2,$T2,$_4 + vsrd $T4,$T3,$_40 + vsrd $T3,$T3,$_14 + vand $T1,$T1,$mask26 + vand $T0,$T0,$mask26 + vand $T2,$T2,$mask26 + vand $T3,$T3,$mask26 + + # inp[2]:inp[0]:inp[3]:inp[1] + vmrgow $I4,$T4,$I4 + vmrgow $I0,$T1,$I0 + vmrgow $I1,$T0,$I1 + vmrgow $I2,$T2,$I2 + vmrgow $I3,$T3,$I3 + vor $I4,$I4,$padbits + + lvx_splt $R0,$x30,$ctx # taking lvx_vsplt out of loop + lvx_splt $R1,$x00,$ctx_ # gives ~8% improvement + lvx_splt $S1,$x10,$ctx_ + lvx_splt $R2,$x20,$ctx_ + lvx_splt $S2,$x30,$ctx_ + lvx_splt $T1,$x40,$ctx_ + lvx_splt $T2,$x50,$ctx_ + lvx_splt $T3,$x60,$ctx_ + lvx_splt $T4,$x70,$ctx_ + stvx $R1,$x00,$_ctx + stvx $S1,$x10,$_ctx + stvx $R2,$x20,$_ctx + stvx $S2,$x30,$_ctx + stvx $T1,$x40,$_ctx + stvx $T2,$x50,$_ctx + stvx $T3,$x60,$_ctx + stvx $T4,$x70,$_ctx + + addi $inp,$inp,0x40 + addi $const,$const,0x50 + addi r0,$len,-64 + srdi r0,r0,6 + mtctr r0 + b Loop_vsx + +.align 4 +Loop_vsx: + ################################################################ + ## ((inp[0]*r^4+inp[2]*r^2+inp[4])*r^4+inp[6]*r^2 + ## ((inp[1]*r^4+inp[3]*r^2+inp[5])*r^3+inp[7]*r + ## \___________________/ + ## + ## Note that we start with inp[2:3]*r^2. This is because it + ## doesn't depend on reduction in previous iteration. + ################################################################ + ## d4 = h4*r0 + h3*r1 + h2*r2 + h1*r3 + h0*r4 + ## d3 = h3*r0 + h2*r1 + h1*r2 + h0*r3 + h4*5*r4 + ## d2 = h2*r0 + h1*r1 + h0*r2 + h4*5*r3 + h3*5*r4 + ## d1 = h1*r0 + h0*r1 + h4*5*r2 + h3*5*r3 + h2*5*r4 + ## d0 = h0*r0 + h4*5*r1 + h3*5*r2 + h2*5*r3 + h1*5*r4 + + vmuleuw $ACC0,$I0,$R0 + vmuleuw $ACC1,$I0,$R1 + vmuleuw $ACC2,$I0,$R2 + vmuleuw $ACC3,$I1,$R2 + + vmuleuw $T0,$I1,$R0 + vaddudm $ACC1,$ACC1,$T0 + vmuleuw $T0,$I1,$R1 + vaddudm $ACC2,$ACC2,$T0 + vmuleuw $ACC4,$I2,$R2 + vmuleuw $T0,$I4,$S1 + vaddudm $ACC0,$ACC0,$T0 + vmuleuw $T0,$I2,$R1 + vaddudm $ACC3,$ACC3,$T0 + lvx $S3,$x50,$_ctx + vmuleuw $T0,$I3,$R1 + vaddudm $ACC4,$ACC4,$T0 + lvx $R3,$x40,$_ctx + + vaddudm $H2,$H2,$I2 + vaddudm $H0,$H0,$I0 + vaddudm $H3,$H3,$I3 + vaddudm $H1,$H1,$I1 + vaddudm $H4,$H4,$I4 + + vmuleuw $T0,$I3,$S2 + vaddudm $ACC0,$ACC0,$T0 + vmuleuw $T0,$I4,$S2 + vaddudm $ACC1,$ACC1,$T0 + vmuleuw $T0,$I2,$R0 + vaddudm $ACC2,$ACC2,$T0 + vmuleuw $T0,$I3,$R0 + vaddudm $ACC3,$ACC3,$T0 + lvx $S4,$x70,$_ctx + vmuleuw $T0,$I4,$R0 + vaddudm $ACC4,$ACC4,$T0 + lvx $R4,$x60,$_ctx + + vmuleuw $T0,$I2,$S3 + vaddudm $ACC0,$ACC0,$T0 + vmuleuw $T0,$I3,$S3 + vaddudm $ACC1,$ACC1,$T0 + vmuleuw $T0,$I4,$S3 + vaddudm $ACC2,$ACC2,$T0 + vmuleuw $T0,$I0,$R3 + vaddudm $ACC3,$ACC3,$T0 + vmuleuw $T0,$I1,$R3 + vaddudm $ACC4,$ACC4,$T0 + + be?lvx_u $_4,$x00,$const # byte swap mask + lvx_u $T1,$x00,$inp # load next input block + lvx_u $T2,$x10,$inp + lvx_u $T3,$x20,$inp + lvx_u $T4,$x30,$inp + be?vperm $T1,$T1,$T1,$_4 + be?vperm $T2,$T2,$T2,$_4 + be?vperm $T3,$T3,$T3,$_4 + be?vperm $T4,$T4,$T4,$_4 + + vmuleuw $T0,$I1,$S4 + vaddudm $ACC0,$ACC0,$T0 + vmuleuw $T0,$I2,$S4 + vaddudm $ACC1,$ACC1,$T0 + vmuleuw $T0,$I3,$S4 + vaddudm $ACC2,$ACC2,$T0 + vmuleuw $T0,$I4,$S4 + vaddudm $ACC3,$ACC3,$T0 + vmuleuw $T0,$I0,$R4 + vaddudm $ACC4,$ACC4,$T0 + + vpermdi $I0,$T1,$T2,0b00 # smash input to base 2^26 + vspltisb $_4,4 + vperm $I2,$T1,$T2,$I2perm # 0x...0e0f0001...1e1f1011 + vpermdi $I3,$T1,$T2,0b11 + + # (hash + inp[0:1]) * r^4 + vmulouw $T0,$H0,$R0 + vaddudm $ACC0,$ACC0,$T0 + vmulouw $T0,$H1,$R0 + vaddudm $ACC1,$ACC1,$T0 + vmulouw $T0,$H2,$R0 + vaddudm $ACC2,$ACC2,$T0 + vmulouw $T0,$H3,$R0 + vaddudm $ACC3,$ACC3,$T0 + vmulouw $T0,$H4,$R0 + vaddudm $ACC4,$ACC4,$T0 + + vpermdi $T1,$T3,$T4,0b00 + vperm $T2,$T3,$T4,$I2perm # 0x...0e0f0001...1e1f1011 + vpermdi $T3,$T3,$T4,0b11 + + vmulouw $T0,$H2,$S3 + vaddudm $ACC0,$ACC0,$T0 + vmulouw $T0,$H3,$S3 + vaddudm $ACC1,$ACC1,$T0 + vmulouw $T0,$H4,$S3 + vaddudm $ACC2,$ACC2,$T0 + vmulouw $T0,$H0,$R3 + vaddudm $ACC3,$ACC3,$T0 + lvx $S1,$x10,$_ctx + vmulouw $T0,$H1,$R3 + vaddudm $ACC4,$ACC4,$T0 + lvx $R1,$x00,$_ctx + + vsrd $I1,$I0,$_26 + vsrd $I2,$I2,$_4 + vsrd $I4,$I3,$_40 + vsrd $I3,$I3,$_14 + + vmulouw $T0,$H1,$S4 + vaddudm $ACC0,$ACC0,$T0 + vmulouw $T0,$H2,$S4 + vaddudm $ACC1,$ACC1,$T0 + vmulouw $T0,$H3,$S4 + vaddudm $ACC2,$ACC2,$T0 + vmulouw $T0,$H4,$S4 + vaddudm $ACC3,$ACC3,$T0 + lvx $S2,$x30,$_ctx + vmulouw $T0,$H0,$R4 + vaddudm $ACC4,$ACC4,$T0 + lvx $R2,$x20,$_ctx + + vand $I0,$I0,$mask26 + vand $I1,$I1,$mask26 + vand $I2,$I2,$mask26 + vand $I3,$I3,$mask26 + + vmulouw $T0,$H4,$S1 + vaddudm $ACC0,$ACC0,$T0 + vmulouw $T0,$H0,$R1 + vaddudm $ACC1,$ACC1,$T0 + vmulouw $T0,$H1,$R1 + vaddudm $ACC2,$ACC2,$T0 + vmulouw $T0,$H2,$R1 + vaddudm $ACC3,$ACC3,$T0 + vmulouw $T0,$H3,$R1 + vaddudm $ACC4,$ACC4,$T0 + + vsrd $T2,$T2,$_4 + vsrd $_4,$T1,$_26 + vsrd $T4,$T3,$_40 + vsrd $T3,$T3,$_14 + + vmulouw $T0,$H3,$S2 + vaddudm $ACC0,$ACC0,$T0 + vmulouw $T0,$H4,$S2 + vaddudm $ACC1,$ACC1,$T0 + vmulouw $T0,$H0,$R2 + vaddudm $ACC2,$ACC2,$T0 + vmulouw $T0,$H1,$R2 + vaddudm $ACC3,$ACC3,$T0 + vmulouw $T0,$H2,$R2 + vaddudm $ACC4,$ACC4,$T0 + + vand $T1,$T1,$mask26 + vand $_4,$_4,$mask26 + vand $T2,$T2,$mask26 + vand $T3,$T3,$mask26 + + ################################################################ + # lazy reduction as discussed in "NEON crypto" by D.J. Bernstein + # and P. Schwabe + + vspltisb $T0,2 + vsrd $H4,$ACC3,$_26 + vsrd $H1,$ACC0,$_26 + vand $H3,$ACC3,$mask26 + vand $H0,$ACC0,$mask26 + vaddudm $H4,$H4,$ACC4 # h3 -> h4 + vaddudm $H1,$H1,$ACC1 # h0 -> h1 + + vmrgow $I4,$T4,$I4 + vmrgow $I0,$T1,$I0 + vmrgow $I1,$_4,$I1 + vmrgow $I2,$T2,$I2 + vmrgow $I3,$T3,$I3 + vor $I4,$I4,$padbits + + vsrd $ACC4,$H4,$_26 + vsrd $ACC1,$H1,$_26 + vand $H4,$H4,$mask26 + vand $H1,$H1,$mask26 + vaddudm $H0,$H0,$ACC4 + vaddudm $H2,$ACC2,$ACC1 # h1 -> h2 + + vsld $ACC4,$ACC4,$T0 # <<2 + vsrd $ACC2,$H2,$_26 + vand $H2,$H2,$mask26 + vaddudm $H0,$H0,$ACC4 # h4 -> h0 + vaddudm $H3,$H3,$ACC2 # h2 -> h3 + + vsrd $ACC0,$H0,$_26 + vsrd $ACC3,$H3,$_26 + vand $H0,$H0,$mask26 + vand $H3,$H3,$mask26 + vaddudm $H1,$H1,$ACC0 # h0 -> h1 + vaddudm $H4,$H4,$ACC3 # h3 -> h4 + + addi $inp,$inp,0x40 + bdnz Loop_vsx + + neg $len,$len + andi. $len,$len,0x30 + sub $inp,$inp,$len + + lvx_u $R0,$x30,$ctx # load all powers + lvx_u $R1,$x00,$ctx_ + lvx_u $S1,$x10,$ctx_ + lvx_u $R2,$x20,$ctx_ + lvx_u $S2,$x30,$ctx_ + +Last_vsx: + vmuleuw $ACC0,$I0,$R0 + vmuleuw $ACC1,$I1,$R0 + vmuleuw $ACC2,$I2,$R0 + vmuleuw $ACC3,$I3,$R0 + vmuleuw $ACC4,$I4,$R0 + + vmuleuw $T0,$I4,$S1 + vaddudm $ACC0,$ACC0,$T0 + vmuleuw $T0,$I0,$R1 + vaddudm $ACC1,$ACC1,$T0 + vmuleuw $T0,$I1,$R1 + vaddudm $ACC2,$ACC2,$T0 + vmuleuw $T0,$I2,$R1 + vaddudm $ACC3,$ACC3,$T0 + lvx_u $S3,$x50,$ctx_ + vmuleuw $T0,$I3,$R1 + vaddudm $ACC4,$ACC4,$T0 + lvx_u $R3,$x40,$ctx_ + + vaddudm $H2,$H2,$I2 + vaddudm $H0,$H0,$I0 + vaddudm $H3,$H3,$I3 + vaddudm $H1,$H1,$I1 + vaddudm $H4,$H4,$I4 + + vmuleuw $T0,$I3,$S2 + vaddudm $ACC0,$ACC0,$T0 + vmuleuw $T0,$I4,$S2 + vaddudm $ACC1,$ACC1,$T0 + vmuleuw $T0,$I0,$R2 + vaddudm $ACC2,$ACC2,$T0 + vmuleuw $T0,$I1,$R2 + vaddudm $ACC3,$ACC3,$T0 + lvx_u $S4,$x70,$ctx_ + vmuleuw $T0,$I2,$R2 + vaddudm $ACC4,$ACC4,$T0 + lvx_u $R4,$x60,$ctx_ + + vmuleuw $T0,$I2,$S3 + vaddudm $ACC0,$ACC0,$T0 + vmuleuw $T0,$I3,$S3 + vaddudm $ACC1,$ACC1,$T0 + vmuleuw $T0,$I4,$S3 + vaddudm $ACC2,$ACC2,$T0 + vmuleuw $T0,$I0,$R3 + vaddudm $ACC3,$ACC3,$T0 + vmuleuw $T0,$I1,$R3 + vaddudm $ACC4,$ACC4,$T0 + + vmuleuw $T0,$I1,$S4 + vaddudm $ACC0,$ACC0,$T0 + vmuleuw $T0,$I2,$S4 + vaddudm $ACC1,$ACC1,$T0 + vmuleuw $T0,$I3,$S4 + vaddudm $ACC2,$ACC2,$T0 + vmuleuw $T0,$I4,$S4 + vaddudm $ACC3,$ACC3,$T0 + vmuleuw $T0,$I0,$R4 + vaddudm $ACC4,$ACC4,$T0 + + # (hash + inp[0:1]) * r^4 + vmulouw $T0,$H0,$R0 + vaddudm $ACC0,$ACC0,$T0 + vmulouw $T0,$H1,$R0 + vaddudm $ACC1,$ACC1,$T0 + vmulouw $T0,$H2,$R0 + vaddudm $ACC2,$ACC2,$T0 + vmulouw $T0,$H3,$R0 + vaddudm $ACC3,$ACC3,$T0 + vmulouw $T0,$H4,$R0 + vaddudm $ACC4,$ACC4,$T0 + + vmulouw $T0,$H2,$S3 + vaddudm $ACC0,$ACC0,$T0 + vmulouw $T0,$H3,$S3 + vaddudm $ACC1,$ACC1,$T0 + vmulouw $T0,$H4,$S3 + vaddudm $ACC2,$ACC2,$T0 + vmulouw $T0,$H0,$R3 + vaddudm $ACC3,$ACC3,$T0 + lvx_u $S1,$x10,$ctx_ + vmulouw $T0,$H1,$R3 + vaddudm $ACC4,$ACC4,$T0 + lvx_u $R1,$x00,$ctx_ + + vmulouw $T0,$H1,$S4 + vaddudm $ACC0,$ACC0,$T0 + vmulouw $T0,$H2,$S4 + vaddudm $ACC1,$ACC1,$T0 + vmulouw $T0,$H3,$S4 + vaddudm $ACC2,$ACC2,$T0 + vmulouw $T0,$H4,$S4 + vaddudm $ACC3,$ACC3,$T0 + lvx_u $S2,$x30,$ctx_ + vmulouw $T0,$H0,$R4 + vaddudm $ACC4,$ACC4,$T0 + lvx_u $R2,$x20,$ctx_ + + vmulouw $T0,$H4,$S1 + vaddudm $ACC0,$ACC0,$T0 + vmulouw $T0,$H0,$R1 + vaddudm $ACC1,$ACC1,$T0 + vmulouw $T0,$H1,$R1 + vaddudm $ACC2,$ACC2,$T0 + vmulouw $T0,$H2,$R1 + vaddudm $ACC3,$ACC3,$T0 + vmulouw $T0,$H3,$R1 + vaddudm $ACC4,$ACC4,$T0 + + vmulouw $T0,$H3,$S2 + vaddudm $ACC0,$ACC0,$T0 + vmulouw $T0,$H4,$S2 + vaddudm $ACC1,$ACC1,$T0 + vmulouw $T0,$H0,$R2 + vaddudm $ACC2,$ACC2,$T0 + vmulouw $T0,$H1,$R2 + vaddudm $ACC3,$ACC3,$T0 + vmulouw $T0,$H2,$R2 + vaddudm $ACC4,$ACC4,$T0 + + ################################################################ + # horizontal addition + + vpermdi $H0,$ACC0,$ACC0,0b10 + vpermdi $H1,$ACC1,$ACC1,0b10 + vpermdi $H2,$ACC2,$ACC2,0b10 + vpermdi $H3,$ACC3,$ACC3,0b10 + vpermdi $H4,$ACC4,$ACC4,0b10 + vaddudm $ACC0,$ACC0,$H0 + vaddudm $ACC1,$ACC1,$H1 + vaddudm $ACC2,$ACC2,$H2 + vaddudm $ACC3,$ACC3,$H3 + vaddudm $ACC4,$ACC4,$H4 + + ################################################################ + # lazy reduction + + vspltisb $T0,2 + vsrd $H4,$ACC3,$_26 + vsrd $H1,$ACC0,$_26 + vand $H3,$ACC3,$mask26 + vand $H0,$ACC0,$mask26 + vaddudm $H4,$H4,$ACC4 # h3 -> h4 + vaddudm $H1,$H1,$ACC1 # h0 -> h1 + + vsrd $ACC4,$H4,$_26 + vsrd $ACC1,$H1,$_26 + vand $H4,$H4,$mask26 + vand $H1,$H1,$mask26 + vaddudm $H0,$H0,$ACC4 + vaddudm $H2,$ACC2,$ACC1 # h1 -> h2 + + vsld $ACC4,$ACC4,$T0 # <<2 + vsrd $ACC2,$H2,$_26 + vand $H2,$H2,$mask26 + vaddudm $H0,$H0,$ACC4 # h4 -> h0 + vaddudm $H3,$H3,$ACC2 # h2 -> h3 + + vsrd $ACC0,$H0,$_26 + vsrd $ACC3,$H3,$_26 + vand $H0,$H0,$mask26 + vand $H3,$H3,$mask26 + vaddudm $H1,$H1,$ACC0 # h0 -> h1 + vaddudm $H4,$H4,$ACC3 # h3 -> h4 + + beq Ldone_vsx + + add r6,$const,$len + + be?lvx_u $_4,$x00,$const # byte swap mask + lvx_u $T1,$x00,$inp # load last partial input block + lvx_u $T2,$x10,$inp + lvx_u $T3,$x20,$inp + lvx_u $T4,$x30,$inp + be?vperm $T1,$T1,$T1,$_4 + be?vperm $T2,$T2,$T2,$_4 + be?vperm $T3,$T3,$T3,$_4 + be?vperm $T4,$T4,$T4,$_4 + + vpermdi $I0,$T1,$T2,0b00 # smash input to base 2^26 + vspltisb $_4,4 + vperm $I2,$T1,$T2,$I2perm # 0x...0e0f0001...1e1f1011 + vpermdi $I3,$T1,$T2,0b11 + + vsrd $I1,$I0,$_26 + vsrd $I2,$I2,$_4 + vsrd $I4,$I3,$_40 + vsrd $I3,$I3,$_14 + vand $I0,$I0,$mask26 + vand $I1,$I1,$mask26 + vand $I2,$I2,$mask26 + vand $I3,$I3,$mask26 + + vpermdi $T0,$T3,$T4,0b00 + vperm $T1,$T3,$T4,$I2perm # 0x...0e0f0001...1e1f1011 + vpermdi $T2,$T3,$T4,0b11 + + lvx_u $ACC0,$x00,r6 + lvx_u $ACC1,$x30,r6 + + vsrd $T3,$T0,$_26 + vsrd $T1,$T1,$_4 + vsrd $T4,$T2,$_40 + vsrd $T2,$T2,$_14 + vand $T0,$T0,$mask26 + vand $T3,$T3,$mask26 + vand $T1,$T1,$mask26 + vand $T2,$T2,$mask26 + + # inp[2]:inp[0]:inp[3]:inp[1] + vmrgow $I4,$T4,$I4 + vmrgow $I0,$T0,$I0 + vmrgow $I1,$T3,$I1 + vmrgow $I2,$T1,$I2 + vmrgow $I3,$T2,$I3 + vor $I4,$I4,$padbits + + vperm $H0,$H0,$H0,$ACC0 # move hash to right lane + vand $I0,$I0, $ACC1 # mask redundant input lane[s] + vperm $H1,$H1,$H1,$ACC0 + vand $I1,$I1, $ACC1 + vperm $H2,$H2,$H2,$ACC0 + vand $I2,$I2, $ACC1 + vperm $H3,$H3,$H3,$ACC0 + vand $I3,$I3, $ACC1 + vperm $H4,$H4,$H4,$ACC0 + vand $I4,$I4, $ACC1 + + vaddudm $I0,$I0,$H0 # accumulate hash + vxor $H0,$H0,$H0 # wipe hash value + vaddudm $I1,$I1,$H1 + vxor $H1,$H1,$H1 + vaddudm $I2,$I2,$H2 + vxor $H2,$H2,$H2 + vaddudm $I3,$I3,$H3 + vxor $H3,$H3,$H3 + vaddudm $I4,$I4,$H4 + vxor $H4,$H4,$H4 + + xor. $len,$len,$len + b Last_vsx + +.align 4 +Ldone_vsx: + $POP r0,`$VSXFRAME+$LRSAVE`($sp) + li $x10,4 + li $x20,8 + li $x30,12 + li $x40,16 + stvwx_u $H0,$x00,$ctx # store hash + stvwx_u $H1,$x10,$ctx + stvwx_u $H2,$x20,$ctx + stvwx_u $H3,$x30,$ctx + stvwx_u $H4,$x40,$ctx + + lwz r12,`$VSXFRAME-$SIZE_T*5-4`($sp)# pull vrsave + mtlr r0 + li r10,`15+$LOCALS+128` + li r11,`31+$LOCALS+128` + mtspr 256,r12 # restore vrsave + lvx v20,r10,$sp + addi r10,r10,32 + lvx v21,r10,$sp + addi r10,r10,32 + lvx v22,r11,$sp + addi r11,r11,32 + lvx v23,r10,$sp + addi r10,r10,32 + lvx v24,r11,$sp + addi r11,r11,32 + lvx v25,r10,$sp + addi r10,r10,32 + lvx v26,r11,$sp + addi r11,r11,32 + lvx v27,r10,$sp + addi r10,r10,32 + lvx v28,r11,$sp + addi r11,r11,32 + lvx v29,r10,$sp + addi r10,r10,32 + lvx v30,r11,$sp + lvx v31,r10,$sp + $POP r27,`$VSXFRAME-$SIZE_T*5`($sp) + $POP r28,`$VSXFRAME-$SIZE_T*4`($sp) + $POP r29,`$VSXFRAME-$SIZE_T*3`($sp) + $POP r30,`$VSXFRAME-$SIZE_T*2`($sp) + $POP r31,`$VSXFRAME-$SIZE_T*1`($sp) + addi $sp,$sp,$VSXFRAME + blr + .long 0 + .byte 0,12,0x04,1,0x80,5,4,0 + .long 0 +.size __poly1305_blocks_vsx,.-__poly1305_blocks_vsx + +.align 6 +LPICmeup: + mflr r0 + bcl 20,31,\$+4 + mflr $const # vvvvvv "distance" between . and 1st data entry + addi $const,$const,`64-8` + mtlr r0 + blr + .long 0 + .byte 0,12,0x14,0,0,0,0,0 + .space `64-9*4` + +.quad 0x0000000003ffffff,0x0000000003ffffff # mask26 +.quad 0x000000000000001a,0x000000000000001a # _26 +.quad 0x0000000000000028,0x0000000000000028 # _40 +.quad 0x000000000e0f0001,0x000000001e1f1011 # I2perm +.quad 0x0100000001000000,0x0100000001000000 # padbits +.quad 0x0706050403020100,0x0f0e0d0c0b0a0908 # byte swap for big-endian + +.quad 0x0000000000000000,0x0000000004050607 # magic tail masks +.quad 0x0405060700000000,0x0000000000000000 +.quad 0x0000000000000000,0x0405060700000000 + +.quad 0xffffffff00000000,0xffffffffffffffff +.quad 0xffffffff00000000,0xffffffff00000000 +.quad 0x0000000000000000,0xffffffff00000000 +___ +}}} +$code.=<<___; +.asciz "Poly1305 for PPC, CRYPTOGAMS by \@dot-asm" ___ -$code =~ s/\`([^\`]*)\`/eval $1/gem; -print $code; +foreach (split("\n",$code)) { + s/\`([^\`]*)\`/eval($1)/ge; + + # instructions prefixed with '?' are endian-specific and need + # to be adjusted accordingly... + if ($flavour !~ /le$/) { # big-endian + s/be\?// or + s/le\?/#le#/ + } else { # little-endian + s/le\?// or + s/be\?/#be#/ + } + + print $_,"\n"; +} close STDOUT; diff --git a/crypto/poly1305/asm/poly1305-s390x.pl b/crypto/poly1305/asm/poly1305-s390x.pl index 21ca8605..390f9eef 100755 --- a/crypto/poly1305/asm/poly1305-s390x.pl +++ b/crypto/poly1305/asm/poly1305-s390x.pl @@ -24,204 +24,820 @@ # # On side note, z13 enables vector base 2^26 implementation... -$flavour = shift; +# +# January 2019 +# +# Add vx code path (base 2^26). +# +# Copyright IBM Corp. 2019 +# Author: Patrick Steuer +use strict; +use FindBin qw($Bin); +use lib "$Bin/../.."; +use perlasm::s390x qw(:DEFAULT :VX AUTOLOAD LABEL); + +my $flavour = shift; + +my ($z,$SIZE_T); if ($flavour =~ /3[12]/) { + $z=0; # S/390 ABI $SIZE_T=4; - $g=""; } else { + $z=1; # zSeries ABI $SIZE_T=8; - $g="g"; } +my $output; while (($output=shift) && ($output!~/\w[\w\-]*\.\w+$/)) {} -open STDOUT,">$output"; -$sp="%r15"; +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 + +PERLASM_BEGIN($output); + +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","8($ctx)"); + stg ("%r0","16($ctx)"); + +&{$z? \&clgr:\&clr} ($key,"%r0"); + je (".Ldone"); + + lrvg ("%r4","0($key)"); # load little-endian key + lrvg ("%r5","8($key)"); + + nihl ("%r1",0xffc0); # 0xffffffc0ffffffff + srlg ("%r0","%r1",4); # 0x0ffffffc0fffffff + srlg ("%r1","%r1",4); + nill ("%r1",0xfffc); # 0x0ffffffc0ffffffc + + ngr ("%r4","%r0"); + ngr ("%r5","%r1"); + + stg ("%r4","32($ctx)"); + stg ("%r5","40($ctx)"); + + 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)"); + lghi ("%r2",1); + br ("%r14"); + +LABEL (".Ldone"); + lghi ("%r2",0); + 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) +{ +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)); -$code.=<<___; -.text - -.globl poly1305_init -.type poly1305_init,\@function -.align 16 -poly1305_init: - lghi %r0,0 - lghi %r1,-1 - stg %r0,0($ctx) # zero hash value - stg %r0,8($ctx) - stg %r0,16($ctx) - - cl${g}r $inp,%r0 - je .Lno_key - - lrvg %r4,0($inp) # load little-endian key - lrvg %r5,8($inp) - - nihl %r1,0xffc0 # 0xffffffc0ffffffff - srlg %r0,%r1,4 # 0x0ffffffc0fffffff - srlg %r1,%r1,4 - nill %r1,0xfffc # 0x0ffffffc0ffffffc - - ngr %r4,%r0 - ngr %r5,%r1 - - stg %r4,32($ctx) - stg %r5,40($ctx) - -.Lno_key: - lghi %r2,0 - br %r14 -.size poly1305_init,.-poly1305_init -___ -{ 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"); -$code.=<<___; -.globl poly1305_blocks -.type poly1305_blocks,\@function -.align 16 -poly1305_blocks: - srl${g} $len,4 # fixed-up in 64-bit build - lghi %r0,0 - cl${g}r $len,%r0 - je .Lno_data +&{$z? \&stmg:\&stm} ("%r6","%r14","6*$SIZE_T($sp)"); - stm${g} %r6,%r14,`6*$SIZE_T`($sp) - - llgfr $padbit,$padbit # clear upper half, much needed with + llgfr ($padbit,$padbit); # clear upper half, much needed with # non-64-bit ABI - lg $r0,32($ctx) # load key - lg $r1,40($ctx) + lg ($r0,"32($ctx)"); # load key + lg ($r1,"40($ctx)"); - lg $h0,0($ctx) # load hash value - lg $h1,8($ctx) - lg $h2,16($ctx) + lg ($h0,"0($ctx)"); # load hash value + lg ($h1,"8($ctx)"); + lg ($h2,"16($ctx)"); - st$g $ctx,`2*$SIZE_T`($sp) # off-load $ctx - srlg $s1,$r1,2 - algr $s1,$r1 # s1 = r1 + r1>>2 - j .Loop +&{$z? \&stg:\&st} ($ctx,"2*$SIZE_T($sp)"); # off-load $ctx + srlg ($s1,$r1,2); + algr ($s1,$r1); # s1 = r1 + r1>>2 + j (".Loop"); -.align 16 -.Loop: - lrvg $d0lo,0($inp) # load little-endian input - lrvg $d1lo,8($inp) - la $inp,16($inp) +ALIGN (16); +LABEL (".Loop"); + lrvg ($d0lo,"0($inp)"); # load little-endian input + lrvg ($d1lo,"8($inp)"); + la ($inp,"16($inp)"); - algr $d0lo,$h0 # accumulate input - alcgr $d1lo,$h1 + algr ($d0lo,$h0); # accumulate input + alcgr ($d1lo,$h1); - lgr $h0,$d0lo - mlgr $d0hi,$r0 # h0*r0 -> $d0hi:$d0lo - lgr $h1,$d1lo - mlgr $d1hi,$s1 # h1*5*r1 -> $d1hi:$d1lo + lgr ($h0,$d0lo); + mlgr ($d0hi,$r0); # h0*r0 -> $d0hi:$d0lo + lgr ($h1,$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 + alcgr ($h2,$padbit); - algr $d0lo,$d1lo - lgr $d1lo,$h2 - alcgr $d0hi,$d1hi - lghi $d1hi,0 + algr ($d0lo,$d1lo); + lgr ($d1lo,$h2); + alcgr ($d0hi,$d1hi); + lghi ($d1hi,0); - algr $h1,$h0 - alcgr $t1,$t0 + 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 + algr ($h1,$d1lo); + alcgr ($t1,$d1hi); # $d1hi is zero - algr $h1,$d0hi - alcgr $h2,$t1 + algr ($h1,$d0hi); + alcgr ($h2,$t1); - lghi $h0,-4 # final reduction step - ngr $h0,$h2 - srlg $t0,$h2,2 - algr $h0,$t0 - lghi $t1,3 - ngr $h2,$t1 + lghi ($h0,-4); # final reduction step + ngr ($h0,$h2); + srlg ($t0,$h2,2); + algr ($h0,$t0); + lghi ($t1,3); + ngr ($h2,$t1); - algr $h0,$d0lo - alcgr $h1,$d1hi # $d1hi is still zero - alcgr $h2,$d1hi # $d1hi is still zero + algr ($h0,$d0lo); + alcgr ($h1,$d1hi); # $d1hi is still zero + alcgr ($h2,$d1hi); # $d1hi is still zero - brct$g $len,.Loop +&{$z? \&brctg:\&brct} ($len,".Loop"); - l$g $ctx,`2*$SIZE_T`($sp) # restore $ctx +&{$z? \&lg:\&l} ($ctx,"2*$SIZE_T($sp)");# restore $ctx - stg $h0,0($ctx) # store hash value - stg $h1,8($ctx) - stg $h2,16($ctx) + stg ($h0,"0($ctx)"); # store hash value + stg ($h1,"8($ctx)"); + stg ($h2,"16($ctx)"); - lm${g} %r6,%r14,`6*$SIZE_T`($sp) -.Lno_data: - br %r14 -.size poly1305_blocks,.-poly1305_blocks -___ +&{$z? \&lmg:\&lm} ("%r6","%r14","6*$SIZE_T($sp)"); +LABEL (".Lno_data"); + br ("%r14"); +SIZE ("poly1305_blocks",".-poly1305_blocks"); } + +################ +# static void poly1305_emit(void *ctx, unsigned char mac[16], +# const u32 nonce[4]) { -my ($mac,$nonce)=($inp,$len); +my ($ctx,$mac,$nonce) = map("%r$_",(2..4)); my ($h0,$h1,$h2,$d0,$d1)=map("%r$_",(5..9)); -$code.=<<___; -.globl poly1305_emit -.type poly1305_emit,\@function -.align 16 -poly1305_emit: - stm${g} %r6,%r9,`6*$SIZE_T`($sp) +GLOBL ("poly1305_emit"); +TYPE ("poly1305_emit","\@function"); +ALIGN (16); +LABEL ("poly1305_emit"); +&{$z? \&stmg:\&stm} ("%r6","%r9","6*$SIZE_T($sp)"); - lg $h0,0($ctx) - lg $h1,8($ctx) - lg $h2,16($ctx) + lg ($h0,"0($ctx)"); + lg ($h1,"8($ctx)"); + lg ($h2,"16($ctx)"); - lghi %r0,5 - lghi %r1,0 - lgr $d0,$h0 - lgr $d1,$h1 + lghi ("%r0",5); + lghi ("%r1",0); + lgr ($d0,$h0); + lgr ($d1,$h1); - algr $h0,%r0 # compare to modulus - alcgr $h1,%r1 - alcgr $h2,%r1 + 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 - lg $ctx,8($nonce) - xgr %r0,%r1 # ~%r1 + srlg ($h2,$h2,2); # did it borrow/carry? + slgr ("%r1",$h2); # 0-$h2>>2 + lg ($h2,"0($nonce)"); # load nonce + lghi ("%r0",-1); + lg ($ctx,"8($nonce)"); + xgr ("%r0","%r1"); # ~%r1 - 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 - rllg $d1,$ctx,32 + 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); + rllg ($d1,$ctx,32); - algr $h0,$d0 # accumulate nonce - alcgr $h1,$d1 + algr ($h0,$d0); # accumulate nonce + alcgr ($h1,$d1); - strvg $h0,0($mac) # write little-endian result - strvg $h1,8($mac) + strvg ($h0,"0($mac)"); # write little-endian result + strvg ($h1,"8($mac)"); - lm${g} %r6,%r9,`6*$SIZE_T`($sp) - br %r14 -.size poly1305_emit,.-poly1305_emit - -.string "Poly1305 for s390x, CRYPTOGAMS by " -___ +&{$z? \&lmg:\&lm} ("%r6","%r9","6*$SIZE_T($sp)"); + br ("%r14"); +SIZE ("poly1305_emit",".-poly1305_emit"); } +} +################ -$code =~ s/\`([^\`]*)\`/eval $1/gem; -$code =~ s/\b(srlg\s+)(%r[0-9]+\s*,)\s*([0-9]+)/$1$2$2$3/gm; +ALIGN (128); +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 +STRING ("\"Poly1305 for s390x, CRYPTOGAMS by \""); -print $code; -close STDOUT; +PERLASM_END(); diff --git a/crypto/poly1305/build.info b/crypto/poly1305/build.info index 363d62e6..de44bb88 100644 --- a/crypto/poly1305/build.info +++ b/crypto/poly1305/build.info @@ -17,8 +17,5 @@ GENERATE[poly1305-armv8.S]=asm/poly1305-armv8.pl $(PERLASM_SCHEME) INCLUDE[poly1305-armv8.o]=.. GENERATE[poly1305-mips.S]=asm/poly1305-mips.pl $(PERLASM_SCHEME) INCLUDE[poly1305-mips.o]=.. - -BEGINRAW[Makefile(unix)] -{- $builddir -}/poly1305-%.S: {- $sourcedir -}/asm/poly1305-%.pl - CC="$(CC)" $(PERL) $< $(PERLASM_SCHEME) $@ -ENDRAW[Makefile(unix)] +GENERATE[poly1305-c64xplus.S]=asm/poly1305-c64xplus.pl $(PERLASM_SCHEME) +GENERATE[poly1305-s390x.S]=asm/poly1305-s390x.pl $(PERLASM_SCHEME) diff --git a/crypto/ppccap.c b/crypto/ppccap.c index 70829e4c..96016740 100644 --- a/crypto/ppccap.c +++ b/crypto/ppccap.c @@ -116,10 +116,19 @@ void poly1305_blocks_fpu(void *ctx, const unsigned char *inp, size_t len, unsigned int padbit); void poly1305_emit_fpu(void *ctx, unsigned char mac[16], const unsigned int nonce[4]); +void poly1305_init_vsx(void *ctx, const unsigned char key[16]); +void poly1305_blocks_vsx(void *ctx, const unsigned char *inp, size_t len, + unsigned int padbit); +void poly1305_emit_vsx(void *ctx, unsigned char mac[16], + const unsigned int nonce[4]); int poly1305_init(void *ctx, const unsigned char key[16], void *func[2]); int poly1305_init(void *ctx, const unsigned char key[16], void *func[2]) { - if (sizeof(size_t) == 4 && (OPENSSL_ppccap_P & PPC_FPU)) { + if (OPENSSL_ppccap_P & PPC_CRYPTO207) { + poly1305_init_int(ctx, key); + func[0] = (void*)(uintptr_t)poly1305_blocks_vsx; + func[1] = (void*)(uintptr_t)poly1305_emit; + } else if (sizeof(size_t) == 4 && (OPENSSL_ppccap_P & PPC_FPU)) { poly1305_init_fpu(ctx, key); func[0] = (void*)(uintptr_t)poly1305_blocks_fpu; func[1] = (void*)(uintptr_t)poly1305_emit_fpu; diff --git a/crypto/rc4/build.info b/crypto/rc4/build.info index 46ee66b6..8d272e4f 100644 --- a/crypto/rc4/build.info +++ b/crypto/rc4/build.info @@ -10,9 +10,5 @@ GENERATE[rc4-x86_64.s]=asm/rc4-x86_64.pl $(PERLASM_SCHEME) GENERATE[rc4-md5-x86_64.s]=asm/rc4-md5-x86_64.pl $(PERLASM_SCHEME) GENERATE[rc4-parisc.s]=asm/rc4-parisc.pl $(PERLASM_SCHEME) - -BEGINRAW[Makefile] -# GNU make "catch all" -{- $builddir -}/rc4-%.s: {- $sourcedir -}/asm/rc4-%.pl - CC="$(CC)" $(PERL) $< $(PERLASM_SCHEME) $@ -ENDRAW[Makefile] +GENERATE[rc4-c64xplus.s]=asm/rc4-c64xplus.pl $(PERLASM_SCHEME) +GENERATE[rc4-s390x.s]=asm/rc4-s390x.pl $(PERLASM_SCHEME) diff --git a/crypto/sha/build.info b/crypto/sha/build.info index 5dd5a994..58d15bbb 100644 --- a/crypto/sha/build.info +++ b/crypto/sha/build.info @@ -26,6 +26,7 @@ GENERATE[sha256-mb-x86_64.s]=asm/sha256-mb-x86_64.pl $(PERLASM_SCHEME) GENERATE[sha512-x86_64.s]=asm/sha512-x86_64.pl $(PERLASM_SCHEME) GENERATE[keccak1600-x86_64.s]=asm/keccak1600-x86_64.pl $(PERLASM_SCHEME) +GENERATE[sha1-sparcv9a.S]=asm/sha1-sparcv9a.pl $(PERLASM_SCHEME) GENERATE[sha1-sparcv9.S]=asm/sha1-sparcv9.pl $(PERLASM_SCHEME) INCLUDE[sha1-sparcv9.o]=.. GENERATE[sha256-sparcv9.S]=asm/sha512-sparcv9.pl $(PERLASM_SCHEME) @@ -76,14 +77,15 @@ GENERATE[sha512-s390x.S]=asm/sha512-s390x.pl $(PERLASM_SCHEME) INCLUDE[sha512-s390x.o]=.. GENERATE[keccak1600-s390x.S]=asm/keccak1600-s390x.pl $(PERLASM_SCHEME) -BEGINRAW[Makefile(unix)] -##### SHA assembler implementations +GENERATE[sha1-c64xplus.S]=asm/sha1-c64xplus.pl $(PERLASM_SCHEME) +GENERATE[sha256-c64xplus.S]=asm/sha256-c64xplus.pl $(PERLASM_SCHEME) +GENERATE[sha512-c64xplus.S]=asm/sha512-c64xplus.pl $(PERLASM_SCHEME) +GENERATE[keccak1600-c64x.S]=asm/keccak1600-c64x.pl $(PERLASM_SCHEME) -# GNU make "catch all" -{- $builddir -}/sha1-%.S: {- $sourcedir -}/asm/sha1-%.pl - CC="$(CC)" $(PERL) $< $(PERLASM_SCHEME) $@ -{- $builddir -}/sha256-%.S: {- $sourcedir -}/asm/sha512-%.pl - CC="$(CC)" $(PERL) $< $(PERLASM_SCHEME) $@ -{- $builddir -}/sha512-%.S: {- $sourcedir -}/asm/sha512-%.pl - CC="$(CC)" $(PERL) $< $(PERLASM_SCHEME) $@ -ENDRAW[Makefile(unix)] +# These are not yet used +GENERATE[keccak1600-avx2.S]=asm/keccak1600-avx2.pl $(PERLASM_SCHEME) +GENERATE[keccak1600-avx512.S]=asm/keccak1600-avx512.pl $(PERLASM_SCHEME) +GENERATE[keccak1600-avx512vl.S]=asm/keccak1600-avx512vl.pl $(PERLASM_SCHEME) +GENERATE[keccak1600-mmx.S]=asm/keccak1600-mmx.pl $(PERLASM_SCHEME) +GENERATE[keccak1600p8-ppc.S]=asm/keccak1600p8-ppc.pl $(PERLASM_SCHEME) +GENERATE[sha1-thumb.S]=asm/sha1-thumb.pl $(PERLASM_SCHEME) diff --git a/crypto/srp/srp_vfy.c b/crypto/srp/srp_vfy.c index d69e330c..79e76c9a 100644 --- a/crypto/srp/srp_vfy.c +++ b/crypto/srp/srp_vfy.c @@ -187,7 +187,7 @@ void SRP_user_pwd_free(SRP_user_pwd *user_pwd) SRP_user_pwd *SRP_user_pwd_new(void) { SRP_user_pwd *ret; - + if ((ret = OPENSSL_malloc(sizeof(*ret))) == NULL) { /* SRPerr(SRP_F_SRP_USER_PWD_NEW, ERR_R_MALLOC_FAILURE); */ /*ckerr_ignore*/ return NULL; diff --git a/crypto/x509/x_crl.c b/crypto/x509/x_crl.c index 89e13e87..3984f014 100644 --- a/crypto/x509/x_crl.c +++ b/crypto/x509/x_crl.c @@ -158,6 +158,18 @@ static int crl_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, int idx; switch (operation) { + case ASN1_OP_D2I_PRE: + if (crl->meth->crl_free) { + if (!crl->meth->crl_free(crl)) + return 0; + } + AUTHORITY_KEYID_free(crl->akid); + ISSUING_DIST_POINT_free(crl->idp); + ASN1_INTEGER_free(crl->crl_number); + ASN1_INTEGER_free(crl->base_crl_number); + sk_GENERAL_NAMES_pop_free(crl->issuers, GENERAL_NAMES_free); + /* fall thru */ + case ASN1_OP_NEW_POST: crl->idp = NULL; crl->akid = NULL; diff --git a/crypto/x509/x_pubkey.c b/crypto/x509/x_pubkey.c index f980af77..be42684e 100644 --- a/crypto/x509/x_pubkey.c +++ b/crypto/x509/x_pubkey.c @@ -36,6 +36,7 @@ static int pubkey_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, /* Attempt to decode public key and cache in pubkey structure. */ X509_PUBKEY *pubkey = (X509_PUBKEY *)*pval; EVP_PKEY_free(pubkey->pkey); + pubkey->pkey = NULL; /* * Opportunistically decode the key but remove any non fatal errors * from the queue. Subsequent explicit attempts to decode/use the key diff --git a/crypto/x509/x_x509.c b/crypto/x509/x_x509.c index 596e1e41..bf0270ef 100644 --- a/crypto/x509/x_x509.c +++ b/crypto/x509/x_x509.c @@ -40,12 +40,35 @@ static int x509_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, switch (operation) { + case ASN1_OP_D2I_PRE: + CRYPTO_free_ex_data(CRYPTO_EX_INDEX_X509, ret, &ret->ex_data); + X509_CERT_AUX_free(ret->aux); + ASN1_OCTET_STRING_free(ret->skid); + AUTHORITY_KEYID_free(ret->akid); + CRL_DIST_POINTS_free(ret->crldp); + policy_cache_free(ret->policy_cache); + GENERAL_NAMES_free(ret->altname); + NAME_CONSTRAINTS_free(ret->nc); +#ifndef OPENSSL_NO_RFC3779 + sk_IPAddressFamily_pop_free(ret->rfc3779_addr, IPAddressFamily_free); + ASIdentifiers_free(ret->rfc3779_asid); +#endif + + /* fall thru */ + case ASN1_OP_NEW_POST: + ret->ex_cached = 0; + ret->ex_kusage = 0; + ret->ex_xkusage = 0; + ret->ex_nscert = 0; ret->ex_flags = 0; ret->ex_pathlen = -1; ret->ex_pcpathlen = -1; ret->skid = NULL; ret->akid = NULL; + ret->policy_cache = NULL; + ret->altname = NULL; + ret->nc = NULL; #ifndef OPENSSL_NO_RFC3779 ret->rfc3779_addr = NULL; ret->rfc3779_asid = NULL; diff --git a/demos/bio/accept.cnf b/demos/bio/accept.cnf index eb696583..cb0cefba 100644 --- a/demos/bio/accept.cnf +++ b/demos/bio/accept.cnf @@ -6,7 +6,7 @@ Port = 4433 # Only support 3 curves Curves = P-521:P-384:P-256 # Restricted signature algorithms -SignatureAlgorithms = RSA+SHA512:ECDSA+SHA512 +SignatureAlgorithms = RSA+SHA512:ECDSA+SHA512 Certificate=server.pem PrivateKey=server.pem ChainCAFile=root.pem diff --git a/demos/bio/connect.cnf b/demos/bio/connect.cnf index 4dee03c3..ab764403 100644 --- a/demos/bio/connect.cnf +++ b/demos/bio/connect.cnf @@ -6,4 +6,4 @@ Connect = localhost:4433 # Only support 3 curves Curves = P-521:P-384:P-256 # Restricted signature algorithms -SignatureAlgorithms = RSA+SHA512:ECDSA+SHA512 +SignatureAlgorithms = RSA+SHA512:ECDSA+SHA512 diff --git a/demos/bio/descrip.mms b/demos/bio/descrip.mms index 8e127b07..d49725ff 100644 --- a/demos/bio/descrip.mms +++ b/demos/bio/descrip.mms @@ -23,7 +23,7 @@ SHARED = TRUE @ ! # Because we use an option file, we need to redefine this -.obj.exe : +.obj.exe : $(LINK) $(LINKFLAGS) $<,OPT:/OPT all : client-arg.exe client-conf.exe saccept.exe sconnect.exe - diff --git a/demos/certs/README b/demos/certs/README index 126663a1..fde832eb 100644 --- a/demos/certs/README +++ b/demos/certs/README @@ -8,7 +8,7 @@ automatically using scripts. Example creates a root CA, an intermediate CA signed by the root and several certificates signed by the intermediate CA. The script then creates an empty index.txt file and adds entries for the -certificates and generates a CRL. Then one certificate is revoked and a +certificates and generates a CRL. Then one certificate is revoked and a second CRL generated. The script ocsprun.sh runs the test responder on port 8888 covering the diff --git a/demos/certs/apps/mkxcerts.sh b/demos/certs/apps/mkxcerts.sh index 0f88a48f..ebe19204 100644 --- a/demos/certs/apps/mkxcerts.sh +++ b/demos/certs/apps/mkxcerts.sh @@ -13,7 +13,7 @@ CN="OpenSSL Test RSA SHA-512 cert" $OPENSSL req \ -config apps.cnf -extensions usr_cert -x509 -nodes \ -keyout tsha512.pem -out tsha512.pem -new -days 3650 -sha512 -# Create EC parameters +# Create EC parameters $OPENSSL ecparam -name P-256 -out ecp256.pem $OPENSSL ecparam -name P-384 -out ecp384.pem diff --git a/demos/certs/mkcerts.sh b/demos/certs/mkcerts.sh index 18daa6bc..2d14a959 100644 --- a/demos/certs/mkcerts.sh +++ b/demos/certs/mkcerts.sh @@ -42,7 +42,7 @@ CN="Test OCSP Responder Cert" $OPENSSL req -config ca.cnf -nodes \ $OPENSSL x509 -req -in respreq.pem -CA intca.pem -CAkey intkey.pem -days 3600 \ -extfile ca.cnf -extensions ocsp_cert -CAcreateserial -out resp.pem -# Example creating a PKCS#3 DH certificate. +# Example creating a PKCS#3 DH certificate. # First DH parameters diff --git a/doc/HOWTO/certificates.txt b/doc/HOWTO/certificates.txt index c2efdca8..cfd2bdab 100644 --- a/doc/HOWTO/certificates.txt +++ b/doc/HOWTO/certificates.txt @@ -106,5 +106,5 @@ some applications, you don't even have to do that. By now, you have your certificate and your private key and can start using applications that depend on it. --- +-- Richard Levitte diff --git a/doc/HOWTO/proxy_certificates.txt b/doc/HOWTO/proxy_certificates.txt index 18b3e034..2936cd6e 100644 --- a/doc/HOWTO/proxy_certificates.txt +++ b/doc/HOWTO/proxy_certificates.txt @@ -315,5 +315,5 @@ certificates checked properly, using the code above: SSL_CTX_set_cert_verify_callback(s_ctx, my_X509_verify_cert, &needed_rights); --- +-- Richard Levitte diff --git a/doc/fingerprints.txt b/doc/fingerprints.txt index 2cb74aec..51e76c8f 100644 --- a/doc/fingerprints.txt +++ b/doc/fingerprints.txt @@ -18,7 +18,7 @@ uid Richard Levitte uid Richard Levitte uid Richard Levitte -pub 2048R/0E604491 2013-04-30 +pub 2048R/0E604491 2013-04-30 Key fingerprint = 8657 ABB2 60F0 56B1 E519 0839 D9C4 D26D 0E60 4491 uid Matt Caswell uid Matt Caswell diff --git a/doc/man1/ca.pod b/doc/man1/ca.pod index cf6fe7e5..d1e5a996 100644 --- a/doc/man1/ca.pod +++ b/doc/man1/ca.pod @@ -475,7 +475,7 @@ the B<-selfsign> command line option. Note that it is valid in some circumstances for certificates to be created without any subject. In the case where there are multiple certificates without -subjects this does not count as a duplicate. +subjects this does not count as a duplicate. =item B diff --git a/doc/man1/pkcs12.pod b/doc/man1/pkcs12.pod index 67adaa1e..b1b68844 100644 --- a/doc/man1/pkcs12.pod +++ b/doc/man1/pkcs12.pod @@ -154,7 +154,8 @@ Don't attempt to verify the integrity MAC before reading the file. Prompt for separate integrity and encryption passwords: most software always assumes these are the same so this option will render such -PKCS#12 files unreadable. +PKCS#12 files unreadable. Cannot be used in combination with the options +-password, -passin (if importing) or -passout (if exporting). =back diff --git a/doc/man1/s_client.pod b/doc/man1/s_client.pod index 70b97bf4..e16450b5 100644 --- a/doc/man1/s_client.pod +++ b/doc/man1/s_client.pod @@ -102,6 +102,7 @@ B B [B<-dtls1>] [B<-dtls1_2>] [B<-sctp>] +[B<-sctp_label_bug>] [B<-fallback_scsv>] [B<-async>] [B<-max_send_frag>] @@ -506,6 +507,14 @@ Use SCTP for the transport protocol instead of UDP in DTLS. Must be used in conjunction with B<-dtls>, B<-dtls1> or B<-dtls1_2>. This option is only available where OpenSSL has support for SCTP enabled. +=item B<-sctp_label_bug> + +Use the incorrect behaviour of older OpenSSL implementations when computing +endpoint-pair shared secrets for DTLS/SCTP. This allows communication with +older broken implementations but breaks interoperability with correct +implementations. Must be used in conjunction with B<-sctp>. This option is only +available where OpenSSL has support for SCTP enabled. + =item B<-fallback_scsv> Send TLS_FALLBACK_SCSV in the ClientHello. diff --git a/doc/man1/s_server.pod b/doc/man1/s_server.pod index e86c2b36..b15ccdf1 100644 --- a/doc/man1/s_server.pod +++ b/doc/man1/s_server.pod @@ -173,6 +173,7 @@ B B [B<-dtls1>] [B<-dtls1_2>] [B<-sctp>] +[B<-sctp_label_bug>] [B<-no_dhe>] [B<-nextprotoneg val>] [B<-use_srtp val>] @@ -685,6 +686,14 @@ Use SCTP for the transport protocol instead of UDP in DTLS. Must be used in conjunction with B<-dtls>, B<-dtls1> or B<-dtls1_2>. This option is only available where OpenSSL has support for SCTP enabled. +=item B<-sctp_label_bug> + +Use the incorrect behaviour of older OpenSSL implementations when computing +endpoint-pair shared secrets for DTLS/SCTP. This allows communication with +older broken implementations but breaks interoperability with correct +implementations. Must be used in conjunction with B<-sctp>. This option is only +available where OpenSSL has support for SCTP enabled. + =item B<-no_dhe> If this option is set then no DH parameters will be loaded effectively @@ -825,7 +834,7 @@ unknown cipher suites a client says it supports. L, L, L, L L, L, -L +L =head1 HISTORY diff --git a/doc/man3/EVP_MAC.pod b/doc/man3/EVP_MAC.pod index 0e0d749b..32bf5896 100644 --- a/doc/man3/EVP_MAC.pod +++ b/doc/man3/EVP_MAC.pod @@ -87,9 +87,6 @@ through diverse controls. This should be called before calling EVP_MAC_update() and EVP_MAC_final(). -EVP_MAC_reset() resets the computation for the given context. -This may not be supported by the MAC implementation. - EVP_MAC_update() adds C bytes from C to the MAC input. EVP_MAC_final() does the final computation and stores the result in @@ -171,18 +168,23 @@ Some MAC implementations require an IV, this control sets the IV. =item B -This control expects two arguments: C, C +This control expects two arguments: C, C -Some MAC implementations (KMAC) require an Customization String, +Some MAC implementations (KMAC, BLAKE2) accept a Customization String, this control sets the Customization String. The default value is "". +=item B + +This control expects two arguments: C, C + +This option is used by BLAKE2 MAC. + =item B This control expects one argument: C This option is used by KMAC. - =item B This control expects one argument: C @@ -231,7 +233,7 @@ created EVP_MAC_CTX, or NULL if allocation failed. EVP_MAC_CTX_free() returns nothing at all. -EVP_MAC_CTX_copy(), EVP_MAC_reset(), EVP_MAC_init(), EVP_MAC_update(), +EVP_MAC_CTX_copy(), EVP_MAC_init(), EVP_MAC_update(), and EVP_MAC_final() return 1 on success, 0 on error. EVP_MAC_ctrl(), EVP_MAC_ctrl_str(), EVP_MAC_str2ctrl() and @@ -346,6 +348,7 @@ F<./foo>) =head1 SEE ALSO +L, L, L, L, diff --git a/doc/man3/EVP_PKEY_CTX_ctrl.pod b/doc/man3/EVP_PKEY_CTX_ctrl.pod index e09a2fe7..5b35156f 100644 --- a/doc/man3/EVP_PKEY_CTX_ctrl.pod +++ b/doc/man3/EVP_PKEY_CTX_ctrl.pod @@ -23,6 +23,8 @@ EVP_PKEY_CTX_get_rsa_oaep_md, EVP_PKEY_CTX_set0_rsa_oaep_label, EVP_PKEY_CTX_get0_rsa_oaep_label, EVP_PKEY_CTX_set_dsa_paramgen_bits, +EVP_PKEY_CTX_set_dsa_paramgen_q_bits, +EVP_PKEY_CTX_set_dsa_paramgen_md, EVP_PKEY_CTX_set_dh_paramgen_prime_len, EVP_PKEY_CTX_set_dh_paramgen_subprime_len, EVP_PKEY_CTX_set_dh_paramgen_generator, @@ -93,6 +95,8 @@ EVP_PKEY_CTX_set1_id, EVP_PKEY_CTX_get1_id, EVP_PKEY_CTX_get1_id_len #include int EVP_PKEY_CTX_set_dsa_paramgen_bits(EVP_PKEY_CTX *ctx, int nbits); + int EVP_PKEY_CTX_set_dsa_paramgen_q_bits(EVP_PKEY_CTX *ctx, int qbits); + int EVP_PKEY_CTX_set_dsa_paramgen_md(EVP_PKEY_CTX *ctx, const EVP_MD *md); #include @@ -255,7 +259,17 @@ by the library and should not be freed by the caller. =head2 DSA parameters The EVP_PKEY_CTX_set_dsa_paramgen_bits() macro sets the number of bits used -for DSA parameter generation to B. If not specified 1024 is used. +for DSA parameter generation to B. If not specified, 1024 is used. + +The EVP_PKEY_CTX_set_dsa_paramgen_q_bits() macro sets the number of bits in the +subprime parameter B for DSA parameter generation to B. If not +specified, 160 is used. If a digest function is specified below, this parameter +is ignored and instead, the number of bits in B matches the size of the +digest. + +The EVP_PKEY_CTX_set_dsa_paramgen_md() macro sets the digest function used for +DSA parameter generation to B. If not specified, one of SHA-1, SHA-224, or +SHA-256 is selected to match the bit length of B above. =head2 DH parameters diff --git a/doc/man3/EVP_PKEY_asn1_get_count.pod b/doc/man3/EVP_PKEY_asn1_get_count.pod index 24e14fe3..19d1e364 100644 --- a/doc/man3/EVP_PKEY_asn1_get_count.pod +++ b/doc/man3/EVP_PKEY_asn1_get_count.pod @@ -48,7 +48,7 @@ engine that implements it. EVP_PKEY_asn1_get0_info() returns the public key ID, base public key ID (both NIDs), any flags, the method description and PEM type string -associated with the public key ASN.1 method B<*ameth>. +associated with the public key ASN.1 method B<*ameth>. EVP_PKEY_asn1_count(), EVP_PKEY_asn1_get0(), EVP_PKEY_asn1_find() and EVP_PKEY_asn1_find_str() are not thread safe, but as long as all diff --git a/doc/man3/HMAC.pod b/doc/man3/HMAC.pod index 5c851c1f..10a72506 100644 --- a/doc/man3/HMAC.pod +++ b/doc/man3/HMAC.pod @@ -91,7 +91,7 @@ because reuse of an existing key with a different digest is not supported. HMAC_Init() initializes a B structure to use the hash function B and the key B which is B bytes -long. +long. HMAC_Update() can be called repeatedly with chunks of the message to be authenticated (B bytes at B). diff --git a/doc/man3/OPENSSL_malloc.pod b/doc/man3/OPENSSL_malloc.pod index e17ff633..f1de27a1 100644 --- a/doc/man3/OPENSSL_malloc.pod +++ b/doc/man3/OPENSSL_malloc.pod @@ -90,10 +90,8 @@ generally macro's that add the standard C B<__FILE__> and B<__LINE__> parameters and call a lower-level B API. Some functions do not add those parameters, but exist for consistency. -OPENSSL_malloc_init() sets the lower-level memory allocation functions -to their default implementation. -It is generally not necessary to call this, except perhaps in certain -shared-library situations. +OPENSSL_malloc_init() does nothing and does not need to be called. It is +included for compatibility with older versions of OpenSSL. OPENSSL_malloc(), OPENSSL_realloc(), and OPENSSL_free() are like the C malloc(), realloc(), and free() functions. diff --git a/doc/man3/SSL_CTX_set0_CA_list.pod b/doc/man3/SSL_CTX_set0_CA_list.pod index 67601583..64e8117f 100644 --- a/doc/man3/SSL_CTX_set0_CA_list.pod +++ b/doc/man3/SSL_CTX_set0_CA_list.pod @@ -101,7 +101,7 @@ set CA names using the "client CA list" functions and then get them using the used on the server side then the "client CA list" functions take precedence. Typically, on the server side, the "client CA list " functions should be used in preference. As noted above in most cases it is not necessary to set CA names on -the client side. +the client side. SSL_CTX_set0_CA_list() sets the list of CAs to be sent to the peer to B. Ownership of B is transferred to B and diff --git a/doc/man3/SSL_CTX_set_ctlog_list_file.pod b/doc/man3/SSL_CTX_set_ctlog_list_file.pod index 98ddb974..d99659ba 100644 --- a/doc/man3/SSL_CTX_set_ctlog_list_file.pod +++ b/doc/man3/SSL_CTX_set_ctlog_list_file.pod @@ -24,7 +24,7 @@ See L for the file format. =head1 NOTES These functions will not clear the existing CT log list - it will be appended -to. To replace the existing list, use L first. +to. To replace the existing list, use L first. If an error occurs whilst parsing a particular log entry in the file, that log entry will be skipped. diff --git a/doc/man3/SSL_CTX_set_mode.pod b/doc/man3/SSL_CTX_set_mode.pod index 06e9a29c..a4997c96 100644 --- a/doc/man3/SSL_CTX_set_mode.pod +++ b/doc/man3/SSL_CTX_set_mode.pod @@ -121,6 +121,15 @@ Kernel TLS might not support all the features of OpenSSL. For instance, renegotiation, and setting the maximum fragment size is not possible as of Linux 4.20. +=item SSL_MODE_DTLS_SCTP_LABEL_LENGTH_BUG + +Older versions of OpenSSL had a bug in the computation of the label length +used for computing the endpoint-pair shared secret. The bug was that the +terminating zero was included in the length of the label. Setting this option +enables this behaviour to allow interoperability with such broken +implementations. Please note that setting this option breaks interoperability +with correct implementations. This option only applies to DTLS over SCTP. + =back All modes are off by default except for SSL_MODE_AUTO_RETRY which is on by diff --git a/doc/man3/SSL_CTX_set_record_padding_callback.pod b/doc/man3/SSL_CTX_set_record_padding_callback.pod index 4bf87c8b..3df66218 100644 --- a/doc/man3/SSL_CTX_set_record_padding_callback.pod +++ b/doc/man3/SSL_CTX_set_record_padding_callback.pod @@ -19,10 +19,10 @@ SSL_set_block_padding - install callback to specify TLS 1.3 record padding void SSL_set_record_padding_callback(SSL *ssl, size_t (*cb)(SSL *s, int type, size_t len, void *arg)); void SSL_CTX_set_record_padding_callback_arg(SSL_CTX *ctx, void *arg); - void *SSL_CTX_get_record_padding_callback_arg(SSL_CTX *ctx); + void *SSL_CTX_get_record_padding_callback_arg(const SSL_CTX *ctx); void SSL_set_record_padding_callback_arg(SSL *ssl, void *arg); - void *SSL_get_record_padding_callback_arg(SSL *ssl); + void *SSL_get_record_padding_callback_arg(const SSL *ssl); int SSL_CTX_set_block_padding(SSL_CTX *ctx, size_t block_size); int SSL_set_block_padding(SSL *ssl, size_t block_size); diff --git a/doc/man3/SSL_CTX_set_ssl_version.pod b/doc/man3/SSL_CTX_set_ssl_version.pod index 0671b533..b4107311 100644 --- a/doc/man3/SSL_CTX_set_ssl_version.pod +++ b/doc/man3/SSL_CTX_set_ssl_version.pod @@ -11,7 +11,7 @@ SSL_CTX_set_ssl_version, SSL_set_ssl_method, SSL_get_ssl_method int SSL_CTX_set_ssl_version(SSL_CTX *ctx, const SSL_METHOD *method); int SSL_set_ssl_method(SSL *s, const SSL_METHOD *method); - const SSL_METHOD *SSL_get_ssl_method(SSL *ssl); + const SSL_METHOD *SSL_get_ssl_method(const SSL *ssl); =head1 DESCRIPTION diff --git a/doc/man3/SSL_key_update.pod b/doc/man3/SSL_key_update.pod index 61021436..f95d89e4 100644 --- a/doc/man3/SSL_key_update.pod +++ b/doc/man3/SSL_key_update.pod @@ -14,11 +14,11 @@ SSL_renegotiate_pending #include int SSL_key_update(SSL *s, int updatetype); - int SSL_get_key_update_type(SSL *s); + int SSL_get_key_update_type(const SSL *s); int SSL_renegotiate(SSL *s); int SSL_renegotiate_abbreviated(SSL *s); - int SSL_renegotiate_pending(SSL *s); + int SSL_renegotiate_pending(const SSL *s); =head1 DESCRIPTION diff --git a/doc/man3/SSL_read_early_data.pod b/doc/man3/SSL_read_early_data.pod index e87c1450..91a79bdd 100644 --- a/doc/man3/SSL_read_early_data.pod +++ b/doc/man3/SSL_read_early_data.pod @@ -93,7 +93,7 @@ the server. A client uses the function SSL_write_early_data() to send early data. This function is similar to the L function, but with the following differences. See L for information on how to write bytes to -the underlying connection, and how to handle any errors that may arise. This +the underlying connection, and how to handle any errors that may arise. This page describes the differences between SSL_write_early_data() and L. diff --git a/doc/man3/d2i_PrivateKey.pod b/doc/man3/d2i_PrivateKey.pod index 87ac8a85..eab98b3d 100644 --- a/doc/man3/d2i_PrivateKey.pod +++ b/doc/man3/d2i_PrivateKey.pod @@ -50,15 +50,19 @@ If the B<*a> is not NULL when calling d2i_PrivateKey() or d2i_AutoPrivateKey() (i.e. an existing structure is being reused) and the key format is PKCS#8 then B<*a> will be freed and replaced on a successful call. +To decode a key with type B, d2i_PublicKey() requires B<*a> to be +a non-NULL EVP_PKEY structure assigned an EC_KEY structure referencing the proper +EC_GROUP. + =head1 RETURN VALUES -d2i_PrivateKey() and d2i_AutoPrivateKey() return a valid B structure -or B if an error occurs. The error code can be obtained by calling -L. +The d2i_PrivateKey(), d2i_AutoPrivateKey(), d2i_PrivateKey_bio(), d2i_PrivateKey_fp(), +and d2i_PublicKey() functions return a valid B structure or B if an +error occurs. The error code can be obtained by calling L. -i2d_PrivateKey() returns the number of bytes successfully encoded or a -negative value if an error occurs. The error code can be obtained by calling -L. +i2d_PrivateKey() and i2d_PublicKey() return the number of bytes successfully +encoded or a negative value if an error occurs. The error code can be obtained +by calling L. =head1 SEE ALSO @@ -67,7 +71,7 @@ L =head1 COPYRIGHT -Copyright 2017-2018 The OpenSSL Project Authors. All Rights Reserved. +Copyright 2017-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/man7/EVP_MAC_BLAKE2.pod b/doc/man7/EVP_MAC_BLAKE2.pod new file mode 100644 index 00000000..58b4f993 --- /dev/null +++ b/doc/man7/EVP_MAC_BLAKE2.pod @@ -0,0 +1,114 @@ +=pod + +=head1 NAME + +EVP_MAC_BLAKE2 - The BLAKE2 EVP_MAC implementation + +=head1 DESCRIPTION + +Support for computing BLAKE2 MACs through the B API. + +=head2 Numeric identity + +B and B are the numeric identities for this +implementation, and can be used in functions like EVP_MAC_CTX_new_id() and +EVP_get_macbynid(). + +=head2 Supported controls + +The supported controls are: + +=over 4 + +=item B + +This is a string value of at most 64 bytes for EVP_MAC_BLAKE2B +or 32 for EVP_MAC_BLAKE2S and at least 1 byte in both cases. +This must be set before calling EVP_MAC_init(). + +EVP_MAC_ctrl_str() takes two type strings for this control: + +=over 4 + +=item "key" + +The value string is used as is. + +=item "hexkey" + +The value string is expected to be a hexadecimal number, which will be +decoded before passing on as control value. + +=back + +=item B + +This is an optional string value of at most 16 bytes for EVP_MAC_BLAKE2B +or 8 for EVP_MAC_BLAKE2S, set to all-NULL by default. +If used this must be set before calling EVP_MAC_init(). + +EVP_MAC_ctrl_str() takes two type strings for this control: + +=over 4 + +=item "custom" + +The value string is used as is. + +=item "hexcustom" + +The value string is expected to be a hexadecimal number, which will be +decoded before passing on as control value. + +=back + +=item B + +This is an optional string value of at most 16 bytes for EVP_MAC_BLAKE2B +or 8 for EVP_MAC_BLAKE2S, set to all-NULL by default. +If used this must be set before calling EVP_MAC_init(). + +EVP_MAC_ctrl_str() takes two type strings for this control: + +=over 4 + +=item "salt" + +The value string is used as is. + +=item "hexsalt" + +The value string is expected to be a hexadecimal number, which will be +decoded before passing on as control value. + +=back + +=item B + +EVP_MAC_ctrl_str() type string: "outlen" + +This is an optional value string containing a decimal number between 1 and +32 for EVP_MAC_BLAKE2S or 64 for EVP_MAC_BLAKE2B. +If it is not set it uses the default digest size of 32 and 64 respectively. +If used this must be set before calling EVP_MAC_init(). + +=back + +=head1 SEE ALSO + +L, L + +=head1 HISTORY + +The macros and functions described here were added to OpenSSL 3.0.0. + +=head1 COPYRIGHT + +Copyright 2018 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/include/internal/thread_once.h b/include/internal/thread_once.h index dcb0c689..033e9705 100644 --- a/include/internal/thread_once.h +++ b/include/internal/thread_once.h @@ -13,7 +13,7 @@ * DEFINE_RUN_ONCE: Define an initialiser function that should be run exactly * once. It takes no arguments and returns and int result (1 for success or * 0 for failure). Typical usage might be: - * + * * DEFINE_RUN_ONCE(myinitfunc) * { * do_some_initialisation(); @@ -45,7 +45,7 @@ * exactly once. This function will be declared as static within the file. It * takes no arguments and returns and int result (1 for success or 0 for * failure). Typical usage might be: - * + * * DEFINE_RUN_ONCE_STATIC(myinitfunc) * { * do_some_initialisation(); @@ -74,10 +74,10 @@ * is used only one of the primary or the alternative initialiser function will * ever be called - and that function will be called exactly once. Definitition * of an alternative initialiser function MUST occur AFTER the definition of the - * primiary initialiser function. - * + * primiary initialiser function. + * * Typical usage might be: - * + * * DEFINE_RUN_ONCE_STATIC(myinitfunc) * { * do_some_initialisation(); @@ -86,7 +86,7 @@ * * return 0; * } - * + * * DEFINE_RUN_ONCE_STATIC_ALT(myaltinitfunc, myinitfunc) * { * do_some_alternative_initialisation(); diff --git a/include/internal/tsan_assist.h b/include/internal/tsan_assist.h index b1664659..5bf30c41 100644 --- a/include/internal/tsan_assist.h +++ b/include/internal/tsan_assist.h @@ -6,7 +6,7 @@ * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html */ - + /* * Contemporary compilers implement lock-free atomic memory access * primitives that facilitate writing "thread-opportunistic" or even real diff --git a/include/openssl/crypto.h b/include/openssl/crypto.h index f9123021..cbde3d5e 100644 --- a/include/openssl/crypto.h +++ b/include/openssl/crypto.h @@ -109,13 +109,8 @@ DEFINE_STACK_OF(void) # define CRYPTO_EX_INDEX_DRBG 15 # define CRYPTO_EX_INDEX__COUNT 16 -/* - * This is the default callbacks, but we can have others as well: this is - * needed in Win32 where the application malloc and the library malloc may - * not be the same. - */ -#define OPENSSL_malloc_init() \ - CRYPTO_set_mem_functions(CRYPTO_malloc, CRYPTO_realloc, CRYPTO_free) +/* No longer needed, so this is a no-op */ +#define OPENSSL_malloc_init() while(0) continue int CRYPTO_mem_ctrl(int mode); diff --git a/include/openssl/dsa.h b/include/openssl/dsa.h index a9df8cc4..ea01aafd 100644 --- a/include/openssl/dsa.h +++ b/include/openssl/dsa.h @@ -162,6 +162,12 @@ DH *DSA_dup_DH(const DSA *r); # define EVP_PKEY_CTX_set_dsa_paramgen_bits(ctx, nbits) \ EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DSA, EVP_PKEY_OP_PARAMGEN, \ EVP_PKEY_CTRL_DSA_PARAMGEN_BITS, nbits, NULL) +# define EVP_PKEY_CTX_set_dsa_paramgen_q_bits(ctx, qbits) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DSA, EVP_PKEY_OP_PARAMGEN, \ + EVP_PKEY_CTRL_DSA_PARAMGEN_Q_BITS, qbits, NULL) +# define EVP_PKEY_CTX_set_dsa_paramgen_md(ctx, md) \ + EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DSA, EVP_PKEY_OP_PARAMGEN, \ + EVP_PKEY_CTRL_DSA_PARAMGEN_MD, 0, (void *)(md)) # define EVP_PKEY_CTRL_DSA_PARAMGEN_BITS (EVP_PKEY_ALG_CTRL + 1) # define EVP_PKEY_CTRL_DSA_PARAMGEN_Q_BITS (EVP_PKEY_ALG_CTRL + 2) diff --git a/include/openssl/evp.h b/include/openssl/evp.h index 774f102e..c90c6435 100644 --- a/include/openssl/evp.h +++ b/include/openssl/evp.h @@ -959,14 +959,9 @@ const EVP_CIPHER *EVP_sm4_ctr(void); | OPENSSL_INIT_ADD_ALL_DIGESTS, NULL) # ifdef OPENSSL_LOAD_CONF -# define OpenSSL_add_all_algorithms() \ - OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_CIPHERS \ - | OPENSSL_INIT_ADD_ALL_DIGESTS \ - | OPENSSL_INIT_LOAD_CONFIG, NULL) +# define OpenSSL_add_all_algorithms() OPENSSL_add_all_algorithms_conf() # else -# define OpenSSL_add_all_algorithms() \ - OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_CIPHERS \ - | OPENSSL_INIT_ADD_ALL_DIGESTS, NULL) +# define OpenSSL_add_all_algorithms() OPENSSL_add_all_algorithms_noconf() # endif # define OpenSSL_add_all_ciphers() \ @@ -999,6 +994,8 @@ void EVP_MD_do_all_sorted(void (*fn) /* MAC stuff */ +# define EVP_MAC_BLAKE2B NID_blake2bmac +# define EVP_MAC_BLAKE2S NID_blake2smac # define EVP_MAC_CMAC NID_cmac # define EVP_MAC_GMAC NID_gmac # define EVP_MAC_HMAC NID_hmac @@ -1043,6 +1040,7 @@ void EVP_MAC_do_all_sorted(void (*fn) # define EVP_MAC_CTRL_SET_IV 0x07 /* unsigned char *, size_t */ # define EVP_MAC_CTRL_SET_CUSTOM 0x08 /* unsigned char *, size_t */ # define EVP_MAC_CTRL_SET_XOF 0x09 /* int */ +# define EVP_MAC_CTRL_SET_SALT 0x0a /* unsigned char *, size_t */ /* PKEY stuff */ int EVP_PKEY_decrypt_old(unsigned char *dec_key, diff --git a/include/openssl/evperr.h b/include/openssl/evperr.h index 0f78d368..d3ed5b5a 100644 --- a/include/openssl/evperr.h +++ b/include/openssl/evperr.h @@ -32,6 +32,10 @@ int ERR_load_EVP_strings(void); # define EVP_F_ARIA_GCM_INIT_KEY 176 # define EVP_F_ARIA_INIT_KEY 185 # define EVP_F_B64_NEW 198 +# define EVP_F_BLAKE2B_MAC_CTRL 220 +# define EVP_F_BLAKE2B_MAC_INIT 221 +# define EVP_F_BLAKE2S_MAC_CTRL 222 +# define EVP_F_BLAKE2S_MAC_INIT 223 # define EVP_F_CAMELLIA_INIT_KEY 159 # define EVP_F_CHACHA20_POLY1305_CTRL 182 # define EVP_F_CMLL_T4_INIT_KEY 179 @@ -168,6 +172,7 @@ int ERR_load_EVP_strings(void); # define EVP_R_INVALID_KEY 163 # define EVP_R_INVALID_KEY_LENGTH 130 # define EVP_R_INVALID_OPERATION 148 +# define EVP_R_INVALID_SALT_LENGTH 186 # define EVP_R_KEYGEN_FAILURE 120 # define EVP_R_KEY_SETUP_FAILED 180 # define EVP_R_MEMORY_LIMIT_EXCEEDED 172 diff --git a/include/openssl/obj_mac.h b/include/openssl/obj_mac.h index c8960d0e..a9b34124 100644 --- a/include/openssl/obj_mac.h +++ b/include/openssl/obj_mac.h @@ -57,6 +57,14 @@ #define LN_kmac256 "kmac256" #define NID_kmac256 1197 +#define SN_blake2bmac "BLAKE2BMAC" +#define LN_blake2bmac "blake2bmac" +#define NID_blake2bmac 1201 + +#define SN_blake2smac "BLAKE2SMAC" +#define LN_blake2smac "blake2smac" +#define NID_blake2smac 1202 + #define SN_hmac_md5 "HMAC-MD5" #define LN_hmac_md5 "hmac-md5" #define NID_hmac_md5 780 @@ -4826,7 +4834,7 @@ #define SN_chacha20_poly1305_draft "ChaCha20-Poly1305-D" #define LN_chacha20_poly1305_draft "chacha20-poly1305-draft" -#define NID_chacha20_poly1305_draft 1201 +#define NID_chacha20_poly1305_draft 1203 #define SN_dhpublicnumber "dhpublicnumber" #define LN_dhpublicnumber "X9.42 DH" diff --git a/include/openssl/ssl.h b/include/openssl/ssl.h index 8aa02066..c2bce682 100644 --- a/include/openssl/ssl.h +++ b/include/openssl/ssl.h @@ -501,6 +501,18 @@ typedef int (*SSL_async_callback_fn)(SSL *s, void *arg); * Use the kernel TLS transmission data-path. */ # define SSL_MODE_NO_KTLS_TX 0x00000200U +/* + * When using DTLS/SCTP, include the terminating zero in the label + * used for computing the endpoint-pair shared secret. Required for + * interoperability with implementations having this bug like these + * older version of OpenSSL: + * - OpenSSL 1.0.0 series + * - OpenSSL 1.0.1 series + * - OpenSSL 1.0.2 series + * - OpenSSL 1.1.0 series + * - OpenSSL 1.1.1 and 1.1.1a + */ +# define SSL_MODE_DTLS_SCTP_LABEL_LENGTH_BUG 0x00000400U /* Cert related flags */ /* @@ -1920,17 +1932,17 @@ __owur STACK_OF(SSL_CIPHER) *SSL_get1_supported_ciphers(SSL *s); __owur int SSL_do_handshake(SSL *s); int SSL_key_update(SSL *s, int updatetype); -int SSL_get_key_update_type(SSL *s); +int SSL_get_key_update_type(const SSL *s); int SSL_renegotiate(SSL *s); int SSL_renegotiate_abbreviated(SSL *s); -__owur int SSL_renegotiate_pending(SSL *s); +__owur int SSL_renegotiate_pending(const SSL *s); int SSL_shutdown(SSL *s); __owur int SSL_verify_client_post_handshake(SSL *s); void SSL_CTX_set_post_handshake_auth(SSL_CTX *ctx, int val); void SSL_set_post_handshake_auth(SSL *s, int val); -__owur const SSL_METHOD *SSL_CTX_get_ssl_method(SSL_CTX *ctx); -__owur const SSL_METHOD *SSL_get_ssl_method(SSL *s); +__owur const SSL_METHOD *SSL_CTX_get_ssl_method(const SSL_CTX *ctx); +__owur const SSL_METHOD *SSL_get_ssl_method(const SSL *s); __owur int SSL_set_ssl_method(SSL *s, const SSL_METHOD *method); __owur const char *SSL_alert_type_string_long(int value); __owur const char *SSL_alert_type_string(int value); @@ -2078,8 +2090,8 @@ void SSL_set_tmp_dh_callback(SSL *ssl, int keylength)); # endif -__owur const COMP_METHOD *SSL_get_current_compression(SSL *s); -__owur const COMP_METHOD *SSL_get_current_expansion(SSL *s); +__owur const COMP_METHOD *SSL_get_current_compression(const SSL *s); +__owur const COMP_METHOD *SSL_get_current_expansion(const SSL *s); __owur const char *SSL_COMP_get_name(const COMP_METHOD *comp); __owur const char *SSL_COMP_get0_name(const SSL_COMP *comp); __owur int SSL_COMP_get_id(const SSL_COMP *comp); @@ -2123,20 +2135,20 @@ void SSL_CTX_set_record_padding_callback(SSL_CTX *ctx, size_t (*cb) (SSL *ssl, int type, size_t len, void *arg)); void SSL_CTX_set_record_padding_callback_arg(SSL_CTX *ctx, void *arg); -void *SSL_CTX_get_record_padding_callback_arg(SSL_CTX *ctx); +void *SSL_CTX_get_record_padding_callback_arg(const SSL_CTX *ctx); int SSL_CTX_set_block_padding(SSL_CTX *ctx, size_t block_size); void SSL_set_record_padding_callback(SSL *ssl, size_t (*cb) (SSL *ssl, int type, size_t len, void *arg)); void SSL_set_record_padding_callback_arg(SSL *ssl, void *arg); -void *SSL_get_record_padding_callback_arg(SSL *ssl); +void *SSL_get_record_padding_callback_arg(const SSL *ssl); int SSL_set_block_padding(SSL *ssl, size_t block_size); int SSL_set_num_tickets(SSL *s, size_t num_tickets); -size_t SSL_get_num_tickets(SSL *s); +size_t SSL_get_num_tickets(const SSL *s); int SSL_CTX_set_num_tickets(SSL_CTX *ctx, size_t num_tickets); -size_t SSL_CTX_get_num_tickets(SSL_CTX *ctx); +size_t SSL_CTX_get_num_tickets(const SSL_CTX *ctx); # if !OPENSSL_API_1_1_0 # define SSL_cache_hit(s) SSL_session_reused(s) diff --git a/include/openssl/tls1.h b/include/openssl/tls1.h index e145b178..4fa1d8a3 100644 --- a/include/openssl/tls1.h +++ b/include/openssl/tls1.h @@ -32,16 +32,6 @@ extern "C" { # define TLS_MAX_VERSION TLS1_3_VERSION # endif -/* TODO(TLS1.3) REMOVE ME: Version indicators for draft version */ -# define TLS1_3_VERSION_DRAFT_23 0x7f17 -# define TLS1_3_VERSION_DRAFT_26 0x7f1a -# define TLS1_3_VERSION_DRAFT_27 0x7f1b -# define TLS1_3_VERSION_DRAFT 0x7f1c -# define TLS1_3_VERSION_DRAFT_TXT_23 "TLS 1.3 (draft 23)" -# define TLS1_3_VERSION_DRAFT_TXT_26 "TLS 1.3 (draft 26)" -# define TLS1_3_VERSION_DRAFT_TXT_27 "TLS 1.3 (draft 27)" -# define TLS1_3_VERSION_DRAFT_TXT "TLS 1.3 (draft 28)" - /* Special value for method supporting multiple versions */ # define TLS_ANY_VERSION 0x10000 diff --git a/ssl/record/ssl3_record_tls13.c b/ssl/record/ssl3_record_tls13.c index 4f1c2f2b..30e5dddf 100644 --- a/ssl/record/ssl3_record_tls13.c +++ b/ssl/record/ssl3_record_tls13.c @@ -173,9 +173,8 @@ int tls13_enc(SSL *s, SSL3_RECORD *recs, size_t n_recs, int sending) if (((alg_enc & SSL_AESCCM) != 0 && EVP_CipherUpdate(ctx, NULL, &lenu, NULL, (unsigned int)rec->length) <= 0) - || (s->version_draft != TLS1_3_VERSION_DRAFT_23 - && EVP_CipherUpdate(ctx, NULL, &lenu, recheader, - sizeof(recheader)) <= 0) + || EVP_CipherUpdate(ctx, NULL, &lenu, recheader, + sizeof(recheader)) <= 0 || EVP_CipherUpdate(ctx, rec->data, &lenu, rec->input, (unsigned int)rec->length) <= 0 || EVP_CipherFinal_ex(ctx, rec->data + lenu, &lenf) <= 0 diff --git a/ssl/ssl_lib.c b/ssl/ssl_lib.c index e8e2e189..e12f0c3d 100644 --- a/ssl/ssl_lib.c +++ b/ssl/ssl_lib.c @@ -2240,7 +2240,7 @@ int SSL_key_update(SSL *s, int updatetype) return 1; } -int SSL_get_key_update_type(SSL *s) +int SSL_get_key_update_type(const SSL *s) { return s->key_update; } @@ -2281,7 +2281,7 @@ int SSL_renegotiate_abbreviated(SSL *s) return s->method->ssl_renegotiate(s); } -int SSL_renegotiate_pending(SSL *s) +int SSL_renegotiate_pending(const SSL *s) { /* * becomes true when negotiation is requested; false again once a @@ -3565,12 +3565,12 @@ void ssl_update_cache(SSL *s, int mode) } } -const SSL_METHOD *SSL_CTX_get_ssl_method(SSL_CTX *ctx) +const SSL_METHOD *SSL_CTX_get_ssl_method(const SSL_CTX *ctx) { return ctx->method; } -const SSL_METHOD *SSL_get_ssl_method(SSL *s) +const SSL_METHOD *SSL_get_ssl_method(const SSL *s) { return s->method; } @@ -4010,7 +4010,7 @@ const SSL_CIPHER *SSL_get_pending_cipher(const SSL *s) return s->s3->tmp.new_cipher; } -const COMP_METHOD *SSL_get_current_compression(SSL *s) +const COMP_METHOD *SSL_get_current_compression(const SSL *s) { #ifndef OPENSSL_NO_COMP return s->compress ? COMP_CTX_get_method(s->compress) : NULL; @@ -4019,7 +4019,7 @@ const COMP_METHOD *SSL_get_current_compression(SSL *s) #endif } -const COMP_METHOD *SSL_get_current_expansion(SSL *s) +const COMP_METHOD *SSL_get_current_expansion(const SSL *s) { #ifndef OPENSSL_NO_COMP return s->expand ? COMP_CTX_get_method(s->expand) : NULL; @@ -4467,7 +4467,7 @@ void SSL_CTX_set_record_padding_callback_arg(SSL_CTX *ctx, void *arg) ctx->record_padding_arg = arg; } -void *SSL_CTX_get_record_padding_callback_arg(SSL_CTX *ctx) +void *SSL_CTX_get_record_padding_callback_arg(const SSL_CTX *ctx) { return ctx->record_padding_arg; } @@ -4496,7 +4496,7 @@ void SSL_set_record_padding_callback_arg(SSL *ssl, void *arg) ssl->record_padding_arg = arg; } -void *SSL_get_record_padding_callback_arg(SSL *ssl) +void *SSL_get_record_padding_callback_arg(const SSL *ssl) { return ssl->record_padding_arg; } @@ -4520,7 +4520,7 @@ int SSL_set_num_tickets(SSL *s, size_t num_tickets) return 1; } -size_t SSL_get_num_tickets(SSL *s) +size_t SSL_get_num_tickets(const SSL *s) { return s->num_tickets; } @@ -4532,7 +4532,7 @@ int SSL_CTX_set_num_tickets(SSL_CTX *ctx, size_t num_tickets) return 1; } -size_t SSL_CTX_get_num_tickets(SSL_CTX *ctx) +size_t SSL_CTX_get_num_tickets(const SSL_CTX *ctx) { return ctx->num_tickets; } diff --git a/ssl/ssl_locl.h b/ssl/ssl_locl.h index 5a095c95..41894e0a 100644 --- a/ssl/ssl_locl.h +++ b/ssl/ssl_locl.h @@ -1126,8 +1126,6 @@ struct ssl_st { * DTLS1_VERSION) */ int version; - /* TODO(TLS1.3): Remove this before release */ - int version_draft; /* SSLv3 */ const SSL_METHOD *method; /* diff --git a/ssl/statem/extensions_clnt.c b/ssl/statem/extensions_clnt.c index f26bc8e8..6e133e02 100644 --- a/ssl/statem/extensions_clnt.c +++ b/ssl/statem/extensions_clnt.c @@ -533,25 +533,8 @@ EXT_RETURN tls_construct_ctos_supported_versions(SSL *s, WPACKET *pkt, return EXT_RETURN_FAIL; } - /* - * TODO(TLS1.3): There is some discussion on the TLS list as to whether - * we should include versions = min_version; currv--) { - /* TODO(TLS1.3): Remove this first if clause prior to release!! */ - if (currv == TLS1_3_VERSION) { - if (!WPACKET_put_bytes_u16(pkt, TLS1_3_VERSION) - || !WPACKET_put_bytes_u16(pkt, TLS1_3_VERSION_DRAFT) - || !WPACKET_put_bytes_u16(pkt, TLS1_3_VERSION_DRAFT_27) - || !WPACKET_put_bytes_u16(pkt, TLS1_3_VERSION_DRAFT_26) - || !WPACKET_put_bytes_u16(pkt, TLS1_3_VERSION_DRAFT_23)) { - SSLfatal(s, SSL_AD_INTERNAL_ERROR, - SSL_F_TLS_CONSTRUCT_CTOS_SUPPORTED_VERSIONS, - ERR_R_INTERNAL_ERROR); - return EXT_RETURN_FAIL; - } - } else if (!WPACKET_put_bytes_u16(pkt, currv)) { + if (!WPACKET_put_bytes_u16(pkt, currv)) { SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CONSTRUCT_CTOS_SUPPORTED_VERSIONS, ERR_R_INTERNAL_ERROR); @@ -1780,15 +1763,6 @@ int tls_parse_stoc_supported_versions(SSL *s, PACKET *pkt, unsigned int context, return 0; } - /* TODO(TLS1.3): Remove this before release */ - if (version == TLS1_3_VERSION_DRAFT - || version == TLS1_3_VERSION_DRAFT_27 - || version == TLS1_3_VERSION_DRAFT_26 - || version == TLS1_3_VERSION_DRAFT_23) { - s->version_draft = version; - version = TLS1_3_VERSION; - } - /* * The only protocol version we support which is valid in this extension in * a ServerHello is TLSv1.3 therefore we shouldn't be getting anything else. diff --git a/ssl/statem/extensions_srvr.c b/ssl/statem/extensions_srvr.c index 15786a7b..6545f572 100644 --- a/ssl/statem/extensions_srvr.c +++ b/ssl/statem/extensions_srvr.c @@ -897,8 +897,7 @@ int tls_parse_ctos_cookie(SSL *s, PACKET *pkt, unsigned int context, X509 *x, } if (!WPACKET_put_bytes_u16(&hrrpkt, TLSEXT_TYPE_supported_versions) || !WPACKET_start_sub_packet_u16(&hrrpkt) - /* TODO(TLS1.3): Fix this before release */ - || !WPACKET_put_bytes_u16(&hrrpkt, s->version_draft) + || !WPACKET_put_bytes_u16(&hrrpkt, s->version) || !WPACKET_close(&hrrpkt)) { WPACKET_cleanup(&hrrpkt); SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_PARSE_CTOS_COOKIE, @@ -1653,8 +1652,7 @@ EXT_RETURN tls_construct_stoc_supported_versions(SSL *s, WPACKET *pkt, if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_supported_versions) || !WPACKET_start_sub_packet_u16(pkt) - /* TODO(TLS1.3): Update to remove the TLSv1.3 draft indicator */ - || !WPACKET_put_bytes_u16(pkt, s->version_draft) + || !WPACKET_put_bytes_u16(pkt, s->version) || !WPACKET_close(pkt)) { SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CONSTRUCT_STOC_SUPPORTED_VERSIONS, diff --git a/ssl/statem/statem_clnt.c b/ssl/statem/statem_clnt.c index 53bc5ef3..1f551133 100644 --- a/ssl/statem/statem_clnt.c +++ b/ssl/statem/statem_clnt.c @@ -1707,6 +1707,7 @@ MSG_PROCESS_RETURN tls_process_server_hello(SSL *s, PACKET *pkt) if (SSL_IS_DTLS(s) && s->hit) { unsigned char sctpauthkey[64]; char labelbuffer[sizeof(DTLS1_SCTP_AUTH_LABEL)]; + size_t labellen; /* * Add new shared key for SCTP-Auth, will be ignored if @@ -1715,10 +1716,15 @@ MSG_PROCESS_RETURN tls_process_server_hello(SSL *s, PACKET *pkt) memcpy(labelbuffer, DTLS1_SCTP_AUTH_LABEL, sizeof(DTLS1_SCTP_AUTH_LABEL)); + /* Don't include the terminating zero. */ + labellen = sizeof(labelbuffer) - 1; + if (s->mode & SSL_MODE_DTLS_SCTP_LABEL_LENGTH_BUG) + labellen += 1; + if (SSL_export_keying_material(s, sctpauthkey, sizeof(sctpauthkey), labelbuffer, - sizeof(labelbuffer), NULL, 0, 0) <= 0) { + labellen, NULL, 0, 0) <= 0) { SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_PROCESS_SERVER_HELLO, ERR_R_INTERNAL_ERROR); goto err; @@ -3397,6 +3403,7 @@ int tls_client_key_exchange_post_work(SSL *s) if (SSL_IS_DTLS(s)) { unsigned char sctpauthkey[64]; char labelbuffer[sizeof(DTLS1_SCTP_AUTH_LABEL)]; + size_t labellen; /* * Add new shared key for SCTP-Auth, will be ignored if no SCTP @@ -3405,9 +3412,14 @@ int tls_client_key_exchange_post_work(SSL *s) memcpy(labelbuffer, DTLS1_SCTP_AUTH_LABEL, sizeof(DTLS1_SCTP_AUTH_LABEL)); + /* Don't include the terminating zero. */ + labellen = sizeof(labelbuffer) - 1; + if (s->mode & SSL_MODE_DTLS_SCTP_LABEL_LENGTH_BUG) + labellen += 1; + if (SSL_export_keying_material(s, sctpauthkey, sizeof(sctpauthkey), labelbuffer, - sizeof(labelbuffer), NULL, 0, 0) <= 0) { + labellen, NULL, 0, 0) <= 0) { SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CLIENT_KEY_EXCHANGE_POST_WORK, ERR_R_INTERNAL_ERROR); diff --git a/ssl/statem/statem_lib.c b/ssl/statem/statem_lib.c index 5d5121d1..2f78a3f6 100644 --- a/ssl/statem/statem_lib.c +++ b/ssl/statem/statem_lib.c @@ -1770,8 +1770,6 @@ int ssl_choose_server_version(SSL *s, CLIENTHELLO_MSG *hello, DOWNGRADE *dgrd) unsigned int best_vers = 0; const SSL_METHOD *best_method = NULL; PACKET versionslist; - /* TODO(TLS1.3): Remove this before release */ - unsigned int orig_candidate = 0; suppversions->parsed = 1; @@ -1793,23 +1791,6 @@ int ssl_choose_server_version(SSL *s, CLIENTHELLO_MSG *hello, DOWNGRADE *dgrd) return SSL_R_BAD_LEGACY_VERSION; while (PACKET_get_net_2(&versionslist, &candidate_vers)) { - /* TODO(TLS1.3): Remove this before release */ - if (candidate_vers == TLS1_3_VERSION - || candidate_vers == TLS1_3_VERSION_DRAFT - || candidate_vers == TLS1_3_VERSION_DRAFT_26 - || candidate_vers == TLS1_3_VERSION_DRAFT_23) { - if (best_vers == TLS1_3_VERSION - && (orig_candidate > candidate_vers - || orig_candidate == TLS1_3_VERSION)) - continue; - orig_candidate = candidate_vers; - candidate_vers = TLS1_3_VERSION; - } - /* - * TODO(TLS1.3): There is some discussion on the TLS list about - * whether to ignore versions version = best_vers; - /* TODO(TLS1.3): Remove this before release */ - if (best_vers == TLS1_3_VERSION) - s->version_draft = orig_candidate; s->method = best_method; return 0; } diff --git a/ssl/statem/statem_srvr.c b/ssl/statem/statem_srvr.c index 1d096858..69c515c9 100644 --- a/ssl/statem/statem_srvr.c +++ b/ssl/statem/statem_srvr.c @@ -830,6 +830,7 @@ WORK_STATE ossl_statem_server_post_work(SSL *s, WORK_STATE wst) if (SSL_IS_DTLS(s) && s->hit) { unsigned char sctpauthkey[64]; char labelbuffer[sizeof(DTLS1_SCTP_AUTH_LABEL)]; + size_t labellen; /* * Add new shared key for SCTP-Auth, will be ignored if no @@ -838,9 +839,14 @@ WORK_STATE ossl_statem_server_post_work(SSL *s, WORK_STATE wst) memcpy(labelbuffer, DTLS1_SCTP_AUTH_LABEL, sizeof(DTLS1_SCTP_AUTH_LABEL)); + /* Don't include the terminating zero. */ + labellen = sizeof(labelbuffer) - 1; + if (s->mode & SSL_MODE_DTLS_SCTP_LABEL_LENGTH_BUG) + labellen += 1; + if (SSL_export_keying_material(s, sctpauthkey, sizeof(sctpauthkey), labelbuffer, - sizeof(labelbuffer), NULL, 0, + labellen, NULL, 0, 0) <= 0) { SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_OSSL_STATEM_SERVER_POST_WORK, @@ -3501,6 +3507,7 @@ WORK_STATE tls_post_process_client_key_exchange(SSL *s, WORK_STATE wst) if (SSL_IS_DTLS(s)) { unsigned char sctpauthkey[64]; char labelbuffer[sizeof(DTLS1_SCTP_AUTH_LABEL)]; + size_t labellen; /* * Add new shared key for SCTP-Auth, will be ignored if no SCTP * used. @@ -3508,9 +3515,14 @@ WORK_STATE tls_post_process_client_key_exchange(SSL *s, WORK_STATE wst) memcpy(labelbuffer, DTLS1_SCTP_AUTH_LABEL, sizeof(DTLS1_SCTP_AUTH_LABEL)); + /* Don't include the terminating zero. */ + labellen = sizeof(labelbuffer) - 1; + if (s->mode & SSL_MODE_DTLS_SCTP_LABEL_LENGTH_BUG) + labellen += 1; + if (SSL_export_keying_material(s, sctpauthkey, sizeof(sctpauthkey), labelbuffer, - sizeof(labelbuffer), NULL, 0, + labellen, NULL, 0, 0) <= 0) { SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_POST_PROCESS_CLIENT_KEY_EXCHANGE, diff --git a/ssl/t1_trce.c b/ssl/t1_trce.c index 654271f3..656fefe8 100644 --- a/ssl/t1_trce.c +++ b/ssl/t1_trce.c @@ -65,11 +65,6 @@ static const ssl_trace_tbl ssl_version_tbl[] = { {TLS1_1_VERSION, "TLS 1.1"}, {TLS1_2_VERSION, "TLS 1.2"}, {TLS1_3_VERSION, "TLS 1.3"}, - /* TODO(TLS1.3): Remove these lines before release */ - {TLS1_3_VERSION_DRAFT_23, TLS1_3_VERSION_DRAFT_TXT_23}, - {TLS1_3_VERSION_DRAFT_26, TLS1_3_VERSION_DRAFT_TXT_26}, - {TLS1_3_VERSION_DRAFT_27, TLS1_3_VERSION_DRAFT_TXT_27}, - {TLS1_3_VERSION_DRAFT, TLS1_3_VERSION_DRAFT_TXT}, {DTLS1_VERSION, "DTLS 1.0"}, {DTLS1_2_VERSION, "DTLS 1.2"}, {DTLS1_BAD_VER, "DTLS 1.0 (bad)"} @@ -643,19 +638,8 @@ static int ssl_print_version(BIO *bio, int indent, const char *name, if (*pmsglen < 2) return 0; vers = ((*pmsg)[0] << 8) | (*pmsg)[1]; - if (version != NULL) { - /* TODO(TLS1.3): Remove the draft conditional here before release */ - switch(vers) { - case TLS1_3_VERSION_DRAFT_23: - case TLS1_3_VERSION_DRAFT_26: - case TLS1_3_VERSION_DRAFT_27: - case TLS1_3_VERSION_DRAFT: - *version = TLS1_3_VERSION; - break; - default: - *version = vers; - } - } + if (version != NULL) + *version = vers; BIO_indent(bio, indent, 80); BIO_printf(bio, "%s=0x%x (%s)\n", name, vers, ssl_trace_str(vers, ssl_version_tbl)); diff --git a/test/README.external b/test/README.external index f836b1b4..2f5423cb 100644 --- a/test/README.external +++ b/test/README.external @@ -145,7 +145,7 @@ To update the commit for any of the above test suites: - Enter subdirectory and pull from the repository (use a specific branch/tag if required): - $ cd + $ cd $ git pull origin master - Go to root directory, there should be a new git status: diff --git a/test/build.info b/test/build.info index a7d31d45..0ac2fa76 100644 --- a/test/build.info +++ b/test/build.info @@ -9,7 +9,7 @@ SUBDIRS=ossl_shim "" -} IF[{- !$disabled{tests} -}] - LIBS{noinst}=libtestutil.a + LIBS{noinst,has_main}=libtestutil.a SOURCE[libtestutil.a]=testutil/basic_output.c testutil/output_helpers.c \ testutil/driver.c testutil/tests.c testutil/cb.c testutil/stanza.c \ testutil/format_output.c testutil/tap_bio.c \ @@ -17,13 +17,6 @@ IF[{- !$disabled{tests} -}] INCLUDE[libtestutil.a]=../include DEPEND[libtestutil.a]=../libcrypto - # Special hack for descrip.mms to include the MAIN object module - # explicitly. This will only be done if there isn't a 'main' in the - # program's object modules already. - BEGINRAW[descrip.mms] -INCLUDE_MAIN___test_libtestutil_OLB = /INCLUDE=main - ENDRAW[descrip.mms] - PROGRAMS{noinst}=\ versions \ aborttest test_test \ @@ -350,7 +343,7 @@ INCLUDE_MAIN___test_libtestutil_OLB = /INCLUDE=main SOURCE[drbg_cavs_test]=drbg_cavs_test.c drbg_cavs_data_ctr.c \ drbg_cavs_data_hash.c drbg_cavs_data_hmac.c - + INCLUDE[drbg_cavs_test]=../include . .. DEPEND[drbg_cavs_test]=../libcrypto libtestutil.a diff --git a/test/crltest.c b/test/crltest.c index 3b0fab77..6a2ef4e9 100644 --- a/test/crltest.c +++ b/test/crltest.c @@ -357,6 +357,20 @@ static int test_unknown_critical_crl(int n) return r; } +static int test_reuse_crl(void) +{ + X509_CRL *reused_crl = CRL_from_strings(kBasicCRL); + char *p; + BIO *b = glue2bio(kRevokedCRL, &p); + + reused_crl = PEM_read_bio_X509_CRL(b, &reused_crl, NULL, NULL); + + OPENSSL_free(p); + BIO_free(b); + X509_CRL_free(reused_crl); + return 1; +} + int setup_tests(void) { if (!TEST_ptr(test_root = X509_from_strings(kCRLTestRoot)) @@ -368,6 +382,7 @@ int setup_tests(void) ADD_TEST(test_bad_issuer_crl); ADD_TEST(test_known_critical_crl); ADD_ALL_TESTS(test_unknown_critical_crl, OSSL_NELEM(unknown_critical_crls)); + ADD_TEST(test_reuse_crl); return 1; } diff --git a/test/drbgtest.c b/test/drbgtest.c index 4546f633..362a1d2b 100644 --- a/test/drbgtest.c +++ b/test/drbgtest.c @@ -429,7 +429,7 @@ static int error_check(DRBG_SELFTEST_DATA *td) */ /* Test explicit reseed with too large additional input */ - if (!init(drbg, td, &t) + if (!instantiate(drbg, td, &t) || RAND_DRBG_reseed(drbg, td->adin, drbg->max_adinlen + 1, 0) > 0) goto err; @@ -440,7 +440,7 @@ static int error_check(DRBG_SELFTEST_DATA *td) goto err; /* Test explicit reseed with too much entropy */ - if (!init(drbg, td, &t)) + if (!instantiate(drbg, td, &t)) goto err; t.entropylen = drbg->max_entropylen + 1; if (!TEST_int_le(RAND_DRBG_reseed(drbg, td->adin, td->adinlen, 0), 0) @@ -448,7 +448,7 @@ static int error_check(DRBG_SELFTEST_DATA *td) goto err; /* Test explicit reseed with too little entropy */ - if (!init(drbg, td, &t)) + if (!instantiate(drbg, td, &t)) goto err; t.entropylen = drbg->min_entropylen - 1; if (!TEST_int_le(RAND_DRBG_reseed(drbg, td->adin, td->adinlen, 0), 0) @@ -839,6 +839,11 @@ typedef HANDLE thread_t; static DWORD WINAPI thread_run(LPVOID arg) { run_multi_thread_test(); + /* + * Because we're linking with a static library, we must stop each + * thread explicitly, or so says OPENSSL_thread_stop(3) + */ + OPENSSL_thread_stop(); return 0; } @@ -860,6 +865,11 @@ typedef pthread_t thread_t; static void *thread_run(void *arg) { run_multi_thread_test(); + /* + * Because we're linking with a static library, we must stop each + * thread explicitly, or so says OPENSSL_thread_stop(3) + */ + OPENSSL_thread_stop(); return NULL; } diff --git a/test/evp_extra_test.c b/test/evp_extra_test.c index eefebd58..eac0c43b 100644 --- a/test/evp_extra_test.c +++ b/test/evp_extra_test.c @@ -299,6 +299,21 @@ static const unsigned char kExampleECPubKeyDER[] = { 0x56, 0x6a, 0xc6, 0xc8, 0xa5, 0x0b, 0xe5 }; +/* + * kExampleBadECKeyDER is a sample EC public key with a wrong OID + * 1.2.840.10045.2.2 instead of 1.2.840.10045.2.1 - EC Public Key + */ +static const unsigned char kExampleBadECPubKeyDER[] = { + 0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, + 0x02, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07, 0x03, + 0x42, 0x00, 0x04, 0xba, 0xeb, 0x83, 0xfb, 0x3b, 0xb2, 0xff, 0x30, 0x53, + 0xdb, 0xce, 0x32, 0xf2, 0xac, 0xae, 0x44, 0x0d, 0x3d, 0x13, 0x53, 0xb8, + 0xd1, 0x68, 0x55, 0xde, 0x44, 0x46, 0x05, 0xa6, 0xc9, 0xd2, 0x04, 0xb7, + 0xe3, 0xa2, 0x96, 0xc8, 0xb2, 0x5e, 0x22, 0x03, 0xd7, 0x03, 0x7a, 0x8b, + 0x13, 0x5c, 0x42, 0x49, 0xc2, 0xab, 0x86, 0xd6, 0xac, 0x6b, 0x93, 0x20, + 0x56, 0x6a, 0xc6, 0xc8, 0xa5, 0x0b, 0xe5 +}; + static const unsigned char pExampleECParamDER[] = { 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07 }; @@ -963,6 +978,37 @@ static int test_HKDF(void) return ret; } +#ifndef OPENSSL_NO_EC +static int test_X509_PUBKEY_inplace(void) +{ + int ret = 0; + X509_PUBKEY *xp = NULL; + const unsigned char *p = kExampleECPubKeyDER; + size_t input_len = sizeof(kExampleECPubKeyDER); + + if (!TEST_ptr(xp = d2i_X509_PUBKEY(NULL, &p, input_len))) + goto done; + + if (!TEST_ptr(X509_PUBKEY_get0(xp))) + goto done; + + p = kExampleBadECPubKeyDER; + input_len = sizeof(kExampleBadECPubKeyDER); + + if (!TEST_ptr(xp = d2i_X509_PUBKEY(&xp, &p, input_len))) + goto done; + + if (!TEST_true(X509_PUBKEY_get0(xp) == NULL)) + goto done; + + ret = 1; + +done: + X509_PUBKEY_free(xp); + return ret; +} +#endif + int setup_tests(void) { ADD_TEST(test_EVP_DigestSignInit); @@ -987,5 +1033,8 @@ int setup_tests(void) return 0; ADD_ALL_TESTS(test_EVP_PKEY_check, OSSL_NELEM(keycheckdata)); ADD_TEST(test_HKDF); +#ifndef OPENSSL_NO_EC + ADD_TEST(test_X509_PUBKEY_inplace); +#endif return 1; } diff --git a/test/evp_test.c b/test/evp_test.c index eaedab2c..932b03c6 100644 --- a/test/evp_test.c +++ b/test/evp_test.c @@ -864,6 +864,9 @@ typedef struct mac_data_st { size_t output_len; unsigned char *custom; size_t custom_len; + /* MAC salt (blake2) */ + unsigned char *salt; + size_t salt_len; /* Collection of controls */ STACK_OF(OPENSSL_STRING) *controls; } MAC_DATA; @@ -947,6 +950,7 @@ static void mac_test_cleanup(EVP_TEST *t) OPENSSL_free(mdat->key); OPENSSL_free(mdat->iv); OPENSSL_free(mdat->custom); + OPENSSL_free(mdat->salt); OPENSSL_free(mdat->input); OPENSSL_free(mdat->output); } @@ -962,6 +966,8 @@ static int mac_test_parse(EVP_TEST *t, return parse_bin(value, &mdata->iv, &mdata->iv_len); if (strcmp(keyword, "Custom") == 0) return parse_bin(value, &mdata->custom, &mdata->custom_len); + if (strcmp(keyword, "Salt") == 0) + return parse_bin(value, &mdata->salt, &mdata->salt_len); if (strcmp(keyword, "Algorithm") == 0) { mdata->alg = OPENSSL_strdup(value); if (!mdata->alg) @@ -1156,6 +1162,18 @@ static int mac_test_run_mac(EVP_TEST *t) } } + if (expected->salt != NULL) { + rv = EVP_MAC_ctrl(ctx, EVP_MAC_CTRL_SET_SALT, + expected->salt, expected->salt_len); + if (rv == -2) { + t->err = "MAC_CTRL_INVALID"; + goto err; + } else if (rv <= 0) { + t->err = "MAC_CTRL_ERROR"; + goto err; + } + } + if (expected->iv != NULL) { rv = EVP_MAC_ctrl(ctx, EVP_MAC_CTRL_SET_IV, expected->iv, expected->iv_len); @@ -1168,10 +1186,6 @@ static int mac_test_run_mac(EVP_TEST *t) } } - if (!EVP_MAC_init(ctx)) { - t->err = "MAC_INIT_ERROR"; - goto err; - } for (i = 0; i < sk_OPENSSL_STRING_num(expected->controls); i++) { char *p, *tmpval; char *value = sk_OPENSSL_STRING_value(expected->controls, i); @@ -1193,6 +1207,10 @@ static int mac_test_run_mac(EVP_TEST *t) goto err; } } + if (!EVP_MAC_init(ctx)) { + t->err = "MAC_INIT_ERROR"; + goto err; + } if (!EVP_MAC_update(ctx, expected->input, expected->input_len)) { t->err = "MAC_UPDATE_ERROR"; goto err; diff --git a/test/handshake_helper.c b/test/handshake_helper.c index a9ef753d..a85d22e3 100644 --- a/test/handshake_helper.c +++ b/test/handshake_helper.c @@ -22,6 +22,10 @@ #include "handshake_helper.h" #include "testutil.h" +#if !defined(OPENSSL_NO_SCTP) && !defined(OPENSSL_NO_SOCK) +#include +#endif + HANDSHAKE_RESULT *HANDSHAKE_RESULT_new(void) { HANDSHAKE_RESULT *ret; @@ -1282,13 +1286,33 @@ static int peer_pkey_type(SSL *s) #if !defined(OPENSSL_NO_SCTP) && !defined(OPENSSL_NO_SOCK) static int set_sock_as_sctp(int sock) { + struct sctp_assocparams assocparams; + struct sctp_rtoinfo rto_info; + BIO *tmpbio; + + /* + * To allow tests to fail fast (within a second or so), reduce the + * retransmission timeouts and the number of retransmissions. + */ + memset(&rto_info, 0, sizeof(struct sctp_rtoinfo)); + rto_info.srto_initial = 100; + rto_info.srto_max = 200; + rto_info.srto_min = 50; + (void)setsockopt(sock, IPPROTO_SCTP, SCTP_RTOINFO, + (const void *)&rto_info, sizeof(struct sctp_rtoinfo)); + memset(&assocparams, 0, sizeof(struct sctp_assocparams)); + assocparams.sasoc_asocmaxrxt = 2; + (void)setsockopt(sock, IPPROTO_SCTP, SCTP_ASSOCINFO, + (const void *)&assocparams, + sizeof(struct sctp_assocparams)); + /* * For SCTP we have to set various options on the socket prior to * connecting. This is done automatically by BIO_new_dgram_sctp(). * We don't actually need the created BIO though so we free it again * immediately. */ - BIO *tmpbio = BIO_new_dgram_sctp(sock, BIO_NOCLOSE); + tmpbio = BIO_new_dgram_sctp(sock, BIO_NOCLOSE); if (tmpbio == NULL) return 0; @@ -1438,6 +1462,13 @@ static HANDSHAKE_RESULT *do_handshake_internal( return NULL; } +#if !defined(OPENSSL_NO_SCTP) && !defined(OPENSSL_NO_SOCK) + if (test_ctx->enable_client_sctp_label_bug) + SSL_CTX_set_mode(client_ctx, SSL_MODE_DTLS_SCTP_LABEL_LENGTH_BUG); + if (test_ctx->enable_server_sctp_label_bug) + SSL_CTX_set_mode(server_ctx, SSL_MODE_DTLS_SCTP_LABEL_LENGTH_BUG); +#endif + /* Setup SSL and buffers; additional configuration happens below. */ if (!create_peer(&server, server_ctx)) { TEST_note("creating server context"); diff --git a/test/rdrand_sanitytest.c b/test/rdrand_sanitytest.c index 0f2b70ee..851e14cc 100644 --- a/test/rdrand_sanitytest.c +++ b/test/rdrand_sanitytest.c @@ -1,6 +1,6 @@ /* * Copyright 2018 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 @@ -24,7 +24,7 @@ void OPENSSL_cpuid_setup(void); extern unsigned int OPENSSL_ia32cap_P[4]; -static int sanity_check_bytes(size_t (*rng)(unsigned char *, size_t), +static int sanity_check_bytes(size_t (*rng)(unsigned char *, size_t), int rounds, int min_failures, int max_retries, int max_zero_words) { int testresult = 0; diff --git a/test/recipes/30-test_evp_data/evpmac.txt b/test/recipes/30-test_evp_data/evpmac.txt index ba691c55..732c8c4d 100644 --- a/test/recipes/30-test_evp_data/evpmac.txt +++ b/test/recipes/30-test_evp_data/evpmac.txt @@ -167,6 +167,236 @@ Ctrl = digestsize:13 Key = 000102030405060708090A0B0C0D0E0F Result = EVPPKEYCTXCTRL_ERROR +Title = Keyed BLAKE2 tests (Test vectors from reference implementation) + +MAC = BLAKE2BMAC +Key = 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f +Input = +Output = 10ebb67700b1868efb4417987acf4690ae9d972fb7a590c2f02871799aaa4786b5e996e8f0f4eb981fc214b005f42d2ff4233499391653df7aefcbc13fc51568 + +MAC = BLAKE2BMAC +Key = 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f +Input = 00 +Output = 961f6dd1e4dd30f63901690c512e78e4b45e4742ed197c3c5e45c549fd25f2e4187b0bc9fe30492b16b0d0bc4ef9b0f34c7003fac09a5ef1532e69430234cebd + +MAC = BLAKE2BMAC +Key = 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f +Input = 0001 +Output = da2cfbe2d8409a0f38026113884f84b50156371ae304c4430173d08a99d9fb1b983164a3770706d537f49e0c916d9f32b95cc37a95b99d857436f0232c88a965 + +MAC = BLAKE2BMAC +Key = 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f +Input = 000102 +Output = 33d0825dddf7ada99b0e7e307104ad07ca9cfd9692214f1561356315e784f3e5a17e364ae9dbb14cb2036df932b77f4b292761365fb328de7afdc6d8998f5fc1 + +MAC = BLAKE2BMAC +Key = 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f +Input = 00010203 +Output = beaa5a3d08f3807143cf621d95cd690514d0b49efff9c91d24b59241ec0eefa5f60196d407048bba8d2146828ebcb0488d8842fd56bb4f6df8e19c4b4daab8ac + +MAC = BLAKE2BMAC +Key = 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f +Input = 0001020304 +Output = 098084b51fd13deae5f4320de94a688ee07baea2800486689a8636117b46c1f4c1f6af7f74ae7c857600456a58a3af251dc4723a64cc7c0a5ab6d9cac91c20bb + +MAC = BLAKE2BMAC +Key = 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f +Input = 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9 +Output = 1085d78307b1c4b008c57a2e7e5b234658a0a82e4ff1e4aaac72b312fda0fe27d233bc5b10e9cc17fdc7697b540c7d95eb215a19a1a0e20e1abfa126efd568c7 + +MAC = BLAKE2BMAC +Key = 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f +Input = 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fa +Output = 4e5c734c7dde011d83eac2b7347b373594f92d7091b9ca34cb9c6f39bdf5a8d2f134379e16d822f6522170ccf2ddd55c84b9e6c64fc927ac4cf8dfb2a17701f2 + +MAC = BLAKE2BMAC +Key = 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f +Input = 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafb +Output = 695d83bd990a1117b3d0ce06cc888027d12a054c2677fd82f0d4fbfc93575523e7991a5e35a3752e9b70ce62992e268a877744cdd435f5f130869c9a2074b338 + +MAC = BLAKE2BMAC +Key = 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f +Input = 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfc +Output = a6213743568e3b3158b9184301f3690847554c68457cb40fc9a4b8cfd8d4a118c301a07737aeda0f929c68913c5f51c80394f53bff1c3e83b2e40ca97eba9e15 + +MAC = BLAKE2BMAC +Key = 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f +Input = 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfd +Output = d444bfa2362a96df213d070e33fa841f51334e4e76866b8139e8af3bb3398be2dfaddcbc56b9146de9f68118dc5829e74b0c28d7711907b121f9161cb92b69a9 + +MAC = BLAKE2BMAC +Key = 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f +Input = 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfe +Output = 142709d62e28fcccd0af97fad0f8465b971e82201dc51070faa0372aa43e92484be1c1e73ba10906d5d1853db6a4106e0a7bf9800d373d6dee2d46d62ef2a461 + +MAC = BLAKE2SMAC +Key = 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f +Input = +Output = 48a8997da407876b3d79c0d92325ad3b89cbb754d86ab71aee047ad345fd2c49 + +MAC = BLAKE2SMAC +Key = 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f +Input = 00 +Output = 40d15fee7c328830166ac3f918650f807e7e01e177258cdc0a39b11f598066f1 + +MAC = BLAKE2SMAC +Key = 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f +Input = 0001 +Output = 6bb71300644cd3991b26ccd4d274acd1adeab8b1d7914546c1198bbe9fc9d803 + +MAC = BLAKE2SMAC +Key = 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f +Input = 000102 +Output = 1d220dbe2ee134661fdf6d9e74b41704710556f2f6e5a091b227697445dbea6b + +MAC = BLAKE2SMAC +Key = 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f +Input = 00010203 +Output = f6c3fbadb4cc687a0064a5be6e791bec63b868ad62fba61b3757ef9ca52e05b2 + +MAC = BLAKE2SMAC +Key = 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f +Input = 0001020304 +Output = 49c1f21188dfd769aea0e911dd6b41f14dab109d2b85977aa3088b5c707e8598 + +MAC = BLAKE2SMAC +Key = 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f +Input = 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9 +Output = 9fc5450109e1b779f6c7ae79d56c27635c8dd426c5a9d54e2578db989b8c3b4e + +MAC = BLAKE2SMAC +Key = 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f +Input = 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fa +Output = d12bf3732ef4af5c22fa90356af8fc50fcb40f8f2ea5c8594737a3b3d5abdbd7 + +MAC = BLAKE2SMAC +Key = 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f +Input = 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafb +Output = 11030b9289bba5af65260672ab6fee88b87420acef4a1789a2073b7ec2f2a09e + +MAC = BLAKE2SMAC +Key = 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f +Input = 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfc +Output = 69cb192b8444005c8c0ceb12c846860768188cda0aec27a9c8a55cdee2123632 + +MAC = BLAKE2SMAC +Key = 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f +Input = 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfd +Output = db444c15597b5f1a03d1f9edd16e4a9f43a667cc275175dfa2b704e3bb1a9b83 + +MAC = BLAKE2SMAC +Key = 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f +Input = 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfe +Output = 3fb735061abc519dfe979e54c1ee5bfad0a9d858b3315bad34bde999efd724dd + +Title = Custom keyed BLAKE2 tests + +MAC = BLAKE2BMAC +Key = 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f +Custom = "email" +Input = "Sample input for keylen 28; # = scalar @conf_srcs +plan tests => 29; # = scalar @conf_srcs # Some test results depend on the configuration of enabled protocols. We only # verify generated sources in the default configuration. @@ -102,6 +102,7 @@ my %skip = ( "24-padding.conf" => disabled("tls1_3"), "25-cipher.conf" => disabled("ec") || disabled("tls1_2"), "26-tls13_client_auth.conf" => disabled("tls1_3"), + "29-dtls-sctp-label-bug.conf" => disabled("sctp") || disabled("sock"), ); foreach my $conf (@conf_files) { diff --git a/test/recipes/90-test_shlibload.t b/test/recipes/90-test_shlibload.t index 1f097eda..fee56cd2 100644 --- a/test/recipes/90-test_shlibload.t +++ b/test/recipes/90-test_shlibload.t @@ -21,6 +21,7 @@ use platform; plan skip_all => "Test only supported in a shared build" if disabled("shared"); plan skip_all => "Test is disabled on AIX" if config('target') =~ m|^aix|; +plan skip_all => "Test only supported in a dso build" if disabled("dso"); plan tests => 10; diff --git a/test/servername_test.c b/test/servername_test.c index 0614d4bf..f84c1870 100644 --- a/test/servername_test.c +++ b/test/servername_test.c @@ -203,7 +203,7 @@ static int server_setup_sni(void) /* SNI should have been cleared during handshake */ goto end; } - + testresult = 1; end: SSL_free(serverssl); diff --git a/test/ssl-tests/29-dtls-sctp-label-bug.conf b/test/ssl-tests/29-dtls-sctp-label-bug.conf new file mode 100644 index 00000000..24f9e04f --- /dev/null +++ b/test/ssl-tests/29-dtls-sctp-label-bug.conf @@ -0,0 +1,116 @@ +# Generated with generate_ssl_tests.pl + +num_tests = 4 + +test-0 = 0-SCTPLabelBug-good1 +test-1 = 1-SCTPLabelBug-good2 +test-2 = 2-SCTPLabelBug-bad1 +test-3 = 3-SCTPLabelBug-bad2 +# =========================================================== + +[0-SCTPLabelBug-good1] +ssl_conf = 0-SCTPLabelBug-good1-ssl + +[0-SCTPLabelBug-good1-ssl] +server = 0-SCTPLabelBug-good1-server +client = 0-SCTPLabelBug-good1-client + +[0-SCTPLabelBug-good1-server] +Certificate = ${ENV::TEST_CERTS_DIR}/servercert.pem +CipherString = DEFAULT +PrivateKey = ${ENV::TEST_CERTS_DIR}/serverkey.pem + +[0-SCTPLabelBug-good1-client] +CipherString = DEFAULT +VerifyCAFile = ${ENV::TEST_CERTS_DIR}/rootcert.pem +VerifyMode = Peer + +[test-0] +EnableClientSCTPLabelBug = No +EnableServerSCTPLabelBug = No +ExpectedResult = Success +Method = DTLS +UseSCTP = Yes + + +# =========================================================== + +[1-SCTPLabelBug-good2] +ssl_conf = 1-SCTPLabelBug-good2-ssl + +[1-SCTPLabelBug-good2-ssl] +server = 1-SCTPLabelBug-good2-server +client = 1-SCTPLabelBug-good2-client + +[1-SCTPLabelBug-good2-server] +Certificate = ${ENV::TEST_CERTS_DIR}/servercert.pem +CipherString = DEFAULT +PrivateKey = ${ENV::TEST_CERTS_DIR}/serverkey.pem + +[1-SCTPLabelBug-good2-client] +CipherString = DEFAULT +VerifyCAFile = ${ENV::TEST_CERTS_DIR}/rootcert.pem +VerifyMode = Peer + +[test-1] +EnableClientSCTPLabelBug = Yes +EnableServerSCTPLabelBug = Yes +ExpectedResult = Success +Method = DTLS +UseSCTP = Yes + + +# =========================================================== + +[2-SCTPLabelBug-bad1] +ssl_conf = 2-SCTPLabelBug-bad1-ssl + +[2-SCTPLabelBug-bad1-ssl] +server = 2-SCTPLabelBug-bad1-server +client = 2-SCTPLabelBug-bad1-client + +[2-SCTPLabelBug-bad1-server] +Certificate = ${ENV::TEST_CERTS_DIR}/servercert.pem +CipherString = DEFAULT +PrivateKey = ${ENV::TEST_CERTS_DIR}/serverkey.pem + +[2-SCTPLabelBug-bad1-client] +CipherString = DEFAULT +VerifyCAFile = ${ENV::TEST_CERTS_DIR}/rootcert.pem +VerifyMode = Peer + +[test-2] +EnableClientSCTPLabelBug = Yes +EnableServerSCTPLabelBug = No +ExpectedResult = ClientFail +Method = DTLS +UseSCTP = Yes + + +# =========================================================== + +[3-SCTPLabelBug-bad2] +ssl_conf = 3-SCTPLabelBug-bad2-ssl + +[3-SCTPLabelBug-bad2-ssl] +server = 3-SCTPLabelBug-bad2-server +client = 3-SCTPLabelBug-bad2-client + +[3-SCTPLabelBug-bad2-server] +Certificate = ${ENV::TEST_CERTS_DIR}/servercert.pem +CipherString = DEFAULT +PrivateKey = ${ENV::TEST_CERTS_DIR}/serverkey.pem + +[3-SCTPLabelBug-bad2-client] +CipherString = DEFAULT +VerifyCAFile = ${ENV::TEST_CERTS_DIR}/rootcert.pem +VerifyMode = Peer + +[test-3] +EnableClientSCTPLabelBug = No +EnableServerSCTPLabelBug = Yes +ExpectedResult = ClientFail +Method = DTLS +UseSCTP = Yes + + diff --git a/test/ssl-tests/29-dtls-sctp-label-bug.conf.in b/test/ssl-tests/29-dtls-sctp-label-bug.conf.in new file mode 100644 index 00000000..ab04d052 --- /dev/null +++ b/test/ssl-tests/29-dtls-sctp-label-bug.conf.in @@ -0,0 +1,67 @@ +# -*- mode: perl; -*- +# Copyright 2019-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 + + +## Test SSL_MODE_DTLS_SCTP_LABEL_LENGTH_BUG handling + +use strict; +use warnings; + +package ssltests; +use OpenSSL::Test::Utils; + +our @tests = ( + { + name => "SCTPLabelBug-good1", + server => {}, + client => {}, + test => { + "Method" => "DTLS", + "UseSCTP" => "Yes", + "EnableClientSCTPLabelBug" => "No", + "EnableServerSCTPLabelBug" => "No", + "ExpectedResult" => "Success" + } + }, + { + name => "SCTPLabelBug-good2", + server => {}, + client => {}, + test => { + "Method" => "DTLS", + "UseSCTP" => "Yes", + "EnableClientSCTPLabelBug" => "Yes", + "EnableServerSCTPLabelBug" => "Yes", + "ExpectedResult" => "Success" + } + }, + { + name => "SCTPLabelBug-bad1", + server => {}, + client => {}, + test => { + "Method" => "DTLS", + "UseSCTP" => "Yes", + "EnableClientSCTPLabelBug" => "Yes", + "EnableServerSCTPLabelBug" => "No", + "ExpectedResult" => "ClientFail" + } + }, + { + name => "SCTPLabelBug-bad2", + server => {}, + client => {}, + test => { + "Method" => "DTLS", + "UseSCTP" => "Yes", + "EnableClientSCTPLabelBug" => "No", + "EnableServerSCTPLabelBug" => "Yes", + "ExpectedResult" => "ClientFail" + } + }, +); diff --git a/test/ssl_test_ctx.c b/test/ssl_test_ctx.c index 3b7cc3eb..6a3b66bc 100644 --- a/test/ssl_test_ctx.c +++ b/test/ssl_test_ctx.c @@ -446,6 +446,8 @@ const char *ssl_ct_validation_name(ssl_ct_validation_t mode) IMPLEMENT_SSL_TEST_BOOL_OPTION(SSL_TEST_CTX, test, resumption_expected) IMPLEMENT_SSL_TEST_BOOL_OPTION(SSL_TEST_SERVER_CONF, server, broken_session_ticket) IMPLEMENT_SSL_TEST_BOOL_OPTION(SSL_TEST_CTX, test, use_sctp) +IMPLEMENT_SSL_TEST_BOOL_OPTION(SSL_TEST_CTX, test, enable_client_sctp_label_bug) +IMPLEMENT_SSL_TEST_BOOL_OPTION(SSL_TEST_CTX, test, enable_server_sctp_label_bug) /* CertStatus */ @@ -669,6 +671,8 @@ static const ssl_test_ctx_option ssl_test_ctx_options[] = { { "ExpectedClientSignType", &parse_expected_client_sign_type }, { "ExpectedClientCANames", &parse_expected_client_ca_names }, { "UseSCTP", &parse_test_use_sctp }, + { "EnableClientSCTPLabelBug", &parse_test_enable_client_sctp_label_bug }, + { "EnableServerSCTPLabelBug", &parse_test_enable_server_sctp_label_bug }, { "ExpectedCipher", &parse_test_expected_cipher }, { "ExpectedSessionTicketAppData", &parse_test_expected_session_ticket_app_data }, }; diff --git a/test/ssl_test_ctx.h b/test/ssl_test_ctx.h index 8fa3af0a..3a21ac52 100644 --- a/test/ssl_test_ctx.h +++ b/test/ssl_test_ctx.h @@ -214,6 +214,10 @@ typedef struct { STACK_OF(X509_NAME) *expected_client_ca_names; /* Whether to use SCTP for the transport */ int use_sctp; + /* Enable SSL_MODE_DTLS_SCTP_LABEL_LENGTH_BUG on client side */ + int enable_client_sctp_label_bug; + /* Enable SSL_MODE_DTLS_SCTP_LABEL_LENGTH_BUG on server side */ + int enable_server_sctp_label_bug; /* Whether to expect a session id from the server */ ssl_session_id_t session_id_expected; char *expected_cipher; diff --git a/test/testutil/main.c b/test/testutil/main.c index 9dc651b6..8b30ac60 100644 --- a/test/testutil/main.c +++ b/test/testutil/main.c @@ -54,7 +54,7 @@ int main(int argc, char *argv[]) ret = pulldown_test_framework(ret); test_close_streams(); - return ret; + return ret; } const char *test_get_program_name(void) diff --git a/test/tls13secretstest.c b/test/tls13secretstest.c index e079b8d3..490e7c9d 100644 --- a/test/tls13secretstest.c +++ b/test/tls13secretstest.c @@ -18,7 +18,7 @@ /* * Based on the test vectors availble in: - * https://tools.ietf.org/html/draft-ietf-tls-tls13-vectors-06 + * https://tools.ietf.org/html/draft-ietf-tls-tls13-vectors-06 */ static unsigned char hs_start_hash[] = { diff --git a/test/x509aux.c b/test/x509aux.c index a9764ef2..4488aa68 100644 --- a/test/x509aux.c +++ b/test/x509aux.c @@ -30,6 +30,7 @@ static int test_certs(int num) typedef int (*i2d_X509_t)(X509 *, unsigned char **); int err = 0; BIO *fp = BIO_new_file(test_get_argument(num), "r"); + X509 *reuse = NULL; if (!TEST_ptr(fp)) return 0; @@ -91,6 +92,13 @@ static int test_certs(int num) err = 1; goto next; } + p = buf; + reuse = d2i(&reuse, &p, enclen); + if (reuse == NULL || X509_cmp (reuse, cert)) { + TEST_error("X509_cmp does not work with %s", name); + err = 1; + goto next; + } OPENSSL_free(buf); buf = NULL; @@ -139,6 +147,7 @@ static int test_certs(int num) OPENSSL_free(data); } BIO_free(fp); + X509_free(reuse); if (ERR_GET_REASON(ERR_peek_last_error()) == PEM_R_NO_START_LINE) { /* Reached end of PEM file */ diff --git a/util/indent.pro b/util/indent.pro index 443bddb1..3d3f747b 100644 --- a/util/indent.pro +++ b/util/indent.pro @@ -26,7 +26,7 @@ -nprs -npsl -nsc --ppi1 +-ppi1 -saf -sai -saw diff --git a/util/openssl-format-source b/util/openssl-format-source index 5f63a708..dc6a65d3 100755 --- a/util/openssl-format-source +++ b/util/openssl-format-source @@ -8,18 +8,18 @@ # https://www.openssl.org/source/license.html # -# openssl-format-source +# openssl-format-source # - format source tree according to OpenSSL coding style using indent # # usage: # openssl-format-source [-v] [-n] [file|directory] ... # # note: the indent options assume GNU indent v2.2.10 which was released -# Feb-2009 so if you have an older indent the options may not +# Feb-2009 so if you have an older indent the options may not # match what is expected # # any marked block comment blocks have to be moved to align manually after -# the reformatting has been completed as marking a block causes indent to +# the reformatting has been completed as marking a block causes indent to # not move it at all ... # @@ -55,17 +55,17 @@ fi # Extra arguments; for adding the comment-formatting INDENT_ARGS="" -for i +for i do if [ "$STOPARGS" != "true" ]; then case $i in --) STOPARGS="true"; continue;; -n) DONT="true"; continue;; - -v) VERBOSE="true"; + -v) VERBOSE="true"; echo "INDENT_PROFILE=$INDENT_PROFILE"; continue;; - -c) COMMENTS="true"; - INDENT_ARGS="-fc1 -fca -cdb -sc"; + -c) COMMENTS="true"; + INDENT_ARGS="-fc1 -fca -cdb -sc"; continue;; -nc) COMMENTS="true"; continue;; @@ -76,14 +76,14 @@ do if [ -d "$i" ]; then LIST=`find "$i" -name '*.[ch]' -print` - else + else if [ ! -f "$i" ]; then echo "$0: source file not found: $i" >&2 exit 1 fi LIST="$i" fi - + for j in $LIST do # ignore symlinks - we only ever process the base file - so if we @@ -98,7 +98,7 @@ do tmp=$(mktemp /tmp/indent.XXXXXX) trap 'rm -f "$tmp"' HUP INT TERM EXIT - case `basename $j` in + case `basename $j` in # the list of files that indent is unable to handle correctly # that we simply leave alone for manual formatting now obj_dat.h|aes_core.c|aes_x86core.c|ecp_nistz256.c) @@ -108,11 +108,11 @@ do if [ "$COMMENTS" = "true" ]; then # we have to mark single line comments as /*- ...*/ to stop indent # messing with them, run expand then indent as usual but with the - # the process-comments options and then undo that marking, and then + # the process-comments options and then undo that marking, and then # finally re-run indent without process-comments so the marked-to- - # be-ignored comments we did automatically end up getting moved - # into the right position within the code as indent leaves marked - # comments entirely untouched - we appear to have no way to avoid + # be-ignored comments we did automatically end up getting moved + # into the right position within the code as indent leaves marked + # comments entirely untouched - we appear to have no way to avoid # the double processing and get the desired output cat "$j" | \ expand | \ diff --git a/util/perl/TLSProxy/Alert.pm b/util/perl/TLSProxy/Alert.pm index e4cff596..f63eeac8 100644 --- a/util/perl/TLSProxy/Alert.pm +++ b/util/perl/TLSProxy/Alert.pm @@ -16,7 +16,7 @@ sub new $encrypted, $level, $description) = @_; - + my $self = { server => $server, encrypted => $encrypted, diff --git a/util/perl/TLSProxy/Message.pm b/util/perl/TLSProxy/Message.pm index 71803698..bc5561c8 100644 --- a/util/perl/TLSProxy/Message.pm +++ b/util/perl/TLSProxy/Message.pm @@ -238,7 +238,7 @@ sub get_messages $startoffset = $recoffset; $recoffset += 4; $payload = ""; - + if ($recoffset <= $record->decrypt_len) { #Some payload data is present in this record if ($record->decrypt_len - $recoffset >= $messlen) { @@ -410,7 +410,7 @@ sub new $records, $startoffset, $message_frag_lens) = @_; - + my $self = { server => $server, data => $data, diff --git a/util/perl/TLSProxy/Proxy.pm b/util/perl/TLSProxy/Proxy.pm index 38213856..a583e636 100644 --- a/util/perl/TLSProxy/Proxy.pm +++ b/util/perl/TLSProxy/Proxy.pm @@ -44,7 +44,7 @@ BEGIN $s->close(); }; if ($@ eq "") { - $IP_factory = sub { IO::Socket::INET6->new(@_); }; + $IP_factory = sub { IO::Socket::INET6->new(Domain => AF_INET6, @_); }; $have_IPv6 = 1; } else { eval { diff --git a/util/perl/TLSProxy/Record.pm b/util/perl/TLSProxy/Record.pm index 18ee98db..183aa056 100644 --- a/util/perl/TLSProxy/Record.pm +++ b/util/perl/TLSProxy/Record.pm @@ -173,7 +173,7 @@ sub new $decrypt_len, $data, $decrypt_data) = @_; - + my $self = { flight => $flight, content_type => $content_type, diff --git a/util/perl/TLSProxy/ServerHello.pm b/util/perl/TLSProxy/ServerHello.pm index 14eb813d..ab7f2c8f 100644 --- a/util/perl/TLSProxy/ServerHello.pm +++ b/util/perl/TLSProxy/ServerHello.pm @@ -25,7 +25,7 @@ sub new $records, $startoffset, $message_frag_lens) = @_; - + my $self = $class->SUPER::new( $server, TLSProxy::Message::MT_SERVER_HELLO, @@ -78,7 +78,7 @@ sub parse my $extension_data; if ($extensions_len != 0) { $extension_data = substr($self->data, $ptr); - + if (length($extension_data) != $extensions_len) { die "Invalid extension length\n"; } diff --git a/util/perl/TLSProxy/ServerKeyExchange.pm b/util/perl/TLSProxy/ServerKeyExchange.pm index 11768a9f..e694c151 100644 --- a/util/perl/TLSProxy/ServerKeyExchange.pm +++ b/util/perl/TLSProxy/ServerKeyExchange.pm @@ -20,7 +20,7 @@ sub new $records, $startoffset, $message_frag_lens) = @_; - + my $self = $class->SUPER::new( $server, TLSProxy::Message::MT_SERVER_KEY_EXCHANGE, diff --git a/util/private.num b/util/private.num index 7a7c73f0..6fe43925 100644 --- a/util/private.num +++ b/util/private.num @@ -235,6 +235,8 @@ EVP_PKEY_CTX_set_dh_pad define EVP_PKEY_CTX_set_dh_rfc5114 define EVP_PKEY_CTX_set_dhx_rfc5114 define EVP_PKEY_CTX_set_dsa_paramgen_bits define +EVP_PKEY_CTX_set_dsa_paramgen_q_bits define +EVP_PKEY_CTX_set_dsa_paramgen_md define EVP_PKEY_CTX_set_ec_param_enc define EVP_PKEY_CTX_set_ec_paramgen_curve_nid define EVP_PKEY_CTX_set_ecdh_cofactor_mode define