diff options
author | John Baldwin <jhb@FreeBSD.org> | 2020-07-29 14:56:58 -0700 |
---|---|---|
committer | Matt Caswell <matt@openssl.org> | 2020-08-31 09:34:19 +0100 |
commit | eb818d23c2f451ed56030d9e9fb94bd60ec48b07 (patch) | |
tree | 0a3d1f30c3b58d33a5523effc7826ea0a34bcac5 /test | |
parent | c7b46b549d59797c3f1ea6541f8ff6f02009cbc5 (diff) |
Refactor the KTLS tests to minimize code duplication.
Use the low 4 bits of the test number directly as flags for which of
the connection sides should use KTLS or not for each test instead of
having 16 nearly identical functions to do the same thing.
This makes it easier to skip tests that aren't supported (e.g. KTLS RX
on TLS 1.3).
Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/12111)
Diffstat (limited to 'test')
-rw-r--r-- | test/sslapitest.c | 365 |
1 files changed, 24 insertions, 341 deletions
diff --git a/test/sslapitest.c b/test/sslapitest.c index cf9947ea0b..0914ac559c 100644 --- a/test/sslapitest.c +++ b/test/sslapitest.c @@ -1177,314 +1177,11 @@ end: return testresult; } -static int test_ktls_no_txrx_client_no_txrx_server(int tlsver) -{ - int testresult = 1; - -#ifdef OPENSSL_KTLS_AES_GCM_128 - testresult &= execute_test_ktls(0, 0, 0, 0, tlsver, - "AES128-GCM-SHA256", TLS_CIPHER_AES_GCM_128_REC_SEQ_SIZE); -#endif -#ifdef OPENSSL_KTLS_AES_CCM_128 - testresult &= execute_test_ktls(0, 0, 0, 0, tlsver, - "AES128-CCM-SHA256", TLS_CIPHER_AES_CCM_128_REC_SEQ_SIZE); -#endif -#ifdef OPENSSL_KTLS_AES_GCM_256 - testresult &= execute_test_ktls(0, 0, 0, 0, tlsver, - "AES256-GCM-SHA384", TLS_CIPHER_AES_GCM_256_REC_SEQ_SIZE); -#endif - return testresult; -} - -static int test_ktls_no_rx_client_no_txrx_server(int tlsver) -{ - int testresult = 1; - -#ifdef OPENSSL_KTLS_AES_GCM_128 - testresult &= execute_test_ktls(1, 0, 0, 0, tlsver, - "AES128-GCM-SHA256", TLS_CIPHER_AES_GCM_128_REC_SEQ_SIZE); -#endif -#ifdef OPENSSL_KTLS_AES_CCM_128 - testresult &= execute_test_ktls(1, 0, 0, 0, tlsver, - "AES128-CCM-SHA256", TLS_CIPHER_AES_CCM_128_REC_SEQ_SIZE); -#endif -#ifdef OPENSSL_KTLS_AES_GCM_256 - testresult &= execute_test_ktls(1, 0, 0, 0, tlsver, - "AES256-GCM-SHA384", TLS_CIPHER_AES_GCM_256_REC_SEQ_SIZE); -#endif - return testresult; -} - -static int test_ktls_no_tx_client_no_txrx_server(int tlsver) -{ - int testresult = 1; - -#ifdef OPENSSL_KTLS_AES_GCM_128 - testresult &= execute_test_ktls(0, 1, 0, 0, tlsver, - "AES128-GCM-SHA256", TLS_CIPHER_AES_GCM_128_REC_SEQ_SIZE); -#endif -#ifdef OPENSSL_KTLS_AES_CCM_128 - testresult &= execute_test_ktls(0, 1, 0, 0, tlsver, - "AES128-CCM-SHA256", TLS_CIPHER_AES_CCM_128_REC_SEQ_SIZE); -#endif -#ifdef OPENSSL_KTLS_AES_GCM_256 - testresult &= execute_test_ktls(0, 1, 0, 0, tlsver, - "AES256-GCM-SHA384", TLS_CIPHER_AES_GCM_256_REC_SEQ_SIZE); -#endif - return testresult; -} - -static int test_ktls_client_no_txrx_server(int tlsver) -{ - int testresult = 1; - -#ifdef OPENSSL_KTLS_AES_GCM_128 - testresult &= execute_test_ktls(1, 1, 0, 0, tlsver, - "AES128-GCM-SHA256", TLS_CIPHER_AES_GCM_128_REC_SEQ_SIZE); -#endif -#ifdef OPENSSL_KTLS_AES_CCM_128 - testresult &= execute_test_ktls(1, 1, 0, 0, tlsver, - "AES128-CCM-SHA256", TLS_CIPHER_AES_CCM_128_REC_SEQ_SIZE); -#endif -#ifdef OPENSSL_KTLS_AES_GCM_256 - testresult &= execute_test_ktls(1, 1, 0, 0, tlsver, - "AES256-GCM-SHA384", TLS_CIPHER_AES_GCM_256_REC_SEQ_SIZE); -#endif - return testresult; -} - -static int test_ktls_no_txrx_client_no_rx_server(int tlsver) -{ - int testresult = 1; - -#ifdef OPENSSL_KTLS_AES_GCM_128 - testresult &= execute_test_ktls(0, 0, 1, 0, tlsver, - "AES128-GCM-SHA256", TLS_CIPHER_AES_GCM_128_REC_SEQ_SIZE); -#endif -#ifdef OPENSSL_KTLS_AES_CCM_128 - testresult &= execute_test_ktls(0, 0, 1, 0, tlsver, - "AES128-CCM-SHA256", TLS_CIPHER_AES_CCM_128_REC_SEQ_SIZE); -#endif -#ifdef OPENSSL_KTLS_AES_GCM_256 - testresult &= execute_test_ktls(0, 0, 1, 0, tlsver, - "AES256-GCM-SHA384", TLS_CIPHER_AES_GCM_256_REC_SEQ_SIZE); -#endif - return testresult; -} - -static int test_ktls_no_rx_client_no_rx_server(int tlsver) -{ - int testresult = 1; - -#ifdef OPENSSL_KTLS_AES_GCM_128 - testresult &= execute_test_ktls(1, 0, 1, 0, tlsver, - "AES128-GCM-SHA256", TLS_CIPHER_AES_GCM_128_REC_SEQ_SIZE); -#endif -#ifdef OPENSSL_KTLS_AES_CCM_128 - testresult &= execute_test_ktls(1, 0, 1, 0, tlsver, - "AES128-CCM-SHA256", TLS_CIPHER_AES_CCM_128_REC_SEQ_SIZE); -#endif -#ifdef OPENSSL_KTLS_AES_GCM_256 - testresult &= execute_test_ktls(1, 0, 1, 0, tlsver, - "AES256-GCM-SHA384", TLS_CIPHER_AES_GCM_256_REC_SEQ_SIZE); -#endif - return testresult; -} - -static int test_ktls_no_tx_client_no_rx_server(int tlsver) -{ - int testresult = 1; - -#ifdef OPENSSL_KTLS_AES_GCM_128 - testresult &= execute_test_ktls(0, 1, 1, 0, tlsver, - "AES128-GCM-SHA256", TLS_CIPHER_AES_GCM_128_REC_SEQ_SIZE); -#endif -#ifdef OPENSSL_KTLS_AES_CCM_128 - testresult &= execute_test_ktls(0, 1, 1, 0, tlsver, - "AES128-CCM-SHA256", TLS_CIPHER_AES_CCM_128_REC_SEQ_SIZE); -#endif -#ifdef OPENSSL_KTLS_AES_GCM_256 - testresult &= execute_test_ktls(0, 1, 1, 0, tlsver, - "AES256-GCM-SHA384", TLS_CIPHER_AES_GCM_256_REC_SEQ_SIZE); -#endif - return testresult; -} - -static int test_ktls_client_no_rx_server(int tlsver) -{ - int testresult = 1; - -#ifdef OPENSSL_KTLS_AES_GCM_128 - testresult &= execute_test_ktls(1, 1, 1, 0, tlsver, - "AES128-GCM-SHA256", TLS_CIPHER_AES_GCM_128_REC_SEQ_SIZE); -#endif -#ifdef OPENSSL_KTLS_AES_CCM_128 - testresult &= execute_test_ktls(1, 1, 1, 0, tlsver, - "AES128-CCM-SHA256", TLS_CIPHER_AES_CCM_128_REC_SEQ_SIZE); -#endif -#ifdef OPENSSL_KTLS_AES_GCM_256 - testresult &= execute_test_ktls(1, 1, 1, 0, tlsver, - "AES256-GCM-SHA384", TLS_CIPHER_AES_GCM_256_REC_SEQ_SIZE); -#endif - return testresult; -} - -static int test_ktls_no_txrx_client_no_tx_server(int tlsver) -{ - int testresult = 1; - -#ifdef OPENSSL_KTLS_AES_GCM_128 - testresult &= execute_test_ktls(0, 0, 0, 1, tlsver, - "AES128-GCM-SHA256", TLS_CIPHER_AES_GCM_128_REC_SEQ_SIZE); -#endif -#ifdef OPENSSL_KTLS_AES_CCM_128 - testresult &= execute_test_ktls(0, 0, 0, 1, tlsver, - "AES128-CCM-SHA256", TLS_CIPHER_AES_CCM_128_REC_SEQ_SIZE); -#endif -#ifdef OPENSSL_KTLS_AES_GCM_256 - testresult &= execute_test_ktls(0, 0, 0, 1, tlsver, - "AES256-GCM-SHA384", TLS_CIPHER_AES_GCM_256_REC_SEQ_SIZE); -#endif - return testresult; -} - -static int test_ktls_no_rx_client_no_tx_server(int tlsver) -{ - int testresult = 1; - -#ifdef OPENSSL_KTLS_AES_GCM_128 - testresult &= execute_test_ktls(1, 0, 0, 1, tlsver, - "AES128-GCM-SHA256", TLS_CIPHER_AES_GCM_128_REC_SEQ_SIZE); -#endif -#ifdef OPENSSL_KTLS_AES_CCM_128 - testresult &= execute_test_ktls(1, 0, 0, 1, tlsver, - "AES128-CCM-SHA256", TLS_CIPHER_AES_CCM_128_REC_SEQ_SIZE); -#endif -#ifdef OPENSSL_KTLS_AES_GCM_256 - testresult &= execute_test_ktls(1, 0, 0, 1, tlsver, - "AES256-GCM-SHA384", TLS_CIPHER_AES_GCM_256_REC_SEQ_SIZE); -#endif - return testresult; -} - -static int test_ktls_no_tx_client_no_tx_server(int tlsver) -{ - int testresult = 1; - -#ifdef OPENSSL_KTLS_AES_GCM_128 - testresult &= execute_test_ktls(0, 1, 0, 1, tlsver, - "AES128-GCM-SHA256", TLS_CIPHER_AES_GCM_128_REC_SEQ_SIZE); -#endif -#ifdef OPENSSL_KTLS_AES_CCM_128 - testresult &= execute_test_ktls(0, 1, 0, 1, tlsver, - "AES128-CCM-SHA256", TLS_CIPHER_AES_CCM_128_REC_SEQ_SIZE); -#endif -#ifdef OPENSSL_KTLS_AES_GCM_256 - testresult &= execute_test_ktls(0, 1, 0, 1, tlsver, - "AES256-GCM-SHA384", TLS_CIPHER_AES_GCM_256_REC_SEQ_SIZE); -#endif - return testresult; -} - -static int test_ktls_client_no_tx_server(int tlsver) -{ - int testresult = 1; - -#ifdef OPENSSL_KTLS_AES_GCM_128 - testresult &= execute_test_ktls(1, 1, 0, 1, tlsver, - "AES128-GCM-SHA256", TLS_CIPHER_AES_GCM_128_REC_SEQ_SIZE); -#endif -#ifdef OPENSSL_KTLS_AES_CCM_128 - testresult &= execute_test_ktls(1, 1, 0, 1, tlsver, - "AES128-CCM-SHA256", TLS_CIPHER_AES_CCM_128_REC_SEQ_SIZE); -#endif -#ifdef OPENSSL_KTLS_AES_GCM_256 - testresult &= execute_test_ktls(1, 1, 0, 1, tlsver, - "AES256-GCM-SHA384", TLS_CIPHER_AES_GCM_256_REC_SEQ_SIZE); -#endif - return testresult; -} - -static int test_ktls_no_txrx_client_server(int tlsver) -{ - int testresult = 1; - -#ifdef OPENSSL_KTLS_AES_GCM_128 - testresult &= execute_test_ktls(0, 0, 1, 1, tlsver, - "AES128-GCM-SHA256", TLS_CIPHER_AES_GCM_128_REC_SEQ_SIZE); -#endif -#ifdef OPENSSL_KTLS_AES_CCM_128 - testresult &= execute_test_ktls(0, 0, 1, 1, tlsver, - "AES128-CCM-SHA256", TLS_CIPHER_AES_CCM_128_REC_SEQ_SIZE); -#endif -#ifdef OPENSSL_KTLS_AES_GCM_256 - testresult &= execute_test_ktls(0, 0, 1, 1, tlsver, - "AES256-GCM-SHA384", TLS_CIPHER_AES_GCM_256_REC_SEQ_SIZE); -#endif - return testresult; -} - -static int test_ktls_no_rx_client_server(int tlsver) -{ - int testresult = 1; - -#ifdef OPENSSL_KTLS_AES_GCM_128 - testresult &= execute_test_ktls(1, 0, 1, 1, tlsver, - "AES128-GCM-SHA256", TLS_CIPHER_AES_GCM_128_REC_SEQ_SIZE); -#endif -#ifdef OPENSSL_KTLS_AES_CCM_128 - testresult &= execute_test_ktls(1, 0, 1, 1, tlsver, - "AES128-CCM-SHA256", TLS_CIPHER_AES_CCM_128_REC_SEQ_SIZE); -#endif -#ifdef OPENSSL_KTLS_AES_GCM_256 - testresult &= execute_test_ktls(1, 0, 1, 1, tlsver, - "AES256-GCM-SHA384", TLS_CIPHER_AES_GCM_256_REC_SEQ_SIZE); -#endif - return testresult; -} - -static int test_ktls_no_tx_client_server(int tlsver) -{ - int testresult = 1; - -#ifdef OPENSSL_KTLS_AES_GCM_128 - testresult &= execute_test_ktls(0, 1, 1, 1, tlsver, - "AES128-GCM-SHA256", TLS_CIPHER_AES_GCM_128_REC_SEQ_SIZE); -#endif -#ifdef OPENSSL_KTLS_AES_CCM_128 - testresult &= execute_test_ktls(0, 1, 1, 1, tlsver, - "AES128-CCM-SHA256", TLS_CIPHER_AES_CCM_128_REC_SEQ_SIZE); -#endif -#ifdef OPENSSL_KTLS_AES_GCM_256 - testresult &= execute_test_ktls(0, 1, 1, 1, tlsver, - "AES256-GCM-SHA384", TLS_CIPHER_AES_GCM_256_REC_SEQ_SIZE); -#endif - return testresult; -} - -static int test_ktls_client_server(int tlsver) -{ - int testresult = 1; - -#ifdef OPENSSL_KTLS_AES_GCM_128 - testresult &= execute_test_ktls(1, 1, 1, 1, tlsver, - "AES128-GCM-SHA256", TLS_CIPHER_AES_GCM_128_REC_SEQ_SIZE); -#endif -#ifdef OPENSSL_KTLS_AES_CCM_128 - testresult &= execute_test_ktls(1, 1, 1, 1, tlsver, - "AES128-CCM-SHA256", TLS_CIPHER_AES_CCM_128_REC_SEQ_SIZE); -#endif -#ifdef OPENSSL_KTLS_AES_GCM_256 - testresult &= execute_test_ktls(1, 1, 1, 1, tlsver, - "AES256-GCM-SHA384", TLS_CIPHER_AES_GCM_256_REC_SEQ_SIZE); -#endif - return testresult; -} - #if !defined(OPENSSL_NO_TLS1_2) || !defined(OPENSSL_NO_TLS1_3) static int test_ktls(int test) { - int tlsver; + int cis_ktls_tx, cis_ktls_rx, sis_ktls_tx, sis_ktls_rx; + int tlsver, testresult; if (test > 15) { #if defined(OPENSSL_NO_TLS1_3) @@ -1501,42 +1198,28 @@ static int test_ktls(int test) #endif } - switch(test) { - case 0: - return test_ktls_no_txrx_client_no_txrx_server(tlsver); - case 1: - return test_ktls_no_rx_client_no_txrx_server(tlsver); - case 2: - return test_ktls_no_tx_client_no_txrx_server(tlsver); - case 3: - return test_ktls_client_no_txrx_server(tlsver); - case 4: - return test_ktls_no_txrx_client_no_rx_server(tlsver); - case 5: - return test_ktls_no_rx_client_no_rx_server(tlsver); - case 6: - return test_ktls_no_tx_client_no_rx_server(tlsver); - case 7: - return test_ktls_client_no_rx_server(tlsver); - case 8: - return test_ktls_no_txrx_client_no_tx_server(tlsver); - case 9: - return test_ktls_no_rx_client_no_tx_server(tlsver); - case 10: - return test_ktls_no_tx_client_no_tx_server(tlsver); - case 11: - return test_ktls_client_no_tx_server(tlsver); - case 12: - return test_ktls_no_txrx_client_server(tlsver); - case 13: - return test_ktls_no_rx_client_server(tlsver); - case 14: - return test_ktls_no_tx_client_server(tlsver); - case 15: - return test_ktls_client_server(tlsver); - default: - return 0; - } + cis_ktls_tx = (test & 1) != 0; + cis_ktls_rx = (test & 2) != 0; + sis_ktls_tx = (test & 4) != 0; + sis_ktls_rx = (test & 8) != 0; + + testresult = 1; +#ifdef OPENSSL_KTLS_AES_GCM_128 + testresult &= execute_test_ktls(cis_ktls_tx, cis_ktls_rx, sis_ktls_tx, + sis_ktls_rx, tlsver, "AES128-GCM-SHA256", + TLS_CIPHER_AES_GCM_128_REC_SEQ_SIZE); +#endif +#ifdef OPENSSL_KTLS_AES_CCM_128 + testresult &= execute_test_ktls(cis_ktls_tx, cis_ktls_rx, sis_ktls_tx, + sis_ktls_rx, tlsver, "AES128-CCM-SHA256", + TLS_CIPHER_AES_CCM_128_REC_SEQ_SIZE); +#endif +#ifdef OPENSSL_KTLS_AES_GCM_256 + testresult &= execute_test_ktls(cis_ktls_tx, cis_ktls_rx, sis_ktls_tx, + sis_ktls_rx, tlsver, "AES256-GCM-SHA384", + TLS_CIPHER_AES_GCM_256_REC_SEQ_SIZE); +#endif + return testresult; } static int test_ktls_sendfile_anytls(int tst) |