abstract

## abstract abstract |

## Functions

int | gnutls_certificate_set_key ()
void | gnutls_certificate_set_retrieve_function2 ()
void | gnutls_pcert_deinit ()
int | gnutls_pcert_import_openpgp ()
int | gnutls_pcert_import_openpgp_raw ()
int | gnutls_pcert_import_x509 ()
int | gnutls_pcert_import_x509_raw ()
int | gnutls_pcert_list_import_x509_raw ()
int | gnutls_privkey_decrypt_data ()
int | (*gnutls_privkey_decrypt_func) ()
void | gnutls_privkey_deinit ()
void | (*gnutls_privkey_deinit_func) ()
int | gnutls_privkey_get_pk_algorithm ()
int | gnutls_privkey_import_ext ()
int | gnutls_privkey_import_ext2 ()
int | gnutls_privkey_import_openpgp ()
int | gnutls_privkey_import_openpgp_raw ()
int | gnutls_privkey_import_pkcs11 ()
int | gnutls_privkey_import_pkcs11_url ()
int | gnutls_privkey_import_tpm_raw ()
int | gnutls_privkey_import_tpm_url ()
int | gnutls_privkey_import_url ()
int | gnutls_privkey_import_x509 ()
int | gnutls_privkey_import_x509_raw ()
int | gnutls_privkey_init ()
void | gnutls_privkey_set_pin_function ()
int | gnutls_privkey_sign_data ()
int | (*gnutls_privkey_sign_func) ()
int | gnutls_privkey_sign_hash ()
void | gnutls_pubkey_deinit ()
int | gnutls_pubkey_encrypt_data ()
int | gnutls_pubkey_export ()
int | gnutls_pubkey_export2 ()
int | gnutls_pubkey_get_key_id ()
int | gnutls_pubkey_get_key_usage ()
int | gnutls_pubkey_get_openpgp_key_id ()
int | gnutls_pubkey_get_pk_algorithm ()
int | gnutls_pubkey_get_preferred_hash_algorithm ()
int | gnutls_pubkey_import ()
int | gnutls_pubkey_import_dsa_raw ()
int | gnutls_pubkey_import_ecc_raw ()
int | gnutls_pubkey_import_ecc_x962 ()
int | gnutls_pubkey_import_openpgp ()
int | gnutls_pubkey_import_openpgp_raw ()
int | gnutls_pubkey_import_pkcs11 ()
#define | gnutls_pubkey_import_pkcs11_url()
int | gnutls_pubkey_import_privkey ()
int | gnutls_pubkey_import_rsa_raw ()
int | gnutls_pubkey_import_tpm_raw ()
int | gnutls_pubkey_import_tpm_url ()
int | gnutls_pubkey_import_url ()
int | gnutls_pubkey_import_x509 ()
int | gnutls_pubkey_import_x509_crq ()
int | gnutls_pubkey_import_x509_raw ()
int | gnutls_pubkey_init ()
int | gnutls_pubkey_set_key_usage ()
void | gnutls_pubkey_set_pin_function ()
int | gnutls_pubkey_verify_data2 ()
int | gnutls_pubkey_verify_hash2 ()
int | gnutls_x509_crl_privkey_sign ()
int | gnutls_x509_crq_privkey_sign ()
int | gnutls_x509_crq_set_pubkey ()
int | gnutls_x509_crt_privkey_sign ()
int | gnutls_x509_crt_set_pubkey ()

## Types and Values

#define | GNUTLS_PCERT_NO_CERT
#define | GNUTLS_PUBKEY_VERIFY_FLAG_TLS_RSA
struct | gnutls_privkey_st
typedef | gnutls_privkey_t
#define | gnutls_pubkey_get_pk_dsa_raw
#define | gnutls_pubkey_get_pk_ecc_raw
#define | gnutls_pubkey_get_pk_ecc_x962
#define | gnutls_pubkey_get_pk_rsa_raw
struct | gnutls_pubkey_st
typedef | gnutls_pubkey_t

## Description

## Functions

### gnutls_certificate_set_key ()

    int
    gnutls_certificate_set_key (gnutls_certificate_credentials_t res,
                                const char **names,
                                int names_size,
                                gnutls_pcert_st *pcert_list,
                                int pcert_list_size,
                                gnutls_privkey_t key);

This function sets a public/private key pair in the gnutls_certificate_credentials_t type. The given public key may be encapsulated in a certificate or can be given as a raw key. This function may be called more than once, in case multiple key pairs exist for the server. For clients that want to send more than their own end- entity certificate (e.g., also an intermediate CA cert), the full certificate chain must be provided in `pcert_list` .

Note that the `key` will become part of the credentials structure and must not be deallocated. It will be automatically deallocated when the `res` structure is deinitialized.

If this function fails, the `res` structure is at an undefined state and it must not be reused to load other keys or certificates.

Note that, this function by default returns zero on success and a negative value on error. Since 3.5.6, when the flag `GNUTLS_CERTIFICATE_API_V2` is set using `gnutls_certificate_set_flags()` it returns an index (greater or equal to zero). That index can be used for other functions to refer to the added key-pair.

Since GnuTLS 3.6.6 this function also handles raw public keys.

#### Parameters

res | is a gnutls_certificate_credentials_t type. |
names | is an array of DNS names belonging to the public-key (NULL if none) |
names_size | holds the size of the names list |
pcert_list | contains a certificate list (chain) or raw public-key |
pcert_list_size | holds the size of the certificate list |
key | is a gnutls_privkey_t key corresponding to the first public-key in pcert_list |

#### Returns

On success this functions returns zero, and otherwise a negative value on error (see above for modifying that behavior).

Since: 3.0

### gnutls_certificate_set_retrieve_function2 ()

    void
    gnutls_certificate_set_retrieve_function2
                                   (gnutls_certificate_credentials_t cred,
                                    gnutls_certificate_retrieve_function2 *func);

This function sets a callback to be called in order to retrieve the certificate to be used in the handshake. The callback will take control only if a certificate is requested by the peer.

The callback's function prototype is: int (*callback)(gnutls_session_t, const gnutls_datum_t* req_ca_dn, int nreqs, const gnutls_pk_algorithm_t* pk_algos, int pk_algos_length, gnutls_pcert_st** pcert, unsigned int *pcert_length, gnutls_privkey_t * pkey);

`req_ca_dn` is only used in X.509 certificates. Contains a list with the CA names that the server considers trusted. This is a hint and typically the client should send a certificate that is signed by one of these CAs. These names, when available, are DER encoded. To get a more meaningful value use the function `gnutls_x509_rdn_get()`.

