| 
									
										
										
										
											2020-03-17 01:55:32 +08:00
										 |  |  | =pod | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | =head1 NAME | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-14 18:42:30 +08:00
										 |  |  | EVP_PKEY_is_a, EVP_PKEY_can_sign, EVP_PKEY_type_names_do_all, | 
					
						
							| 
									
										
										
										
											2021-07-13 17:15:29 +08:00
										 |  |  | EVP_PKEY_get0_type_name, EVP_PKEY_get0_description, EVP_PKEY_get0_provider | 
					
						
							| 
									
										
										
										
											2020-03-17 01:55:32 +08:00
										 |  |  | - key type and capabilities functions | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | =head1 SYNOPSIS | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  #include <openssl/evp.h> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  int EVP_PKEY_is_a(const EVP_PKEY *pkey, const char *name); | 
					
						
							|  |  |  |  int EVP_PKEY_can_sign(const EVP_PKEY *pkey); | 
					
						
							| 
									
										
										
										
											2021-04-14 18:42:30 +08:00
										 |  |  |  int EVP_PKEY_type_names_do_all(const EVP_PKEY *pkey, | 
					
						
							|  |  |  |                                 void (*fn)(const char *name, void *data), | 
					
						
							|  |  |  |                                 void *data); | 
					
						
							|  |  |  |  const char *EVP_PKEY_get0_type_name(const EVP_PKEY *key); | 
					
						
							| 
									
										
										
										
											2021-07-13 17:15:29 +08:00
										 |  |  |  const char *EVP_PKEY_get0_description(const EVP_PKEY *key); | 
					
						
							| 
									
										
										
										
											2021-07-13 16:40:45 +08:00
										 |  |  |  const OSSL_PROVIDER *EVP_PKEY_get0_provider(const EVP_PKEY *key); | 
					
						
							| 
									
										
										
										
											2020-09-14 23:30:50 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-17 01:55:32 +08:00
										 |  |  | =head1 DESCRIPTION | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | EVP_PKEY_is_a() checks if the key type of I<pkey> is I<name>. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | EVP_PKEY_can_sign() checks if the functionality for the key type of | 
					
						
							|  |  |  | I<pkey> supports signing.  No other check is done, such as whether | 
					
						
							|  |  |  | I<pkey> contains a private key. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-14 18:42:30 +08:00
										 |  |  | EVP_PKEY_type_names_do_all() traverses all names for I<pkey>'s key type, and | 
					
						
							| 
									
										
										
										
											2020-09-14 17:21:37 +08:00
										 |  |  | calls I<fn> with each name and I<data>.  For example, an RSA B<EVP_PKEY> may | 
					
						
							|  |  |  | be named both C<RSA> and C<rsaEncryption>. | 
					
						
							| 
									
										
										
										
											2021-04-14 18:42:30 +08:00
										 |  |  | The order of the names depends on the provider implementation that holds | 
					
						
							|  |  |  | the key. | 
					
						
							| 
									
										
										
										
											2020-09-14 17:21:37 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-14 18:42:30 +08:00
										 |  |  | EVP_PKEY_get0_type_name() returns the first key type name that is found | 
					
						
							| 
									
										
										
										
											2020-09-14 23:30:50 +08:00
										 |  |  | for the given I<pkey>. Note that the I<pkey> may have multiple synonyms | 
					
						
							| 
									
										
										
										
											2021-04-14 18:42:30 +08:00
										 |  |  | associated with it. In this case it depends on the provider implementation | 
					
						
							|  |  |  | that holds the key which one will be returned. | 
					
						
							| 
									
										
										
										
											2020-09-14 23:30:50 +08:00
										 |  |  | Ownership of the returned string is retained by the I<pkey> object and should | 
					
						
							|  |  |  | not be freed by the caller. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-13 17:15:29 +08:00
										 |  |  | EVP_PKEY_get0_description() returns a description of the type of B<EVP_PKEY>, | 
					
						
							|  |  |  | meant for display and human consumption.  The description is at the | 
					
						
							|  |  |  | discretion of the key type implementation. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-13 16:40:45 +08:00
										 |  |  | EVP_PKEY_get0_provider() returns the provider of the B<EVP_PKEY>'s | 
					
						
							|  |  |  | L<EVP_KEYMGMT(3)>. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-17 01:55:32 +08:00
										 |  |  | =head1 RETURN VALUES | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | EVP_PKEY_is_a() returns 1 if I<pkey> has the key type I<name>, | 
					
						
							|  |  |  | otherwise 0. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | EVP_PKEY_can_sign() returns 1 if the I<pkey> key type functionality | 
					
						
							|  |  |  | supports signing, otherwise 0. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-14 18:42:30 +08:00
										 |  |  | EVP_PKEY_get0_type_name() returns the name that is found or NULL on error. | 
					
						
							| 
									
										
										
										
											2020-09-14 23:30:50 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-13 17:15:29 +08:00
										 |  |  | EVP_PKEY_get0_description() returns the description if found or NULL if not. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-13 16:40:45 +08:00
										 |  |  | EVP_PKEY_get0_provider() returns the provider if found or NULL if not. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-14 18:42:30 +08:00
										 |  |  | EVP_PKEY_type_names_do_all() returns 1 if the callback was called for all | 
					
						
							|  |  |  | names. A return value of 0 means that the callback was not called for any | 
					
						
							|  |  |  | names. | 
					
						
							| 
									
										
										
										
											2021-02-20 01:03:43 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-17 01:55:32 +08:00
										 |  |  | =head1 EXAMPLES | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | =head2 EVP_PKEY_is_a() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | The loaded providers and what key types they support will ultimately | 
					
						
							|  |  |  | determine what I<name> is possible to use with EVP_PKEY_is_a().  We do know | 
					
						
							|  |  |  | that the default provider supports RSA, DH, DSA and EC keys, so we can use | 
					
						
							|  |  |  | this as an crude example: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  #include <openssl/evp.h> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  ... | 
					
						
							|  |  |  |      /* |pkey| is an EVP_PKEY* */ | 
					
						
							|  |  |  |      if (EVP_PKEY_is_a(pkey, "RSA")) { | 
					
						
							|  |  |  |          BIGNUM *modulus = NULL; | 
					
						
							|  |  |  |          if (EVP_PKEY_get_bn_param(pkey, "n", &modulus)) | 
					
						
							|  |  |  |              /* do whatever with the modulus */ | 
					
						
							|  |  |  |          BN_free(modulus); | 
					
						
							|  |  |  |      } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | =head2 EVP_PKEY_can_sign() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  #include <openssl/evp.h> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  ... | 
					
						
							|  |  |  |      /* |pkey| is an EVP_PKEY* */ | 
					
						
							|  |  |  |      if (!EVP_PKEY_can_sign(pkey)) { | 
					
						
							|  |  |  |          fprintf(stderr, "Not a signing key!"); | 
					
						
							|  |  |  |          exit(1); | 
					
						
							|  |  |  |      } | 
					
						
							|  |  |  |      /* Sign something... */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-14 23:30:50 +08:00
										 |  |  | =head1 HISTORY | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | The functions described here were added in OpenSSL 3.0. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-17 01:55:32 +08:00
										 |  |  | =head1 COPYRIGHT | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-11 21:27:36 +08:00
										 |  |  | Copyright 2020-2021 The OpenSSL Project Authors. All Rights Reserved. | 
					
						
							| 
									
										
										
										
											2020-03-17 01:55:32 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | Licensed under the Apache License 2.0 (the "License").  You may not use | 
					
						
							|  |  |  | this file except in compliance with the License.  You can obtain a copy | 
					
						
							|  |  |  | in the file LICENSE in the source distribution or at | 
					
						
							|  |  |  | L<https://www.openssl.org/source/license.html>. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | =cut |