bignum: no-op make_string_bn_inplace for LIBGCRYPT

Disable the 'make_string_bn_inplace' helper function for the LIBGCRYPT
build, rather than using '#error' to fail the build completely.

Signed-off-by: Jon Simons <jon@jonsimons.org>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
torture: fix warning for SSH_KEYTYPE_ED25519

Signed-off-by: Jon Simons <jon@jonsimons.org>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
pki_gcrypt: fix warnings for SSH_KEYTYPE_ED25519

Signed-off-by: Jon Simons <jon@jonsimons.org>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
pki_gcrypt: fix DSA signature extraction

Fix DSA signature extraction for the LIBGCRYPT build.  Here, the same fix
that was applied to the LIBCRYPTO build for https://red.libssh.org/issues/144
is now adapted for pki_gcrypt.  Additionally, ensure to set the resulting
output sig_blob buffer before returning.

Before this fix, one can observe the failure with the pkd test on a LIBGCRYPT
build as so:

  # ./pkd_hello -i 1 -t torture_pkd_openssh_dsa_dsa_default

After, runs of 10000 back-to-back iterations of the same test are passing.

Signed-off-by: Jon Simons <jon@jonsimons.org>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
messages: emit pubkey failures to callbacks

With this change, errors encountered while processing public keys
in 'ssh_packet_userauth_request' will be propagated back up to the
user-provided 'auth_pubkey_function' callback.

For example, if signature validation fails, the user callback will
be invoked with a signature state of SSH_PUBLICKEY_STATE_WRONG.

Before this change, a failure in signature validation would not be
made explicit via the 'ssh_server_callbacks'.

Conflicts:
	src/messages.c
channel: add ssh_channel_write timeout family

Conflicts:
	include/libssh/channels.h
	src/channels.c
buffer: always start off with BUFFER_INIT_SIZE

Initialize all new buffers with a BUFFER_INIT_SIZE allocation right
off the bat, to avoid later byte-by-byte repeated realloc calls.
buffer: never realloc down in buffer_reinit

Never realloc buffers down to 127 bytes in buffer_reinit: during large
transmits, this causes a "realloc ping-pong" with the session out buffer
constantly being realloc'd down to 127 bytes, just to be realloc'd back
up to 32 kilobytes for the next packet send (for example).

Were the realloc behavior desired in buffer_reinit, it would be better
to issue a free followed by malloc (as-is, 127 bytes that we don't care
about are memmove'd to the new buffer).
bind: add selective use of XCLOSE
socket: add selective use of XCLOSE
channel: is_local_eof|closed getters

Given an invocation to 'ssh_channel_close', upon SSH_AGAIN, there
is currently no way to know whether the SSH_AGAIN means that EOF
has been totally sent and CLOSE message bytes have been enqueued,
or whether sending and flushing EOF needs to be retried, and CLOSE
message bytes are yet to be queued.

Expose getters for 'local_eof' and the new field 'local_closed'.
Until the latter is set, it is not the case the CLOSE message
bytes have been enqueued to the outgoing session socket.

Motivation: when unable to distinguish the above ssh_channel_close
cases, clients either have to resort to missing a channel close, or
possibly sending more than one CLOSE message for a given channel.
Both of those options are bad for the case of session multiplexing
(for example, OpenSSH might indefinitely hang if it never sees a
corresponding CLOSE response for a closed channel; likewise, it
may abruptly disconnect if it receives a duplicate CLOSE or a
CLOSE for an unknown channel).
channel: DISABLE_AUTH_AGENT_REQ test

Conflicts:
	src/channels.c
session: check session error in blocking_flush
session: add get_in|outbuffer_rest_len helpers
ConfigureChecks.cmake: fix htonll/ntohll checks

Fixes the build on OSX Yosemite, Linux build remains OK.

See also:
 * https://red.libssh.org/issues/164
 * https://red.libssh.org/issues/174
server: expose 'ssh_server_init_kex' API

Expose an API 'ssh_server_init_kex' which allows one to change the set of
key exchange, hostkey, ciphers, MACs, and compression algorithms currently
configured for the ssh_session at hand, after having started the
'ssh_handle_key_exchange' process.

One can use this API from the already-existing 'connect_status_function'
callback to dynamically modify the set of algorithms used after having
received the client banner, but before sending out the initial KEXINIT
message.

For example, one might want to prevent advertising the curve25519 key
exchange algorithm for older OpenSSH clients due to interop bugs.

BUG: https://red.libssh.org/issues/159

Signed-off-by: Jon Simons <jon@jonsimons.org>