`pk_algos` contains a list with server's acceptable public key algorithms. The certificate returned should support the server's given algorithms.

`pcert` should contain a single certificate and public key or a list of them.

`pcert_length` is the size of the previous list.

`pkey` is the private key.

If the callback function is provided then gnutls will call it, in the handshake, after the certificate request message has been received. All the provided by the callback values will not be released or modified by gnutls.

In server side pk_algos and req_ca_dn are NULL.

The callback function should set the certificate list to be sent, and return 0 on success. If no certificate was selected then the number of certificates should be set to zero. The value (-1) indicates error and the handshake will be terminated. If both certificates are set in the credentials and a callback is available, the callback takes predence.

#### Parameters

cred | is a gnutls_certificate_credentials_t type. |
func | is the callback function |

Since: 3.0

### gnutls_pcert_deinit ()

    void
    gnutls_pcert_deinit (gnutls_pcert_st *pcert);

This function will deinitialize a pcert structure.

#### Parameters

pcert | The structure to be deinitialized |

Since: 3.0

### gnutls_pcert_import_openpgp ()

    int
    gnutls_pcert_import_openpgp (gnutls_pcert_st *pcert,
                                 gnutls_openpgp_crt_t crt,
                                 unsigned int flags);

This function is no-op.

#### Parameters

pcert | The pcert structure |
crt | The raw certificate to be imported |
flags | zero for now |

#### Returns

`GNUTLS_E_UNIMPLEMENTED_FEATURE`.

Since: 3.0

### gnutls_pcert_import_openpgp_raw ()

    int
    gnutls_pcert_import_openpgp_raw (gnutls_pcert_st *pcert,
                                     const gnutls_datum_t *cert,
                                     gnutls_openpgp_crt_fmt_t format,
                                     gnutls_openpgp_keyid_t keyid,
                                     unsigned int flags);

This function is no-op.

#### Parameters

pcert | The pcert structure |
cert | The raw certificate to be imported |
format | The format of the certificate |
keyid | The key ID to use (NULL for the master key) |
flags | zero for now |

#### Returns

`GNUTLS_E_UNIMPLEMENTED_FEATURE`.

Since: 3.0

### gnutls_pcert_import_x509 ()

    int
    gnutls_pcert_import_x509 (gnutls_pcert_st *pcert,
                              gnutls_x509_crt_t crt,
                              unsigned int flags);

This convenience function will import the given certificate to a gnutls_pcert_st structure. The structure must be deinitialized afterwards using `gnutls_pcert_deinit()`;

#### Parameters

pcert | The pcert structure |
crt | The certificate to be imported |
flags | zero for now |

#### Returns

On success, `GNUTLS_E_SUCCESS` (0) is returned, otherwise a negative error value.

Since: 3.0

### gnutls_pcert_import_x509_raw ()

    int
    gnutls_pcert_import_x509_raw (gnutls_pcert_st *pcert,
                                  const gnutls_datum_t *cert,
                                  gnutls_x509_crt_fmt_t format,
                                  unsigned int flags);

This convenience function will import the given certificate to a gnutls_pcert_st structure. The structure must be deinitialized afterwards using `gnutls_pcert_deinit()`;

#### Parameters

pcert | The pcert structure |
cert | The raw certificate to be imported |
format | The format of the certificate |
flags | zero for now |

#### Returns

On success, `GNUTLS_E_SUCCESS` (0) is returned, otherwise a negative error value.

Since: 3.0

### gnutls_pcert_list_import_x509_raw ()

    int
    gnutls_pcert_list_import_x509_raw (gnutls_pcert_st *pcerts,
                                       unsigned int *pcert_max,
                                       const gnutls_datum_t *data,
                                       gnutls_x509_crt_fmt_t format,
                                       unsigned int flags);

This function will import the provided DER or PEM encoded certificates to an already allocated set of gnutls_pcert_st structures. The structures must be deinitialized afterwards using `gnutls_pcert_deinit()`. `pcert_list` should contain space for at least `pcert_list_size` elements.

If the Certificate is PEM encoded it should have a header of "X509 CERTIFICATE", or "CERTIFICATE".

#### Parameters

pcert_list | The structures to store the certificates; must not contain initialized gnutls_pcert_st structures. |
pcert_list_size | Initially must hold the maximum number of certs. It will be updated with the number of certs available. |
data | The certificates. |
format | One of DER or PEM. |
flags | must be (0) or an OR'd sequence of gnutls_certificate_import_flags. |

#### Returns

On success, `GNUTLS_E_SUCCESS` (0) is returned, otherwise a negative error value; if the `pcert` list doesn't have enough space `GNUTLS_E_SHORT_MEMORY_BUFFER` will be returned.

Since: 3.0

### gnutls_privkey_decrypt_data ()

    int
    gnutls_privkey_decrypt_data (gnutls_privkey_t key,
                                 unsigned int flags,
                                 const gnutls_datum_t *ciphertext,
                                 gnutls_datum_t *plaintext);

This function will decrypt the given data using the algorithm supported by the private key.

#### Parameters

key | Holds the key |
flags | zero for now |
ciphertext | holds the data to be decrypted |
plaintext | will contain the decrypted data, allocated with `gnutls_malloc()` |

#### Returns

On success, `GNUTLS_E_SUCCESS` (0) is returned, otherwise a negative error value.

Since: 2.12.0

### gnutls_privkey_decrypt_func ()

    int
    (*gnutls_privkey_decrypt_func) (gnutls_privkey_t key,
                                    void *userdata,
                                    const gnutls_datum_t *ciphertext,
                                    gnutls_datum_t *plaintext);

### gnutls_privkey_deinit ()

    void
    gnutls_privkey_deinit (gnutls_privkey_t key);

This function will deinitialize a private key structure.

#### Parameters

key | The key to be deinitialized |

Since: 2.12.0

### gnutls_privkey_deinit_func ()

    void
    (*gnutls_privkey_deinit_func) (gnutls_privkey_t key,
                                   void *userdata);

### gnutls_privkey_get_pk_algorithm ()

    int
    gnutls_privkey_get_pk_algorithm (gnutls_privkey_t key,
                                     unsigned int *bits);

This function will return the public key algorithm of a private key and if possible will return a number of bits that indicates the security parameter of the key.

#### Parameters

key | should contain a gnutls_privkey_t type |
bits | If set will return the number of bits of the parameters (may be NULL) |

#### Returns

