[IRC-Dev CVS] [CVS] Module ircdh: Change committed
Brought to you by:
zolty
From: Toni G. <zo...@us...> - 2003-01-18 23:39:24
|
CVSROOT : /cvsroot/irc-dev Module : ircdh Commit time: 2003-01-18 23:39:24 UTC Added files: tools/tea/Makefile tools/tea/README tools/tea/cifranick.c Log message: Directorio tea de utilidades tea en tools/ ---------------------- diff included ---------------------- Index: ircdh/tools/tea/Makefile diff -u /dev/null ircdh/tools/tea/Makefile:1.1 --- /dev/null Sat Jan 18 15:39:24 2003 +++ ircdh/tools/tea/Makefile Sat Jan 18 15:39:13 2003 @@ -0,0 +1,35 @@ +#************************************************************************ +#* IRC - Internet Relay Chat, ircd/crypt/tea/Makefile +#* Copyright (C) 2002 IRC-Hispano.org - ESNET - zoltan +#* +#* This program is free software; you can redistribute it and/or modify +#* it under the terms of the GNU General Public License as published by +#* the Free Software Foundation; either version 1, or (at your option) +#* any later version. +#* +#* This program is distributed in the hope that it will be useful, +#* but WITHOUT ANY WARRANTY; without even the implied warranty of +#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +#* GNU General Public License for more details. +#* +#* You should have received a copy of the GNU General Public License +#* along with this program; if not, write to the Free Software +#* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#*/ +# +# Makefile para compilar el programa de encriptar las claves +# de los nicks para la tabla 'n'. + + + +all: cifran + +cifran: + gcc -c cifranick.c + gcc cifranick.o -o cifranick + +install: + @echo 'Ya esta instalado, no hacia falta ;-).' + +clean: + /bin/rm -f cifranick *.o core *.c~ Index: ircdh/tools/tea/README diff -u /dev/null ircdh/tools/tea/README:1.1 --- /dev/null Sat Jan 18 15:39:24 2003 +++ ircdh/tools/tea/README Sat Jan 18 15:39:13 2003 @@ -0,0 +1,64 @@ +/************************************************************************ + * IRC - Internet Relay Chat, ircd/crypt/tea/README + * Copyright (C) 2002 IRC-Hispano.org - ESNET - zoltan + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 1, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + + +Fichero README del programa para encriptar claves de nick para +introducir en la tabla 'n'. + + + COMPILACION en LINUX o entornos UNIX +Para compilarlo necesitas el Make y gcc de gnu, lo podras encontrar +en http://www.gnu.org. Se compila tecleando "gmake" o "make". + + + COMPILACION en WINDOWS +Si tienes el suite Visual Studio o uno de sus partes Visual C++, puedes +hacerlo en modo grafico o en modo consola. +En modo consola se hace con "cl cifranick.c ws2_32.lib" y te generará un +ejecutable *.exe + + +Para utilizar el programa hay que teclear en la consola: + + En Linux/UNIX: + ./cifranick <nick> <clave> + En Windows: + cifranick <nick> <clave> + +siendo <nick> el nick del usuario para encriptar su clave y +<clave> la clave del usuario. (Notese que si la clave mide mas de +12 caracteres, se trunca a 12 caracteres). +El programa devolvera el nick normalizado en minusculas teniendo en +cuenta lo siguiente + La minuscula de ^ es ~ + " " de \ es | + " " de [ es { + " " de ] es } +y la clave sale encriptada, lista para meterla en la tabla 'n'. + + +Para dudas, preguntas, sugerencias, puede comentarlas en el canal +#irc-dev del iRC-Hispano o visitar la web http://www.irc-dev.net y +exponerlas en los foros. + + +08/04/2002 zoltan <zo...@ir...> + + +PD: La may£scula de NiCK es nick2 ;-) Index: ircdh/tools/tea/cifranick.c diff -u /dev/null ircdh/tools/tea/cifranick.c:1.1 --- /dev/null Sat Jan 18 15:39:24 2003 +++ ircdh/tools/tea/cifranick.c Sat Jan 18 15:39:13 2003 @@ -0,0 +1,202 @@ +/* + * IRC - Internet Relay Chat, ircd/crypt/tea/cifranick.c + * Copyright (C) 2002 IRC-Hispano.org - ESNET - zoltan + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 1, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +/* + * Programa para generar las claves cifradas de nicks + * para introducirlos en la tabla 'n' del ircd. + * + * -- zoltan + */ + + +#include <stdio.h> +#include <string.h> +#ifdef _WIN32 +# include <winsock.h> +#else +# include <netinet/in.h> +#endif + + +#define NUMNICKLOG 6 +#define NICKLEN 9 +#define NUMNICKBASE 64 /* (2 << NUMNICKLOG) */ +#define NUMNICKMASK 63 /* (NUMNICKBASE-1) */ + +static const char convert2y[] = { + 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P', + 'Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f', + 'g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v', + 'w','x','y','z','0','1','2','3','4','5','6','7','8','9','[',']' +}; + +static const unsigned int convert2n[] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 52,53,54,55,56,57,58,59,60,61, 0, 0, 0, 0, 0, 0, + 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14, + 15,16,17,18,19,20,21,22,23,24,25,62, 0,63, 0, 0, + 0,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40, + 41,42,43,44,45,46,47,48,49,50,51, 0, 0, 0, 0, 0, + + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +}; + +unsigned int base64toint(const char *s) +{ + unsigned int i = convert2n[(unsigned char)*s++]; + while (*s) + { + i <<= NUMNICKLOG; + i += convert2n[(unsigned char)*s++]; + } + return i; +} + +const char *inttobase64(char *buf, unsigned int v, unsigned int count) +{ + buf[count] = '\0'; + while (count > 0) + { + buf[--count] = convert2y[(v & NUMNICKMASK)]; + v >>= NUMNICKLOG; + } + return buf; +} + +/* + * La siguiente tabla es utilizada por la macro toLower, + * esta tabla esta extraida del archivo common.c del ircd. + * + * --Daijo + */ +const char NTL_tolower_tab[] = { + /* x00-x07 */ '\x00', '\x01', '\x02', '\x03', '\x04', '\x05', '\x06', '\x07', + /* x08-x0f */ '\x08', '\x09', '\x0a', '\x0b', '\x0c', '\x0d', '\x0e', '\x0f', + /* x10-x17 */ '\x10', '\x11', '\x12', '\x13', '\x14', '\x15', '\x16', '\x17', + /* x18-x1f */ '\x18', '\x19', '\x1a', '\x1b', '\x1c', '\x1d', '\x1e', '\x1f', + /* ' '-x27 */ ' ', '!', '"', '#', '$', '%', '&', '\x27', + /* '('-'/' */ '(', ')', '*', '+', ',', '-', '.', '/', + /* '0'-'7' */ '0', '1', '2', '3', '4', '5', '6', '7', + /* '8'-'?' */ '8', '9', ':', ';', '<', '=', '>', '?', + /* '@'-'G' */ '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', + /* 'H'-'O' */ 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', + /* 'P'-'W' */ 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', + /* 'X'-'_' */ 'x', 'y', 'z', '{', '|', '}', '~', '_', + /* '`'-'g' */ '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', + /* 'h'-'o' */ 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', + /* 'p'-'w' */ 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', + /* 'x'-x7f */ 'x', 'y', 'z', '{', '|', '}', '~', '\x7f' +}; +#define toLower(c) (NTL_tolower_tab[(c)]) + +/* + * TEA (cifrado) + * + * Cifra 64 bits de datos, usando clave de 64 bits (los 64 bits superiores son cero) + * Se cifra v[0]^x[0], v[1]^x[1], para poder hacer CBC facilmente. + * + */ +void tea(unsigned int v[], unsigned int k[], unsigned int x[]) +{ + unsigned int y = v[0] ^ x[0], z = v[1] ^ x[1], sum = 0, delta = 0x9E3779B9; + unsigned int a = k[0], b = k[1], n = 32; + unsigned int c = 0, d = 0; + + while (n-- > 0) + { + sum += delta; + y += (z << 4) + a ^ z + sum ^ (z >> 5) + b; + z += (y << 4) + c ^ y + sum ^ (y >> 5) + d; + } + + x[0] = y; + x[1] = z; +} + + +int main(int argc, char *argv[]) +{ + + unsigned int v[2], k[2], x[2]; + int cont = (NICKLEN + 8) / 8; + char tmpnick[8 * ((NICKLEN + 8) / 8) + 1]; + char tmppass[12 + 1]; + unsigned int *p = (unsigned int *)tmpnick; /* int == 32 bits */ + + char nick[NICKLEN + 1]; /* Nick normalizado */ + char clave[12 + 1]; /* Clave encriptada */ + int i = 0; + + + if (argc != 3) + { + printf("Uso: cifranick nick password\n"); + return 1; + } + + strcpy(nick, argv[1]); + nick[NICKLEN] = '\0'; + + + /* Normalizar nick */ + while (nick[i] != 0) + { + nick[i] = toLower(nick[i]); + i++; + } + + memset(tmpnick, 0, sizeof(tmpnick)); + strncpy(tmpnick, nick ,sizeof(tmpnick) - 1); + + memset(tmppass, 0, sizeof(tmppass)); + strncpy(tmppass, argv[2], sizeof(tmppass) - 1); + + /* relleno -> 123456789012 */ + strncat(tmppass, "AAAAAAAAAAAA", sizeof(tmppass) - strlen(tmppass) -1); + + x[0] = x[1] = 0; + + k[1] = base64toint(tmppass + 6); + tmppass[6] = '\0'; + k[0] = base64toint(tmppass); + + while(cont--) + { + v[0] = ntohl(*p++); /* 32 bits */ + v[1] = ntohl(*p++); /* 32 bits */ + tea(v, k, x); + } + + inttobase64(clave, x[0], 6); + inttobase64(clave + 6, x[1], 6); + + printf("Clave cifrada para %s es %s\n", nick, clave); + + return 0; + +} ----------------------- End of diff ----------------------- |