openssl.git
2 years agoconst-ify some input SSL * arguments
Benjamin Kaduk [Wed, 30 May 2018 14:28:03 +0000 (09:28 -0500)]
const-ify some input SSL * arguments

These tiny functions only read from the input SSL, and we are
about to use them from functions that only have a const SSL* available,
so propagate const a bit further.

Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6378)

2 years agocrypto/*: address standard-compilance nits.
Andy Polyakov [Thu, 19 Jul 2018 13:28:34 +0000 (15:28 +0200)]
crypto/*: address standard-compilance nits.

Reviewed-by: Rich Salz <rsalz@openssl.org>
Reviewed-by: Kurt Roeckx <kurt@roeckx.be>
(Merged from https://github.com/openssl/openssl/pull/6745)

2 years agobio/bss_dgram.c: harmonize usage of OPENSSL_USE_IPV6 with the rest.
Andy Polyakov [Thu, 19 Jul 2018 13:27:24 +0000 (15:27 +0200)]
bio/bss_dgram.c: harmonize usage of OPENSSL_USE_IPV6 with the rest.

Reviewed-by: Rich Salz <rsalz@openssl.org>
Reviewed-by: Kurt Roeckx <kurt@roeckx.be>
(Merged from https://github.com/openssl/openssl/pull/6745)

2 years agoinclude/openssl/e_os2.h: define last-resort SSIZE_MAX.
Andy Polyakov [Thu, 19 Jul 2018 13:16:38 +0000 (15:16 +0200)]
include/openssl/e_os2.h: define last-resort SSIZE_MAX.

Reviewed-by: Rich Salz <rsalz@openssl.org>
Reviewed-by: Kurt Roeckx <kurt@roeckx.be>
(Merged from https://github.com/openssl/openssl/pull/6745)

2 years agoec/ec_lcl.h: fix pre-C9x compilation problems.
Andy Polyakov [Thu, 19 Jul 2018 12:45:06 +0000 (14:45 +0200)]
ec/ec_lcl.h: fix pre-C9x compilation problems.

Reviewed-by: Rich Salz <rsalz@openssl.org>
Reviewed-by: Kurt Roeckx <kurt@roeckx.be>
(Merged from https://github.com/openssl/openssl/pull/6745)

2 years ago.travis.yml: exercise -std=c89 in order to catch corresponding problems.
Andy Polyakov [Thu, 19 Jul 2018 10:30:26 +0000 (12:30 +0200)]
.travis.yml: exercise -std=c89 in order to catch corresponding problems.

Reviewed-by: Rich Salz <rsalz@openssl.org>
Reviewed-by: Kurt Roeckx <kurt@roeckx.be>
(Merged from https://github.com/openssl/openssl/pull/6745)

2 years agoValidate legacy_version
Matt Caswell [Thu, 19 Jul 2018 15:51:58 +0000 (16:51 +0100)]
Validate legacy_version

The spec says that a client MUST set legacy_version to TLSv1.2, and
requires servers to verify that it isn't SSLv3.

Fixes #6600

Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6747)

2 years agoUpdate the TLSv1.3 test vectors
Matt Caswell [Thu, 19 Jul 2018 11:46:02 +0000 (12:46 +0100)]
Update the TLSv1.3 test vectors

Use the latest version of the test vectors available in:
https://tools.ietf.org/html/draft-ietf-tls-tls13-vectors-06

Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6746)

2 years agoTest early_data sent after a second ClientHello causes a failure
Matt Caswell [Wed, 18 Jul 2018 11:29:36 +0000 (12:29 +0100)]
Test early_data sent after a second ClientHello causes a failure

Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6737)

2 years agoDon't skip over early_data if we sent an HRR
Matt Caswell [Wed, 18 Jul 2018 10:16:28 +0000 (11:16 +0100)]
Don't skip over early_data if we sent an HRR

It is not valid to send early_data after an HRR has been received.

Fixes #6734

Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6737)

2 years agoCHANGES: mention blinding reverting in ECDSA. [skip ci]
Andy Polyakov [Sun, 15 Jul 2018 15:59:59 +0000 (17:59 +0200)]
CHANGES: mention blinding reverting in ECDSA. [skip ci]

Reviewed-by: Rich Salz <rsalz@openssl.org>
Reviewed-by: David Benjamin <davidben@google.com>
(Merged from https://github.com/openssl/openssl/pull/6664)

2 years agoec/ecdsa_ossl.c: switch to fixed-length Montgomery multiplication.
Andy Polyakov [Thu, 12 Jul 2018 20:27:43 +0000 (22:27 +0200)]
ec/ecdsa_ossl.c: switch to fixed-length Montgomery multiplication.

Reviewed-by: Rich Salz <rsalz@openssl.org>
Reviewed-by: David Benjamin <davidben@google.com>
(Merged from https://github.com/openssl/openssl/pull/6664)

2 years agoec/ecdsa_ossl.c: formatting and readability fixes.
Andy Polyakov [Fri, 6 Jul 2018 14:13:29 +0000 (16:13 +0200)]
ec/ecdsa_ossl.c: formatting and readability fixes.

Reviewed-by: Rich Salz <rsalz@openssl.org>
Reviewed-by: David Benjamin <davidben@google.com>
(Merged from https://github.com/openssl/openssl/pull/6664)

2 years agoec/ecdsa_ossl.c: revert blinding in ECDSA signature.
Andy Polyakov [Fri, 6 Jul 2018 13:55:34 +0000 (15:55 +0200)]
ec/ecdsa_ossl.c: revert blinding in ECDSA signature.

Originally suggested solution for "Return Of the Hidden Number Problem"
is arguably too expensive. While it has marginal impact on slower
curves, none to ~6%, optimized implementations suffer real penalties.
Most notably sign with P-256 went more than 2 times[!] slower. Instead,
just implement constant-time BN_mod_add_quick.

Reviewed-by: Rich Salz <rsalz@openssl.org>
Reviewed-by: David Benjamin <davidben@google.com>
(Merged from https://github.com/openssl/openssl/pull/6664)

2 years agobn/bn_lib.c address Coverity nit in bn2binpad.
Andy Polyakov [Mon, 16 Jul 2018 16:17:44 +0000 (18:17 +0200)]
bn/bn_lib.c address Coverity nit in bn2binpad.

It was false positive, but one can as well view it as readability issue.
Switch even to unsigned indices because % BN_BYTES takes 4-6 instructions
with signed dividend vs. 1 (one) with unsigned.

Reviewed-by: Rich Salz <rsalz@openssl.org>
2 years agoAdd a test for mismatch between key OID and sig alg
Matt Caswell [Tue, 17 Jul 2018 16:29:08 +0000 (17:29 +0100)]
Add a test for mismatch between key OID and sig alg

Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6732)

2 years agoCheck that the public key OID matches the sig alg
Matt Caswell [Tue, 17 Jul 2018 15:31:07 +0000 (16:31 +0100)]
Check that the public key OID matches the sig alg

Using the rsa_pss_rsae_sha256 sig alg should imply that the key OID is
rsaEncryption. Similarly rsa_pss_pss_sha256 implies the key OID is
rsassaPss. However we did not check this and incorrectly tolerated a key
OID that did not match the sig alg sent by the peer.

Fixes #6611

Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6732)

2 years agoFix typo in x25519-x86_64.pl
Mat [Tue, 17 Jul 2018 13:48:27 +0000 (09:48 -0400)]
Fix typo in x25519-x86_64.pl

Reviewed-by: Tim Hudson <tjh@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6726)

2 years agoSkip the GOST test where appropriate
Matt Caswell [Tue, 17 Jul 2018 10:43:30 +0000 (11:43 +0100)]
Skip the GOST test where appropriate

The GOST ciphers are dynamically loaded via the GOST engine, so we must
be able to support that. The engine also uses DSA and CMS symbols, so we
skip the test on no-dsa or no-cms.

Reviewed-by: Tim Hudson <tjh@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6730)

2 years agoFix a memory leak in the ticket test
Matt Caswell [Tue, 17 Jul 2018 09:27:57 +0000 (10:27 +0100)]
Fix a memory leak in the ticket test

Also fixes a function name typo.

Reviewed-by: Bernd Edlinger <bernd.edlinger@hotmail.de>
(Merged from https://github.com/openssl/openssl/pull/6729)

2 years agoFix no-psk
Matt Caswell [Mon, 16 Jul 2018 16:31:37 +0000 (17:31 +0100)]
Fix no-psk

Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6724)

2 years agoTest that a failed resumption issues the correct number of tickets
Matt Caswell [Mon, 16 Jul 2018 15:58:23 +0000 (16:58 +0100)]
Test that a failed resumption issues the correct number of tickets

Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6722)

2 years agoAlways issue new tickets when using TLSv1.3 stateful tickets
Matt Caswell [Mon, 16 Jul 2018 15:57:36 +0000 (16:57 +0100)]
Always issue new tickets when using TLSv1.3 stateful tickets

Previously we were failing to issue new tickets if a resumption attempt
failed.

Fixes #6654

Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6722)

2 years agoImprove testing of stateful tickets
Matt Caswell [Thu, 5 Jul 2018 16:19:03 +0000 (17:19 +0100)]
Improve testing of stateful tickets

Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6722)

2 years agoDon't remove sessions from the cache during PHA in TLSv1.3
Matt Caswell [Mon, 16 Jul 2018 13:57:35 +0000 (14:57 +0100)]
Don't remove sessions from the cache during PHA in TLSv1.3

If we issue new tickets due to post-handshake authentication there is no
reason to remove previous tickets from the cache. The code that did that
only removed the last session anyway - so if more than one ticket got
issued then those other tickets are still valid.

Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6722)

2 years agoImprove documentation about reading and writing
Kurt Roeckx [Sun, 13 May 2018 09:24:11 +0000 (11:24 +0200)]
Improve documentation about reading and writing

Reviewed-by: Matt Caswell <matt@openssl.org>
GH: #6240

2 years agoEnable all protocols and ciphers in the fuzzer
Kurt Roeckx [Sun, 15 Jul 2018 11:49:53 +0000 (13:49 +0200)]
Enable all protocols and ciphers in the fuzzer

The config file can override it.
In case of the server, it needs to be set on the ctx or some of the
other functions on the ctx might file.

Reviewed-by: Rich Salz <rsalz@openssl.org>
DH: #6718

2 years agoEC2M Lopez-Dahab ladder: use it also for ECDSA verify
Nicola Tuveri [Sun, 8 Jul 2018 07:39:39 +0000 (10:39 +0300)]
EC2M Lopez-Dahab ladder: use it also for ECDSA verify

By default `ec_scalar_mul_ladder` (which uses the Lopez-Dahab ladder
implementation) is used only for (k * Generator) or (k * VariablePoint).
ECDSA verification uses (a * Generator + b * VariablePoint): this commit
forces the use of `ec_scalar_mul_ladder` also for the ECDSA verification
path, while using the default wNAF implementation for any other case.

With this commit `ec_scalar_mul_ladder` loses the static attribute, and
is added to ec_lcl.h so EC_METHODs can directly use it.

While working on a new custom EC_POINTs_mul implementation, I realized
that many checks (e.g. all the points being compatible with the given
EC_GROUP, creating a temporary BN_CTX if `ctx == NULL`, check for the
corner case `scalar == NULL && num == 0`) were duplicated again and
again in every single implementation (and actually some
implementations lacked some of the tests).
I thought that it makes way more sense for those checks that are
independent from the actual implementation and should always be done, to
be moved in the EC_POINTs_mul wrapper: so this commit also includes
these changes.

Reviewed-by: Andy Polyakov <appro@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6690)

2 years agoEC2M Lopez-Dahab ladder implementation
Nicola Tuveri [Fri, 13 Jul 2018 21:55:01 +0000 (00:55 +0300)]
EC2M Lopez-Dahab ladder implementation

This commit uses the new ladder scaffold to implement a specialized
ladder step based on differential addition-and-doubling in mixed
Lopez-Dahab projective coordinates, modified to independently blind the
operands.

The arithmetic in `ladder_pre`, `ladder_step` and `ladder_post` is
auto generated with tooling:
- see, e.g., "Guide to ECC" Alg 3.40 for reference about the
  `ladder_pre` implementation;
- see https://www.hyperelliptic.org/EFD/g12o/auto-code/shortw/xz/ladder/mladd-2003-s.op3
  for the differential addition-and-doubling formulas implemented in
  `ladder_step`;
- see, e.g., "Fast Multiplication on Elliptic Curves over GF(2**m)
  without Precomputation" (Lopez and Dahab, CHES 1999) Appendix Alg Mxy
  for the `ladder_post` implementation to recover the `(x,y)` result in
  affine coordinates.

Co-authored-by: Billy Brumley <bbrumley@gmail.com>
Co-authored-by: Sohaib ul Hassan <soh.19.hassan@gmail.com>
Reviewed-by: Andy Polyakov <appro@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6690)

2 years ago[test] test some important ladder corner cases
Billy Brumley [Sat, 7 Jul 2018 22:27:34 +0000 (01:27 +0300)]
[test] test some important ladder corner cases
and catch corner cases better and earlier

Reviewed-by: Andy Polyakov <appro@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6690)

2 years agoEC point multiplication: add `ladder` scaffold
Nicola Tuveri [Sat, 7 Jul 2018 21:50:49 +0000 (00:50 +0300)]
EC point multiplication: add `ladder` scaffold
for specialized Montgomery ladder implementations

PR #6009 and #6070 replaced the default EC point multiplication path for
prime and binary curves with a unified Montgomery ladder implementation
with various timing attack defenses (for the common paths when a secret
scalar is feed to the point multiplication).
The newly introduced default implementation directly used
EC_POINT_add/dbl in the main loop.

The scaffolding introduced by this commit allows EC_METHODs to define a
specialized `ladder_step` function to improve performances by taking
advantage of efficient formulas for differential addition-and-doubling
and different coordinate systems.

- `ladder_pre` is executed before the main loop of the ladder: by
  default it copies the input point P into S, and doubles it into R.
  Specialized implementations could, e.g., use this hook to transition
  to different coordinate systems before copying and doubling;
- `ladder_step` is the core of the Montgomery ladder loop: by default it
  computes `S := R+S; R := 2R;`, but specific implementations could,
  e.g., implement a more efficient formula for differential
  addition-and-doubling;
- `ladder_post` is executed after the Montgomery ladder loop: by default
  it's a noop, but specialized implementations could, e.g., use this
  hook to transition back from the coordinate system used for optimizing
  the differential addition-and-doubling or recover the y coordinate of
  the result point.

This commit also renames `ec_mul_consttime` to `ec_scalar_mul_ladder`,
as it better corresponds to what this function does: nothing can be
truly said about the constant-timeness of the overall execution of this
function, given that the underlying operations are not necessarily
constant-time themselves.
What this implementation ensures is that the same fixed sequence of
operations is executed for each scalar multiplication (for a given
EC_GROUP), with no dependency on the value of the input scalar.

Co-authored-by: Sohaib ul Hassan <soh.19.hassan@gmail.com>
Co-authored-by: Billy Brumley <bbrumley@gmail.com>
Reviewed-by: Andy Polyakov <appro@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6690)

2 years agoRemove stale SM2 error codes
Nicola Tuveri [Fri, 13 Jul 2018 08:48:29 +0000 (11:48 +0300)]
Remove stale SM2 error codes

Run `make update ERROR_REBUILD=-rebuild` to remove some stale error
codes for SM2 (which is now using its own submodule for error codes,
i.e., `SM2_*`).

Reviewed-by: Andy Polyakov <appro@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6690)

2 years agoec/curve25519.c: reorganize for better accessibility.
Andy Polyakov [Thu, 12 Jul 2018 09:53:16 +0000 (11:53 +0200)]
ec/curve25519.c: reorganize for better accessibility.

Move base 2^64 code to own #if section. It was nested in base 2^51 section,
which arguably might have been tricky to follow.

Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6699)

2 years agoec/asm/x25519-x86_64.pl: add CFI directives and Windows SE handler.
Andy Polyakov [Wed, 11 Jul 2018 20:36:49 +0000 (22:36 +0200)]
ec/asm/x25519-x86_64.pl: add CFI directives and Windows SE handler.

Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6699)

2 years agotest/.../evppkey.txt: X25519 regression test vectors.
Andy Polyakov [Wed, 11 Jul 2018 20:22:52 +0000 (22:22 +0200)]
test/.../evppkey.txt: X25519 regression test vectors.

Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6699)

2 years agoec/asm/x25519-x86_64.pl: fix base 2^64 add/sub and final reduction.
Andy Polyakov [Wed, 11 Jul 2018 20:08:02 +0000 (22:08 +0200)]
ec/asm/x25519-x86_64.pl: fix base 2^64 add/sub and final reduction.

Base 2^64 addition/subtraction and final reduction failed to treat
partially reduced values correctly.

Thanks to Wycheproof Project for vectors and Paul Kehrer for report.

Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6699)

2 years agobn/bn_lcl.h,bn_nist.c: addres strict warnings with -DBN_DEBUG.
Andy Polyakov [Thu, 12 Jul 2018 17:15:26 +0000 (19:15 +0200)]
bn/bn_lcl.h,bn_nist.c: addres strict warnings with -DBN_DEBUG.

Reviewed-by: Rich Salz <rsalz@openssl.org>
2 years agorsa/*: switch to BN_bn2binpad.
Andy Polyakov [Sun, 4 Feb 2018 14:24:54 +0000 (15:24 +0100)]
rsa/*: switch to BN_bn2binpad.

Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/5254)

2 years agobn/bn_lib.c: make BN_bn2binpad computationally constant-time.
Andy Polyakov [Sun, 4 Feb 2018 14:20:29 +0000 (15:20 +0100)]
bn/bn_lib.c: make BN_bn2binpad computationally constant-time.

"Computationally constant-time" means that it might still leak
information about input's length, but only in cases when input
is missing complete BN_ULONG limbs. But even then leak is possible
only if attacker can observe memory access pattern with limb
granularity.

Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/5254)

2 years agoAdd a GOST test
Matt Caswell [Fri, 13 Jul 2018 15:11:46 +0000 (16:11 +0100)]
Add a GOST test

Test that we never negotiate TLSv1.3 using GOST

Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6650)

2 years agoAs a server don't select TLSv1.3 if we're not capable of it
Matt Caswell [Wed, 4 Jul 2018 15:48:56 +0000 (16:48 +0100)]
As a server don't select TLSv1.3 if we're not capable of it

Check that we are either configured for PSK, or that we have a TLSv1.3
capable certificate type. DSA certs can't be used in TLSv1.3 and we
don't (currently) allow GOST ones either (owing to the lack of standard
sig algs).

Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6650)

2 years agoUse ssl_version_supported() when choosing server version
Matt Caswell [Wed, 4 Jul 2018 15:02:20 +0000 (16:02 +0100)]
Use ssl_version_supported() when choosing server version

Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6650)

2 years agoDo not use GOST sig algs in TLSv1.3 where possible
Matt Caswell [Tue, 3 Jul 2018 16:45:35 +0000 (17:45 +0100)]
Do not use GOST sig algs in TLSv1.3 where possible

Fixes #6513

Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6650)

2 years agoDocumentation typo fix in BN_bn2bin.pod
Alexandre Perrin [Fri, 13 Jul 2018 08:32:42 +0000 (10:32 +0200)]
Documentation typo fix in BN_bn2bin.pod

Change the description for BN_hex2bn() so that it uses the same BIGNUM argument name as its prototype.

CLA: trivial

Reviewed-by: Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com>
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6712)

2 years agoFix undefined behavior in s390x aes-gcm/ccm
Patrick Steuer [Thu, 12 Jul 2018 17:19:07 +0000 (13:19 -0400)]
Fix undefined behavior in s390x aes-gcm/ccm

Reviewed-by: Rich Salz <rsalz@openssl.org>
Reviewed-by: Andy Polyakov <appro@openssl.org>
2 years agobn/bn_{mont|exp}.c: switch to zero-padded intermediate vectors.
Andy Polyakov [Fri, 6 Jul 2018 13:13:15 +0000 (15:13 +0200)]
bn/bn_{mont|exp}.c: switch to zero-padded intermediate vectors.

Note that exported functions maintain original behaviour, so that
external callers won't observe difference. While internally we can
now perform Montogomery multiplication on fixed-length vectors, fixed
at modulus size. The new functions, bn_to_mont_fixed_top and
bn_mul_mont_fixed_top, are declared in bn_int.h, because one can use
them even outside bn, e.g. in RSA, DSA, ECDSA...

Reviewed-by: Rich Salz <rsalz@openssl.org>
Reviewed-by: David Benjamin <davidben@google.com>
(Merged from https://github.com/openssl/openssl/pull/6662)

2 years agobn/bn_lib.c: add BN_FLG_FIXED_TOP flag.
Andy Polyakov [Fri, 6 Jul 2018 13:02:29 +0000 (15:02 +0200)]
bn/bn_lib.c: add BN_FLG_FIXED_TOP flag.

The new flag marks vectors that were not treated with bn_correct_top,
in other words such vectors are permitted to be zero padded. For now
it's BN_DEBUG-only flag, as initial use case for zero-padded vectors
would be controlled Montgomery multiplication/exponentiation, not
general purpose. For general purpose use another type might be more
appropriate. Advantage of this suggestion is that it's possible to
back-port it...

bn/bn_div.c: fix memory sanitizer problem.
bn/bn_sqr.c: harmonize with BN_mul.

Reviewed-by: Rich Salz <rsalz@openssl.org>
Reviewed-by: David Benjamin <davidben@google.com>
(Merged from https://github.com/openssl/openssl/pull/6662)

2 years agobn/bn_mont.c: improve readability of post-condition code.
Andy Polyakov [Fri, 6 Jul 2018 12:54:34 +0000 (14:54 +0200)]
bn/bn_mont.c: improve readability of post-condition code.

Reviewed-by: Rich Salz <rsalz@openssl.org>
Reviewed-by: David Benjamin <davidben@google.com>
(Merged from https://github.com/openssl/openssl/pull/6662)

2 years agobn/bn_mont.c: move boundary condition check closer to caller.
Andy Polyakov [Fri, 6 Jul 2018 11:46:07 +0000 (13:46 +0200)]
bn/bn_mont.c: move boundary condition check closer to caller.

Reviewed-by: Rich Salz <rsalz@openssl.org>
Reviewed-by: David Benjamin <davidben@google.com>
(Merged from https://github.com/openssl/openssl/pull/6662)

2 years agobn/bn_lib.c: remove bn_check_top from bn_expand2.
Andy Polyakov [Fri, 6 Jul 2018 11:16:40 +0000 (13:16 +0200)]
bn/bn_lib.c: remove bn_check_top from bn_expand2.

Trouble is that addition is postponing expansion till carry is
calculated, and if addition carries, top word can be zero, which
triggers assertion in bn_check_top.

Reviewed-by: Rich Salz <rsalz@openssl.org>
Reviewed-by: David Benjamin <davidben@google.com>
(Merged from https://github.com/openssl/openssl/pull/6662)

2 years agoapps/speed.c: let EVP_Update_loop_ccm behave more like EVP_Update_loop
Patrick Steuer [Fri, 2 Feb 2018 10:09:25 +0000 (11:09 +0100)]
apps/speed.c: let EVP_Update_loop_ccm behave more like EVP_Update_loop

Signed-off-by: Patrick Steuer <patrick.steuer@de.ibm.com>
Reviewed-by: Tim Hudson <tjh@openssl.org>
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/5246)

2 years agoWindows: avoid using 'rem' in the nmake makefile
Richard Levitte [Wed, 11 Jul 2018 09:05:15 +0000 (11:05 +0200)]
Windows: avoid using 'rem' in the nmake makefile

To avoid the possibility that someone creates rem.exe, rem.bat or
rem.cmd, simply don't use it.  In the cases it was used, it was to
avoid empty lines, but it turns out that nmake handles those fine, so
no harm done.

Reviewed-by: Andy Polyakov <appro@openssl.org>
Reviewed-by: Bernd Edlinger <bernd.edlinger@hotmail.de>
(Merged from https://github.com/openssl/openssl/pull/6686)

2 years agoWindows: fix echo for nmake
Richard Levitte [Tue, 10 Jul 2018 12:12:33 +0000 (14:12 +0200)]
Windows: fix echo for nmake

It seems that nmake first tries to run executables on its own, and
only pass commands to cmd if that fails.  That means it's possible to
have nmake run something like 'echo.exe' when the builtin 'echo'
command was expected, which might give us unexpected results.

To get around this, we create our own echoing script and call it
explicitly from the nmake makefile.

Fixes #6670

Reviewed-by: Andy Polyakov <appro@openssl.org>
Reviewed-by: Bernd Edlinger <bernd.edlinger@hotmail.de>
(Merged from https://github.com/openssl/openssl/pull/6686)

2 years agoNCONF_get_number refix.
Pauli [Tue, 3 Jul 2018 23:30:43 +0000 (09:30 +1000)]
NCONF_get_number refix.

Fix the NULL check lack in a different way that is more compatible with
non-NULL branch.  Refer #6632

Also mark and pop the error stack instead of clearing all errors when something
goes awry in CONF_get_number.

Reviewed-by: Rich Salz <rsalz@openssl.org>
Reviewed-by: Andy Polyakov <appro@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6643)

2 years agoGuard DECLARE_DEPRECATED against multiple includes of opensslconf.h
Richard Levitte [Tue, 10 Jul 2018 17:11:06 +0000 (19:11 +0200)]
Guard DECLARE_DEPRECATED against multiple includes of opensslconf.h

Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6689)

2 years agoutil/dofile.pl: require Text::Template 1.46 or newer
Richard Levitte [Mon, 9 Jul 2018 19:10:10 +0000 (21:10 +0200)]
util/dofile.pl: require Text::Template 1.46 or newer

The reason is that we override Text::Template::append_text_to_output(),
and it didn't exist before Text::Template 1.46.

Fixes #6641

Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6682)

2 years agoExisting transfer modules must have a package and a $VERSION
Richard Levitte [Mon, 9 Jul 2018 19:09:30 +0000 (21:09 +0200)]
Existing transfer modules must have a package and a $VERSION

Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6682)

2 years agoMake 'with_fallback' use 'use' instead of 'require'
Richard Levitte [Mon, 9 Jul 2018 19:07:25 +0000 (21:07 +0200)]
Make 'with_fallback' use 'use' instead of 'require'

This enables us to require module versions, and to fall back to a
bundled version if the system version is too low.

Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6682)

2 years agoAvoid __GNUC__ warnings when defining DECLARE_DEPRECATED
Richard Levitte [Mon, 9 Jul 2018 15:31:23 +0000 (17:31 +0200)]
Avoid __GNUC__ warnings when defining DECLARE_DEPRECATED

We need to check that __GNUC__ is defined before trying to use it.
This demands a slightly different way to define DECLARE_DEPRECATED.

Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6680)

2 years agopoly1305/asm/poly1305-x86_64.pl: fix solaris64-x86_64-cc build.
Andy Polyakov [Mon, 9 Jul 2018 09:11:37 +0000 (11:11 +0200)]
poly1305/asm/poly1305-x86_64.pl: fix solaris64-x86_64-cc build.

Reviewed-by: Paul Dale <paul.dale@oracle.com>
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6676)

2 years agoAdd tests for the "req" command, -addext flag
Rich Salz [Mon, 9 Jul 2018 18:55:17 +0000 (14:55 -0400)]
Add tests for the "req" command, -addext flag

Also fixed a memory leak found by the test.

Reviewed-by: Andy Polyakov <appro@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6681)

2 years agoFix minor windows build issues
Bernd Edlinger [Thu, 5 Jul 2018 13:38:28 +0000 (15:38 +0200)]
Fix minor windows build issues

[extended tests]

Reviewed-by: Rich Salz <rsalz@openssl.org>
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6661)

2 years agoapps/req.c: fix -addext option.
Andy Polyakov [Sun, 8 Jul 2018 16:57:30 +0000 (18:57 +0200)]
apps/req.c: fix -addext option.

Address even Coverity nit.

Reviewed-by: Paul Dale <paul.dale@oracle.com>
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6671)

2 years agoCorrectly check for cryptodev hash support
Conrad Meyer [Mon, 9 Jul 2018 16:45:28 +0000 (12:45 -0400)]
Correctly check for cryptodev hash support

The sense of the check for build-time support for most hashes was inverted.

CLA: trivial

Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Paul Dale <paul.dale@oracle.com>
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6673)

2 years agomodes/ocb128.c: readability and formatting improvements.
Andy Polyakov [Sun, 8 Jul 2018 10:12:15 +0000 (12:12 +0200)]
modes/ocb128.c: readability and formatting improvements.

Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6669)

2 years agomodes/ocb128.c: improve the calculation of double mask
DesWurstes [Sat, 7 Jul 2018 09:10:53 +0000 (12:10 +0300)]
modes/ocb128.c: improve the calculation of double mask

CLA: trivial

Reviewed-by: Andy Polyakov <appro@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6667)

2 years agoKeep supporting the env / make variable PERL
Richard Levitte [Sun, 8 Jul 2018 10:00:06 +0000 (12:00 +0200)]
Keep supporting the env / make variable PERL

OpenSSL 1.1.0 supports the use of this environment variable for
passing to the build files.  For the sake of backward compatibility,
we keep it.

Reviewed-by: Tim Hudson <tjh@openssl.org>
Reviewed-by: Paul Dale <paul.dale@oracle.com>
Reviewed-by: Bernd Edlinger <bernd.edlinger@hotmail.de>
(Merged from https://github.com/openssl/openssl/pull/6668)

2 years agoUpdate AUTHORS list, add commentary
Rich Salz [Mon, 9 Jul 2018 00:32:04 +0000 (20:32 -0400)]
Update AUTHORS list, add commentary

Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/6602)

2 years agoUpdate DRBG CHANGES section
Kurt Roeckx [Sat, 7 Jul 2018 08:55:18 +0000 (10:55 +0200)]
Update DRBG CHANGES section

Reviewed-by: Tim Hudson <tjh@openssl.org>
Reviewed-by: Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com>
GH: #6666

2 years agoRemove a memset
Matt Caswell [Tue, 26 Jun 2018 14:21:09 +0000 (15:21 +0100)]
Remove a memset

Also avoids calling EVP_MD_size() and a missing negative result check.

Issue found by Coverity.

Reviewed-by: Andy Polyakov <appro@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6592)

2 years agoCheck a return value for success in ec_field_size()
Matt Caswell [Tue, 26 Jun 2018 14:12:56 +0000 (15:12 +0100)]
Check a return value for success in ec_field_size()

Reviewed-by: Andy Polyakov <appro@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6592)

2 years agoFix some Coverity issues in sm2_encrypt()
Matt Caswell [Tue, 26 Jun 2018 14:10:56 +0000 (15:10 +0100)]
Fix some Coverity issues in sm2_encrypt()

Check for a negative EVP_MD_size().
Don't dereference group until we've checked if it is NULL.

Reviewed-by: Andy Polyakov <appro@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6592)

2 years agoCheck md_size isn't negative before we use it
Matt Caswell [Tue, 26 Jun 2018 14:03:05 +0000 (15:03 +0100)]
Check md_size isn't negative before we use it

Issue found by Coverity

Reviewed-by: Andy Polyakov <appro@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6592)

2 years agoDon't fail if the PSK identity doesn't match
Matt Caswell [Fri, 6 Jul 2018 08:16:51 +0000 (09:16 +0100)]
Don't fail if the PSK identity doesn't match

In 1.1.0 s_server if the PSK identity doesn't match what we have then
a warning is printed and we continue the connection anyway. In 1.1.1,
if TLSv1.3 is used and the identity doesn't match then we abort the
connection. We should really be consistent with the old behaviour.

Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6659)

2 years agoevp/e_chacha20_poly1305.c: further improve small-fragment TLS performance.
Andy Polyakov [Tue, 3 Jul 2018 19:34:08 +0000 (21:34 +0200)]
evp/e_chacha20_poly1305.c: further improve small-fragment TLS performance.

Improvement coefficients vary with TLS fragment length and platform, on
most Intel processors maximum improvement is ~50%, while on Ryzen - 80%.
The "secret" is new dedicated ChaCha20_128 code path and vectorized xor
helpers.

Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6638)

2 years agoDocument SSL_CTX_set_recv_max_early_data() etc
Matt Caswell [Thu, 5 Jul 2018 15:53:56 +0000 (16:53 +0100)]
Document SSL_CTX_set_recv_max_early_data() etc

Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/6655)

2 years agoAdd the ability to configure recv_max_early_data via s_server
Matt Caswell [Thu, 5 Jul 2018 14:42:36 +0000 (15:42 +0100)]
Add the ability to configure recv_max_early_data via s_server

Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/6655)

2 years agoAdd a test for the recv_max_early_data setting
Matt Caswell [Thu, 5 Jul 2018 14:31:51 +0000 (15:31 +0100)]
Add a test for the recv_max_early_data setting

Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/6655)

2 years agoIntroduce the recv_max_early_data setting
Matt Caswell [Thu, 5 Jul 2018 13:40:39 +0000 (14:40 +0100)]
Introduce the recv_max_early_data setting

Previoulsy we just had max_early_data which controlled both the value of
max early_data that we advertise in tickets *and* the amount of early_data
that we are willing to receive from clients. This doesn't work too well in
the case where we want to reduce a previously advertised max_early_data
value. In that case clients with old, stale tickets may attempt to send us
more early data than we are willing to receive. Instead of rejecting the
early data we abort the connection if that happens.

To avoid this we introduce a new "recv_max_early_data" value. The old
max_early_data becomes the value that is advertised in tickets while
recv_max_early_data is the maximum we will tolerate from clients.

Fixes #6647

Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/6655)

2 years agoReject duplicate -addext parameters
Rich Salz [Thu, 5 Jul 2018 23:57:22 +0000 (19:57 -0400)]
Reject duplicate -addext parameters

Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/6636)

2 years agoAdd missing include file to doc
Rich Salz [Thu, 5 Jul 2018 20:10:55 +0000 (16:10 -0400)]
Add missing include file to doc

Reported by Ingo Schwarze

Reviewed-by: Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com>
(Merged from https://github.com/openssl/openssl/pull/6656)

2 years agoDocument more EVP_MD_CTX functions
Richard Levitte [Wed, 4 Jul 2018 07:26:05 +0000 (09:26 +0200)]
Document more EVP_MD_CTX functions

Fixes #6644

Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6645)

2 years ago[crypto/ec] disable SCA mitigations for curves with incomplete parameters
Billy Brumley [Wed, 4 Jul 2018 12:35:18 +0000 (15:35 +0300)]
[crypto/ec] disable SCA mitigations for curves with incomplete parameters

Reviewed-by: Rich Salz <rsalz@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6648)

2 years agoFix no-tls1_2
Matt Caswell [Tue, 3 Jul 2018 12:36:31 +0000 (13:36 +0100)]
Fix no-tls1_2

Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6634)

2 years agoTests for MD5-SHA1 combined digest.
Pauli [Tue, 3 Jul 2018 21:48:45 +0000 (07:48 +1000)]
Tests for MD5-SHA1 combined digest.

Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6642)

2 years agoFix some issues found by Denian's lintian tool
Rich Salz [Tue, 3 Jul 2018 16:45:14 +0000 (12:45 -0400)]
Fix some issues found by Denian's lintian tool

Also fix some L<> labels and =item entries found while doing this.

Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/6630)

2 years agochacha/asm/chacha-x86_64.pl: add dedicated path for 128-byte inputs.
Andy Polyakov [Mon, 2 Jul 2018 11:16:33 +0000 (13:16 +0200)]
chacha/asm/chacha-x86_64.pl: add dedicated path for 128-byte inputs.

The 128-byte vectors are extensively used in chacha20_poly1305_tls_cipher
and dedicated code path is ~30-50% faster on most platforms.

Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6626)

2 years agoperlasm/x86_64-xlate.pl: refine symbol recognition in .xdata.
Andy Polyakov [Mon, 2 Jul 2018 11:12:49 +0000 (13:12 +0200)]
perlasm/x86_64-xlate.pl: refine symbol recognition in .xdata.

Hexadecimals were erroneously recognized as symbols in .xdata.

Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6626)

2 years agoRemove TLSv1.3 tickets from the client cache as we use them
Matt Caswell [Tue, 26 Jun 2018 17:07:56 +0000 (18:07 +0100)]
Remove TLSv1.3 tickets from the client cache as we use them

Tickets are supposed to be single use so we remove them from the cache on
use.

Fixes #6377

Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/6601)

2 years agoRestore behaviour from commit 36ff232cf that was incorrectly removed
Matt Caswell [Tue, 26 Jun 2018 17:06:45 +0000 (18:06 +0100)]
Restore behaviour from commit 36ff232cf that was incorrectly removed

In TLSv1.2 and below we should remove an old session from the client
session cache in the event that we receive a new session ticket from the
server.

Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/6601)

2 years agoCheck for NULL conf in NCONF_get_number
Pauli [Mon, 2 Jul 2018 22:02:37 +0000 (08:02 +1000)]
Check for NULL conf in NCONF_get_number

The problematic case falls back to a NULL conf which returns the result
of getenv(2).  If this returns NULL, everything was good.  If this returns
a string an attempt to convert it to a number is made using the function
pointers from conf.

This fix uses the strtol(3) function instead, we don't have the
configuration settings and this behaves as the default would.

Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6632)

2 years agoAdd the ability to configure anti-replay via SSL_CONF
Matt Caswell [Fri, 15 Jun 2018 13:55:06 +0000 (14:55 +0100)]
Add the ability to configure anti-replay via SSL_CONF

This also adds the ability to control this through s_server

Reviewed-by: Viktor Dukhovni <viktor@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6469)

2 years agoAdd a test for the new early data callback
Matt Caswell [Fri, 8 Jun 2018 09:03:19 +0000 (10:03 +0100)]
Add a test for the new early data callback

Reviewed-by: Viktor Dukhovni <viktor@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6469)

2 years agoDocument the new early data callback and option
Matt Caswell [Thu, 7 Jun 2018 15:32:19 +0000 (16:32 +0100)]
Document the new early data callback and option

Document SSL_OP_NO_ANTI_REPLAY and SSL_CTX_set_allow_early_data_cb()

Reviewed-by: Viktor Dukhovni <viktor@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6469)

2 years agoAdd setters to set the early_data callback
Matt Caswell [Thu, 7 Jun 2018 14:14:36 +0000 (15:14 +0100)]
Add setters to set the early_data callback

Reviewed-by: Viktor Dukhovni <viktor@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6469)

2 years agoMake the anti-replay feature optional
Matt Caswell [Thu, 7 Jun 2018 08:11:05 +0000 (09:11 +0100)]
Make the anti-replay feature optional

Fixes #6389

Reviewed-by: Viktor Dukhovni <viktor@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6469)

2 years agoFix a NULL ptr deref in error path in tls_process_cke_dhe()
Matt Caswell [Tue, 26 Jun 2018 14:40:54 +0000 (15:40 +0100)]
Fix a NULL ptr deref in error path in tls_process_cke_dhe()

Fixes #6574

Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6593)

2 years agoAddress coverity-reported NULL dereference in SSL_SESSION_print()
Benjamin Kaduk [Sun, 1 Jul 2018 17:49:24 +0000 (12:49 -0500)]
Address coverity-reported NULL dereference in SSL_SESSION_print()

We need to check the provided SSL_SESSION* for NULL before
attempting to derference it to see if it's a TLS 1.3 session.

Reviewed-by: Kurt Roeckx <kurt@roeckx.be>
(Merged from https://github.com/openssl/openssl/pull/6622)

2 years agoRemove development artifacts.
Pauli [Wed, 27 Jun 2018 01:34:54 +0000 (11:34 +1000)]
Remove development artifacts.

The issue was discovered on the x86/64 when attempting to include
libcrypto inside another shared library.  A relocation of type
R_X86_64_PC32 was generated which causes a linker error.

Reviewed-by: Rich Salz <rsalz@openssl.org>
Reviewed-by: Andy Polyakov <appro@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6595)

2 years agorand/rand_unix.c: address macro redifinition warning.
Andy Polyakov [Fri, 29 Jun 2018 16:46:57 +0000 (18:46 +0200)]
rand/rand_unix.c: address macro redifinition warning.

Occasionally, e.g. when compiling for elderly glibc, you end up passing
-D_GNU_SOURCE on command line, and doing so triggered warning...

Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6616)