[svn-upgrade] Integrating new upstream version, iodine (0.5.0)
[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 <arpa/inet.h>
19 #include <sys/types.h>
20
21 #include "md5.h"
22
23 /* 
24  * Needs a 16byte array for output, and 32 bytes password 
25  */
26 void 
27 login_calculate(char *buf, int buflen, char *pass, int seed) 
28 {
29         unsigned char temp[32];
30         md5_state_t ctx;
31         int *ix;
32         int i;
33         int k;
34
35         if (buflen < 16) 
36                 return;
37
38         memcpy(temp, pass, 32);
39         ix = (int*) temp;
40
41         for (i = 0; i < 8; i++) {
42                 k = ntohl(*ix);
43                 k ^= seed;
44                 *ix++ = htonl(k);
45         }
46
47         md5_init(&ctx);
48         md5_append(&ctx, temp, 32);
49         md5_finish(&ctx, (unsigned char *) buf);
50
51 }
52