keys.h

Go to the documentation of this file.
00001 /*
00002  * 
00003  * keys.h
00004  *
00005  * priv key definitions
00006  *
00007  * a Net::DNS like library for C
00008  *
00009  * (c) NLnet Labs, 2005-2006
00010  *
00011  * See the file LICENSE for the license
00012  */
00013 
00021 #ifndef LDNS_KEYS_H
00022 #define LDNS_KEYS_H
00023 
00024 #ifdef HAVE_SSL
00025 #include <openssl/ssl.h>
00026 #endif /* HAVE_SSL */
00027 #include <ldns/dnssec.h>
00028 #include <ldns/util.h>
00029 
00030 extern ldns_lookup_table ldns_signing_algorithms[];
00031 
00032 #define LDNS_KEY_ZONE_KEY 0x0100
00033 #define LDNS_KEY_SEP_KEY 0x0001
00034 
00038 enum ldns_enum_algorithm
00039 {
00040         LDNS_RSAMD5             = 1,
00041         LDNS_DH                 = 2,
00042         LDNS_DSA                = 3,
00043         LDNS_ECC                = 4,
00044         LDNS_RSASHA1            = 5,
00045         LDNS_INDIRECT           = 252,
00046         LDNS_PRIVATEDNS         = 253,
00047         LDNS_PRIVATEOID         = 254
00048 };
00049 typedef enum ldns_enum_algorithm ldns_algorithm;
00050 
00054 enum ldns_enum_hash
00055 {
00056         LDNS_SHA1               = 1,
00057         LDNS_SHA256             = 2
00058 };
00059 typedef enum ldns_enum_hash ldns_hash;
00060 
00064 enum ldns_enum_signing_algorithm
00065 {
00066         LDNS_SIGN_RSAMD5         = LDNS_RSAMD5,
00067         LDNS_SIGN_RSASHA1        = LDNS_RSASHA1,
00068         LDNS_SIGN_DSA            = LDNS_DSA,
00069         LDNS_SIGN_HMACMD5        = 150  /* not official! */
00070 };
00071 typedef enum ldns_enum_signing_algorithm ldns_signing_algorithm;
00072 
00083 struct ldns_struct_key {
00084         ldns_signing_algorithm _alg;
00086         /* TODO remove unions? */
00087         union {
00088 #ifdef HAVE_SSL
00089                 RSA     *rsa;
00090                 DSA     *dsa;
00091 #endif /* HAVE_SSL */
00092                 unsigned char *hmac;
00093         } _key;
00095         union {
00097                 struct {
00099                         uint32_t orig_ttl;
00101                         uint32_t inception;
00103                         uint32_t expiration;
00105                         uint16_t keytag;
00107                         uint16_t flags;
00108                 }  dnssec;
00109         } _extra;
00111         ldns_rdf *_pubkey_owner;
00112 };
00113 typedef struct ldns_struct_key ldns_key;
00114 
00118 struct ldns_struct_key_list
00119 {
00120         size_t _key_count;
00121         ldns_key **_keys;
00122 };
00123 typedef struct ldns_struct_key_list ldns_key_list;
00124 
00125 
00130 ldns_key_list *ldns_key_list_new();
00131 
00136 ldns_key *ldns_key_new();
00137 
00145 ldns_key *ldns_key_new_frm_algorithm(ldns_signing_algorithm a, uint16_t size);
00146 
00157 ldns_status ldns_key_new_frm_fp(ldns_key **k, FILE *fp);
00158 
00170 ldns_status ldns_key_new_frm_fp_l(ldns_key **k, FILE *fp, int *line_nr);
00171 
00172 #ifdef HAVE_SSL
00173 
00179 RSA *ldns_key_new_frm_fp_rsa(FILE *fp);
00180 #endif /* HAVE_SSL */
00181 
00182 #ifdef HAVE_SSL
00183 
00190 RSA *ldns_key_new_frm_fp_rsa_l(FILE *fp, int *line_nr);
00191 #endif /* HAVE_SSL */
00192 
00193 #ifdef HAVE_SSL
00194 
00200 DSA *ldns_key_new_frm_fp_dsa(FILE *fp);
00201 #endif /* HAVE_SSL */
00202 
00203 #ifdef HAVE_SSL
00204 
00211 DSA *ldns_key_new_frm_fp_dsa_l(FILE *fp, int *line_nr);
00212 #endif /* HAVE_SSL */
00213 
00214 /* acces write functions */
00220 void ldns_key_set_algorithm(ldns_key *k, ldns_signing_algorithm l);
00221 #ifdef HAVE_SSL
00222 
00227 void ldns_key_set_rsa_key(ldns_key *k, RSA *r);
00233 void ldns_key_set_dsa_key(ldns_key *k, DSA *d);
00234 #endif /* HAVE_SSL */
00235 
00240 void ldns_key_set_hmac_key(ldns_key *k, unsigned char *hmac);
00246 void ldns_key_set_origttl(ldns_key *k, uint32_t t);
00252 void ldns_key_set_inception(ldns_key *k, uint32_t i);
00258 void ldns_key_set_expiration(ldns_key *k, uint32_t e);
00264 void ldns_key_set_pubkey_owner(ldns_key *k, ldns_rdf *r);
00270 void ldns_key_set_keytag(ldns_key *k, uint16_t tag);
00276 void ldns_key_set_flags(ldns_key *k, uint16_t flags);
00282 void ldns_key_list_set_key_count(ldns_key_list *key, size_t count);
00283 
00290 bool ldns_key_list_push_key(ldns_key_list *key_list, ldns_key *key);
00291 
00297 size_t ldns_key_list_key_count(const ldns_key_list *key_list);
00298 
00305 ldns_key *ldns_key_list_key(const ldns_key_list *key, size_t nr);
00306 
00307 #ifdef HAVE_SSL
00308 
00313 RSA *ldns_key_rsa_key(const ldns_key *k);
00314 #endif /* HAVE_SSL */
00315 
00319 #ifdef HAVE_SSL
00320 DSA *ldns_key_dsa_key(const ldns_key *k);
00321 #endif /* HAVE_SSL */
00322 
00328 ldns_signing_algorithm ldns_key_algorithm(const ldns_key *k);
00334 unsigned char *ldns_key_hmac_key(const ldns_key *k);
00340 uint32_t ldns_key_origttl(const ldns_key *k);
00346 uint32_t ldns_key_inception(const ldns_key *k);
00352 uint32_t ldns_key_expiration(const ldns_key *k);
00358 uint16_t ldns_key_keytag(const ldns_key *k);
00364 ldns_rdf *ldns_key_pubkey_owner(const ldns_key *k);
00370 uint16_t ldns_key_flags(const ldns_key *k);
00371 
00377 ldns_key *ldns_key_list_pop_key(ldns_key_list *key_list);
00378 
00385 ldns_rr *ldns_key2rr(const ldns_key *k);
00386 
00393 void ldns_key_print(FILE *output, const ldns_key *k);
00394 
00400 void ldns_key_free(ldns_key *key);
00401 
00407 void ldns_key_deep_free(ldns_key *key);
00408 
00413 void ldns_key_list_free(ldns_key_list *key_list);
00414 
00415 #endif /* LDNS_KEYS_H */

Generated on Fri Nov 23 00:48:29 2007 for ldns by  doxygen 1.5.3-20071008