a member of the gnutls_pk_algorithm_t enumeration on success, or a negative error code on error.

Since: 2.12.0

### gnutls_privkey_import_ext ()

    int
    gnutls_privkey_import_ext (gnutls_privkey_t pkey,
                               gnutls_pk_algorithm_t pk,
                               void *userdata,
                               gnutls_privkey_sign_func sign_func,
                               gnutls_privkey_decrypt_func decrypt_func,
                               unsigned int flags);

This function will associate the given callbacks with the gnutls_privkey_t type. At least one of the two callbacks must be non-null.

Note that the signing function is supposed to "raw" sign data, i.e., without any hashing or preprocessing. In case of RSA the DigestInfo will be provided, and the signing function is expected to do the PKCS #1 1.5 padding and the exponentiation.

See also `gnutls_privkey_import_ext3()`.

#### Parameters

pkey | The private key |
pk | The public key algorithm |
userdata | private data to be provided to the callbacks |
sign_func | callback for signature operations |
decrypt_func | callback for decryption operations |
flags | Flags for the import |

#### Returns

On success, `GNUTLS_E_SUCCESS` (0) is returned, otherwise a negative error value.

Since: 3.0

### gnutls_privkey_import_ext2 ()

    int
    gnutls_privkey_import_ext2 (gnutls_privkey_t pkey,
                                gnutls_pk_algorithm_t pk,
                                void *userdata,
                                gnutls_privkey_sign_func sign_func,
                                gnutls_privkey_decrypt_func decrypt_func,
                                gnutls_privkey_deinit_func deinit_func,
                                unsigned int flags);

This function will associate the given callbacks with the gnutls_privkey_t type. At least one of the two callbacks must be non-null. If a deinitialization function is provided then flags is assumed to contain `GNUTLS_PRIVKEY_IMPORT_AUTO_RELEASE`.

Note that the signing function is supposed to "raw" sign data, i.e., without any hashing or preprocessing. In case of RSA the DigestInfo will be provided, and the signing function is expected to do the PKCS #1 1.5 padding and the exponentiation.

See also `gnutls_privkey_import_ext3()`.

#### Parameters

pkey | The private key |
pk | The public key algorithm |
userdata | private data to be provided to the callbacks |
sign_fn | callback for signature operations |
decrypt_fn | callback for decryption operations |
deinit_fn | a deinitialization function |
flags | Flags for the import |

#### Returns

On success, `GNUTLS_E_SUCCESS` (0) is returned, otherwise a negative error value.

Since: 3.1

### gnutls_privkey_import_openpgp ()

    int
    gnutls_privkey_import_openpgp (gnutls_privkey_t pkey,
                                   gnutls_openpgp_privkey_t key,
                                   unsigned int flags);

This function is no-op.

#### Parameters

pkey | The private key |
key | The private key to be imported |
flags | Flags for the import |

#### Returns

`GNUTLS_E_UNIMPLEMENTED_FEATURE`.

Since: 2.12.0

### gnutls_privkey_import_openpgp_raw ()

    int
    gnutls_privkey_import_openpgp_raw (gnutls_privkey_t pkey,
                                       const gnutls_datum_t *data,
                                       gnutls_openpgp_crt_fmt_t format,
                                       const gnutls_openpgp_keyid_t keyid,
                                       const char *password);

This function is no-op.

#### Parameters

pkey | The private key |
data | The private key data to be imported |
format | The format of the private key |
keyid | The key id to use (optional) |
password | A password (optional) |

#### Returns

`GNUTLS_E_UNIMPLEMENTED_FEATURE`.

Since: 3.1.0

### gnutls_privkey_import_pkcs11 ()

    int
    gnutls_privkey_import_pkcs11 (gnutls_privkey_t pkey,
                                  gnutls_pkcs11_privkey_t key,
                                  unsigned int flags);

This function will import the given private key to the abstract gnutls_privkey_t type.

The gnutls_pkcs11_privkey_t object must not be deallocated during the lifetime of this structure.

`flags` might be zero or one of `GNUTLS_PRIVKEY_IMPORT_AUTO_RELEASE` and `GNUTLS_PRIVKEY_IMPORT_COPY`.

#### Parameters

pkey | The private key |
key | The private key to be imported |
flags | Flags for the import |

#### Returns

On success, `GNUTLS_E_SUCCESS` (0) is returned, otherwise a negative error value.

Since: 2.12.0

### gnutls_privkey_import_pkcs11_url ()

    int
    gnutls_privkey_import_pkcs11_url (gnutls_privkey_t key,
                                      const char *url);

This function will import a PKCS 11 private key to a gnutls_private_key_t type.

#### Parameters

key | A key of type gnutls_pubkey_t |
url | A PKCS 11 url |

#### Returns

On success, `GNUTLS_E_SUCCESS` (0) is returned, otherwise a negative error value.

Since: 3.1.0

### gnutls_privkey_import_tpm_raw ()

    int
    gnutls_privkey_import_tpm_raw (gnutls_privkey_t pkey,
                                   const gnutls_datum_t *fdata,
                                   gnutls_tpmkey_fmt_t format,
                                   const char *srk_password,
                                   const char *key_password,
                                   unsigned int flags);

This function will import the given private key to the abstract gnutls_privkey_t type.

With respect to passwords the same as in `gnutls_privkey_import_tpm_url()` apply.

#### Parameters

pkey | The private key |
fdata | The TPM key to be imported |
format | The format of the private key |
srk_password | The password for the SRK key (optional) |
key_password | A password for the key (optional) |
flags | should be zero |

#### Returns

On success, `GNUTLS_E_SUCCESS` (0) is returned, otherwise a negative error value.

Since: 3.1.0

### gnutls_privkey_import_tpm_url ()

    int
    gnutls_privkey_import_tpm_url (gnutls_privkey_t pkey,
                                   const char *url,
                                   const char *srk_password,
                                   const char *key_password,
                                   unsigned int flags);

This function will import the given private key to the abstract gnutls_privkey_t type.

Note that unless `GNUTLS_PRIVKEY_DISABLE_CALLBACKS` is specified, if incorrect (or NULL) passwords are given the PKCS11 callback functions will be used to obtain the correct passwords. Otherwise if the SRK password is wrong `GNUTLS_E_TPM_SRK_PASSWORD_ERROR` is returned and if the key password is wrong or not provided then `GNUTLS_E_TPM_KEY_PASSWORD_ERROR` is returned.

#### Parameters

