Lines Matching +full:pk +full:- +full:pk
2 * Copyright 2019-2024 The OpenSSL Project Authors. All Rights Reserved.
43 for (i = *len, curr = buf, writ = buf; i > 0; i--, curr++) {
45 (*len)--;
138 return -1;
141 static int test_print_key_using_pem(const char *alg, const EVP_PKEY *pk)
150 !TEST_true(PEM_write_bio_PrivateKey(bio_out, pk, EVP_aes_256_cbc(),
153 /* Output zero-length passphrase encrypted private key in PEM form */
154 || !TEST_true(PEM_write_bio_PKCS8PrivateKey(bio_out, pk,
158 || !TEST_true(PEM_write_bio_PKCS8PrivateKey(bio_out, pk,
161 || !TEST_true(PEM_write_bio_PKCS8PrivateKey(bio_out, pk,
164 || !TEST_false(PEM_write_bio_PKCS8PrivateKey(bio_out, pk,
170 bio_out, pk, NID_pbe_WithSHA1And3_Key_TripleDES_CBC,
173 bio_out, pk, NID_pbe_WithSHA1And3_Key_TripleDES_CBC, NULL, 0,
176 bio_out, pk, NID_pbe_WithSHA1And3_Key_TripleDES_CBC, NULL, 0,
179 bio_out, pk, NID_pbe_WithSHA1And3_Key_TripleDES_CBC, NULL, 0,
183 || !TEST_int_gt(EVP_PKEY_print_private(membio, pk, 0, NULL), 0)
186 || !TEST_true(PEM_write_bio_PUBKEY(membio, pk))
189 || !TEST_true(PEM_write_bio_PrivateKey(membio, pk,
206 const EVP_PKEY *pk)
267 if (!TEST_ptr(ctx = OSSL_ENCODER_CTX_new_for_pkey(pk, selection,
289 TEST_note("Displaying PEM encrypted with AES-256-CBC");
290 if (!TEST_true(OSSL_ENCODER_CTX_set_cipher(ctx, "AES-256-CBC", NULL))
314 static int test_print_key_using_encoder(const char *alg, const EVP_PKEY *pk)
320 ret = ret && test_print_key_type_using_encoder(alg, i, pk);
327 const EVP_PKEY *pk)
333 ret = ret && test_print_key_type_using_encoder(alg, i, pk);
353 EVP_PKEY *pk = NULL, *copy_pk = NULL, *dup_pk = NULL;
355 * 32-bit RSA key, extracted from this command,
358 * openssl genrsa 32 | openssl rsa -text
388 || !TEST_int_eq(EVP_PKEY_fromdata(ctx, &pk, EVP_PKEY_KEYPAIR,
394 if (!TEST_int_eq(EVP_PKEY_get_bits(pk), 32)
395 || !TEST_int_eq(EVP_PKEY_get_security_bits(pk), 8)
396 || !TEST_int_eq(EVP_PKEY_get_size(pk), 4)
397 || !TEST_false(EVP_PKEY_missing_parameters(pk)))
401 if (!TEST_ptr(key_ctx = EVP_PKEY_CTX_new_from_pkey(NULL, pk, "")))
412 || !TEST_false(EVP_PKEY_copy_parameters(copy_pk, pk)))
417 ret = test_print_key_using_pem("RSA", pk)
418 && test_print_key_using_encoder("RSA", pk);
423 if (!TEST_ptr(dup_pk = EVP_PKEY_dup(pk)))
425 ret = ret && TEST_int_eq(EVP_PKEY_eq(pk, dup_pk), 1);
426 EVP_PKEY_free(pk);
427 pk = dup_pk;
435 || !TEST_true(EVP_PKEY_get_bn_param(pk, fromdata_params[i].key, &bn))
441 EVP_PKEY_free(pk);
453 EVP_PKEY *pk = NULL;
482 || !TEST_int_eq(EVP_PKEY_fromdata(ctx, &pk, EVP_PKEY_KEYPAIR,
484 || !TEST_ptr(key_ctx = EVP_PKEY_CTX_new_from_pkey(NULL, pk, ""))
485 || !TEST_true(EVP_PKEY_get_bn_param(pk, OSSL_PKEY_PARAM_RSA_N, &n_out))
494 EVP_PKEY_free(pk);
509 EVP_PKEY *pk = NULL, *copy_pk = NULL, *dup_pk = NULL;
521 * openssl genpkey -algorithm DH -pkeyopt group:ffdhe2048
522 * -pkeyopt priv_len:224 -text
573 || !TEST_int_eq(EVP_PKEY_fromdata(ctx, &pk, EVP_PKEY_KEYPAIR,
582 if (!TEST_true(EVP_PKEY_get_utf8_string_param(pk,
586 || !TEST_size_t_eq(len, sizeof(group_name) - 1)
588 || !TEST_true(EVP_PKEY_get_utf8_string_param(pk,
593 || !TEST_size_t_eq(len, sizeof(group_name) - 1)
595 || !TEST_false(EVP_PKEY_get_utf8_string_param(pk,
598 sizeof(group_name) - 1,
601 || !TEST_false(EVP_PKEY_get_utf8_string_param(pk,
604 sizeof(group_name) - 2,
610 if (!TEST_int_eq(EVP_PKEY_get_bits(pk), 2048)
611 || !TEST_int_eq(EVP_PKEY_get_security_bits(pk), 112)
612 || !TEST_int_eq(EVP_PKEY_get_size(pk), 256)
613 || !TEST_false(EVP_PKEY_missing_parameters(pk)))
616 if (!TEST_true(EVP_PKEY_get_utf8_string_param(pk,
622 || !TEST_true(EVP_PKEY_get_bn_param(pk, OSSL_PKEY_PARAM_PUB_KEY,
626 || !TEST_true(EVP_PKEY_get_bn_param(pk, OSSL_PKEY_PARAM_PRIV_KEY,
629 || !TEST_true(EVP_PKEY_get_bn_param(pk, OSSL_PKEY_PARAM_FFC_P, &p))
631 || !TEST_true(EVP_PKEY_get_bn_param(pk, OSSL_PKEY_PARAM_FFC_Q, &q))
633 || !TEST_true(EVP_PKEY_get_bn_param(pk, OSSL_PKEY_PARAM_FFC_G, &g))
635 || !TEST_false(EVP_PKEY_get_bn_param(pk,
639 || !TEST_false(EVP_PKEY_get_octet_string_param(pk,
644 || !TEST_true(EVP_PKEY_get_int_param(pk, OSSL_PKEY_PARAM_FFC_GINDEX,
646 || !TEST_int_eq(gindex, -1)
647 || !TEST_true(EVP_PKEY_get_int_param(pk, OSSL_PKEY_PARAM_FFC_H,
650 || !TEST_true(EVP_PKEY_get_int_param(pk,
653 || !TEST_int_eq(pcounter, -1))
668 if (!TEST_ptr(key_ctx = EVP_PKEY_CTX_new_from_pkey(NULL, pk, "")))
680 || !TEST_true(EVP_PKEY_copy_parameters(copy_pk, pk)))
685 ret = test_print_key_using_pem("DH", pk)
686 && test_print_key_using_encoder("DH", pk);
691 if (!TEST_ptr(dup_pk = EVP_PKEY_dup(pk)))
693 ret = ret && TEST_int_eq(EVP_PKEY_eq(pk, dup_pk), 1);
694 EVP_PKEY_free(pk);
695 pk = dup_pk;
709 EVP_PKEY_free(pk);
723 EVP_PKEY *pk = NULL, *dup_pk = NULL;
735 * openssl genpkey -algorithm DH
736 * -pkeyopt group:ffdhe2048 -pkeyopt priv_len:224 -text
788 || !TEST_int_eq(EVP_PKEY_fromdata(ctx, &pk, EVP_PKEY_KEYPAIR,
794 if (!TEST_int_eq(EVP_PKEY_get_bits(pk), 2048)
795 || !TEST_int_eq(EVP_PKEY_get_security_bits(pk), 112)
796 || !TEST_int_eq(EVP_PKEY_get_size(pk), 256)
797 || !TEST_false(EVP_PKEY_missing_parameters(pk)))
800 if (!TEST_true(EVP_PKEY_get_utf8_string_param(pk,
806 || !TEST_true(EVP_PKEY_get_bn_param(pk, OSSL_PKEY_PARAM_PUB_KEY,
809 || !TEST_true(EVP_PKEY_get_bn_param(pk, OSSL_PKEY_PARAM_PRIV_KEY,
812 || !TEST_true(EVP_PKEY_get_bn_param(pk, OSSL_PKEY_PARAM_FFC_P, &p))
814 || !TEST_true(EVP_PKEY_get_bn_param(pk, OSSL_PKEY_PARAM_FFC_Q, &q))
816 || !TEST_true(EVP_PKEY_get_bn_param(pk, OSSL_PKEY_PARAM_FFC_G, &g))
818 || !TEST_false(EVP_PKEY_get_bn_param(pk,
822 || !TEST_false(EVP_PKEY_get_octet_string_param(pk,
827 || !TEST_true(EVP_PKEY_get_int_param(pk,
830 || !TEST_int_eq(gindex, -1)
831 || !TEST_true(EVP_PKEY_get_int_param(pk, OSSL_PKEY_PARAM_FFC_H,
834 || !TEST_true(EVP_PKEY_get_int_param(pk,
837 || !TEST_int_eq(pcounter, -1))
852 if (!TEST_ptr(key_ctx = EVP_PKEY_CTX_new_from_pkey(NULL, pk, "")))
863 ret = test_print_key_using_pem("DH", pk)
864 && test_print_key_using_encoder("DH", pk);
869 if (!TEST_ptr(dup_pk = EVP_PKEY_dup(pk)))
871 ret = ret && TEST_int_eq(EVP_PKEY_eq(pk, dup_pk), 1);
872 EVP_PKEY_free(pk);
873 pk = dup_pk;
886 EVP_PKEY_free(pk);
910 * tst uses indexes 0 ... (3 * 4 - 1)
920 EVP_PKEY *pk = NULL, *copy_pk = NULL, *dup_pk = NULL;
1098 || !TEST_int_eq(EVP_PKEY_fromdata(ctx, &pk, EVP_PKEY_KEYPAIR,
1104 if (!TEST_int_eq(EVP_PKEY_get_bits(pk), bits)
1105 || !TEST_int_eq(EVP_PKEY_get_security_bits(pk), security_bits)
1106 || !TEST_int_eq(EVP_PKEY_get_size(pk), size)
1107 || !TEST_false(EVP_PKEY_missing_parameters(pk)))
1110 if (!TEST_ptr(ctx2 = EVP_PKEY_CTX_new_from_pkey(NULL, pk, NULL)))
1116 pk, orig_fromdata_params[PRIV_KEY].key,
1122 pk, orig_fromdata_params[PUB_KEY].key,
1140 || !TEST_true(EVP_PKEY_copy_parameters(copy_pk, pk)))
1152 ret = test_print_key_using_encoder_public(alg, pk);
1154 ret = test_print_key_using_pem(alg, pk)
1155 && test_print_key_using_encoder(alg, pk);
1160 if (!TEST_ptr(dup_pk = EVP_PKEY_dup(pk)))
1162 ret = ret && TEST_int_eq(EVP_PKEY_eq(pk, dup_pk), 1);
1163 EVP_PKEY_free(pk);
1164 pk = dup_pk;
1170 EVP_PKEY_free(pk);
1182 EVP_PKEY *pk = NULL, *copy_pk = NULL, *dup_pk = NULL;
1189 const char bad_curve[] = "nonexistent-curve";
1267 || !TEST_int_eq(EVP_PKEY_fromdata(ctx, &pk, EVP_PKEY_KEY_PARAMETERS,
1269 || !TEST_ptr_null(pk))
1273 || !TEST_int_eq(EVP_PKEY_fromdata(ctx, &pk, EVP_PKEY_KEYPAIR,
1279 if (!TEST_int_eq(EVP_PKEY_get_bits(pk), 256)
1280 || !TEST_int_eq(EVP_PKEY_get_security_bits(pk), 128)
1281 || !TEST_int_eq(EVP_PKEY_get_size(pk), 2 + 35 * 2)
1282 || !TEST_false(EVP_PKEY_missing_parameters(pk)))
1286 || !TEST_true(EVP_PKEY_copy_parameters(copy_pk, pk)))
1291 if (!TEST_ptr(gettable = EVP_PKEY_gettable_params(pk))
1307 if (!TEST_true(EVP_PKEY_get_bn_param(pk, OSSL_PKEY_PARAM_EC_A, &a))
1308 || !TEST_true(EVP_PKEY_get_bn_param(pk, OSSL_PKEY_PARAM_EC_B, &b))
1309 || !TEST_true(EVP_PKEY_get_bn_param(pk, OSSL_PKEY_PARAM_EC_P, &p)))
1325 if (!EVP_PKEY_get_utf8_string_param(pk, OSSL_PKEY_PARAM_GROUP_NAME,
1330 || !EVP_PKEY_get_octet_string_param(pk, OSSL_PKEY_PARAM_PUB_KEY,
1340 || !TEST_mem_eq(out_pub + 1, len - 1,
1341 ec_pub_keydata + 1, sizeof(ec_pub_keydata) - 1)
1343 || !TEST_true(EVP_PKEY_get_bn_param(pk, OSSL_PKEY_PARAM_PRIV_KEY,
1350 ret = test_print_key_using_pem(alg, pk)
1351 && test_print_key_using_encoder(alg, pk);
1356 if (!TEST_ptr(dup_pk = EVP_PKEY_dup(pk)))
1358 ret = ret && TEST_int_eq(EVP_PKEY_eq(pk, dup_pk), 1);
1359 EVP_PKEY_free(pk);
1360 pk = dup_pk;
1377 EVP_PKEY_free(pk);
1454 EVP_PKEY *pk = NULL, *copy_pk = NULL, *dup_pk = NULL;
1468 * openssl genpkey -genparam -algorithm DSA -pkeyopt pbits:2048 \
1469 * -pkeyopt qbits:256 -pkeyopt type:0 \
1470 * -pkeyopt gindex:1 -out dsa_params.pem -text
1534 * openssl genpkey -paramfile dsa_params.pem --pkeyopt pcounter:53 \
1535 * -pkeyopt gindex:1 \
1536 * -pkeyopt hexseed:644607328d709cb38a35de6200f26d -text
1598 || !TEST_int_eq(EVP_PKEY_fromdata(ctx, &pk, EVP_PKEY_KEYPAIR,
1604 if (!TEST_int_eq(EVP_PKEY_get_bits(pk), 2048)
1605 || !TEST_int_eq(EVP_PKEY_get_security_bits(pk), 112)
1606 || !TEST_int_eq(EVP_PKEY_get_size(pk), 2 + 2 * (3 + sizeof(q_data)))
1607 || !TEST_false(EVP_PKEY_missing_parameters(pk)))
1610 if (!TEST_false(EVP_PKEY_get_utf8_string_param(pk,
1615 || !TEST_true(EVP_PKEY_get_bn_param(pk, OSSL_PKEY_PARAM_PUB_KEY,
1618 || !TEST_true(EVP_PKEY_get_bn_param(pk, OSSL_PKEY_PARAM_PRIV_KEY,
1621 || !TEST_true(EVP_PKEY_get_bn_param(pk, OSSL_PKEY_PARAM_FFC_P,
1624 || !TEST_true(EVP_PKEY_get_bn_param(pk, OSSL_PKEY_PARAM_FFC_Q,
1627 || !TEST_true(EVP_PKEY_get_bn_param(pk, OSSL_PKEY_PARAM_FFC_G,
1630 || !TEST_false(EVP_PKEY_get_bn_param(pk,
1634 || !TEST_true(EVP_PKEY_get_octet_string_param(pk,
1639 || !TEST_true(EVP_PKEY_get_int_param(pk,
1643 || !TEST_true(EVP_PKEY_get_int_param(pk, OSSL_PKEY_PARAM_FFC_H,
1646 || !TEST_true(EVP_PKEY_get_int_param(pk,
1664 if (!TEST_ptr(key_ctx = EVP_PKEY_CTX_new_from_pkey(NULL, pk, "")))
1676 || !TEST_true(EVP_PKEY_copy_parameters(copy_pk, pk)))
1681 ret = test_print_key_using_pem("DSA", pk)
1682 && test_print_key_using_encoder("DSA", pk);
1687 if (!TEST_ptr(dup_pk = EVP_PKEY_dup(pk)))
1689 ret = ret && TEST_int_eq(EVP_PKEY_eq(pk, dup_pk), 1);
1690 EVP_PKEY_free(pk);
1691 pk = dup_pk;
1710 EVP_PKEY_free(pk);