mirror of
https://git.savannah.nongnu.org/git/lwip.git
synced 2025-08-03 21:14:40 +08:00
Minor changes: coding style (tabs, ident, etc...).
This commit is contained in:
parent
37a5a87057
commit
6bce832060
@ -28,7 +28,7 @@
|
|||||||
* 03-01-01 Marc Boucher <marc@mbsi.ca>
|
* 03-01-01 Marc Boucher <marc@mbsi.ca>
|
||||||
* Ported to lwIP.
|
* Ported to lwIP.
|
||||||
* 97-12-03 Guy Lancaster <lancasterg@acm.org>, Global Election Systems Inc.
|
* 97-12-03 Guy Lancaster <lancasterg@acm.org>, Global Election Systems Inc.
|
||||||
* Original built from BSD network code.
|
* Original built from BSD network code.
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
/*
|
/*
|
||||||
* chap.h - Challenge Handshake Authentication Protocol definitions.
|
* chap.h - Challenge Handshake Authentication Protocol definitions.
|
||||||
@ -62,7 +62,7 @@
|
|||||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
*
|
*
|
||||||
* $Id: chap.h,v 1.2 2007/11/29 22:19:57 fbernon Exp $
|
* $Id: chap.h,v 1.3 2007/12/02 22:56:19 fbernon Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef CHAP_H
|
#ifndef CHAP_H
|
||||||
@ -73,49 +73,49 @@
|
|||||||
*************************/
|
*************************/
|
||||||
|
|
||||||
/* Code + ID + length */
|
/* Code + ID + length */
|
||||||
#define CHAP_HEADERLEN 4
|
#define CHAP_HEADERLEN 4
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* CHAP codes.
|
* CHAP codes.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define CHAP_DIGEST_MD5 5 /* use MD5 algorithm */
|
#define CHAP_DIGEST_MD5 5 /* use MD5 algorithm */
|
||||||
#define MD5_SIGNATURE_SIZE 16 /* 16 bytes in a MD5 message digest */
|
#define MD5_SIGNATURE_SIZE 16 /* 16 bytes in a MD5 message digest */
|
||||||
#define CHAP_MICROSOFT 0x80 /* use Microsoft-compatible alg. */
|
#define CHAP_MICROSOFT 0x80 /* use Microsoft-compatible alg. */
|
||||||
#define MS_CHAP_RESPONSE_LEN 49 /* Response length for MS-CHAP */
|
#define MS_CHAP_RESPONSE_LEN 49 /* Response length for MS-CHAP */
|
||||||
|
|
||||||
#define CHAP_CHALLENGE 1
|
#define CHAP_CHALLENGE 1
|
||||||
#define CHAP_RESPONSE 2
|
#define CHAP_RESPONSE 2
|
||||||
#define CHAP_SUCCESS 3
|
#define CHAP_SUCCESS 3
|
||||||
#define CHAP_FAILURE 4
|
#define CHAP_FAILURE 4
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Challenge lengths (for challenges we send) and other limits.
|
* Challenge lengths (for challenges we send) and other limits.
|
||||||
*/
|
*/
|
||||||
#define MIN_CHALLENGE_LENGTH 32
|
#define MIN_CHALLENGE_LENGTH 32
|
||||||
#define MAX_CHALLENGE_LENGTH 64
|
#define MAX_CHALLENGE_LENGTH 64
|
||||||
#define MAX_RESPONSE_LENGTH 64 /* sufficient for MD5 or MS-CHAP */
|
#define MAX_RESPONSE_LENGTH 64 /* sufficient for MD5 or MS-CHAP */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Client (peer) states.
|
* Client (peer) states.
|
||||||
*/
|
*/
|
||||||
#define CHAPCS_INITIAL 0 /* Lower layer down, not opened */
|
#define CHAPCS_INITIAL 0 /* Lower layer down, not opened */
|
||||||
#define CHAPCS_CLOSED 1 /* Lower layer up, not opened */
|
#define CHAPCS_CLOSED 1 /* Lower layer up, not opened */
|
||||||
#define CHAPCS_PENDING 2 /* Auth us to peer when lower up */
|
#define CHAPCS_PENDING 2 /* Auth us to peer when lower up */
|
||||||
#define CHAPCS_LISTEN 3 /* Listening for a challenge */
|
#define CHAPCS_LISTEN 3 /* Listening for a challenge */
|
||||||
#define CHAPCS_RESPONSE 4 /* Sent response, waiting for status */
|
#define CHAPCS_RESPONSE 4 /* Sent response, waiting for status */
|
||||||
#define CHAPCS_OPEN 5 /* We've received Success */
|
#define CHAPCS_OPEN 5 /* We've received Success */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Server (authenticator) states.
|
* Server (authenticator) states.
|
||||||
*/
|
*/
|
||||||
#define CHAPSS_INITIAL 0 /* Lower layer down, not opened */
|
#define CHAPSS_INITIAL 0 /* Lower layer down, not opened */
|
||||||
#define CHAPSS_CLOSED 1 /* Lower layer up, not opened */
|
#define CHAPSS_CLOSED 1 /* Lower layer up, not opened */
|
||||||
#define CHAPSS_PENDING 2 /* Auth peer when lower up */
|
#define CHAPSS_PENDING 2 /* Auth peer when lower up */
|
||||||
#define CHAPSS_INITIAL_CHAL 3 /* We've sent the first challenge */
|
#define CHAPSS_INITIAL_CHAL 3 /* We've sent the first challenge */
|
||||||
#define CHAPSS_OPEN 4 /* We've sent a Success msg */
|
#define CHAPSS_OPEN 4 /* We've sent a Success msg */
|
||||||
#define CHAPSS_RECHALLENGE 5 /* We've sent another challenge */
|
#define CHAPSS_RECHALLENGE 5 /* We've sent another challenge */
|
||||||
#define CHAPSS_BADAUTH 6 /* We've sent a Failure msg */
|
#define CHAPSS_BADAUTH 6 /* We've sent a Failure msg */
|
||||||
|
|
||||||
/************************
|
/************************
|
||||||
*** PUBLIC DATA TYPES ***
|
*** PUBLIC DATA TYPES ***
|
||||||
@ -126,25 +126,25 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
typedef struct chap_state {
|
typedef struct chap_state {
|
||||||
int unit; /* Interface unit number */
|
int unit; /* Interface unit number */
|
||||||
int clientstate; /* Client state */
|
int clientstate; /* Client state */
|
||||||
int serverstate; /* Server state */
|
int serverstate; /* Server state */
|
||||||
u_char challenge[MAX_CHALLENGE_LENGTH]; /* last challenge string sent */
|
u_char challenge[MAX_CHALLENGE_LENGTH]; /* last challenge string sent */
|
||||||
u_char chal_len; /* challenge length */
|
u_char chal_len; /* challenge length */
|
||||||
u_char chal_id; /* ID of last challenge */
|
u_char chal_id; /* ID of last challenge */
|
||||||
u_char chal_type; /* hash algorithm for challenges */
|
u_char chal_type; /* hash algorithm for challenges */
|
||||||
u_char id; /* Current id */
|
u_char id; /* Current id */
|
||||||
char *chal_name; /* Our name to use with challenge */
|
char *chal_name; /* Our name to use with challenge */
|
||||||
int chal_interval; /* Time until we challenge peer again */
|
int chal_interval; /* Time until we challenge peer again */
|
||||||
int timeouttime; /* Timeout time in seconds */
|
int timeouttime; /* Timeout time in seconds */
|
||||||
int max_transmits; /* Maximum # of challenge transmissions */
|
int max_transmits; /* Maximum # of challenge transmissions */
|
||||||
int chal_transmits; /* Number of transmissions of challenge */
|
int chal_transmits; /* Number of transmissions of challenge */
|
||||||
int resp_transmits; /* Number of transmissions of response */
|
int resp_transmits; /* Number of transmissions of response */
|
||||||
u_char response[MAX_RESPONSE_LENGTH]; /* Response to send */
|
u_char response[MAX_RESPONSE_LENGTH]; /* Response to send */
|
||||||
u_char resp_length; /* length of response */
|
u_char resp_length; /* length of response */
|
||||||
u_char resp_id; /* ID for response messages */
|
u_char resp_id; /* ID for response messages */
|
||||||
u_char resp_type; /* hash algorithm for responses */
|
u_char resp_type; /* hash algorithm for responses */
|
||||||
char *resp_name; /* Our name to send with response */
|
char *resp_name; /* Our name to send with response */
|
||||||
} chap_state;
|
} chap_state;
|
||||||
|
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
* 03-01-01 Marc Boucher <marc@mbsi.ca>
|
* 03-01-01 Marc Boucher <marc@mbsi.ca>
|
||||||
* Ported to lwIP.
|
* Ported to lwIP.
|
||||||
* 97-12-08 Guy Lancaster <lancasterg@acm.org>, Global Election Systems Inc.
|
* 97-12-08 Guy Lancaster <lancasterg@acm.org>, Global Election Systems Inc.
|
||||||
* Original based on BSD chap_ms.c.
|
* Original based on BSD chap_ms.c.
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
/*
|
/*
|
||||||
* chap_ms.c - Microsoft MS-CHAP compatible implementation.
|
* chap_ms.c - Microsoft MS-CHAP compatible implementation.
|
||||||
@ -94,7 +94,7 @@
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
u_char LANManResp[24];
|
u_char LANManResp[24];
|
||||||
u_char NTResp[24];
|
u_char NTResp[24];
|
||||||
u_char UseNT; /* If 1, ignore the LANMan response field */
|
u_char UseNT; /* If 1, ignore the LANMan response field */
|
||||||
} MS_ChapResponse;
|
} MS_ChapResponse;
|
||||||
/* We use MS_CHAP_RESPONSE_LEN, rather than sizeof(MS_ChapResponse),
|
/* We use MS_CHAP_RESPONSE_LEN, rather than sizeof(MS_ChapResponse),
|
||||||
in case this struct gets padded. */
|
in case this struct gets padded. */
|
||||||
@ -109,173 +109,163 @@ typedef struct {
|
|||||||
extern void setkey(const char *);
|
extern void setkey(const char *);
|
||||||
extern void encrypt(char *, int);
|
extern void encrypt(char *, int);
|
||||||
|
|
||||||
static void DesEncrypt (u_char *, u_char *, u_char *);
|
static void DesEncrypt (u_char *, u_char *, u_char *);
|
||||||
static void MakeKey (u_char *, u_char *);
|
static void MakeKey (u_char *, u_char *);
|
||||||
|
|
||||||
#ifdef USE_CRYPT
|
#ifdef USE_CRYPT
|
||||||
static void Expand (u_char *, u_char *);
|
static void Expand (u_char *, u_char *);
|
||||||
static void Collapse (u_char *, u_char *);
|
static void Collapse (u_char *, u_char *);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void ChallengeResponse(
|
static void ChallengeResponse(
|
||||||
u_char *challenge, /* IN 8 octets */
|
u_char *challenge, /* IN 8 octets */
|
||||||
u_char *pwHash, /* IN 16 octets */
|
u_char *pwHash, /* IN 16 octets */
|
||||||
u_char *response /* OUT 24 octets */
|
u_char *response /* OUT 24 octets */
|
||||||
);
|
);
|
||||||
static void ChapMS_NT(
|
static void ChapMS_NT(
|
||||||
char *rchallenge,
|
char *rchallenge,
|
||||||
int rchallenge_len,
|
int rchallenge_len,
|
||||||
char *secret,
|
char *secret,
|
||||||
int secret_len,
|
int secret_len,
|
||||||
MS_ChapResponse *response
|
MS_ChapResponse *response
|
||||||
);
|
);
|
||||||
static u_char Get7Bits(
|
static u_char Get7Bits(
|
||||||
u_char *input,
|
u_char *input,
|
||||||
int startBit
|
int startBit
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
/***********************************/
|
/***********************************/
|
||||||
/*** PUBLIC FUNCTION DEFINITIONS ***/
|
/*** PUBLIC FUNCTION DEFINITIONS ***/
|
||||||
/***********************************/
|
/***********************************/
|
||||||
void ChapMS(
|
void
|
||||||
chap_state *cstate,
|
ChapMS( chap_state *cstate, char *rchallenge, int rchallenge_len, char *secret, int secret_len)
|
||||||
char *rchallenge,
|
|
||||||
int rchallenge_len,
|
|
||||||
char *secret,
|
|
||||||
int secret_len
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
MS_ChapResponse response;
|
MS_ChapResponse response;
|
||||||
#ifdef MSLANMAN
|
#ifdef MSLANMAN
|
||||||
extern int ms_lanman;
|
extern int ms_lanman;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
CHAPDEBUG((LOG_INFO, "ChapMS: secret is '%.*s'\n", secret_len, secret));
|
CHAPDEBUG((LOG_INFO, "ChapMS: secret is '%.*s'\n", secret_len, secret));
|
||||||
#endif
|
#endif
|
||||||
BZERO(&response, sizeof(response));
|
BZERO(&response, sizeof(response));
|
||||||
|
|
||||||
/* Calculate both always */
|
/* Calculate both always */
|
||||||
ChapMS_NT(rchallenge, rchallenge_len, secret, secret_len, &response);
|
ChapMS_NT(rchallenge, rchallenge_len, secret, secret_len, &response);
|
||||||
|
|
||||||
#ifdef MSLANMAN
|
#ifdef MSLANMAN
|
||||||
ChapMS_LANMan(rchallenge, rchallenge_len, secret, secret_len, &response);
|
ChapMS_LANMan(rchallenge, rchallenge_len, secret, secret_len, &response);
|
||||||
|
|
||||||
/* prefered method is set by option */
|
/* prefered method is set by option */
|
||||||
response.UseNT = !ms_lanman;
|
response.UseNT = !ms_lanman;
|
||||||
#else
|
#else
|
||||||
response.UseNT = 1;
|
response.UseNT = 1;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
BCOPY(&response, cstate->response, MS_CHAP_RESPONSE_LEN);
|
BCOPY(&response, cstate->response, MS_CHAP_RESPONSE_LEN);
|
||||||
cstate->resp_length = MS_CHAP_RESPONSE_LEN;
|
cstate->resp_length = MS_CHAP_RESPONSE_LEN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**********************************/
|
/**********************************/
|
||||||
/*** LOCAL FUNCTION DEFINITIONS ***/
|
/*** LOCAL FUNCTION DEFINITIONS ***/
|
||||||
/**********************************/
|
/**********************************/
|
||||||
static void ChallengeResponse(
|
static void
|
||||||
u_char *challenge, /* IN 8 octets */
|
ChallengeResponse( u_char *challenge, /* IN 8 octets */
|
||||||
u_char *pwHash, /* IN 16 octets */
|
u_char *pwHash, /* IN 16 octets */
|
||||||
u_char *response /* OUT 24 octets */
|
u_char *response /* OUT 24 octets */)
|
||||||
)
|
|
||||||
{
|
{
|
||||||
char ZPasswordHash[21];
|
char ZPasswordHash[21];
|
||||||
|
|
||||||
BZERO(ZPasswordHash, sizeof(ZPasswordHash));
|
BZERO(ZPasswordHash, sizeof(ZPasswordHash));
|
||||||
BCOPY(pwHash, ZPasswordHash, 16);
|
BCOPY(pwHash, ZPasswordHash, 16);
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
log_packet(ZPasswordHash, sizeof(ZPasswordHash), "ChallengeResponse - ZPasswordHash", LOG_DEBUG);
|
log_packet(ZPasswordHash, sizeof(ZPasswordHash), "ChallengeResponse - ZPasswordHash", LOG_DEBUG);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
DesEncrypt(challenge, ZPasswordHash + 0, response + 0);
|
DesEncrypt(challenge, ZPasswordHash + 0, response + 0);
|
||||||
DesEncrypt(challenge, ZPasswordHash + 7, response + 8);
|
DesEncrypt(challenge, ZPasswordHash + 7, response + 8);
|
||||||
DesEncrypt(challenge, ZPasswordHash + 14, response + 16);
|
DesEncrypt(challenge, ZPasswordHash + 14, response + 16);
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
log_packet(response, 24, "ChallengeResponse - response", LOG_DEBUG);
|
log_packet(response, 24, "ChallengeResponse - response", LOG_DEBUG);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef USE_CRYPT
|
#ifdef USE_CRYPT
|
||||||
static void DesEncrypt(
|
static void
|
||||||
u_char *clear, /* IN 8 octets */
|
DesEncrypt( u_char *clear, /* IN 8 octets */
|
||||||
u_char *key, /* IN 7 octets */
|
u_char *key, /* IN 7 octets */
|
||||||
u_char *cipher /* OUT 8 octets */
|
u_char *cipher /* OUT 8 octets */)
|
||||||
)
|
|
||||||
{
|
{
|
||||||
u_char des_key[8];
|
u_char des_key[8];
|
||||||
u_char crypt_key[66];
|
u_char crypt_key[66];
|
||||||
u_char des_input[66];
|
u_char des_input[66];
|
||||||
|
|
||||||
MakeKey(key, des_key);
|
MakeKey(key, des_key);
|
||||||
|
|
||||||
Expand(des_key, crypt_key);
|
Expand(des_key, crypt_key);
|
||||||
setkey(crypt_key);
|
setkey(crypt_key);
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
CHAPDEBUG((LOG_INFO, "DesEncrypt: 8 octet input : %02X%02X%02X%02X%02X%02X%02X%02X\n",
|
CHAPDEBUG((LOG_INFO, "DesEncrypt: 8 octet input : %02X%02X%02X%02X%02X%02X%02X%02X\n",
|
||||||
clear[0], clear[1], clear[2], clear[3], clear[4], clear[5], clear[6], clear[7]));
|
clear[0], clear[1], clear[2], clear[3], clear[4], clear[5], clear[6], clear[7]));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Expand(clear, des_input);
|
Expand(clear, des_input);
|
||||||
encrypt(des_input, 0);
|
encrypt(des_input, 0);
|
||||||
Collapse(des_input, cipher);
|
Collapse(des_input, cipher);
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
CHAPDEBUG((LOG_INFO, "DesEncrypt: 8 octet output: %02X%02X%02X%02X%02X%02X%02X%02X\n",
|
CHAPDEBUG((LOG_INFO, "DesEncrypt: 8 octet output: %02X%02X%02X%02X%02X%02X%02X%02X\n",
|
||||||
cipher[0], cipher[1], cipher[2], cipher[3], cipher[4], cipher[5], cipher[6], cipher[7]));
|
cipher[0], cipher[1], cipher[2], cipher[3], cipher[4], cipher[5], cipher[6], cipher[7]));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#else /* USE_CRYPT */
|
#else /* USE_CRYPT */
|
||||||
|
|
||||||
static void DesEncrypt(
|
static void
|
||||||
u_char *clear, /* IN 8 octets */
|
DesEncrypt( u_char *clear, /* IN 8 octets */
|
||||||
u_char *key, /* IN 7 octets */
|
u_char *key, /* IN 7 octets */
|
||||||
u_char *cipher /* OUT 8 octets */
|
u_char *cipher /* OUT 8 octets */)
|
||||||
)
|
|
||||||
{
|
{
|
||||||
des_cblock des_key;
|
des_cblock des_key;
|
||||||
des_key_schedule key_schedule;
|
des_key_schedule key_schedule;
|
||||||
|
|
||||||
MakeKey(key, des_key);
|
MakeKey(key, des_key);
|
||||||
|
|
||||||
des_set_key(&des_key, key_schedule);
|
des_set_key(&des_key, key_schedule);
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
CHAPDEBUG((LOG_INFO, "DesEncrypt: 8 octet input : %02X%02X%02X%02X%02X%02X%02X%02X\n",
|
CHAPDEBUG((LOG_INFO, "DesEncrypt: 8 octet input : %02X%02X%02X%02X%02X%02X%02X%02X\n",
|
||||||
clear[0], clear[1], clear[2], clear[3], clear[4], clear[5], clear[6], clear[7]));
|
clear[0], clear[1], clear[2], clear[3], clear[4], clear[5], clear[6], clear[7]));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
des_ecb_encrypt((des_cblock *)clear, (des_cblock *)cipher, key_schedule, 1);
|
des_ecb_encrypt((des_cblock *)clear, (des_cblock *)cipher, key_schedule, 1);
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
CHAPDEBUG((LOG_INFO, "DesEncrypt: 8 octet output: %02X%02X%02X%02X%02X%02X%02X%02X\n",
|
CHAPDEBUG((LOG_INFO, "DesEncrypt: 8 octet output: %02X%02X%02X%02X%02X%02X%02X%02X\n",
|
||||||
cipher[0], cipher[1], cipher[2], cipher[3], cipher[4], cipher[5], cipher[6], cipher[7]));
|
cipher[0], cipher[1], cipher[2], cipher[3], cipher[4], cipher[5], cipher[6], cipher[7]));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* USE_CRYPT */
|
#endif /* USE_CRYPT */
|
||||||
|
|
||||||
|
|
||||||
static u_char Get7Bits(
|
static u_char
|
||||||
u_char *input,
|
Get7Bits( u_char *input, int startBit)
|
||||||
int startBit
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
register unsigned int word;
|
register unsigned int word;
|
||||||
|
|
||||||
word = (unsigned)input[startBit / 8] << 8;
|
word = (unsigned)input[startBit / 8] << 8;
|
||||||
word |= (unsigned)input[startBit / 8 + 1];
|
word |= (unsigned)input[startBit / 8 + 1];
|
||||||
|
|
||||||
word >>= 15 - (startBit % 8 + 7);
|
word >>= 15 - (startBit % 8 + 7);
|
||||||
|
|
||||||
return word & 0xFE;
|
return word & 0xFE;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef USE_CRYPT
|
#ifdef USE_CRYPT
|
||||||
@ -284,116 +274,120 @@ static u_char Get7Bits(
|
|||||||
* out == 64-byte string where each byte is either 1 or 0
|
* out == 64-byte string where each byte is either 1 or 0
|
||||||
* Note that the low-order "bit" is always ignored by by setkey()
|
* Note that the low-order "bit" is always ignored by by setkey()
|
||||||
*/
|
*/
|
||||||
static void Expand(u_char *in, u_char *out)
|
static void
|
||||||
|
Expand(u_char *in, u_char *out)
|
||||||
{
|
{
|
||||||
int j, c;
|
int j, c;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for(i = 0; i < 64; in++){
|
for(i = 0; i < 64; in++){
|
||||||
c = *in;
|
c = *in;
|
||||||
for(j = 7; j >= 0; j--)
|
for(j = 7; j >= 0; j--) {
|
||||||
*out++ = (c >> j) & 01;
|
*out++ = (c >> j) & 01;
|
||||||
i += 8;
|
}
|
||||||
}
|
i += 8;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The inverse of Expand
|
/* The inverse of Expand
|
||||||
*/
|
*/
|
||||||
static void Collapse(u_char *in, u_char *out)
|
static void
|
||||||
|
Collapse(u_char *in, u_char *out)
|
||||||
{
|
{
|
||||||
int j;
|
int j;
|
||||||
int i;
|
int i;
|
||||||
unsigned int c;
|
unsigned int c;
|
||||||
|
|
||||||
for (i = 0; i < 64; i += 8, out++) {
|
for (i = 0; i < 64; i += 8, out++) {
|
||||||
c = 0;
|
c = 0;
|
||||||
for (j = 7; j >= 0; j--, in++)
|
for (j = 7; j >= 0; j--, in++) {
|
||||||
c |= *in << j;
|
c |= *in << j;
|
||||||
*out = c & 0xff;
|
}
|
||||||
}
|
*out = c & 0xff;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void MakeKey(
|
static void
|
||||||
u_char *key, /* IN 56 bit DES key missing parity bits */
|
MakeKey( u_char *key, /* IN 56 bit DES key missing parity bits */
|
||||||
u_char *des_key /* OUT 64 bit DES key with parity bits added */
|
u_char *des_key /* OUT 64 bit DES key with parity bits added */)
|
||||||
)
|
|
||||||
{
|
{
|
||||||
des_key[0] = Get7Bits(key, 0);
|
des_key[0] = Get7Bits(key, 0);
|
||||||
des_key[1] = Get7Bits(key, 7);
|
des_key[1] = Get7Bits(key, 7);
|
||||||
des_key[2] = Get7Bits(key, 14);
|
des_key[2] = Get7Bits(key, 14);
|
||||||
des_key[3] = Get7Bits(key, 21);
|
des_key[3] = Get7Bits(key, 21);
|
||||||
des_key[4] = Get7Bits(key, 28);
|
des_key[4] = Get7Bits(key, 28);
|
||||||
des_key[5] = Get7Bits(key, 35);
|
des_key[5] = Get7Bits(key, 35);
|
||||||
des_key[6] = Get7Bits(key, 42);
|
des_key[6] = Get7Bits(key, 42);
|
||||||
des_key[7] = Get7Bits(key, 49);
|
des_key[7] = Get7Bits(key, 49);
|
||||||
|
|
||||||
#ifndef USE_CRYPT
|
#ifndef USE_CRYPT
|
||||||
des_set_odd_parity((des_cblock *)des_key);
|
des_set_odd_parity((des_cblock *)des_key);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
CHAPDEBUG((LOG_INFO, "MakeKey: 56-bit input : %02X%02X%02X%02X%02X%02X%02X\n",
|
CHAPDEBUG((LOG_INFO, "MakeKey: 56-bit input : %02X%02X%02X%02X%02X%02X%02X\n",
|
||||||
key[0], key[1], key[2], key[3], key[4], key[5], key[6]));
|
key[0], key[1], key[2], key[3], key[4], key[5], key[6]));
|
||||||
CHAPDEBUG((LOG_INFO, "MakeKey: 64-bit output: %02X%02X%02X%02X%02X%02X%02X%02X\n",
|
CHAPDEBUG((LOG_INFO, "MakeKey: 64-bit output: %02X%02X%02X%02X%02X%02X%02X%02X\n",
|
||||||
des_key[0], des_key[1], des_key[2], des_key[3], des_key[4], des_key[5], des_key[6], des_key[7]));
|
des_key[0], des_key[1], des_key[2], des_key[3], des_key[4], des_key[5], des_key[6], des_key[7]));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ChapMS_NT(
|
static void
|
||||||
char *rchallenge,
|
ChapMS_NT( char *rchallenge,
|
||||||
int rchallenge_len,
|
int rchallenge_len,
|
||||||
char *secret,
|
char *secret,
|
||||||
int secret_len,
|
int secret_len,
|
||||||
MS_ChapResponse *response
|
MS_ChapResponse *response)
|
||||||
)
|
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
MDstruct md4Context;
|
MDstruct md4Context;
|
||||||
u_char unicodePassword[MAX_NT_PASSWORD * 2];
|
u_char unicodePassword[MAX_NT_PASSWORD * 2];
|
||||||
static int low_byte_first = -1;
|
static int low_byte_first = -1;
|
||||||
|
|
||||||
/* Initialize the Unicode version of the secret (== password). */
|
/* Initialize the Unicode version of the secret (== password). */
|
||||||
/* This implicitly supports 8-bit ISO8859/1 characters. */
|
/* This implicitly supports 8-bit ISO8859/1 characters. */
|
||||||
BZERO(unicodePassword, sizeof(unicodePassword));
|
BZERO(unicodePassword, sizeof(unicodePassword));
|
||||||
for (i = 0; i < secret_len; i++)
|
for (i = 0; i < secret_len; i++) {
|
||||||
unicodePassword[i * 2] = (u_char)secret[i];
|
unicodePassword[i * 2] = (u_char)secret[i];
|
||||||
|
}
|
||||||
MDbegin(&md4Context);
|
MDbegin(&md4Context);
|
||||||
MDupdate(&md4Context, unicodePassword, secret_len * 2 * 8); /* Unicode is 2 bytes/char, *8 for bit count */
|
MDupdate(&md4Context, unicodePassword, secret_len * 2 * 8); /* Unicode is 2 bytes/char, *8 for bit count */
|
||||||
|
|
||||||
if (low_byte_first == -1)
|
if (low_byte_first == -1) {
|
||||||
low_byte_first = (htons((unsigned short int)1) != 1);
|
low_byte_first = (htons((unsigned short int)1) != 1);
|
||||||
if (low_byte_first == 0)
|
}
|
||||||
MDreverse((u_long *)&md4Context); /* sfb 961105 */
|
if (low_byte_first == 0) {
|
||||||
|
MDreverse((u_long *)&md4Context); /* sfb 961105 */
|
||||||
MDupdate(&md4Context, NULL, 0); /* Tell MD4 we're done */
|
}
|
||||||
|
|
||||||
ChallengeResponse(rchallenge, (char *)md4Context.buffer, response->NTResp);
|
MDupdate(&md4Context, NULL, 0); /* Tell MD4 we're done */
|
||||||
|
|
||||||
|
ChallengeResponse(rchallenge, (char *)md4Context.buffer, response->NTResp);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef MSLANMAN
|
#ifdef MSLANMAN
|
||||||
static u_char *StdText = (u_char *)"KGS!@#$%"; /* key from rasapi32.dll */
|
static u_char *StdText = (u_char *)"KGS!@#$%"; /* key from rasapi32.dll */
|
||||||
|
|
||||||
static ChapMS_LANMan(
|
static void
|
||||||
char *rchallenge,
|
ChapMS_LANMan( char *rchallenge,
|
||||||
int rchallenge_len,
|
int rchallenge_len,
|
||||||
char *secret,
|
char *secret,
|
||||||
int secret_len,
|
int secret_len,
|
||||||
MS_ChapResponse *response
|
MS_ChapResponse *response)
|
||||||
)
|
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
u_char UcasePassword[MAX_NT_PASSWORD]; /* max is actually 14 */
|
u_char UcasePassword[MAX_NT_PASSWORD]; /* max is actually 14 */
|
||||||
u_char PasswordHash[16];
|
u_char PasswordHash[16];
|
||||||
|
|
||||||
/* LANMan password is case insensitive */
|
/* LANMan password is case insensitive */
|
||||||
BZERO(UcasePassword, sizeof(UcasePassword));
|
BZERO(UcasePassword, sizeof(UcasePassword));
|
||||||
for (i = 0; i < secret_len; i++)
|
for (i = 0; i < secret_len; i++) {
|
||||||
UcasePassword[i] = (u_char)toupper(secret[i]);
|
UcasePassword[i] = (u_char)toupper(secret[i]);
|
||||||
DesEncrypt( StdText, UcasePassword + 0, PasswordHash + 0 );
|
}
|
||||||
DesEncrypt( StdText, UcasePassword + 7, PasswordHash + 8 );
|
DesEncrypt( StdText, UcasePassword + 0, PasswordHash + 0 );
|
||||||
ChallengeResponse(rchallenge, PasswordHash, response->LANManResp);
|
DesEncrypt( StdText, UcasePassword + 7, PasswordHash + 8 );
|
||||||
|
ChallengeResponse(rchallenge, PasswordHash, response->LANManResp);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@
|
|||||||
* 03-01-01 Marc Boucher <marc@mbsi.ca>
|
* 03-01-01 Marc Boucher <marc@mbsi.ca>
|
||||||
* Ported to lwIP.
|
* Ported to lwIP.
|
||||||
* 98-01-30 Guy Lancaster <lancasterg@acm.org>, Global Election Systems Inc.
|
* 98-01-30 Guy Lancaster <lancasterg@acm.org>, Global Election Systems Inc.
|
||||||
* Original built from BSD network code.
|
* Original built from BSD network code.
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
/*
|
/*
|
||||||
* chap.h - Challenge Handshake Authentication Protocol definitions.
|
* chap.h - Challenge Handshake Authentication Protocol definitions.
|
||||||
@ -51,13 +51,13 @@
|
|||||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
*
|
*
|
||||||
* $Id: chpms.h,v 1.3 2004/02/07 00:30:03 likewise Exp $
|
* $Id: chpms.h,v 1.4 2007/12/02 22:56:19 fbernon Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef CHPMS_H
|
#ifndef CHPMS_H
|
||||||
#define CHPMS_H
|
#define CHPMS_H
|
||||||
|
|
||||||
#define MAX_NT_PASSWORD 256 /* Maximum number of (Unicode) chars in an NT password */
|
#define MAX_NT_PASSWORD 256 /* Maximum number of (Unicode) chars in an NT password */
|
||||||
|
|
||||||
void ChapMS (chap_state *, char *, int, char *, int);
|
void ChapMS (chap_state *, char *, int, char *, int);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user