pkey | The private key |
url | The URL of the TPM key to be imported |
srk_password | The password for the SRK key (optional) |
key_password | A password for the key (optional) |
flags | One of the GNUTLS_PRIVKEY_* flags |

#### Returns

On success, `GNUTLS_E_SUCCESS` (0) is returned, otherwise a negative error value.

Since: 3.1.0

### gnutls_privkey_import_url ()

    int
    gnutls_privkey_import_url (gnutls_privkey_t key,
                               const char *url,
                               unsigned int flags);

This function will import a PKCS11 or TPM URL as a private key. The supported URL types can be checked using `gnutls_url_is_supported()`.

#### Parameters

key | A key of type gnutls_privkey_t |
url | A PKCS 11 url |
flags | should be zero |

#### Returns

On success, `GNUTLS_E_SUCCESS` (0) is returned, otherwise a negative error value.

Since: 3.1.0

### gnutls_privkey_import_x509 ()

    int
    gnutls_privkey_import_x509 (gnutls_privkey_t pkey,
                                gnutls_x509_privkey_t key,
                                unsigned int flags);

This function will import the given private key to the abstract gnutls_privkey_t type.

The gnutls_x509_privkey_t object must not be deallocated during the lifetime of this structure.

`flags` might be zero or one of `GNUTLS_PRIVKEY_IMPORT_AUTO_RELEASE` and `GNUTLS_PRIVKEY_IMPORT_COPY`.

#### Parameters

pkey | The private key |
key | The private key to be imported |
flags | Flags for the import |

#### Returns

On success, `GNUTLS_E_SUCCESS` (0) is returned, otherwise a negative error value.

Since: 2.12.0

### gnutls_privkey_import_x509_raw ()

    int
    gnutls_privkey_import_x509_raw (gnutls_privkey_t pkey,
                                    const gnutls_datum_t *data,
                                    gnutls_x509_crt_fmt_t format,
                                    const char *password,
                                    unsigned int flags);

This function will import the given private key to the abstract gnutls_privkey_t type.

The supported formats are basic unencrypted key, PKCS8, PKCS12, and the openssl format.

#### Parameters

pkey | The private key |
data | The private key data to be imported |
format | The format of the private key |
password | A password (optional) |
flags | an ORed sequence of gnutls_pkcs_encrypt_flags_t |

#### Returns

On success, `GNUTLS_E_SUCCESS` (0) is returned, otherwise a negative error value.

Since: 3.1.0

### gnutls_privkey_init ()

    int
    gnutls_privkey_init (gnutls_privkey_t *key);

This function will initialize a private key object. The object can be used to generate, import, and perform cryptographic operations on the associated private key.

Note that when the underlying private key is a PKCS11 key (i.e., when imported with a PKCS11 URI), the limitations of `gnutls_pkcs11_privkey_init()` apply to this object as well. In versions of GnuTLS later than 3.5.11 the object is protected using locks and a single `gnutls_privkey_t` can be re-used by many threads. However, for performance it is recommended to utilize one object per key per thread.

#### Parameters

key | A pointer to the type to be initialized |

#### Returns

On success, `GNUTLS_E_SUCCESS` (0) is returned, otherwise a negative error value.

Since: 2.12.0

### gnutls_privkey_set_pin_function ()

    void
    gnutls_privkey_set_pin_function (gnutls_privkey_t key,
                                     gnutls_pin_callback_t fn,
                                     void *userdata);

This function will set a callback function to be used when required to access the object. This function overrides any other global PIN functions.

Note that this function must be called right after initialization to have effect.

#### Parameters

key | A key of type gnutls_privkey_t |
fn | the callback |
userdata | data associated with the callback |

Since: 3.1.0

### gnutls_privkey_sign_data ()

    int
    gnutls_privkey_sign_data (gnutls_privkey_t signer,
                              gnutls_digest_algorithm_t hash,
                              unsigned int flags,
                              const gnutls_datum_t *data,
                              gnutls_datum_t *signature);

This function will sign the given data using a signature algorithm supported by the private key. Signature algorithms are always used together with a hash functions. Different hash functions may be used for the RSA algorithm, but only the SHA family for the DSA keys.

You may use `gnutls_pubkey_get_preferred_hash_algorithm()` to determine the hash algorithm.

#### Parameters

signer | Holds the key |
hash | should be a digest algorithm |
flags | Zero or one of `gnutls_privkey_flags_t` |
data | holds the data to be signed |
signature | will contain the signature allocated with `gnutls_malloc()` |

#### Returns

On success, `GNUTLS_E_SUCCESS` (0) is returned, otherwise a negative error value.

Since: 2.12.0

### gnutls_privkey_sign_func ()

    int
    (*gnutls_privkey_sign_func) (gnutls_privkey_t key,
                                 void *userdata,
                                 const gnutls_datum_t *raw_data,
                                 gnutls_datum_t *signature);

### gnutls_privkey_sign_hash ()

    int
    gnutls_privkey_sign_hash (gnutls_privkey_t signer,
                              gnutls_digest_algorithm_t hash_algo,
                              unsigned int flags,
                              const gnutls_datum_t *hash_data,
                              gnutls_datum_t *signature);

This function will sign the given hashed data using a signature algorithm supported by the private key. Signature algorithms are always used together with a hash functions. Different hash functions may be used for the RSA algorithm, but only SHA-XXX for the DSA keys.

You may use `gnutls_pubkey_get_preferred_hash_algorithm()` to determine the hash algorithm.

The flags may be `GNUTLS_PRIVKEY_SIGN_FLAG_TLS1_RSA` or `GNUTLS_PRIVKEY_SIGN_FLAG_RSA_PSS`. In the former case this function will ignore `hash_algo` and perform a raw PKCS1 signature, and in the latter an RSA-PSS signature will be generated.

Note that, not all algorithm support signing already hashed data. When signing with Ed25519, `gnutls_privkey_sign_data()` should be used.

#### Parameters

signer | Holds the signer's key |
hash_algo | The hash algorithm used |
flags | Zero or one of `gnutls_privkey_flags_t` |
hash_data | holds the data to be signed |
signature | will contain newly allocated signature |

#### Returns

On success, `GNUTLS_E_SUCCESS` (0) is returned, otherwise a negative error value.

Since: 2.12.0

### gnutls_pubkey_deinit ()

    void
    gnutls_pubkey_deinit (gnutls_pubkey_t key);

This function will deinitialize a public key structure.

#### Parameters

key | The key to be deinitialized |

Since: 2.12.0

