[openssl-dev] [openssl.org #3894] AutoReply: PATCH: EVP_PKEY_get_type (new function)

noloader@gmail.com via RT rt at openssl.org
Wed Jun 3 20:50:25 UTC 2015


Here's an updated patch that includes the documentation changes. `git
diff master` is needed after `git add` because adding doesn't seem to
really add things for git :)

riemann::openssl-git$ cat evp_pkey_get_type.diff
diff --git a/crypto/evp/evp_lib.c b/crypto/evp/evp_lib.c
index 1fdde9a..0cd8a42 100644
--- a/crypto/evp/evp_lib.c
+++ b/crypto/evp/evp_lib.c
@@ -61,6 +61,15 @@
 #include <openssl/evp.h>
 #include <openssl/objects.h>

+/* Returns the key type or EVP_PKEY_NONE if pkey is NULL */
+int EVP_PKEY_get_type(EVP_PKEY *pkey)
+{
+    if (!pkey)
+        return EVP_PKEY_NONE;
+
+    return EVP_PKEY_type(pkey->type);
+}
+
 int EVP_CIPHER_param_to_asn1(EVP_CIPHER_CTX *c, ASN1_TYPE *type)
 {
     int ret;
diff --git a/doc/crypto/EVP_PKEY_get_type.pod b/doc/crypto/EVP_PKEY_get_type.pod
new file mode 100644
index 0000000..1faaae5
--- /dev/null
+++ b/doc/crypto/EVP_PKEY_get_type.pod
@@ -0,0 +1,65 @@
+=pod
+
+=head1 NAME
+
+EVP_PKEY_get_type - queries the EVP_PKEY for the type of key
+
+=head1 SYNOPSIS
+
+ #include <openssl/evp.h>
+
+ int EVP_PKEY_get_type(EVP_PKEY *pkey);
+
+=head1 DESCRIPTION
+
+B<EVP_PKEY_get_type> queries the EVP_PKEY for the type of key.
+
+Though B<EVP_PKEY_get_type> is available, its use is discouraged
because it peeks into implementation specific details.
+
+==head1 RETURN VALUES
+
+If B<pkey> is B<NULL>, then the function returns B<EVP_PKEY_NONE>.
+
+If B<pkey> is not B<NULL>, then the return value will be one of the
following values from B<evp.h>:
+
+ * EVP_PKEY_NONE
+ * EVP_PKEY_RSA
+ * EVP_PKEY_RSA2
+ * EVP_PKEY_DSA
+ * EVP_PKEY_DSA1
+ * EVP_PKEY_DSA2
+ * EVP_PKEY_DSA3
+ * EVP_PKEY_DSA4
+ * EVP_PKEY_DH
+ * EVP_PKEY_DHX
+ * EVP_PKEY_EC
+ * EVP_PKEY_HMAC
+ * EVP_PKEY_CMAC
+
+==head1 EXAMPLE
+
+EVP_PKEY* pkey = PEM_read_PUBKEY(...);
+if(pkey == NULL) /* Error */
+
+int type = EVP_PKEY_get_type(pkey);
+if(type != EVP_PKEY_RSA && type != EVP_PKEY_RSA2) /* Error */
+
+RSA* rsa = EVP_PKEY_get1_RSA(pkey);
+if(rsa == NULL) /* Error */
+
+/* Use 'rsa' in RSA_size, RSA_public_encrypt, etc */
+
+RSA_free(rsa);
+EVP_free(pkey);
+
+==head1 SEE ALSO
+
+B<EVP(3), EVP(3)>,
+B<EVP_PKEY_get1_DH(3), EVP_PKEY_get1_DH(3)>,
+B<EVP_PKEY_get1_DSA(3), EVP_PKEY_get1_DSA(3)>,
+B<EVP_PKEY_get1_EC_KEY(3), EVP_PKEY_get1_EC_KEY(3)>,
+B<EVP_PKEY_get1_RSA(3), EVP_PKEY_get1_RSA(3)>,
+
+==head1 HISTORY
+
+This function was first added to OpenSSL 1.1.0.
\ No newline at end of file
diff --git a/doc/crypto/evp.pod b/doc/crypto/evp.pod
index 29fab9f..288f373 100644
--- a/doc/crypto/evp.pod
+++ b/doc/crypto/evp.pod
@@ -97,6 +97,7 @@ L<EVP_PKEY_verify(3)|EVP_PKEY_verify(3)>,
 L<EVP_PKEY_verify_recover(3)|EVP_PKEY_verify_recover(3)>,
 L<EVP_PKEY_derive(3)|EVP_PKEY_derive(3)>,
 L<EVP_BytesToKey(3)|EVP_BytesToKey(3)>,
+L<EVP_PKEY_get_type(3)|EVP_PKEY_get_type(3)>,
 L<OpenSSL_add_all_algorithms(3)|OpenSSL_add_all_algorithms(3)>,
 L<engine(3)|engine(3)>

diff --git a/include/openssl/evp.h b/include/openssl/evp.h
index dff81b0..8a90b10 100644
--- a/include/openssl/evp.h
+++ b/include/openssl/evp.h
@@ -742,6 +742,9 @@ int EVP_CIPHER_CTX_set_padding(EVP_CIPHER_CTX *c, int pad);
 int EVP_CIPHER_CTX_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr);
 int EVP_CIPHER_CTX_rand_key(EVP_CIPHER_CTX *ctx, unsigned char *key);

+/* Returns the key type or EVP_PKEY_NONE if pkey is NULL */
+int EVP_PKEY_get_type(EVP_PKEY *pkey);
+
 BIO_METHOD *BIO_f_md(void);
 BIO_METHOD *BIO_f_base64(void);
 BIO_METHOD *BIO_f_cipher(void);
riemann::openssl-git$


On Wed, Jun 3, 2015 at 3:00 PM, The default queue via RT <rt at openssl.org> wrote:
>
> Greetings,
>
> This message has been automatically generated in response to the
> creation of a trouble ticket regarding:
>         "PATCH: EVP_PKEY_get_type (new function)",
> a summary of which appears below.
>
> There is no need to reply to this message right now.  Your ticket has been
> assigned an ID of [openssl.org #3894].

-------------- next part --------------
diff --git a/crypto/evp/evp_lib.c b/crypto/evp/evp_lib.c
index 1fdde9a..0cd8a42 100644
--- a/crypto/evp/evp_lib.c
+++ b/crypto/evp/evp_lib.c
@@ -61,6 +61,15 @@
 #include <openssl/evp.h>
 #include <openssl/objects.h>
 
+/* Returns the key type or EVP_PKEY_NONE if pkey is NULL */
+int EVP_PKEY_get_type(EVP_PKEY *pkey)
+{
+    if (!pkey)
+        return EVP_PKEY_NONE;
+
+    return EVP_PKEY_type(pkey->type);
+}
+
 int EVP_CIPHER_param_to_asn1(EVP_CIPHER_CTX *c, ASN1_TYPE *type)
 {
     int ret;
diff --git a/doc/crypto/EVP_PKEY_get_type.pod b/doc/crypto/EVP_PKEY_get_type.pod
new file mode 100644
index 0000000..1faaae5
--- /dev/null
+++ b/doc/crypto/EVP_PKEY_get_type.pod
@@ -0,0 +1,65 @@
+=pod
+
+=head1 NAME
+
+EVP_PKEY_get_type - queries the EVP_PKEY for the type of key
+
+=head1 SYNOPSIS
+
+ #include <openssl/evp.h>
+
+ int EVP_PKEY_get_type(EVP_PKEY *pkey);
+
+=head1 DESCRIPTION
+
+B<EVP_PKEY_get_type> queries the EVP_PKEY for the type of key.
+
+Though B<EVP_PKEY_get_type> is available, its use is discouraged because it peeks into implementation specific details.
+
+==head1 RETURN VALUES
+
+If B<pkey> is B<NULL>, then the function returns B<EVP_PKEY_NONE>.
+
+If B<pkey> is not B<NULL>, then the return value will be one of the following values from B<evp.h>:
+
+ * EVP_PKEY_NONE
+ * EVP_PKEY_RSA
+ * EVP_PKEY_RSA2
+ * EVP_PKEY_DSA
+ * EVP_PKEY_DSA1
+ * EVP_PKEY_DSA2
+ * EVP_PKEY_DSA3
+ * EVP_PKEY_DSA4
+ * EVP_PKEY_DH
+ * EVP_PKEY_DHX
+ * EVP_PKEY_EC
+ * EVP_PKEY_HMAC
+ * EVP_PKEY_CMAC
+
+==head1 EXAMPLE
+
+EVP_PKEY* pkey = PEM_read_PUBKEY(...);
+if(pkey == NULL) /* Error */
+
+int type = EVP_PKEY_get_type(pkey);
+if(type != EVP_PKEY_RSA && type != EVP_PKEY_RSA2) /* Error */
+
+RSA* rsa = EVP_PKEY_get1_RSA(pkey);
+if(rsa == NULL) /* Error */
+
+/* Use 'rsa' in RSA_size, RSA_public_encrypt, etc */
+
+RSA_free(rsa);
+EVP_free(pkey);
+
+==head1 SEE ALSO
+
+B<EVP(3), EVP(3)>,
+B<EVP_PKEY_get1_DH(3), EVP_PKEY_get1_DH(3)>,
+B<EVP_PKEY_get1_DSA(3), EVP_PKEY_get1_DSA(3)>,
+B<EVP_PKEY_get1_EC_KEY(3), EVP_PKEY_get1_EC_KEY(3)>,
+B<EVP_PKEY_get1_RSA(3), EVP_PKEY_get1_RSA(3)>,
+
+==head1 HISTORY
+
+This function was first added to OpenSSL 1.1.0.
\ No newline at end of file
diff --git a/doc/crypto/evp.pod b/doc/crypto/evp.pod
index 29fab9f..288f373 100644
--- a/doc/crypto/evp.pod
+++ b/doc/crypto/evp.pod
@@ -97,6 +97,7 @@ L<EVP_PKEY_verify(3)|EVP_PKEY_verify(3)>,
 L<EVP_PKEY_verify_recover(3)|EVP_PKEY_verify_recover(3)>,
 L<EVP_PKEY_derive(3)|EVP_PKEY_derive(3)>,
 L<EVP_BytesToKey(3)|EVP_BytesToKey(3)>,
+L<EVP_PKEY_get_type(3)|EVP_PKEY_get_type(3)>,
 L<OpenSSL_add_all_algorithms(3)|OpenSSL_add_all_algorithms(3)>,
 L<engine(3)|engine(3)>
 
diff --git a/include/openssl/evp.h b/include/openssl/evp.h
index dff81b0..8a90b10 100644
--- a/include/openssl/evp.h
+++ b/include/openssl/evp.h
@@ -742,6 +742,9 @@ int EVP_CIPHER_CTX_set_padding(EVP_CIPHER_CTX *c, int pad);
 int EVP_CIPHER_CTX_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr);
 int EVP_CIPHER_CTX_rand_key(EVP_CIPHER_CTX *ctx, unsigned char *key);
 
+/* Returns the key type or EVP_PKEY_NONE if pkey is NULL */
+int EVP_PKEY_get_type(EVP_PKEY *pkey);
+
 BIO_METHOD *BIO_f_md(void);
 BIO_METHOD *BIO_f_base64(void);
 BIO_METHOD *BIO_f_cipher(void);


More information about the openssl-dev mailing list