mirror of
https://github.com/libssh2/libssh2.git
synced 2025-11-21 14:00:51 +03:00
build: speed up and extend picky compiler options
Implement picky warnings with clang in autotools. Extend picky gcc warnings, sync them between build tools and compilers and greatly speed up detection in CMake. - autotools: enable clang compiler warnings with `--enable-debug`. - autotools: enable more gcc compiler warnings with `--enable-debug`. - autotools/cmake: sync compiler warning options between gcc and clang. - sync compiler warning options between autotools and cmake. - cmake: reduce option-checks to speed up the detection phase. Bring them down to 3 (from 35). Leaving some checks to keep the CMake logic alive and for an easy way to add new options. clang 3.0 (2011-11-29) and gcc 2.95 (1999-07-31) now required. - autotools logic copied from curl, with these differences: - delete `-Wimplicit-fallthrough=4` due to a false positive. - reduce `-Wformat-truncation=2` to `1` due to a false positive. - simplify MinGW detection for `-Wno-pedantic-ms-format`. - cmake: show enabled picky compiler options (like autotools). - cmake: do compile `tests/simple.c` and `tests/ssh2.c`. - fix new compiler warnings. - `tests/CMakeLists.txt`: fix indentation. Original source of autotools logic: -a8fbdb461c/acinclude.m4-a8fbdb461c/m4/curl-compilers.m4Notice that the autotools implementation considers Apple clang as legacy clang 3.7. CMake detection works more accurately, at the same time more error-prone and difficult to update due to the sparsely documented nature of Apple clang option evolution. Closes #952
This commit is contained in:
211
src/kex.c
211
src/kex.c
@@ -54,7 +54,7 @@
|
||||
kex_method_diffie_hellman_group1_sha1_key_exchange */
|
||||
|
||||
#define LIBSSH2_KEX_METHOD_EC_SHA_VALUE_HASH(value, reqlen, version) \
|
||||
{ \
|
||||
do { \
|
||||
if(type == LIBSSH2_EC_CURVE_NISTP256) { \
|
||||
LIBSSH2_KEX_METHOD_SHA_VALUE_HASH(256, value, reqlen, version); \
|
||||
} \
|
||||
@@ -64,12 +64,11 @@
|
||||
else if(type == LIBSSH2_EC_CURVE_NISTP521) { \
|
||||
LIBSSH2_KEX_METHOD_SHA_VALUE_HASH(512, value, reqlen, version); \
|
||||
} \
|
||||
} \
|
||||
|
||||
} while(0)
|
||||
|
||||
#define LIBSSH2_KEX_METHOD_SHA_VALUE_HASH(digest_type, value, \
|
||||
reqlen, version) \
|
||||
{ \
|
||||
do { \
|
||||
libssh2_sha##digest_type##_ctx hash; \
|
||||
size_t len = 0; \
|
||||
if(!(value)) { \
|
||||
@@ -96,7 +95,7 @@
|
||||
libssh2_sha##digest_type##_final(hash, (value) + len); \
|
||||
len += SHA##digest_type##_DIGEST_LENGTH; \
|
||||
} \
|
||||
}
|
||||
} while(0)
|
||||
|
||||
/*!
|
||||
* @note The following are wrapper functions used by diffie_hellman_sha_algo().
|
||||
@@ -1569,96 +1568,96 @@ kex_method_diffie_hellman_group_exchange_sha256_key_exchange
|
||||
*
|
||||
*/
|
||||
|
||||
#define LIBSSH2_KEX_METHOD_EC_SHA_HASH_CREATE_VERIFY(digest_type) \
|
||||
{ \
|
||||
libssh2_sha##digest_type##_ctx ctx; \
|
||||
exchange_state->exchange_hash = (void *)&ctx; \
|
||||
(void)libssh2_sha##digest_type##_init(&ctx); \
|
||||
if(session->local.banner) { \
|
||||
_libssh2_htonu32(exchange_state->h_sig_comp, \
|
||||
(uint32_t)(strlen((char *) session->local.banner) - 2)); \
|
||||
libssh2_sha##digest_type##_update(ctx, \
|
||||
exchange_state->h_sig_comp, 4); \
|
||||
libssh2_sha##digest_type##_update(ctx, \
|
||||
(char *) session->local.banner, \
|
||||
strlen((char *) \
|
||||
session->local.banner) \
|
||||
- 2); \
|
||||
} \
|
||||
else { \
|
||||
_libssh2_htonu32(exchange_state->h_sig_comp, \
|
||||
sizeof(LIBSSH2_SSH_DEFAULT_BANNER) - 1); \
|
||||
libssh2_sha##digest_type##_update(ctx, \
|
||||
exchange_state->h_sig_comp, 4); \
|
||||
libssh2_sha##digest_type##_update(ctx, \
|
||||
LIBSSH2_SSH_DEFAULT_BANNER, \
|
||||
#define LIBSSH2_KEX_METHOD_EC_SHA_HASH_CREATE_VERIFY(digest_type) \
|
||||
do { \
|
||||
libssh2_sha##digest_type##_ctx ctx; \
|
||||
exchange_state->exchange_hash = (void *)&ctx; \
|
||||
(void)libssh2_sha##digest_type##_init(&ctx); \
|
||||
if(session->local.banner) { \
|
||||
_libssh2_htonu32(exchange_state->h_sig_comp, \
|
||||
(uint32_t)(strlen((char *) session->local.banner) - 2)); \
|
||||
libssh2_sha##digest_type##_update(ctx, \
|
||||
exchange_state->h_sig_comp, 4); \
|
||||
libssh2_sha##digest_type##_update(ctx, \
|
||||
(char *) session->local.banner, \
|
||||
strlen((char *) \
|
||||
session->local.banner) \
|
||||
- 2); \
|
||||
} \
|
||||
else { \
|
||||
_libssh2_htonu32(exchange_state->h_sig_comp, \
|
||||
sizeof(LIBSSH2_SSH_DEFAULT_BANNER) - 1); \
|
||||
libssh2_sha##digest_type##_update(ctx, \
|
||||
exchange_state->h_sig_comp, 4); \
|
||||
libssh2_sha##digest_type##_update(ctx, \
|
||||
LIBSSH2_SSH_DEFAULT_BANNER, \
|
||||
sizeof(LIBSSH2_SSH_DEFAULT_BANNER) \
|
||||
- 1); \
|
||||
} \
|
||||
\
|
||||
_libssh2_htonu32(exchange_state->h_sig_comp, \
|
||||
(uint32_t)strlen((char *) session->remote.banner)); \
|
||||
libssh2_sha##digest_type##_update(ctx, \
|
||||
exchange_state->h_sig_comp, 4); \
|
||||
libssh2_sha##digest_type##_update(ctx, \
|
||||
session->remote.banner, \
|
||||
strlen((char *) \
|
||||
session->remote.banner)); \
|
||||
\
|
||||
_libssh2_htonu32(exchange_state->h_sig_comp, \
|
||||
(uint32_t)session->local.kexinit_len); \
|
||||
libssh2_sha##digest_type##_update(ctx, \
|
||||
exchange_state->h_sig_comp, 4); \
|
||||
libssh2_sha##digest_type##_update(ctx, \
|
||||
session->local.kexinit, \
|
||||
session->local.kexinit_len); \
|
||||
\
|
||||
_libssh2_htonu32(exchange_state->h_sig_comp, \
|
||||
(uint32_t)session->remote.kexinit_len); \
|
||||
libssh2_sha##digest_type##_update(ctx, \
|
||||
exchange_state->h_sig_comp, 4); \
|
||||
libssh2_sha##digest_type##_update(ctx, \
|
||||
session->remote.kexinit, \
|
||||
session->remote.kexinit_len); \
|
||||
\
|
||||
_libssh2_htonu32(exchange_state->h_sig_comp, \
|
||||
session->server_hostkey_len); \
|
||||
libssh2_sha##digest_type##_update(ctx, \
|
||||
exchange_state->h_sig_comp, 4); \
|
||||
libssh2_sha##digest_type##_update(ctx, \
|
||||
session->server_hostkey, \
|
||||
session->server_hostkey_len); \
|
||||
\
|
||||
_libssh2_htonu32(exchange_state->h_sig_comp, \
|
||||
(uint32_t)public_key_len); \
|
||||
libssh2_sha##digest_type##_update(ctx, \
|
||||
exchange_state->h_sig_comp, 4); \
|
||||
libssh2_sha##digest_type##_update(ctx, \
|
||||
public_key, \
|
||||
public_key_len); \
|
||||
\
|
||||
_libssh2_htonu32(exchange_state->h_sig_comp, \
|
||||
(uint32_t)server_public_key_len); \
|
||||
libssh2_sha##digest_type##_update(ctx, \
|
||||
exchange_state->h_sig_comp, 4); \
|
||||
libssh2_sha##digest_type##_update(ctx, \
|
||||
server_public_key, \
|
||||
server_public_key_len); \
|
||||
\
|
||||
libssh2_sha##digest_type##_update(ctx, \
|
||||
exchange_state->k_value, \
|
||||
exchange_state->k_value_len); \
|
||||
\
|
||||
libssh2_sha##digest_type##_final(ctx, exchange_state->h_sig_comp); \
|
||||
\
|
||||
if(session->hostkey-> \
|
||||
sig_verify(session, exchange_state->h_sig, \
|
||||
exchange_state->h_sig_len, exchange_state->h_sig_comp, \
|
||||
SHA##digest_type##_DIGEST_LENGTH, \
|
||||
&session->server_hostkey_abstract)) { \
|
||||
rc = -1; \
|
||||
} \
|
||||
} \
|
||||
- 1); \
|
||||
} \
|
||||
\
|
||||
_libssh2_htonu32(exchange_state->h_sig_comp, \
|
||||
(uint32_t)strlen((char *) session->remote.banner)); \
|
||||
libssh2_sha##digest_type##_update(ctx, \
|
||||
exchange_state->h_sig_comp, 4); \
|
||||
libssh2_sha##digest_type##_update(ctx, \
|
||||
session->remote.banner, \
|
||||
strlen((char *) \
|
||||
session->remote.banner)); \
|
||||
\
|
||||
_libssh2_htonu32(exchange_state->h_sig_comp, \
|
||||
(uint32_t)session->local.kexinit_len); \
|
||||
libssh2_sha##digest_type##_update(ctx, \
|
||||
exchange_state->h_sig_comp, 4); \
|
||||
libssh2_sha##digest_type##_update(ctx, \
|
||||
session->local.kexinit, \
|
||||
session->local.kexinit_len); \
|
||||
\
|
||||
_libssh2_htonu32(exchange_state->h_sig_comp, \
|
||||
(uint32_t)session->remote.kexinit_len); \
|
||||
libssh2_sha##digest_type##_update(ctx, \
|
||||
exchange_state->h_sig_comp, 4); \
|
||||
libssh2_sha##digest_type##_update(ctx, \
|
||||
session->remote.kexinit, \
|
||||
session->remote.kexinit_len); \
|
||||
\
|
||||
_libssh2_htonu32(exchange_state->h_sig_comp, \
|
||||
session->server_hostkey_len); \
|
||||
libssh2_sha##digest_type##_update(ctx, \
|
||||
exchange_state->h_sig_comp, 4); \
|
||||
libssh2_sha##digest_type##_update(ctx, \
|
||||
session->server_hostkey, \
|
||||
session->server_hostkey_len); \
|
||||
\
|
||||
_libssh2_htonu32(exchange_state->h_sig_comp, \
|
||||
(uint32_t)public_key_len); \
|
||||
libssh2_sha##digest_type##_update(ctx, \
|
||||
exchange_state->h_sig_comp, 4); \
|
||||
libssh2_sha##digest_type##_update(ctx, \
|
||||
public_key, \
|
||||
public_key_len); \
|
||||
\
|
||||
_libssh2_htonu32(exchange_state->h_sig_comp, \
|
||||
(uint32_t)server_public_key_len); \
|
||||
libssh2_sha##digest_type##_update(ctx, \
|
||||
exchange_state->h_sig_comp, 4); \
|
||||
libssh2_sha##digest_type##_update(ctx, \
|
||||
server_public_key, \
|
||||
server_public_key_len); \
|
||||
\
|
||||
libssh2_sha##digest_type##_update(ctx, \
|
||||
exchange_state->k_value, \
|
||||
exchange_state->k_value_len); \
|
||||
\
|
||||
libssh2_sha##digest_type##_final(ctx, exchange_state->h_sig_comp); \
|
||||
\
|
||||
if(session->hostkey-> \
|
||||
sig_verify(session, exchange_state->h_sig, \
|
||||
exchange_state->h_sig_len, exchange_state->h_sig_comp, \
|
||||
SHA##digest_type##_DIGEST_LENGTH, \
|
||||
&session->server_hostkey_abstract)) { \
|
||||
rc = -1; \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
|
||||
#if LIBSSH2_ECDSA
|
||||
@@ -3105,17 +3104,19 @@ kex_method_list(unsigned char *buf, uint32_t list_strlen,
|
||||
(uint32_t)((prefvar) ? strlen(prefvar) : \
|
||||
kex_method_strlen((LIBSSH2_COMMON_METHOD**)(defaultvar)))
|
||||
|
||||
#define LIBSSH2_METHOD_PREFS_STR(buf, prefvarlen, prefvar, defaultvar) \
|
||||
if(prefvar) { \
|
||||
_libssh2_htonu32((buf), (prefvarlen)); \
|
||||
buf += 4; \
|
||||
memcpy((buf), (prefvar), (prefvarlen)); \
|
||||
buf += (prefvarlen); \
|
||||
} \
|
||||
else { \
|
||||
buf += kex_method_list((buf), (prefvarlen), \
|
||||
(LIBSSH2_COMMON_METHOD**)(defaultvar)); \
|
||||
}
|
||||
#define LIBSSH2_METHOD_PREFS_STR(buf, prefvarlen, prefvar, defaultvar) \
|
||||
do { \
|
||||
if(prefvar) { \
|
||||
_libssh2_htonu32((buf), (prefvarlen)); \
|
||||
buf += 4; \
|
||||
memcpy((buf), (prefvar), (prefvarlen)); \
|
||||
buf += (prefvarlen); \
|
||||
} \
|
||||
else { \
|
||||
buf += kex_method_list((buf), (prefvarlen), \
|
||||
(LIBSSH2_COMMON_METHOD**)(defaultvar)); \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
/* kexinit
|
||||
* Send SSH_MSG_KEXINIT packet
|
||||
|
||||
Reference in New Issue
Block a user