@@ -1683,6 +1683,49 @@ TEST(EVPExtraTest, Ed25519) {
16831683 ERR_clear_error ();
16841684}
16851685
1686+ // EVP_PKEY_get_private_seed returns an error for key types that don't
1687+ // provide a get_priv_seed method. It must also reject NULL |key| regardless of
1688+ // key type.
1689+ TEST (EVPExtraTest, GetPrivateSeedUnsupportedKeyTypes) {
1690+ // NULL key is rejected.
1691+ size_t seed_len = 0 ;
1692+ ERR_clear_error ();
1693+ EXPECT_FALSE (EVP_PKEY_get_private_seed (nullptr , nullptr , &seed_len));
1694+
1695+ // RSA
1696+ bssl::UniquePtr<EVP_PKEY> rsa_key (ParsePrivateKey (
1697+ EVP_PKEY_RSA, kExampleRSAKeyDER , sizeof (kExampleRSAKeyDER )));
1698+ ASSERT_TRUE (rsa_key);
1699+ ERR_clear_error ();
1700+ EXPECT_FALSE (EVP_PKEY_get_private_seed (rsa_key.get (), nullptr , &seed_len));
1701+ EXPECT_TRUE (ErrorEquals (ERR_get_error (), ERR_LIB_EVP,
1702+ EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE));
1703+
1704+ // EC
1705+ bssl::UniquePtr<EVP_PKEY> ec_key (ParsePrivateKey (
1706+ EVP_PKEY_EC, kExampleECKeyDER , sizeof (kExampleECKeyDER )));
1707+ ASSERT_TRUE (ec_key);
1708+ ERR_clear_error ();
1709+ EXPECT_FALSE (EVP_PKEY_get_private_seed (ec_key.get (), nullptr , &seed_len));
1710+ EXPECT_TRUE (ErrorEquals (ERR_get_error (), ERR_LIB_EVP,
1711+ EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE));
1712+
1713+ // Ed25519: has a raw 32-byte private "seed" but does NOT wire up
1714+ // get_priv_seed. EVP_PKEY_get_raw_private_key is the correct accessor.
1715+ static const uint8_t kEd25519Seed [32 ] = {
1716+ 0x9d , 0x61 , 0xb1 , 0x9d , 0xef , 0xfd , 0x5a , 0x60 , 0xba , 0x84 , 0x4a ,
1717+ 0xf4 , 0x92 , 0xec , 0x2c , 0xc4 , 0x44 , 0x49 , 0xc5 , 0x69 , 0x7b , 0x32 ,
1718+ 0x69 , 0x19 , 0x70 , 0x3b , 0xac , 0x03 , 0x1c , 0xae , 0x7f , 0x60 ,
1719+ };
1720+ bssl::UniquePtr<EVP_PKEY> ed_key (EVP_PKEY_new_raw_private_key (
1721+ EVP_PKEY_ED25519, nullptr , kEd25519Seed , sizeof (kEd25519Seed )));
1722+ ASSERT_TRUE (ed_key);
1723+ ERR_clear_error ();
1724+ EXPECT_FALSE (EVP_PKEY_get_private_seed (ed_key.get (), nullptr , &seed_len));
1725+ EXPECT_TRUE (ErrorEquals (ERR_get_error (), ERR_LIB_EVP,
1726+ EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE));
1727+ }
1728+
16861729static void ExpectECGroupOnly (const EVP_PKEY *pkey, int nid) {
16871730 EC_KEY *ec = EVP_PKEY_get0_EC_KEY (pkey);
16881731 ASSERT_TRUE (ec);
0 commit comments