oweals/openssl.git
7 years agoDefine a value for SYS_F_FCNTL
Benjamin Kaduk [Thu, 27 Jul 2017 15:27:20 +0000 (10:27 -0500)]
Define a value for SYS_F_FCNTL

This symbol was added in commit d33b215b331116e50947ca7e75d210e1db39b78d
but was only used in certain (presumed uncommon) preprocessor conditionals,
as no build failures have been reported yet.

Reported by Balaji Marisetti.

Closes: #4029

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

7 years agoFix trivial coding style nits in a_time/a_tm files
Pauli [Thu, 27 Jul 2017 04:54:27 +0000 (14:54 +1000)]
Fix trivial coding style nits in a_time/a_tm files
Clean up some true/false returns

Reviewed-by: Andy Polyakov <appro@openssl.org>
Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/4001)

7 years agoFix comment typo.
David Benjamin [Wed, 26 Jul 2017 16:30:27 +0000 (12:30 -0400)]
Fix comment typo.

Reviewed-by: Ben Kaduk <kaduk@mit.edu>
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/4023)

7 years agoVarious doc fixes.
Xiaoyin Liu [Fri, 21 Jul 2017 20:13:13 +0000 (16:13 -0400)]
Various doc fixes.

Fix typo in NOTES.WIN: this -> these

Fix wrong capital letter in certificates.txt

Make number of characters in each line more even
Remove redundant empty line

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

7 years agoInstall custom RAND_METHOD for fuzzing
Rich Salz [Wed, 26 Jul 2017 18:27:30 +0000 (14:27 -0400)]
Install custom RAND_METHOD for fuzzing

Instead of setting a "magic" global variable to force RAND to keep
consistent state and always generate the same bytestream, have
the fuzzing code install its own RAND_METHOD that does this.  For
BN_RAND_DEBUG, we just don't do it; that debugging was about mucking
with BN's internal representation, not requiring predictable rand
bytes.

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

7 years agoFix the two new tests since approval.
Pauli [Wed, 26 Jul 2017 22:08:36 +0000 (08:08 +1000)]
Fix the two new tests since approval.

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

7 years agoUpdate the test framework so that the need for test_main is removed. Everything
Pauli [Tue, 18 Jul 2017 01:48:27 +0000 (11:48 +1000)]
Update the test framework so that the need for test_main is removed.  Everything
that needed test_main now works using the same infrastructure as tests that used
register_tests.

This meant:
* renaming register_tests to setup_tests and giving it a success/failure return.
* renaming the init_test function to setup_test_framework.
* renaming the finish_test function to pulldown_test_framework.
* adding a user provided global_init function that runs before the test frame
    work is initialised.  It returns a failure indication that stops the stest.
* adding helper functions that permit tests to access their command line args.
* spliting the BIO initialisation and finalisation out from the test setup and
    teardown.
* hiding some of the now test internal functions.
* fix the comments in testutil.h

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

7 years agoSimplify the handling of shared library version numbers
Richard Levitte [Wed, 19 Jul 2017 08:13:41 +0000 (10:13 +0200)]
Simplify the handling of shared library version numbers

$(SHLIB_MAJOR).$(SHLIB_MINOR) is really a synonym for
$(SHLIB_VERSION_NUMBER), and is therefore an added complexity,
so better to use $(SHLIB_VERSION_NUMBER) directly.  SHLIB_MAJOR and
SHLIB_MINOR are now unused, but are kept around purely as information
in case someone relies on their existence.

At the same time, add support for custom shared library extensions
with the three new Makefile variables SHLIB_EXT, SHLIB_EXT_SIMPLE and
SHLIB_EXT_IMPORT.  By default, they hold the variants of shared
library extensions we support.  On mingw and cygwin, SHLIB_EXT_IMPORT
is defined; on all other Unix platforms, it's empty.

An example to get shared libraries with a slightly different SOVER name:

    $ make SHLIB_EXT='.$(SHLIB_VERSION_NUMBER).so'

Fixes #3902

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

7 years agoadd basic references to the new methods in documentation
Hubert Kario [Wed, 26 Jul 2017 12:26:16 +0000 (14:26 +0200)]
add basic references to the new methods in documentation

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

7 years agohandle scrypt PBKDF in PKCS#12 files info
Hubert Kario [Wed, 26 Jul 2017 14:27:06 +0000 (16:27 +0200)]
handle scrypt PBKDF in PKCS#12 files info

Print the parameters for scrypt PBKDF when used in PKCS#12 files.

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

7 years agonicer formatting for MAC info
Hubert Kario [Wed, 26 Jul 2017 11:23:17 +0000 (13:23 +0200)]
nicer formatting for MAC info

The info printing for PBES2 already uses space after type and commas to
separate items in the line so use the same format for MAC info too.

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

