Changeset a301379c


Ignore:
Timestamp:
2005-12-13T22:43:59Z (14 years ago)
Author:
Jelmer Vernooij <jelmer@…>
Branches:
master
Children:
b73ac9c
Parents:
ab49fdc
Message:

Simplify obfuscation functions - make them a bit more bitlbee-independent

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • crypting.c

    rab49fdc ra301379c  
    2929   the programs will be built. */
    3030
    31 #ifndef CRYPTING_MAIN
    32 #define BITLBEE_CORE
    33 #include "bitlbee.h"
    34 #include "irc.h"
    3531#include "md5.h"
    3632#include "crypting.h"
     
    3834#include <stdio.h>
    3935#include <stdlib.h>
    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
    5536
    5637/*\
     
    8364
    8465
    85 char *hashpass (irc_t *irc) {
     66char *hashpass (const char *password)
     67{
    8668        md5_state_t md5state;
    8769        md5_byte_t digest[16];
     
    9072        char *rv;
    9173       
    92         if (irc->password == NULL) return (NULL);
     74        if (password == NULL) return (NULL);
    9375       
    94         rv = (char *)g_malloc (33);
    95         memset (rv, 0, 33);
     76        rv = g_new0 (char, 33);
    9677       
    9778        md5_init (&md5state);
    98         md5_append (&md5state, (unsigned char *)irc->password, strlen (irc->password));
     79        md5_append (&md5state, (const unsigned char *)password, strlen (password));
    9980        md5_finish (&md5state, digest);
    10081       
     
    10889}
    10990
    110 char *obfucrypt (irc_t *irc, char *line) {
     91char *obfucrypt (char *line, const char *password)
     92{
    11193        int i, j;
    11294        char *rv;
    11395       
    114         if (irc->password == NULL) return (NULL);
     96        if (password == NULL) return (NULL);
    11597       
    116         rv = (char *)g_malloc (strlen (line) + 1);
    117         memset (rv, '\0', strlen (line) + 1);
     98        rv = g_new0 (char, strlen (line) + 1);
    11899       
    119100        i = j = 0;
     
    121102                /* Encrypt/obfuscate the line, using the password */
    122103                if (*(signed char*)line < 0) *line = - (*line);
    123                 if (((signed char*)irc->password)[i] < 0) irc->password[i] = - irc->password[i];
    124104               
    125                 rv[j] = *line + irc->password[i]; /* Overflow intended */
     105                rv[j] = *line + password[i]; /* Overflow intended */
    126106               
    127107                line++;
    128                 if (!irc->password[++i]) i = 0;
     108                if (!password[++i]) i = 0;
    129109                j++;
    130110        }
     
    133113}
    134114
    135 char *deobfucrypt (irc_t *irc, char *line) {
     115char *deobfucrypt (char *line, const char *password)
     116{
    136117        int i, j;
    137118        char *rv;
    138119       
    139         if (irc->password == NULL) return (NULL);
     120        if (password == NULL) return (NULL);
    140121       
    141         rv = (char *)g_malloc (strlen (line) + 1);
    142         memset (rv, '\0', strlen (line) + 1);
     122        rv = g_new0 (char, strlen (line) + 1);
    143123       
    144124        i = j = 0;
    145125        while (*line) {
    146126                /* Decrypt/deobfuscate the line, using the pass */
    147                 rv[j] = *line - irc->password[i]; /* Overflow intended */
     127                rv[j] = *line - password[i]; /* Overflow intended */
    148128               
    149129                line++;
    150                 if (!irc->password[++i]) i = 0;
     130                if (!password[++i]) i = 0;
    151131                j++;
    152132        }
     
    162142int main( int argc, char *argv[] )
    163143{
    164         irc_t *irc = g_malloc( sizeof( irc_t ) );
    165144        char *hash, *action, line[256];
    166         char* (*func)( irc_t *, char * );
     145        char* (*func)( char *, const char * );
    167146       
    168147        if( argc < 2 )
     
    174153        }
    175154       
    176         memset( irc, 0, sizeof( irc_t ) );
    177         irc->password = g_strdup( argv[1] );
    178        
    179         hash = hashpass( irc );
     155        hash = hashpass( argv[1] );
    180156        action = argv[0] + strlen( argv[0] ) - strlen( "encode" );
    181157       
     
    209185                fgetc( stdin );
    210186               
    211                 out = func( irc, line );
     187                out = func( line, argv[1] );
    212188                printf( "%s\n", out );
    213189                g_free( out );
  • crypting.h

    rab49fdc ra301379c  
    2525
    2626int checkpass (const char *password, const char *md5sum);
    27 char *hashpass (irc_t *irc);
    28 char *obfucrypt (irc_t *irc, char *line);
    29 char *deobfucrypt (irc_t *irc, char *line);
     27char *hashpass (const char *password);
     28char *obfucrypt (char *line, const char *password);
     29char *deobfucrypt (char *line, const char *password);
Note: See TracChangeset for help on using the changeset viewer.