keys.h File Reference

Addendum to dnssec.h, this module contains key and algorithm definitions and functions. More...

Go to the source code of this file.

## Data Structures

struct | ldns_struct_key
| General key structure, can contain all types of keys that are used in DNSSEC. More...
struct | ldns_struct_key_list
| Same as rr_list, but now for keys. More...

## Macros

#define | LDNS_KEY_ZONE_KEY 0x0100 /* rfc 4034 */
#define | LDNS_KEY_SEP_KEY 0x0001 /* rfc 4034 */
#define | LDNS_KEY_REVOKE_KEY 0x0080 /* rfc 5011 */

## Typedefs

typedef enum ldns_enum_algorithm | ldns_algorithm
typedef enum ldns_enum_hash | ldns_hash
typedef enum ldns_enum_signing_algorithm | ldns_signing_algorithm
typedef struct ldns_struct_key | ldns_key
typedef struct ldns_struct_key_list | ldns_key_list

## Enumerations

enum | ldns_enum_algorithm { LDNS_RSAMD5 = 1 , LDNS_DH = 2 , LDNS_DSA = 3 , LDNS_ECC = 4 , LDNS_RSASHA1 = 5 , LDNS_DSA_NSEC3 = 6 , LDNS_RSASHA1_NSEC3 = 7 , LDNS_RSASHA256 = 8 , LDNS_RSASHA512 = 10 , LDNS_ECC_GOST = 12 , LDNS_ECDSAP256SHA256 = 13 , LDNS_ECDSAP384SHA384 = 14 , LDNS_ED25519 = 15 , LDNS_ED448 = 16 , LDNS_INDIRECT = 252 , LDNS_PRIVATEDNS = 253 , LDNS_PRIVATEOID = 254 }
| Algorithms used in dns. More...
enum | ldns_enum_hash { LDNS_SHA1 = 1 , LDNS_SHA256 = 2 , LDNS_HASH_GOST = 3 , LDNS_SHA384 = 4 }
| Hashing algorithms used in the DS record. More...

enum

ldns_enum_signing_algorithm {
LDNS_SIGN_RSAMD5 = LDNS_RSAMD5 , LDNS_SIGN_RSASHA1 = LDNS_RSASHA1 , LDNS_SIGN_DSA = LDNS_DSA , LDNS_SIGN_RSASHA1_NSEC3 = LDNS_RSASHA1_NSEC3 ,
LDNS_SIGN_RSASHA256 = LDNS_RSASHA256 , LDNS_SIGN_RSASHA512 = LDNS_RSASHA512 , LDNS_SIGN_DSA_NSEC3 = LDNS_DSA_NSEC3 , LDNS_SIGN_ECC_GOST = LDNS_ECC_GOST ,
LDNS_SIGN_ECDSAP256SHA256 = LDNS_ECDSAP256SHA256 , LDNS_SIGN_ECDSAP384SHA384 = LDNS_ECDSAP384SHA384 , LDNS_SIGN_ED25519 = LDNS_ED25519 , LDNS_SIGN_ED448 = LDNS_ED448 ,
LDNS_SIGN_HMACMD5 = 157 , LDNS_SIGN_HMACSHA1 = 158 , LDNS_SIGN_HMACSHA256 = 159 , LDNS_SIGN_HMACSHA224 = 162 ,
LDNS_SIGN_HMACSHA384 = 164 , LDNS_SIGN_HMACSHA512 = 165
}

| Algorithms used in dns for signing. More...

## Functions