7 years agomake scrypt ASN.1 parameter functions public
Hubert Kario [Wed, 26 Jul 2017 13:05:59 +0000 (15:05 +0200)]
make scrypt ASN.1 parameter functions public

Since scrypt PBKDF can be used both in PKCS#5 and PKCS#12 files,
do share the code between them.

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

7 years agomore info about PKCS#12 structure MAC
Hubert Kario [Wed, 26 Jul 2017 14:25:51 +0000 (16:25 +0200)]
more info about PKCS#12 structure MAC

report additional information about the MAC used over the
PKCS#12 structure: size of mac and salt as well as the
hash algorithm used for creating it

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

7 years agopkcs12.c better formatting for unsupported params
Hubert Kario [Wed, 20 Jul 2016 12:10:29 +0000 (14:10 +0200)]
pkcs12.c better formatting for unsupported params

since when we get to this point, other information was already
printed, we should insert some whitespace between already
printed data and this "unsupported parameters" error message

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

7 years agofix OSSL_STORE man pages
Hubert Kario [Wed, 26 Jul 2017 12:58:58 +0000 (14:58 +0200)]
fix OSSL_STORE man pages

the man pages have lines that contain nothing but whitespace,
clean it up by removing that whitespace

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

7 years agoAdd test cases and docs for ASN1_STRING_TABLE_* functions
Paul Yang [Wed, 26 Jul 2017 17:18:50 +0000 (01:18 +0800)]
Add test cases and docs for ASN1_STRING_TABLE_* functions

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

7 years agoFix async engine pause dead lock in error case.
Emeric Brun [Wed, 26 Jul 2017 13:59:21 +0000 (15:59 +0200)]
Fix async engine pause dead lock in error case.

In 'crypto/rand/ossl_rand.c', a call to
'ASYNC_unblock_pause()' is missing in an error case.

CLA: trivial

Reviewed-by: Rich Salz <rsalz@openssl.org>
Reviewed-by: Ben Kaduk <kaduk@mit.edu>
(Merged from https://github.com/openssl/openssl/pull/4020)

7 years agoAdd support to free/allocate SSL buffers
Todd Short [Fri, 13 Jan 2017 16:00:26 +0000 (11:00 -0500)]
Add support to free/allocate SSL buffers

OpenSSL already has the feature of SSL_MODE_RELEASE_BUFFERS that can
be set to release the read or write buffers when data has finished
reading or writing. OpenSSL will automatically re-allocate the buffers
as needed. This can be quite aggressive in terms of memory allocation.

This provides a manual mechanism. SSL_free_buffers() will free
the data buffers if there's no pending data. SSL_alloc_buffers()
will realloc them; but this function is not strictly necessary, as it's
still done automatically in the state machine.

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

7 years agoFix potential use-after-free and memory leak
Pauli [Wed, 26 Jul 2017 00:04:05 +0000 (10:04 +1000)]
Fix potential use-after-free and memory leak

In function wait_for_async(), allocated async fds is freed if
`SSL_get_all_async_fds` fails, but later `fds` is used. Interestingly,
it is not freed when everything succeeds.

Rewrite the FD set loop to make it more readable and to not modify the allocated
pointer so it can be freed.

Reviewed-by: Andy Polyakov <appro@openssl.org>
Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/3992)

7 years agoWire SHA3 EVPs and add tests.
Andy Polyakov [Sun, 16 Jul 2017 21:41:51 +0000 (23:41 +0200)]
Wire SHA3 EVPs and add tests.

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

7 years agoAdd evp/m_sha3.c.
Andy Polyakov [Sun, 16 Jul 2017 21:40:14 +0000 (23:40 +0200)]
Add evp/m_sha3.c.

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

7 years agosha/keccak1600.c: build and make it work with strict warnings.
Andy Polyakov [Sun, 16 Jul 2017 21:36:54 +0000 (23:36 +0200)]
sha/keccak1600.c: build and make it work with strict warnings.

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

7 years agocrypto/x86_64cpuid.pl: fix typo in Knights Landing detection.
Andy Polyakov [Mon, 24 Jul 2017 21:50:47 +0000 (23:50 +0200)]
crypto/x86_64cpuid.pl: fix typo in Knights Landing detection.

Thanks to David Benjamin for spotting this!

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

7 years agoaes/asm/aesni-sha*-x86_64.pl: add SHAEXT performance results.
Andy Polyakov [Mon, 10 Jul 2017 13:21:00 +0000 (15:21 +0200)]
aes/asm/aesni-sha*-x86_64.pl: add SHAEXT performance results.

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

7 years agoevp/e_aes_cbc_hmac_sha256.c: give SHAEXT right priority.
Andy Polyakov [Mon, 10 Jul 2017 13:19:45 +0000 (15:19 +0200)]
evp/e_aes_cbc_hmac_sha256.c: give SHAEXT right priority.

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

