1 #pragma ident	"%Z%%M%	%I%	%E% SMI"
2 
3 /*
4  * src/lib/krb5/asn.1/asn1_k_encode.h
5  *
6  * Copyright 1994 by the Massachusetts Institute of Technology.
7  * All Rights Reserved.
8  *
9  * Export of this software from the United States of America may
10  *   require a specific license from the United States Government.
11  *   It is the responsibility of any person or organization contemplating
12  *   export to obtain such a license before exporting.
13  *
14  * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
15  * distribute this software and its documentation for any purpose and
16  * without fee is hereby granted, provided that the above copyright
17  * notice appear in all copies and that both that copyright notice and
18  * this permission notice appear in supporting documentation, and that
19  * the name of M.I.T. not be used in advertising or publicity pertaining
20  * to distribution of the software without specific, written prior
21  * permission.  Furthermore if you modify this software you must label
22  * your software as modified software and not distribute it in such a
23  * fashion that it might be confused with the original M.I.T. software.
24  * M.I.T. makes no representations about the suitability of
25  * this software for any purpose.  It is provided "as is" without express
26  * or implied warranty.
27  */
28 
29 #ifndef __ASN1_ENCODE_KRB5_H__
30 #define __ASN1_ENCODE_KRB5_H__
31 
32 #include "k5-int.h"
33 #include <stdio.h>
34 #include "asn1buf.h"
35 
36 /*
37    Overview
38 
39      Encoding routines for various ASN.1 "substructures" as defined in
40      the krb5 protocol.
41 
42    Operations
43 
44     asn1_encode_krb5_flags
45     asn1_encode_ap_options
46     asn1_encode_ticket_flags
47     asn1_encode_kdc_options
48     asn1_encode_kerberos_time
49 
50     asn1_encode_realm
51     asn1_encode_principal_name
52     asn1_encode_encrypted_data
53     asn1_encode_authorization_data
54     asn1_encode_krb5_authdata_elt
55     asn1_encode_kdc_rep
56     asn1_encode_ticket
57     asn1_encode_encryption_key
58     asn1_encode_checksum
59     asn1_encode_host_address
60     asn1_encode_transited_encoding
61     asn1_encode_enc_kdc_rep_part
62     asn1_encode_kdc_req
63     asn1_encode_kdc_req_body
64     asn1_encode_krb_safe_body
65     asn1_encode_krb_cred_info
66     asn1_encode_last_req_entry
67     asn1_encode_pa_data
68 
69     asn1_encode_host_addresses
70     asn1_encode_last_req
71     asn1_encode_sequence_of_pa_data
72     asn1_encode_sequence_of_ticket
73     asn1_encode_sequence_of_enctype
74     asn1_encode_sequence_of_checksum
75     asn1_encode_sequence_of_krb_cred_info
76 */
77 
78 /*
79 **** for simple val's ****
80 asn1_error_code asn1_encode_asn1_type(asn1buf *buf,
81                                       const krb5_type val,
82 				      int *retlen);
83    requires  *buf is allocated
84    effects   Inserts the encoding of val into *buf and
85               returns the length of this encoding in *retlen.
86 	     Returns ASN1_MISSING_FIELD if a required field is empty in val.
87 	     Returns ENOMEM if memory runs out.
88 
89 **** for struct val's ****
90 asn1_error_code asn1_encode_asn1_type(asn1buf *buf,
91                                       const krb5_type *val,
92 				      int *retlen);
93    requires  *buf is allocated
94    effects   Inserts the encoding of *val into *buf and
95               returns the length of this encoding in *retlen.
96 	     Returns ASN1_MISSING_FIELD if a required field is empty in val.
97 	     Returns ENOMEM if memory runs out.
98 
99 **** for array val's ****
100 asn1_error_code asn1_encode_asn1_type(asn1buf *buf,
101                                       const krb5_type **val,
102 				      int *retlen);
103    requires  *buf is allocated, **val != NULL, *val[0] != NULL,
104               **val is a NULL-terminated array of pointers to krb5_type
105    effects   Inserts the encoding of **val into *buf and
106               returns the length of this encoding in *retlen.
107 	     Returns ASN1_MISSING_FIELD if a required field is empty in val.
108 	     Returns ENOMEM if memory runs out.
109 */
110 
111 asn1_error_code asn1_encode_ui_4 (asn1buf *buf,
112 					    const krb5_ui_4 val,
113 					    unsigned int *retlen);
114 
115 asn1_error_code asn1_encode_msgtype (asn1buf *buf,
116 					       const /*krb5_msgtype*/int val,
117 					       unsigned int *retlen);
118 
119 asn1_error_code asn1_encode_realm
120 	(asn1buf *buf, const krb5_principal val, unsigned int *retlen);
121 
122 asn1_error_code asn1_encode_principal_name
123 	(asn1buf *buf, const krb5_principal val, unsigned int *retlen);
124 
125 asn1_error_code asn1_encode_encrypted_data
126 	(asn1buf *buf, const krb5_enc_data *val, unsigned int *retlen);
127 
128 asn1_error_code asn1_encode_krb5_flags
129 	(asn1buf *buf, const krb5_flags val, unsigned int *retlen);
130 
131 asn1_error_code asn1_encode_ap_options
132 	(asn1buf *buf, const krb5_flags val, unsigned int *retlen);
133 
134 asn1_error_code asn1_encode_ticket_flags
135 	(asn1buf *buf, const krb5_flags val, unsigned int *retlen);
136 
137 asn1_error_code asn1_encode_kdc_options
138 	(asn1buf *buf, const krb5_flags val, unsigned int *retlen);
139 
140 asn1_error_code asn1_encode_authorization_data
141 	(asn1buf *buf, const krb5_authdata **val, unsigned int *retlen);
142 
143 asn1_error_code asn1_encode_krb5_authdata_elt
144 	(asn1buf *buf, const krb5_authdata *val, unsigned int *retlen);
145 
146 asn1_error_code asn1_encode_kdc_rep
147 	(int msg_type, asn1buf *buf, const krb5_kdc_rep *val,
148 		   unsigned int *retlen);
149 
150 asn1_error_code asn1_encode_enc_kdc_rep_part
151 	(asn1buf *buf, const krb5_enc_kdc_rep_part *val,
152 		   unsigned int *retlen);
153 
154 asn1_error_code asn1_encode_ticket
155 	(asn1buf *buf, const krb5_ticket *val, unsigned int *retlen);
156 
157 asn1_error_code asn1_encode_encryption_key
158 	(asn1buf *buf, const krb5_keyblock *val, unsigned int *retlen);
159 
160 asn1_error_code asn1_encode_kerberos_time
161 	(asn1buf *buf, const krb5_timestamp val, unsigned int *retlen);
162 
163 asn1_error_code asn1_encode_checksum
164 	(asn1buf *buf, const krb5_checksum *val, unsigned int *retlen);
165 
166 asn1_error_code asn1_encode_host_address
167 	(asn1buf *buf, const krb5_address *val, unsigned int *retlen);
168 
169 asn1_error_code asn1_encode_host_addresses
170 	(asn1buf *buf, const krb5_address **val, unsigned int *retlen);
171 
172 asn1_error_code asn1_encode_transited_encoding
173 	(asn1buf *buf, const krb5_transited *val, unsigned int *retlen);
174 
175 asn1_error_code asn1_encode_last_req
176 	(asn1buf *buf, const krb5_last_req_entry **val,
177 		   unsigned int *retlen);
178 
179 asn1_error_code asn1_encode_sequence_of_pa_data
180 	(asn1buf *buf, const krb5_pa_data **val, unsigned int *retlen);
181 
182 asn1_error_code asn1_encode_sequence_of_ticket
183 	(asn1buf *buf, const krb5_ticket **val, unsigned int *retlen);
184 
185 asn1_error_code asn1_encode_sequence_of_enctype
186 	(asn1buf *buf,
187 		   const int len, const krb5_enctype *val,
188 		   unsigned int *retlen);
189 
190 asn1_error_code asn1_encode_sequence_of_checksum
191 	(asn1buf *buf, const krb5_checksum **val, unsigned int *retlen);
192 
193 asn1_error_code asn1_encode_kdc_req
194 	(int msg_type,
195 		   asn1buf *buf,
196 		   const krb5_kdc_req *val,
197 		   unsigned int *retlen);
198 
199 asn1_error_code asn1_encode_kdc_req_body
200 	(asn1buf *buf, const krb5_kdc_req *val, unsigned int *retlen);
201 
202 asn1_error_code asn1_encode_krb_safe_body
203 	(asn1buf *buf, const krb5_safe *val, unsigned int *retlen);
204 
205 asn1_error_code asn1_encode_sequence_of_krb_cred_info
206 	(asn1buf *buf, const krb5_cred_info **val, unsigned int *retlen);
207 
208 asn1_error_code asn1_encode_krb_cred_info
209 	(asn1buf *buf, const krb5_cred_info *val, unsigned int *retlen);
210 
211 asn1_error_code asn1_encode_last_req_entry
212 	(asn1buf *buf, const krb5_last_req_entry *val,
213 		   unsigned int *retlen);
214 
215 asn1_error_code asn1_encode_pa_data
216 	(asn1buf *buf, const krb5_pa_data *val, unsigned int *retlen);
217 
218 asn1_error_code asn1_encode_alt_method
219 	(asn1buf *buf, const krb5_alt_method *val,
220 		   unsigned int *retlen);
221 
222 asn1_error_code asn1_encode_etype_info_entry
223 	(asn1buf *buf, const krb5_etype_info_entry *val,
224 		   unsigned int *retlen, int etype_info2);
225 
226 asn1_error_code asn1_encode_etype_info
227 	(asn1buf *buf, const krb5_etype_info_entry **val,
228 		   unsigned int *retlen, int etype_info2);
229 
230 asn1_error_code asn1_encode_passwdsequence
231 	(asn1buf *buf, const passwd_phrase_element *val, unsigned int *retlen);
232 
233 asn1_error_code asn1_encode_sequence_of_passwdsequence
234 	(asn1buf *buf, const passwd_phrase_element **val,
235 	unsigned int *retlen);
236 
237 asn1_error_code asn1_encode_sam_flags
238 	(asn1buf * buf, const krb5_flags val, unsigned int *retlen);
239 
240 asn1_error_code asn1_encode_sam_challenge
241 	(asn1buf *buf, const krb5_sam_challenge * val, unsigned int *retlen);
242 
243 asn1_error_code asn1_encode_sam_challenge_2
244 	(asn1buf *buf, const krb5_sam_challenge_2 * val, unsigned int *retlen);
245 
246 asn1_error_code asn1_encode_sam_challenge_2_body
247 	(asn1buf *buf, const krb5_sam_challenge_2_body * val,
248 		   unsigned int *retlen);
249 
250 asn1_error_code asn1_encode_sam_key
251 	(asn1buf *buf, const krb5_sam_key *val, unsigned int *retlen);
252 
253 asn1_error_code asn1_encode_enc_sam_response_enc
254 	(asn1buf *buf, const krb5_enc_sam_response_enc *val,
255 		   unsigned int *retlen);
256 
257 asn1_error_code asn1_encode_enc_sam_response_enc_2
258 	(asn1buf *buf, const krb5_enc_sam_response_enc_2 *val,
259 		   unsigned int *retlen);
260 
261 asn1_error_code asn1_encode_sam_response
262 	(asn1buf *buf, const krb5_sam_response *val, unsigned int *retlen);
263 
264 asn1_error_code asn1_encode_sam_response_2
265 	(asn1buf *buf, const krb5_sam_response_2 *val, unsigned int *retlen);
266 
267 asn1_error_code asn1_encode_predicted_sam_response
268 	(asn1buf *buf, const krb5_predicted_sam_response *val,
269 		   unsigned int *retlen);
270 
271 asn1_error_code asn1_encode_krb_saved_safe_body
272 	(asn1buf *buf, const krb5_data *body, unsigned int *retlen);
273 
274 #endif
275