diff options
Diffstat (limited to 'test/evp_extra_test.c')
| -rw-r--r-- | test/evp_extra_test.c | 1564 |
1 files changed, 757 insertions, 807 deletions
diff --git a/test/evp_extra_test.c b/test/evp_extra_test.c index b783ee45182d..cfe4a406eccd 100644 --- a/test/evp_extra_test.c +++ b/test/evp_extra_test.c @@ -1,5 +1,5 @@ /* - * Copyright 2015-2025 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2015-2026 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 @@ -103,11 +103,11 @@ static const unsigned char kExampleRSAKeyDER[] = { 0x6f, 0xcc, 0xfa, 0x65, 0x77, 0x94, 0xb5, 0xa1, 0x0a, 0xa9, 0xd1, 0x8a, 0x39, 0x37, 0xf4, 0x0b, 0xa0, 0xd7, 0x82, 0x27, 0x5e, 0xae, 0x17, 0x17, 0xa1, 0x1e, 0x54, 0x34, 0xbf, 0x6e, 0xc4, 0x8e, 0x99, 0x5d, 0x08, 0xf1, - 0x2d, 0x86, 0x9d, 0xa5, 0x20, 0x1b, 0xe5, 0xdf, + 0x2d, 0x86, 0x9d, 0xa5, 0x20, 0x1b, 0xe5, 0xdf }; /* -* kExampleDSAKeyDER is a DSA private key in ASN.1, DER format. Of course, you + * kExampleDSAKeyDER is a DSA private key in ASN.1, DER format. Of course, you * should never use this key anywhere but in an example. */ #ifndef OPENSSL_NO_DSA @@ -246,7 +246,7 @@ static const unsigned char kExampleBadRSAKeyDER[] = { 0xe6, 0xe0, 0x25, 0x78, 0x58, 0x14, 0x37, 0xf5, 0x1f, 0xe3, 0x22, 0xef, 0xa8, 0x0e, 0x22, 0xa0, 0x94, 0x3a, 0xf6, 0xc9, 0x13, 0xe6, 0x06, 0xbf, 0x7f, 0x99, 0xc6, 0xcc, 0xd8, 0xc6, 0xbe, 0xd9, 0x2e, 0x24, 0xc7, 0x69, - 0x8c, 0x95, 0xba, 0xf6, 0x04, 0xb3, 0x0a, 0xf4, 0xcb, 0xf0, 0xce, + 0x8c, 0x95, 0xba, 0xf6, 0x04, 0xb3, 0x0a, 0xf4, 0xcb, 0xf0, 0xce }; /* @@ -272,7 +272,7 @@ static const unsigned char kSignature[] = { 0x5a, 0xc8, 0x16, 0x3e, 0x86, 0xd5, 0xc5, 0x71, 0x2f, 0xfc, 0x23, 0x48, 0xd9, 0x0b, 0x13, 0xdd, 0x7b, 0x5a, 0x25, 0x79, 0xef, 0xa5, 0x7b, 0x04, 0xed, 0x44, 0xf6, 0x18, 0x55, 0xe4, 0x0a, 0xe9, 0x57, 0x79, 0x5d, 0xd7, - 0x55, 0xa7, 0xab, 0x45, 0x02, 0x97, 0x60, 0x42, + 0x55, 0xa7, 0xab, 0x45, 0x02, 0x97, 0x60, 0x42 }; /* @@ -332,7 +332,7 @@ static const unsigned char kExampleRSAKeyPKCS8[] = { 0x49, 0xaf, 0x6f, 0xcc, 0xfa, 0x65, 0x77, 0x94, 0xb5, 0xa1, 0x0a, 0xa9, 0xd1, 0x8a, 0x39, 0x37, 0xf4, 0x0b, 0xa0, 0xd7, 0x82, 0x27, 0x5e, 0xae, 0x17, 0x17, 0xa1, 0x1e, 0x54, 0x34, 0xbf, 0x6e, 0xc4, 0x8e, 0x99, 0x5d, - 0x08, 0xf1, 0x2d, 0x86, 0x9d, 0xa5, 0x20, 0x1b, 0xe5, 0xdf, + 0x08, 0xf1, 0x2d, 0x86, 0x9d, 0xa5, 0x20, 0x1b, 0xe5, 0xdf }; #ifndef OPENSSL_NO_EC @@ -351,7 +351,7 @@ static const unsigned char kExampleECKeyDER[] = { 0x1e, 0x9d, 0xdc, 0xba, 0x5a, 0x01, 0xe7, 0xd6, 0x97, 0xa8, 0x0a, 0x18, 0xf9, 0xc3, 0xc4, 0xa3, 0x1e, 0x56, 0xe2, 0x7c, 0x83, 0x48, 0xdb, 0x16, 0x1a, 0x1c, 0xf5, 0x1d, 0x7e, 0xf1, 0x94, 0x2d, 0x4b, 0xcf, 0x72, 0x22, - 0xc1, + 0xc1 }; /* @@ -415,19 +415,19 @@ static const unsigned char kExampleED25519PubKeyDER[] = { 0x97, 0xa3, 0x08, 0xdc, 0x65, 0x80, 0x39, 0x29 }; -# ifndef OPENSSL_NO_DEPRECATED_3_0 +#ifndef OPENSSL_NO_DEPRECATED_3_0 static const unsigned char kExampleX25519KeyDER[] = { 0x30, 0x2e, 0x02, 0x01, 0x00, 0x30, 0x05, 0x06, 0x03, 0x2b, 0x65, 0x6e, 0x04, 0x22, 0x04, 0x20, 0xa0, 0x24, 0x3a, 0x31, 0x24, 0xc3, 0x3f, 0xf6, 0x7b, 0x96, 0x0b, 0xd4, 0x8f, 0xd1, 0xee, 0x67, 0xf2, 0x9b, 0x88, 0xac, 0x50, 0xce, 0x97, 0x36, 0xdd, 0xaf, 0x25, 0xf6, 0x10, 0x34, 0x96, 0x6e }; -# endif +#endif #endif /* kExampleDHKeyDER is a DH private key in ASN.1, DER format. */ #ifndef OPENSSL_NO_DEPRECATED_3_0 -# ifndef OPENSSL_NO_DH +#ifndef OPENSSL_NO_DH static const unsigned char kExampleDHKeyDER[] = { 0x30, 0x82, 0x01, 0x21, 0x02, 0x01, 0x00, 0x30, 0x81, 0x95, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x03, 0x01, 0x30, 0x81, 0x87, @@ -455,7 +455,7 @@ static const unsigned char kExampleDHKeyDER[] = { 0x83, 0xde, 0xad, 0xb6, 0x5d, 0x19, 0xc1, 0x53, 0xec, 0xfb, 0xaf, 0x06, 0x2e, 0x87, 0x2a, 0x0b, 0x7a }; -# endif +#endif #endif static const unsigned char kCFBDefaultKey[] = { @@ -492,7 +492,7 @@ static const unsigned char cfbPlaintext[] = { }; static const unsigned char cfbPlaintext_partial[] = { 0x6B, 0xC1, 0xBE, 0xE2, 0x2E, 0x40, 0x9F, 0x96, 0xE9, 0x3D, 0x7E, 0x11, - 0x73, 0x93, 0x17, 0x2A, 0x6B, 0xC1, 0xBE, 0xE2, 0x2E, 0x40, 0x9F, 0x96, + 0x73, 0x93, 0x17, 0x2A, 0x6B, 0xC1, 0xBE, 0xE2, 0x2E, 0x40, 0x9F, 0x96 }; static const unsigned char gcmDefaultPlaintext[16] = { 0 }; @@ -573,42 +573,41 @@ typedef struct APK_DATA_st { } APK_DATA; static APK_DATA keydata[] = { - {kExampleRSAKeyDER, sizeof(kExampleRSAKeyDER), "RSA", EVP_PKEY_RSA}, - {kExampleRSAKeyPKCS8, sizeof(kExampleRSAKeyPKCS8), "RSA", EVP_PKEY_RSA}, + { kExampleRSAKeyDER, sizeof(kExampleRSAKeyDER), "RSA", EVP_PKEY_RSA }, + { kExampleRSAKeyPKCS8, sizeof(kExampleRSAKeyPKCS8), "RSA", EVP_PKEY_RSA }, #ifndef OPENSSL_NO_EC - {kExampleECKeyDER, sizeof(kExampleECKeyDER), "EC", EVP_PKEY_EC} + { kExampleECKeyDER, sizeof(kExampleECKeyDER), "EC", EVP_PKEY_EC } #endif }; static APK_DATA keycheckdata[] = { - {kExampleRSAKeyDER, sizeof(kExampleRSAKeyDER), "RSA", EVP_PKEY_RSA, 1, 1, 1, - 0}, - {kExampleBadRSAKeyDER, sizeof(kExampleBadRSAKeyDER), "RSA", EVP_PKEY_RSA, - 0, 1, 1, 0}, - {kExampleBad2RSAKeyDER, sizeof(kExampleBad2RSAKeyDER), "RSA", EVP_PKEY_RSA, - 0, 0, 1 /* Since there are no "params" in an RSA key this passes */, 0}, + { kExampleRSAKeyDER, sizeof(kExampleRSAKeyDER), "RSA", EVP_PKEY_RSA, 1, 1, 1, + 0 }, + { kExampleBadRSAKeyDER, sizeof(kExampleBadRSAKeyDER), "RSA", EVP_PKEY_RSA, + 0, 1, 1, 0 }, + { kExampleBad2RSAKeyDER, sizeof(kExampleBad2RSAKeyDER), "RSA", EVP_PKEY_RSA, + 0, 0, 1 /* Since there are no "params" in an RSA key this passes */, 0 }, #ifndef OPENSSL_NO_EC - {kExampleECKeyDER, sizeof(kExampleECKeyDER), "EC", EVP_PKEY_EC, 1, 1, 1, 0}, + { kExampleECKeyDER, sizeof(kExampleECKeyDER), "EC", EVP_PKEY_EC, 1, 1, 1, 0 }, /* group is also associated in our pub key */ - {kExampleECPubKeyDER, sizeof(kExampleECPubKeyDER), "EC", EVP_PKEY_EC, 0, 1, - 1, 1}, - {pExampleECParamDER, sizeof(pExampleECParamDER), "EC", EVP_PKEY_EC, 0, 0, 1, - 2}, - {kExampleED25519KeyDER, sizeof(kExampleED25519KeyDER), "ED25519", - EVP_PKEY_ED25519, 1, 1, 1, 0}, - {kExampleED25519PubKeyDER, sizeof(kExampleED25519PubKeyDER), "ED25519", - EVP_PKEY_ED25519, 0, 1, 1, 1}, + { kExampleECPubKeyDER, sizeof(kExampleECPubKeyDER), "EC", EVP_PKEY_EC, 0, 1, + 1, 1 }, + { pExampleECParamDER, sizeof(pExampleECParamDER), "EC", EVP_PKEY_EC, 0, 0, 1, + 2 }, + { kExampleED25519KeyDER, sizeof(kExampleED25519KeyDER), "ED25519", + EVP_PKEY_ED25519, 1, 1, 1, 0 }, + { kExampleED25519PubKeyDER, sizeof(kExampleED25519PubKeyDER), "ED25519", + EVP_PKEY_ED25519, 0, 1, 1, 1 }, #endif }; static EVP_PKEY *load_example_key(const char *keytype, - const unsigned char *data, size_t data_len) + const unsigned char *data, size_t data_len) { const unsigned char **pdata = &data; EVP_PKEY *pkey = NULL; - OSSL_DECODER_CTX *dctx = - OSSL_DECODER_CTX_new_for_pkey(&pkey, "DER", NULL, keytype, 0, - testctx, testpropq); + OSSL_DECODER_CTX *dctx = OSSL_DECODER_CTX_new_for_pkey(&pkey, "DER", NULL, keytype, 0, + testctx, testpropq); /* |pkey| will be NULL on error */ (void)OSSL_DECODER_from_data(dctx, pdata, &data_len); @@ -619,14 +618,14 @@ static EVP_PKEY *load_example_key(const char *keytype, static EVP_PKEY *load_example_rsa_key(void) { return load_example_key("RSA", kExampleRSAKeyDER, - sizeof(kExampleRSAKeyDER)); + sizeof(kExampleRSAKeyDER)); } #ifndef OPENSSL_NO_DSA static EVP_PKEY *load_example_dsa_key(void) { return load_example_key("DSA", kExampleDSAKeyDER, - sizeof(kExampleDSAKeyDER)); + sizeof(kExampleDSAKeyDER)); } #endif @@ -634,32 +633,32 @@ static EVP_PKEY *load_example_dsa_key(void) static EVP_PKEY *load_example_ec_key(void) { return load_example_key("EC", kExampleECKeyDER, - sizeof(kExampleECKeyDER)); + sizeof(kExampleECKeyDER)); } #endif #ifndef OPENSSL_NO_DEPRECATED_3_0 -# ifndef OPENSSL_NO_DH +#ifndef OPENSSL_NO_DH static EVP_PKEY *load_example_dh_key(void) { return load_example_key("DH", kExampleDHKeyDER, - sizeof(kExampleDHKeyDER)); + sizeof(kExampleDHKeyDER)); } -# endif +#endif -# ifndef OPENSSL_NO_EC +#ifndef OPENSSL_NO_EC static EVP_PKEY *load_example_ed25519_key(void) { return load_example_key("ED25519", kExampleED25519KeyDER, - sizeof(kExampleED25519KeyDER)); + sizeof(kExampleED25519KeyDER)); } static EVP_PKEY *load_example_x25519_key(void) { return load_example_key("X25519", kExampleX25519KeyDER, - sizeof(kExampleX25519KeyDER)); + sizeof(kExampleX25519KeyDER)); } -# endif +#endif #endif /* OPENSSL_NO_DEPRECATED_3_0 */ static EVP_PKEY *load_example_hmac_key(void) @@ -672,7 +671,7 @@ static EVP_PKEY *load_example_hmac_key(void) }; pkey = EVP_PKEY_new_raw_private_key_ex(testctx, "HMAC", - NULL, key, sizeof(key)); + NULL, key, sizeof(key)); if (!TEST_ptr(pkey)) return NULL; @@ -686,20 +685,20 @@ static int test_EVP_set_default_properties(void) int res = 0; if (!TEST_ptr(ctx = OSSL_LIB_CTX_new()) - || !TEST_ptr(md = EVP_MD_fetch(ctx, "sha256", NULL))) + || !TEST_ptr(md = EVP_MD_fetch(ctx, "sha256", NULL))) goto err; EVP_MD_free(md); md = NULL; if (!TEST_true(EVP_set_default_properties(ctx, "provider=fizzbang")) - || !TEST_ptr_null(md = EVP_MD_fetch(ctx, "sha256", NULL)) - || !TEST_ptr(md = EVP_MD_fetch(ctx, "sha256", "-provider"))) + || !TEST_ptr_null(md = EVP_MD_fetch(ctx, "sha256", NULL)) + || !TEST_ptr(md = EVP_MD_fetch(ctx, "sha256", "-provider"))) goto err; EVP_MD_free(md); md = NULL; if (!TEST_true(EVP_set_default_properties(ctx, NULL)) - || !TEST_ptr(md = EVP_MD_fetch(ctx, "sha256", NULL))) + || !TEST_ptr(md = EVP_MD_fetch(ctx, "sha256", NULL))) goto err; res = 1; err: @@ -720,7 +719,8 @@ static EVP_PKEY *make_key_fromdata(char *keytype, OSSL_PARAM *params) if (!TEST_int_eq(EVP_PKEY_CTX_set_params(pctx, params), 0) || !TEST_int_gt(EVP_PKEY_fromdata_init(pctx), 0) || !TEST_int_gt(EVP_PKEY_fromdata(pctx, &tmp_pkey, EVP_PKEY_KEYPAIR, - params), 0)) + params), + 0)) goto err; if (!TEST_ptr(tmp_pkey)) @@ -728,7 +728,7 @@ static EVP_PKEY *make_key_fromdata(char *keytype, OSSL_PARAM *params) pkey = tmp_pkey; tmp_pkey = NULL; - err: +err: EVP_PKEY_free(tmp_pkey); EVP_PKEY_CTX_free(pctx); return pkey; @@ -749,7 +749,7 @@ static int test_selection(EVP_PKEY *pkey, int selection) goto err; } ret = PEM_write_bio_PrivateKey_ex(bio, pkey, NULL, NULL, 0, NULL, NULL, - testctx, NULL); + testctx, NULL); if ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0) { if (!TEST_true(ret)) goto err; @@ -759,7 +759,7 @@ static int test_selection(EVP_PKEY *pkey, int selection) } testresult = 1; - err: +err: BIO_free(bio); return testresult; @@ -818,7 +818,7 @@ static int test_EVP_PKEY_ffc_priv_pub(char *keytype) || !TEST_true(OSSL_PARAM_BLD_push_BN(bld, OSSL_PKEY_PARAM_FFC_Q, q)) || !TEST_true(OSSL_PARAM_BLD_push_BN(bld, OSSL_PKEY_PARAM_FFC_G, g)) || !TEST_true(OSSL_PARAM_BLD_push_BN(bld, OSSL_PKEY_PARAM_PRIV_KEY, - priv))) + priv))) goto err; if (!TEST_ptr(params = OSSL_PARAM_BLD_to_param(bld)) || !TEST_ptr(params_and_priv = make_key_fromdata(keytype, params))) @@ -839,7 +839,7 @@ static int test_EVP_PKEY_ffc_priv_pub(char *keytype) || !TEST_true(OSSL_PARAM_BLD_push_BN(bld, OSSL_PKEY_PARAM_FFC_Q, q)) || !TEST_true(OSSL_PARAM_BLD_push_BN(bld, OSSL_PKEY_PARAM_FFC_G, g)) || !TEST_true(OSSL_PARAM_BLD_push_BN(bld, OSSL_PKEY_PARAM_PUB_KEY, - pub))) + pub))) goto err; if (!TEST_ptr(params = OSSL_PARAM_BLD_to_param(bld)) || !TEST_ptr(params_and_pub = make_key_fromdata(keytype, params))) @@ -860,9 +860,9 @@ static int test_EVP_PKEY_ffc_priv_pub(char *keytype) || !TEST_true(OSSL_PARAM_BLD_push_BN(bld, OSSL_PKEY_PARAM_FFC_Q, q)) || !TEST_true(OSSL_PARAM_BLD_push_BN(bld, OSSL_PKEY_PARAM_FFC_G, g)) || !TEST_true(OSSL_PARAM_BLD_push_BN(bld, OSSL_PKEY_PARAM_PUB_KEY, - pub)) + pub)) || !TEST_true(OSSL_PARAM_BLD_push_BN(bld, OSSL_PKEY_PARAM_PRIV_KEY, - priv))) + priv))) goto err; if (!TEST_ptr(params = OSSL_PARAM_BLD_to_param(bld)) || !TEST_ptr(params_and_keypair = make_key_fromdata(keytype, params))) @@ -872,7 +872,7 @@ static int test_EVP_PKEY_ffc_priv_pub(char *keytype) goto err; ret = 1; - err: +err: OSSL_PARAM_free(params); OSSL_PARAM_BLD_free(bld); EVP_PKEY_free(just_params); @@ -932,8 +932,8 @@ static int test_EC_priv_pub(void) /* Test !priv and !pub */ if (!TEST_ptr(bld = OSSL_PARAM_BLD_new()) || !TEST_true(OSSL_PARAM_BLD_push_utf8_string(bld, - OSSL_PKEY_PARAM_GROUP_NAME, - "P-256", 0))) + OSSL_PKEY_PARAM_GROUP_NAME, + "P-256", 0))) goto err; if (!TEST_ptr(params = OSSL_PARAM_BLD_to_param(bld)) || !TEST_ptr(just_params = make_key_fromdata("EC", params))) @@ -951,10 +951,10 @@ static int test_EC_priv_pub(void) /* Test priv and !pub */ if (!TEST_ptr(bld = OSSL_PARAM_BLD_new()) || !TEST_true(OSSL_PARAM_BLD_push_utf8_string(bld, - OSSL_PKEY_PARAM_GROUP_NAME, - "P-256", 0)) + OSSL_PKEY_PARAM_GROUP_NAME, + "P-256", 0)) || !TEST_true(OSSL_PARAM_BLD_push_BN(bld, OSSL_PKEY_PARAM_PRIV_KEY, - priv))) + priv))) goto err; if (!TEST_ptr(params = OSSL_PARAM_BLD_to_param(bld)) || !TEST_ptr(params_and_priv = make_key_fromdata("EC", params))) @@ -978,11 +978,11 @@ static int test_EC_priv_pub(void) /* Test !priv and pub */ if (!TEST_ptr(bld = OSSL_PARAM_BLD_new()) || !TEST_true(OSSL_PARAM_BLD_push_utf8_string(bld, - OSSL_PKEY_PARAM_GROUP_NAME, - "P-256", 0)) + OSSL_PKEY_PARAM_GROUP_NAME, + "P-256", 0)) || !TEST_true(OSSL_PARAM_BLD_push_octet_string(bld, - OSSL_PKEY_PARAM_PUB_KEY, - ec_pub, sizeof(ec_pub)))) + OSSL_PKEY_PARAM_PUB_KEY, + ec_pub, sizeof(ec_pub)))) goto err; if (!TEST_ptr(params = OSSL_PARAM_BLD_to_param(bld)) || !TEST_ptr(params_and_pub = make_key_fromdata("EC", params))) @@ -1000,13 +1000,13 @@ static int test_EC_priv_pub(void) /* Test priv and pub */ if (!TEST_ptr(bld = OSSL_PARAM_BLD_new()) || !TEST_true(OSSL_PARAM_BLD_push_utf8_string(bld, - OSSL_PKEY_PARAM_GROUP_NAME, - "P-256", 0)) + OSSL_PKEY_PARAM_GROUP_NAME, + "P-256", 0)) || !TEST_true(OSSL_PARAM_BLD_push_octet_string(bld, - OSSL_PKEY_PARAM_PUB_KEY, - ec_pub, sizeof(ec_pub))) + OSSL_PKEY_PARAM_PUB_KEY, + ec_pub, sizeof(ec_pub))) || !TEST_true(OSSL_PARAM_BLD_push_BN(bld, OSSL_PKEY_PARAM_PRIV_KEY, - priv))) + priv))) goto err; if (!TEST_ptr(params = OSSL_PARAM_BLD_to_param(bld)) || !TEST_ptr(params_and_keypair = make_key_fromdata("EC", params))) @@ -1018,11 +1018,11 @@ static int test_EC_priv_pub(void) /* Try key equality */ if (!TEST_int_gt(EVP_PKEY_parameters_eq(just_params, just_params), 0) || !TEST_int_gt(EVP_PKEY_parameters_eq(just_params, params_and_pub), - 0) + 0) || !TEST_int_gt(EVP_PKEY_parameters_eq(just_params, params_and_priv), - 0) + 0) || !TEST_int_gt(EVP_PKEY_parameters_eq(just_params, params_and_keypair), - 0) + 0) || !TEST_int_gt(EVP_PKEY_eq(params_and_pub, params_and_pub), 0) || !TEST_int_gt(EVP_PKEY_eq(params_and_priv, params_and_priv), 0) || !TEST_int_gt(EVP_PKEY_eq(params_and_keypair, params_and_pub), 0) @@ -1042,26 +1042,29 @@ static int test_EC_priv_pub(void) /* Positive and negative testcase for EVP_PKEY_get_octet_string_param */ if (!TEST_int_eq(EVP_PKEY_get_octet_string_param(params_and_pub, - OSSL_PKEY_PARAM_ENCODED_PUBLIC_KEY, - buffer, sizeof(buffer), &len), 1) + OSSL_PKEY_PARAM_ENCODED_PUBLIC_KEY, + buffer, sizeof(buffer), &len), + 1) || !TEST_int_eq(len, 65)) goto err; len = 0; if (!TEST_int_eq(EVP_PKEY_get_octet_string_param(params_and_pub, - OSSL_PKEY_PARAM_ENCODED_PUBLIC_KEY, - NULL, 0, &len), 1) + OSSL_PKEY_PARAM_ENCODED_PUBLIC_KEY, + NULL, 0, &len), + 1) || !TEST_int_eq(len, 65)) goto err; /* too-short buffer len*/ if (!TEST_int_eq(EVP_PKEY_get_octet_string_param(params_and_pub, - OSSL_PKEY_PARAM_ENCODED_PUBLIC_KEY, - buffer, 10, &len), 0)) + OSSL_PKEY_PARAM_ENCODED_PUBLIC_KEY, + buffer, 10, &len), + 0)) goto err; ret = 1; - err: +err: OSSL_PARAM_free(params); OSSL_PARAM_BLD_free(bld); EVP_PKEY_free(just_params); @@ -1074,7 +1077,7 @@ static int test_EC_priv_pub(void) } /* Test that using a legacy EC key with only a private key in it works */ -# ifndef OPENSSL_NO_DEPRECATED_3_0 +#ifndef OPENSSL_NO_DEPRECATED_3_0 static int test_EC_priv_only_legacy(void) { BIGNUM *priv = NULL; @@ -1113,7 +1116,7 @@ static int test_EC_priv_only_legacy(void) * provider side which is sufficient for this test. */ if (!TEST_true(EVP_DigestSignInit_ex(ctx, NULL, NULL, testctx, - testpropq, pkey, NULL))) + testpropq, pkey, NULL))) goto err; EVP_MD_CTX_free(ctx); ctx = NULL; @@ -1132,7 +1135,7 @@ static int test_EC_priv_only_legacy(void) } ret = 1; - err: +err: EVP_MD_CTX_free(ctx); EVP_PKEY_free(pkey); EC_KEY_free(eckey); @@ -1140,7 +1143,7 @@ static int test_EC_priv_only_legacy(void) return ret; } -# endif /* OPENSSL_NO_DEPRECATED_3_0 */ +#endif /* OPENSSL_NO_DEPRECATED_3_0 */ #endif /* OPENSSL_NO_EC */ static int test_EVP_PKEY_sign(int tst) @@ -1155,7 +1158,7 @@ static int test_EVP_PKEY_sign(int tst) 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13 }; - if (tst == 0 ) { + if (tst == 0) { if (!TEST_ptr(pkey = load_example_rsa_key())) goto out; } else if (tst == 1) { @@ -1178,25 +1181,27 @@ static int test_EVP_PKEY_sign(int tst) ctx = EVP_PKEY_CTX_new_from_pkey(testctx, pkey, NULL); if (!TEST_ptr(ctx) - || !TEST_int_gt(EVP_PKEY_sign_init(ctx), 0) - || !TEST_int_gt(EVP_PKEY_sign(ctx, NULL, &sig_len, tbs, - sizeof(tbs)), 0)) + || !TEST_int_gt(EVP_PKEY_sign_init(ctx), 0) + || !TEST_int_gt(EVP_PKEY_sign(ctx, NULL, &sig_len, tbs, + sizeof(tbs)), + 0)) goto out; sig = OPENSSL_malloc(sig_len); if (!TEST_ptr(sig) - /* Test sending a signature buffer that is too short is rejected */ - || !TEST_int_le(EVP_PKEY_sign(ctx, sig, &shortsig_len, tbs, - sizeof(tbs)), 0) - || !TEST_int_gt(EVP_PKEY_sign(ctx, sig, &sig_len, tbs, sizeof(tbs)), - 0) - /* Test the signature round-trips */ - || !TEST_int_gt(EVP_PKEY_verify_init(ctx), 0) - || !TEST_int_gt(EVP_PKEY_verify(ctx, sig, sig_len, tbs, sizeof(tbs)), - 0)) + /* Test sending a signature buffer that is too short is rejected */ + || !TEST_int_le(EVP_PKEY_sign(ctx, sig, &shortsig_len, tbs, + sizeof(tbs)), + 0) + || !TEST_int_gt(EVP_PKEY_sign(ctx, sig, &sig_len, tbs, sizeof(tbs)), + 0) + /* Test the signature round-trips */ + || !TEST_int_gt(EVP_PKEY_verify_init(ctx), 0) + || !TEST_int_gt(EVP_PKEY_verify(ctx, sig, sig_len, tbs, sizeof(tbs)), + 0)) goto out; ret = 1; - out: +out: EVP_PKEY_CTX_free(ctx); OPENSSL_free(sig); EVP_PKEY_free(pkey); @@ -1236,7 +1241,7 @@ static int test_EVP_PKEY_sign_with_app_method(int tst) } else { #ifndef OPENSSL_NO_DSA if (!TEST_ptr(pkey = load_example_dsa_key())) - goto out; + goto out; if (!TEST_ptr(dsa_meth = DSA_meth_dup(DSA_get_default_method()))) goto out; @@ -1253,25 +1258,27 @@ static int test_EVP_PKEY_sign_with_app_method(int tst) ctx = EVP_PKEY_CTX_new_from_pkey(testctx, pkey, NULL); if (!TEST_ptr(ctx) - || !TEST_int_gt(EVP_PKEY_sign_init(ctx), 0) - || !TEST_int_gt(EVP_PKEY_sign(ctx, NULL, &sig_len, tbs, - sizeof(tbs)), 0)) + || !TEST_int_gt(EVP_PKEY_sign_init(ctx), 0) + || !TEST_int_gt(EVP_PKEY_sign(ctx, NULL, &sig_len, tbs, + sizeof(tbs)), + 0)) goto out; sig = OPENSSL_malloc(sig_len); if (!TEST_ptr(sig) - /* Test sending a signature buffer that is too short is rejected */ - || !TEST_int_le(EVP_PKEY_sign(ctx, sig, &shortsig_len, tbs, - sizeof(tbs)), 0) - || !TEST_int_gt(EVP_PKEY_sign(ctx, sig, &sig_len, tbs, sizeof(tbs)), - 0) - /* Test the signature round-trips */ - || !TEST_int_gt(EVP_PKEY_verify_init(ctx), 0) - || !TEST_int_gt(EVP_PKEY_verify(ctx, sig, sig_len, tbs, sizeof(tbs)), - 0)) + /* Test sending a signature buffer that is too short is rejected */ + || !TEST_int_le(EVP_PKEY_sign(ctx, sig, &shortsig_len, tbs, + sizeof(tbs)), + 0) + || !TEST_int_gt(EVP_PKEY_sign(ctx, sig, &sig_len, tbs, sizeof(tbs)), + 0) + /* Test the signature round-trips */ + || !TEST_int_gt(EVP_PKEY_verify_init(ctx), 0) + || !TEST_int_gt(EVP_PKEY_verify(ctx, sig, sig_len, tbs, sizeof(tbs)), + 0)) goto out; ret = 1; - out: +out: EVP_PKEY_CTX_free(ctx); OPENSSL_free(sig); EVP_PKEY_free(pkey); @@ -1307,26 +1314,26 @@ static int test_EVP_Enveloped(int n) if (n == 0) type = (EVP_CIPHER *)EVP_aes_256_cbc(); else if (!TEST_ptr(type = EVP_CIPHER_fetch(testctx, "AES-256-CBC", - testpropq))) + testpropq))) goto err; if (!TEST_ptr(keypair = load_example_rsa_key()) - || !TEST_ptr(kek = OPENSSL_zalloc(EVP_PKEY_get_size(keypair))) - || !TEST_ptr(ctx = EVP_CIPHER_CTX_new()) - || !TEST_true(EVP_SealInit(ctx, type, &kek, &kek_len, iv, - &keypair, 1)) - || !TEST_true(EVP_SealUpdate(ctx, ciphertext, &ciphertext_len, - msg, sizeof(msg))) - || !TEST_true(EVP_SealFinal(ctx, ciphertext + ciphertext_len, - &len))) + || !TEST_ptr(kek = OPENSSL_zalloc(EVP_PKEY_get_size(keypair))) + || !TEST_ptr(ctx = EVP_CIPHER_CTX_new()) + || !TEST_true(EVP_SealInit(ctx, type, &kek, &kek_len, iv, + &keypair, 1)) + || !TEST_true(EVP_SealUpdate(ctx, ciphertext, &ciphertext_len, + msg, sizeof(msg))) + || !TEST_true(EVP_SealFinal(ctx, ciphertext + ciphertext_len, + &len))) goto err; ciphertext_len += len; if (!TEST_true(EVP_OpenInit(ctx, type, kek, kek_len, iv, keypair)) - || !TEST_true(EVP_OpenUpdate(ctx, plaintext, &plaintext_len, - ciphertext, ciphertext_len)) - || !TEST_true(EVP_OpenFinal(ctx, plaintext + plaintext_len, &len))) + || !TEST_true(EVP_OpenUpdate(ctx, plaintext, &plaintext_len, + ciphertext, ciphertext_len)) + || !TEST_true(EVP_OpenFinal(ctx, plaintext + plaintext_len, &len))) goto err; plaintext_len += len; @@ -1393,24 +1400,24 @@ static int test_EVP_DigestSignInit(int tst) goto out; } else { if (!TEST_ptr(a_md_ctx = md_ctx = EVP_MD_CTX_new()) - || !TEST_ptr(a_md_ctx_verify = md_ctx_verify = EVP_MD_CTX_new())) + || !TEST_ptr(a_md_ctx_verify = md_ctx_verify = EVP_MD_CTX_new())) goto out; } if (tst % 3 == 0) { if (!TEST_ptr(pkey = load_example_rsa_key())) - goto out; + goto out; } else if (tst % 3 == 1) { #ifndef OPENSSL_NO_DSA if (!TEST_ptr(pkey = load_example_dsa_key())) - goto out; + goto out; #else ret = 1; goto out; #endif } else { if (!TEST_ptr(pkey = load_example_hmac_key())) - goto out; + goto out; } if (tst >= 3 && tst <= 5) @@ -1435,13 +1442,13 @@ static int test_EVP_DigestSignInit(int tst) if (tst >= 9) { /* Determine the size of the signature. */ if (!TEST_true(EVP_DigestSign(md_ctx, NULL, &sig_len, kMsg, - sizeof(kMsg))) - || !TEST_ptr(sig = OPENSSL_malloc(sig_len))) + sizeof(kMsg))) + || !TEST_ptr(sig = OPENSSL_malloc(sig_len))) goto out; if (tst <= 11) { /* Test that supply a short sig buffer fails */ if (!TEST_false(EVP_DigestSign(md_ctx, sig, &shortsig_len, kMsg, - sizeof(kMsg)))) + sizeof(kMsg)))) goto out; /* * We end here because once EVP_DigestSign() has failed you should @@ -1451,18 +1458,18 @@ static int test_EVP_DigestSignInit(int tst) goto out; } if (!TEST_true(EVP_DigestSign(md_ctx, sig, &sig_len, kMsg, - sizeof(kMsg)))) + sizeof(kMsg)))) goto out; } else { /* Determine the size of the signature. */ if (!TEST_true(EVP_DigestSignFinal(md_ctx, NULL, &sig_len)) - || !TEST_ptr(sig = OPENSSL_malloc(sig_len)) - /* - * Trying to create a signature with a deliberately short - * buffer should fail. - */ - || !TEST_false(EVP_DigestSignFinal(md_ctx, sig, &shortsig_len)) - || !TEST_true(EVP_DigestSignFinal(md_ctx, sig, &sig_len))) + || !TEST_ptr(sig = OPENSSL_malloc(sig_len)) + /* + * Trying to create a signature with a deliberately short + * buffer should fail. + */ + || !TEST_false(EVP_DigestSignFinal(md_ctx, sig, &shortsig_len)) + || !TEST_true(EVP_DigestSignFinal(md_ctx, sig, &sig_len))) goto out; } @@ -1478,7 +1485,7 @@ static int test_EVP_DigestSignInit(int tst) } if (!TEST_true(EVP_DigestVerifyInit(md_ctx_verify, NULL, md, - NULL, pkey))) + NULL, pkey))) goto out; if (tst >= 6 && tst <= 8) { @@ -1486,7 +1493,7 @@ static int test_EVP_DigestSignInit(int tst) goto out; } else { if (!TEST_true(EVP_DigestVerifyUpdate(md_ctx_verify, kMsg, - sizeof(kMsg)))) + sizeof(kMsg)))) goto out; } if (!TEST_int_gt(EVP_DigestVerifyFinal(md_ctx_verify, sig, sig_len), 0)) @@ -1511,7 +1518,7 @@ static int test_EVP_DigestSignInit(int tst) ret = 1; - out: +out: BIO_free(membio); BIO_free(mdbio); EVP_MD_CTX_free(a_md_ctx); @@ -1534,24 +1541,26 @@ static int test_EVP_DigestVerifyInit(void) return TEST_skip("Test does not support a non-default library context"); if (!TEST_ptr(md_ctx = EVP_MD_CTX_new()) - || !TEST_ptr(pkey = load_example_rsa_key())) + || !TEST_ptr(pkey = load_example_rsa_key())) goto out; if (!TEST_true(EVP_DigestVerifyInit(md_ctx, NULL, EVP_sha256(), NULL, pkey)) - || !TEST_true(EVP_DigestVerifyUpdate(md_ctx, kMsg, sizeof(kMsg))) - || !TEST_int_gt(EVP_DigestVerifyFinal(md_ctx, kSignature, - sizeof(kSignature)), 0)) + || !TEST_true(EVP_DigestVerifyUpdate(md_ctx, kMsg, sizeof(kMsg))) + || !TEST_int_gt(EVP_DigestVerifyFinal(md_ctx, kSignature, + sizeof(kSignature)), + 0)) goto out; /* test with reinitialization */ if (!TEST_true(EVP_DigestVerifyInit(md_ctx, NULL, NULL, NULL, NULL)) - || !TEST_true(EVP_DigestVerifyUpdate(md_ctx, kMsg, sizeof(kMsg))) - || !TEST_int_gt(EVP_DigestVerifyFinal(md_ctx, kSignature, - sizeof(kSignature)), 0)) + || !TEST_true(EVP_DigestVerifyUpdate(md_ctx, kMsg, sizeof(kMsg))) + || !TEST_int_gt(EVP_DigestVerifyFinal(md_ctx, kSignature, + sizeof(kSignature)), + 0)) goto out; ret = 1; - out: +out: EVP_MD_CTX_free(md_ctx); EVP_PKEY_free(pkey); return ret; @@ -1578,7 +1587,7 @@ static int test_siphash_digestsign(void) memset(buf, 0, 8); memset(key, 1, 16); if (!TEST_ptr(pkey = EVP_PKEY_new_raw_private_key(EVP_PKEY_SIPHASH, NULL, - key, 16))) + key, 16))) goto out; if (!TEST_ptr(mdctx = EVP_MD_CTX_create())) @@ -1587,8 +1596,9 @@ static int test_siphash_digestsign(void) if (!TEST_true(EVP_DigestSignInit(mdctx, &ctx, NULL, NULL, pkey))) goto out; if (!TEST_int_eq(EVP_PKEY_CTX_ctrl(ctx, -1, EVP_PKEY_OP_SIGNCTX, - EVP_PKEY_CTRL_SET_DIGEST_SIZE, - 8, NULL), 1)) + EVP_PKEY_CTRL_SET_DIGEST_SIZE, + 8, NULL), + 1)) goto out; /* reinitialize */ if (!TEST_true(EVP_DigestSignInit(mdctx, NULL, NULL, NULL, NULL))) @@ -1601,7 +1611,7 @@ static int test_siphash_digestsign(void) goto out; ret = 1; - out: +out: EVP_PKEY_free(pkey); EVP_MD_CTX_free(mdctx); return ret; @@ -1623,38 +1633,38 @@ static int test_EVP_Digest(void) goto out; if (!TEST_ptr(sha256 = EVP_MD_fetch(testctx, "sha256", testpropq)) - || !TEST_ptr(shake256 = EVP_MD_fetch(testctx, "shake256", testpropq))) + || !TEST_ptr(shake256 = EVP_MD_fetch(testctx, "shake256", testpropq))) goto out; if (!TEST_true(EVP_DigestInit_ex(md_ctx, sha256, NULL)) - || !TEST_true(EVP_DigestUpdate(md_ctx, kMsg, sizeof(kMsg))) - || !TEST_true(EVP_DigestFinal(md_ctx, md, NULL)) - /* EVP_DigestFinal resets the EVP_MD_CTX. */ - || !TEST_ptr_eq(EVP_MD_CTX_get0_md(md_ctx), NULL)) + || !TEST_true(EVP_DigestUpdate(md_ctx, kMsg, sizeof(kMsg))) + || !TEST_true(EVP_DigestFinal(md_ctx, md, NULL)) + /* EVP_DigestFinal resets the EVP_MD_CTX. */ + || !TEST_ptr_eq(EVP_MD_CTX_get0_md(md_ctx), NULL)) goto out; if (!TEST_true(EVP_DigestInit_ex(md_ctx, sha256, NULL)) - || !TEST_true(EVP_DigestUpdate(md_ctx, kMsg, sizeof(kMsg))) - || !TEST_true(EVP_DigestFinal_ex(md_ctx, md, NULL)) - /* EVP_DigestFinal_ex does not reset the EVP_MD_CTX. */ - || !TEST_ptr(EVP_MD_CTX_get0_md(md_ctx)) - /* - * EVP_DigestInit_ex with NULL type should work on - * pre-initialized context. - */ - || !TEST_true(EVP_DigestInit_ex(md_ctx, NULL, NULL))) + || !TEST_true(EVP_DigestUpdate(md_ctx, kMsg, sizeof(kMsg))) + || !TEST_true(EVP_DigestFinal_ex(md_ctx, md, NULL)) + /* EVP_DigestFinal_ex does not reset the EVP_MD_CTX. */ + || !TEST_ptr(EVP_MD_CTX_get0_md(md_ctx)) + /* + * EVP_DigestInit_ex with NULL type should work on + * pre-initialized context. + */ + || !TEST_true(EVP_DigestInit_ex(md_ctx, NULL, NULL))) goto out; if (!TEST_true(EVP_DigestInit_ex(md_ctx, shake256, NULL)) - || !TEST_true(EVP_DigestUpdate(md_ctx, kMsg, sizeof(kMsg))) - || !TEST_true(EVP_DigestFinalXOF(md_ctx, md, sizeof(md))) - /* EVP_DigestFinalXOF does not reset the EVP_MD_CTX. */ - || !TEST_ptr(EVP_MD_CTX_get0_md(md_ctx)) - || !TEST_true(EVP_DigestInit_ex(md_ctx, NULL, NULL))) + || !TEST_true(EVP_DigestUpdate(md_ctx, kMsg, sizeof(kMsg))) + || !TEST_true(EVP_DigestFinalXOF(md_ctx, md, sizeof(md))) + /* EVP_DigestFinalXOF does not reset the EVP_MD_CTX. */ + || !TEST_ptr(EVP_MD_CTX_get0_md(md_ctx)) + || !TEST_true(EVP_DigestInit_ex(md_ctx, NULL, NULL))) goto out; ret = 1; - out: +out: EVP_MD_CTX_free(md_ctx); EVP_MD_free(sha256); EVP_MD_free(shake256); @@ -1685,7 +1695,7 @@ static int test_EVP_md_null(void) goto out; ret = 1; - out: +out: EVP_MD_CTX_free(md_ctx); return ret; } @@ -1702,13 +1712,13 @@ static int test_d2i_AutoPrivateKey(int i) p = input; if (!TEST_ptr(pkey = d2i_AutoPrivateKey(NULL, &p, input_len)) - || !TEST_ptr_eq(p, input + input_len) - || !TEST_int_eq(EVP_PKEY_get_id(pkey), expected_id)) + || !TEST_ptr_eq(p, input + input_len) + || !TEST_int_eq(EVP_PKEY_get_id(pkey), expected_id)) goto done; ret = 1; - done: +done: EVP_PKEY_free(pkey); return ret; } @@ -1762,10 +1772,10 @@ static int test_invalide_ec_char2_pub_range_decode(int id) EVP_PKEY *pkey; pkey = load_example_key("EC", ec_der_pub_keys[id].der, - ec_der_pub_keys[id].len); + ec_der_pub_keys[id].len); ret = (ec_der_pub_keys[id].valid && TEST_ptr(pkey)) - || TEST_ptr_null(pkey); + || TEST_ptr_null(pkey); EVP_PKEY_free(pkey); return ret; } @@ -1779,11 +1789,11 @@ static int test_EVP_PKCS82PKEY(void) EVP_PKEY *pkey = NULL; if (!TEST_ptr(p8inf = d2i_PKCS8_PRIV_KEY_INFO(NULL, &derp, - sizeof(kExampleBadECKeyDER)))) + sizeof(kExampleBadECKeyDER)))) goto done; if (!TEST_ptr_eq(derp, - kExampleBadECKeyDER + sizeof(kExampleBadECKeyDER))) + kExampleBadECKeyDER + sizeof(kExampleBadECKeyDER))) goto done; if (!TEST_ptr_null(pkey = EVP_PKCS82PKEY(p8inf))) @@ -1791,7 +1801,7 @@ static int test_EVP_PKCS82PKEY(void) ret = 1; - done: +done: PKCS8_PRIV_KEY_INFO_free(p8inf); EVP_PKEY_free(pkey); @@ -1815,8 +1825,8 @@ static int test_EVP_PKCS82PKEY_wrong_tag(void) if (!TEST_ptr(membio = BIO_new(BIO_s_mem())) || !TEST_ptr(pkey = load_example_rsa_key()) || !TEST_int_gt(i2d_PKCS8PrivateKey_bio(membio, pkey, NULL, - NULL, 0, NULL, NULL), - 0) + NULL, 0, NULL, NULL), + 0) || !TEST_int_gt(BIO_get_mem_data(membio, &membuf), 0) || !TEST_ptr(p8inf = d2i_PKCS8_PRIV_KEY_INFO_bio(membio, NULL)) || !TEST_ptr(pkey2 = EVP_PKCS82PKEY(p8inf)) @@ -1825,7 +1835,7 @@ static int test_EVP_PKCS82PKEY_wrong_tag(void) } ok = 1; - done: +done: EVP_PKEY_free(pkey); EVP_PKEY_free(pkey2); PKCS8_PRIV_KEY_INFO_free(p8inf); @@ -1845,23 +1855,23 @@ static int test_privatekey_to_pkcs8(void) if (!TEST_ptr(membio = BIO_new(BIO_s_mem())) || !TEST_ptr(pkey = load_example_rsa_key()) || !TEST_int_gt(i2d_PKCS8PrivateKey_bio(membio, pkey, NULL, - NULL, 0, NULL, NULL), - 0) + NULL, 0, NULL, NULL), + 0) || !TEST_int_gt(membuf_len = BIO_get_mem_data(membio, &membuf), 0) || !TEST_ptr(membuf) || !TEST_mem_eq(membuf, (size_t)membuf_len, - kExampleRSAKeyPKCS8, sizeof(kExampleRSAKeyPKCS8)) + kExampleRSAKeyPKCS8, sizeof(kExampleRSAKeyPKCS8)) /* * We try to write PEM as well, just to see that it doesn't err, but * assume that the result is correct. */ || !TEST_int_gt(PEM_write_bio_PKCS8PrivateKey(membio, pkey, NULL, - NULL, 0, NULL, NULL), - 0)) + NULL, 0, NULL, NULL), + 0)) goto done; ok = 1; - done: +done: EVP_PKEY_free(pkey); BIO_free_all(membio); return ok; @@ -1873,7 +1883,7 @@ static const struct { const char *encoding_name; } ec_encodings[] = { { OPENSSL_EC_EXPLICIT_CURVE, OSSL_PKEY_EC_ENCODING_EXPLICIT }, - { OPENSSL_EC_NAMED_CURVE, OSSL_PKEY_EC_ENCODING_GROUP } + { OPENSSL_EC_NAMED_CURVE, OSSL_PKEY_EC_ENCODING_GROUP } }; static int ec_export_get_encoding_cb(const OSSL_PARAM params[], void *arg) @@ -1886,7 +1896,7 @@ static int ec_export_get_encoding_cb(const OSSL_PARAM params[], void *arg) *enc = -1; if (!TEST_ptr(p = OSSL_PARAM_locate_const(params, - OSSL_PKEY_PARAM_EC_ENCODING)) + OSSL_PKEY_PARAM_EC_ENCODING)) || !TEST_true(OSSL_PARAM_get_utf8_string_ptr(p, &enc_name))) return 0; @@ -1927,12 +1937,12 @@ static int test_EC_keygen_with_enc(int idx) /* Check that the encoding got all the way into the key */ if (!TEST_true(evp_keymgmt_util_export(key, OSSL_KEYMGMT_SELECT_ALL, - ec_export_get_encoding_cb, &enc)) + ec_export_get_encoding_cb, &enc)) || !TEST_int_eq(enc, ec_encodings[idx].encoding)) goto done; ret = 1; - done: +done: EVP_PKEY_free(key); EVP_PKEY_free(params); EVP_PKEY_CTX_free(kctx); @@ -1945,11 +1955,10 @@ static int test_EC_keygen_with_enc(int idx) static int test_EVP_SM2_verify(void) { - const char *pubkey = - "-----BEGIN PUBLIC KEY-----\n" - "MFkwEwYHKoZIzj0CAQYIKoEcz1UBgi0DQgAEp1KLWq1ZE2jmoAnnBJE1LBGxVr18\n" - "YvvqECWCpXfAQ9qUJ+UmthnUPf0iM3SaXKHe6PlLIDyNlWMWb9RUh/yU3g==\n" - "-----END PUBLIC KEY-----\n"; + const char *pubkey = "-----BEGIN PUBLIC KEY-----\n" + "MFkwEwYHKoZIzj0CAQYIKoEcz1UBgi0DQgAEp1KLWq1ZE2jmoAnnBJE1LBGxVr18\n" + "YvvqECWCpXfAQ9qUJ+UmthnUPf0iM3SaXKHe6PlLIDyNlWMWb9RUh/yU3g==\n" + "-----END PUBLIC KEY-----\n"; const char *msg = "message digest"; const char *id = "ALICE123@YAHOO.COM"; @@ -2006,7 +2015,7 @@ static int test_EVP_SM2_verify(void) goto done; rc = 1; - done: +done: BIO_free(bio); EVP_PKEY_free(pkey); EVP_PKEY_CTX_free(pctx); @@ -2036,15 +2045,15 @@ static int test_EVP_SM2(void) uint8_t plaintext[8]; size_t ptext_len = sizeof(plaintext); - uint8_t sm2_id[] = {1, 2, 3, 4, 'l', 'e', 't', 't', 'e', 'r'}; + uint8_t sm2_id[] = { 1, 2, 3, 4, 'l', 'e', 't', 't', 'e', 'r' }; - OSSL_PARAM sparams[2] = {OSSL_PARAM_END, OSSL_PARAM_END}; - OSSL_PARAM gparams[2] = {OSSL_PARAM_END, OSSL_PARAM_END}; + OSSL_PARAM sparams[2] = { OSSL_PARAM_END, OSSL_PARAM_END }; + OSSL_PARAM gparams[2] = { OSSL_PARAM_END, OSSL_PARAM_END }; int i; char mdname[OSSL_MAX_NAME_SIZE]; if (!TEST_ptr(pctx = EVP_PKEY_CTX_new_from_name(testctx, - "SM2", testpropq))) + "SM2", testpropq))) goto done; if (!TEST_true(EVP_PKEY_paramgen_init(pctx) == 1)) @@ -2057,7 +2066,7 @@ static int test_EVP_SM2(void) goto done; if (!TEST_ptr(kctx = EVP_PKEY_CTX_new_from_pkey(testctx, - pkeyparams, testpropq))) + pkeyparams, testpropq))) goto done; if (!TEST_int_gt(EVP_PKEY_keygen_init(kctx), 0)) @@ -2103,7 +2112,7 @@ static int test_EVP_SM2(void) /* Ensure that the signature round-trips. */ if (!TEST_true(EVP_DigestVerifyInit(md_ctx_verify, NULL, check_md, NULL, - pkey))) + pkey))) goto done; if (!TEST_int_gt(EVP_PKEY_CTX_set1_id(sctx, sm2_id, sizeof(sm2_id)), 0)) @@ -2121,7 +2130,7 @@ static int test_EVP_SM2(void) */ if (!TEST_true(EVP_DigestVerifyInit(md_ctx_verify, NULL, check_md, NULL, - pkey))) + pkey))) goto done; if (!TEST_int_gt(EVP_PKEY_CTX_set1_id(sctx, NULL, 0), 0)) @@ -2136,7 +2145,7 @@ static int test_EVP_SM2(void) /* now check encryption/decryption */ gparams[0] = OSSL_PARAM_construct_utf8_string(OSSL_ASYM_CIPHER_PARAM_DIGEST, - mdname, sizeof(mdname)); + mdname, sizeof(mdname)); for (i = 0; i < 2; i++) { const char *mdnames[] = { #ifndef OPENSSL_NO_SM3 @@ -2144,18 +2153,18 @@ static int test_EVP_SM2(void) #else NULL, #endif - "SHA2-256" }; + "SHA2-256" + }; EVP_PKEY_CTX_free(cctx); if (mdnames[i] == NULL) continue; - sparams[0] = - OSSL_PARAM_construct_utf8_string(OSSL_ASYM_CIPHER_PARAM_DIGEST, - (char *)mdnames[i], 0); + sparams[0] = OSSL_PARAM_construct_utf8_string(OSSL_ASYM_CIPHER_PARAM_DIGEST, + (char *)mdnames[i], 0); if (!TEST_ptr(cctx = EVP_PKEY_CTX_new_from_pkey(testctx, - pkey, testpropq))) + pkey, testpropq))) goto done; if (!TEST_true(EVP_PKEY_encrypt_init(cctx))) @@ -2165,7 +2174,7 @@ static int test_EVP_SM2(void) goto done; if (!TEST_true(EVP_PKEY_encrypt(cctx, ciphertext, &ctext_len, kMsg, - sizeof(kMsg)))) + sizeof(kMsg)))) goto done; if (!TEST_int_gt(EVP_PKEY_decrypt_init(cctx), 0)) @@ -2175,7 +2184,8 @@ static int test_EVP_SM2(void) goto done; if (!TEST_int_gt(EVP_PKEY_decrypt(cctx, plaintext, &ptext_len, ciphertext, - ctext_len), 0)) + ctext_len), + 0)) goto done; if (!TEST_true(EVP_PKEY_CTX_get_params(cctx, gparams))) @@ -2223,36 +2233,28 @@ static struct keys_st { char *priv; char *pub; } keys[] = { - { - EVP_PKEY_HMAC, "0123456789", NULL - }, - { - EVP_PKEY_HMAC, "", NULL + { EVP_PKEY_HMAC, "0123456789", NULL }, + { EVP_PKEY_HMAC, "", NULL #ifndef OPENSSL_NO_POLY1305 - }, { - EVP_PKEY_POLY1305, "01234567890123456789012345678901", NULL + }, + { EVP_PKEY_POLY1305, "01234567890123456789012345678901", NULL #endif #ifndef OPENSSL_NO_SIPHASH - }, { - EVP_PKEY_SIPHASH, "0123456789012345", NULL + }, + { EVP_PKEY_SIPHASH, "0123456789012345", NULL #endif }, #ifndef OPENSSL_NO_EC - { - EVP_PKEY_X25519, "01234567890123456789012345678901", - "abcdefghijklmnopqrstuvwxyzabcdef" - }, { - EVP_PKEY_ED25519, "01234567890123456789012345678901", - "abcdefghijklmnopqrstuvwxyzabcdef" - }, { - EVP_PKEY_X448, + { EVP_PKEY_X25519, "01234567890123456789012345678901", + "abcdefghijklmnopqrstuvwxyzabcdef" }, + { EVP_PKEY_ED25519, "01234567890123456789012345678901", + "abcdefghijklmnopqrstuvwxyzabcdef" }, + { EVP_PKEY_X448, "01234567890123456789012345678901234567890123456789012345", - "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcd" - }, { - EVP_PKEY_ED448, + "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcd" }, + { EVP_PKEY_ED448, "012345678901234567890123456789012345678901234567890123456", - "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcde" - } + "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcde" } #endif }; @@ -2276,16 +2278,16 @@ static int test_set_get_raw_keys_int(int tst, int pub, int uselibctx) in = (unsigned char *)keys[tst].pub; if (uselibctx) { pkey = EVP_PKEY_new_raw_public_key_ex( - testctx, - OBJ_nid2sn(keys[tst].type), - NULL, - in, - inlen); + testctx, + OBJ_nid2sn(keys[tst].type), + NULL, + in, + inlen); } else { pkey = EVP_PKEY_new_raw_public_key(keys[tst].type, - NULL, - in, - inlen); + NULL, + in, + inlen); } #else return 1; @@ -2295,42 +2297,40 @@ static int test_set_get_raw_keys_int(int tst, int pub, int uselibctx) in = (unsigned char *)keys[tst].priv; if (uselibctx) { pkey = EVP_PKEY_new_raw_private_key_ex( - testctx, OBJ_nid2sn(keys[tst].type), - NULL, - in, - inlen); + testctx, OBJ_nid2sn(keys[tst].type), + NULL, + in, + inlen); } else { pkey = EVP_PKEY_new_raw_private_key(keys[tst].type, - NULL, - in, - inlen); + NULL, + in, + inlen); } } if (!TEST_ptr(pkey) - || !TEST_int_eq(EVP_PKEY_eq(pkey, pkey), 1) - || (!pub && !TEST_true(EVP_PKEY_get_raw_private_key(pkey, NULL, &len))) - || (pub && !TEST_true(EVP_PKEY_get_raw_public_key(pkey, NULL, &len))) - || !TEST_true(len == inlen)) + || !TEST_int_eq(EVP_PKEY_eq(pkey, pkey), 1) + || (!pub && !TEST_true(EVP_PKEY_get_raw_private_key(pkey, NULL, &len))) + || (pub && !TEST_true(EVP_PKEY_get_raw_public_key(pkey, NULL, &len))) + || !TEST_true(len == inlen)) goto done; if (tst != 1) { /* * Test that supplying a buffer that is too small fails. Doesn't apply * to HMAC with a zero length key */ - if ((!pub && !TEST_false(EVP_PKEY_get_raw_private_key(pkey, buf, - &shortlen))) - || (pub && !TEST_false(EVP_PKEY_get_raw_public_key(pkey, buf, - &shortlen)))) + if ((!pub && !TEST_false(EVP_PKEY_get_raw_private_key(pkey, buf, &shortlen))) + || (pub && !TEST_false(EVP_PKEY_get_raw_public_key(pkey, buf, &shortlen)))) goto done; } if ((!pub && !TEST_true(EVP_PKEY_get_raw_private_key(pkey, buf, &len))) - || (pub && !TEST_true(EVP_PKEY_get_raw_public_key(pkey, buf, &len))) - || !TEST_mem_eq(in, inlen, buf, len)) + || (pub && !TEST_true(EVP_PKEY_get_raw_public_key(pkey, buf, &len))) + || !TEST_mem_eq(in, inlen, buf, len)) goto done; ret = 1; - done: +done: EVP_PKEY_free(pkey); return ret; } @@ -2338,9 +2338,9 @@ static int test_set_get_raw_keys_int(int tst, int pub, int uselibctx) static int test_set_get_raw_keys(int tst) { return (nullprov != NULL || test_set_get_raw_keys_int(tst, 0, 0)) - && test_set_get_raw_keys_int(tst, 0, 1) - && (nullprov != NULL || test_set_get_raw_keys_int(tst, 1, 0)) - && test_set_get_raw_keys_int(tst, 1, 1); + && test_set_get_raw_keys_int(tst, 0, 1) + && (nullprov != NULL || test_set_get_raw_keys_int(tst, 1, 0)) + && test_set_get_raw_keys_int(tst, 1, 1); } #ifndef OPENSSL_NO_DEPRECATED_3_0 @@ -2415,7 +2415,7 @@ static int test_EVP_PKEY_check(int i) ret = 1; - done: +done: EVP_PKEY_CTX_free(ctx); #ifndef OPENSSL_NO_DEPRECATED_3_0 EVP_PKEY_CTX_free(ctx2); @@ -2433,11 +2433,11 @@ static int get_cmac_val(EVP_PKEY *pkey, unsigned char *mac) int ret = 1; if (!TEST_ptr(mdctx) - || !TEST_true(EVP_DigestSignInit_ex(mdctx, NULL, NULL, testctx, - testpropq, pkey, NULL)) - || !TEST_true(EVP_DigestSignUpdate(mdctx, msg, sizeof(msg))) - || !TEST_true(EVP_DigestSignFinal(mdctx, mac, &maclen)) - || !TEST_size_t_eq(maclen, AES_BLOCK_SIZE)) + || !TEST_true(EVP_DigestSignInit_ex(mdctx, NULL, NULL, testctx, + testpropq, pkey, NULL)) + || !TEST_true(EVP_DigestSignUpdate(mdctx, msg, sizeof(msg))) + || !TEST_true(EVP_DigestSignFinal(mdctx, mac, &maclen)) + || !TEST_size_t_eq(maclen, AES_BLOCK_SIZE)) ret = 0; EVP_MD_CTX_free(mdctx); @@ -2455,9 +2455,9 @@ static int test_CMAC_keygen(void) int ret = 0; EVP_PKEY *pkey = NULL; unsigned char mac[AES_BLOCK_SIZE]; -# if !defined(OPENSSL_NO_DEPRECATED_3_0) +#if !defined(OPENSSL_NO_DEPRECATED_3_0) unsigned char mac2[AES_BLOCK_SIZE]; -# endif +#endif if (nullprov != NULL) return TEST_skip("Test does not support a non-default library context"); @@ -2470,18 +2470,20 @@ static int test_CMAC_keygen(void) /* Test a CMAC key created using the "generated" method */ if (!TEST_int_gt(EVP_PKEY_keygen_init(kctx), 0) - || !TEST_int_gt(EVP_PKEY_CTX_ctrl(kctx, -1, EVP_PKEY_OP_KEYGEN, - EVP_PKEY_CTRL_CIPHER, - 0, (void *)EVP_aes_256_ecb()), 0) - || !TEST_int_gt(EVP_PKEY_CTX_ctrl(kctx, -1, EVP_PKEY_OP_KEYGEN, - EVP_PKEY_CTRL_SET_MAC_KEY, - sizeof(key), (void *)key), 0) - || !TEST_int_gt(EVP_PKEY_keygen(kctx, &pkey), 0) - || !TEST_ptr(pkey) - || !TEST_true(get_cmac_val(pkey, mac))) + || !TEST_int_gt(EVP_PKEY_CTX_ctrl(kctx, -1, EVP_PKEY_OP_KEYGEN, + EVP_PKEY_CTRL_CIPHER, + 0, (void *)EVP_aes_256_ecb()), + 0) + || !TEST_int_gt(EVP_PKEY_CTX_ctrl(kctx, -1, EVP_PKEY_OP_KEYGEN, + EVP_PKEY_CTRL_SET_MAC_KEY, + sizeof(key), (void *)key), + 0) + || !TEST_int_gt(EVP_PKEY_keygen(kctx, &pkey), 0) + || !TEST_ptr(pkey) + || !TEST_true(get_cmac_val(pkey, mac))) goto done; -# if !defined(OPENSSL_NO_DEPRECATED_3_0) +#if !defined(OPENSSL_NO_DEPRECATED_3_0) EVP_PKEY_free(pkey); /* @@ -2490,14 +2492,14 @@ static int test_CMAC_keygen(void) */ pkey = EVP_PKEY_new_CMAC_key(NULL, key, sizeof(key), EVP_aes_256_ecb()); if (!TEST_ptr(pkey) - || !TEST_true(get_cmac_val(pkey, mac2)) - || !TEST_mem_eq(mac, sizeof(mac), mac2, sizeof(mac2))) + || !TEST_true(get_cmac_val(pkey, mac2)) + || !TEST_mem_eq(mac, sizeof(mac), mac2, sizeof(mac2))) goto done; -# endif +#endif ret = 1; - done: +done: EVP_PKEY_free(pkey); EVP_PKEY_CTX_free(kctx); return ret; @@ -2528,21 +2530,24 @@ static int test_HKDF(void) memset(out, 0, outlen); if (!TEST_int_gt(EVP_PKEY_derive_init(pctx), 0) - || !TEST_int_gt(EVP_PKEY_CTX_set_hkdf_md(pctx, EVP_sha256()), 0) - || !TEST_int_gt(EVP_PKEY_CTX_set1_hkdf_salt(pctx, salt, - sizeof(salt) - 1), 0) - || !TEST_int_gt(EVP_PKEY_CTX_set1_hkdf_key(pctx, key, - sizeof(key) - 1), 0) - || !TEST_int_gt(EVP_PKEY_CTX_add1_hkdf_info(pctx, info, - sizeof(info) - 1), 0) - || !TEST_int_gt(EVP_PKEY_derive(pctx, out, &outlen), 0) - || !TEST_mem_eq(out, outlen, expected, expectedlen)) + || !TEST_int_gt(EVP_PKEY_CTX_set_hkdf_md(pctx, EVP_sha256()), 0) + || !TEST_int_gt(EVP_PKEY_CTX_set1_hkdf_salt(pctx, salt, + sizeof(salt) - 1), + 0) + || !TEST_int_gt(EVP_PKEY_CTX_set1_hkdf_key(pctx, key, + sizeof(key) - 1), + 0) + || !TEST_int_gt(EVP_PKEY_CTX_add1_hkdf_info(pctx, info, + sizeof(info) - 1), + 0) + || !TEST_int_gt(EVP_PKEY_derive(pctx, out, &outlen), 0) + || !TEST_mem_eq(out, outlen, expected, expectedlen)) goto done; } ret = 1; - done: +done: EVP_PKEY_CTX_free(pctx); return ret; @@ -2570,20 +2575,23 @@ static int test_emptyikm_HKDF(void) memset(out, 0, outlen); if (!TEST_int_gt(EVP_PKEY_derive_init(pctx), 0) - || !TEST_int_gt(EVP_PKEY_CTX_set_hkdf_md(pctx, EVP_sha256()), 0) - || !TEST_int_gt(EVP_PKEY_CTX_set1_hkdf_salt(pctx, salt, - sizeof(salt) - 1), 0) - || !TEST_int_gt(EVP_PKEY_CTX_set1_hkdf_key(pctx, key, - sizeof(key) - 1), 0) - || !TEST_int_gt(EVP_PKEY_CTX_add1_hkdf_info(pctx, info, - sizeof(info) - 1), 0) - || !TEST_int_gt(EVP_PKEY_derive(pctx, out, &outlen), 0) - || !TEST_mem_eq(out, outlen, expected, expectedlen)) + || !TEST_int_gt(EVP_PKEY_CTX_set_hkdf_md(pctx, EVP_sha256()), 0) + || !TEST_int_gt(EVP_PKEY_CTX_set1_hkdf_salt(pctx, salt, + sizeof(salt) - 1), + 0) + || !TEST_int_gt(EVP_PKEY_CTX_set1_hkdf_key(pctx, key, + sizeof(key) - 1), + 0) + || !TEST_int_gt(EVP_PKEY_CTX_add1_hkdf_info(pctx, info, + sizeof(info) - 1), + 0) + || !TEST_int_gt(EVP_PKEY_derive(pctx, out, &outlen), 0) + || !TEST_mem_eq(out, outlen, expected, expectedlen)) goto done; ret = 1; - done: +done: EVP_PKEY_CTX_free(pctx); return ret; @@ -2600,8 +2608,8 @@ static int test_empty_salt_info_HKDF(void) unsigned char key[] = "012345678901234567890123456789"; unsigned char info[] = ""; const unsigned char expected[] = { - 0x67, 0x12, 0xf9, 0x27, 0x8a, 0x8a, 0x3a, 0x8f, 0x7d, 0x2c, 0xa3, 0x6a, - 0xaa, 0xe9, 0xb3, 0xb9, 0x52, 0x5f, 0xe0, 0x06, + 0x67, 0x12, 0xf9, 0x27, 0x8a, 0x8a, 0x3a, 0x8f, 0x7d, 0x2c, 0xa3, 0x6a, + 0xaa, 0xe9, 0xb3, 0xb9, 0x52, 0x5f, 0xe0, 0x06 }; size_t expectedlen = sizeof(expected); @@ -2612,22 +2620,26 @@ static int test_empty_salt_info_HKDF(void) memset(out, 0, outlen); if (!TEST_int_gt(EVP_PKEY_derive_init(pctx), 0) - || !TEST_int_gt(EVP_PKEY_CTX_set_hkdf_md(pctx, EVP_sha256()), 0) - || !TEST_int_gt(EVP_PKEY_CTX_set1_hkdf_salt(pctx, fake, - sizeof(fake) - 1), 0) - || !TEST_int_gt(EVP_PKEY_CTX_set1_hkdf_salt(pctx, salt, - sizeof(salt) - 1), 0) - || !TEST_int_gt(EVP_PKEY_CTX_set1_hkdf_key(pctx, key, - sizeof(key) - 1), 0) - || !TEST_int_gt(EVP_PKEY_CTX_add1_hkdf_info(pctx, info, - sizeof(info) - 1), 0) - || !TEST_int_gt(EVP_PKEY_derive(pctx, out, &outlen), 0) - || !TEST_mem_eq(out, outlen, expected, expectedlen)) + || !TEST_int_gt(EVP_PKEY_CTX_set_hkdf_md(pctx, EVP_sha256()), 0) + || !TEST_int_gt(EVP_PKEY_CTX_set1_hkdf_salt(pctx, fake, + sizeof(fake) - 1), + 0) + || !TEST_int_gt(EVP_PKEY_CTX_set1_hkdf_salt(pctx, salt, + sizeof(salt) - 1), + 0) + || !TEST_int_gt(EVP_PKEY_CTX_set1_hkdf_key(pctx, key, + sizeof(key) - 1), + 0) + || !TEST_int_gt(EVP_PKEY_CTX_add1_hkdf_info(pctx, info, + sizeof(info) - 1), + 0) + || !TEST_int_gt(EVP_PKEY_derive(pctx, out, &outlen), 0) + || !TEST_mem_eq(out, outlen, expected, expectedlen)) goto done; ret = 1; - done: +done: EVP_PKEY_CTX_free(pctx); return ret; @@ -2660,7 +2672,7 @@ static int test_X509_PUBKEY_inplace(void) ret = 1; - done: +done: X509_PUBKEY_free(xp); return ret; } @@ -2674,14 +2686,14 @@ static int test_X509_PUBKEY_dup(void) xp = X509_PUBKEY_new_ex(testctx, testpropq); if (!TEST_ptr(xp) - || !TEST_ptr(d2i_X509_PUBKEY(&xp, &p, input_len)) - || !TEST_ptr(xq = X509_PUBKEY_dup(xp)) - || !TEST_ptr_ne(xp, xq)) + || !TEST_ptr(d2i_X509_PUBKEY(&xp, &p, input_len)) + || !TEST_ptr(xq = X509_PUBKEY_dup(xp)) + || !TEST_ptr_ne(xp, xq)) goto done; if (!TEST_ptr(X509_PUBKEY_get0(xq)) - || !TEST_ptr(X509_PUBKEY_get0(xp)) - || !TEST_ptr_ne(X509_PUBKEY_get0(xq), X509_PUBKEY_get0(xp))) + || !TEST_ptr(X509_PUBKEY_get0(xp)) + || !TEST_ptr_ne(X509_PUBKEY_get0(xq), X509_PUBKEY_get0(xp))) goto done; X509_PUBKEY_free(xq); @@ -2690,7 +2702,7 @@ static int test_X509_PUBKEY_dup(void) input_len = sizeof(kExampleBadECPubKeyDER); if (!TEST_ptr(xp = d2i_X509_PUBKEY(&xp, &p, input_len)) - || !TEST_ptr(xq = X509_PUBKEY_dup(xp))) + || !TEST_ptr(xq = X509_PUBKEY_dup(xp))) goto done; X509_PUBKEY_free(xp); @@ -2700,7 +2712,7 @@ static int test_X509_PUBKEY_dup(void) ret = 1; - done: +done: X509_PUBKEY_free(xp); X509_PUBKEY_free(xq); return ret; @@ -2722,7 +2734,7 @@ static int test_EVP_PKEY_CTX_get_set_params(EVP_PKEY *pkey) /* Initialise a sign operation */ ctx = EVP_PKEY_CTX_new_from_pkey(testctx, pkey, testpropq); if (!TEST_ptr(ctx) - || !TEST_int_gt(EVP_PKEY_sign_init(ctx), 0)) + || !TEST_int_gt(EVP_PKEY_sign_init(ctx), 0)) goto err; /* @@ -2731,15 +2743,15 @@ static int test_EVP_PKEY_CTX_get_set_params(EVP_PKEY *pkey) params = EVP_PKEY_CTX_settable_params(ctx); if (!TEST_ptr(params) || !TEST_ptr(OSSL_PARAM_locate_const(params, - OSSL_SIGNATURE_PARAM_DIGEST))) + OSSL_SIGNATURE_PARAM_DIGEST))) goto err; params = EVP_PKEY_CTX_gettable_params(ctx); if (!TEST_ptr(params) || !TEST_ptr(OSSL_PARAM_locate_const(params, - OSSL_SIGNATURE_PARAM_ALGORITHM_ID)) + OSSL_SIGNATURE_PARAM_ALGORITHM_ID)) || !TEST_ptr(OSSL_PARAM_locate_const(params, - OSSL_SIGNATURE_PARAM_DIGEST))) + OSSL_SIGNATURE_PARAM_DIGEST))) goto err; /* @@ -2749,7 +2761,7 @@ static int test_EVP_PKEY_CTX_get_set_params(EVP_PKEY *pkey) strcpy(mdname, "SHA512"); param_md = param; *param++ = OSSL_PARAM_construct_utf8_string(OSSL_SIGNATURE_PARAM_DIGEST, - mdname, 0); + mdname, 0); *param++ = OSSL_PARAM_construct_end(); if (!TEST_true(EVP_PKEY_CTX_set_params(ctx, ourparams))) @@ -2757,9 +2769,9 @@ static int test_EVP_PKEY_CTX_get_set_params(EVP_PKEY *pkey) mdname[0] = '\0'; *param_md = OSSL_PARAM_construct_utf8_string(OSSL_SIGNATURE_PARAM_DIGEST, - mdname, sizeof(mdname)); + mdname, sizeof(mdname)); if (!TEST_true(EVP_PKEY_CTX_get_params(ctx, ourparams)) - || !TEST_str_eq(mdname, "SHA512")) + || !TEST_str_eq(mdname, "SHA512")) goto err; /* @@ -2767,8 +2779,8 @@ static int test_EVP_PKEY_CTX_get_set_params(EVP_PKEY *pkey) * TEST_PKEY_CTX_get_signature_md() functions */ if (!TEST_int_gt(EVP_PKEY_CTX_set_signature_md(ctx, EVP_sha256()), 0) - || !TEST_int_gt(EVP_PKEY_CTX_get_signature_md(ctx, &md), 0) - || !TEST_ptr_eq(md, EVP_sha256())) + || !TEST_int_gt(EVP_PKEY_CTX_get_signature_md(ctx, &md), 0) + || !TEST_ptr_eq(md, EVP_sha256())) goto err; /* @@ -2777,7 +2789,7 @@ static int test_EVP_PKEY_CTX_get_set_params(EVP_PKEY *pkey) mdctx = EVP_MD_CTX_new(); if (!TEST_ptr(mdctx) || !TEST_true(EVP_DigestSignInit_ex(mdctx, NULL, "SHA1", testctx, testpropq, - pkey, NULL))) + pkey, NULL))) goto err; /* @@ -2786,15 +2798,15 @@ static int test_EVP_PKEY_CTX_get_set_params(EVP_PKEY *pkey) */ params = EVP_MD_CTX_settable_params(mdctx); if (!TEST_ptr(params) - || !TEST_int_eq(strcmp(params[0].key, OSSL_DIGEST_PARAM_SSL3_MS), 0) - /* The final key should be NULL */ - || !TEST_ptr_null(params[1].key)) + || !TEST_int_eq(strcmp(params[0].key, OSSL_DIGEST_PARAM_SSL3_MS), 0) + /* The final key should be NULL */ + || !TEST_ptr_null(params[1].key)) goto err; param = ourparams; memset(ssl3ms, 0, sizeof(ssl3ms)); *param++ = OSSL_PARAM_construct_octet_string(OSSL_DIGEST_PARAM_SSL3_MS, - ssl3ms, sizeof(ssl3ms)); + ssl3ms, sizeof(ssl3ms)); *param++ = OSSL_PARAM_construct_end(); if (!TEST_true(EVP_MD_CTX_set_params(mdctx, ourparams))) @@ -2802,7 +2814,7 @@ static int test_EVP_PKEY_CTX_get_set_params(EVP_PKEY *pkey) ret = 1; - err: +err: EVP_MD_CTX_free(mdctx); EVP_PKEY_CTX_free(ctx); @@ -2835,16 +2847,17 @@ static int test_DSA_get_set_params(void) || !TEST_true(OSSL_PARAM_BLD_push_BN(bld, OSSL_PKEY_PARAM_FFC_Q, q)) || !TEST_true(OSSL_PARAM_BLD_push_BN(bld, OSSL_PKEY_PARAM_FFC_G, g)) || !TEST_true(OSSL_PARAM_BLD_push_BN(bld, OSSL_PKEY_PARAM_PUB_KEY, - pub)) + pub)) || !TEST_true(OSSL_PARAM_BLD_push_BN(bld, OSSL_PKEY_PARAM_PRIV_KEY, - priv))) + priv))) goto err; if (!TEST_ptr(params = OSSL_PARAM_BLD_to_param(bld))) goto err; if (!TEST_int_gt(EVP_PKEY_fromdata_init(pctx), 0) || !TEST_int_gt(EVP_PKEY_fromdata(pctx, &pkey, EVP_PKEY_KEYPAIR, - params), 0)) + params), + 0)) goto err; if (!TEST_ptr(pkey)) @@ -2852,7 +2865,7 @@ static int test_DSA_get_set_params(void) ret = test_EVP_PKEY_CTX_get_set_params(pkey); - err: +err: EVP_PKEY_free(pkey); EVP_PKEY_CTX_free(pctx); OSSL_PARAM_free(params); @@ -2905,7 +2918,8 @@ static int test_RSA_get_set_params(void) if (!TEST_int_gt(EVP_PKEY_fromdata_init(pctx), 0) || !TEST_int_gt(EVP_PKEY_fromdata(pctx, &pkey, EVP_PKEY_KEYPAIR, - params), 0)) + params), + 0)) goto err; if (!TEST_ptr(pkey)) @@ -2913,7 +2927,7 @@ static int test_RSA_get_set_params(void) ret = test_EVP_PKEY_CTX_get_set_params(pkey); - err: +err: EVP_PKEY_free(pkey); EVP_PKEY_CTX_free(pctx); OSSL_PARAM_free(params); @@ -2944,12 +2958,12 @@ static int test_RSA_OAEP_set_get_params(void) params[0] = OSSL_PARAM_construct_int(OSSL_SIGNATURE_PARAM_PAD_MODE, &padding); params[1] = OSSL_PARAM_construct_utf8_string(OSSL_ASYM_CIPHER_PARAM_OAEP_DIGEST, - OSSL_DIGEST_NAME_SHA2_256, 0); + OSSL_DIGEST_NAME_SHA2_256, 0); params[2] = OSSL_PARAM_construct_utf8_string(OSSL_ASYM_CIPHER_PARAM_MGF1_DIGEST, - OSSL_DIGEST_NAME_SHA1, 0); + OSSL_DIGEST_NAME_SHA1, 0); params[3] = OSSL_PARAM_construct_end(); - if (!TEST_int_gt(EVP_PKEY_encrypt_init_ex(key_ctx, params),0)) + if (!TEST_int_gt(EVP_PKEY_encrypt_init_ex(key_ctx, params), 0)) goto err; } { @@ -2958,9 +2972,9 @@ static int test_RSA_OAEP_set_get_params(void) char mgf1md[30] = { '\0' }; params[0] = OSSL_PARAM_construct_utf8_string(OSSL_ASYM_CIPHER_PARAM_OAEP_DIGEST, - oaepmd, sizeof(oaepmd)); + oaepmd, sizeof(oaepmd)); params[1] = OSSL_PARAM_construct_utf8_string(OSSL_ASYM_CIPHER_PARAM_MGF1_DIGEST, - mgf1md, sizeof(mgf1md)); + mgf1md, sizeof(mgf1md)); params[2] = OSSL_PARAM_construct_end(); if (!TEST_true(EVP_PKEY_CTX_get_params(key_ctx, params))) @@ -2973,7 +2987,7 @@ static int test_RSA_OAEP_set_get_params(void) ret = 1; - err: +err: EVP_PKEY_free(key); EVP_PKEY_CTX_free(key_ctx); @@ -3003,7 +3017,7 @@ static int test_RSA_OAEP_set_null_label(void) ret = 1; - err: +err: EVP_PKEY_free(key); EVP_PKEY_CTX_free(key_ctx); @@ -3020,7 +3034,7 @@ static int test_RSA_encrypt(void) if (!TEST_ptr(pkey = load_example_rsa_key()) || !TEST_ptr(pctx = EVP_PKEY_CTX_new_from_pkey(testctx, - pkey, testpropq)) + pkey, testpropq)) || !TEST_int_gt(EVP_PKEY_encrypt_init(pctx), 0) || !TEST_int_gt(EVP_PKEY_encrypt(pctx, cbuf, &clen, kMsg, sizeof(kMsg)), 0) || !TEST_ptr(cbuf = OPENSSL_malloc(clen)) @@ -3055,7 +3069,7 @@ done: #if !defined(OPENSSL_NO_CHACHA) && !defined(OPENSSL_NO_POLY1305) static int test_decrypt_null_chunks(void) { - EVP_CIPHER_CTX* ctx = NULL; + EVP_CIPHER_CTX *ctx = NULL; EVP_CIPHER *cipher = NULL; const unsigned char key[32] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, @@ -3074,46 +3088,46 @@ static int test_decrypt_null_chunks(void) const int enc_offset = 10, dec_offset = 20; if (!TEST_ptr(cipher = EVP_CIPHER_fetch(testctx, "ChaCha20-Poly1305", testpropq)) - || !TEST_ptr(ctx = EVP_CIPHER_CTX_new()) - || !TEST_true(EVP_EncryptInit_ex(ctx, cipher, NULL, - key, iv)) - || !TEST_true(EVP_EncryptUpdate(ctx, ciphertext, &ctlen, msg, - enc_offset)) - /* Deliberate add a zero length update */ - || !TEST_true(EVP_EncryptUpdate(ctx, ciphertext + ctlen, &tmp, NULL, - 0)) - || !TEST_int_eq(tmp, 0) - || !TEST_true(EVP_EncryptUpdate(ctx, ciphertext + ctlen, &tmp, - msg + enc_offset, - sizeof(msg) - enc_offset)) - || !TEST_int_eq(ctlen += tmp, sizeof(msg)) - || !TEST_true(EVP_EncryptFinal(ctx, ciphertext + ctlen, &tmp)) - || !TEST_int_eq(tmp, 0)) + || !TEST_ptr(ctx = EVP_CIPHER_CTX_new()) + || !TEST_true(EVP_EncryptInit_ex(ctx, cipher, NULL, + key, iv)) + || !TEST_true(EVP_EncryptUpdate(ctx, ciphertext, &ctlen, msg, + enc_offset)) + /* Deliberate add a zero length update */ + || !TEST_true(EVP_EncryptUpdate(ctx, ciphertext + ctlen, &tmp, NULL, + 0)) + || !TEST_int_eq(tmp, 0) + || !TEST_true(EVP_EncryptUpdate(ctx, ciphertext + ctlen, &tmp, + msg + enc_offset, + sizeof(msg) - enc_offset)) + || !TEST_int_eq(ctlen += tmp, sizeof(msg)) + || !TEST_true(EVP_EncryptFinal(ctx, ciphertext + ctlen, &tmp)) + || !TEST_int_eq(tmp, 0)) goto err; /* Deliberately initialise tmp to a non zero value */ tmp = 99; if (!TEST_true(EVP_DecryptInit_ex(ctx, cipher, NULL, key, iv)) - || !TEST_true(EVP_DecryptUpdate(ctx, plaintext, &ptlen, ciphertext, - dec_offset)) - /* - * Deliberately add a zero length update. We also deliberately do - * this at a different offset than for encryption. - */ - || !TEST_true(EVP_DecryptUpdate(ctx, plaintext + ptlen, &tmp, NULL, - 0)) - || !TEST_int_eq(tmp, 0) - || !TEST_true(EVP_DecryptUpdate(ctx, plaintext + ptlen, &tmp, - ciphertext + dec_offset, - ctlen - dec_offset)) - || !TEST_int_eq(ptlen += tmp, sizeof(msg)) - || !TEST_true(EVP_DecryptFinal(ctx, plaintext + ptlen, &tmp)) - || !TEST_int_eq(tmp, 0) - || !TEST_mem_eq(msg, sizeof(msg), plaintext, ptlen)) + || !TEST_true(EVP_DecryptUpdate(ctx, plaintext, &ptlen, ciphertext, + dec_offset)) + /* + * Deliberately add a zero length update. We also deliberately do + * this at a different offset than for encryption. + */ + || !TEST_true(EVP_DecryptUpdate(ctx, plaintext + ptlen, &tmp, NULL, + 0)) + || !TEST_int_eq(tmp, 0) + || !TEST_true(EVP_DecryptUpdate(ctx, plaintext + ptlen, &tmp, + ciphertext + dec_offset, + ctlen - dec_offset)) + || !TEST_int_eq(ptlen += tmp, sizeof(msg)) + || !TEST_true(EVP_DecryptFinal(ctx, plaintext + ptlen, &tmp)) + || !TEST_int_eq(tmp, 0) + || !TEST_mem_eq(msg, sizeof(msg), plaintext, ptlen)) goto err; ret = 1; - err: +err: EVP_CIPHER_CTX_free(ctx); EVP_CIPHER_free(cipher); return ret; @@ -3130,7 +3144,7 @@ static int test_DH_priv_pub(void) return test_EVP_PKEY_ffc_priv_pub("DH"); } -# ifndef OPENSSL_NO_DEPRECATED_3_0 +#ifndef OPENSSL_NO_DEPRECATED_3_0 static int test_EVP_PKEY_set1_DH(void) { DH *x942dh = NULL, *noqdh = NULL; @@ -3142,16 +3156,16 @@ static int test_EVP_PKEY_set1_DH(void) size_t len = 0; if (!TEST_ptr(p = BN_new()) - || !TEST_ptr(g = BN_new()) - || !TEST_ptr(pubkey = BN_new()) - || !TEST_true(BN_set_word(p, 9999)) - || !TEST_true(BN_set_word(g, 2)) - || !TEST_true(BN_set_word(pubkey, 4321)) - || !TEST_ptr(noqdh = DH_new()) - || !TEST_true(DH_set0_pqg(noqdh, p, NULL, g)) - || !TEST_true(DH_set0_key(noqdh, pubkey, NULL)) - || !TEST_ptr(pubkey = BN_new()) - || !TEST_true(BN_set_word(pubkey, 4321))) + || !TEST_ptr(g = BN_new()) + || !TEST_ptr(pubkey = BN_new()) + || !TEST_true(BN_set_word(p, 9999)) + || !TEST_true(BN_set_word(g, 2)) + || !TEST_true(BN_set_word(pubkey, 4321)) + || !TEST_ptr(noqdh = DH_new()) + || !TEST_true(DH_set0_pqg(noqdh, p, NULL, g)) + || !TEST_true(DH_set0_key(noqdh, pubkey, NULL)) + || !TEST_ptr(pubkey = BN_new()) + || !TEST_true(BN_set_word(pubkey, 4321))) goto err; p = g = NULL; @@ -3159,34 +3173,34 @@ static int test_EVP_PKEY_set1_DH(void) pkey1 = EVP_PKEY_new(); pkey2 = EVP_PKEY_new(); if (!TEST_ptr(x942dh) - || !TEST_ptr(noqdh) - || !TEST_ptr(pkey1) - || !TEST_ptr(pkey2) - || !TEST_true(DH_set0_key(x942dh, pubkey, NULL))) + || !TEST_ptr(noqdh) + || !TEST_ptr(pkey1) + || !TEST_ptr(pkey2) + || !TEST_true(DH_set0_key(x942dh, pubkey, NULL))) goto err; pubkey = NULL; if (!TEST_true(EVP_PKEY_set1_DH(pkey1, x942dh)) - || !TEST_int_eq(EVP_PKEY_get_id(pkey1), EVP_PKEY_DHX)) + || !TEST_int_eq(EVP_PKEY_get_id(pkey1), EVP_PKEY_DHX)) goto err; if (!TEST_true(EVP_PKEY_get_bn_param(pkey1, OSSL_PKEY_PARAM_PUB_KEY, - &pubkey)) - || !TEST_ptr(pubkey)) + &pubkey)) + || !TEST_ptr(pubkey)) goto err; if (!TEST_true(EVP_PKEY_set1_DH(pkey2, noqdh)) - || !TEST_int_eq(EVP_PKEY_get_id(pkey2), EVP_PKEY_DH)) + || !TEST_int_eq(EVP_PKEY_get_id(pkey2), EVP_PKEY_DH)) goto err; if (!TEST_true(EVP_PKEY_get_octet_string_param(pkey2, - OSSL_PKEY_PARAM_PUB_KEY, - pub, sizeof(pub), &len)) - || !TEST_size_t_ne(len, 0)) + OSSL_PKEY_PARAM_PUB_KEY, + pub, sizeof(pub), &len)) + || !TEST_size_t_ne(len, 0)) goto err; ret = 1; - err: +err: BN_free(p); BN_free(g); BN_free(pubkey); @@ -3197,7 +3211,7 @@ static int test_EVP_PKEY_set1_DH(void) return ret; } -# endif /* !OPENSSL_NO_DEPRECATED_3_0 */ +#endif /* !OPENSSL_NO_DEPRECATED_3_0 */ #endif /* !OPENSSL_NO_DH */ /* @@ -3237,7 +3251,7 @@ static int test_keygen_with_empty_template(int n) goto err; ret = 1; - err: +err: EVP_PKEY_CTX_free(ctx); EVP_PKEY_free(pkey); EVP_PKEY_free(tkey); @@ -3270,9 +3284,9 @@ static int test_pkey_ctx_fail_without_provider(int tst) /* * We check for certain algos in the null provider. - * If an algo is expected to have a provider keymgmt, contructing an + * If an algo is expected to have a provider keymgmt, constructing an * EVP_PKEY_CTX is expected to fail (return NULL). - * Otherwise, if it's expected to have legacy support, contructing an + * Otherwise, if it's expected to have legacy support, constructing an * EVP_PKEY_CTX is expected to succeed (return non-NULL). */ switch (tst) { @@ -3302,11 +3316,11 @@ static int test_pkey_ctx_fail_without_provider(int tst) goto err; #if defined(OPENSSL_NO_EC) || defined(OPENSSL_NO_SM2) - end: +end: #endif ret = 1; - err: +err: EVP_PKEY_CTX_free(pctx); OSSL_PROVIDER_unload(tmpnullprov); OSSL_LIB_CTX_free(tmpctx); @@ -3325,7 +3339,7 @@ static int test_rand_agglomeration(void) unsigned char out[sizeof(seed)]; if (!TEST_int_ne(sizeof(seed) % step, 0) - || !TEST_ptr(rand = EVP_RAND_fetch(testctx, "TEST-RAND", testpropq))) + || !TEST_ptr(rand = EVP_RAND_fetch(testctx, "TEST-RAND", testpropq))) return 0; ctx = EVP_RAND_CTX_new(rand, NULL); EVP_RAND_free(rand); @@ -3334,12 +3348,12 @@ static int test_rand_agglomeration(void) memset(out, 0, sizeof(out)); *p++ = OSSL_PARAM_construct_octet_string(OSSL_RAND_PARAM_TEST_ENTROPY, - seed, sizeof(seed)); + seed, sizeof(seed)); *p++ = OSSL_PARAM_construct_uint(OSSL_RAND_PARAM_MAX_REQUEST, &step); *p = OSSL_PARAM_construct_end(); res = TEST_true(EVP_RAND_CTX_set_params(ctx, params)) - && TEST_true(EVP_RAND_generate(ctx, out, sizeof(out), 0, 1, NULL, 0)) - && TEST_mem_eq(seed, sizeof(seed), out, sizeof(out)); + && TEST_true(EVP_RAND_generate(ctx, out, sizeof(out), 0, 1, NULL, 0)) + && TEST_mem_eq(seed, sizeof(seed), out, sizeof(out)); EVP_RAND_CTX_free(ctx); return res; } @@ -3353,28 +3367,27 @@ static int test_evp_iv_aes(int idx) { int ret = 0; EVP_CIPHER_CTX *ctx = NULL; - unsigned char key[16] = {0x4c, 0x43, 0xdb, 0xdd, 0x42, 0x73, 0x47, 0xd1, - 0xe5, 0x62, 0x7d, 0xcd, 0x4d, 0x76, 0x4d, 0x57}; - unsigned char init_iv[EVP_MAX_IV_LENGTH] = - {0x57, 0x71, 0x7d, 0xad, 0xdb, 0x9b, 0x98, 0x82, - 0x5a, 0x55, 0x91, 0x81, 0x42, 0xa8, 0x89, 0x34}; + unsigned char key[16] = { 0x4c, 0x43, 0xdb, 0xdd, 0x42, 0x73, 0x47, 0xd1, + 0xe5, 0x62, 0x7d, 0xcd, 0x4d, 0x76, 0x4d, 0x57 }; + unsigned char init_iv[EVP_MAX_IV_LENGTH] = { 0x57, 0x71, 0x7d, 0xad, 0xdb, 0x9b, 0x98, 0x82, + 0x5a, 0x55, 0x91, 0x81, 0x42, 0xa8, 0x89, 0x34 }; static const unsigned char msg[] = { 1, 2, 3, 4, 5, 6, 7, 8, - 9, 10, 11, 12, 13, 14, 15, 16 }; + 9, 10, 11, 12, 13, 14, 15, 16 }; unsigned char ciphertext[32], oiv[16], iv[16]; unsigned char *ref_iv; - unsigned char cbc_state[16] = {0x10, 0x2f, 0x05, 0xcc, 0xc2, 0x55, 0x72, 0xb9, - 0x88, 0xe6, 0x4a, 0x17, 0x10, 0x74, 0x22, 0x5e}; + unsigned char cbc_state[16] = { 0x10, 0x2f, 0x05, 0xcc, 0xc2, 0x55, 0x72, 0xb9, + 0x88, 0xe6, 0x4a, 0x17, 0x10, 0x74, 0x22, 0x5e }; - unsigned char ofb_state[16] = {0x76, 0xe6, 0x66, 0x61, 0xd0, 0x8a, 0xe4, 0x64, - 0xdd, 0x66, 0xbf, 0x00, 0xf0, 0xe3, 0x6f, 0xfd}; - unsigned char cfb_state[16] = {0x77, 0xe4, 0x65, 0x65, 0xd5, 0x8c, 0xe3, 0x6c, - 0xd4, 0x6c, 0xb4, 0x0c, 0xfd, 0xed, 0x60, 0xed}; - unsigned char gcm_state[12] = {0x57, 0x71, 0x7d, 0xad, 0xdb, 0x9b, - 0x98, 0x82, 0x5a, 0x55, 0x91, 0x81}; - unsigned char ccm_state[7] = {0x57, 0x71, 0x7d, 0xad, 0xdb, 0x9b, 0x98}; + unsigned char ofb_state[16] = { 0x76, 0xe6, 0x66, 0x61, 0xd0, 0x8a, 0xe4, 0x64, + 0xdd, 0x66, 0xbf, 0x00, 0xf0, 0xe3, 0x6f, 0xfd }; + unsigned char cfb_state[16] = { 0x77, 0xe4, 0x65, 0x65, 0xd5, 0x8c, 0xe3, 0x6c, + 0xd4, 0x6c, 0xb4, 0x0c, 0xfd, 0xed, 0x60, 0xed }; + unsigned char gcm_state[12] = { 0x57, 0x71, 0x7d, 0xad, 0xdb, 0x9b, + 0x98, 0x82, 0x5a, 0x55, 0x91, 0x81 }; + unsigned char ccm_state[7] = { 0x57, 0x71, 0x7d, 0xad, 0xdb, 0x9b, 0x98 }; #ifndef OPENSSL_NO_OCB - unsigned char ocb_state[12] = {0x57, 0x71, 0x7d, 0xad, 0xdb, 0x9b, - 0x98, 0x82, 0x5a, 0x55, 0x91, 0x81}; + unsigned char ocb_state[12] = { 0x57, 0x71, 0x7d, 0xad, 0xdb, 0x9b, + 0x98, 0x82, 0x5a, 0x55, 0x91, 0x81 }; #endif int len = sizeof(ciphertext); size_t ivlen, ref_len; @@ -3384,13 +3397,12 @@ static int test_evp_iv_aes(int idx) if (nullprov != NULL && idx < 6) return TEST_skip("Test does not support a non-default library context"); - switch(idx) { + switch (idx) { case 0: type = EVP_aes_128_cbc(); /* FALLTHROUGH */ case 6: - type = (type != NULL) ? type : - EVP_CIPHER_fetch(testctx, "aes-128-cbc", testpropq); + type = (type != NULL) ? type : EVP_CIPHER_fetch(testctx, "aes-128-cbc", testpropq); ref_iv = cbc_state; ref_len = sizeof(cbc_state); iv_reset = 1; @@ -3399,8 +3411,7 @@ static int test_evp_iv_aes(int idx) type = EVP_aes_128_ofb(); /* FALLTHROUGH */ case 7: - type = (type != NULL) ? type : - EVP_CIPHER_fetch(testctx, "aes-128-ofb", testpropq); + type = (type != NULL) ? type : EVP_CIPHER_fetch(testctx, "aes-128-ofb", testpropq); ref_iv = ofb_state; ref_len = sizeof(ofb_state); iv_reset = 1; @@ -3409,8 +3420,7 @@ static int test_evp_iv_aes(int idx) type = EVP_aes_128_cfb(); /* FALLTHROUGH */ case 8: - type = (type != NULL) ? type : - EVP_CIPHER_fetch(testctx, "aes-128-cfb", testpropq); + type = (type != NULL) ? type : EVP_CIPHER_fetch(testctx, "aes-128-cfb", testpropq); ref_iv = cfb_state; ref_len = sizeof(cfb_state); iv_reset = 1; @@ -3419,8 +3429,7 @@ static int test_evp_iv_aes(int idx) type = EVP_aes_128_gcm(); /* FALLTHROUGH */ case 9: - type = (type != NULL) ? type : - EVP_CIPHER_fetch(testctx, "aes-128-gcm", testpropq); + type = (type != NULL) ? type : EVP_CIPHER_fetch(testctx, "aes-128-gcm", testpropq); ref_iv = gcm_state; ref_len = sizeof(gcm_state); break; @@ -3428,8 +3437,7 @@ static int test_evp_iv_aes(int idx) type = EVP_aes_128_ccm(); /* FALLTHROUGH */ case 10: - type = (type != NULL) ? type : - EVP_CIPHER_fetch(testctx, "aes-128-ccm", testpropq); + type = (type != NULL) ? type : EVP_CIPHER_fetch(testctx, "aes-128-ccm", testpropq); ref_iv = ccm_state; ref_len = sizeof(ccm_state); break; @@ -3442,8 +3450,7 @@ static int test_evp_iv_aes(int idx) type = EVP_aes_128_ocb(); /* FALLTHROUGH */ case 11: - type = (type != NULL) ? type : - EVP_CIPHER_fetch(testctx, "aes-128-ocb", testpropq); + type = (type != NULL) ? type : EVP_CIPHER_fetch(testctx, "aes-128-ocb", testpropq); ref_iv = ocb_state; ref_len = sizeof(ocb_state); break; @@ -3453,17 +3460,17 @@ static int test_evp_iv_aes(int idx) } if (!TEST_ptr(type) - || !TEST_ptr((ctx = EVP_CIPHER_CTX_new())) - || !TEST_true(EVP_EncryptInit_ex(ctx, type, NULL, key, init_iv)) - || !TEST_true(EVP_EncryptUpdate(ctx, ciphertext, &len, msg, - (int)sizeof(msg))) - || !TEST_true(EVP_CIPHER_CTX_get_original_iv(ctx, oiv, sizeof(oiv))) - || !TEST_true(EVP_CIPHER_CTX_get_updated_iv(ctx, iv, sizeof(iv))) - || !TEST_true(EVP_EncryptFinal_ex(ctx, ciphertext, &len))) + || !TEST_ptr((ctx = EVP_CIPHER_CTX_new())) + || !TEST_true(EVP_EncryptInit_ex(ctx, type, NULL, key, init_iv)) + || !TEST_true(EVP_EncryptUpdate(ctx, ciphertext, &len, msg, + (int)sizeof(msg))) + || !TEST_true(EVP_CIPHER_CTX_get_original_iv(ctx, oiv, sizeof(oiv))) + || !TEST_true(EVP_CIPHER_CTX_get_updated_iv(ctx, iv, sizeof(iv))) + || !TEST_true(EVP_EncryptFinal_ex(ctx, ciphertext, &len))) goto err; ivlen = EVP_CIPHER_CTX_get_iv_length(ctx); if (!TEST_mem_eq(init_iv, ivlen, oiv, ivlen) - || !TEST_mem_eq(ref_iv, ref_len, iv, ivlen)) + || !TEST_mem_eq(ref_iv, ref_len, iv, ivlen)) goto err; /* CBC, OFB, and CFB modes: the updated iv must be reset after reinit */ @@ -3500,7 +3507,7 @@ static int test_evp_iv_des(int idx) 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 }; static const unsigned char msg[] = { 1, 2, 3, 4, 5, 6, 7, 8, - 9, 10, 11, 12, 13, 14, 15, 16 }; + 9, 10, 11, 12, 13, 14, 15, 16 }; unsigned char ciphertext[32], oiv[8], iv[8]; unsigned const char *ref_iv; static const unsigned char cbc_state_des[8] = { @@ -3528,7 +3535,7 @@ static int test_evp_iv_des(int idx) if (lgcyprov == NULL && idx < 3) return TEST_skip("Test requires legacy provider to be loaded"); - switch(idx) { + switch (idx) { case 0: type = EVP_CIPHER_fetch(testctx, "des-cbc", testpropq); ref_iv = cbc_state_des; @@ -3564,17 +3571,17 @@ static int test_evp_iv_des(int idx) } if (!TEST_ptr(type) - || !TEST_ptr((ctx = EVP_CIPHER_CTX_new())) - || !TEST_true(EVP_EncryptInit_ex(ctx, type, NULL, key, init_iv)) - || !TEST_true(EVP_EncryptUpdate(ctx, ciphertext, &len, msg, - (int)sizeof(msg))) - || !TEST_true(EVP_CIPHER_CTX_get_original_iv(ctx, oiv, sizeof(oiv))) - || !TEST_true(EVP_CIPHER_CTX_get_updated_iv(ctx, iv, sizeof(iv))) - || !TEST_true(EVP_EncryptFinal_ex(ctx, ciphertext, &len))) + || !TEST_ptr((ctx = EVP_CIPHER_CTX_new())) + || !TEST_true(EVP_EncryptInit_ex(ctx, type, NULL, key, init_iv)) + || !TEST_true(EVP_EncryptUpdate(ctx, ciphertext, &len, msg, + (int)sizeof(msg))) + || !TEST_true(EVP_CIPHER_CTX_get_original_iv(ctx, oiv, sizeof(oiv))) + || !TEST_true(EVP_CIPHER_CTX_get_updated_iv(ctx, iv, sizeof(iv))) + || !TEST_true(EVP_EncryptFinal_ex(ctx, ciphertext, &len))) goto err; ivlen = EVP_CIPHER_CTX_get_iv_length(ctx); if (!TEST_mem_eq(init_iv, ivlen, oiv, ivlen) - || !TEST_mem_eq(ref_iv, ref_len, iv, ivlen)) + || !TEST_mem_eq(ref_iv, ref_len, iv, ivlen)) goto err; if (!TEST_true(EVP_EncryptInit_ex(ctx, NULL, NULL, NULL, NULL)) @@ -3605,8 +3612,8 @@ static int test_evp_bf_default_keylen(int idx) return TEST_skip("Test requires legacy provider to be loaded"); if (!TEST_ptr(cipher = EVP_CIPHER_fetch(testctx, algos[idx], testpropq)) - || !TEST_int_eq(EVP_CIPHER_get_key_length(cipher), 16) - || !TEST_int_eq(EVP_CIPHER_get_iv_length(cipher), ivlen[idx])) + || !TEST_int_eq(EVP_CIPHER_get_key_length(cipher), 16) + || !TEST_int_eq(EVP_CIPHER_get_iv_length(cipher), ivlen[idx])) goto err; ret = 1; @@ -3620,10 +3627,10 @@ err: static int ecpub_nids[] = { NID_brainpoolP256r1, NID_X9_62_prime256v1, NID_secp384r1, NID_secp521r1, -# ifndef OPENSSL_NO_EC2M +#ifndef OPENSSL_NO_EC2M NID_sect233k1, NID_sect233r1, NID_sect283r1, NID_sect409k1, NID_sect409r1, NID_sect571k1, NID_sect571r1, -# endif +#endif NID_brainpoolP384r1, NID_brainpoolP512r1 }; @@ -3635,11 +3642,11 @@ static int test_ecpub(int idx) unsigned char *p; EVP_PKEY *pkey = NULL; EVP_PKEY_CTX *ctx = NULL; -# ifndef OPENSSL_NO_DEPRECATED_3_0 +#ifndef OPENSSL_NO_DEPRECATED_3_0 const unsigned char *q; EVP_PKEY *pkey2 = NULL; EC_KEY *ec = NULL; -# endif +#endif if (nullprov != NULL) return TEST_skip("Test does not support a non-default library context"); @@ -3660,15 +3667,15 @@ static int test_ecpub(int idx) p = buf; len = i2d_PublicKey(pkey, &p); if (!TEST_int_ge(len, 1) - || !TEST_int_eq(len, savelen)) + || !TEST_int_eq(len, savelen)) goto done; -# ifndef OPENSSL_NO_DEPRECATED_3_0 +#ifndef OPENSSL_NO_DEPRECATED_3_0 /* Now try to decode the just-created DER. */ q = buf; if (!TEST_ptr((pkey2 = EVP_PKEY_new())) - || !TEST_ptr((ec = EC_KEY_new_by_curve_name(nid))) - || !TEST_true(EVP_PKEY_assign_EC_KEY(pkey2, ec))) + || !TEST_ptr((ec = EC_KEY_new_by_curve_name(nid))) + || !TEST_true(EVP_PKEY_assign_EC_KEY(pkey2, ec))) goto done; /* EC_KEY ownership transferred */ ec = NULL; @@ -3677,17 +3684,17 @@ static int test_ecpub(int idx) /* The keys should match. */ if (!TEST_int_eq(EVP_PKEY_eq(pkey, pkey2), 1)) goto done; -# endif +#endif ret = 1; - done: +done: EVP_PKEY_CTX_free(ctx); EVP_PKEY_free(pkey); -# ifndef OPENSSL_NO_DEPRECATED_3_0 +#ifndef OPENSSL_NO_DEPRECATED_3_0 EVP_PKEY_free(pkey2); EC_KEY_free(ec); -# endif +#endif return ret; } #endif @@ -3781,7 +3788,7 @@ static int test_names_do_all(void) goto err; testresult = 1; - err: +err: EVP_MD_free(sha256); OSSL_LIB_CTX_free(ctx); return testresult; @@ -3804,80 +3811,56 @@ typedef struct { } EVP_INIT_TEST_st; static const EVP_INIT_TEST_st evp_init_tests[] = { - { - "aes-128-cfb", kCFBDefaultKey, iCFBIV, cfbPlaintext, + { "aes-128-cfb", kCFBDefaultKey, iCFBIV, cfbPlaintext, cfbCiphertext, NULL, 0, sizeof(cfbPlaintext), sizeof(cfbCiphertext), - 0, 1, 0, 1 - }, - { - "aes-256-gcm", kGCMDefaultKey, iGCMDefaultIV, gcmDefaultPlaintext, + 0, 1, 0, 1 }, + { "aes-256-gcm", kGCMDefaultKey, iGCMDefaultIV, gcmDefaultPlaintext, gcmDefaultCiphertext, gcmDefaultTag, sizeof(iGCMDefaultIV), sizeof(gcmDefaultPlaintext), sizeof(gcmDefaultCiphertext), - sizeof(gcmDefaultTag), 1, 0, 1 - }, - { - "aes-128-cfb", kCFBDefaultKey, iCFBIV, cfbPlaintext, + sizeof(gcmDefaultTag), 1, 0, 1 }, + { "aes-128-cfb", kCFBDefaultKey, iCFBIV, cfbPlaintext, cfbCiphertext, NULL, 0, sizeof(cfbPlaintext), sizeof(cfbCiphertext), - 0, 0, 0, 1 - }, - { - "aes-256-gcm", kGCMDefaultKey, iGCMDefaultIV, gcmDefaultPlaintext, + 0, 0, 0, 1 }, + { "aes-256-gcm", kGCMDefaultKey, iGCMDefaultIV, gcmDefaultPlaintext, gcmDefaultCiphertext, gcmDefaultTag, sizeof(iGCMDefaultIV), sizeof(gcmDefaultPlaintext), sizeof(gcmDefaultCiphertext), - sizeof(gcmDefaultTag), 0, 0, 1 - }, - { - "aes-128-cfb", kCFBDefaultKey, iCFBIV, cfbCiphertext, + sizeof(gcmDefaultTag), 0, 0, 1 }, + { "aes-128-cfb", kCFBDefaultKey, iCFBIV, cfbCiphertext, cfbPlaintext, NULL, 0, sizeof(cfbCiphertext), sizeof(cfbPlaintext), - 0, 1, 1, 0 - }, - { - "aes-256-gcm", kGCMDefaultKey, iGCMDefaultIV, gcmDefaultCiphertext, + 0, 1, 1, 0 }, + { "aes-256-gcm", kGCMDefaultKey, iGCMDefaultIV, gcmDefaultCiphertext, gcmDefaultPlaintext, gcmDefaultTag, sizeof(iGCMDefaultIV), sizeof(gcmDefaultCiphertext), sizeof(gcmDefaultPlaintext), - sizeof(gcmDefaultTag), 1, 1, 0 - }, - { - "aes-128-cfb", kCFBDefaultKey, iCFBIV, cfbCiphertext, + sizeof(gcmDefaultTag), 1, 1, 0 }, + { "aes-128-cfb", kCFBDefaultKey, iCFBIV, cfbCiphertext, cfbPlaintext, NULL, 0, sizeof(cfbCiphertext), sizeof(cfbPlaintext), - 0, 0, 1, 0 - }, - { - "aes-256-gcm", kGCMDefaultKey, iGCMDefaultIV, gcmDefaultCiphertext, + 0, 0, 1, 0 }, + { "aes-256-gcm", kGCMDefaultKey, iGCMDefaultIV, gcmDefaultCiphertext, gcmDefaultPlaintext, gcmDefaultTag, sizeof(iGCMDefaultIV), sizeof(gcmDefaultCiphertext), sizeof(gcmDefaultPlaintext), - sizeof(gcmDefaultTag), 0, 1, 0 - } + sizeof(gcmDefaultTag), 0, 1, 0 } }; /* use same key, iv and plaintext for cfb and ofb */ static const EVP_INIT_TEST_st evp_reinit_tests[] = { - { - "aes-128-cfb", kCFBDefaultKey, iCFBIV, cfbPlaintext_partial, + { "aes-128-cfb", kCFBDefaultKey, iCFBIV, cfbPlaintext_partial, cfbCiphertext_partial, NULL, 0, sizeof(cfbPlaintext_partial), - sizeof(cfbCiphertext_partial), 0, 0, 1, 0 - }, - { - "aes-128-cfb", kCFBDefaultKey, iCFBIV, cfbCiphertext_partial, + sizeof(cfbCiphertext_partial), 0, 0, 1, 0 }, + { "aes-128-cfb", kCFBDefaultKey, iCFBIV, cfbCiphertext_partial, cfbPlaintext_partial, NULL, 0, sizeof(cfbCiphertext_partial), - sizeof(cfbPlaintext_partial), 0, 0, 0, 0 - }, - { - "aes-128-ofb", kCFBDefaultKey, iCFBIV, cfbPlaintext_partial, + sizeof(cfbPlaintext_partial), 0, 0, 0, 0 }, + { "aes-128-ofb", kCFBDefaultKey, iCFBIV, cfbPlaintext_partial, ofbCiphertext_partial, NULL, 0, sizeof(cfbPlaintext_partial), - sizeof(ofbCiphertext_partial), 0, 0, 1, 0 - }, - { - "aes-128-ofb", kCFBDefaultKey, iCFBIV, ofbCiphertext_partial, + sizeof(ofbCiphertext_partial), 0, 0, 1, 0 }, + { "aes-128-ofb", kCFBDefaultKey, iCFBIV, ofbCiphertext_partial, cfbPlaintext_partial, NULL, 0, sizeof(ofbCiphertext_partial), - sizeof(cfbPlaintext_partial), 0, 0, 0, 0 - }, + sizeof(cfbPlaintext_partial), 0, 0, 0, 0 }, }; static int evp_init_seq_set_iv(EVP_CIPHER_CTX *ctx, const EVP_INIT_TEST_st *t) { int res = 0; - + if (t->ivlen != 0) { if (!TEST_int_gt(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_IVLEN, t->ivlen, NULL), 0)) goto err; @@ -3885,7 +3868,7 @@ static int evp_init_seq_set_iv(EVP_CIPHER_CTX *ctx, const EVP_INIT_TEST_st *t) if (!TEST_true(EVP_CipherInit_ex(ctx, NULL, NULL, NULL, t->iv, -1))) goto err; res = 1; - err: +err: return res; } @@ -3931,7 +3914,7 @@ static int test_evp_init_seq(int idx) errmsg = "IV_INIT"; goto err; } - if (t->keyfirst == 0 && !TEST_true(EVP_CipherInit_ex(ctx, NULL, NULL, t->key, NULL, -1))) { + if (t->keyfirst == 0 && !TEST_true(EVP_CipherInit_ex(ctx, NULL, NULL, t->key, NULL, -1))) { errmsg = "KEY_INIT (after iv)"; goto err; } @@ -3946,7 +3929,8 @@ static int test_evp_init_seq(int idx) if (t->finalenc == 0 && t->tag != NULL) { /* Set expected tag */ if (!TEST_int_gt(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG, - t->taglen, (void *)t->tag), 0)) { + t->taglen, (void *)t->tag), + 0)) { errmsg = "SET_TAG"; goto err; } @@ -3970,7 +3954,7 @@ static int test_evp_init_seq(int idx) } } testresult = 1; - err: +err: if (errmsg != NULL) TEST_info("evp_init_test %d: %s", idx, errmsg); EVP_CIPHER_CTX_free(ctx); @@ -3993,24 +3977,24 @@ static int test_evp_reinit_seq(int idx) EVP_CIPHER *type = NULL; if (!TEST_ptr(ctx = EVP_CIPHER_CTX_new()) - || !TEST_ptr(type = EVP_CIPHER_fetch(testctx, t->cipher, testpropq)) - /* setup cipher context */ - || !TEST_true(EVP_CipherInit_ex2(ctx, type, t->key, t->iv, t->initenc, NULL)) - /* first iteration */ - || !TEST_true(EVP_CipherUpdate(ctx, outbuf1, &outlen1, t->input, t->inlen)) - || !TEST_true(EVP_CipherFinal_ex(ctx, outbuf1, &outlen_final)) - /* check test results iteration 1 */ - || !TEST_mem_eq(t->expected, t->expectedlen, outbuf1, outlen1 + outlen_final) - /* now re-init the context (same cipher, key and iv) */ - || !TEST_true(EVP_CipherInit_ex2(ctx, NULL, NULL, NULL, -1, NULL)) - /* second iteration */ - || !TEST_true(EVP_CipherUpdate(ctx, outbuf2, &outlen2, t->input, t->inlen)) - || !TEST_true(EVP_CipherFinal_ex(ctx, outbuf2, &outlen_final)) - /* check test results iteration 2 */ - || !TEST_mem_eq(t->expected, t->expectedlen, outbuf2, outlen2 + outlen_final)) + || !TEST_ptr(type = EVP_CIPHER_fetch(testctx, t->cipher, testpropq)) + /* setup cipher context */ + || !TEST_true(EVP_CipherInit_ex2(ctx, type, t->key, t->iv, t->initenc, NULL)) + /* first iteration */ + || !TEST_true(EVP_CipherUpdate(ctx, outbuf1, &outlen1, t->input, t->inlen)) + || !TEST_true(EVP_CipherFinal_ex(ctx, outbuf1, &outlen_final)) + /* check test results iteration 1 */ + || !TEST_mem_eq(t->expected, t->expectedlen, outbuf1, outlen1 + outlen_final) + /* now re-init the context (same cipher, key and iv) */ + || !TEST_true(EVP_CipherInit_ex2(ctx, NULL, NULL, NULL, -1, NULL)) + /* second iteration */ + || !TEST_true(EVP_CipherUpdate(ctx, outbuf2, &outlen2, t->input, t->inlen)) + || !TEST_true(EVP_CipherFinal_ex(ctx, outbuf2, &outlen_final)) + /* check test results iteration 2 */ + || !TEST_mem_eq(t->expected, t->expectedlen, outbuf2, outlen2 + outlen_final)) goto err; testresult = 1; - err: +err: EVP_CIPHER_CTX_free(ctx); EVP_CIPHER_free(type); return testresult; @@ -4025,14 +4009,10 @@ typedef struct { } EVP_RESET_TEST_st; static const EVP_RESET_TEST_st evp_reset_tests[] = { - { - cfbPlaintext, cfbCiphertext, - sizeof(cfbPlaintext), sizeof(cfbCiphertext), 1 - }, - { - cfbCiphertext, cfbPlaintext, - sizeof(cfbCiphertext), sizeof(cfbPlaintext), 0 - } + { cfbPlaintext, cfbCiphertext, + sizeof(cfbPlaintext), sizeof(cfbCiphertext), 1 }, + { cfbCiphertext, cfbPlaintext, + sizeof(cfbCiphertext), sizeof(cfbPlaintext), 0 } }; /* @@ -4094,7 +4074,7 @@ static int test_evp_reset(int idx) goto err; } testresult = 1; - err: +err: if (errmsg != NULL) TEST_info("test_evp_reset %d: %s", idx, errmsg); EVP_CIPHER_CTX_free(ctx); @@ -4108,42 +4088,18 @@ typedef struct { } EVP_UPDATED_IV_TEST_st; static const EVP_UPDATED_IV_TEST_st evp_updated_iv_tests[] = { - { - "aes-128-cfb", 1 - }, - { - "aes-128-cfb", 0 - }, - { - "aes-128-cfb1", 1 - }, - { - "aes-128-cfb1", 0 - }, - { - "aes-128-cfb8", 1 - }, - { - "aes-128-cfb8", 0 - }, - { - "aes-128-ofb", 1 - }, - { - "aes-128-ofb", 0 - }, - { - "aes-128-ctr", 1 - }, - { - "aes-128-ctr", 0 - }, - { - "aes-128-cbc", 1 - }, - { - "aes-128-cbc", 0 - } + { "aes-128-cfb", 1 }, + { "aes-128-cfb", 0 }, + { "aes-128-cfb1", 1 }, + { "aes-128-cfb1", 0 }, + { "aes-128-cfb8", 1 }, + { "aes-128-cfb8", 0 }, + { "aes-128-ofb", 1 }, + { "aes-128-ofb", 0 }, + { "aes-128-ctr", 1 }, + { "aes-128-ctr", 0 }, + { "aes-128-cbc", 1 }, + { "aes-128-cbc", 0 } }; /* @@ -4199,9 +4155,9 @@ static int test_evp_updated_iv(int idx) errmsg = "CIPHER_FINAL"; goto err; } - ok: +ok: testresult = 1; - err: +err: if (errmsg != NULL) TEST_info("test_evp_updated_iv %d: %s", idx, errmsg); EVP_CIPHER_CTX_free(ctx); @@ -4223,16 +4179,12 @@ typedef struct { } TEST_GCM_IV_REINIT_st; static const TEST_GCM_IV_REINIT_st gcm_reinit_tests[] = { - { - iGCMResetIV1, iGCMResetIV2, gcmResetCiphertext1, gcmResetCiphertext2, + { iGCMResetIV1, iGCMResetIV2, gcmResetCiphertext1, gcmResetCiphertext2, gcmResetTag1, gcmResetTag2, sizeof(iGCMResetIV1), sizeof(iGCMResetIV2), - sizeof(gcmResetCiphertext1), sizeof(gcmResetCiphertext2) - }, - { - iGCMResetIV2, iGCMResetIV1, gcmResetCiphertext2, gcmResetCiphertext1, + sizeof(gcmResetCiphertext1), sizeof(gcmResetCiphertext2) }, + { iGCMResetIV2, iGCMResetIV1, gcmResetCiphertext2, gcmResetCiphertext1, gcmResetTag2, gcmResetTag1, sizeof(iGCMResetIV2), sizeof(iGCMResetIV1), - sizeof(gcmResetCiphertext2), sizeof(gcmResetCiphertext1) - } + sizeof(gcmResetCiphertext2), sizeof(gcmResetCiphertext1) } }; static int test_gcm_reinit(int idx) @@ -4273,7 +4225,7 @@ static int test_gcm_reinit(int idx) } EVP_CIPHER_CTX_set_padding(ctx, 0); if (!TEST_true(EVP_CipherUpdate(ctx, outbuf, &outlen1, gcmResetPlaintext, - sizeof(gcmResetPlaintext)))) { + sizeof(gcmResetPlaintext)))) { errmsg = "CIPHER_UPDATE1"; goto err; } @@ -4307,7 +4259,7 @@ static int test_gcm_reinit(int idx) goto err; } if (!TEST_true(EVP_CipherUpdate(ctx, outbuf, &outlen1, gcmResetPlaintext, - sizeof(gcmResetPlaintext)))) { + sizeof(gcmResetPlaintext)))) { errmsg = "CIPHER_UPDATE2"; goto err; } @@ -4328,7 +4280,7 @@ static int test_gcm_reinit(int idx) goto err; } testresult = 1; - err: +err: if (errmsg != NULL) TEST_info("evp_init_test %d: %s", idx, errmsg); EVP_CIPHER_CTX_free(ctx); @@ -4351,8 +4303,8 @@ static int test_ivlen_change(int idx) int res = 0; unsigned char outbuf[1024]; static const unsigned char iv[] = { - 0x57, 0x71, 0x7d, 0xad, 0xdb, 0x9b, 0x98, 0x82, - 0x5a, 0x55, 0x91, 0x81, 0x42, 0xa8, 0x89, 0x34 + 0x57, 0x71, 0x7d, 0xad, 0xdb, 0x9b, 0x98, 0x82, + 0x5a, 0x55, 0x91, 0x81, 0x42, 0xa8, 0x89, 0x34 }; EVP_CIPHER_CTX *ctx = NULL; EVP_CIPHER *ciph = NULL; @@ -4363,31 +4315,31 @@ static int test_ivlen_change(int idx) goto err; if (!TEST_ptr(ciph = EVP_CIPHER_fetch(testctx, ivlen_change_ciphers[idx], - testpropq))) + testpropq))) goto err; if (!TEST_true(EVP_CipherInit_ex(ctx, ciph, NULL, kGCMDefaultKey, iv, 1))) goto err; if (!TEST_true(EVP_CipherUpdate(ctx, outbuf, &outlen, gcmDefaultPlaintext, - sizeof(gcmDefaultPlaintext)))) + sizeof(gcmDefaultPlaintext)))) goto err; params[0] = OSSL_PARAM_construct_size_t(OSSL_CIPHER_PARAM_AEAD_IVLEN, - &ivlen); + &ivlen); if (!TEST_true(EVP_CIPHER_CTX_set_params(ctx, params))) goto err; ERR_set_mark(); if (!TEST_false(EVP_CipherUpdate(ctx, outbuf, &outlen, gcmDefaultPlaintext, - sizeof(gcmDefaultPlaintext)))) { + sizeof(gcmDefaultPlaintext)))) { ERR_clear_last_mark(); goto err; } ERR_pop_to_mark(); res = 1; - err: +err: EVP_CIPHER_CTX_free(ctx); EVP_CIPHER_free(ciph); return res; @@ -4419,8 +4371,8 @@ static int test_keylen_change(int idx) int res = 0; unsigned char outbuf[1024]; static const unsigned char key[] = { - 0x57, 0x71, 0x7d, 0xad, 0xdb, 0x9b, 0x98, 0x82, - 0x5a, 0x55, 0x91, 0x81, 0x42, 0xa8, 0x89, 0x34 + 0x57, 0x71, 0x7d, 0xad, 0xdb, 0x9b, 0x98, 0x82, + 0x5a, 0x55, 0x91, 0x81, 0x42, 0xa8, 0x89, 0x34 }; EVP_CIPHER_CTX *ctx = NULL; EVP_CIPHER *ciph = NULL; @@ -4434,41 +4386,41 @@ static int test_keylen_change(int idx) goto err; if (!TEST_ptr(ciph = EVP_CIPHER_fetch(testctx, keylen_change_ciphers[idx], - testpropq))) + testpropq))) goto err; if (!TEST_true(EVP_CipherInit_ex(ctx, ciph, NULL, key, NULL, 1))) goto err; if (!TEST_true(EVP_CipherUpdate(ctx, outbuf, &outlen, gcmDefaultPlaintext, - sizeof(gcmDefaultPlaintext)))) + sizeof(gcmDefaultPlaintext)))) goto err; params[0] = OSSL_PARAM_construct_size_t(OSSL_CIPHER_PARAM_KEYLEN, - &keylen); + &keylen); if (!TEST_true(EVP_CIPHER_CTX_set_params(ctx, params))) goto err; ERR_set_mark(); if (!TEST_false(EVP_CipherUpdate(ctx, outbuf, &outlen, gcmDefaultPlaintext, - sizeof(gcmDefaultPlaintext)))) { + sizeof(gcmDefaultPlaintext)))) { ERR_clear_last_mark(); goto err; } ERR_pop_to_mark(); res = 1; - err: +err: EVP_CIPHER_CTX_free(ctx); EVP_CIPHER_free(ciph); return res; } #ifndef OPENSSL_NO_DEPRECATED_3_0 -static EVP_PKEY_METHOD *custom_pmeth = NULL; +static EVP_PKEY_METHOD *custom_pmeth = NULL; static const EVP_PKEY_METHOD *orig_pmeth = NULL; -# define EVP_PKEY_CTRL_MY_COMMAND 9999 +#define EVP_PKEY_CTRL_MY_COMMAND 9999 static int custom_pmeth_init(EVP_PKEY_CTX *ctx) { @@ -4487,29 +4439,29 @@ static void custom_pmeth_cleanup(EVP_PKEY_CTX *ctx) } static int custom_pmeth_sign(EVP_PKEY_CTX *ctx, unsigned char *out, - size_t *outlen, const unsigned char *in, - size_t inlen) + size_t *outlen, const unsigned char *in, + size_t inlen) { int (*psign)(EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen, - const unsigned char *tbs, size_t tbslen); + const unsigned char *tbs, size_t tbslen); EVP_PKEY_meth_get_sign(orig_pmeth, NULL, &psign); return psign(ctx, out, outlen, in, inlen); } static int custom_pmeth_digestsign(EVP_MD_CTX *ctx, unsigned char *sig, - size_t *siglen, const unsigned char *tbs, - size_t tbslen) + size_t *siglen, const unsigned char *tbs, + size_t tbslen) { int (*pdigestsign)(EVP_MD_CTX *ctx, unsigned char *sig, size_t *siglen, - const unsigned char *tbs, size_t tbslen); + const unsigned char *tbs, size_t tbslen); EVP_PKEY_meth_get_digestsign(orig_pmeth, &pdigestsign); return pdigestsign(ctx, sig, siglen, tbs, tbslen); } static int custom_pmeth_derive(EVP_PKEY_CTX *ctx, unsigned char *key, - size_t *keylen) + size_t *keylen) { int (*pderive)(EVP_PKEY_CTX *ctx, unsigned char *key, size_t *keylen); @@ -4560,7 +4512,7 @@ static int test_custom_pmeth(int idx) if (testctx != NULL) return 1; - switch(idx) { + switch (idx) { case 0: case 6: id = EVP_PKEY_RSA; @@ -4568,52 +4520,52 @@ static int test_custom_pmeth(int idx) break; case 1: case 7: -# ifndef OPENSSL_NO_DSA +#ifndef OPENSSL_NO_DSA id = EVP_PKEY_DSA; pkey = load_example_dsa_key(); break; -# else +#else return 1; -# endif +#endif case 2: case 8: -# ifndef OPENSSL_NO_EC +#ifndef OPENSSL_NO_EC id = EVP_PKEY_EC; pkey = load_example_ec_key(); break; -# else +#else return 1; -# endif +#endif case 3: case 9: -# ifndef OPENSSL_NO_EC +#ifndef OPENSSL_NO_EC id = EVP_PKEY_ED25519; md = NULL; pkey = load_example_ed25519_key(); break; -# else +#else return 1; -# endif +#endif case 4: case 10: -# ifndef OPENSSL_NO_DH +#ifndef OPENSSL_NO_DH id = EVP_PKEY_DH; doderive = 1; pkey = load_example_dh_key(); break; -# else +#else return 1; -# endif +#endif case 5: case 11: -# ifndef OPENSSL_NO_EC +#ifndef OPENSSL_NO_EC id = EVP_PKEY_X25519; doderive = 1; pkey = load_example_x25519_key(); break; -# else +#else return 1; -# endif +#endif default: TEST_error("Should not happen"); goto err; @@ -4644,17 +4596,18 @@ static int test_custom_pmeth(int idx) } if (!TEST_ptr(orig_pmeth = EVP_PKEY_meth_find(id)) - || !TEST_ptr(pkey)) + || !TEST_ptr(pkey)) goto err; EVP_PKEY_meth_get0_info(&orig_id, &orig_flags, orig_pmeth); if (!TEST_int_eq(orig_id, id) - || !TEST_ptr(custom_pmeth = EVP_PKEY_meth_new(id, orig_flags))) + || !TEST_ptr(custom_pmeth = EVP_PKEY_meth_new(id, orig_flags))) goto err; if (id == EVP_PKEY_ED25519) { EVP_PKEY_meth_set_digestsign(custom_pmeth, custom_pmeth_digestsign); - } if (id == EVP_PKEY_DH || id == EVP_PKEY_X25519) { + } + if (id == EVP_PKEY_DH || id == EVP_PKEY_X25519) { EVP_PKEY_meth_set_derive(custom_pmeth, NULL, custom_pmeth_derive); } else { EVP_PKEY_meth_set_sign(custom_pmeth, NULL, custom_pmeth_sign); @@ -4671,27 +4624,27 @@ static int test_custom_pmeth(int idx) if (doderive) { pctx = EVP_PKEY_CTX_new(pkey, NULL); if (!TEST_ptr(pctx) - || !TEST_int_eq(EVP_PKEY_derive_init(pctx), 1) - || !TEST_int_ge(EVP_PKEY_CTX_ctrl(pctx, -1, -1, - EVP_PKEY_CTRL_MY_COMMAND, 0, NULL), - 1) - || !TEST_int_eq(ctrl_called, 1) - || !TEST_int_ge(EVP_PKEY_derive_set_peer(pctx, pkey), 1) - || !TEST_int_ge(EVP_PKEY_derive(pctx, NULL, &reslen), 1) - || !TEST_ptr(res = OPENSSL_malloc(reslen)) - || !TEST_int_ge(EVP_PKEY_derive(pctx, res, &reslen), 1)) + || !TEST_int_eq(EVP_PKEY_derive_init(pctx), 1) + || !TEST_int_ge(EVP_PKEY_CTX_ctrl(pctx, -1, -1, + EVP_PKEY_CTRL_MY_COMMAND, 0, NULL), + 1) + || !TEST_int_eq(ctrl_called, 1) + || !TEST_int_ge(EVP_PKEY_derive_set_peer(pctx, pkey), 1) + || !TEST_int_ge(EVP_PKEY_derive(pctx, NULL, &reslen), 1) + || !TEST_ptr(res = OPENSSL_malloc(reslen)) + || !TEST_int_ge(EVP_PKEY_derive(pctx, res, &reslen), 1)) goto err; } else { ctx = EVP_MD_CTX_new(); reslen = EVP_PKEY_size(pkey); res = OPENSSL_malloc(reslen); if (!TEST_ptr(ctx) - || !TEST_ptr(res) - || !TEST_true(EVP_DigestSignInit(ctx, &pctx, md, NULL, pkey)) - || !TEST_int_ge(EVP_PKEY_CTX_ctrl(pctx, -1, -1, - EVP_PKEY_CTRL_MY_COMMAND, 0, NULL), - 1) - || !TEST_int_eq(ctrl_called, 1)) + || !TEST_ptr(res) + || !TEST_true(EVP_DigestSignInit(ctx, &pctx, md, NULL, pkey)) + || !TEST_int_ge(EVP_PKEY_CTX_ctrl(pctx, -1, -1, + EVP_PKEY_CTRL_MY_COMMAND, 0, NULL), + 1) + || !TEST_int_eq(ctrl_called, 1)) goto err; if (id == EVP_PKEY_ED25519) { @@ -4699,13 +4652,13 @@ static int test_custom_pmeth(int idx) goto err; } else { if (!TEST_true(EVP_DigestUpdate(ctx, msg, sizeof(msg))) - || !TEST_true(EVP_DigestSignFinal(ctx, res, &reslen))) + || !TEST_true(EVP_DigestSignFinal(ctx, res, &reslen))) goto err; } } testresult = 1; - err: +err: OPENSSL_free(res); EVP_MD_CTX_free(ctx); if (doderive) @@ -4728,7 +4681,7 @@ static int test_evp_md_cipher_meth(void) testresult = 1; - err: +err: EVP_MD_meth_free(md); EVP_CIPHER_meth_free(ciph); @@ -4736,7 +4689,7 @@ static int test_evp_md_cipher_meth(void) } typedef struct { - int data; + int data; } custom_dgst_ctx; static int custom_md_init_called = 0; @@ -4792,42 +4745,42 @@ static int test_custom_md_meth(void) goto err; if (!TEST_true(EVP_MD_meth_set_init(tmp, custom_md_init)) - || !TEST_true(EVP_MD_meth_set_cleanup(tmp, custom_md_cleanup)) - || !TEST_true(EVP_MD_meth_set_app_datasize(tmp, - sizeof(custom_dgst_ctx)))) + || !TEST_true(EVP_MD_meth_set_cleanup(tmp, custom_md_cleanup)) + || !TEST_true(EVP_MD_meth_set_app_datasize(tmp, + sizeof(custom_dgst_ctx)))) goto err; mdctx = EVP_MD_CTX_new(); if (!TEST_ptr(mdctx) - /* - * Initing our custom md and then initing another md should - * result in the init and cleanup functions of the custom md - * being called. - */ - || !TEST_true(EVP_DigestInit_ex(mdctx, tmp, NULL)) - || !TEST_true(EVP_DigestInit_ex(mdctx, EVP_sha256(), NULL)) - || !TEST_true(EVP_DigestUpdate(mdctx, mess, strlen(mess))) - || !TEST_true(EVP_DigestFinal_ex(mdctx, md_value, &md_len)) - || !TEST_int_eq(custom_md_init_called, 1) - || !TEST_int_eq(custom_md_cleanup_called, 1)) + /* + * Initing our custom md and then initing another md should + * result in the init and cleanup functions of the custom md + * being called. + */ + || !TEST_true(EVP_DigestInit_ex(mdctx, tmp, NULL)) + || !TEST_true(EVP_DigestInit_ex(mdctx, EVP_sha256(), NULL)) + || !TEST_true(EVP_DigestUpdate(mdctx, mess, strlen(mess))) + || !TEST_true(EVP_DigestFinal_ex(mdctx, md_value, &md_len)) + || !TEST_int_eq(custom_md_init_called, 1) + || !TEST_int_eq(custom_md_cleanup_called, 1)) goto err; testresult = 1; - err: +err: EVP_MD_CTX_free(mdctx); EVP_MD_meth_free(tmp); return testresult; } typedef struct { - int data; + int data; } custom_ciph_ctx; static int custom_ciph_init_called = 0; static int custom_ciph_cleanup_called = 0; static int custom_ciph_init(EVP_CIPHER_CTX *ctx, const unsigned char *key, - const unsigned char *iv, int enc) + const unsigned char *iv, int enc) { custom_ciph_ctx *p = EVP_CIPHER_CTX_get_cipher_data(ctx); @@ -4874,34 +4827,34 @@ static int test_custom_ciph_meth(void) goto err; if (!TEST_true(EVP_CIPHER_meth_set_init(tmp, custom_ciph_init)) - || !TEST_true(EVP_CIPHER_meth_set_flags(tmp, EVP_CIPH_ALWAYS_CALL_INIT)) - || !TEST_true(EVP_CIPHER_meth_set_cleanup(tmp, custom_ciph_cleanup)) - || !TEST_true(EVP_CIPHER_meth_set_impl_ctx_size(tmp, - sizeof(custom_ciph_ctx)))) + || !TEST_true(EVP_CIPHER_meth_set_flags(tmp, EVP_CIPH_ALWAYS_CALL_INIT)) + || !TEST_true(EVP_CIPHER_meth_set_cleanup(tmp, custom_ciph_cleanup)) + || !TEST_true(EVP_CIPHER_meth_set_impl_ctx_size(tmp, + sizeof(custom_ciph_ctx)))) goto err; ciphctx = EVP_CIPHER_CTX_new(); if (!TEST_ptr(ciphctx) - /* - * Initing our custom cipher and then initing another cipher - * should result in the init and cleanup functions of the custom - * cipher being called. - */ - || !TEST_true(EVP_CipherInit_ex(ciphctx, tmp, NULL, NULL, NULL, 1)) - || !TEST_true(EVP_CipherInit_ex(ciphctx, EVP_aes_128_cbc(), NULL, - NULL, NULL, 1)) - || !TEST_int_eq(custom_ciph_init_called, 1) - || !TEST_int_eq(custom_ciph_cleanup_called, 1)) + /* + * Initing our custom cipher and then initing another cipher + * should result in the init and cleanup functions of the custom + * cipher being called. + */ + || !TEST_true(EVP_CipherInit_ex(ciphctx, tmp, NULL, NULL, NULL, 1)) + || !TEST_true(EVP_CipherInit_ex(ciphctx, EVP_aes_128_cbc(), NULL, + NULL, NULL, 1)) + || !TEST_int_eq(custom_ciph_init_called, 1) + || !TEST_int_eq(custom_ciph_cleanup_called, 1)) goto err; testresult = 1; - err: +err: EVP_CIPHER_CTX_free(ciphctx); EVP_CIPHER_meth_free(tmp); return testresult; } -# ifndef OPENSSL_NO_DYNAMIC_ENGINE +#ifndef OPENSSL_NO_DYNAMIC_ENGINE /* Test we can create a signature keys with an associated ENGINE */ static int test_signatures_with_engine(int tst) { @@ -4925,11 +4878,11 @@ static int test_signatures_with_engine(int tst) size_t maclen = 0; int ret; -# ifdef OPENSSL_NO_CMAC +#ifdef OPENSSL_NO_CMAC /* Skip CMAC tests in a no-cmac build */ if (tst <= 1) return 1; -# endif +#endif if (!TEST_ptr(e = ENGINE_by_id(engine_id))) return 0; @@ -4942,15 +4895,15 @@ static int test_signatures_with_engine(int tst) switch (tst) { case 0: pkey = EVP_PKEY_new_CMAC_key(e, cmackey, sizeof(cmackey), - EVP_aes_128_cbc()); + EVP_aes_128_cbc()); break; case 1: pkey = EVP_PKEY_new_CMAC_key(e, badcmackey, sizeof(badcmackey), - EVP_aes_128_cbc()); + EVP_aes_128_cbc()); break; case 2: pkey = EVP_PKEY_new_raw_private_key(EVP_PKEY_ED25519, e, ed25519key, - sizeof(ed25519key)); + sizeof(ed25519key)); break; default: TEST_error("Invalid test case"); @@ -4963,13 +4916,13 @@ static int test_signatures_with_engine(int tst) goto err; ret = EVP_DigestSignInit(ctx, NULL, tst == 2 ? NULL : EVP_sha256(), NULL, - pkey); + pkey); if (tst == 0) { if (!TEST_true(ret)) goto err; if (!TEST_true(EVP_DigestSignUpdate(ctx, msg, sizeof(msg))) - || !TEST_true(EVP_DigestSignFinal(ctx, NULL, &maclen))) + || !TEST_true(EVP_DigestSignFinal(ctx, NULL, &maclen))) goto err; if (!TEST_ptr(mac = OPENSSL_malloc(maclen))) @@ -4984,7 +4937,7 @@ static int test_signatures_with_engine(int tst) } testresult = 1; - err: +err: EVP_MD_CTX_free(ctx); OPENSSL_free(mac); EVP_PKEY_free(pkey); @@ -5017,7 +4970,7 @@ static int test_cipher_with_engine(void) } if (!TEST_ptr(ctx = EVP_CIPHER_CTX_new()) - || !TEST_ptr(ctx2 = EVP_CIPHER_CTX_new())) + || !TEST_ptr(ctx2 = EVP_CIPHER_CTX_new())) goto err; if (!TEST_true(EVP_EncryptInit_ex(ctx, EVP_aes_128_cbc(), e, keyiv, keyiv))) @@ -5028,11 +4981,11 @@ static int test_cipher_with_engine(void) goto err; if (!TEST_true(EVP_EncryptUpdate(ctx2, buf, &len, msg, sizeof(msg))) - || !TEST_true(EVP_EncryptFinal_ex(ctx2, buf + len, &len))) + || !TEST_true(EVP_EncryptFinal_ex(ctx2, buf + len, &len))) goto err; testresult = 1; - err: +err: EVP_CIPHER_CTX_free(ctx); EVP_CIPHER_CTX_free(ctx2); ENGINE_finish(e); @@ -5040,7 +4993,7 @@ static int test_cipher_with_engine(void) return testresult; } -# endif /* OPENSSL_NO_DYNAMIC_ENGINE */ +#endif /* OPENSSL_NO_DYNAMIC_ENGINE */ #endif /* OPENSSL_NO_DEPRECATED_3_0 */ static int ecxnids[] = { @@ -5056,9 +5009,8 @@ static int test_ecx_short_keys(int tst) unsigned char ecxkeydata = 1; EVP_PKEY *pkey; - pkey = EVP_PKEY_new_raw_private_key_ex(testctx, OBJ_nid2sn(ecxnids[tst]), - NULL, &ecxkeydata, 1); + NULL, &ecxkeydata, 1); if (!TEST_ptr_null(pkey)) { EVP_PKEY_free(pkey); return 0; @@ -5112,7 +5064,7 @@ static int test_ecx_not_private_key(int tst) pubkeylen = strlen(keys[tst].pub); pkey = EVP_PKEY_new_raw_public_key_ex(testctx, OBJ_nid2sn(keys[tst].type), - NULL, pubkey, pubkeylen); + NULL, pubkey, pubkeylen); if (!TEST_ptr(pkey)) goto err; @@ -5131,7 +5083,7 @@ static int test_ecx_not_private_key(int tst) if (!TEST_int_eq(EVP_DigestSign(ctx, mac, &maclen, msg, sizeof(msg)), 0)) goto err; - check_err: +check_err: /* * Currently only EVP_DigestSign will throw PROV_R_NOT_A_PRIVATE_KEY, * but we relax the check to allow error also thrown by @@ -5142,7 +5094,7 @@ static int test_ecx_not_private_key(int tst) ERR_clear_error(); } - err: +err: EVP_MD_CTX_free(ctx); OPENSSL_free(mac); EVP_PKEY_free(pkey); @@ -5152,11 +5104,11 @@ static int test_ecx_not_private_key(int tst) #endif /* OPENSSL_NO_EC */ static int aes_gcm_encrypt(const unsigned char *gcm_key, size_t gcm_key_s, - const unsigned char *gcm_iv, size_t gcm_ivlen, - const unsigned char *gcm_pt, size_t gcm_pt_s, - const unsigned char *gcm_aad, size_t gcm_aad_s, - const unsigned char *gcm_ct, size_t gcm_ct_s, - const unsigned char *gcm_tag, size_t gcm_tag_s) + const unsigned char *gcm_iv, size_t gcm_ivlen, + const unsigned char *gcm_pt, size_t gcm_pt_s, + const unsigned char *gcm_aad, size_t gcm_aad_s, + const unsigned char *gcm_ct, size_t gcm_ct_s, + const unsigned char *gcm_tag, size_t gcm_tag_s) { int ret = 0; EVP_CIPHER_CTX *ctx; @@ -5169,27 +5121,27 @@ static int aes_gcm_encrypt(const unsigned char *gcm_key, size_t gcm_key_s, }; if (!TEST_ptr(ctx = EVP_CIPHER_CTX_new()) - || !TEST_ptr(cipher = EVP_CIPHER_fetch(testctx, "AES-256-GCM", ""))) + || !TEST_ptr(cipher = EVP_CIPHER_fetch(testctx, "AES-256-GCM", ""))) goto err; params[0] = OSSL_PARAM_construct_size_t(OSSL_CIPHER_PARAM_AEAD_IVLEN, - &gcm_ivlen); + &gcm_ivlen); if (!TEST_true(EVP_EncryptInit_ex2(ctx, cipher, gcm_key, gcm_iv, params)) - || (gcm_aad != NULL - && !TEST_true(EVP_EncryptUpdate(ctx, NULL, &outlen, - gcm_aad, gcm_aad_s))) - || !TEST_true(EVP_EncryptUpdate(ctx, outbuf, &outlen, - gcm_pt, gcm_pt_s)) - || !TEST_true(EVP_EncryptFinal_ex(ctx, outbuf, &tmplen))) + || (gcm_aad != NULL + && !TEST_true(EVP_EncryptUpdate(ctx, NULL, &outlen, + gcm_aad, gcm_aad_s))) + || !TEST_true(EVP_EncryptUpdate(ctx, outbuf, &outlen, + gcm_pt, gcm_pt_s)) + || !TEST_true(EVP_EncryptFinal_ex(ctx, outbuf, &tmplen))) goto err; params[0] = OSSL_PARAM_construct_octet_string(OSSL_CIPHER_PARAM_AEAD_TAG, - outtag, sizeof(outtag)); + outtag, sizeof(outtag)); if (!TEST_true(EVP_CIPHER_CTX_get_params(ctx, params)) - || !TEST_mem_eq(outbuf, outlen, gcm_ct, gcm_ct_s) - || !TEST_mem_eq(outtag, gcm_tag_s, gcm_tag, gcm_tag_s)) + || !TEST_mem_eq(outbuf, outlen, gcm_ct, gcm_ct_s) + || !TEST_mem_eq(outtag, gcm_tag_s, gcm_tag, gcm_tag_s)) goto err; ret = 1; @@ -5201,11 +5153,11 @@ err: } static int aes_gcm_decrypt(const unsigned char *gcm_key, size_t gcm_key_s, - const unsigned char *gcm_iv, size_t gcm_ivlen, - const unsigned char *gcm_pt, size_t gcm_pt_s, - const unsigned char *gcm_aad, size_t gcm_aad_s, - const unsigned char *gcm_ct, size_t gcm_ct_s, - const unsigned char *gcm_tag, size_t gcm_tag_s) + const unsigned char *gcm_iv, size_t gcm_ivlen, + const unsigned char *gcm_pt, size_t gcm_pt_s, + const unsigned char *gcm_aad, size_t gcm_aad_s, + const unsigned char *gcm_ct, size_t gcm_ct_s, + const unsigned char *gcm_tag, size_t gcm_tag_s) { int ret = 0; EVP_CIPHER_CTX *ctx; @@ -5223,22 +5175,22 @@ static int aes_gcm_decrypt(const unsigned char *gcm_key, size_t gcm_key_s, goto err; params[0] = OSSL_PARAM_construct_size_t(OSSL_CIPHER_PARAM_AEAD_IVLEN, - &gcm_ivlen); + &gcm_ivlen); if (!TEST_true(EVP_DecryptInit_ex2(ctx, cipher, gcm_key, gcm_iv, params)) - || (gcm_aad != NULL - && !TEST_true(EVP_DecryptUpdate(ctx, NULL, &outlen, - gcm_aad, gcm_aad_s))) - || !TEST_true(EVP_DecryptUpdate(ctx, outbuf, &outlen, - gcm_ct, gcm_ct_s)) - || !TEST_mem_eq(outbuf, outlen, gcm_pt, gcm_pt_s)) + || (gcm_aad != NULL + && !TEST_true(EVP_DecryptUpdate(ctx, NULL, &outlen, + gcm_aad, gcm_aad_s))) + || !TEST_true(EVP_DecryptUpdate(ctx, outbuf, &outlen, + gcm_ct, gcm_ct_s)) + || !TEST_mem_eq(outbuf, outlen, gcm_pt, gcm_pt_s)) goto err; params[0] = OSSL_PARAM_construct_octet_string(OSSL_CIPHER_PARAM_AEAD_TAG, - (void*)gcm_tag, gcm_tag_s); + (void *)gcm_tag, gcm_tag_s); if (!TEST_true(EVP_CIPHER_CTX_set_params(ctx, params)) - ||!TEST_true(EVP_DecryptFinal_ex(ctx, outbuf, &outlen))) + || !TEST_true(EVP_DecryptFinal_ex(ctx, outbuf, &outlen))) goto err; ret = 1; @@ -5255,7 +5207,7 @@ static int test_aes_gcm_ivlen_change_cve_2023_5363(void) static const unsigned char gcm_key[] = { 0xd0, 0xc2, 0x67, 0xc1, 0x9f, 0x30, 0xd8, 0x0b, 0x89, 0x14, 0xbb, 0xbf, 0xb7, 0x2f, 0x73, 0xb8, 0xd3, 0xcd, 0x5f, 0x6a, 0x78, 0x70, 0x15, 0x84, - 0x8a, 0x7b, 0x30, 0xe3, 0x8f, 0x16, 0xf1, 0x8b, + 0x8a, 0x7b, 0x30, 0xe3, 0x8f, 0x16, 0xf1, 0x8b }; static const unsigned char gcm_iv[] = { 0xb6, 0xdc, 0xda, 0x95, 0xac, 0x99, 0x77, 0x76, 0x25, 0xae, 0x87, 0xf8, @@ -5268,33 +5220,33 @@ static int test_aes_gcm_ivlen_change_cve_2023_5363(void) 0x95, 0x90, 0xac, 0x7b, 0x1f, 0x7b, 0xa0, 0x99, 0xe1, 0xf3, 0x48, 0x54, 0xd0, 0xfc, 0xa9, 0xcc, 0x91, 0xf8, 0x1f, 0x9b, 0x6c, 0x9a, 0xe0, 0xdc, 0x63, 0xea, 0x7d, 0x2a, 0x4a, 0x7d, 0xa5, 0xed, 0x68, 0x57, 0x27, 0x6b, - 0x68, 0xe0, 0xf2, 0xb8, 0x51, 0x50, 0x8d, 0x3d, + 0x68, 0xe0, 0xf2, 0xb8, 0x51, 0x50, 0x8d, 0x3d }; static const unsigned char gcm_pt[] = { 0xb8, 0xb6, 0x88, 0x36, 0x44, 0xe2, 0x34, 0xdf, 0x24, 0x32, 0x91, 0x07, - 0x4f, 0xe3, 0x6f, 0x81, + 0x4f, 0xe3, 0x6f, 0x81 }; static const unsigned char gcm_ct[] = { 0xff, 0x4f, 0xb3, 0xf3, 0xf9, 0xa2, 0x51, 0xd4, 0x82, 0xc2, 0xbe, 0xf3, - 0xe2, 0xd0, 0xec, 0xed, + 0xe2, 0xd0, 0xec, 0xed }; static const unsigned char gcm_tag[] = { 0xbd, 0x06, 0x38, 0x09, 0xf7, 0xe1, 0xc4, 0x72, 0x0e, 0xf2, 0xea, 0x63, - 0xdb, 0x99, 0x6c, 0x21, + 0xdb, 0x99, 0x6c, 0x21 }; return aes_gcm_encrypt(gcm_key, sizeof(gcm_key), gcm_iv, sizeof(gcm_iv), - gcm_pt, sizeof(gcm_pt), NULL, 0, - gcm_ct, sizeof(gcm_ct), gcm_tag, sizeof(gcm_tag)) + gcm_pt, sizeof(gcm_pt), NULL, 0, + gcm_ct, sizeof(gcm_ct), gcm_tag, sizeof(gcm_tag)) && aes_gcm_decrypt(gcm_key, sizeof(gcm_key), gcm_iv, sizeof(gcm_iv), - gcm_pt, sizeof(gcm_pt), NULL, 0, - gcm_ct, sizeof(gcm_ct), gcm_tag, sizeof(gcm_tag)); + gcm_pt, sizeof(gcm_pt), NULL, 0, + gcm_ct, sizeof(gcm_ct), gcm_tag, sizeof(gcm_tag)); } #ifndef OPENSSL_NO_RC4 static int rc4_encrypt(const unsigned char *rc4_key, size_t rc4_key_s, - const unsigned char *rc4_pt, size_t rc4_pt_s, - const unsigned char *rc4_ct, size_t rc4_ct_s) + const unsigned char *rc4_pt, size_t rc4_pt_s, + const unsigned char *rc4_ct, size_t rc4_ct_s) { int ret = 0; EVP_CIPHER_CTX *ctx; @@ -5306,16 +5258,16 @@ static int rc4_encrypt(const unsigned char *rc4_key, size_t rc4_key_s, }; if (!TEST_ptr(ctx = EVP_CIPHER_CTX_new()) - || !TEST_ptr(cipher = EVP_CIPHER_fetch(testctx, "RC4", ""))) + || !TEST_ptr(cipher = EVP_CIPHER_fetch(testctx, "RC4", ""))) goto err; params[0] = OSSL_PARAM_construct_size_t(OSSL_CIPHER_PARAM_KEYLEN, - &rc4_key_s); + &rc4_key_s); if (!TEST_true(EVP_EncryptInit_ex2(ctx, cipher, rc4_key, NULL, params)) - || !TEST_true(EVP_EncryptUpdate(ctx, outbuf, &outlen, - rc4_pt, rc4_pt_s)) - || !TEST_true(EVP_EncryptFinal_ex(ctx, outbuf, &tmplen))) + || !TEST_true(EVP_EncryptUpdate(ctx, outbuf, &outlen, + rc4_pt, rc4_pt_s)) + || !TEST_true(EVP_EncryptFinal_ex(ctx, outbuf, &tmplen))) goto err; if (!TEST_mem_eq(outbuf, outlen, rc4_ct, rc4_ct_s)) @@ -5330,8 +5282,8 @@ err: } static int rc4_decrypt(const unsigned char *rc4_key, size_t rc4_key_s, - const unsigned char *rc4_pt, size_t rc4_pt_s, - const unsigned char *rc4_ct, size_t rc4_ct_s) + const unsigned char *rc4_pt, size_t rc4_pt_s, + const unsigned char *rc4_ct, size_t rc4_ct_s) { int ret = 0; EVP_CIPHER_CTX *ctx; @@ -5349,12 +5301,12 @@ static int rc4_decrypt(const unsigned char *rc4_key, size_t rc4_key_s, goto err; params[0] = OSSL_PARAM_construct_size_t(OSSL_CIPHER_PARAM_KEYLEN, - &rc4_key_s); + &rc4_key_s); if (!TEST_true(EVP_DecryptInit_ex2(ctx, cipher, rc4_key, NULL, params)) - || !TEST_true(EVP_DecryptUpdate(ctx, outbuf, &outlen, - rc4_ct, rc4_ct_s)) - || !TEST_mem_eq(outbuf, outlen, rc4_pt, rc4_pt_s)) + || !TEST_true(EVP_DecryptUpdate(ctx, outbuf, &outlen, + rc4_ct, rc4_ct_s)) + || !TEST_mem_eq(outbuf, outlen, rc4_pt, rc4_pt_s)) goto err; ret = 1; @@ -5372,12 +5324,10 @@ static int test_aes_rc4_keylen_change_cve_2023_5363(void) unsigned char key[5]; unsigned char padding[11]; } rc4_key = { - { /* Five bytes of key material */ - 0x83, 0x32, 0x22, 0x77, 0x2a, - }, - { /* Random padding to 16 bytes */ - 0x80, 0xad, 0x97, 0xbd, 0xc9, 0x73, 0xdf, 0x8a, 0xaa, 0x32, 0x91 - } + { /* Five bytes of key material */ + 0x83, 0x32, 0x22, 0x77, 0x2a }, + { /* Random padding to 16 bytes */ + 0x80, 0xad, 0x97, 0xbd, 0xc9, 0x73, 0xdf, 0x8a, 0xaa, 0x32, 0x91 } }; static const unsigned char rc4_pt[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -5392,9 +5342,9 @@ static int test_aes_rc4_keylen_change_cve_2023_5363(void) return TEST_skip("Test requires legacy provider to be loaded"); return rc4_encrypt(rc4_key.key, sizeof(rc4_key.key), - rc4_pt, sizeof(rc4_pt), rc4_ct, sizeof(rc4_ct)) + rc4_pt, sizeof(rc4_pt), rc4_ct, sizeof(rc4_ct)) && rc4_decrypt(rc4_key.key, sizeof(rc4_key.key), - rc4_pt, sizeof(rc4_pt), rc4_ct, sizeof(rc4_ct)); + rc4_pt, sizeof(rc4_pt), rc4_ct, sizeof(rc4_ct)); } #endif @@ -5429,13 +5379,13 @@ int setup_tests(void) if (!TEST_ptr(testctx)) return 0; #ifdef STATIC_LEGACY - /* - * This test is always statically linked against libcrypto. We must not - * attempt to load legacy.so that might be dynamically linked against - * libcrypto. Instead we use a built-in version of the legacy provider. - */ - if (!OSSL_PROVIDER_add_builtin(testctx, "legacy", ossl_legacy_provider_init)) - return 0; + /* + * This test is always statically linked against libcrypto. We must not + * attempt to load legacy.so that might be dynamically linked against + * libcrypto. Instead we use a built-in version of the legacy provider. + */ + if (!OSSL_PROVIDER_add_builtin(testctx, "legacy", ossl_legacy_provider_init)) + return 0; #endif /* Swap the libctx to test non-default context only */ nullprov = OSSL_PROVIDER_load(NULL, "null"); @@ -5497,7 +5447,7 @@ int setup_tests(void) ADD_TEST(test_X509_PUBKEY_inplace); ADD_TEST(test_X509_PUBKEY_dup); ADD_ALL_TESTS(test_invalide_ec_char2_pub_range_decode, - OSSL_NELEM(ec_der_pub_keys)); + OSSL_NELEM(ec_der_pub_keys)); #endif #ifndef OPENSSL_NO_DSA ADD_TEST(test_DSA_get_set_params); @@ -5512,15 +5462,15 @@ int setup_tests(void) #endif #ifndef OPENSSL_NO_DH ADD_TEST(test_DH_priv_pub); -# ifndef OPENSSL_NO_DEPRECATED_3_0 +#ifndef OPENSSL_NO_DEPRECATED_3_0 ADD_TEST(test_EVP_PKEY_set1_DH); -# endif +#endif #endif #ifndef OPENSSL_NO_EC ADD_TEST(test_EC_priv_pub); -# ifndef OPENSSL_NO_DEPRECATED_3_0 +#ifndef OPENSSL_NO_DEPRECATED_3_0 ADD_TEST(test_EC_priv_only_legacy); -# endif +#endif #endif ADD_ALL_TESTS(test_keygen_with_empty_template, 2); ADD_ALL_TESTS(test_pkey_ctx_fail_without_provider, 2); @@ -5556,17 +5506,17 @@ int setup_tests(void) ADD_TEST(test_custom_md_meth); ADD_TEST(test_custom_ciph_meth); -# ifndef OPENSSL_NO_DYNAMIC_ENGINE +#ifndef OPENSSL_NO_DYNAMIC_ENGINE /* Tests only support the default libctx */ if (testctx == NULL) { -# ifndef OPENSSL_NO_EC +#ifndef OPENSSL_NO_EC ADD_ALL_TESTS(test_signatures_with_engine, 3); -# else +#else ADD_ALL_TESTS(test_signatures_with_engine, 2); -# endif +#endif ADD_TEST(test_cipher_with_engine); } -# endif +#endif #endif ADD_ALL_TESTS(test_ecx_short_keys, OSSL_NELEM(ecxnids)); |