ldns_key_list * | ldns_key_list_new (void)
| Creates a new empty key list.
ldns_key * | ldns_key_new (void)
| Creates a new empty key structure.
ldns_key * | ldns_key_new_frm_algorithm (ldns_signing_algorithm a, uint16_t size)
| Creates a new key based on the algorithm.
ldns_status | ldns_key_new_frm_fp (ldns_key **k, FILE *fp)
| Creates a new priv key based on the contents of the file pointed by fp.
ldns_status | ldns_key_new_frm_fp_l (ldns_key **k, FILE *fp, int *line_nr)
| Creates a new private key based on the contents of the file pointed by fp.
ldns_status | ldns_key_new_frm_engine (ldns_key **key, ENGINE *e, char *key_id, ldns_algorithm a)
| Read the key with the given id from the given engine and store it in the given ldns_key structure.
RSA * | ldns_key_new_frm_fp_rsa (FILE *fp)
| frm_fp helper function.
RSA * | ldns_key_new_frm_fp_rsa_l (FILE *fp, int *line_nr)
| frm_fp helper function.
DSA * | ldns_key_new_frm_fp_dsa (FILE *fp)
| frm_fp helper function.
DSA * | ldns_key_new_frm_fp_dsa_l (FILE *fp, int *line_nr)
| frm_fp helper function.
unsigned char * | ldns_key_new_frm_fp_hmac (FILE *fp, size_t *hmac_size)
| frm_fp helper function.
unsigned char * | ldns_key_new_frm_fp_hmac_l (FILE *fp, int *line_nr, size_t *hmac_size)
| frm_fp helper function.
void | ldns_key_set_algorithm (ldns_key *k, ldns_signing_algorithm l)
| Set the key's algorithm.
void | ldns_key_set_evp_key (ldns_key *k, EVP_PKEY *e)
| Set the key's evp key.
void | ldns_key_set_rsa_key (ldns_key *k, RSA *r)
| Set the key's rsa data.
void | ldns_key_set_dsa_key (ldns_key *k, DSA *d)
| Set the key's dsa data The dsa data should be freed by the user.
void | ldns_key_assign_rsa_key (ldns_key *k, RSA *r)
| Assign the key's rsa data The rsa data will be freed automatically when the key is freed.
void | ldns_key_assign_dsa_key (ldns_key *k, DSA *d)
| Assign the key's dsa data The dsa data will be freed automatically when the key is freed.
int | ldns_key_EVP_load_gost_id (void)
| Get the PKEY id for GOST, loads GOST into openssl as a side effect.
void | ldns_key_EVP_unload_gost (void)
| Release the engine reference held for the GOST engine.
void | ldns_key_set_hmac_key (ldns_key *k, unsigned char *hmac)
| Set the key's hmac data.
void | ldns_key_set_external_key (ldns_key *key, void *external_key)
| Set the key id data.
void | ldns_key_set_hmac_size (ldns_key *k, size_t hmac_size)
| Set the key's hmac size.
void | ldns_key_set_origttl (ldns_key *k, uint32_t t)
| Set the key's original ttl.
void | ldns_key_set_inception (ldns_key *k, uint32_t i)
| Set the key's inception date (seconds after epoch)
void | ldns_key_set_expiration (ldns_key *k, uint32_t e)
| Set the key's expiration date (seconds after epoch)
void | ldns_key_set_pubkey_owner (ldns_key *k, ldns_rdf *r)
| Set the key's pubkey owner.
void | ldns_key_set_keytag (ldns_key *k, uint16_t tag)
| Set the key's key tag.
void | ldns_key_set_flags (ldns_key *k, uint16_t flags)
| Set the key's flags.
void | ldns_key_list_set_key_count (ldns_key_list *key, size_t count)
| Set the keylist's key count to count.
signed char | ldns_key_list_push_key (ldns_key_list *key_list, ldns_key *key)
| pushes a key to a keylist
size_t | ldns_key_list_key_count (const ldns_key_list *key_list)
| returns the number of keys in the key list
ldns_key * | ldns_key_list_key (const ldns_key_list *key, size_t nr)
| returns a pointer to the key in the list at the given position
RSA * | ldns_key_rsa_key (const ldns_key *k)
| returns the (openssl) RSA struct contained in the key
EVP_PKEY * | ldns_key_evp_key (const ldns_key *k)
| returns the (openssl) EVP struct contained in the key
DSA * | ldns_key_dsa_key (const ldns_key *k)
| returns the (openssl) DSA struct contained in the key
ldns_signing_algorithm | ldns_key_algorithm (const ldns_key *k)
| return the signing alg of the key
void | ldns_key_set_use (ldns_key *k, signed char v)
| set the use flag
signed char | ldns_key_use (const ldns_key *k)
| return the use flag
unsigned char * | ldns_key_hmac_key (const ldns_key *k)
| return the hmac key data
void * | ldns_key_external_key (const ldns_key *k)
| return the key id key data
size_t | ldns_key_hmac_size (const ldns_key *k)
| return the hmac key size
uint32_t | ldns_key_origttl (const ldns_key *k)
| return the original ttl of the key
uint32_t | ldns_key_inception (const ldns_key *k)
| return the key's inception date
uint32_t | ldns_key_expiration (const ldns_key *k)
| return the key's expiration date
uint16_t | ldns_key_keytag (const ldns_key *k)
| return the keytag
ldns_rdf * | ldns_key_pubkey_owner (const ldns_key *k)
| return the public key's owner
void | ldns_key_list_set_use (ldns_key_list *keys, signed char v)
| Set the 'use' flag for all keys in the list.
uint16_t | ldns_key_flags (const ldns_key *k)
| return the flag of the key
ldns_key * | ldns_key_list_pop_key (ldns_key_list *key_list)
| pops the last rr from a keylist
ldns_rr * | ldns_key2rr (const ldns_key *k)
| converts a ldns_key to a public key rr If the key data exists at an external point, the corresponding rdata field must still be added with ldns_rr_rdf_push() to the result rr of this function
void | ldns_key_print (FILE *output, const ldns_key *k)
| print a private key to the file output
void | ldns_key_free (ldns_key *key)
| frees a key structure, but not its internal data structures
void | ldns_key_deep_free (ldns_key *key)
| frees a key structure and all its internal data structures, except the data set by ldns_key_set_external_key()
void | ldns_key_list_free (ldns_key_list *key_list)
| Frees a key list structure.
ldns_rr * | ldns_read_anchor_file (const char *filename)
| Instantiates a DNSKEY or DS RR from file.
char * | ldns_key_get_file_base_name (const ldns_key *key)
| Returns the 'default base name' for key files; IE.
int | ldns_key_algo_supported (int algo)
| See if a key algorithm is supported.
ldns_signing_algorithm | ldns_get_signing_algorithm_by_name (const char *name)
| Get signing algorithm by name.

## Variables

ldns_lookup_table | ldns_signing_algorithms []

## Detailed Description

Addendum to dnssec.h, this module contains key and algorithm definitions and functions.

Definition in file keys.h.

## Macro Definition Documentation

## LDNS_KEY_ZONE_KEY

#define LDNS_KEY_ZONE_KEY 0x0100 /* rfc 4034 */

Definition at line 37 of file keys.h.

## LDNS_KEY_SEP_KEY

#define LDNS_KEY_SEP_KEY 0x0001 /* rfc 4034 */

Definition at line 38 of file keys.h.

