xref: /netbsd-src/crypto/external/bsd/heimdal/dist/lib/ntlm/heimntlm-protos.h (revision a8c74629f602faa0ccf8a463757d7baf858bbf3a)
1 /*	$NetBSD: heimntlm-protos.h,v 1.2 2019/12/15 22:50:51 christos Exp $	*/
2 
3 /* This is a generated file */
4 #ifndef __heimntlm_protos_h__
5 #define __heimntlm_protos_h__
6 #ifndef DOXY
7 
8 #include <stdarg.h>
9 
10 #ifdef __cplusplus
11 extern "C" {
12 #endif
13 
14 /**
15  * Generates an NTLMv1 session random with assosited session master key.
16  *
17  * @param key the ntlm v1 key
18  * @param len length of key
19  * @param session generated session nonce, should be freed with heim_ntlm_free_buf().
20  * @param master calculated session master key, should be freed with heim_ntlm_free_buf().
21  *
22  * @return In case of success 0 is return, an errors, a errno in what
23  * went wrong.
24  *
25  * @ingroup ntlm_core
26  */
27 
28 int
29 heim_ntlm_build_ntlm1_master (
30 	void */*key*/,
31 	size_t /*len*/,
32 	struct ntlm_buf */*session*/,
33 	struct ntlm_buf */*master*/);
34 
35 /**
36  * Generates an NTLMv2 session random with associated session master key.
37  *
38  * @param key the NTLMv2 key
39  * @param len length of key
40  * @param blob the NTLMv2 "blob"
41  * @param session generated session nonce, should be freed with heim_ntlm_free_buf().
42  * @param master calculated session master key, should be freed with heim_ntlm_free_buf().
43  *
44  * @return In case of success 0 is return, an errors, a errno in what
45  * went wrong.
46  *
47  * @ingroup ntlm_core
48  */
49 
50 int
51 heim_ntlm_build_ntlm2_master (
52 	void */*key*/,
53 	size_t /*len*/,
54 	struct ntlm_buf */*blob*/,
55 	struct ntlm_buf */*session*/,
56 	struct ntlm_buf */*master*/);
57 
58 /**
59  * Calculate LMv2 response
60  *
61  * @param key the ntlm key
62  * @param len length of key
63  * @param username name of the user, as sent in the message, assumed to be in UTF8.
64  * @param target the name of the target, assumed to be in UTF8.
65  * @param serverchallenge challenge as sent by the server in the type2 message.
66  * @param ntlmv2 calculated session key
67  * @param answer ntlm response answer, should be freed with heim_ntlm_free_buf().
68  *
69  * @return In case of success 0 is return, an errors, a errno in what
70  * went wrong.
71  *
72  * @ingroup ntlm_core
73  */
74 
75 int
76 heim_ntlm_calculate_lm2 (
77 	const void */*key*/,
78 	size_t /*len*/,
79 	const char */*username*/,
80 	const char */*target*/,
81 	const unsigned char serverchallenge[8],
82 	unsigned char ntlmv2[16],
83 	struct ntlm_buf */*answer*/);
84 
85 /**
86  * Calculate NTLMv1 response hash
87  *
88  * @param key the ntlm v1 key
89  * @param len length of key
90  * @param challenge sent by the server
91  * @param answer calculated answer, should be freed with heim_ntlm_free_buf().
92  *
93  * @return In case of success 0 is return, an errors, a errno in what
94  * went wrong.
95  *
96  * @ingroup ntlm_core
97  */
98 
99 int
100 heim_ntlm_calculate_ntlm1 (
101 	void */*key*/,
102 	size_t /*len*/,
103 	unsigned char challenge[8],
104 	struct ntlm_buf */*answer*/);
105 
106 /**
107  * Calculate NTLMv2 response
108  *
109  * @param key the ntlm key
110  * @param len length of key
111  * @param username name of the user, as sent in the message, assumed to be in UTF8.
112  * @param target the name of the target, assumed to be in UTF8.
113  * @param serverchallenge challenge as sent by the server in the type2 message.
114  * @param infotarget infotarget as sent by the server in the type2 message.
115  * @param ntlmv2 calculated session key
116  * @param answer ntlm response answer, should be freed with heim_ntlm_free_buf().
117  *
118  * @return In case of success 0 is return, an errors, a errno in what
119  * went wrong.
120  *
121  * @ingroup ntlm_core
122  */
123 
124 int
125 heim_ntlm_calculate_ntlm2 (
126 	const void */*key*/,
127 	size_t /*len*/,
128 	const char */*username*/,
129 	const char */*target*/,
130 	const unsigned char serverchallenge[8],
131 	const struct ntlm_buf */*infotarget*/,
132 	unsigned char ntlmv2[16],
133 	struct ntlm_buf */*answer*/);
134 
135 /**
136      * Third check with empty domain.
137  */
138 
139 int
140 heim_ntlm_calculate_ntlm2_sess (
141 	const unsigned char clnt_nonce[8],
142 	const unsigned char svr_chal[8],
143 	const unsigned char ntlm_hash[16],
144 	struct ntlm_buf */*lm*/,
145 	struct ntlm_buf */*ntlm*/);
146 
147 int
148 heim_ntlm_calculate_ntlm2_sess_hash (
149 	const unsigned char clnt_nonce[8],
150 	const unsigned char svr_chal[8],
151 	unsigned char verifier[8]);
152 
153 /**
154  * Decodes an NTLM targetinfo message
155  *
156  * @param data input data buffer with the encode NTLM targetinfo message
157  * @param ucs2 if the strings should be encoded with ucs2 (selected by flag in message).
158  * @param ti the decoded target info, should be freed with heim_ntlm_free_targetinfo().
159  *
160  * @return In case of success 0 is return, an errors, a errno in what
161  * went wrong.
162  *
163  * @ingroup ntlm_core
164  */
165 
166 int
167 heim_ntlm_decode_targetinfo (
168 	const struct ntlm_buf */*data*/,
169 	int /*ucs2*/,
170 	struct ntlm_targetinfo */*ti*/);
171 
172 int
173 heim_ntlm_decode_type1 (
174 	const struct ntlm_buf */*buf*/,
175 	struct ntlm_type1 */*data*/);
176 
177 int
178 heim_ntlm_decode_type2 (
179 	const struct ntlm_buf */*buf*/,
180 	struct ntlm_type2 */*type2*/);
181 
182 int
183 heim_ntlm_decode_type3 (
184 	const struct ntlm_buf */*buf*/,
185 	int /*ucs2*/,
186 	struct ntlm_type3 */*type3*/);
187 
188 void
189 heim_ntlm_derive_ntlm2_sess (
190 	const unsigned char sessionkey[16],
191 	const unsigned char */*clnt_nonce*/,
192 	size_t /*clnt_nonce_length*/,
193 	const unsigned char svr_chal[8],
194 	unsigned char derivedkey[16]);
195 
196 /**
197  * Encodes a ntlm_targetinfo message.
198  *
199  * @param ti the ntlm_targetinfo message to encode.
200  * @param ucs2 ignored
201  * @param data is the return buffer with the encoded message, should be
202  * freed with heim_ntlm_free_buf().
203  *
204  * @return In case of success 0 is return, an errors, a errno in what
205  * went wrong.
206  *
207  * @ingroup ntlm_core
208  */
209 
210 int
211 heim_ntlm_encode_targetinfo (
212 	const struct ntlm_targetinfo */*ti*/,
213 	int /*ucs2*/,
214 	struct ntlm_buf */*data*/);
215 
216 /**
217  * Encodes an ntlm_type1 message.
218  *
219  * @param type1 the ntlm_type1 message to encode.
220  * @param data is the return buffer with the encoded message, should be
221  * freed with heim_ntlm_free_buf().
222  *
223  * @return In case of success 0 is return, an errors, a errno in what
224  * went wrong.
225  *
226  * @ingroup ntlm_core
227  */
228 
229 int
230 heim_ntlm_encode_type1 (
231 	const struct ntlm_type1 */*type1*/,
232 	struct ntlm_buf */*data*/);
233 
234 /**
235  * Encodes an ntlm_type2 message.
236  *
237  * @param type2 the ntlm_type2 message to encode.
238  * @param data is the return buffer with the encoded message, should be
239  * freed with heim_ntlm_free_buf().
240  *
241  * @return In case of success 0 is return, an errors, a errno in what
242  * went wrong.
243  *
244  * @ingroup ntlm_core
245  */
246 
247 int
248 heim_ntlm_encode_type2 (
249 	const struct ntlm_type2 */*type2*/,
250 	struct ntlm_buf */*data*/);
251 
252 /**
253  * Encodes an ntlm_type3 message.
254  *
255  * @param type3 the ntlm_type3 message to encode.
256  * @param data is the return buffer with the encoded message, should be
257  * @param[out] mic_offset offset of message integrity code
258  * freed with heim_ntlm_free_buf().
259  *
260  * @return In case of success 0 is return, an errors, a errno in what
261  * went wrong.
262  *
263  * @ingroup ntlm_core
264  */
265 
266 int
267 heim_ntlm_encode_type3 (
268 	const struct ntlm_type3 */*type3*/,
269 	struct ntlm_buf */*data*/,
270 	size_t */*mic_offset*/);
271 
272 /**
273  * heim_ntlm_free_buf frees the ntlm buffer
274  *
275  * @param p buffer to be freed
276  *
277  * @ingroup ntlm_core
278  */
279 
280 void
281 heim_ntlm_free_buf (struct ntlm_buf */*p*/);
282 
283 /**
284  * Frees the ntlm_targetinfo message
285  *
286  * @param ti targetinfo to be freed
287  *
288  * @ingroup ntlm_core
289  */
290 
291 void
292 heim_ntlm_free_targetinfo (struct ntlm_targetinfo */*ti*/);
293 
294 /**
295  * Frees the ntlm_type1 message
296  *
297  * @param data message to be freed
298  *
299  * @ingroup ntlm_core
300  */
301 
302 void
303 heim_ntlm_free_type1 (struct ntlm_type1 */*data*/);
304 
305 /**
306  * Frees the ntlm_type2 message
307  *
308  * @param data message to be freed
309  *
310  * @ingroup ntlm_core
311  */
312 
313 void
314 heim_ntlm_free_type2 (struct ntlm_type2 */*data*/);
315 
316 /**
317  * Frees the ntlm_type3 message
318  *
319  * @param data message to be freed
320  *
321  * @ingroup ntlm_core
322  */
323 
324 void
325 heim_ntlm_free_type3 (struct ntlm_type3 */*data*/);
326 
327 /**
328  * Given a key and encrypted session, unwrap the session key
329  *
330  * @param baseKey the sessionBaseKey
331  * @param encryptedSession encrypted session, type3.session field.
332  * @param session generated session nonce, should be freed with heim_ntlm_free_buf().
333  *
334  * @return In case of success 0 is return, an errors, a errno in what
335  * went wrong.
336  *
337  * @ingroup ntlm_core
338  */
339 
340 int
341 heim_ntlm_keyex_unwrap (
342 	struct ntlm_buf */*baseKey*/,
343 	struct ntlm_buf */*encryptedSession*/,
344 	struct ntlm_buf */*session*/);
345 
346 int
347 heim_ntlm_keyex_wrap (
348 	struct ntlm_buf */*base_session*/,
349 	struct ntlm_buf */*session*/,
350 	struct ntlm_buf */*encryptedSession*/);
351 
352 /**
353  * Calculate the NTLM key, the password is assumed to be in UTF8.
354  *
355  * @param password password to calcute the key for.
356  * @param key calcuted key, should be freed with heim_ntlm_free_buf().
357  *
358  * @return In case of success 0 is return, an errors, a errno in what
359  * went wrong.
360  *
361  * @ingroup ntlm_core
362  */
363 
364 int
365 heim_ntlm_nt_key (
366 	const char */*password*/,
367 	struct ntlm_buf */*key*/);
368 
369 /**
370  * Generates an NTLMv2 session key.
371  *
372  * @param key the ntlm key
373  * @param len length of key
374  * @param username name of the user, as sent in the message, assumed to be in UTF8.
375  * @param target the name of the target, assumed to be in UTF8.
376  * @param upper_case_target upper case the target, should not be used only for legacy systems
377  * @param ntlmv2 the ntlmv2 session key
378  *
379  * @return 0 on success, or an error code on failure.
380  *
381  * @ingroup ntlm_core
382  */
383 
384 int
385 heim_ntlm_ntlmv2_key (
386 	const void */*key*/,
387 	size_t /*len*/,
388 	const char */*username*/,
389 	const char */*target*/,
390 	int /*upper_case_target*/,
391 	unsigned char ntlmv2[16]);
392 
393 time_t
394 heim_ntlm_ts2unixtime (uint64_t /*t*/);
395 
396 uint64_t
397 heim_ntlm_unix2ts_time (time_t /*unix_time*/);
398 
399 /**
400  @defgroup ntlm_core Heimdal NTLM library *
401  * The NTLM core functions implement the string2key generation
402  * function, message encode and decode function, and the hash function
403  * functions.
404  */
405 
406 size_t
407 heim_ntlm_unparse_flags (
408 	uint32_t /*flags*/,
409 	char */*s*/,
410 	size_t /*len*/);
411 
412 int
413 heim_ntlm_v1_base_session (
414 	void */*key*/,
415 	size_t /*len*/,
416 	struct ntlm_buf */*session*/);
417 
418 int
419 heim_ntlm_v2_base_session (
420 	void */*key*/,
421 	size_t /*len*/,
422 	struct ntlm_buf */*ntlmResponse*/,
423 	struct ntlm_buf */*session*/);
424 
425 /**
426  * Verify NTLMv2 response.
427  *
428  * @param key the ntlm key
429  * @param len length of key
430  * @param username name of the user, as sent in the message, assumed to be in UTF8.
431  * @param target the name of the target, assumed to be in UTF8.
432  * @param now the time now (0 if the library should pick it up itself)
433  * @param serverchallenge challenge as sent by the server in the type2 message.
434  * @param answer ntlm response answer, should be freed with heim_ntlm_free_buf().
435  * @param infotarget infotarget as sent by the server in the type2 message.
436  * @param ntlmv2 calculated session key
437  *
438  * @return In case of success 0 is return, an errors, a errno in what
439  * went wrong.
440  *
441  * @ingroup ntlm_core
442  */
443 
444 int
445 heim_ntlm_verify_ntlm2 (
446 	const void */*key*/,
447 	size_t /*len*/,
448 	const char */*username*/,
449 	const char */*target*/,
450 	time_t /*now*/,
451 	const unsigned char serverchallenge[8],
452 	const struct ntlm_buf */*answer*/,
453 	struct ntlm_buf */*infotarget*/,
454 	unsigned char ntlmv2[16]);
455 
456 #ifdef __cplusplus
457 }
458 #endif
459 
460 #endif /* DOXY */
461 #endif /* __heimntlm_protos_h__ */
462