32#if PPP_SUPPORT && CHAP_SUPPORT
46#define MD5_HASH_SIZE 16
47#define MD5_MIN_CHALLENGE 17
48#define MD5_MAX_CHALLENGE 24
49#define MD5_MIN_MAX_POWER_OF_TWO_CHALLENGE 3
52static void chap_md5_generate_challenge(ppp_pcb *pcb,
unsigned char *
cp) {
56 clen = MD5_MIN_CHALLENGE + magic_pow(MD5_MIN_MAX_POWER_OF_TWO_CHALLENGE);
58 magic_random_bytes(
cp, clen);
61static int chap_md5_verify_response(ppp_pcb *pcb,
int id,
const char *
name,
62 const unsigned char *
secret,
int secret_len,
63 const unsigned char *challenge,
const unsigned char *response,
64 char *
message,
int message_space) {
66 unsigned char idbyte =
id;
67 unsigned char hash[MD5_HASH_SIZE];
68 int challenge_len, response_len;
72 challenge_len = *challenge++;
73 response_len = *response++;
74 if (response_len == MD5_HASH_SIZE) {
77 lwip_md5_starts(&
ctx);
78 lwip_md5_update(&
ctx, &idbyte, 1);
79 lwip_md5_update(&
ctx,
secret, secret_len);
80 lwip_md5_update(&
ctx, challenge, challenge_len);
85 if (
memcmp(
hash, response, MD5_HASH_SIZE) == 0) {
86 ppp_slprintf(
message, message_space,
"Access granted");
90 ppp_slprintf(
message, message_space,
"Access denied");
95static void chap_md5_make_response(ppp_pcb *pcb,
unsigned char *response,
int id,
const char *our_name,
96 const unsigned char *challenge,
const char *
secret,
int secret_len,
97 unsigned char *private_) {
99 unsigned char idbyte =
id;
100 int challenge_len = *challenge++;
106 lwip_md5_starts(&
ctx);
107 lwip_md5_update(&
ctx, &idbyte, 1);
109 lwip_md5_update(&
ctx, challenge, challenge_len);
110 lwip_md5_finish(&
ctx, &response[1]);
112 response[0] = MD5_HASH_SIZE;
115const struct chap_digest_type md5_digest = {
118 chap_md5_generate_challenge,
119 chap_md5_verify_response,
121 chap_md5_make_response,
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
#define LWIP_UNUSED_ARG(x)
static DATA_BLOB CRYPTPROTECT_PROMPTSTRUCT DATA_BLOB *static LPWSTR DATA_BLOB CRYPTPROTECT_PROMPTSTRUCT DATA_BLOB *static char secret[]