## LDNS_KEY_REVOKE_KEY

#define LDNS_KEY_REVOKE_KEY 0x0080 /* rfc 5011 */

Definition at line 39 of file keys.h.

## Typedef Documentation

## ldns_algorithm

typedef enum ldns_enum_algorithm ldns_algorithm

Definition at line 64 of file keys.h.

## ldns_hash

typedef enum ldns_enum_hash ldns_hash

Definition at line 76 of file keys.h.

## ldns_signing_algorithm

typedef enum ldns_enum_signing_algorithm ldns_signing_algorithm

Definition at line 110 of file keys.h.

## ldns_key

typedef struct ldns_struct_key ldns_key

Definition at line 167 of file keys.h.

## ldns_key_list

typedef struct ldns_struct_key_list ldns_key_list

Definition at line 177 of file keys.h.

## Enumeration Type Documentation

## ldns_enum_algorithm

enum ldns_enum_algorithm

Algorithms used in dns.

Enumerator
LDNS_RSAMD5 |
LDNS_DH |
LDNS_DSA |
LDNS_ECC |
LDNS_RSASHA1 |
LDNS_DSA_NSEC3 |
LDNS_RSASHA1_NSEC3 |
LDNS_RSASHA256 |
LDNS_RSASHA512 |
LDNS_ECC_GOST |
LDNS_ECDSAP256SHA256 |
LDNS_ECDSAP384SHA384 |
LDNS_ED25519 |
LDNS_ED448 |
LDNS_INDIRECT |
LDNS_PRIVATEDNS |
LDNS_PRIVATEOID |

Definition at line 44 of file keys.h.

## ldns_enum_hash

enum ldns_enum_hash

Hashing algorithms used in the DS record.

Enumerator
LDNS_SHA1 |
LDNS_SHA256 |
LDNS_HASH_GOST |
LDNS_SHA384 |

Definition at line 69 of file keys.h.

## ldns_enum_signing_algorithm

enum ldns_enum_signing_algorithm

Algorithms used in dns for signing.

Enumerator
LDNS_SIGN_RSAMD5 |
LDNS_SIGN_RSASHA1 |
LDNS_SIGN_DSA |
LDNS_SIGN_RSASHA1_NSEC3 |
LDNS_SIGN_RSASHA256 |
LDNS_SIGN_RSASHA512 |
LDNS_SIGN_DSA_NSEC3 |
LDNS_SIGN_ECC_GOST |
LDNS_SIGN_ECDSAP256SHA256 |
LDNS_SIGN_ECDSAP384SHA384 |
LDNS_SIGN_ED25519 |
LDNS_SIGN_ED448 |
LDNS_SIGN_HMACMD5 |
LDNS_SIGN_HMACSHA1 |
LDNS_SIGN_HMACSHA256 |
LDNS_SIGN_HMACSHA224 |
LDNS_SIGN_HMACSHA384 |
LDNS_SIGN_HMACSHA512 |

Definition at line 81 of file keys.h.

## Function Documentation

## ldns_key_list_new()

ldns_key_list * ldns_key_list_new | ( | void |  | ) |

Creates a new empty key list.

Returns
  a new ldns_key_list structure pointer

Definition at line 70 of file keys.c.

References ldns_struct_key_list::_key_count, ldns_struct_key_list::_keys, and LDNS_MALLOC.

## ldns_key_new()

ldns_key * ldns_key_new | ( | void |  | ) |

Creates a new empty key structure.

Returns
  a new ldns_key * structure

Definition at line 83 of file keys.c.

References ldns_key_set_evp_key(), ldns_key_set_expiration(), ldns_key_set_external_key(), ldns_key_set_flags(), ldns_key_set_hmac_key(), ldns_key_set_inception(), ldns_key_set_keytag(), ldns_key_set_origttl(), ldns_key_set_pubkey_owner(), ldns_key_set_use(), LDNS_KEY_ZONE_KEY, and LDNS_MALLOC.

## ldns_key_new_frm_algorithm()

ldns_key * ldns_key_new_frm_algorithm | ( | ldns_signing_algorithm | a,
|  | uint16_t | size
| ) |  |

Creates a new key based on the algorithm.

Parameters

  [in] | a | The algorithm to use
  [in] | size | the number of bytes for the keysize

Returns
  a new ldns_key structure with the key

Definition at line 1083 of file keys.c.

References ldns_struct_key::_key, ldns_struct_key::key, LDNS_FREE, ldns_key_free(), ldns_key_new(), ldns_key_set_algorithm(), ldns_key_set_dsa_key(), ldns_key_set_evp_key(), ldns_key_set_flags(), ldns_key_set_hmac_key(), ldns_key_set_hmac_size(), ldns_key_set_rsa_key(), LDNS_SIGN_DSA, LDNS_SIGN_DSA_NSEC3, LDNS_SIGN_ECC_GOST, LDNS_SIGN_ECDSAP256SHA256, LDNS_SIGN_ECDSAP384SHA384, LDNS_SIGN_ED25519, LDNS_SIGN_ED448, LDNS_SIGN_HMACMD5, LDNS_SIGN_HMACSHA1, LDNS_SIGN_HMACSHA224, LDNS_SIGN_HMACSHA256, LDNS_SIGN_HMACSHA384, LDNS_SIGN_HMACSHA512, LDNS_SIGN_RSAMD5, LDNS_SIGN_RSASHA1, LDNS_SIGN_RSASHA1_NSEC3, LDNS_SIGN_RSASHA256, LDNS_SIGN_RSASHA512, and LDNS_XMALLOC.

