Changes in crypting.c [a301379c:34759e6]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
crypting.c
ra301379c r34759e6 29 29 the programs will be built. */ 30 30 31 #ifndef CRYPTING_MAIN 32 #define BITLBEE_CORE 33 #include "bitlbee.h" 34 #include "irc.h" 31 35 #include "md5.h" 32 36 #include "crypting.h" … … 35 39 #include <stdlib.h> 36 40 41 #else 42 43 typedef struct irc 44 { 45 char *password; 46 } irc_t; 47 48 #include "md5.h" 49 #include "crypting.h" 50 #include <string.h> 51 #include <stdio.h> 52 #include <stdlib.h> 53 54 #endif 55 37 56 /*\ 38 57 * [SH] Do _not_ call this if it's not entirely sure that it will not cause … … 64 83 65 84 66 char *hashpass (const char *password) 67 { 85 char *hashpass (irc_t *irc) { 68 86 md5_state_t md5state; 69 87 md5_byte_t digest[16]; … … 72 90 char *rv; 73 91 74 if (password == NULL) return (NULL); 75 76 rv = g_new0 (char, 33); 92 if (irc->password == NULL) return (NULL); 93 94 rv = (char *)g_malloc (33); 95 memset (rv, 0, 33); 77 96 78 97 md5_init (&md5state); 79 md5_append (&md5state, ( const unsigned char *)password, strlen (password));98 md5_append (&md5state, (unsigned char *)irc->password, strlen (irc->password)); 80 99 md5_finish (&md5state, digest); 81 100 … … 89 108 } 90 109 91 char *obfucrypt ( char *line, const char *password)110 char *obfucrypt (irc_t *irc, char *line) 92 111 { 93 112 int i, j; 94 113 char *rv; 95 114 96 if ( password == NULL) return (NULL);97 98 rv = g_new0 115 if (irc->password == NULL) return (NULL); 116 117 rv = g_new0(char, strlen (line) + 1); 99 118 100 119 i = j = 0; … … 102 121 /* Encrypt/obfuscate the line, using the password */ 103 122 if (*(signed char*)line < 0) *line = - (*line); 104 105 rv[j] = *line + password[i]; /* Overflow intended */ 123 if (((signed char*)irc->password)[i] < 0) irc->password[i] = - irc->password[i]; 124 125 rv[j] = *line + irc->password[i]; /* Overflow intended */ 106 126 107 127 line++; 108 if (! password[++i]) i = 0;128 if (!irc->password[++i]) i = 0; 109 129 j++; 110 130 } … … 113 133 } 114 134 115 char *deobfucrypt ( char *line, const char *password)135 char *deobfucrypt (irc_t *irc, char *line) 116 136 { 117 137 int i, j; 118 138 char *rv; 119 139 120 if ( password == NULL) return (NULL);121 122 rv = g_new0 140 if (irc->password == NULL) return (NULL); 141 142 rv = g_new0(char, strlen (line) + 1); 123 143 124 144 i = j = 0; 125 145 while (*line) { 126 146 /* Decrypt/deobfuscate the line, using the pass */ 127 rv[j] = *line - password[i]; /* Overflow intended */147 rv[j] = *line - irc->password[i]; /* Overflow intended */ 128 148 129 149 line++; 130 if (! password[++i]) i = 0;150 if (!irc->password[++i]) i = 0; 131 151 j++; 132 152 } … … 142 162 int main( int argc, char *argv[] ) 143 163 { 164 irc_t *irc = g_new0( irc_t, 1 ); 144 165 char *hash, *action, line[256]; 145 char* (*func)( char *, constchar * );166 char* (*func)( irc_t *, char * ); 146 167 147 168 if( argc < 2 ) … … 153 174 } 154 175 155 hash = hashpass( argv[1] ); 176 irc->password = g_strdup( argv[1] ); 177 178 hash = hashpass( irc ); 156 179 action = argv[0] + strlen( argv[0] ) - strlen( "encode" ); 157 180 … … 185 208 fgetc( stdin ); 186 209 187 out = func( line, argv[1]);210 out = func( irc, line ); 188 211 printf( "%s\n", out ); 189 212 g_free( out );
Note: See TracChangeset
for help on using the changeset viewer.