-
-/*
- * Copyright (c) 2002-2009, Jouni Malinen <j@w1.fi>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * Alternatively, this software may be distributed under the terms of BSD
- * license.
- *
- * See README and COPYING for more details.
- */
-#include <openssl/md5.h>
-
-static int
-_rs_decrypt_mppe(struct rs_request *request, VALUE_PAIR *vp)
-{
- unsigned char *key = vp->vp_octets;
- size_t len = vp->length;
- unsigned char plain[1 + MAX_STRING_LEN], *ppos = plain, *res;
- const unsigned char *pos;
- size_t left, plen;
- unsigned char hash[MD5_DIGEST_LENGTH];
- int i, first = 1;
- const unsigned char *addr[3];
- struct rs_connection *conn;
-
- assert (request);
- assert (request->conn);
- conn = request->conn;
-
- if (vp->type != PW_TYPE_OCTETS)
- return rs_err_conn_push_fl (conn, RSE_BADAUTH, __FILE__, __LINE__, NULL);
-
- pos = key + 2;
- left = len - 2;
- if (left % 16)
- return rs_err_conn_push_fl (conn, RSE_BADAUTH, __FILE__, __LINE__, NULL);
-
- plen = left;
- if (plen > MAX_STRING_LEN)
- return rs_err_conn_push_fl (conn, RSE_BADAUTH, __FILE__, __LINE__, NULL);
-
- plain[0] = 0;
-
- while (left)
- {
- MD5_CTX md5;
-
- MD5_Init (&md5);
- MD5_Update (&md5, conn->active_peer->secret,
- strlen (conn->active_peer->secret));
- if (first)
- {
- MD5_Update (&md5, request->req->rpkt->vector, MD5_DIGEST_LENGTH);
- MD5_Update (&md5, key, 2);
- first = 0;
- }
- else
- {
- MD5_Update (&md5, pos - MD5_DIGEST_LENGTH, MD5_DIGEST_LENGTH);
- }
- MD5_Final (hash, &md5);
-
- for (i = 0; i < MD5_DIGEST_LENGTH; i++)
- *ppos++ = *pos++ ^ hash[i];
- left -= MD5_DIGEST_LENGTH;
- }
-
- if (plain[0] == 0 || plain[0] > plen - 1)
- return rs_err_conn_push_fl (conn, RSE_NOMEM, __FILE__, __LINE__, NULL);
-
- memcpy (vp->vp_octets, plain + 1, plain[0]);
- vp->length = plain[0];
-
- return RSE_OK;
-}