### gnutls_pubkey_encrypt_data ()

    int
    gnutls_pubkey_encrypt_data (gnutls_pubkey_t key,
                                unsigned int flags,
                                const gnutls_datum_t *plaintext,
                                gnutls_datum_t *ciphertext);

This function will encrypt the given data, using the public key. On success the `ciphertext` will be allocated using `gnutls_malloc()`.

#### Parameters

key | Holds the public key |
flags | should be 0 for now |
plaintext | The data to be encrypted |
ciphertext | contains the encrypted data |

#### Returns

On success, `GNUTLS_E_SUCCESS` (0) is returned, otherwise a negative error value.

Since: 3.0

### gnutls_pubkey_export ()

    int
    gnutls_pubkey_export (gnutls_pubkey_t key,
                          gnutls_x509_crt_fmt_t format,
                          void *output_data,
                          size_t *output_data_size);

This function will export the public key to DER or PEM format. The contents of the exported data is the SubjectPublicKeyInfo X.509 structure.

If the buffer provided is not long enough to hold the output, then *output_data_size is updated and `GNUTLS_E_SHORT_MEMORY_BUFFER` will be returned.

If the structure is PEM encoded, it will have a header of "BEGIN CERTIFICATE".

#### Parameters

key | Holds the certificate |
format | the format of output params. One of PEM or DER. |
output_data | will contain a certificate PEM or DER encoded |
output_data_size | holds the size of output_data (and will be replaced by the actual size of parameters) |

#### Returns

In case of failure a negative error code will be returned, and 0 on success.

Since: 2.12.0

### gnutls_pubkey_export2 ()

    int
    gnutls_pubkey_export2 (gnutls_pubkey_t key,
                           gnutls_x509_crt_fmt_t format,
                           gnutls_datum_t *out);

This function will export the public key to DER or PEM format. The contents of the exported data is the SubjectPublicKeyInfo X.509 structure.

The output buffer will be allocated using `gnutls_malloc()`.

If the structure is PEM encoded, it will have a header of "BEGIN CERTIFICATE".

#### Parameters

key | Holds the certificate |
format | the format of output params. One of PEM or DER. |
out | will contain a certificate PEM or DER encoded |

#### Returns

In case of failure a negative error code will be returned, and 0 on success.

Since: 3.1.3

### gnutls_pubkey_get_key_id ()

    int
    gnutls_pubkey_get_key_id (gnutls_pubkey_t key,
                              unsigned int flags,
                              unsigned char *output_data,
                              size_t *output_data_size);

This function will return a unique ID that depends on the public key parameters. This ID can be used in checking whether a certificate corresponds to the given public key.

If the buffer provided is not long enough to hold the output, then *output_data_size is updated and `GNUTLS_E_SHORT_MEMORY_BUFFER` will be returned. The output will normally be a SHA-1 hash output, which is 20 bytes.

#### Parameters

key | Holds the public key |
flags | should be one of the flags from `gnutls_keyid_flags_t` |
output_data | will contain the key ID |
output_data_size | holds the size of output_data (and will be replaced by the actual size of parameters) |

#### Returns

In case of failure a negative error code will be returned, and 0 on success.

Since: 2.12.0

### gnutls_pubkey_get_key_usage ()

    int
    gnutls_pubkey_get_key_usage (gnutls_pubkey_t key,
                                 unsigned int *usage);

This function will return the key usage of the public key.

#### Parameters

key | should contain a gnutls_pubkey_t type |
usage | If set will return the number of bits of the parameters (may be NULL) |

#### Returns

On success, `GNUTLS_E_SUCCESS` (0) is returned, otherwise a negative error value.

Since: 2.12.0

### gnutls_pubkey_get_openpgp_key_id ()

    int
    gnutls_pubkey_get_openpgp_key_id (gnutls_pubkey_t key,
                                      unsigned int flags,
                                      unsigned char *output_data,
                                      size_t *output_data_size,
                                      unsigned int *subkey);

### gnutls_pubkey_get_pk_algorithm ()

    int
    gnutls_pubkey_get_pk_algorithm (gnutls_pubkey_t key,
                                    unsigned int *bits);

This function will return the public key algorithm of a public key and if possible will return a number of bits that indicates the security parameter of the key.

#### Parameters

key | should contain a gnutls_pubkey_t type |
bits | If set will return the number of bits of the parameters (may be NULL) |

#### Returns

a member of the gnutls_pk_algorithm_t enumeration on success, or a negative error code on error.

Since: 2.12.0

### gnutls_pubkey_get_preferred_hash_algorithm ()

    int
    gnutls_pubkey_get_preferred_hash_algorithm
                                   (gnutls_pubkey_t key,
                                    gnutls_digest_algorithm_t *hash,
                                    unsigned int *mand);

This function will read the certificate and return the appropriate digest algorithm to use for signing with this certificate. Some certificates (i.e. DSA might not be able to sign without the preferred algorithm).

To get the signature algorithm instead of just the hash use `gnutls_pk_to_sign()` with the algorithm of the certificate/key and the provided `hash` .

#### Parameters

key | Holds the certificate |
hash | The result of the call with the hash algorithm used for signature |
mand | If non zero it means that the algorithm MUST use this hash. May be NULL. |

#### Returns

the 0 if the hash algorithm is found. A negative error code is returned on error.

Since: 2.12.0

### gnutls_pubkey_import ()

    int
    gnutls_pubkey_import (gnutls_pubkey_t key,
                          const gnutls_datum_t *data,
                          gnutls_x509_crt_fmt_t format);

This function will import the provided public key in a SubjectPublicKeyInfo X.509 structure to a native `gnutls_pubkey_t` type. The output will be stored in `key` . If the public key is PEM encoded it should have a header of "PUBLIC KEY".

#### Parameters

key | The public key. |
data | The DER or PEM encoded certificate. |
format | One of DER or PEM |

#### Returns

On success, `GNUTLS_E_SUCCESS` (0) is returned, otherwise a negative error value.

Since: 2.12.0

### gnutls_pubkey_import_dsa_raw ()

    int
    gnutls_pubkey_import_dsa_raw (gnutls_pubkey_t key,
                                  const gnutls_datum_t *p,
                                  const gnutls_datum_t *q,
                                  const gnutls_datum_t *g,
                                  const gnutls_datum_t *y);

This function will convert the given DSA raw parameters to the native gnutls_pubkey_t format. The output will be stored in `key` .

#### Parameters

key | The structure to store the parsed key |
p | holds the p |
q | holds the q |
g | holds the g |
y | holds the y |

#### Returns

