diff options
| author | Wilmer van der Gaast <wilmer@gaast.net> | 2005-12-14 00:21:21 +0100 | 
|---|---|---|
| committer | Wilmer van der Gaast <wilmer@gaast.net> | 2005-12-14 00:21:21 +0100 | 
| commit | 6aaa2213588f7c4c00a68c5622f6974679eaf196 (patch) | |
| tree | 7aad536700d387bacd3003927e9ac3c531616259 /crypting.c | |
| parent | ab4afbab829a4a5bf520d4e1425a743cdb8c4865 (diff) | |
| parent | d3307e281afdbed22a561eb2cd73f97a03e3073d (diff) | |
More work on the storage abstraction layer from Jelmer.
Diffstat (limited to 'crypting.c')
| -rw-r--r-- | crypting.c | 59 | 
1 files changed, 18 insertions, 41 deletions
| @@ -28,31 +28,12 @@     included if CRYPTING_MAIN is defined. Or just do "make decode" and     the programs will be built. */ -#ifndef CRYPTING_MAIN -#define BITLBEE_CORE -#include "bitlbee.h" -#include "irc.h"  #include "md5.h"  #include "crypting.h"  #include <string.h>  #include <stdio.h>  #include <stdlib.h> -#else - -typedef struct irc -{ -	char *password; -} irc_t; - -#include "md5.h" -#include "crypting.h" -#include <string.h> -#include <stdio.h> -#include <stdlib.h> - -#endif -  /*\   * [SH] Do _not_ call this if it's not entirely sure that it will not cause   * harm to another users file, since this does not check the password for @@ -82,20 +63,20 @@ int checkpass (const char *pass, const char *md5sum)  } -char *hashpass (irc_t *irc) { +char *hashpass (const char *password) +{  	md5_state_t md5state;  	md5_byte_t digest[16];  	int i;  	char digits[3];  	char *rv; -	if (irc->password == NULL) return (NULL); +	if (password == NULL) return (NULL); -	rv = (char *)g_malloc (33); -	memset (rv, 0, 33); +	rv = g_new0 (char, 33);  	md5_init (&md5state); -	md5_append (&md5state, (unsigned char *)irc->password, strlen (irc->password)); +	md5_append (&md5state, (const unsigned char *)password, strlen (password));  	md5_finish (&md5state, digest);  	for (i = 0; i < 16; i++) { @@ -107,47 +88,46 @@ char *hashpass (irc_t *irc) {  	return (rv);  } -char *obfucrypt (irc_t *irc, char *line)  +char *obfucrypt (char *line, const char *password)   {  	int i, j;  	char *rv; -	if (irc->password == NULL) return (NULL); +	if (password == NULL) return (NULL); -	rv = g_new0(char, strlen (line) + 1); +	rv = g_new0 (char, strlen (line) + 1);  	i = j = 0;  	while (*line) {  		/* Encrypt/obfuscate the line, using the password */  		if (*(signed char*)line < 0) *line = - (*line); -		if (((signed char*)irc->password)[i] < 0) irc->password[i] = - irc->password[i]; -		rv[j] = *line + irc->password[i]; /* Overflow intended */ +		rv[j] = *line + password[i]; /* Overflow intended */  		line++; -		if (!irc->password[++i]) i = 0; +		if (!password[++i]) i = 0;  		j++;  	}  	return (rv);  } -char *deobfucrypt (irc_t *irc, char *line)  +char *deobfucrypt (char *line, const char *password)   {  	int i, j;  	char *rv; -	if (irc->password == NULL) return (NULL); +	if (password == NULL) return (NULL); -	rv = g_new0(char, strlen (line) + 1); +	rv = g_new0 (char, strlen (line) + 1);  	i = j = 0;  	while (*line) {  		/* Decrypt/deobfuscate the line, using the pass */ -		rv[j] = *line - irc->password[i]; /* Overflow intended */ +		rv[j] = *line - password[i]; /* Overflow intended */  		line++; -		if (!irc->password[++i]) i = 0; +		if (!password[++i]) i = 0;  		j++;  	} @@ -161,9 +141,8 @@ char *deobfucrypt (irc_t *irc, char *line)  int main( int argc, char *argv[] )  { -	irc_t *irc = g_new0( irc_t, 1 );  	char *hash, *action, line[256]; -	char* (*func)( irc_t *, char * ); +	char* (*func)( char *, const char * );  	if( argc < 2 )  	{ @@ -173,9 +152,7 @@ int main( int argc, char *argv[] )  		return( 1 );  	} -	irc->password = g_strdup( argv[1] ); -	 -	hash = hashpass( irc ); +	hash = hashpass( argv[1] );  	action = argv[0] + strlen( argv[0] ) - strlen( "encode" );  	if( strcmp( action, "encode" ) == 0 ) @@ -207,7 +184,7 @@ int main( int argc, char *argv[] )  		/* Flush the newline */  		fgetc( stdin ); -		out = func( irc, line ); +		out = func( line, argv[1] );  		printf( "%s\n", out );  		g_free( out );  	} | 