7 years agosha/asm/keccak1600-avx512.pl: improve performance by 17%.
Andy Polyakov [Sun, 23 Jul 2017 14:06:26 +0000 (16:06 +0200)]
sha/asm/keccak1600-avx512.pl: improve performance by 17%.

Improvement is result of combination of data layout ideas from
Keccak Code Package and initial version of this module.

Hardware used for benchmarking courtesy of Atos, experiments run by
Romain Dolbeau <romain.dolbeau@atos.net>. Kudos!

Reviewed-by: Bernd Edlinger <bernd.edlinger@hotmail.de>
Reviewed-by: Rich Salz <rsalz@openssl.org>
7 years agoschlock global variable needs to be volatile
Xiaoyin Liu [Mon, 24 Jul 2017 15:28:50 +0000 (11:28 -0400)]
schlock global variable needs to be volatile

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

7 years agoFix nid assignment in ASN1_STRING_TABLE_add
lolyonok [Fri, 14 Jul 2017 15:22:12 +0000 (18:22 +0300)]
Fix nid assignment in ASN1_STRING_TABLE_add

CLA: trivial

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

7 years agoMakefile.shared: Make link_shlib.linux-shared less verbose again
Richard Levitte [Mon, 24 Jul 2017 09:48:02 +0000 (11:48 +0200)]
Makefile.shared: Make link_shlib.linux-shared less verbose again

A previous change inavertently removed a silencing '@'

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

7 years agotest/recipes/80-test_tsa.t: Don't trust 'OPENSSL_CONF'
Richard Levitte [Sat, 22 Jul 2017 21:37:06 +0000 (23:37 +0200)]
test/recipes/80-test_tsa.t: Don't trust 'OPENSSL_CONF'

There's a case when the environment variable OPENSSL_CONF is
useless...  when cross compiling for mingw and your wine environment
has an environment variable OPENSSL_CONF.  The latter will override
anything that's given when starting wine and there make the use of
that environment variable useless in our tests.

Therefore, we should not trust it, and use explicit '-config' options
instead.

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

7 years agoSimplify Makefile.shared
Richard Levitte [Fri, 21 Jul 2017 16:04:51 +0000 (18:04 +0200)]
Simplify Makefile.shared

Makefile.shared was designed to figure out static library names,
shared library names, library version compatibility, import library
names and the like on its own.  This was a design for pre-1.1.0
OpenSSL because the main Makefile didn't have all that knowledge.

With 1.1.0, the situation isn't the same, a lot more knowledge is
included in the main Makefile, and while Makefile.shared did things
right most of the time (there are some corner cases, such as the
choice of .sl or .so as DSO extension on some HPUX versions), there's
still an inherent fragility when one has to keep an eye on
Makefile.shared to make sure it produces what the main Makefile
produces.

This change simplifies Makefile.shared by removing all its
"intelligence" and have it depend entirely on the input from the main
Makefile instead.  That way, all the naming is driven from
configuration data.

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

7 years agoImprove struct tm population
Pauli [Sun, 23 Jul 2017 23:10:13 +0000 (09:10 +1000)]
Improve struct tm population

Using Zeller's congruence to fill the day of week field,
Also populate the day of year field.

Add unit test to cover a number of cases.

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

7 years agoAdd asn1_time_to_tm function and check days in month
Paul Yang [Mon, 10 Jul 2017 19:01:24 +0000 (03:01 +0800)]
Add asn1_time_to_tm function and check days in month

Based on discussion in PR #3566. Reduce duplicated code in original
asn1_utctime_to_tm and asn1_generalizedtime_to_tm, and introduce a new
internal function asn1_time_to_tm. This function also checks if the days
in the input time string is valid or not for the corresponding month.

Test cases are also added.

Reviewed-by: Andy Polyakov <appro@openssl.org>
Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/3905)

7 years agoUpdate documentation for SSL_is_server()
Paul Yang [Sun, 9 Jul 2017 16:55:38 +0000 (00:55 +0800)]
Update documentation for SSL_is_server()

Reviewed-by: Paul Dale <paul.dale@oracle.com>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/3893)

7 years agoRemove unused function prototypes
Xiaoyin Liu [Sat, 22 Jul 2017 22:44:27 +0000 (18:44 -0400)]
Remove unused function prototypes

`args_verify()` and `opt_reset()` are declared in `apps/apps.h`, but they are
not referenced anywhere. So can we remove them from `apps.h`?

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

7 years agoUpdate doc/ca.pod to clarify description for dates
Paul Yang [Sun, 9 Jul 2017 17:52:33 +0000 (01:52 +0800)]
Update doc/ca.pod to clarify description for dates

"Note" part is based on PR #3566

Reviewed-by: Ben Kaduk <kaduk@mit.edu>
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/3895)

7 years agoFix const correctness of EC_KEY_METHOD_get_*
Johannes Bauer [Fri, 21 Jul 2017 17:58:18 +0000 (19:58 +0200)]
Fix const correctness of EC_KEY_METHOD_get_*