On success, `GNUTLS_E_SUCCESS` (0) is returned, otherwise a negative error value.

Since: 2.12.0

### gnutls_pubkey_import_ecc_raw ()

    int
    gnutls_pubkey_import_ecc_raw (gnutls_pubkey_t key,
                                  gnutls_ecc_curve_t curve,
                                  const gnutls_datum_t *x,
                                  const gnutls_datum_t *y);

This function will convert the given elliptic curve parameters to a gnutls_pubkey_t. The output will be stored in `key` .

In EdDSA curves the `y` parameter should be `NULL` and the `x` parameter must be the value in the native format for the curve.

#### Parameters

key | The structure to store the parsed key |
curve | holds the curve |
x | holds the x-coordinate |
y | holds the y-coordinate |

#### Returns

On success, `GNUTLS_E_SUCCESS` (0) is returned, otherwise a negative error value.

Since: 3.0

### gnutls_pubkey_import_ecc_x962 ()

    int
    gnutls_pubkey_import_ecc_x962 (gnutls_pubkey_t key,
                                   const gnutls_datum_t *parameters,
                                   const gnutls_datum_t *ecpoint);

This function will convert the given elliptic curve parameters to a gnutls_pubkey_t. The output will be stored in `key` .

#### Parameters

key | The structure to store the parsed key |
parameters | DER encoding of an ANSI X9.62 parameters |
ecpoint | DER encoding of ANSI X9.62 ECPoint |

#### Returns

On success, `GNUTLS_E_SUCCESS` (0) is returned, otherwise a negative error value.

Since: 3.0

### gnutls_pubkey_import_openpgp ()

    int
    gnutls_pubkey_import_openpgp (gnutls_pubkey_t key,
                                  gnutls_openpgp_crt_t crt,
                                  unsigned int flags);

This function is no-op.

#### Parameters

key | The public key |
crt | The certificate to be imported |
flags | should be zero |

#### Returns

`GNUTLS_E_UNIMPLEMENTED_FEATURE`.

Since: 2.12.0

### gnutls_pubkey_import_openpgp_raw ()

    int
    gnutls_pubkey_import_openpgp_raw (gnutls_pubkey_t pkey,
                                      const gnutls_datum_t *data,
                                      gnutls_openpgp_crt_fmt_t format,
                                      const gnutls_openpgp_keyid_t keyid,
                                      unsigned int flags);

This function is no-op.

#### Parameters

pkey | The public key |
data | The public key data to be imported |
format | The format of the public key |
keyid | The key id to use (optional) |
flags | Should be zero |

#### Returns

`GNUTLS_E_UNIMPLEMENTED_FEATURE`.

Since: 3.1.3

### gnutls_pubkey_import_pkcs11 ()

    int
    gnutls_pubkey_import_pkcs11 (gnutls_pubkey_t key,
                                 gnutls_pkcs11_obj_t obj,
                                 unsigned int flags);

Imports a public key from a pkcs11 key. This function will import the given public key to the abstract gnutls_pubkey_t type.

#### Parameters

key | The public key |
obj | The parameters to be imported |
flags | should be zero |

#### Returns

On success, `GNUTLS_E_SUCCESS` (0) is returned, otherwise a negative error value.

Since: 2.12.0

### gnutls_pubkey_import_pkcs11_url()

    #define gnutls_pubkey_import_pkcs11_url(key, url, flags) gnutls_pubkey_import_url(key, url, flags)

This function will import a PKCS 11 certificate to a gnutls_pubkey_t structure.

#### Parameters

key | A key of type gnutls_pubkey_t |
url | A PKCS 11 url |
flags | One of GNUTLS_PKCS11_OBJ_* flags |

#### Returns

On success, `GNUTLS_E_SUCCESS` (0) is returned, otherwise a negative error value.

Since: 2.12.0

### gnutls_pubkey_import_privkey ()

    int
    gnutls_pubkey_import_privkey (gnutls_pubkey_t key,
                                  gnutls_privkey_t pkey,
                                  unsigned int usage,
                                  unsigned int flags);

Imports the public key from a private. This function will import the given public key to the abstract gnutls_pubkey_t type.

Note that in certain keys this operation may not be possible, e.g., in other than RSA PKCS11 keys.

#### Parameters

key | The public key |
pkey | The private key |
usage | GNUTLS_KEY_* key usage flags. |
flags | should be zero |

#### Returns

On success, `GNUTLS_E_SUCCESS` (0) is returned, otherwise a negative error value.

Since: 2.12.0

### gnutls_pubkey_import_rsa_raw ()

    int
    gnutls_pubkey_import_rsa_raw (gnutls_pubkey_t key,
                                  const gnutls_datum_t *m,
                                  const gnutls_datum_t *e);

This function will replace the parameters in the given structure. The new parameters should be stored in the appropriate gnutls_datum.

#### Parameters

key | The key |
m | holds the modulus |
e | holds the public exponent |

#### Returns

`GNUTLS_E_SUCCESS` on success, or an negative error code.

Since: 2.12.0

### gnutls_pubkey_import_tpm_raw ()

    int
    gnutls_pubkey_import_tpm_raw (gnutls_pubkey_t pkey,
                                  const gnutls_datum_t *fdata,
                                  gnutls_tpmkey_fmt_t format,
                                  const char *srk_password,
                                  unsigned int flags);

This function will import the public key from the provided TPM key structure.

With respect to passwords the same as in `gnutls_pubkey_import_tpm_url()` apply.

#### Parameters

pkey | The public key |
fdata | The TPM key to be imported |
format | The format of the private key |
srk_password | The password for the SRK key (optional) |
flags | One of the GNUTLS_PUBKEY_* flags |

#### Returns

On success, `GNUTLS_E_SUCCESS` (0) is returned, otherwise a negative error value.

Since: 3.1.0

### gnutls_pubkey_import_tpm_url ()

    int
    gnutls_pubkey_import_tpm_url (gnutls_pubkey_t pkey,
                                  const char *url,
                                  const char *srk_password,
                                  unsigned int flags);

This function will import the given private key to the abstract gnutls_privkey_t type.

Note that unless `GNUTLS_PUBKEY_DISABLE_CALLBACKS` is specified, if incorrect (or NULL) passwords are given the PKCS11 callback functions will be used to obtain the correct passwords. Otherwise if the SRK password is wrong `GNUTLS_E_TPM_SRK_PASSWORD_ERROR` is returned.

#### Parameters

pkey | The public key |
url | The URL of the TPM key to be imported |
srk_password | The password for the SRK key (optional) |
flags | should be zero |