## ldns_key_new_frm_fp()

ldns_status ldns_key_new_frm_fp | ( | ldns_key ** | k,
|  | FILE * | fp
| ) |  |

Creates a new priv key based on the contents of the file pointed by fp.

The file should be in Private-key-format v1.x.

Parameters

  [out] | k | the new ldns_key structure
  [in] | fp | the file pointer to use

Returns
  an error or LDNS_STATUS_OK

Definition at line 109 of file keys.c.

References ldns_key_new_frm_fp_l().

## ldns_key_new_frm_fp_l()

ldns_status ldns_key_new_frm_fp_l | ( | ldns_key ** | k,
|  | FILE * | fp,
|  | int * | line_nr
| ) |  |

Creates a new private key based on the contents of the file pointed by fp.

The file should be in Private-key-format v1.x.

Parameters

  [out] | k | the new ldns_key structure
  [in] | fp | the file pointer to use
  [in] | line_nr | pointer to an integer containing the current line number (for debugging purposes)

Returns
  an error or LDNS_STATUS_OK

Definition at line 417 of file keys.c.

References ldns_struct_key::_key, ldns_struct_key::key, ldns_calc_keytag(), LDNS_DH, LDNS_ECC, ldns_fget_keyword_data_l(), LDNS_FREE, ldns_key2rr(), ldns_key_assign_dsa_key(), ldns_key_assign_rsa_key(), ldns_key_EVP_load_gost_id(), ldns_key_free(), ldns_key_new(), ldns_key_new_frm_fp_dsa_l(), ldns_key_new_frm_fp_hmac_l(), ldns_key_new_frm_fp_rsa_l(), ldns_key_set_algorithm(), ldns_key_set_evp_key(), ldns_key_set_hmac_key(), ldns_key_set_hmac_size(), ldns_key_set_keytag(), LDNS_MAX_LINELEN, ldns_rr_free(), LDNS_SIGN_DSA, LDNS_SIGN_DSA_NSEC3, LDNS_SIGN_ECC_GOST, LDNS_SIGN_ECDSAP256SHA256, LDNS_SIGN_ECDSAP384SHA384, LDNS_SIGN_ED25519, LDNS_SIGN_ED448, LDNS_SIGN_HMACMD5, LDNS_SIGN_HMACSHA1, LDNS_SIGN_HMACSHA224, LDNS_SIGN_HMACSHA256, LDNS_SIGN_HMACSHA384, LDNS_SIGN_HMACSHA512, LDNS_SIGN_RSAMD5, LDNS_SIGN_RSASHA1, LDNS_SIGN_RSASHA1_NSEC3, LDNS_SIGN_RSASHA256, LDNS_SIGN_RSASHA512, LDNS_STATUS_CRYPTO_ALGO_NOT_IMPL, LDNS_STATUS_ERR, LDNS_STATUS_MEM_ERR, LDNS_STATUS_OK, LDNS_STATUS_SYNTAX_ALG_ERR, LDNS_STATUS_SYNTAX_ERR, LDNS_STATUS_SYNTAX_VERSION_ERR, and LDNS_XMALLOC.

## ldns_key_new_frm_engine()

ldns_status ldns_key_new_frm_engine | ( | ldns_key ** | key,
|  | ENGINE * | e,
|  | char * | key_id,
|  | ldns_algorithm | a
| ) |  |

Read the key with the given id from the given engine and store it in the given ldns_key structure.

The algorithm type is set

Parameters

  [out] | key | the new ldns_key structure
  [in] | e | the engine from which to read the key
  [in] | key_id | the id of the key with which to lookup the key in the engine
  [in] | a | the algorithm to set for this key

Returns
  an error or LDNS_STATUS_OK

Definition at line 116 of file keys.c.

References ldns_struct_key::_key, ldns_struct_key::key, ldns_key_free(), ldns_key_new(), ldns_key_set_algorithm(), LDNS_STATUS_ENGINE_KEY_NOT_LOADED, LDNS_STATUS_MEM_ERR, and LDNS_STATUS_OK.

## ldns_key_new_frm_fp_rsa()

RSA * ldns_key_new_frm_fp_rsa | ( | FILE * | fp | ) |

frm_fp helper function.

This function parses the remainder of the (RSA) priv. key file generated from bind9

Parameters

  [in] | fp | the file to parse

Returns
  NULL on failure otherwise a RSA structure

Definition at line 731 of file keys.c.

References ldns_key_new_frm_fp_rsa_l().

## ldns_key_new_frm_fp_rsa_l()

RSA * ldns_key_new_frm_fp_rsa_l | ( | FILE * | fp,
|  | int * | line_nr
| ) |  |

frm_fp helper function.

This function parses the remainder of the (RSA) priv. key file generated from bind9

Parameters

  [in] | fp | the file to parse
  [in] | line_nr | pointer to an integer containing the current line number (for debugging purposes)

Returns
  NULL on failure otherwise a RSA structure

Definition at line 737 of file keys.c.

References ldns_b64_pton(), ldns_fget_keyword_data_l(), LDNS_FREE, LDNS_MAX_LINELEN, and LDNS_XMALLOC.

## ldns_key_new_frm_fp_dsa()

DSA * ldns_key_new_frm_fp_dsa | ( | FILE * | fp | ) |

frm_fp helper function.

This function parses the remainder of the (DSA) priv. key file

Parameters

  [in] | fp | the file to parse

Returns
  NULL on failure otherwise a RSA structure

Definition at line 910 of file keys.c.

References ldns_key_new_frm_fp_dsa_l().

## ldns_key_new_frm_fp_dsa_l()

DSA * ldns_key_new_frm_fp_dsa_l | ( | FILE * | fp,
|  | int * | line_nr
| ) |  |

frm_fp helper function.

This function parses the remainder of the (DSA) priv. key file

Parameters

  [in] | fp | the file to parse
  [in] | line_nr | pointer to an integer containing the current line number (for debugging purposes)

Returns
  NULL on failure otherwise a RSA structure

## ldns_key_new_frm_fp_hmac()

unsigned char * ldns_key_new_frm_fp_hmac | ( | FILE * | fp,
|  | size_t * | hmac_size
| ) |  |

frm_fp helper function.

This function parses the remainder of the (HMAC-MD5) key file This function allocated a buffer that needs to be freed

Parameters

  [in] | fp | the file to parse
  [out] | hmac_size | the number of bits in the resulting buffer

Returns
  NULL on failure otherwise a newly allocated char buffer

Definition at line 1022 of file keys.c.

References ldns_key_new_frm_fp_hmac_l().

## ldns_key_new_frm_fp_hmac_l()

unsigned char * ldns_key_new_frm_fp_hmac_l | ( | FILE * | fp,
|  | int * | line_nr,
|  | size_t * | hmac_size
| ) |  |

frm_fp helper function.

This function parses the remainder of the (HMAC-MD5) key file This function allocated a buffer that needs to be freed

Parameters

  [in] | fp | the file to parse
  [in] | line_nr | pointer to an integer containing the current line number (for error reporting purposes)
  [out] | hmac_size | the number of bits in the resulting buffer

Returns
  NULL on failure otherwise a newly allocated char buffer

## ldns_key_set_algorithm()

void ldns_key_set_algorithm | ( | ldns_key * | k,
|  | ldns_signing_algorithm | l
| ) |  |

Set the key's algorithm.

Parameters

  [in] | k | the key
  [in] | l | the algorithm

Definition at line 1336 of file keys.c.

References ldns_struct_key::_alg.

## ldns_key_set_evp_key()

void ldns_key_set_evp_key | ( | ldns_key * | k,
|  | EVP_PKEY * | e
| ) |  |

Set the key's evp key.

Parameters

  [in] | k | the key
  [in] | e | the evp key

Definition at line 1350 of file keys.c.

References ldns_struct_key::_key, and ldns_struct_key::key.

## ldns_key_set_rsa_key()

void ldns_key_set_rsa_key | ( | ldns_key * | k,
|  | RSA * | r
| ) |  |

Set the key's rsa data.

The rsa data should be freed by the user.

Parameters

  [in] | k | the key
  [in] | r | the rsa data

Definition at line 1356 of file keys.c.

References ldns_struct_key::_key, and ldns_struct_key::key.

## ldns_key_set_dsa_key()

void ldns_key_set_dsa_key | ( | ldns_key * | k,
|  | DSA * | d
| ) |  |

Set the key's dsa data The dsa data should be freed by the user.

Parameters

  [in] | k | the key
  [in] | d | the dsa data

Definition at line 1364 of file keys.c.

References ldns_struct_key::_key, and ldns_struct_key::key.

## ldns_key_assign_rsa_key()

void ldns_key_assign_rsa_key | ( | ldns_key * | k,
|  | RSA * | r
| ) |  |

Assign the key's rsa data The rsa data will be freed automatically when the key is freed.

Parameters

  [in] | k | the key
  [in] | r | the rsa data

Definition at line 1376 of file keys.c.

References ldns_struct_key::_key, and ldns_struct_key::key.

## ldns_key_assign_dsa_key()

void ldns_key_assign_dsa_key | ( | ldns_key * | k,
|  | DSA * | d
| ) |  |

Assign the key's dsa data The dsa data will be freed automatically when the key is freed.

Parameters

  [in] | k | the key
  [in] | d | the dsa data

Definition at line 1384 of file keys.c.

References ldns_struct_key::_key, and ldns_struct_key::key.

## ldns_key_EVP_load_gost_id()

int ldns_key_EVP_load_gost_id | ( | void |  | ) |

Get the PKEY id for GOST, loads GOST into openssl as a side effect.

Only available if GOST is compiled into the library and openssl.

Returns
  the gost id for EVP_CTX creation.

## ldns_key_EVP_unload_gost()

void ldns_key_EVP_unload_gost | ( | void |  | ) |

Release the engine reference held for the GOST engine.

## ldns_key_set_hmac_key()

void ldns_key_set_hmac_key | ( | ldns_key * | k,
|  | unsigned char * | hmac
| ) |  |

Set the key's hmac data.

Parameters

  [in] | k | the key
  [in] | hmac | the raw key data

Definition at line 1398 of file keys.c.

References ldns_struct_key::_key, ldns_struct_key::hmac, and ldns_struct_key::key.

## ldns_key_set_external_key()

void ldns_key_set_external_key | ( | ldns_key * | key,
|  | void * | external_key
| ) |  |

Set the key id data.

This is used if the key points to some externally stored key data

Only the pointer is set, the data there is not copied, and must be freed manually; ldns_key_deep_free() does not free this data

Parameters

  [in] | key | the key
  [in] | external_key | key id data

Definition at line 1410 of file keys.c.

References ldns_struct_key::_key, and ldns_struct_key::external_key.

## ldns_key_set_hmac_size()

void ldns_key_set_hmac_size | ( | ldns_key * | k,
|  | size_t | hmac_size
| ) |  |

Set the key's hmac size.

Parameters

  [in] | k | the key
  [in] | hmac_size | the size of the hmac data

Definition at line 1404 of file keys.c.

References ldns_struct_key::_key, ldns_struct_key::hmac, and ldns_struct_key::size.

## ldns_key_set_origttl()

void ldns_key_set_origttl | ( | ldns_key * | k,
|  | uint32_t | t
| ) |  |

Set the key's original ttl.

Parameters

  [in] | k | the key
  [in] | t | the ttl

Definition at line 1416 of file keys.c.

References ldns_struct_key::_extra, ldns_struct_key::dnssec, and ldns_struct_key::orig_ttl.

## ldns_key_set_inception()

void ldns_key_set_inception | ( | ldns_key * | k,
|  | uint32_t | i
| ) |  |

Set the key's inception date (seconds after epoch)

Parameters

  [in] | k | the key
  [in] | i | the inception

Definition at line 1422 of file keys.c.

References ldns_struct_key::_extra, ldns_struct_key::dnssec, and ldns_struct_key::inception.

## ldns_key_set_expiration()

void ldns_key_set_expiration | ( | ldns_key * | k,
|  | uint32_t | e
| ) |  |

Set the key's expiration date (seconds after epoch)

Parameters

  [in] | k | the key
  [in] | e | the expiration

Definition at line 1428 of file keys.c.

References ldns_struct_key::_extra, ldns_struct_key::dnssec, and ldns_struct_key::expiration.

## ldns_key_set_pubkey_owner()

void ldns_key_set_pubkey_owner | ( | ldns_key * | k,
|  | ldns_rdf * | r
| ) |  |

Set the key's pubkey owner.

Parameters

  [in] | k | the key
  [in] | r | the owner

Definition at line 1434 of file keys.c.

References ldns_struct_key::_pubkey_owner.

## ldns_key_set_keytag()

void ldns_key_set_keytag | ( | ldns_key * | k,
|  | uint16_t | tag
| ) |  |

Set the key's key tag.

Parameters

  [in] | k | the key
  [in] | tag | the keytag

Definition at line 1440 of file keys.c.

References ldns_struct_key::_extra, ldns_struct_key::dnssec, and ldns_struct_key::keytag.

## ldns_key_set_flags()

void ldns_key_set_flags | ( | ldns_key * | k,
|  | uint16_t | flags
| ) |  |

Set the key's flags.

Parameters

  [in] | k | the key
  [in] | flags | the flags

Definition at line 1342 of file keys.c.

References ldns_struct_key::_extra, ldns_struct_key::dnssec, and ldns_struct_key::flags.

## ldns_key_list_set_key_count()

void ldns_key_list_set_key_count | ( | ldns_key_list * | key,
|  | size_t | count
| ) |  |

Set the keylist's key count to count.

Parameters

  [in] | key | the key
  [in] | count | the count

Definition at line 1594 of file keys.c.

References ldns_struct_key_list::_key_count.

## ldns_key_list_push_key()

signed char ldns_key_list_push_key | ( | ldns_key_list * | key_list,
|  | ldns_key * | key
| ) |  |

pushes a key to a keylist

Parameters

  [in] | key_list | the key_list to push to
  [in] | key | the key to push

Returns
  false on error, otherwise true

Definition at line 1600 of file keys.c.

References ldns_struct_key_list::_keys, ldns_key_list_key_count(), ldns_key_list_set_key_count(), and LDNS_XREALLOC.

## ldns_key_list_key_count()

size_t ldns_key_list_key_count | ( | const ldns_key_list * | key_list | ) |

returns the number of keys in the key list

Parameters

  [in] | key_list | the key_list

Returns
  the numbers of keys in the list

Definition at line 1447 of file keys.c.

References ldns_struct_key_list::_key_count.

## ldns_key_list_key()

ldns_key * ldns_key_list_key | ( | const ldns_key_list * | key,
|  | size_t | nr
| ) |  |

returns a pointer to the key in the list at the given position

Parameters

  [in] | key | the key
  [in] | nr | the position in the list

Returns
  the key

Definition at line 1453 of file keys.c.

References ldns_struct_key_list::_keys, and ldns_key_list_key_count().

## ldns_key_rsa_key()

RSA * ldns_key_rsa_key | ( | const ldns_key * | k | ) |

returns the (openssl) RSA struct contained in the key

Parameters

  [in] | k | the key to look in

Returns
  the RSA * structure in the key

Definition at line 1494 of file keys.c.

References ldns_struct_key::_key, and ldns_struct_key::key.

## ldns_key_evp_key()

EVP_PKEY * ldns_key_evp_key | ( | const ldns_key * | k | ) |

returns the (openssl) EVP struct contained in the key

Parameters

  [in] | k | the key to look in

Returns
  the RSA * structure in the key

Definition at line 1488 of file keys.c.

References ldns_struct_key::_key, and ldns_struct_key::key.

## ldns_key_dsa_key()

DSA * ldns_key_dsa_key | ( | const ldns_key * | k | ) |

returns the (openssl) DSA struct contained in the key

Definition at line 1504 of file keys.c.

References ldns_struct_key::_key, and ldns_struct_key::key.

## ldns_key_algorithm()

ldns_signing_algorithm ldns_key_algorithm | ( | const ldns_key * | k | ) |

return the signing alg of the key

Parameters

  [in] | k | the key

Returns
  the algorithm

Definition at line 1463 of file keys.c.

References ldns_struct_key::_alg.

## ldns_key_set_use()

void ldns_key_set_use | ( | ldns_key * | k,
|  | signed char | v
| ) |  |

set the use flag

Parameters

  [in] | k | the key
  [in] | v | the boolean value to set the _use field to

## ldns_key_use()

signed char ldns_key_use | ( | const ldns_key * | k | ) |

return the use flag

Parameters

  [in] | k | the key

Returns
  the boolean value of the _use field

Definition at line 1477 of file keys.c.

References ldns_struct_key::_use.

## ldns_key_hmac_key()

unsigned char * ldns_key_hmac_key | ( | const ldns_key * | k | ) |

return the hmac key data

Parameters

  [in] | k | the key

Returns
  the hmac key data

Definition at line 1521 of file keys.c.

References ldns_struct_key::_key, ldns_struct_key::hmac, and ldns_struct_key::key.

## ldns_key_external_key()

void * ldns_key_external_key | ( | const ldns_key * | k | ) |

return the key id key data

Parameters

  [in] | k | the key

Returns
  the key id data

Definition at line 1541 of file keys.c.

References ldns_struct_key::_key, and ldns_struct_key::external_key.

## ldns_key_hmac_size()

size_t ldns_key_hmac_size | ( | const ldns_key * | k | ) |

return the hmac key size

Parameters

  [in] | k | the key

Returns
  the hmac key size

Definition at line 1531 of file keys.c.

References ldns_struct_key::_key, ldns_struct_key::hmac, and ldns_struct_key::size.

## ldns_key_origttl()

uint32_t ldns_key_origttl | ( | const ldns_key * | k | ) |

return the original ttl of the key

Parameters

  [in] | k | the key

Returns
  the original ttl

Definition at line 1547 of file keys.c.

References ldns_struct_key::_extra, ldns_struct_key::dnssec, and ldns_struct_key::orig_ttl.

## ldns_key_inception()

uint32_t ldns_key_inception | ( | const ldns_key * | k | ) |

return the key's inception date

Parameters

  [in] | k | the key

Returns
  the inception date

Definition at line 1559 of file keys.c.

References ldns_struct_key::_extra, ldns_struct_key::dnssec, and ldns_struct_key::inception.

## ldns_key_expiration()

uint32_t ldns_key_expiration | ( | const ldns_key * | k | ) |

return the key's expiration date

Parameters

  [in] | k | the key

Returns
  the expiration date

Definition at line 1565 of file keys.c.

References ldns_struct_key::_extra, ldns_struct_key::dnssec, and ldns_struct_key::expiration.

## ldns_key_keytag()

uint16_t ldns_key_keytag | ( | const ldns_key * | k | ) |

return the keytag

Parameters

  [in] | k | the key

Returns
  the keytag

Definition at line 1571 of file keys.c.

References ldns_struct_key::_extra, ldns_struct_key::dnssec, and ldns_struct_key::keytag.

## ldns_key_pubkey_owner()

ldns_rdf * ldns_key_pubkey_owner | ( | const ldns_key * | k | ) |

return the public key's owner

Parameters

  [in] | k | the key

Returns
  the owner

Definition at line 1577 of file keys.c.

References ldns_struct_key::_pubkey_owner.

## ldns_key_list_set_use()

void ldns_key_list_set_use | ( | ldns_key_list * | keys,
|  | signed char | v
| ) |  |

Set the 'use' flag for all keys in the list.

Parameters

  [in] | keys | The key_list
  [in] | v | The value to set the use flags to

## ldns_key_flags()

uint16_t ldns_key_flags | ( | const ldns_key * | k | ) |

return the flag of the key

Parameters

  [in] | k | the key

Returns
  the flag

Definition at line 1553 of file keys.c.

References ldns_struct_key::_extra, ldns_struct_key::dnssec, and ldns_struct_key::flags.

## ldns_key_list_pop_key()

ldns_key * ldns_key_list_pop_key | ( | ldns_key_list * | key_list | ) |

pops the last rr from a keylist

Parameters

  [in] | key_list | the rr_list to pop from

Returns
  NULL if nothing to pop. Otherwise the popped RR

Definition at line 1623 of file keys.c.

References ldns_struct_key_list::_keys, ldns_key_list_key(), ldns_key_list_key_count(), ldns_key_list_set_key_count(), and LDNS_XREALLOC.

## ldns_key2rr()

ldns_rr * ldns_key2rr | ( | const ldns_key * | k | ) |

converts a ldns_key to a public key rr If the key data exists at an external point, the corresponding rdata field must still be added with ldns_rr_rdf_push() to the result rr of this function

Parameters

  [in] | k | the ldns_key to convert

Returns
  ldns_rr representation of the key

Definition at line 1803 of file keys.c.

