michael@0: /* $NetBSD: dst.h,v 1.1.1.1 2004/05/20 19:49:41 christos Exp $ */ michael@0: michael@0: /* michael@0: * This version of this file is derived from Android 2.3 "Gingerbread", michael@0: * which contains uncredited changes by Android/Google developers. It has michael@0: * been modified in 2011 for use in the Android build of Mozilla Firefox by michael@0: * Mozilla contributors (including Michael Edwards , michael@0: * and Steve Workman ). michael@0: * These changes are offered under the same license as the original NetBSD michael@0: * file, whose copyright and license are unchanged above. michael@0: */ michael@0: michael@0: #ifndef DST_H michael@0: #define DST_H michael@0: michael@0: #ifndef HAS_DST_KEY michael@0: typedef struct dst_key { michael@0: char *dk_key_name; /* name of the key */ michael@0: int dk_key_size; /* this is the size of the key in bits */ michael@0: int dk_proto; /* what protocols this key can be used for */ michael@0: int dk_alg; /* algorithm number from key record */ michael@0: u_int32_t dk_flags; /* and the flags of the public key */ michael@0: u_int16_t dk_id; /* identifier of the key */ michael@0: } DST_KEY; michael@0: #endif /* HAS_DST_KEY */ michael@0: michael@0: /* michael@0: * do not taint namespace michael@0: */ michael@0: #define dst_bsafe_init __dst_bsafe_init michael@0: #define dst_buffer_to_key __dst_buffer_to_key michael@0: #define dst_check_algorithm __dst_check_algorithm michael@0: #define dst_compare_keys __dst_compare_keys michael@0: #define dst_cylink_init __dst_cylink_init michael@0: #define dst_dnskey_to_key __dst_dnskey_to_key michael@0: #define dst_eay_dss_init __dst_eay_dss_init michael@0: #define dst_free_key __dst_free_key michael@0: #define dst_generate_key __dst_generate_key michael@0: #define dst_hmac_md5_init __dst_hmac_md5_init michael@0: #define dst_init __dst_init michael@0: #define dst_key_to_buffer __dst_key_to_buffer michael@0: #define dst_key_to_dnskey __dst_key_to_dnskey michael@0: #define dst_read_key __dst_read_key michael@0: #define dst_rsaref_init __dst_rsaref_init michael@0: #define dst_s_build_filename __dst_s_build_filename michael@0: #define dst_s_calculate_bits __dst_s_calculate_bits michael@0: #define dst_s_conv_bignum_b64_to_u8 __dst_s_conv_bignum_b64_to_u8 michael@0: #define dst_s_conv_bignum_u8_to_b64 __dst_s_conv_bignum_u8_to_b64 michael@0: #define dst_s_dns_key_id __dst_s_dns_key_id michael@0: #define dst_s_dump __dst_s_dump michael@0: #define dst_s_filename_length __dst_s_filename_length michael@0: #define dst_s_fopen __dst_s_fopen michael@0: #define dst_s_get_int16 __dst_s_get_int16 michael@0: #define dst_s_get_int32 __dst_s_get_int32 michael@0: #define dst_s_id_calc __dst_s_id_calc michael@0: #define dst_s_put_int16 __dst_s_put_int16 michael@0: #define dst_s_put_int32 __dst_s_put_int32 michael@0: #define dst_s_quick_random __dst_s_quick_random michael@0: #define dst_s_quick_random_set __dst_s_quick_random_set michael@0: #define dst_s_random __dst_s_random michael@0: #define dst_s_semi_random __dst_s_semi_random michael@0: #define dst_s_verify_str __dst_s_verify_str michael@0: #define dst_sig_size __dst_sig_size michael@0: #define dst_sign_data __dst_sign_data michael@0: #define dst_verify_data __dst_verify_data michael@0: #define dst_write_key __dst_write_key michael@0: michael@0: /* michael@0: * DST Crypto API defintions michael@0: */ michael@0: void dst_init(void); michael@0: int dst_check_algorithm(const int); michael@0: michael@0: int dst_sign_data(const int, /* specifies INIT/UPDATE/FINAL/ALL */ michael@0: DST_KEY *, /* the key to use */ michael@0: void **, /* pointer to state structure */ michael@0: const u_char *, /* data to be signed */ michael@0: const int, /* length of input data */ michael@0: u_char *, /* buffer to write signature to */ michael@0: const int); /* size of output buffer */ michael@0: michael@0: int dst_verify_data(const int, /* specifies INIT/UPDATE/FINAL/ALL */ michael@0: DST_KEY *, /* the key to use */ michael@0: void **, /* pointer to state structure */ michael@0: const u_char *, /* data to be verified */ michael@0: const int, /* length of input data */ michael@0: const u_char *, /* buffer containing signature */ michael@0: const int); /* length of signature */ michael@0: michael@0: michael@0: DST_KEY *dst_read_key(const char *, /* name of key */ michael@0: const u_int16_t, /* key tag identifier */ michael@0: const int, /* key algorithm */ michael@0: const int); /* Private/PublicKey wanted*/ michael@0: michael@0: int dst_write_key(const DST_KEY *, /* key to write out */ michael@0: const int); /* Public/Private */ michael@0: michael@0: DST_KEY *dst_dnskey_to_key(const char *, /* KEY record name */ michael@0: const u_char *, /* KEY RDATA */ michael@0: const int); /* size of input buffer*/ michael@0: michael@0: michael@0: int dst_key_to_dnskey(const DST_KEY *, /* key to translate */ michael@0: u_char *, /* output buffer */ michael@0: const int); /* size of out_storage*/ michael@0: michael@0: michael@0: DST_KEY *dst_buffer_to_key(const char *, /* name of the key */ michael@0: const int, /* algorithm */ michael@0: const int, /* dns flags */ michael@0: const int, /* dns protocol */ michael@0: const u_char *, /* key in dns wire fmt */ michael@0: const int); /* size of key */ michael@0: michael@0: michael@0: int dst_key_to_buffer(DST_KEY *, u_char *, int); michael@0: michael@0: DST_KEY *dst_generate_key(const char *, /* name of new key */ michael@0: const int, /* key algorithm to generate */ michael@0: const int, /* size of new key */ michael@0: const int, /* alg dependent parameter*/ michael@0: const int, /* key DNS flags */ michael@0: const int); /* key DNS protocol */ michael@0: michael@0: DST_KEY *dst_free_key(DST_KEY *); michael@0: int dst_compare_keys(const DST_KEY *, const DST_KEY *); michael@0: michael@0: int dst_sig_size(DST_KEY *); michael@0: michael@0: michael@0: /* support for dns key tags/ids */ michael@0: u_int16_t dst_s_dns_key_id(const u_char *, const int); michael@0: u_int16_t dst_s_id_calc(const u_char *, const int); michael@0: michael@0: /* Used by callers as well as by the library. */ michael@0: #define RAW_KEY_SIZE 8192 /* large enough to store any key */ michael@0: michael@0: /* DST_API control flags */ michael@0: /* These are used used in functions dst_sign_data and dst_verify_data */ michael@0: #define SIG_MODE_INIT 1 /* initialize digest */ michael@0: #define SIG_MODE_UPDATE 2 /* add data to digest */ michael@0: #define SIG_MODE_FINAL 4 /* generate/verify signature */ michael@0: #define SIG_MODE_ALL (SIG_MODE_INIT|SIG_MODE_UPDATE|SIG_MODE_FINAL) michael@0: michael@0: /* Flags for dst_read_private_key() */ michael@0: #define DST_FORCE_READ 0x1000000 michael@0: #define DST_CAN_SIGN 0x010F michael@0: #define DST_NO_AUTHEN 0x8000 michael@0: #define DST_EXTEND_FLAG 0x1000 michael@0: #define DST_STANDARD 0 michael@0: #define DST_PRIVATE 0x2000000 michael@0: #define DST_PUBLIC 0x4000000 michael@0: #define DST_RAND_SEMI 1 michael@0: #define DST_RAND_STD 2 michael@0: #define DST_RAND_KEY 3 michael@0: #define DST_RAND_DSS 4 michael@0: michael@0: michael@0: /* DST algorithm codes */ michael@0: #define KEY_RSA 1 michael@0: #define KEY_DH 2 michael@0: #define KEY_DSA 3 michael@0: #define KEY_PRIVATE 254 michael@0: #define KEY_EXPAND 255 michael@0: #define KEY_HMAC_MD5 157 michael@0: #define KEY_HMAC_SHA1 158 michael@0: #define UNKNOWN_KEYALG 0 michael@0: #define DST_MAX_ALGS KEY_HMAC_SHA1 michael@0: michael@0: /* DST constants to locations in KEY record changes in new KEY record */ michael@0: #define DST_FLAGS_SIZE 2 michael@0: #define DST_KEY_PROT 2 michael@0: #define DST_KEY_ALG 3 michael@0: #define DST_EXT_FLAG 4 michael@0: #define DST_KEY_START 4 michael@0: michael@0: #ifndef SIGN_F_NOKEY michael@0: #define SIGN_F_NOKEY 0xC000 michael@0: #endif michael@0: michael@0: /* error codes from dst routines */ michael@0: #define SIGN_INIT_FAILURE (-23) michael@0: #define SIGN_UPDATE_FAILURE (-24) michael@0: #define SIGN_FINAL_FAILURE (-25) michael@0: #define VERIFY_INIT_FAILURE (-26) michael@0: #define VERIFY_UPDATE_FAILURE (-27) michael@0: #define VERIFY_FINAL_FAILURE (-28) michael@0: #define MISSING_KEY_OR_SIGNATURE (-30) michael@0: #define UNSUPPORTED_KEYALG (-31) michael@0: michael@0: #endif /* DST_H */