#### Returns

On success, `GNUTLS_E_SUCCESS` (0) is returned, otherwise a negative error value.

Since: 3.1.0

### gnutls_pubkey_import_url ()

    int
    gnutls_pubkey_import_url (gnutls_pubkey_t key,
                              const char *url,
                              unsigned int flags);

This function will import a public key from the provided URL.

#### Parameters

key | A key of type gnutls_pubkey_t |
url | A PKCS 11 url |
flags | One of GNUTLS_PKCS11_OBJ_* flags |

#### Returns

On success, `GNUTLS_E_SUCCESS` (0) is returned, otherwise a negative error value.

Since: 3.1.0

### gnutls_pubkey_import_x509 ()

    int
    gnutls_pubkey_import_x509 (gnutls_pubkey_t key,
                               gnutls_x509_crt_t crt,
                               unsigned int flags);

This function will import the given public key to the abstract gnutls_pubkey_t type.

#### Parameters

key | The public key |
crt | The certificate to be imported |
flags | should be zero |

#### Returns

On success, `GNUTLS_E_SUCCESS` (0) is returned, otherwise a negative error value.

Since: 2.12.0

### gnutls_pubkey_import_x509_crq ()

    int
    gnutls_pubkey_import_x509_crq (gnutls_pubkey_t key,
                                   gnutls_x509_crq_t crq,
                                   unsigned int flags);

This function will import the given public key to the abstract gnutls_pubkey_t type.

#### Parameters

key | The public key |
crq | The certificate to be imported |
flags | should be zero |

#### Returns

On success, `GNUTLS_E_SUCCESS` (0) is returned, otherwise a negative error value.

Since: 3.1.5

### gnutls_pubkey_import_x509_raw ()

    int
    gnutls_pubkey_import_x509_raw (gnutls_pubkey_t pkey,
                                   const gnutls_datum_t *data,
                                   gnutls_x509_crt_fmt_t format,
                                   unsigned int flags);

This function will import the given public key to the abstract gnutls_pubkey_t type.

#### Parameters

pkey | The public key |
data | The public key data to be imported |
format | The format of the public key |
flags | should be zero |

#### Returns

On success, `GNUTLS_E_SUCCESS` (0) is returned, otherwise a negative error value.

Since: 3.1.3

### gnutls_pubkey_init ()

    int
    gnutls_pubkey_init (gnutls_pubkey_t *key);

This function will initialize a public key.

#### Parameters

key | A pointer to the type to be initialized |

#### Returns

On success, `GNUTLS_E_SUCCESS` (0) is returned, otherwise a negative error value.

Since: 2.12.0

### gnutls_pubkey_set_key_usage ()

    int
    gnutls_pubkey_set_key_usage (gnutls_pubkey_t key,
                                 unsigned int usage);

This function will set the key usage flags of the public key. This is only useful if the key is to be exported to a certificate or certificate request.

#### Parameters

key | a certificate of type gnutls_x509_crt_t |
usage | an ORed sequence of the GNUTLS_KEY_* elements. |

#### Returns

On success, `GNUTLS_E_SUCCESS` (0) is returned, otherwise a negative error value.

Since: 2.12.0

### gnutls_pubkey_set_pin_function ()

    void
    gnutls_pubkey_set_pin_function (gnutls_pubkey_t key,
                                    gnutls_pin_callback_t fn,
                                    void *userdata);

This function will set a callback function to be used when required to access the object. This function overrides any other global PIN functions.

Note that this function must be called right after initialization to have effect.

#### Parameters

key | A key of type gnutls_pubkey_t |
fn | the callback |
userdata | data associated with the callback |

Since: 3.1.0

### gnutls_pubkey_verify_data2 ()

    int
    gnutls_pubkey_verify_data2 (gnutls_pubkey_t pubkey,
                                gnutls_sign_algorithm_t algo,
                                unsigned int flags,
                                const gnutls_datum_t *data,
                                const gnutls_datum_t *signature);

This function will verify the given signed data, using the parameters from the certificate.

#### Parameters

pubkey | Holds the public key |
algo | The signature algorithm used |
flags | Zero or an OR list of gnutls_certificate_verify_flags |
data | holds the signed data |
signature | contains the signature |

#### Returns

In case of a verification failure `GNUTLS_E_PK_SIG_VERIFY_FAILED` is returned, and zero or positive code on success. For known to be insecure signatures this function will return `GNUTLS_E_INSUFFICIENT_SECURITY` unless the flag `GNUTLS_VERIFY_ALLOW_BROKEN` is specified.

Since: 3.0

### gnutls_pubkey_verify_hash2 ()

    int
    gnutls_pubkey_verify_hash2 (gnutls_pubkey_t key,
                                gnutls_sign_algorithm_t algo,
                                unsigned int flags,
                                const gnutls_datum_t *hash,
                                const gnutls_datum_t *signature);

This function will verify the given signed digest, using the parameters from the public key. Note that unlike `gnutls_privkey_sign_hash()`, this function accepts a signature algorithm instead of a digest algorithm. You can use `gnutls_pk_to_sign()` to get the appropriate value.

#### Parameters

key | Holds the public key |
algo | The signature algorithm used |
flags | Zero or an OR list of gnutls_certificate_verify_flags |
hash | holds the hash digest to be verified |
signature | contains the signature |

#### Returns

In case of a verification failure `GNUTLS_E_PK_SIG_VERIFY_FAILED` is returned, and zero or positive code on success. For known to be insecure signatures this function will return `GNUTLS_E_INSUFFICIENT_SECURITY` unless the flag `GNUTLS_VERIFY_ALLOW_BROKEN` is specified.

Since: 3.0

### gnutls_x509_crl_privkey_sign ()

    int
    gnutls_x509_crl_privkey_sign (gnutls_x509_crl_t crl,
                                  gnutls_x509_crt_t issuer,
                                  gnutls_privkey_t issuer_key,
                                  gnutls_digest_algorithm_t dig,
                                  unsigned int flags);

This function will sign the CRL with the issuer's private key, and will copy the issuer's information into the CRL.

This must be the last step in a certificate CRL since all the previously set parameters are now signed.

A known limitation of this function is, that a newly-signed CRL will not be fully functional (e.g., for signature verification), until it is exported an re-imported.

After GnuTLS 3.6.1 the value of `dig` may be `GNUTLS_DIG_UNKNOWN`, and in that case, a suitable but reasonable for the key algorithm will be selected.

#### Parameters

