Add missing NULL checks for calls to ssl_replace_hash(). This function
calls EVP_MD_CTX_create(), which will return NULL if it fails to allocate
memory.

ok miod@
Fix another two cases where the return value of ssl_replace_hash() is
unchecked.

In the case of tls1_change_cipher_state(), it is fairly pointless to use
ssl_replace_hash(), since it does not initialise the hash and there is
special handling required in the DTLS write case. Instead, just inline
the part of ssl_replace_hash() that is needed and only
ssl_clear_hash_ctx() the write hash in the non-DTLS case.

Also add a detailed comment explaining why there needs to be specialised
handling for DTLS write context and where the contexts are actually freed.

ok miod@
When you have functions that perform specific functions, use them.

EVP_CIPHER_CTX_free() does a NULL check, then calls EVP_CIPHER_CTX_cleanup()
and frees the memory. COMP_CTX_free() also had its own NULL check, so there
is no point in duplicating that here.

ok beck@
Make it substantially easier to identify protocol version requirements
by adding an enc_flags field to the ssl3_enc_method, specifying four flags
that are used with this field and providing macros for evaluating these
conditions. Currently the version requirements are identified by
continually checking the version number and other criteria.

This change also adds separate SSL3_ENC_METHOD data for TLS v1.1 and v1.2,
since they have different enc_flags from TLS v1.

Based on changes in OpenSSL head.

No objection from miod@
use calloc, from Benjamin Baier
repair KNF indent
unidef DH, ECDH, and ECDSA. there's no purpose to a libssl without them.
ok deraadt jsing
consistent braces
line up else better
no space before label
kssl is dead.
Any sane platform has stdio. Stop pretending we will ever use a platform
that does not.
"fire bomb" tedu@
Make make includes work again without kssl.h
remove back compat that was already disabled back in 1998.
from Alexander Schrijver
Everything sane has stdio, and FILE *. we don't need ifdefs for this.
ok to firebomb from tedu@
convert 53 malloc(a*b) to reallocarray(NULL, a, b).  that is 53
potential integer overflows easily changed into an allocation return
of NULL, with errno nicely set if need be.  checks for an allocations
returning NULL are commonplace, or if the object is dereferenced
(quite normal) will result in a nice fault which can be detected &
repaired properly.
ok tedu
ok, next pass after review:  when possible, put the reallocarray arguments
in the "size_t nmemb, size_t size"
we no longer care that these aren't used for ssl2
the comment says RAND_pseudo_bytes should be RAND_bytes. make it so.
ok deraadt
trivial realloc -> reallocarray