/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "Licence").
 * You may not use this file except in compliance with the Licence.
 *
 * You can obtain a copy of the licence at RISC OS path @.^.LICENCE
 * or  http://www.riscosdev.com/lanman98/LICENCE.CDDL
 * See the Licence for the specific language governing permissions
 * and limitations under the Licence.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the Licence file. If applicable, add the
 * following below this CDDL HEADER, with the fields enclosed by
 * brackets "[]" replaced with your own identifying information:
 * Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 *   Portions Copyright RISC OS Developments 2019+, credited to the RISC OS One Project.
 */

/*
 *   The three NTLMSSP messages, as [MS-NLMP].
 *
 *   SMB1 carried the challenge in its own session setup reply and the
 *   response in the next request.  SMB2 has no such fields: it carries an
 *   opaque security blob instead, and this is what goes in it.  The
 *   exchange is the same shape as before - the server offers a challenge,
 *   the client answers it - but the challenge now arrives with a list of
 *   target information which has to be folded into the answer verbatim.
 *
 *   Sent raw, without a SPNEGO wrapper.  Samba accepts that; Windows
 *   expects the wrapper, which is why this alone does not reach it.
 *
 *   Nothing here touches the network, so it can be checked against the
 *   worked example in the specification.
 */

#ifndef _NTLMSSP_
#define _NTLMSSP_

#include "ntlm.h"

int NTLMSSPNegotiate(unsigned char *out, int out_max);
/*
    The first message, which asks the server to state its terms.  Returns
    the length written, or 0 if it would not fit.
*/

int NTLMSSPParseChallenge(const unsigned char *msg, int len,
                          unsigned char challenge[NTLM_CHAL_LEN],
                          const unsigned char **target_info,
                          int *target_len);
/*
    Pick the server challenge and the target information out of the second
    message.  target_info points into msg and lives as long as it does.
    Returns 1 if the message was one, 0 if it was not.
*/

int NTLMSSPAnonymous(char *workstation, unsigned char *out, int out_max);
/*
    Ask to be let in without a name.  Returns the length written, or 0 if
    it would not fit.  A session got this way has no key and is never
    signed.
*/

int NTLMSSPAuthenticate(char *user, char *domain, char *workstation,
                        unsigned char nt_hash[NTLM_HASH_LEN],
                        unsigned char challenge[NTLM_CHAL_LEN],
                        unsigned char *client_challenge,
                        unsigned int time_low, unsigned int time_high,
                        const unsigned char *target_info, int target_len,
                        unsigned char *session_key,
                        unsigned char *out, int out_max);
/*
    The third message, carrying the NTLMv2 answer.  session_key, if not
    NULL, receives the 16 byte session base key, which is what signing is
    later derived from.  Returns the length written, or 0.
*/

#endif
