K2.6 patches and update.
[tomato.git] / release / src-rt / wl / nas / mppe.c
blob60ec1c200ad0c4eefc8d87937444cac87f9d0045
1 /*
2 * Microsoft Point-to-Point Encryption Protocol (MPPE)
4 * Copyright (C) 2010, Broadcom Corporation
5 * All Rights Reserved.
6 *
7 * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Broadcom Corporation;
8 * the contents of this file may not be disclosed to third parties, copied
9 * or duplicated in any form, in whole or in part, without the prior
10 * written permission of Broadcom Corporation.
12 * $Id: mppe.c 241388 2011-02-18 03:33:22Z stakita $
15 #include <typedefs.h>
16 #include <string.h>
17 #include <bcmcrypto/md5.h>
19 #include "mppe.h"
21 #define bcopy(src, dst, len) memcpy((dst), (src), (len))
22 #define bzero(b, len) memset((b), '\0', (len))
24 /* Encrypt or decrypt a MPPE message in place */
25 void
26 mppe_crypt(unsigned char salt[2], /* 2 bytes Salt */
27 unsigned char *text, int text_len, /* Multiple of 16 bytes String */
28 unsigned char *key, int key_len, /* Shared secret */
29 unsigned char vector[16], /* 16 bytes Request Authenticator vector */
30 int encrypt) /* Encrypt if 1 */
32 unsigned char b[16], c[16], *p;
33 MD5_CTX md5;
34 int i;
36 /* Initial cipher block is Request Authenticator vector */
37 bcopy(vector, c, 16);
38 for (p = text; &p[15] < &text[text_len]; p += 16) {
39 MD5Init(&md5);
40 /* Add shared secret */
41 MD5Update(&md5, key, key_len);
42 /* Add last cipher block */
43 MD5Update(&md5, c, 16);
44 /* Add salt */
45 if (p == text)
46 MD5Update(&md5, salt, 2);
47 MD5Final(b, &md5);
48 if (encrypt) {
49 for (i = 0; i < 16; i++) {
50 p[i] ^= b[i];
51 c[i] = p[i];
53 } else {
54 for (i = 0; i < 16; i++) {
55 c[i] = p[i];
56 p[i] ^= b[i];