|
1 /* $NetBSD: dst.h,v 1.1.1.1 2004/05/20 19:49:41 christos Exp $ */ |
|
2 |
|
3 /* |
|
4 * This version of this file is derived from Android 2.3 "Gingerbread", |
|
5 * which contains uncredited changes by Android/Google developers. It has |
|
6 * been modified in 2011 for use in the Android build of Mozilla Firefox by |
|
7 * Mozilla contributors (including Michael Edwards <m.k.edwards@gmail.com>, |
|
8 * and Steve Workman <sjhworkman@gmail.com>). |
|
9 * These changes are offered under the same license as the original NetBSD |
|
10 * file, whose copyright and license are unchanged above. |
|
11 */ |
|
12 |
|
13 #ifndef DST_H |
|
14 #define DST_H |
|
15 |
|
16 #ifndef HAS_DST_KEY |
|
17 typedef struct dst_key { |
|
18 char *dk_key_name; /* name of the key */ |
|
19 int dk_key_size; /* this is the size of the key in bits */ |
|
20 int dk_proto; /* what protocols this key can be used for */ |
|
21 int dk_alg; /* algorithm number from key record */ |
|
22 u_int32_t dk_flags; /* and the flags of the public key */ |
|
23 u_int16_t dk_id; /* identifier of the key */ |
|
24 } DST_KEY; |
|
25 #endif /* HAS_DST_KEY */ |
|
26 |
|
27 /* |
|
28 * do not taint namespace |
|
29 */ |
|
30 #define dst_bsafe_init __dst_bsafe_init |
|
31 #define dst_buffer_to_key __dst_buffer_to_key |
|
32 #define dst_check_algorithm __dst_check_algorithm |
|
33 #define dst_compare_keys __dst_compare_keys |
|
34 #define dst_cylink_init __dst_cylink_init |
|
35 #define dst_dnskey_to_key __dst_dnskey_to_key |
|
36 #define dst_eay_dss_init __dst_eay_dss_init |
|
37 #define dst_free_key __dst_free_key |
|
38 #define dst_generate_key __dst_generate_key |
|
39 #define dst_hmac_md5_init __dst_hmac_md5_init |
|
40 #define dst_init __dst_init |
|
41 #define dst_key_to_buffer __dst_key_to_buffer |
|
42 #define dst_key_to_dnskey __dst_key_to_dnskey |
|
43 #define dst_read_key __dst_read_key |
|
44 #define dst_rsaref_init __dst_rsaref_init |
|
45 #define dst_s_build_filename __dst_s_build_filename |
|
46 #define dst_s_calculate_bits __dst_s_calculate_bits |
|
47 #define dst_s_conv_bignum_b64_to_u8 __dst_s_conv_bignum_b64_to_u8 |
|
48 #define dst_s_conv_bignum_u8_to_b64 __dst_s_conv_bignum_u8_to_b64 |
|
49 #define dst_s_dns_key_id __dst_s_dns_key_id |
|
50 #define dst_s_dump __dst_s_dump |
|
51 #define dst_s_filename_length __dst_s_filename_length |
|
52 #define dst_s_fopen __dst_s_fopen |
|
53 #define dst_s_get_int16 __dst_s_get_int16 |
|
54 #define dst_s_get_int32 __dst_s_get_int32 |
|
55 #define dst_s_id_calc __dst_s_id_calc |
|
56 #define dst_s_put_int16 __dst_s_put_int16 |
|
57 #define dst_s_put_int32 __dst_s_put_int32 |
|
58 #define dst_s_quick_random __dst_s_quick_random |
|
59 #define dst_s_quick_random_set __dst_s_quick_random_set |
|
60 #define dst_s_random __dst_s_random |
|
61 #define dst_s_semi_random __dst_s_semi_random |
|
62 #define dst_s_verify_str __dst_s_verify_str |
|
63 #define dst_sig_size __dst_sig_size |
|
64 #define dst_sign_data __dst_sign_data |
|
65 #define dst_verify_data __dst_verify_data |
|
66 #define dst_write_key __dst_write_key |
|
67 |
|
68 /* |
|
69 * DST Crypto API defintions |
|
70 */ |
|
71 void dst_init(void); |
|
72 int dst_check_algorithm(const int); |
|
73 |
|
74 int dst_sign_data(const int, /* specifies INIT/UPDATE/FINAL/ALL */ |
|
75 DST_KEY *, /* the key to use */ |
|
76 void **, /* pointer to state structure */ |
|
77 const u_char *, /* data to be signed */ |
|
78 const int, /* length of input data */ |
|
79 u_char *, /* buffer to write signature to */ |
|
80 const int); /* size of output buffer */ |
|
81 |
|
82 int dst_verify_data(const int, /* specifies INIT/UPDATE/FINAL/ALL */ |
|
83 DST_KEY *, /* the key to use */ |
|
84 void **, /* pointer to state structure */ |
|
85 const u_char *, /* data to be verified */ |
|
86 const int, /* length of input data */ |
|
87 const u_char *, /* buffer containing signature */ |
|
88 const int); /* length of signature */ |
|
89 |
|
90 |
|
91 DST_KEY *dst_read_key(const char *, /* name of key */ |
|
92 const u_int16_t, /* key tag identifier */ |
|
93 const int, /* key algorithm */ |
|
94 const int); /* Private/PublicKey wanted*/ |
|
95 |
|
96 int dst_write_key(const DST_KEY *, /* key to write out */ |
|
97 const int); /* Public/Private */ |
|
98 |
|
99 DST_KEY *dst_dnskey_to_key(const char *, /* KEY record name */ |
|
100 const u_char *, /* KEY RDATA */ |
|
101 const int); /* size of input buffer*/ |
|
102 |
|
103 |
|
104 int dst_key_to_dnskey(const DST_KEY *, /* key to translate */ |
|
105 u_char *, /* output buffer */ |
|
106 const int); /* size of out_storage*/ |
|
107 |
|
108 |
|
109 DST_KEY *dst_buffer_to_key(const char *, /* name of the key */ |
|
110 const int, /* algorithm */ |
|
111 const int, /* dns flags */ |
|
112 const int, /* dns protocol */ |
|
113 const u_char *, /* key in dns wire fmt */ |
|
114 const int); /* size of key */ |
|
115 |
|
116 |
|
117 int dst_key_to_buffer(DST_KEY *, u_char *, int); |
|
118 |
|
119 DST_KEY *dst_generate_key(const char *, /* name of new key */ |
|
120 const int, /* key algorithm to generate */ |
|
121 const int, /* size of new key */ |
|
122 const int, /* alg dependent parameter*/ |
|
123 const int, /* key DNS flags */ |
|
124 const int); /* key DNS protocol */ |
|
125 |
|
126 DST_KEY *dst_free_key(DST_KEY *); |
|
127 int dst_compare_keys(const DST_KEY *, const DST_KEY *); |
|
128 |
|
129 int dst_sig_size(DST_KEY *); |
|
130 |
|
131 |
|
132 /* support for dns key tags/ids */ |
|
133 u_int16_t dst_s_dns_key_id(const u_char *, const int); |
|
134 u_int16_t dst_s_id_calc(const u_char *, const int); |
|
135 |
|
136 /* Used by callers as well as by the library. */ |
|
137 #define RAW_KEY_SIZE 8192 /* large enough to store any key */ |
|
138 |
|
139 /* DST_API control flags */ |
|
140 /* These are used used in functions dst_sign_data and dst_verify_data */ |
|
141 #define SIG_MODE_INIT 1 /* initialize digest */ |
|
142 #define SIG_MODE_UPDATE 2 /* add data to digest */ |
|
143 #define SIG_MODE_FINAL 4 /* generate/verify signature */ |
|
144 #define SIG_MODE_ALL (SIG_MODE_INIT|SIG_MODE_UPDATE|SIG_MODE_FINAL) |
|
145 |
|
146 /* Flags for dst_read_private_key() */ |
|
147 #define DST_FORCE_READ 0x1000000 |
|
148 #define DST_CAN_SIGN 0x010F |
|
149 #define DST_NO_AUTHEN 0x8000 |
|
150 #define DST_EXTEND_FLAG 0x1000 |
|
151 #define DST_STANDARD 0 |
|
152 #define DST_PRIVATE 0x2000000 |
|
153 #define DST_PUBLIC 0x4000000 |
|
154 #define DST_RAND_SEMI 1 |
|
155 #define DST_RAND_STD 2 |
|
156 #define DST_RAND_KEY 3 |
|
157 #define DST_RAND_DSS 4 |
|
158 |
|
159 |
|
160 /* DST algorithm codes */ |
|
161 #define KEY_RSA 1 |
|
162 #define KEY_DH 2 |
|
163 #define KEY_DSA 3 |
|
164 #define KEY_PRIVATE 254 |
|
165 #define KEY_EXPAND 255 |
|
166 #define KEY_HMAC_MD5 157 |
|
167 #define KEY_HMAC_SHA1 158 |
|
168 #define UNKNOWN_KEYALG 0 |
|
169 #define DST_MAX_ALGS KEY_HMAC_SHA1 |
|
170 |
|
171 /* DST constants to locations in KEY record changes in new KEY record */ |
|
172 #define DST_FLAGS_SIZE 2 |
|
173 #define DST_KEY_PROT 2 |
|
174 #define DST_KEY_ALG 3 |
|
175 #define DST_EXT_FLAG 4 |
|
176 #define DST_KEY_START 4 |
|
177 |
|
178 #ifndef SIGN_F_NOKEY |
|
179 #define SIGN_F_NOKEY 0xC000 |
|
180 #endif |
|
181 |
|
182 /* error codes from dst routines */ |
|
183 #define SIGN_INIT_FAILURE (-23) |
|
184 #define SIGN_UPDATE_FAILURE (-24) |
|
185 #define SIGN_FINAL_FAILURE (-25) |
|
186 #define VERIFY_INIT_FAILURE (-26) |
|
187 #define VERIFY_UPDATE_FAILURE (-27) |
|
188 #define VERIFY_FINAL_FAILURE (-28) |
|
189 #define MISSING_KEY_OR_SIGNATURE (-30) |
|
190 #define UNSUPPORTED_KEYALG (-31) |
|
191 |
|
192 #endif /* DST_H */ |