When you expect a function to return a particular value, don't put a comment
saying that you expect it to return that value and compare it against zero
because it is supposedly faster, for this leads to bugs (especially given the
high rate of sloppy cut'n'paste within ssl3 and dtls1 routines in this
library).

Instead, compare for the exact value it ought to return upon success.

ok deraadt@
Oops, revert changes commited by mistake. The previous commit was supposed
to only apply to s23_srvr.c.
Fix CVE-2014-3506, DTLS handshake message size checks.  From
https://git.openssl.org/gitweb/?p=openssl.git;a=commit;h=1250f12613b61758675848f6600ebd914ccd7636
with comment/whitespace style tweaks

ok bcook@ miod@
Correct test reversed during merge of fix for CVE-2014-3509

pointed out by Watson Ladd (watson (at) matasano.com)
ok deraadt@
Fix CVE-2014-3508, pretty printing and OID validation:
 - make sure the output buffer is always NUL terminated if buf_len
   was initially greater than zero.
 - reject OIDs that are too long, too short, or not in proper base-127

Based on
https://git.openssl.org/gitweb/?p=openssl.git;a=commit;h=0042fb5fd1c9d257d713b15a1f45da05cf5c1c87

ok bcook@
Fix CVE-2014-3507, avoid allocating and then leaking a fresh fragment
structure when a zero-length fragment is received.

Based on
https://git.openssl.org/gitweb/?p=openssl.git;a=commitdiff;h=d0a4b7d1a2948fce38515b8d862f43e7ba0ebf74

diff by miod@, ok guenther@ bcook@ deraadt@
Only need <stdint.h> and not all of <inttypes.h> here
AF_IMPLINK and AF_BLUETOOTH are gone, but add printing of SOCK_SEQPACKET
Since we no longer need to support SSLv2-style cipher lists, start
unravelling the maze of function pointers and callbacks by directly
calling ssl3_{get,put}_cipher_by_char() and removing the
ssl_{get,put}_cipher_by_char macros.

Prompted by similar changes in boringssl.

ok guenther.
Remove disabled (weakened export and non-ephemeral DH) cipher suites from
the cipher list. This reduces code size, saves data segment space and
prevents them from being turned back on at runtime by flipping a bit in
memory.

ok guenther@
Tweak cipher list comments and add missing cipher value comments.
Provide a ssl3_get_cipher_by_id() function that allows ciphers to be looked
up by their ID. For one, this avoids an ugly mess in ssl_sess.c, where the
cipher value is manually written into a buffer, just so the cipher can be
located using ssl3_get_cipher_by_char().

ok bcook@ miod@
Currently, ssl3_put_char_by_bytes(NULL, NULL) is just a long handed way
of writing "2". Add a define for the SSL3_CIPHER_VALUE_SIZE (rather than
using a less-readable hardcoded constant everywhere) and replace the
ssl3_put_char_by_bytes(NULL, NULL) calls with it.

ok bcook@ miod@
Remove now-unused SSL2_STATE as well as ssl2-specific state machine values.
ok guenther@ jsing@
Unchecked memory allocation and potential leak upon error in
ssl3_get_cert_verify().
ok guenther@ jsing@
Check the return value of sk_SSL_CIPHER_new_null(), since it allocates
memory and can return NULL.

ok miod@
Guard RSA / RC4-5 ASM when NO_ASM is not defined

Most assembly blocks remain inactive if OPENSSL_NO_ASM is not defined,
only enabling inline assembly, but the RSA / RC4-5 blocks (used only in
amd64 systems) turn on implicitly. Guard these two as well.

This simplifies enabling just inline ASM in portable, no effective
change in OpenBSD.
digests: *_LONG_LOG2 is not used, stop talking about it

Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
md32_common: allow digest to override Final function

Define HASH_NO_FINAL to let digest implementation to provide Hash_Final
function on its own.

Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
SSL: Drop non-standard GOST ciphers

Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>