[svn-upgrade] Integrating new upstream version, iodine (0.5.1)
[debian/iodine.git] / src / login.c
1 /*
2  * Copyright (c) 2006-2009 Bjorn Andersson <flex@kryo.se>, Erik Ekman <yarrick@kryo.se>
3  *
4  * Permission to use, copy, modify, and distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16
17 #include <string.h>
18 #include <sys/types.h>
19
20 #ifdef WINDOWS32
21 #include "windows.h"
22 #else
23 #include <arpa/inet.h>
24 #endif
25
26 #include "md5.h"
27
28 /* 
29  * Needs a 16byte array for output, and 32 bytes password 
30  */
31 void 
32 login_calculate(char *buf, int buflen, char *pass, int seed) 
33 {
34         unsigned char temp[32];
35         md5_state_t ctx;
36         int *ix;
37         int i;
38         int k;
39
40         if (buflen < 16) 
41                 return;
42
43         memcpy(temp, pass, 32);
44         ix = (int*) temp;
45
46         for (i = 0; i < 8; i++) {
47                 k = ntohl(*ix);
48                 k ^= seed;
49                 *ix++ = htonl(k);
50         }
51
52         md5_init(&ctx);
53         md5_append(&ctx, temp, 32);
54         md5_finish(&ctx, (unsigned char *) buf);
55
56 }
57