aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--crypting.c64
-rw-r--r--crypting.h6
2 files changed, 23 insertions, 47 deletions
diff --git a/crypting.c b/crypting.c
index 8f43d3af..5ba47e5b 100644
--- a/crypting.c
+++ b/crypting.c
@@ -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 = (char *)g_malloc (strlen (line) + 1);
- memset (rv, '\0', 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 = (char *)g_malloc (strlen (line) + 1);
- memset (rv, '\0', 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_malloc( sizeof( irc_t ) );
char *hash, *action, line[256];
- char* (*func)( irc_t *, char * );
+ char* (*func)( char *, const char * );
if( argc < 2 )
{
@@ -173,10 +152,7 @@ int main( int argc, char *argv[] )
return( 1 );
}
- memset( irc, 0, sizeof( irc_t ) );
- 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 )
@@ -208,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 );
}
diff --git a/crypting.h b/crypting.h
index c2572770..fbaa7dcc 100644
--- a/crypting.h
+++ b/crypting.h
@@ -24,6 +24,6 @@
*/
int checkpass (const char *password, const char *md5sum);
-char *hashpass (irc_t *irc);
-char *obfucrypt (irc_t *irc, char *line);
-char *deobfucrypt (irc_t *irc, char *line);
+char *hashpass (const char *password);
+char *obfucrypt (char *line, const char *password);
+char *deobfucrypt (char *line, const char *password);