Double free in i2o_ECPublicKey

PR: 3338
Set Enveloped data version to 2 if ktri version not zero.
(cherry picked from commit 9c5d953a07f472452ae2cb578e39eddea2de2b9c)
Initialize num properly.

PR#3289
PR#3345
(cherry picked from commit 3ba1e406c2309adb427ced9815ebf05f5b58d155)
dso: eliminate VMS code on non-VMS systems

Even though the meat of dso_vms.c is compiled out on non-VMS builds,
the (pre-)compiler still traverses some of the macro handling. This
trips up at least one non-VMS build configuration, so this commit
makes the skip-VMS case more robust.

Signed-off-by: Geoff Thorpe <geoff@openssl.org>
bignum: allow concurrent BN_MONT_CTX_set_locked()

The lazy-initialisation of BN_MONT_CTX was serialising all threads, as
noted by Daniel Sands and co at Sandia. This was to handle the case that
2 or more threads race to lazy-init the same context, but stunted all
scalability in the case where 2 or more threads are doing unrelated
things! We favour the latter case by punishing the former. The init work
gets done by each thread that finds the context to be uninitialised, and
we then lock the "set" logic after that work is done - the winning
thread's work gets used, the losing threads throw away what they've done.

Signed-off-by: Geoff Thorpe <geoff@openssl.org>
evp: prevent underflow in base64 decoding

This patch resolves RT ticket #2608.

Thanks to Robert Dugal for originally spotting this, and to David
Ramos for noticing that the ball had been dropped.

Signed-off-by: Geoff Thorpe <geoff@openssl.org>
Fixed NULL pointer dereference in PKCS7_dataDecode reported by David Ramos in PR#3339
fix coverity issue 966597 - error line is not always initialised
PR#3342 fix resource leak coverity issue 966577
coverity 966576 - close socket in error path
Return an error if no recipient type matches.

If the key type does not match any CMS recipient type return
an error instead of using a random key (MMA mitigation). This
does not leak any useful information to an attacker.

PR#3348
(cherry picked from commit 83a3182e0560f76548f4378325393461f6275493)
safety check to ensure we dont send out beyond the users buffer
Fix infinite loop. PR#3347
Avoid out-of-bounds write in SSL_get_shared_ciphers

PR: 3317
Fixed NULL pointer dereference. See PR#3321
Replace manual ASN1 decoder with ASN1_get_object

Replace manual ASN.1 decoder with ASN1_get object. This
will decode the tag and length properly and check against
it does not exceed the supplied buffer length.

PR#3335
(cherry picked from commit b0308dddd1cc6a8e1de803ef29ba6da25ee072c2)
Correct the return type on the signature for X509_STORE_CTX_get_ex_data given in the pod file.
Check sk_SSL_CIPHER_num() after assigning sk.
Corrected POD syntax errors. PR#3353
Add information to BUGS section of enc documentation. PR#3354