Changeset d3307e2 for crypting.c


Ignore:
Timestamp:
2005-12-13T23:07:05Z (19 years ago)
Author:
Jelmer Vernooij <jelmer@…>
Branches:
master
Children:
6aaa221
Parents:
34759e6 (diff), b73ac9c (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge my storage fixes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • crypting.c

    r34759e6 rd3307e2  
    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)
    11192{
    11293        int i, j;
    11394        char *rv;
    11495       
    115         if (irc->password == NULL) return (NULL);
     96        if (password == NULL) return (NULL);
    11697       
    117         rv = g_new0(char, 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)
    136116{
    137117        int i, j;
    138118        char *rv;
    139119       
    140         if (irc->password == NULL) return (NULL);
     120        if (password == NULL) return (NULL);
    141121       
    142         rv = g_new0(char, 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_new0( irc_t, 1 );
    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         irc->password = g_strdup( argv[1] );
    177        
    178         hash = hashpass( irc );
     155        hash = hashpass( argv[1] );
    179156        action = argv[0] + strlen( argv[0] ) - strlen( "encode" );
    180157       
     
    208185                fgetc( stdin );
    209186               
    210                 out = func( irc, line );
     187                out = func( line, argv[1] );
    211188                printf( "%s\n", out );
    212189                g_free( out );
Note: See TracChangeset for help on using the changeset viewer.