Changes the EC_KEY_METHOD_get_* family to not need a EC_KEY_METHOD* as
its first parameter, but a const EC_KEY_METHOD*, which is entirely
sufficient.

Reviewed-by: Kurt Roeckx <kurt@roeckx.be>
Reviewed-by: Paul Dale <paul.dale@oracle.com>
GH: #3985

7 years agoAdd --with-rand-seed
Rich Salz [Tue, 18 Jul 2017 13:39:21 +0000 (09:39 -0400)]
Add --with-rand-seed

Add a new config param to specify how the CSPRNG should be seeded.
Illegal values or nonsensical combinations (e.g., anything other
than "os" on VMS or HP VOS etc) result in build failures.
Add RDSEED support.
Add RDTSC but leave it disabled for now pending more investigation.

Refactor and reorganization all seeding files (rand_unix/win/vms) so
that they are simpler.

Only require 128 bits of seeding material.

Many document improvements, including why to not use RAND_add() and the
limitations around using load_file/write_file.
Document RAND_poll().

Cleanup Windows RAND_poll and return correct status

More completely initialize the default DRBG.

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

7 years agosha/asm/keccak1600-avx512.pl: absorb bug-fix and minor optimization.
Andy Polyakov [Thu, 20 Jul 2017 11:56:17 +0000 (13:56 +0200)]
sha/asm/keccak1600-avx512.pl: absorb bug-fix and minor optimization.

Hardware used for benchmarking courtesy of Atos, experiments run by
Romain Dolbeau <romain.dolbeau@atos.net>. Kudos!

Reviewed-by: Rich Salz <rsalz@openssl.org>
7 years agox86_64 assembly pack: "optimize" for Knights Landing, add AVX-512 results.
Andy Polyakov [Thu, 20 Jul 2017 07:48:35 +0000 (09:48 +0200)]
x86_64 assembly pack: "optimize" for Knights Landing, add AVX-512 results.

"Optimize" is in quotes because it's rather a "salvage operation"
for now. Idea is to identify processor capability flags that
drive Knights Landing to suboptimial code paths and mask them.
Two flags were identified, XSAVE and ADCX/ADOX. Former affects
choice of AES-NI code path specific for Silvermont (Knights Landing
is of Silvermont "ancestry"). And 64-bit ADCX/ADOX instructions are
effectively mishandled at decode time. In both cases we are looking
at ~2x improvement.

AVX-512 results cover even Skylake-X :-)

Hardware used for benchmarking courtesy of Atos, experiments run by
Romain Dolbeau <romain.dolbeau@atos.net>. Kudos!

Reviewed-by: Rich Salz <rsalz@openssl.org>
7 years agoSupport converting cipher name to RFC name and vice versa
Paul Yang [Thu, 29 Jun 2017 19:06:19 +0000 (03:06 +0800)]
Support converting cipher name to RFC name and vice versa

Fixes: issue #3747

make SSL_CIPHER_standard_name globally available and introduce a new
function OPENSSL_cipher_name.

A new option '-convert' is also added to 'openssl ciphers' app.

Documentation and test cases are added.

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

7 years agoFix out-of-bounds read in ctr_XOR
Benjamin Kaduk [Wed, 19 Jul 2017 22:59:52 +0000 (17:59 -0500)]
Fix out-of-bounds read in ctr_XOR

Looking at
http://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-90Ar1.pdf
we see that in the CTR_DRBG_Update() algorithm (internal page number 51),
the provided input data is (after truncation to seedlen) xor-d with the
key and V vector (of length keylen and blocklen respectively).  The comment
in ctr_XOR notes that xor-ing with 0 is the identity function, so we can
just ignore the case when the provided input is shorter than seedlen.

The code in ctr_XOR() then proceeds to xor the key with the input, up
to the amount of input present, and computes the remaining input that
could be used to xor with the V vector, before accessing a full 16-byte
stretch of the input vector and ignoring the calculated length.  The correct
behavior is to respect the supplied input length and only xor the
indicated number of bytes.

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

7 years agotypedef's for RAND_DRBG methods
Benjamin Kaduk [Wed, 19 Jul 2017 22:32:08 +0000 (17:32 -0500)]
typedef's for RAND_DRBG methods

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

7 years agoRemove trailing whitespace from drbgtest.c
Benjamin Kaduk [Wed, 19 Jul 2017 22:18:16 +0000 (17:18 -0500)]
Remove trailing whitespace from drbgtest.c

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

7 years agoRename internal rand.h file
Rich Salz [Thu, 20 Jul 2017 14:20:47 +0000 (10:20 -0400)]
Rename internal rand.h file

Replacement fix for #3975

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

7 years agoFix faulty include
Richard Levitte [Thu, 20 Jul 2017 09:58:28 +0000 (11:58 +0200)]
Fix faulty include

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

