From 8c80877d2995ef13d99f2af9d24a66e0d68f692f Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Mon, 24 Nov 2003 16:12:20 +0000 Subject: [PATCH] Optimized the brute-force decryption. Now it still first tries the correct hash and if doesn't succed it goes for bruteforce. --- server.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/server.c b/server.c index 00d07a2..dd73482 100644 --- a/server.c +++ b/server.c @@ -904,15 +904,15 @@ static void check_sockets() if (!FD_ISSET(fd, &fds)) continue; sgets(buf, sizeof(buf), fd); + if (player_socks[i] < 0) { /* Our extension: the client can give up on the meaningless * encryption completely. */ if (strncmp(buf,"tetrisstart ",12) != 0) { /* Messy decoding stuff */ char iphashbuf[16], newbuf[1024]; -#ifdef NO_BRUTE_FORCE_DECRYPTION unsigned char *ip; -#else +#ifndef NO_BRUTE_FORCE_DECRYPTION int hashval; #endif @@ -921,35 +921,41 @@ static void check_sockets() player_socks[i] = -1; continue; } -#ifdef NO_BRUTE_FORCE_DECRYPTION + ip = player_ips[i]; sprintf(iphashbuf, "%d", ip[0]*54 + ip[1]*41 + ip[2]*29 + ip[3]*17); -#else + decrypt_message(buf, newbuf, iphashbuf); + if(strncmp(newbuf,"tetrisstart ",12) == 0) + cryptok; + +#ifndef NO_BRUTE_FORCE_DECRYPTION /* The IP-based crypt does not work for clients behind NAT. So * help them by brute-forcing the crypt. This should not be * even noticeable unless you are running this under ucLinux on * some XT machine. */ for (hashval = 0; hashval < 35956; hashval++) { sprintf(iphashbuf, "%d", hashval); -#endif decrypt_message(buf, newbuf, iphashbuf); -#ifndef NO_BRUTE_FORCE_DECRYPTION if(strncmp(newbuf,"tetrisstart ",12) == 0) - break; + goto cryptok; } /* for (hashval) */ #endif + if (strncmp(newbuf, "tetrisstart ", 12) != 0) { close(fd); player_socks[i] = -1; continue; } + +cryptok: /* Buffers should be the same size, but let's be paranoid */ strncpy(buf, newbuf, sizeof(buf)); buf[sizeof(buf)-1] = 0; } /* if encrypted */ player_socks[i] = fd; /* Has now registered */ } /* if client not registered */ + if (!server_parse(i+1, buf)) { close(fd); player_socks[i] = -1; -- 2.11.4.GIT