Add session/channel byte/packet counters

Signed-off-by: Audrius Butkevicius <audrius.butkevicius@elastichosts.com>
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'.
channel: add ssh_channel_write timeout family
poll: ssh_event_set/get_fd_events
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).
packet: remove extra memset of 'padstring'
packet: elide two buffer_prepend calls into one

In packet_send2, rather that issue two separate buffer_prepend_data calls
(each of which may entail realloc + memmove + memcpy), elide the prepend
work into a single buffer_prepend_data: the header information is computed
locally, and a single 5 byte prepend operation is now done instead of
prepending 1, then 4 bytes.
buffer: reserve PACKET_SEND_HEADER_SIZE for packet_send2
pki_crypto: guard against NULL pubkey->rsa in signature extraction
packet: log disconnect code in host byte order
bind: only set bindfd after successful listen

In 'ssh_bind_listen', move setting of 'sshbind->bindfd' to only happen after
the listen call: otherwise 'bindfd' can be set to a bogus descriptor for the
case that listen fails.
bind: add selective use of XCLOSE
socket: add selective use of XCLOSE
doc: fix SSH_BIND_OPTIONS_RSAKEY typo
options: add SSH_BIND_OPTIONS_ECDSAKEY
pki: Fix ability to use ECDSA host keys

- Ensure ecdsa_nid is copied into duplicated private keys
- Use SHA-2 for sessionid generation with ECDSA keys (was SHA-1)

Signed-off-by: Alan Dunn <amdunn@gmail.com>
kex: enable more ECDSA hostkey algos
pki crypto: pki_key_ecdsa_name
channel: check for closed state in waitwindow loops