7 years agoAdd range-checking to RAND_DRBG_set_reseed_interval
Rich Salz [Wed, 19 Jul 2017 21:41:26 +0000 (17:41 -0400)]
Add range-checking to RAND_DRBG_set_reseed_interval

As suggested by Kurt.

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

7 years agoAdd keygen test data
Dr. Stephen Henson [Tue, 18 Jul 2017 16:21:37 +0000 (17:21 +0100)]
Add keygen test data

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

7 years agoAdd keygen test to evp_test
Dr. Stephen Henson [Sun, 16 Jul 2017 23:15:58 +0000 (00:15 +0100)]
Add keygen test to evp_test

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

7 years agoTypo: should check mgf1md
Dr. Stephen Henson [Thu, 13 Jul 2017 14:51:27 +0000 (15:51 +0100)]
Typo: should check mgf1md

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

7 years agoSet maskHash when creating parameters.
Dr. Stephen Henson [Thu, 13 Jul 2017 12:37:57 +0000 (13:37 +0100)]
Set maskHash when creating parameters.

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

7 years agoRemove some dead code
Matt Caswell [Mon, 17 Jul 2017 15:55:32 +0000 (16:55 +0100)]
Remove some dead code

The intention of the removed code was to check if the previous operation
carried. However this does not work. The "mask" value always ends up being
a constant and is all ones - thus it has no effect. This check is no longer
required because of the previous commit.

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

7 years agoFix undefined behaviour in e_aes_cbc_hmac_sha256.c and e_aes_cbc_hmac_sha1.c
Matt Caswell [Wed, 28 Jun 2017 14:18:30 +0000 (15:18 +0100)]
Fix undefined behaviour in e_aes_cbc_hmac_sha256.c and e_aes_cbc_hmac_sha1.c

In TLS mode of operation the padding value "pad" is obtained along with the
maximum possible padding value "maxpad". If pad > maxpad then the data is
invalid. However we must continue anyway because this is constant time code.

We calculate the payload length like this:

    inp_len = len - (SHA_DIGEST_LENGTH + pad + 1);

However if pad is invalid then inp_len ends up -ve (actually large +ve
because it is a size_t).

Later we do this:

    /* verify HMAC */
    out += inp_len;
    len -= inp_len;

This ends up with "out" pointing before the buffer which is undefined
behaviour. Next we calculate "p" like this:

    unsigned char *p =
        out + len - 1 - maxpad - SHA256_DIGEST_LENGTH;

Because of the "out + len" term the -ve inp_len value is cancelled out
so "p" points to valid memory (although technically the pointer arithmetic
is undefined behaviour again).

We only ever then dereference "p" and never "out" directly so there is
never an invalid read based on the bad pointer - so there is no security
issue.

This commit fixes the undefined behaviour by ensuring we use maxpad in
place of pad, if the supplied pad is invalid.

With thanks to Brian Carpenter for reporting this issue.

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

7 years agoAdd DRBG random method
Rich Salz [Tue, 27 Jun 2017 16:04:37 +0000 (12:04 -0400)]
Add DRBG random method

Ported from the last FIPS release, with DUAL_EC and SHA1 and the
self-tests removed.  Since only AES-CTR is supported, other code
simplifications were done.  Removed the "entropy blocklen" concept.

Moved internal functions to new include/internal/rand.h.

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

7 years agoAdd some performance notes about early data
Matt Caswell [Tue, 18 Jul 2017 13:54:23 +0000 (14:54 +0100)]
Add some performance notes about early data

In particular add information about the effect of Nagle's algorithm on
early data.

Fixes #3906

