31 RCSID(
"$Id: 48737b18c9e3e55881eeb21708daeaddb800498a $")
33 #include <freeradius-devel/radiusd.h>
34 #include <freeradius-devel/modules.h>
35 #include <freeradius-devel/rad_assert.h>
36 #include <freeradius-devel/md5.h>
37 #include <freeradius-devel/sha1.h>
55 uint8_t ucs2_password[512];
57 len =
fr_utf8_to_ucs2(ucs2_password,
sizeof(ucs2_password), password, strlen(password));
73 uint8_t
const *auth_challenge,
74 char const *user_name, uint8_t *challenge )
85 memcpy(challenge, hash, 8);
94 uint8_t
const *nt_hash_hash,
95 uint8_t
const *ntresponse,
96 uint8_t
const *peer_challenge, uint8_t
const *auth_challenge,
100 static const uint8_t
magic1[39] =
101 {0x4D, 0x61, 0x67, 0x69, 0x63, 0x20, 0x73, 0x65, 0x72, 0x76,
102 0x65, 0x72, 0x20, 0x74, 0x6F, 0x20, 0x63, 0x6C, 0x69, 0x65,
103 0x6E, 0x74, 0x20, 0x73, 0x69, 0x67, 0x6E, 0x69, 0x6E, 0x67,
104 0x20, 0x63, 0x6F, 0x6E, 0x73, 0x74, 0x61, 0x6E, 0x74};
106 static const uint8_t
magic2[41] =
107 {0x50, 0x61, 0x64, 0x20, 0x74, 0x6F, 0x20, 0x6D, 0x61, 0x6B,
108 0x65, 0x20, 0x69, 0x74, 0x20, 0x64, 0x6F, 0x20, 0x6D, 0x6F,
109 0x72, 0x65, 0x20, 0x74, 0x68, 0x61, 0x6E, 0x20, 0x6F, 0x6E,
110 0x65, 0x20, 0x69, 0x74, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6F,
113 static char const hex[] =
"0123456789ABCDEF";
116 uint8_t challenge[8];
144 for (i = 0; i <
sizeof(digest); i++) {
145 response[2 + (i * 2)] = hex[(digest[i] >> 4) & 0x0f];
146 response[3 + (i * 2)] = hex[digest[i] & 0x0f];
void fr_sha1_update(fr_sha1_ctx *context, uint8_t const *data, size_t len)
void fr_md4_calc(uint8_t out[MD4_DIGEST_LENGTH], uint8_t const *in, size_t inlen)
Calculate the MD4 hash of the contents of a buffer.
void mschap_challenge_hash(uint8_t const *peer_challenge, uint8_t const *auth_challenge, char const *user_name, uint8_t *challenge)
void fr_sha1_init(fr_sha1_ctx *context)
static unsigned int hash(char const *username, unsigned int tablesize)
void mschap_auth_response(char const *username, uint8_t const *nt_hash_hash, uint8_t const *ntresponse, uint8_t const *peer_challenge, uint8_t const *auth_challenge, char *response)
int mschap_ntpwdhash(uint8_t *out, char const *password)
Converts Unicode password to 16-byte NT hash with MD4.
void fr_sha1_final(uint8_t digest[20], fr_sha1_ctx *context)
ssize_t fr_utf8_to_ucs2(uint8_t *out, size_t outlen, char const *in, size_t inlen)
Convert UTF8 string to UCS2 encoding.
static const uint8_t magic2[84]
static const uint8_t magic1[27]