crl | should contain a gnutls_x509_crl_t type |
issuer | is the certificate of the certificate issuer |
issuer_key | holds the issuer's private key |
dig | The message digest to use. GNUTLS_DIG_SHA256 is the safe choice unless you know what you're doing. |
flags | must be 0 |

#### Returns

On success, `GNUTLS_E_SUCCESS` (0) is returned, otherwise a negative error value.

Since 2.12.0

### gnutls_x509_crq_privkey_sign ()

    int
    gnutls_x509_crq_privkey_sign (gnutls_x509_crq_t crq,
                                  gnutls_privkey_t key,
                                  gnutls_digest_algorithm_t dig,
                                  unsigned int flags);

This function will sign the certificate request with a private key. This must be the same key as the one used in `gnutls_x509_crt_set_key()` since a certificate request is self signed.

This must be the last step in a certificate request generation since all the previously set parameters are now signed.

A known limitation of this function is, that a newly-signed request will not be fully functional (e.g., for signature verification), until it is exported an re-imported.

After GnuTLS 3.6.1 the value of `dig` may be `GNUTLS_DIG_UNKNOWN`, and in that case, a suitable but reasonable for the key algorithm will be selected.

#### Parameters

crq | should contain a gnutls_x509_crq_t type |
key | holds a private key |
dig | The message digest to use, i.e., `GNUTLS_DIG_SHA1` |
flags | must be 0 |

#### Returns

`GNUTLS_E_SUCCESS` on success, otherwise a negative error code. `GNUTLS_E_ASN1_VALUE_NOT_FOUND` is returned if you didn't set all information in the certificate request (e.g., the version using `gnutls_x509_crq_set_version()`).

Since: 2.12.0

### gnutls_x509_crq_set_pubkey ()

    int
    gnutls_x509_crq_set_pubkey (gnutls_x509_crq_t crq,
                                gnutls_pubkey_t key);

This function will set the public parameters from the given public key to the request. The `key` can be deallocated after that.

#### Parameters

crq | should contain a gnutls_x509_crq_t type |
key | holds a public key |

#### Returns

On success, `GNUTLS_E_SUCCESS` (0) is returned, otherwise a negative error value.

Since: 2.12.0

### gnutls_x509_crt_privkey_sign ()

    int
    gnutls_x509_crt_privkey_sign (gnutls_x509_crt_t crt,
                                  gnutls_x509_crt_t issuer,
                                  gnutls_privkey_t issuer_key,
                                  gnutls_digest_algorithm_t dig,
                                  unsigned int flags);

This function will sign the certificate with the issuer's private key, and will copy the issuer's information into the certificate.

This must be the last step in a certificate generation since all the previously set parameters are now signed.

A known limitation of this function is, that a newly-signed certificate will not be fully functional (e.g., for signature verification), until it is exported an re-imported.

After GnuTLS 3.6.1 the value of `dig` may be `GNUTLS_DIG_UNKNOWN`, and in that case, a suitable but reasonable for the key algorithm will be selected.

#### Parameters

crt | a certificate of type gnutls_x509_crt_t |
issuer | is the certificate of the certificate issuer |
issuer_key | holds the issuer's private key |
dig | The message digest to use, `GNUTLS_DIG_SHA256` is a safe choice |
flags | must be 0 |

#### Returns

On success, `GNUTLS_E_SUCCESS` (0) is returned, otherwise a negative error value.

### gnutls_x509_crt_set_pubkey ()

    int
    gnutls_x509_crt_set_pubkey (gnutls_x509_crt_t crt,
                                gnutls_pubkey_t key);

This function will set the public parameters from the given public key to the certificate. The `key` can be deallocated after that.

#### Parameters

crt | should contain a gnutls_x509_crt_t type |
key | holds a public key |

#### Returns

On success, `GNUTLS_E_SUCCESS` (0) is returned, otherwise a negative error value.

Since: 2.12.0

## Types and Values

### GNUTLS_PCERT_NO_CERT

    #define GNUTLS_PCERT_NO_CERT 1

### GNUTLS_PUBKEY_VERIFY_FLAG_TLS_RSA

    #define GNUTLS_PUBKEY_VERIFY_FLAG_TLS_RSA GNUTLS_PUBKEY_VERIFY_FLAG_TLS1_RSA

### struct gnutls_privkey_st

    struct gnutls_privkey_st {
    	gnutls_privkey_type_t type;
    	gnutls_pk_algorithm_t pk_algorithm;

    	union {
    		gnutls_x509_privkey_t x509;
    #ifdef ENABLE_PKCS11
    		gnutls_pkcs11_privkey_t pkcs11;
    #endif
    		struct {
    			gnutls_privkey_sign_func sign_func; /* raw like TLS 1.x */
    			gnutls_privkey_sign_data_func sign_data_func;
    			gnutls_privkey_sign_hash_func sign_hash_func;
    			gnutls_privkey_decrypt_func decrypt_func;
    			gnutls_privkey_decrypt_func2 decrypt_func2;
    			gnutls_privkey_deinit_func deinit_func;
    			gnutls_privkey_info_func info_func;
    			void *userdata;
    			unsigned bits;
    		} ext;
    	} key;

    	unsigned int flags;
    	struct pin_info_st pin;
    };

### gnutls_privkey_t

### gnutls_pubkey_get_pk_dsa_raw

    #define gnutls_pubkey_get_pk_dsa_raw gnutls_pubkey_export_dsa_raw

### gnutls_pubkey_get_pk_ecc_raw

    #define gnutls_pubkey_get_pk_ecc_raw gnutls_pubkey_export_ecc_raw

### gnutls_pubkey_get_pk_ecc_x962

    #define gnutls_pubkey_get_pk_ecc_x962 gnutls_pubkey_export_ecc_x962

### gnutls_pubkey_get_pk_rsa_raw

    #define gnutls_pubkey_get_pk_rsa_raw gnutls_pubkey_export_rsa_raw

### struct gnutls_pubkey_st

    struct gnutls_pubkey_st {
    	unsigned int bits; /* an indication of the security parameter */

    	/* the size of params depends on the public
    	 * key algorithm
    	 * RSA: [0] is modulus
    	 *      [1] is public exponent
    	 * DSA: [0] is p
    	 *      [1] is q
    	 *      [2] is g
    	 *      [3] is public key
    	 */
    	gnutls_pk_params_st params;

    	unsigned int key_usage; /* bits from GNUTLS_KEY_* */

    	struct pin_info_st pin;
    };

### gnutls_pubkey_t