summaryrefslogtreecommitdiff
path: root/pppd/chap-md5.c
diff options
context:
space:
mode:
Diffstat (limited to 'pppd/chap-md5.c')
-rw-r--r--pppd/chap-md5.c79
1 files changed, 39 insertions, 40 deletions
diff --git a/pppd/chap-md5.c b/pppd/chap-md5.c
index 750a8d7..8bcbbba 100644
--- a/pppd/chap-md5.c
+++ b/pppd/chap-md5.c
@@ -42,7 +42,6 @@
#include "magic.h"
#include "ppp-crypto.h"
-#define MD5_HASH_SIZE 16
#define MD5_MIN_CHALLENGE 16
#define MD5_MAX_CHALLENGE 24
@@ -64,42 +63,42 @@ chap_md5_verify_response(int id, char *name,
char *message, int message_space)
{
unsigned char idbyte = id;
- unsigned char hash[MD5_HASH_SIZE];
- unsigned int hash_len = MD5_HASH_SIZE;
+ unsigned char hash[MD5_DIGEST_LENGTH];
+ unsigned int hash_len = MD5_DIGEST_LENGTH;
int challenge_len, response_len;
- bool success = 0;
+ bool success = 0;
challenge_len = *challenge++;
response_len = *response++;
- if (response_len == MD5_HASH_SIZE) {
+ if (response_len == MD5_DIGEST_LENGTH) {
/* Generate hash of ID, secret, challenge */
- PPP_MD_CTX* ctx = PPP_MD_CTX_new();
- if (ctx) {
+ PPP_MD_CTX* ctx = PPP_MD_CTX_new();
+ if (ctx) {
- if (PPP_DigestInit(ctx, PPP_md5())) {
+ if (PPP_DigestInit(ctx, PPP_md5())) {
- if (PPP_DigestUpdate(ctx, &idbyte, 1)) {
+ if (PPP_DigestUpdate(ctx, &idbyte, 1)) {
- if (PPP_DigestUpdate(ctx, secret, secret_len)) {
+ if (PPP_DigestUpdate(ctx, secret, secret_len)) {
- if (PPP_DigestUpdate(ctx, challenge, challenge_len)) {
+ if (PPP_DigestUpdate(ctx, challenge, challenge_len)) {
- if (PPP_DigestFinal(ctx, hash, &hash_len)) {
+ if (PPP_DigestFinal(ctx, hash, &hash_len)) {
- success = 1;
- }
- }
- }
- }
- }
- PPP_MD_CTX_free(ctx);
- }
+ success = 1;
+ }
+ }
+ }
+ }
+ }
+ PPP_MD_CTX_free(ctx);
+ }
+ }
+ if (success && memcmp(hash, response, hash_len) == 0) {
+ slprintf(message, message_space, "Access granted");
+ return 1;
}
- if (success && memcmp(hash, response, hash_len) == 0) {
- slprintf(message, message_space, "Access granted");
- return 1;
- }
slprintf(message, message_space, "Access denied");
return 0;
}
@@ -111,29 +110,29 @@ chap_md5_make_response(unsigned char *response, int id, char *our_name,
{
unsigned char idbyte = id;
int challenge_len = *challenge++;
- int hash_len = MD5_HASH_SIZE;
+ int hash_len = MD5_DIGEST_LENGTH;
- PPP_MD_CTX* ctx = PPP_MD_CTX_new();
- if (ctx) {
+ PPP_MD_CTX* ctx = PPP_MD_CTX_new();
+ if (ctx) {
- if (PPP_DigestInit(ctx, PPP_md5())) {
+ if (PPP_DigestInit(ctx, PPP_md5())) {
- if (PPP_DigestUpdate(ctx, &idbyte, 1)) {
+ if (PPP_DigestUpdate(ctx, &idbyte, 1)) {
- if (PPP_DigestUpdate(ctx, secret, secret_len)) {
+ if (PPP_DigestUpdate(ctx, secret, secret_len)) {
- if (PPP_DigestUpdate(ctx, challenge, challenge_len)) {
+ if (PPP_DigestUpdate(ctx, challenge, challenge_len)) {
- if (PPP_DigestFinal(ctx, &response[1], &hash_len)) {
+ if (PPP_DigestFinal(ctx, &response[1], &hash_len)) {
- response[0] = hash_len;
- }
- }
- }
- }
- }
- PPP_MD_CTX_free(ctx);
- }
+ response[0] = hash_len;
+ }
+ }
+ }
+ }
+ }
+ PPP_MD_CTX_free(ctx);
+ }
}
static struct chap_digest_type md5_digest = {