100 "Magic server to client signing constant";
104 "Pad to make it do more than one iteration";
122 const char *username,
127 digest_init ( sha1,
ctx->sha1 );
128 digest_update ( sha1,
ctx->sha1,
peer, sizeof ( *
peer ) );
129 digest_update ( sha1,
ctx->sha1, challenge, sizeof ( *challenge ) );
131 digest_update ( sha1,
ctx->sha1, username,
134 digest_final ( sha1,
ctx->sha1, chash->
sha1 );
135 DBGC (
ctx,
"MSCHAPv2 authenticator challenge:\n" );
136 DBGC_HDA (
ctx, 0, challenge,
sizeof ( *challenge ) );
137 DBGC (
ctx,
"MSCHAPv2 peer challenge:\n" );
139 DBGC (
ctx,
"MSCHAPv2 challenge hash:\n" );
154 const char *password,
161 memset ( phash, 0,
sizeof ( *phash ) );
162 digest_init ( md4,
ctx->md4 );
164 while ( (
c = *(password++) ) ) {
166 digest_update ( md4,
ctx->md4, &
wc, sizeof (
wc ) );
169 digest_final ( md4,
ctx->md4, phash->
md4 );
170 DBGC (
ctx,
"MSCHAPv2 password hash:\n" );
188 digest_init ( md4,
ctx->md4 );
189 digest_update ( md4,
ctx->md4, phash->
md4, sizeof ( phash->
md4 ) );
190 digest_final ( md4,
ctx->md4, phash->
md4 );
191 DBGC (
ctx,
"MSCHAPv2 password hash hash:\n" );
211 for ( i = (
sizeof ( phash->
expand ) - 1 ) ; i > 0 ; i-- ) {
213 src = (
dst - ( i / 8 ) );
214 *
dst = ( ( (
src[-1] << 8 ) |
src[0] ) >> ( i % 8 ) );
216 DBGC (
ctx,
"MSCHAPv2 expanded password hash:\n" );
245 for ( i = 0 ; i < (
sizeof ( phash->
des ) /
246 sizeof ( phash->
des[0] ) ) ; i++ ) {
247 rc = cipher_setkey ( des,
ctx->des, phash->
des[i],
248 sizeof ( phash->
des[i] ) );
251 sizeof ( chash->
des ) );
253 DBGC (
ctx,
"MSCHAPv2 NT response:\n" );
278 memset ( response, 0,
sizeof ( *response ) );
292 DBGC ( &
ctx,
"MSCHAPv2 challenge response:\n" );
293 DBGC_HDA ( &
ctx, 0, response,
sizeof ( *response ) );
325 digest_init (
sha1,
ctx.sha1 );
326 digest_update (
sha1,
ctx.sha1, phash.
md4, sizeof ( phash.
md4 ) );
327 digest_update (
sha1,
ctx.sha1, &response->
nt,
328 sizeof ( response->
nt ) );
332 DBGC ( &
ctx,
"MSCHAPv2 NT response:\n" );
334 DBGC ( &
ctx,
"MSCHAPv2 unnamed intermediate hash:\n" );
342 digest_init (
sha1,
ctx.sha1 );
344 digest_update (
sha1,
ctx.sha1, chash.
des, sizeof ( chash.
des ) );
348 DBGC ( &
ctx,
"MSCHAPv2 authenticator response hash:\n" );
355 DBGC ( &
ctx,
"MSCHAPv2 authenticator response: S=" );
356 for ( i = 0 ; i <
sizeof ( phash.
sha1 ) ; i++ ) {
#define MD4_DIGEST_SIZE
MD4 digest size.
struct arbelprm_rc_send_wqe rc
static const char mschapv2_magic1[39]
MS-CHAPv2 magic constant 1.
static void mschapv2_hash_hash(union mschapv2_context *ctx, union mschapv2_password_hash *phash)
Hash the MS-CHAPv2 password hash.
MS-CHAPv2 challenge hash.
uint8_t des[3][DES_BLOCKSIZE]
DES keys.
static void const void void * dst
static void const void * src
uint8_t sha1[SHA1_DIGEST_SIZE]
SHA-1 digest.
void mschapv2_response(const char *username, const char *password, const struct mschapv2_challenge *challenge, const struct mschapv2_challenge *peer, struct mschapv2_response *response)
Calculate MS-CHAPv2 challenge response.
struct cipher_algorithm des_algorithm
Basic DES algorithm.
#define DES_CTX_SIZE
DES context size.
#define cipher_encrypt(cipher, ctx, src, dst, len)
void * memcpy(void *dest, const void *src, size_t len) __nonnull
uint8_t des[DES_CTX_SIZE]
DES cipher context.
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
uint8_t md4[MD4_DIGEST_SIZE]
MD4 digest.
char wtf[42]
Authenticator response string.
MS-CHAPv2 authentication.
uint8_t des[DES_BLOCKSIZE]
DES plaintext block.
uint8_t md4[MD4_CTX_SIZE]
MD4 digest context.
uint8_t sha1[SHA1_CTX_SIZE]
SHA-1 digest context.
void mschapv2_auth(const char *username, const char *password, const struct mschapv2_challenge *challenge, const struct mschapv2_response *response, struct mschapv2_auth *auth)
Calculate MS-CHAPv2 authenticator response.
struct golan_eq_context ctx
size_t strlen(const char *src)
Get length of string.
An MS-CHAPv2 challenge response.
struct mschapv2_nt_response nt
NT response.
static void mschapv2_challenge_response(union mschapv2_context *ctx, const union mschapv2_challenge_hash *chash, const union mschapv2_password_hash *phash, struct mschapv2_nt_response *nt)
Calculate MS-CHAPv2 challenge response.
static void mschapv2_challenge_hash(union mschapv2_context *ctx, const struct mschapv2_challenge *challenge, const struct mschapv2_challenge *peer, const char *username, union mschapv2_challenge_hash *chash)
Calculate MS-CHAPv2 challenge hash.
#define MD4_CTX_SIZE
MD4 context size.
An MS-CHAPv2 authenticator response.
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
#define SHA1_CTX_SIZE
SHA-1 context size.
uint8_t sha1[SHA1_DIGEST_SIZE]
SHA-1 digest.
static const char mschapv2_magic2[41]
MS-CHAPv2 magic constant 2.
#define DES_BLOCKSIZE
DES blocksize.
#define cpu_to_le16(value)
A message digest algorithm.
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
struct digest_algorithm md4_algorithm
MD4 algorithm.
struct mschapv2_challenge peer
Peer challenge.
uint8_t expand[3 *DES_BLOCKSIZE]
DES key expansion.
uint8_t block[3][8]
DES-encrypted blocks.
struct mschapv2_challenge peer
Peer challenge.
static void mschapv2_password_hash(union mschapv2_context *ctx, const char *password, union mschapv2_password_hash *phash)
Calculate MS-CHAPv2 password hash.
struct mschapv2_nt_response nt
NT response.
An MS-CHAPv2 NT response.
static void mschapv2_expand_hash(union mschapv2_context *ctx, union mschapv2_password_hash *phash)
Expand MS-CHAPv2 password hash by inserting DES dummy parity bits.
struct digest_algorithm sha1_algorithm
SHA-1 algorithm.
void * memset(void *dest, int character, size_t len) __nonnull