bld = NULL;
/*
- * We indicate only parameters here, in spite of having built a key that
- * has a private part, because the PEM_write_bio_PrivateKey_ex call is
- * expected to fail because it does not support exporting a private EC
- * key without a corresponding public key
+ * ossl_ec_key_fromdata() automatically generates the public key on import
+ * if one is not provided, so fail the test if a public key is not
+ * available.
*/
- if (!test_selection(params_and_priv, OSSL_KEYMGMT_SELECT_ALL_PARAMETERS)
- || test_selection(params_and_priv, OSSL_KEYMGMT_SELECT_PUBLIC_KEY))
+ if (!test_selection(params_and_priv, OSSL_KEYMGMT_SELECT_KEYPAIR))
goto err;
/* Test !priv and pub */
}
/*
- * ECX keys autogen the public key if a private key is loaded,
- * So this test passes for ECX, but fails for EC
+ * ECX and EC keys autogen the public key if a private key is loaded.
*/
static int test_nopublic(int tstid)
{
int encap = ((tstid & 1) == 0);
int keytype = tstid >= TEST_KEM_ENCAP_DECAP;
const TEST_ENCAPDATA *t = &ec_encapdata[keytype];
- int expected = (keytype == TEST_KEYTYPE_X25519);
TEST_note("%s %s", t->curve, encap ? "Encap" : "Decap");
if (!TEST_ptr(priv = new_raw_private_key(t->curve, t->rpriv, t->rprivlen,
goto err;
if (encap) {
- if (!TEST_int_eq(EVP_PKEY_encapsulate_init(ctx, opparam), expected))
+ if (!TEST_int_eq(EVP_PKEY_encapsulate_init(ctx, opparam), 1))
goto err;
} else {
- if (!TEST_int_eq(EVP_PKEY_decapsulate_init(ctx, opparam), expected))
+ if (!TEST_int_eq(EVP_PKEY_decapsulate_init(ctx, opparam), 1))
goto err;
}
- if (expected == 0
- && !TEST_int_eq(ERR_GET_REASON(ERR_get_error()), PROV_R_NOT_A_PUBLIC_KEY))
- goto err;
ret = 1;
err:
EVP_PKEY_free(priv);
return ret;
}
-/* Test that not setting the auth public key fails the auth encap/decap init */
+/*
+ * Test that not setting the auth public key does not fail the auth
+ * encap/decap init
+ */
static int test_noauthpublic(int tstid)
{
int ret = 0;
int keytype = tstid >= TEST_KEM_ENCAP_DECAP;
const TEST_ENCAPDATA *t = &ec_encapdata[keytype];
EVP_PKEY_CTX *ctx = rctx[keytype];
- int expected = (keytype == TEST_KEYTYPE_X25519);
TEST_note("%s %s", t->curve, encap ? "Encap" : "Decap");
if (!TEST_ptr(auth = new_raw_private_key(t->curve, t->rpriv,
- t->rprivlen, NULL, expected)))
+ t->rprivlen, NULL, 1)))
goto err;
if (encap) {
if (!TEST_int_eq(EVP_PKEY_auth_encapsulate_init(ctx, auth,
opparam),
- expected))
+ 1))
goto err;
} else {
if (!TEST_int_eq(EVP_PKEY_auth_decapsulate_init(ctx, auth,
opparam),
- expected))
+ 1))
goto err;
}
- if (expected == 0
- && !TEST_int_eq(ERR_GET_REASON(ERR_get_error()),
- PROV_R_NOT_A_PUBLIC_KEY))
- goto err;
ret = 1;
err:
EVP_PKEY_free(auth);