VirtualBox

Ignore:
Timestamp:
Mar 31, 2022 9:00:36 AM (3 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
150730
Message:

libs/openssl: Update to 3.0.2 and switch to it, bugref:10128

Location:
trunk/src/libs/openssl-3.0.2
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/libs/openssl-3.0.2

    • Property svn:mergeinfo
      •  

        old new  
        1313/vendor/openssl/1.1.1k:145841-145843
        1414/vendor/openssl/3.0.1:150323-150324
        15 /vendor/openssl/current:147554-150322
         15/vendor/openssl/3.0.2:150728-150729
         16/vendor/openssl/current:147554-150727
  • trunk/src/libs/openssl-3.0.2/test/evp_extra_test2.c

    r94320 r94404  
    11/*
    2  * Copyright 2015-2021 The OpenSSL Project Authors. All Rights Reserved.
     2 * Copyright 2015-2022 The OpenSSL Project Authors. All Rights Reserved.
    33 *
    44 * Licensed under the Apache License 2.0 (the "License").  You may not use
     
    255255#endif
    256256};
     257
     258static int pkey_has_private(EVP_PKEY *key, const char *privtag,
     259                            int use_octstring)
     260{
     261    int ret = 0;
     262
     263    if (use_octstring) {
     264        unsigned char buf[64];
     265
     266        ret = EVP_PKEY_get_octet_string_param(key, privtag, buf, sizeof(buf),
     267                                              NULL);
     268    } else {
     269        BIGNUM *bn = NULL;
     270
     271        ret = EVP_PKEY_get_bn_param(key, privtag, &bn);
     272        BN_free(bn);
     273    }
     274    return ret;
     275}
     276
     277static int do_pkey_tofrom_data_select(EVP_PKEY *key, const char *keytype)
     278{
     279    int ret = 0;
     280    OSSL_PARAM *pub_params = NULL, *keypair_params = NULL;
     281    EVP_PKEY *fromkey = NULL, *fromkeypair = NULL;
     282    EVP_PKEY_CTX *fromctx = NULL;
     283    const char *privtag = strcmp(keytype, "RSA") == 0 ? "d" : "priv";
     284    const int use_octstring = strcmp(keytype, "X25519") == 0;
     285
     286    /*
     287     * Select only the public key component when using EVP_PKEY_todata() and
     288     * check that the resulting param array does not contain a private key.
     289     */
     290    if (!TEST_int_eq(EVP_PKEY_todata(key, EVP_PKEY_PUBLIC_KEY, &pub_params), 1)
     291        || !TEST_ptr_null(OSSL_PARAM_locate(pub_params, privtag)))
     292        goto end;
     293    /*
     294     * Select the keypair when using EVP_PKEY_todata() and check that
     295     * the param array contains a private key.
     296     */
     297    if (!TEST_int_eq(EVP_PKEY_todata(key, EVP_PKEY_KEYPAIR, &keypair_params), 1)
     298        || !TEST_ptr(OSSL_PARAM_locate(keypair_params, privtag)))
     299        goto end;
     300
     301    /*
     302     * Select only the public key when using EVP_PKEY_fromdata() and check that
     303     * the resulting key does not contain a private key.
     304     */
     305    if (!TEST_ptr(fromctx = EVP_PKEY_CTX_new_from_name(mainctx, keytype, NULL))
     306        || !TEST_int_eq(EVP_PKEY_fromdata_init(fromctx), 1)
     307        || !TEST_int_eq(EVP_PKEY_fromdata(fromctx, &fromkey, EVP_PKEY_PUBLIC_KEY,
     308                                          keypair_params), 1)
     309        || !TEST_false(pkey_has_private(fromkey, privtag, use_octstring)))
     310        goto end;
     311    /*
     312     * Select the keypair when using EVP_PKEY_fromdata() and check that
     313     * the resulting key contains a private key.
     314     */
     315    if (!TEST_int_eq(EVP_PKEY_fromdata(fromctx, &fromkeypair,
     316                                       EVP_PKEY_KEYPAIR, keypair_params), 1)
     317        || !TEST_true(pkey_has_private(fromkeypair, privtag, use_octstring)))
     318        goto end;
     319    ret = 1;
     320end:
     321    EVP_PKEY_free(fromkeypair);
     322    EVP_PKEY_free(fromkey);
     323    EVP_PKEY_CTX_free(fromctx);
     324    OSSL_PARAM_free(keypair_params);
     325    OSSL_PARAM_free(pub_params);
     326    return ret;
     327}
     328
     329#ifndef OPENSSL_NO_DH
     330static int test_dh_tofrom_data_select(void)
     331{
     332    int ret;
     333    OSSL_PARAM params[2];
     334    EVP_PKEY *key = NULL;
     335    EVP_PKEY_CTX *gctx = NULL;
     336
     337    params[0] = OSSL_PARAM_construct_utf8_string("group", "ffdhe2048", 0);
     338    params[1] = OSSL_PARAM_construct_end();
     339    ret = TEST_ptr(gctx = EVP_PKEY_CTX_new_from_name(mainctx, "DHX", NULL))
     340          && TEST_int_gt(EVP_PKEY_keygen_init(gctx), 0)
     341          && TEST_true(EVP_PKEY_CTX_set_params(gctx, params))
     342          && TEST_int_gt(EVP_PKEY_generate(gctx, &key), 0)
     343          && TEST_true(do_pkey_tofrom_data_select(key, "DHX"));
     344    EVP_PKEY_free(key);
     345    EVP_PKEY_CTX_free(gctx);
     346    return ret;
     347}
     348#endif
     349
     350#ifndef OPENSSL_NO_EC
     351static int test_ec_tofrom_data_select(void)
     352{
     353    int ret;
     354    EVP_PKEY *key = NULL;
     355
     356    ret = TEST_ptr(key = EVP_PKEY_Q_keygen(mainctx, NULL, "EC", "P-256"))
     357          && TEST_true(do_pkey_tofrom_data_select(key, "EC"));
     358    EVP_PKEY_free(key);
     359    return ret;
     360}
     361
     362static int test_ecx_tofrom_data_select(void)
     363{
     364    int ret;
     365    EVP_PKEY *key = NULL;
     366
     367    ret = TEST_ptr(key = EVP_PKEY_Q_keygen(mainctx, NULL, "X25519"))
     368          && TEST_true(do_pkey_tofrom_data_select(key, "X25519"));
     369    EVP_PKEY_free(key);
     370    return ret;
     371}
     372#endif
     373
     374static int test_rsa_tofrom_data_select(void)
     375{
     376    int ret;
     377    EVP_PKEY *key = NULL;
     378    const unsigned char *pdata = kExampleRSAKeyDER;
     379    int pdata_len = sizeof(kExampleRSAKeyDER);
     380
     381    ret = TEST_ptr(key = d2i_AutoPrivateKey_ex(NULL, &pdata, pdata_len,
     382                                               mainctx, NULL))
     383          && TEST_true(do_pkey_tofrom_data_select(key, "RSA"));
     384    EVP_PKEY_free(key);
     385    return ret;
     386}
    257387
    258388/* This is the equivalent of test_d2i_AutoPrivateKey in evp_extra_test */
     
    662792}
    663793
     794static int test_dsa_tofrom_data_select(void)
     795{
     796    int ret;
     797    EVP_PKEY *key = NULL;
     798    const unsigned char *pkeydata = dsa_key;
     799
     800    ret = TEST_ptr(key = d2i_AutoPrivateKey_ex(NULL, &pkeydata, sizeof(dsa_key),
     801                                               mainctx, NULL))
     802          && TEST_true(do_pkey_tofrom_data_select(key, "DSA"));
     803
     804    EVP_PKEY_free(key);
     805    return ret;
     806}
     807
    664808static int test_dsa_todata(void)
    665809{
     
    8821026#ifndef OPENSSL_NO_EC
    8831027    ADD_ALL_TESTS(test_d2i_PrivateKey_ex, 2);
     1028    ADD_TEST(test_ec_tofrom_data_select);
     1029    ADD_TEST(test_ecx_tofrom_data_select);
    8841030#else
    8851031    ADD_ALL_TESTS(test_d2i_PrivateKey_ex, 1);
     
    8871033#ifndef OPENSSL_NO_DSA
    8881034    ADD_TEST(test_dsa_todata);
     1035    ADD_TEST(test_dsa_tofrom_data_select);
    8891036#endif
     1037#ifndef OPENSSL_NO_DH
     1038    ADD_TEST(test_dh_tofrom_data_select);
     1039#endif
     1040    ADD_TEST(test_rsa_tofrom_data_select);
     1041
    8901042    ADD_TEST(test_pkey_todata_null);
    8911043    ADD_TEST(test_pkey_export_null);
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette