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...

Defines

#define LDNS_KEY_ZONE_KEY   0x0100
#define LDNS_KEY_SEP_KEY   0x0001

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 ldns_struct_key ldns_key
typedef 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_INDIRECT = 252, LDNS_PRIVATEDNS = 253, LDNS_PRIVATEOID = 254
}
 Algorithms used in dns. More...
enum  ldns_enum_hash { LDNS_SHA1 = 1, LDNS_SHA256 = 2 }
 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_HMACMD5 = 157 }
 Algorithms used in dns for signing. More...

Functions

ldns_key_listldns_key_list_new ()
 Creates a new empty key list.
ldns_keyldns_key_new ()
 Creates a new empty key structure.
ldns_keyldns_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.
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_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.
void ldns_key_set_hmac_key (ldns_key *k, unsigned char *hmac)
 Set the key's hmac data.
void ldns_key_set_hmac_size (ldns_key *k, size_t 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.
bool 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_keyldns_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
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
unsigned char * ldns_key_hmac_key (const ldns_key *k)
 return the hmac 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_rdfldns_key_pubkey_owner (const ldns_key *k)
 return the public key's owner
uint16_t ldns_key_flags (const ldns_key *k)
 return the flag of the key
ldns_keyldns_key_list_pop_key (ldns_key_list *key_list)
 pops the last rr from a keylist
ldns_rrldns_key2rr (const ldns_key *k)
 converts a ldns_key to a public key rr
void ldns_key_print (FILE *output, const ldns_key *k)
 print a private key to the file ouput
void ldns_key_free (ldns_key *key)
 frees a key structure
void ldns_key_deep_free (ldns_key *key)
 frees a key structure and all it's internal data
void ldns_key_list_free (ldns_key_list *key_list)
 Frees a key list structure.

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.


Define Documentation

#define LDNS_KEY_ZONE_KEY   0x0100

Definition at line 32 of file keys.h.

#define LDNS_KEY_SEP_KEY   0x0001

Definition at line 33 of file keys.h.


Typedef Documentation

typedef enum ldns_enum_algorithm ldns_algorithm

Definition at line 49 of file keys.h.

typedef enum ldns_enum_hash ldns_hash

Definition at line 59 of file keys.h.

typedef enum ldns_enum_signing_algorithm ldns_signing_algorithm

Definition at line 71 of file keys.h.

typedef struct ldns_struct_key ldns_key

Definition at line 116 of file keys.h.

typedef struct ldns_struct_key_list ldns_key_list

Definition at line 126 of file keys.h.


Enumeration Type Documentation

enum ldns_enum_algorithm

Algorithms used in dns.

Enumerator:
LDNS_RSAMD5 
LDNS_DH 
LDNS_DSA 
LDNS_ECC 
LDNS_RSASHA1 
LDNS_INDIRECT 
LDNS_PRIVATEDNS 
LDNS_PRIVATEOID 

Definition at line 38 of file keys.h.

enum ldns_enum_hash

Hashing algorithms used in the DS record.

Enumerator:
LDNS_SHA1 
LDNS_SHA256 

Definition at line 54 of file keys.h.

enum ldns_enum_signing_algorithm

Algorithms used in dns for signing.

Enumerator:
LDNS_SIGN_RSAMD5 
LDNS_SIGN_RSASHA1 
LDNS_SIGN_DSA 
LDNS_SIGN_HMACMD5 

Definition at line 64 of file keys.h.


Function Documentation

ldns_key_list* ldns_key_list_new (  ) 

Creates a new empty key list.

Returns:
a new ldns_key_list structure pointer

Definition at line 32 of file keys.c.

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

ldns_key* ldns_key_new (  ) 

Creates a new empty key structure.

Returns:
a new ldns_key * structure

Definition at line 45 of file keys.c.

References ldns_key_set_dsa_key(), ldns_key_set_expiration(), 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_rsa_key(), LDNS_KEY_ZONE_KEY, and LDNS_MALLOC.

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 426 of file keys.c.

References ldns_struct_key::_key, ldns_struct_key::dsa, LDNS_FREE, ldns_key_free(), ldns_key_new(), ldns_key_set_algorithm(), ldns_key_set_dsa_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_HMACMD5, LDNS_SIGN_RSAMD5, LDNS_SIGN_RSASHA1, LDNS_XMALLOC, and ldns_struct_key::rsa.

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.2.

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 68 of file keys.c.

References 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.2.

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 74 of file keys.c.

References ldns_calc_keytag(), ldns_fget_keyword_data_l(), LDNS_FREE, ldns_key2rr(), 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_dsa_key(), ldns_key_set_hmac_key(), ldns_key_set_hmac_size(), ldns_key_set_keytag(), ldns_key_set_rsa_key(), LDNS_MAX_LINELEN, ldns_rr_free(), LDNS_SIGN_DSA, LDNS_SIGN_HMACMD5, LDNS_SIGN_RSAMD5, LDNS_SIGN_RSASHA1, 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.

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 166 of file keys.c.

References 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 172 of file keys.c.

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

DSA* ldns_key_new_frm_fp_dsa ( FILE *  fp  ) 

frm_fp helper function.

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

Parameters:
[in] fp the file to parse
Returns:
NULL on failure otherwise a RSA structure

Definition at line 306 of file keys.c.

References 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 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 312 of file keys.c.

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

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 allocates 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 392 of file keys.c.

References 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 allocates 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 debugging purposes)
[out] hmac_size the number of bits in the resulting buffer
Returns:
NULL on failure otherwise a newly allocated char buffer

Definition at line 398 of file keys.c.

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

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 507 of file keys.c.

References ldns_struct_key::_alg.

void ldns_key_set_rsa_key ( ldns_key k,
RSA *  r 
)

Set the key's rsa data.

Parameters:
[in] k the key
[in] r the rsa data

Definition at line 519 of file keys.c.

References ldns_struct_key::_key, and ldns_struct_key::rsa.

void ldns_key_set_dsa_key ( ldns_key k,
DSA *  d 
)

Set the key's dsa data.

Parameters:
[in] k the key
[in] d the dsa data

Definition at line 525 of file keys.c.

References ldns_struct_key::_key, and ldns_struct_key::dsa.

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 hmac data

Definition at line 531 of file keys.c.

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

void ldns_key_set_hmac_size ( ldns_key k,
size_t  hmac_size 
)

Definition at line 537 of file keys.c.

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

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 543 of file keys.c.

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

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 549 of file keys.c.

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

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 555 of file keys.c.

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

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 561 of file keys.c.

References ldns_struct_key::_pubkey_owner.

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 567 of file keys.c.

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

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 513 of file keys.c.

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

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 cuont

Definition at line 657 of file keys.c.

References ldns_struct_key_list::_key_count.

bool 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 663 of file keys.c.

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

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 574 of file keys.c.

References ldns_struct_key_list::_key_count.

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 580 of file keys.c.

References ldns_struct_key_list::_keys, and ldns_key_list_key_count().

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 596 of file keys.c.

References ldns_struct_key::_key, and ldns_struct_key::rsa.

DSA* ldns_key_dsa_key ( const ldns_key k  ) 

returns the (openssl) DSA struct contained in the key

Definition at line 602 of file keys.c.

References ldns_struct_key::_key, and ldns_struct_key::dsa.

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 590 of file keys.c.

References ldns_struct_key::_alg.

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 608 of file keys.c.

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

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 614 of file keys.c.

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

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 620 of file keys.c.

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

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 632 of file keys.c.

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

uint32_t ldns_key_expiration ( const ldns_key k  ) 

return the key's expiration date

Parameters:
[in] k the key
Returns:
the experiration date

Definition at line 638 of file keys.c.

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

uint16_t ldns_key_keytag ( const ldns_key k  ) 

return the keytag

Parameters:
[in] k the key
Returns:
the keytag

Definition at line 644 of file keys.c.

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

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 650 of file keys.c.

References ldns_struct_key::_pubkey_owner.

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 626 of file keys.c.

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

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 687 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_rr* ldns_key2rr ( const ldns_key k  ) 

converts a ldns_key to a public key rr

Parameters:
[in] k the ldns_key to convert
Returns:
ldns_rr representation of the key

Definition at line 772 of file keys.c.

References LDNS_DNSSEC_KEYPROTO, LDNS_DSA, 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_new(), ldns_rr_push_rdf(), ldns_rr_set_owner(), ldns_rr_set_type(), LDNS_RR_TYPE_DNSKEY, LDNS_RR_TYPE_KEY, LDNS_RSAMD5, LDNS_RSASHA1, LDNS_SIGN_DSA, LDNS_SIGN_HMACMD5, LDNS_SIGN_RSAMD5, LDNS_SIGN_RSASHA1, LDNS_XMALLOC, and LDNS_XREALLOC.

void ldns_key_print ( FILE *  output,
const ldns_key k 
)

print a private key to the file ouput

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

Definition at line 494 of file keys.c.

References LDNS_FREE, and ldns_key2str().

void ldns_key_free ( ldns_key key  ) 

frees a key structure

Parameters:
[in] key the key object to free

Definition at line 856 of file keys.c.

References LDNS_FREE.

void ldns_key_deep_free ( ldns_key key  ) 

frees a key structure and all it's internal data

Parameters:
[in] key the key object to free

Definition at line 862 of file keys.c.

References LDNS_FREE, ldns_key_algorithm(), ldns_key_dsa_key(), ldns_key_hmac_key(), ldns_key_pubkey_owner(), ldns_key_rsa_key(), ldns_rdf_deep_free(), LDNS_SIGN_DSA, LDNS_SIGN_HMACMD5, LDNS_SIGN_RSAMD5, and LDNS_SIGN_RSASHA1.

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 889 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().


Variable Documentation

ldns_lookup_table ldns_signing_algorithms[]

Definition at line 22 of file keys.c.


Generated on Thu Nov 29 14:15:00 2007 for ldns by  doxygen 1.5.1