Reviewed-by: Ben Kaduk <kaduk@mit.edu>
(Merged from https://github.com/openssl/openssl/pull/3955)

7 years agoRemove session checks from SSL_clear()
Matt Caswell [Tue, 18 Jul 2017 15:28:38 +0000 (16:28 +0100)]
Remove session checks from SSL_clear()

We now allow a different protocol version when reusing a session so we can
unconditionally reset the SSL_METHOD if it has changed.

Reviewed-by: Ben Kaduk <kaduk@mit.edu>
Reviewed-by: Bernd Edlinger <bernd.edlinger@hotmail.de>
(Merged from https://github.com/openssl/openssl/pull/3954)

7 years agoAdd a test for SSL_clear()
Matt Caswell [Tue, 18 Jul 2017 10:34:47 +0000 (11:34 +0100)]
Add a test for SSL_clear()

Reviewed-by: Ben Kaduk <kaduk@mit.edu>
Reviewed-by: Bernd Edlinger <bernd.edlinger@hotmail.de>
(Merged from https://github.com/openssl/openssl/pull/3954)

7 years agoFix SSL_clear() in TLSv1.3
Matt Caswell [Tue, 18 Jul 2017 10:18:31 +0000 (11:18 +0100)]
Fix SSL_clear() in TLSv1.3

SSL_clear() does not reset the SSL_METHOD if a session already exists in
the SSL object. However, TLSv1.3 does not have an externally visible
version fixed method (only an internal one). The state machine assumes
that we are always starting from a version flexible method for TLSv1.3.
The simplest solution is to just fix SSL_clear() to always reset the method
if it is using the internal TLSv1.3 version fixed method.

Reviewed-by: Ben Kaduk <kaduk@mit.edu>
Reviewed-by: Bernd Edlinger <bernd.edlinger@hotmail.de>
(Merged from https://github.com/openssl/openssl/pull/3954)

7 years agoTolerate a zero length ticket nonce
Matt Caswell [Tue, 18 Jul 2017 15:11:20 +0000 (16:11 +0100)]
Tolerate a zero length ticket nonce

TLSv1.3 draft-21 requires the ticket nonce to be at least 1 byte in length.
However NSS sends a zero length nonce. This is actually ok because the next
draft will allow zero length nonces anyway, so we should tolerate this.

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

7 years agoAdd a test for early_data when an HRR occurs
Matt Caswell [Fri, 14 Jul 2017 11:23:56 +0000 (12:23 +0100)]
Add a test for early_data when an HRR occurs

Reviewed-by: Ben Kaduk <kaduk@mit.edu>
(Merged from https://github.com/openssl/openssl/pull/3933)

7 years agoFix early_data with an HRR
Matt Caswell [Fri, 14 Jul 2017 13:50:48 +0000 (14:50 +0100)]
Fix early_data with an HRR

early_data is not allowed after an HRR. We failed to handle that
correctly.

Reviewed-by: Ben Kaduk <kaduk@mit.edu>
(Merged from https://github.com/openssl/openssl/pull/3933)

7 years agoRSA_padding_check_PKCS1_type_2 is not constant time.
Emilia Kasper [Mon, 17 Jul 2017 14:47:13 +0000 (16:47 +0200)]
RSA_padding_check_PKCS1_type_2 is not constant time.

This is an inherent weakness of the padding mode. We can't make the
implementation constant time (see the comments in rsa_pk1.c), so add a
warning to the docs.

Reviewed-by: Rich Salz <rsalz@openssl.org>
7 years agoRemove resolved TODO
Emilia Kasper [Thu, 13 Jul 2017 16:30:56 +0000 (18:30 +0200)]
Remove resolved TODO

Fixed in 5b8fa431ae8eb5a18ba913494119e394230d4b70

[ci skip]

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

7 years agoFix bogus use of BIO_sock_should_retry.
Bernd Edlinger [Mon, 17 Jul 2017 09:51:19 +0000 (11:51 +0200)]
Fix bogus use of BIO_sock_should_retry.

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

7 years agoFix TLSv1.3 exporter secret
Tatsuhiro Tsujikawa [Sun, 16 Jul 2017 03:40:48 +0000 (12:40 +0900)]
Fix TLSv1.3 exporter secret

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

7 years agoFix use-after-free
Rich Salz [Mon, 17 Jul 2017 06:52:26 +0000 (02:52 -0400)]
Fix use-after-free

Also fix a RANDerr call.

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

7 years agoFix some pedantic warnings.
Pauli [Mon, 17 Jul 2017 01:05:13 +0000 (11:05 +1000)]
Fix some pedantic warnings.

Introduced by #3862

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

7 years agoStandardize apps use of -rand, etc.
Rich Salz [Wed, 5 Jul 2017 14:58:48 +0000 (10:58 -0400)]
Standardize apps use of -rand, etc.

Standardized the -rand flag and added a new one:
    -rand file...
            Always reads the specified files
    -writerand file
            Always writes to the file on exit

For apps that use a config file, the RANDFILE config parameter reads
the file at startup (to seed the RNG) and write to it on exit if
the -writerand flag isn't used.

Ensured that every app that took -rand also took -writerand, and
made sure all of that agreed with all the documentation.

Fix error reporting in write_file and -rand

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

7 years agoDon't use "version" in "OpenSSL Version 1.1.0" etc
Rich Salz [Sat, 15 Jul 2017 13:39:45 +0000 (09:39 -0400)]
Don't use "version" in "OpenSSL Version 1.1.0" etc

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

7 years agoAddress Coverity issues.
Pauli [Fri, 14 Jul 2017 00:08:38 +0000 (10:08 +1000)]
Address Coverity issues.

This patch addresses the use of uninitialised data raised in Coverity
issues 1414881 and 1414882.

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

7 years agosha/asm/keccak1600-avx2.pl: optimized remodelled version.
Andy Polyakov [Wed, 12 Jul 2017 14:02:42 +0000 (16:02 +0200)]
sha/asm/keccak1600-avx2.pl: optimized remodelled version.

New register usage pattern allows to achieve sligtly better
performance. Not as much as I hoped for. Performance is believed
to be limited by irreconcilable write-back conflicts, rather than
lack of computational resources or data dependencies.

Reviewed-by: Rich Salz <rsalz@openssl.org>
7 years agosha/asm/keccak1600-avx2.pl: remodel register usage.
Andy Polyakov [Wed, 12 Jul 2017 13:55:19 +0000 (15:55 +0200)]
sha/asm/keccak1600-avx2.pl: remodel register usage.

This gives much more freedom to rearrange instructions. This is
unoptimized version, provided for reference. Basically you need
to compare it to initial 29724d0e15b4934abdf2d7ab71957b05d1a28256
to figure out the key difference.

Reviewed-by: Rich Salz <rsalz@openssl.org>
7 years agotestutil: stanza files are text files, open them as such
Richard Levitte [Sat, 15 Jul 2017 16:20:24 +0000 (18:20 +0200)]
testutil: stanza files are text files, open them as such

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

7 years agoOSSL_STORE "file" scheme loader: check that a DOS device is correctly named
Richard Levitte [Sat, 15 Jul 2017 09:21:11 +0000 (11:21 +0200)]
OSSL_STORE "file" scheme loader: check that a DOS device is correctly named

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

7 years agoOSSL_STORE "file" scheme loader: check for absolute path in URI later
Richard Levitte [Wed, 12 Jul 2017 10:44:24 +0000 (12:44 +0200)]
OSSL_STORE "file" scheme loader: check for absolute path in URI later

If we have a local file with a name starting with 'file:', we don't
want to check if the part after 'file:' is absolute.  Instead, mark
each possibility for absolute check if needed, and perform the
absolute check later on, when checking each actual path.

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

7 years agotest/recipes/90-test_store.t: Add a few cases with files starting with 'file:'
Richard Levitte [Wed, 12 Jul 2017 10:42:16 +0000 (12:42 +0200)]
test/recipes/90-test_store.t: Add a few cases with files starting with 'file:'

These cases are performed on Linux only.  They check that files with
names starting with 'file:' can be processed as well.

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

7 years agoOSSL_STORE: Treat URIs as files first (with exceptions), then as full URIs
Richard Levitte [Tue, 11 Jul 2017 09:54:00 +0000 (11:54 +0200)]
OSSL_STORE: Treat URIs as files first (with exceptions), then as full URIs

To handle paths that contain devices (for example, C:/foo/bar.pem on
Windows), try to "open" the URI using the file scheme loader first,
and failing that, check if the device is really a scheme we know.

The "file" scheme does the same kind of thing to pick out the path
part of the URI.

An exception to this special treatment is if the URI has an authority
part (something that starts with "//" directly after what looks like a
scheme).  Such URIs will never be treated as plain file paths.

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

7 years agoOSSL_STORE: spell error reason correctly
Richard Levitte [Tue, 11 Jul 2017 09:46:14 +0000 (11:46 +0200)]
OSSL_STORE: spell error reason correctly

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

7 years agotest/recipes/90-test_store.t: Test absolute files
Richard Levitte [Tue, 11 Jul 2017 07:51:04 +0000 (09:51 +0200)]
test/recipes/90-test_store.t: Test absolute files

We haven't tested plain absolute paths without making them URIs...

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

7 years agotest/recipes/90-test_store.t: Rename some functions
Richard Levitte [Tue, 11 Jul 2017 07:48:08 +0000 (09:48 +0200)]
test/recipes/90-test_store.t: Rename some functions

to_rel_file_uri really treated all files appropriately, absolute and
relative alike, and really just constructs a URI, so gets renamed to
to_file_uri

to_file_uri, on the other hand, forces the path into an absolute one,
so gets renamed to to_abs_file_uri

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

7 years agoStart to overhaul RAND API
Rich Salz [Thu, 22 Jun 2017 13:21:43 +0000 (09:21 -0400)]
Start to overhaul RAND API

Remove unused rand_hw_xor, MD/EVP indirection
Make rand_pseudo same as rand.
Cleanup formatting and ifdef control
Rename some things:
    - rand_meth to openssl_rand_meth; make it global
    - source file
    - lock/init functions, start per-thread state
    - ossl_meth_init to ossl_rand_init
Put state into RAND_STATE structure
And put OSSL_RAND_STATE into ossl_typ.h
Use "randomness" instead of "entropy"

Reviewed-by: Ben Kaduk <kaduk@mit.edu>
(Merged from https://github.com/openssl/openssl/pull/3758)

7 years agoFor Windows, use _stat rather than stat
Richard Levitte [Fri, 14 Jul 2017 04:33:16 +0000 (06:33 +0200)]
For Windows, use _stat rather than stat

This allows for better flexibility with mixed /M compiler flags

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

7 years agoFix style in crypto/store/loader_file.c
Richard Levitte [Fri, 14 Jul 2017 04:30:45 +0000 (06:30 +0200)]
Fix style in crypto/store/loader_file.c

With added commenting to describe the individual decoders a little
more.

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

7 years agoUpdate PR#3925
Roelof duToit [Thu, 13 Jul 2017 18:09:19 +0000 (14:09 -0400)]
Update PR#3925

Reviewed-by: Tim Hudson <tjh@openssl.org>
Reviewed-by: Bernd Edlinger <bernd.edlinger@hotmail.de>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/3925)

7 years agoRetry SSL_read on ERROR_WANT_READ.
Roelof duToit [Thu, 13 Jul 2017 17:07:26 +0000 (13:07 -0400)]
Retry SSL_read on ERROR_WANT_READ.
This resolves the retry issue in general, but also the specific case where a TLS 1.3 server sends a post-handshake NewSessionTicket message prior to appdata.

Reviewed-by: Tim Hudson <tjh@openssl.org>
Reviewed-by: Bernd Edlinger <bernd.edlinger@hotmail.de>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/3925)

7 years agoFix #946 Add -preserve_dates to x509 app
Todd Short [Fri, 20 Feb 2015 20:00:28 +0000 (15:00 -0500)]
Fix #946 Add -preserve_dates to x509 app

Add the -preserve_dates dates option to preserve dates when signing
a certificate.
Prevent -days and -preserve_dates being used simultaneously
Fixes #946

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

7 years agoFix bug in err_string_data_cmp
Rich Salz [Sat, 8 Jul 2017 16:43:55 +0000 (12:43 -0400)]
Fix bug in err_string_data_cmp

Unsigned overflow.  Thanks to Brian Carpenter for reporting this.

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

7 years agoRemove trailing blanks.
Pauli [Thu, 13 Jul 2017 00:41:57 +0000 (10:41 +1000)]
Remove trailing blanks.

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

7 years agoTest cleaning and modernisation
Pauli [Wed, 12 Jul 2017 21:37:01 +0000 (07:37 +1000)]
Test cleaning and modernisation

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

7 years agoChange return (x) to return x
Pauli [Wed, 12 Jul 2017 22:23:22 +0000 (08:23 +1000)]
Change return (x) to return x

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

7 years agoAvoid having an unsigned integer decrement below zero.
Pauli [Tue, 11 Jul 2017 22:54:14 +0000 (08:54 +1000)]
Avoid having an unsigned integer decrement below zero.

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

7 years agoFix some issues raise by coverity in the tests.
Pauli [Wed, 5 Jul 2017 23:10:28 +0000 (09:10 +1000)]
Fix some issues raise by coverity in the tests.

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

7 years agoAdd sanity test for certificate table
Dr. Stephen Henson [Sat, 8 Jul 2017 18:28:15 +0000 (19:28 +0100)]
Add sanity test for certificate table

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

7 years agoMove certificate table to header file so it can be tested.
Dr. Stephen Henson [Sat, 8 Jul 2017 11:11:59 +0000 (12:11 +0100)]
Move certificate table to header file so it can be tested.

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

7 years agoAdd additional ECDSA/Ed25519 selection tests.
Dr. Stephen Henson [Tue, 4 Jul 2017 12:07:22 +0000 (13:07 +0100)]
Add additional ECDSA/Ed25519 selection tests.

Add two tests with ECDSA+SHA256 preferred over Ed25519, the second also
excludes P-256 from the supported curves extension which will force the
use of Ed25519 in TLS 1.2, but not TLS 1.3: this would fail before the
certificate table updates.

Add TLS 1.3 test also with P-256 exclude from the groups extension: this
should have no effect as the groups extension is not used for signature
selection in TLS 1.3

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

7 years agoUse cert tables in ssl_set_sig_mask
Dr. Stephen Henson [Tue, 4 Jul 2017 10:38:23 +0000 (11:38 +0100)]
Use cert tables in ssl_set_sig_mask

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

7 years agomake errors
Dr. Stephen Henson [Sat, 8 Jul 2017 22:16:09 +0000 (23:16 +0100)]
make errors

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

7 years agoUse cert tables instead of X509_certificate_type
Dr. Stephen Henson [Thu, 29 Jun 2017 15:10:31 +0000 (16:10 +0100)]
Use cert tables instead of X509_certificate_type

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

7 years agoUse certificate tables instead of ssl_cert_type
Dr. Stephen Henson [Thu, 29 Jun 2017 14:20:09 +0000 (15:20 +0100)]
Use certificate tables instead of ssl_cert_type

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

7 years agoUse certificate tables instead of ssl_cipher_get_cert_index.
Dr. Stephen Henson [Thu, 29 Jun 2017 13:55:06 +0000 (14:55 +0100)]
Use certificate tables instead of ssl_cipher_get_cert_index.

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