diff options
Diffstat (limited to 'test')
74 files changed, 2442 insertions, 337 deletions
diff --git a/test/acvp_test.c b/test/acvp_test.c index 45509095af..82ecaf8b00 100644 --- a/test/acvp_test.c +++ b/test/acvp_test.c @@ -46,6 +46,9 @@ static OSSL_PROVIDER *prov_null = NULL; static OSSL_LIB_CTX *libctx = NULL; static SELF_TEST_ARGS self_test_args = { 0 }; static OSSL_CALLBACK self_test_events; +#ifndef OPENSSL_NO_DSA +static int dsasign_allowed = 1; +#endif const OPTIONS *test_get_options(void) { @@ -597,12 +600,14 @@ static int dsa_siggen_test(int id) if (!TEST_ptr(pkey = dsa_keygen(tst->L, tst->N))) goto err; - if (!TEST_true(sig_gen(pkey, NULL, tst->digest_alg, tst->msg, tst->msg_len, - &sig, &sig_len)) - || !TEST_true(get_dsa_sig_rs_bytes(sig, sig_len, &r, &s, &rlen, &slen))) - goto err; - test_output_memory("r", r, rlen); - test_output_memory("s", s, slen); + if (dsasign_allowed) { + if (!TEST_true(sig_gen(pkey, NULL, tst->digest_alg, tst->msg, tst->msg_len, + &sig, &sig_len)) + || !TEST_true(get_dsa_sig_rs_bytes(sig, sig_len, &r, &s, &rlen, &slen))) + goto err; + test_output_memory("r", r, rlen); + test_output_memory("s", s, slen); + } ret = 1; err: OPENSSL_free(r); @@ -1479,6 +1484,7 @@ int setup_tests(void) #endif /* OPENSSL_NO_DH */ #ifndef OPENSSL_NO_DSA + dsasign_allowed = fips_provider_version_lt(libctx, 3, 4, 0); ADD_ALL_TESTS(dsa_keygen_test, OSSL_NELEM(dsa_keygen_data)); ADD_ALL_TESTS(dsa_paramgen_test, OSSL_NELEM(dsa_paramgen_data)); ADD_ALL_TESTS(dsa_pqver_test, OSSL_NELEM(dsa_pqver_data)); diff --git a/test/asn1_encode_test.c b/test/asn1_encode_test.c index 335f24e113..834b2cdd64 100644 --- a/test/asn1_encode_test.c +++ b/test/asn1_encode_test.c @@ -738,8 +738,7 @@ static int test_intern(const TEST_PACKAGE *package) /* Do decode_custom checks */ nelems = package->encode_expectations_size / package->encode_expectations_elem_size; - OPENSSL_assert(nelems == - sizeof(test_custom_data) / sizeof(test_custom_data[0])); + OPENSSL_assert(nelems == OSSL_NELEM(test_custom_data)); for (i = 0; i < nelems; i++) { size_t pos = i * package->encode_expectations_elem_size; EXPECTED *expected diff --git a/test/bftest.c b/test/bftest.c index 9a197b4f45..94eaedeb8c 100644 --- a/test/bftest.c +++ b/test/bftest.c @@ -163,8 +163,9 @@ static unsigned char cbc_key[16] = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0xf0, 0xe1, 0xd2, 0xc3, 0xb4, 0xa5, 0x96, 0x87 }; -static unsigned char cbc_iv[8] = - { 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 }; +static unsigned char cbc_iv[8] = { + 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 +}; static char cbc_data[40] = "7654321 Now is the time for "; static unsigned char cbc_ok[32] = { 0x6B, 0x77, 0xB4, 0xD6, 0x30, 0x06, 0xDE, 0xE6, @@ -195,8 +196,9 @@ static unsigned char key_test[KEY_TEST_NUM] = { 0x88 }; -static unsigned char key_data[8] = - { 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10 }; +static unsigned char key_data[8] = { + 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10 +}; static unsigned char key_out[KEY_TEST_NUM][8] = { {0xF9, 0xAD, 0x59, 0x7C, 0x49, 0xDB, 0x00, 0x5E}, diff --git a/test/bio_enc_test.c b/test/bio_enc_test.c index 3dc5a7cc48..fffb8da3a4 100644 --- a/test/bio_enc_test.c +++ b/test/bio_enc_test.c @@ -41,7 +41,7 @@ static int do_bio_cipher(const EVP_CIPHER* cipher, const unsigned char* key, BIO *b, *mem; static unsigned char inp[BUF_SIZE] = { 0 }; unsigned char out[BUF_SIZE], ref[BUF_SIZE]; - int i, lref, len; + int i, lref, len, tmplen; /* Fill buffer with non-zero data so that over steps can be detected */ if (!TEST_int_gt(RAND_bytes(inp, DATA_SIZE), 0)) @@ -77,13 +77,20 @@ static int do_bio_cipher(const EVP_CIPHER* cipher, const unsigned char* key, BIO_push(b, mem); memset(out, 0, sizeof(out)); out[i] = ~ref[i]; - len = BIO_read(b, out, i); + tmplen = BIO_read(b, out, i); + if (tmplen < 0) + goto err; + len = tmplen; /* check for overstep */ if (!TEST_uchar_eq(out[i], (unsigned char)~ref[i])) { TEST_info("Encrypt overstep check failed @ operation %d", i); goto err; } - len += BIO_read(b, out + len, sizeof(out) - len); + tmplen = BIO_read(b, out + len, sizeof(out) - len); + if (tmplen < 0) + goto err; + len += tmplen; + BIO_free_all(b); if (!TEST_mem_eq(out, len, ref, lref)) { @@ -206,8 +213,7 @@ err: static int do_test_bio_cipher(const EVP_CIPHER* cipher, int idx) { - switch (idx) - { + switch (idx) { case 0: return do_bio_cipher(cipher, KEY, NULL); case 1: diff --git a/test/bioprinttest.c b/test/bioprinttest.c index 04d1613c6c..95da0bd9bb 100644 --- a/test/bioprinttest.c +++ b/test/bioprinttest.c @@ -12,12 +12,11 @@ #include <stdio.h> #include <string.h> #include <openssl/bio.h> +#include "internal/nelem.h" #include "internal/numbers.h" #include "testutil.h" #include "testutil/output.h" -#define nelem(x) (int)(sizeof(x) / sizeof((x)[0])) - static int justprint = 0; static char *fpexpected[][10][5] = { @@ -192,7 +191,7 @@ static int dofptest(int test, int sub, double val, const char *width, int prec) char format[80], result[80]; int ret = 1, i; - for (i = 0; i < nelem(fspecs); i++) { + for (i = 0; i < (int)OSSL_NELEM(fspecs); i++) { const char *fspec = fspecs[i]; if (prec >= 0) @@ -287,9 +286,9 @@ int setup_tests(void) } ADD_TEST(test_big); - ADD_ALL_TESTS(test_fp, nelem(pw_params)); - ADD_ALL_TESTS(test_zu, nelem(zu_data)); - ADD_ALL_TESTS(test_j, nelem(jf_data)); + ADD_ALL_TESTS(test_fp, OSSL_NELEM(pw_params)); + ADD_ALL_TESTS(test_zu, OSSL_NELEM(zu_data)); + ADD_ALL_TESTS(test_j, OSSL_NELEM(jf_data)); return 1; } diff --git a/test/bntest.c b/test/bntest.c index 20020cac42..8c68203866 100644 --- a/test/bntest.c +++ b/test/bntest.c @@ -2847,12 +2847,11 @@ static int test_gcd_prime(void) return st; } -typedef struct mod_exp_test_st -{ - const char *base; - const char *exp; - const char *mod; - const char *res; +typedef struct mod_exp_test_st { + const char *base; + const char *exp; + const char *mod; + const char *res; } MOD_EXP_TEST; static const MOD_EXP_TEST ModExpTests[] = { diff --git a/test/build.info b/test/build.info index 80394085b9..be7a9e312a 100644 --- a/test/build.info +++ b/test/build.info @@ -40,7 +40,7 @@ IF[{- !$disabled{tests} -}] exptest pbetest localetest evp_pkey_ctx_new_from_name \ evp_pkey_provided_test evp_test evp_extra_test evp_extra_test2 \ evp_fetch_prov_test evp_libctx_test ossl_store_test \ - v3nametest v3ext punycode_test \ + v3nametest v3ext punycode_test evp_byname_test \ crltest danetest bad_dtls_test lhash_test sparse_array_test \ conf_include_test params_api_test params_conversion_test \ constant_time_test safe_math_test verify_extra_test clienthellotest \ @@ -64,7 +64,7 @@ IF[{- !$disabled{tests} -}] ca_internals_test bio_tfo_test membio_test bio_dgram_test list_test \ fips_version_test x509_test hpke_test pairwise_fail_test \ nodefltctxtest evp_xof_test x509_load_cert_file_test bio_meth_test \ - x509_acert_test x509_req_test + x509_acert_test x509_req_test strtoultest IF[{- !$disabled{'rpk'} -}] PROGRAMS{noinst}=rpktest @@ -413,6 +413,10 @@ IF[{- !$disabled{tests} -}] INCLUDE[punycode_test]=../include ../apps/include DEPEND[punycode_test]=../libcrypto.a libtestutil.a + SOURCE[evp_byname_test]=evp_byname_test.c + INCLUDE[evp_byname_test]=../include ../apps/include + DEPEND[evp_byname_test]=../libcrypto libtestutil.a + SOURCE[stack_test]=stack_test.c INCLUDE[stack_test]=../include ../apps/include DEPEND[stack_test]=../libcrypto libtestutil.a @@ -1215,6 +1219,10 @@ ENDIF INCLUDE[x509_req_test]=../include ../apps/include DEPEND[x509_req_test]=../libcrypto libtestutil.a + SOURCE[strtoultest]=strtoultest.c + INCLUDE[strtoultest]=../include ../apps/include + DEPEND[strtoultest]=../libcrypto libtestutil.a + {- use File::Spec::Functions; use File::Basename; diff --git a/test/casttest.c b/test/casttest.c index 5bc47e824a..5d8412c1d2 100644 --- a/test/casttest.c +++ b/test/casttest.c @@ -29,8 +29,9 @@ static unsigned char k[16] = { 0x23, 0x45, 0x67, 0x89, 0x34, 0x56, 0x78, 0x9A }; -static unsigned char in[8] = - { 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF }; +static unsigned char in[8] = { + 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF +}; static int k_len[3] = { 16, 10, 5 }; diff --git a/test/certs/ext-basicAttConstraints.pem b/test/certs/ext-basicAttConstraints.pem new file mode 100644 index 0000000000..9d3a25bd2e --- /dev/null +++ b/test/certs/ext-basicAttConstraints.pem @@ -0,0 +1,11 @@ +-----BEGIN CERTIFICATE----- +MIIBjDCCAXigAwIBAgIDAQIDMAsGCSqGSIb3DQEBBTAAMCIYDzIwMjEwODMxMDIx +MjQ5WhgPMjAyMTA4MzEwMjEyNDlaMAAwggEgMAsGCSqGSIb3DQEBAQOCAQ8AMIIB +CgKCAQEAtnjLm1ts1hC4fNNt3UnQD9y73bDXgioTyWYSI3ca/KNfuTydjFTEYAmq +nuGrBOUfgbmH3PRQ0AmpqljgWTb3d3K8H4UFvDWQTPSS21IMjm8oqd19nE5GxWir +Gu0oDRzhWLHe1RZ7ZrohCPg/1Ocsy47QZuK2laFB0rEmrRWBmEYbDl3/wxf5XfqI +qpOynJB02thXrTCcTM7Rz1FqCFt/ZVZB5hKY2S+CTdE9OIVKlr4WHMfuvUYeOj06 +GkwLFJHNv2tU+tovI3mYRxUuY4UupkS3MC+Otey7XKm1P+INjWWoegm6iCAt3Vus +pVz+6pU2xgl3nrAVMQHB4fReQPH0pQIDAQABoxMwETAPBgNVHSkECDAGAQH/AgED +MAsGCSqGSIb3DQEBBQMBAA== +-----END CERTIFICATE----- diff --git a/test/certs/ext-userNotice.pem b/test/certs/ext-userNotice.pem new file mode 100644 index 0000000000..7061deda10 --- /dev/null +++ b/test/certs/ext-userNotice.pem @@ -0,0 +1,13 @@ +-----BEGIN CERTIFICATE----- +MIIB8jCCAd6gAwIBAgIDAQIDMAsGCSqGSIb3DQEBBTAAMCIYDzIwMjEwODMwMDEw +MjAzWhgPMjAyMTA4MzAwMTAyMDNaMAAwggEgMAsGCSqGSIb3DQEBAQOCAQ8AMIIB +CgKCAQEAtnjLm1ts1hC4fNNt3UnQD9y73bDXgioTyWYSI3ca/KNfuTydjFTEYAmq +nuGrBOUfgbmH3PRQ0AmpqljgWTb3d3K8H4UFvDWQTPSS21IMjm8oqd19nE5GxWir +Gu0oDRzhWLHe1RZ7ZrohCPg/1Ocsy47QZuK2laFB0rEmrRWBmEYbDl3/wxf5XfqI +qpOynJB02thXrTCcTM7Rz1FqCFt/ZVZB5hKY2S+CTdE9OIVKlr4WHMfuvUYeOj06 +GkwLFJHNv2tU+tovI3mYRxUuY4UupkS3MC+Otey7XKm1P+INjWWoegm6iCAt3Vus +pVz+6pU2xgl3nrAVMQHB4fReQPH0pQIDAQABo3kwdzB1BgNVHTEEbjBsMDEwHAwR +V2lsZGJvYXIgU29mdHdhcmUwBwIBewICAcgaEUhleSB0aGVyZSBiaWcgYm9pMDcw +Jx4eAEoAbwBuAGEAdABoAGEAbgAgAFcAaQBsAGIAdQByMAUCAwDFSQwMSWNlIGlj +ZSBiYWJ5MAsGCSqGSIb3DQEBBQMBAA== +-----END CERTIFICATE----- diff --git a/test/cmsapitest.c b/test/cmsapitest.c index 5839eb7431..0684afd10e 100644 --- a/test/cmsapitest.c +++ b/test/cmsapitest.c @@ -332,6 +332,9 @@ static unsigned char *read_all(BIO *bio, long *p_len) if (ret < 0) break; + if (LONG_MAX - ret < *p_len) + break; + *p_len += ret; if (ret < step) diff --git a/test/default-and-jitter.cnf b/test/default-and-jitter.cnf new file mode 100644 index 0000000000..aec9b85445 --- /dev/null +++ b/test/default-and-jitter.cnf @@ -0,0 +1,17 @@ +openssl_conf = openssl_init + +# Comment out the next line to ignore configuration errors +config_diagnostics = 1 + +[openssl_init] +providers = provider_sect +random = random + +[provider_sect] +default = default_sect + +[default_sect] +activate = 1 + +[random] +seed=JITTER diff --git a/test/destest.c b/test/destest.c index d5f00fa691..7655aa5097 100644 --- a/test/destest.c +++ b/test/destest.c @@ -177,14 +177,18 @@ static unsigned char cipher_ecb2[NUM_TESTS - 1][8] = { {0x08, 0xD7, 0xB4, 0xFB, 0x62, 0x9D, 0x08, 0x85} }; -static unsigned char cbc_key[8] = - { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef }; -static unsigned char cbc2_key[8] = - { 0xf1, 0xe0, 0xd3, 0xc2, 0xb5, 0xa4, 0x97, 0x86 }; -static unsigned char cbc3_key[8] = - { 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 }; -static unsigned char cbc_iv[8] = - { 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 }; +static unsigned char cbc_key[8] = { + 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef +}; +static unsigned char cbc2_key[8] = { + 0xf1, 0xe0, 0xd3, 0xc2, 0xb5, 0xa4, 0x97, 0x86 +}; +static unsigned char cbc3_key[8] = { + 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 +}; +static unsigned char cbc_iv[8] = { + 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 +}; /* * Changed the following text constant to binary so it will work on ebcdic * machines :-) @@ -208,8 +212,9 @@ static unsigned char cbc_ok[32] = { # ifdef SCREW_THE_PARITY # error "SCREW_THE_PARITY is not meant to be defined." # error "Original vectors are preserved for reference only." -static unsigned char cbc2_key[8] = - { 0xf0, 0xe1, 0xd2, 0xc3, 0xb4, 0xa5, 0x96, 0x87 }; +static unsigned char cbc2_key[8] = { + 0xf0, 0xe1, 0xd2, 0xc3, 0xb4, 0xa5, 0x96, 0x87 +}; static unsigned char xcbc_ok[32] = { 0x86, 0x74, 0x81, 0x0D, 0x61, 0xA4, 0xA5, 0x48, 0xB9, 0x93, 0x03, 0xE1, 0xB8, 0xBB, 0xBD, 0xBD, @@ -239,10 +244,12 @@ static unsigned char pcbc_ok[32] = { 0xf7, 0x17, 0x46, 0x3b, 0x8a, 0xb3, 0xcc, 0x88 }; -static unsigned char cfb_key[8] = - { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef }; -static unsigned char cfb_iv[8] = - { 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef }; +static unsigned char cfb_key[8] = { + 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef +}; +static unsigned char cfb_iv[8] = { + 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef +}; static unsigned char cfb_buf1[40], cfb_buf2[40], cfb_tmp[8]; static unsigned char plain[24] = { 0x4e, 0x6f, 0x77, 0x20, 0x69, 0x73, @@ -276,10 +283,12 @@ static unsigned char cfb_cipher64[24] = { 0x1A, 0x92, 0xF7, 0x84, 0x03, 0x46, 0x71, 0x33, 0x89, 0x8E, 0xA6, 0x22 }; -static unsigned char ofb_key[8] = - { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef }; -static unsigned char ofb_iv[8] = - { 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef }; +static unsigned char ofb_key[8] = { + 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef +}; +static unsigned char ofb_iv[8] = { + 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef +}; static unsigned char ofb_buf1[24], ofb_buf2[24], ofb_tmp[8]; static unsigned char ofb_cipher[24] = { 0xf3, 0x09, 0x62, 0x49, 0xc7, 0xf4, 0x6e, 0x51, @@ -287,8 +296,9 @@ static unsigned char ofb_cipher[24] = { 0x3d, 0x6d, 0x5b, 0xe3, 0x25, 0x5a, 0xf8, 0xc3 }; static DES_LONG cbc_cksum_ret = 0xF7FE62B4L; -static unsigned char cbc_cksum_data[8] = - { 0x1D, 0x26, 0x93, 0x97, 0xf7, 0xfe, 0x62, 0xb4 }; +static unsigned char cbc_cksum_data[8] = { + 0x1D, 0x26, 0x93, 0x97, 0xf7, 0xfe, 0x62, 0xb4 +}; static char *pt(const unsigned char *p, char buf[DATA_BUF_SIZE]) { diff --git a/test/evp_byname_test.c b/test/evp_byname_test.c new file mode 100644 index 0000000000..e16e27a3a5 --- /dev/null +++ b/test/evp_byname_test.c @@ -0,0 +1,40 @@ +/* + * Copyright 2024 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the Apache License 2.0 (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include <openssl/evp.h> +#include "testutil.h" + +static int test_evp_get_digestbyname(void) +{ + const EVP_MD *md; + + if (!TEST_ptr(md = EVP_get_digestbyname("SHA2-256"))) + return 0; + return 1; +} + +static int test_evp_get_cipherbyname(void) +{ + const EVP_CIPHER *cipher; + + if (!TEST_ptr(cipher = EVP_get_cipherbyname("AES-256-WRAP"))) + return 0; + return 1; +} + +int setup_tests(void) +{ + ADD_TEST(test_evp_get_digestbyname); + ADD_TEST(test_evp_get_cipherbyname); + return 1; +} diff --git a/test/evp_extra_test.c b/test/evp_extra_test.c index a42e42d929..1b9b440d8c 100644 --- a/test/evp_extra_test.c +++ b/test/evp_extra_test.c @@ -3504,28 +3504,43 @@ static int test_evp_iv_aes(int idx) { int ret = 0; EVP_CIPHER_CTX *ctx = NULL; - |