References ldns_struct_key::_key, ldns_struct_key::key, LDNS_DNSSEC_KEYPROTO, LDNS_DSA, LDNS_DSA_NSEC3, LDNS_FREE, ldns_key_algorithm(), ldns_key_dsa_key(), ldns_key_flags(), ldns_key_hmac_key(), ldns_key_hmac_size(), ldns_key_pubkey_owner(), ldns_key_rsa_key(), LDNS_MAX_KEYLEN, ldns_native2rdf_int16(), ldns_native2rdf_int8(), ldns_rdf_clone(), ldns_rdf_new_frm_data(), LDNS_RDF_TYPE_ALG, LDNS_RDF_TYPE_B64, LDNS_RDF_TYPE_INT16, LDNS_RDF_TYPE_INT8, ldns_rr_free(), ldns_rr_new(), ldns_rr_push_rdf(), ldns_rr_set_owner(), ldns_rr_set_type(), LDNS_RR_TYPE_DNSKEY, LDNS_RR_TYPE_KEY, LDNS_SIGN_DSA, LDNS_SIGN_DSA_NSEC3, LDNS_SIGN_ECC_GOST, LDNS_SIGN_ECDSAP256SHA256, LDNS_SIGN_ECDSAP384SHA384, LDNS_SIGN_ED25519, LDNS_SIGN_ED448, LDNS_SIGN_HMACMD5, LDNS_SIGN_HMACSHA1, LDNS_SIGN_HMACSHA224, LDNS_SIGN_HMACSHA256, LDNS_SIGN_HMACSHA384, LDNS_SIGN_HMACSHA512, LDNS_SIGN_RSAMD5, LDNS_SIGN_RSASHA1, LDNS_SIGN_RSASHA1_NSEC3, LDNS_SIGN_RSASHA256, LDNS_SIGN_RSASHA512, and LDNS_XMALLOC.

## ldns_key_print()

void ldns_key_print | ( | FILE * | output,
|  | const ldns_key * | k
| ) |  |

print a private key to the file output

Parameters

  [in] | output | the FILE descriptor where to print to
  [in] | k | the ldns_key to print

Definition at line 1323 of file keys.c.

References LDNS_FREE, and ldns_key2str().

## ldns_key_free()

void ldns_key_free | ( | ldns_key * | key | ) |

frees a key structure, but not its internal data structures

Parameters

  [in] | key | the key object to free

Definition at line 2048 of file keys.c.

References LDNS_FREE.

## ldns_key_deep_free()

void ldns_key_deep_free | ( | ldns_key * | key | ) |

frees a key structure and all its internal data structures, except the data set by ldns_key_set_external_key()

Parameters

  [in] | key | the key object to free

Definition at line 2054 of file keys.c.

References LDNS_FREE, ldns_key_evp_key(), ldns_key_hmac_key(), ldns_key_pubkey_owner(), and ldns_rdf_deep_free().

## ldns_key_list_free()

void ldns_key_list_free | ( | ldns_key_list * | key_list | ) |

Frees a key list structure.

Parameters

  [in] | key_list | the key list object to free

Definition at line 2073 of file keys.c.

References ldns_struct_key_list::_keys, LDNS_FREE, ldns_key_deep_free(), ldns_key_list_key(), and ldns_key_list_key_count().

## ldns_read_anchor_file()

ldns_rr * ldns_read_anchor_file | ( | const char * | filename | ) |

Instantiates a DNSKEY or DS RR from file.

Parameters

  [in] | filename | the file to read the record from

Returns
  the corresponding RR, or NULL if the parsing failed

Definition at line 2084 of file keys.c.

References LDNS_FREE, ldns_get_errorstr_by_id(), LDNS_MAX_PACKETLEN, ldns_rr_get_type(), ldns_rr_new_frm_str(), LDNS_RR_TYPE_DNSKEY, LDNS_RR_TYPE_DS, LDNS_STATUS_OK, and LDNS_XMALLOC.

## ldns_key_get_file_base_name()

char * ldns_key_get_file_base_name | ( | const ldns_key * | key | ) |

Returns the 'default base name' for key files; IE.

K<zone>+<alg>+<keytag> (without the .key or .private) The memory for this is allocated by this function, and should be freed by the caller

Parameters

  [in] | key | the key to get the file name from

Returns
  A string containing the file base name

Definition at line 2136 of file keys.c.

References ldns_buffer_export(), ldns_buffer_free(), ldns_buffer_new(), ldns_buffer_printf(), ldns_key_algorithm(), ldns_key_keytag(), ldns_key_pubkey_owner(), and ldns_rdf2buffer_str_dname().

## ldns_key_algo_supported()

int ldns_key_algo_supported | ( | int | algo | ) |

See if a key algorithm is supported.

Parameters

  [in] | algo | the signing algorithm number.

Returns
  true if supported.

Definition at line 2153 of file keys.c.

References ldns_struct_lookup_table::id, ldns_signing_algorithms, and ldns_struct_lookup_table::name.

## ldns_get_signing_algorithm_by_name()

ldns_signing_algorithm ldns_get_signing_algorithm_by_name | ( | const char * | name | ) |

Get signing algorithm by name.

Comparison is case insensitive.

Parameters

  [in] | name | string with the name.

Returns
  0 on parse failure or the algorithm number.

Definition at line 2164 of file keys.c.

References ldns_struct_lookup_table::id, LDNS_DH, LDNS_ECC, LDNS_INDIRECT, LDNS_PRIVATEDNS, LDNS_PRIVATEOID, LDNS_SIGN_DSA_NSEC3, LDNS_SIGN_ECC_GOST, LDNS_SIGN_HMACMD5, LDNS_SIGN_RSASHA1_NSEC3, ldns_signing_algorithms, and ldns_struct_lookup_table::name.

## Variable Documentation

## ldns_signing_algorithms

ldns_lookup_table ldns_signing_algorithms[]

extern

Definition at line 35 of file keys.c.