Changeset a7b5925


Ignore:
Timestamp:
2007-10-07T20:42:37Z (17 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
2305488
Parents:
9334cc2
Message:

Renaming RC4 to ArcFour (possible trademark issues).

Files:
2 edited
2 moved

Legend:

Unmodified
Added
Removed
  • lib/Makefile

    r9334cc2 ra7b5925  
    1010
    1111# [SH] Program variables
    12 objects = base64.o $(EVENT_HANDLER) http_client.o ini.o md5.o misc.o proxy.o rc4.o sha.o $(SSL_CLIENT) url.o
     12objects = arc.o base64.o $(EVENT_HANDLER) http_client.o ini.o md5.o misc.o proxy.o sha.o $(SSL_CLIENT) url.o
    1313
    1414CFLAGS += -Wall
  • lib/arc.c

    r9334cc2 ra7b5925  
    22*                                                                           *
    33*  BitlBee - An IRC to IM gateway                                           *
    4 *  Simple (but secure) RC4 implementation for safer password storage.       *
     4*  Simple (but secure) ArcFour implementation for safer password storage.   *
    55*                                                                           *
    66*  Copyright 2006 Wilmer van der Gaast <wilmer@gaast.net>                   *
     
    2323
    2424/*
    25    This file implements RC4-encryption, which will mainly be used to save IM
    26    passwords safely in the new XML-format. Possibly other uses will come up
    27    later. It's supposed to be quite reliable (thanks to the use of a 6-byte
    28    IV/seed), certainly compared to the old format. The only realistic way to
    29    crack BitlBee passwords now is to use a sniffer to get your hands on the
    30    user's password.
     25   This file implements ArcFour-encryption, which will mainly be used to
     26   save IM passwords safely in the new XML-format. Possibly other uses will
     27   come up later. It's supposed to be quite reliable (thanks to the use of a
     28   6-byte IV/seed), certainly compared to the old format. The only realistic
     29   way to crack BitlBee passwords now is to use a sniffer to get your hands
     30   on the user's password.
    3131   
    3232   If you see that something's wrong in this implementation (I asked a
    3333   couple of people to look at it already, but who knows), please tell me.
    3434   
    35    The reason I chose for RC4 is because it's pretty simple but effective,
     35   The reason I picked ArcFour is because it's pretty simple but effective,
    3636   so it will work without adding several KBs or an extra library dependency.
     37   
     38   (ArcFour is an RC4-compatible cipher. See for details:
     39   http://www.mozilla.org/projects/security/pki/nss/draft-kaukonen-cipher-arcfour-03.txt)
    3740*/
    3841
     
    4346#include <string.h>
    4447#include "misc.h"
    45 #include "rc4.h"
     48#include "arc.h"
    4649
    4750/* Add some seed to the password, to make sure we *never* use the same key.
    4851   This defines how many bytes we use as a seed. */
    49 #define RC4_IV_LEN 6
     52#define ARC_IV_LEN 6
    5053
    5154/* To defend against a "Fluhrer, Mantin and Shamir attack", it is recommended
    5255   to shuffle S[] just a bit more before you start to use it. This defines how
    5356   many bytes we'll request before we'll really use them for encryption. */
    54 #define RC4_CYCLES 1024
     57#define ARC_CYCLES 1024
    5558
    56 struct rc4_state *rc4_keymaker( unsigned char *key, int kl, int cycles )
     59struct arc_state *arc_keymaker( unsigned char *key, int kl, int cycles )
    5760{
    58         struct rc4_state *st;
     61        struct arc_state *st;
    5962        int i, j, tmp;
    6063       
    61         st = g_malloc( sizeof( struct rc4_state ) );
     64        st = g_malloc( sizeof( struct arc_state ) );
    6265        st->i = st->j = 0;
    6366        for( i = 0; i < 256; i ++ )
     
    7679       
    7780        for( i = 0; i < cycles; i ++ )
    78                 rc4_getbyte( st );
     81                arc_getbyte( st );
    7982       
    8083        return st;
     
    8285
    8386/*
    84    For those who don't know, RC4 is basically an algorithm that generates a
    85    stream of bytes after you give it a key. Just get a byte from it and xor
    86    it with your cleartext. To decrypt, just give it the same key again and
    87    start xorring.
     87   For those who don't know, ArcFour is basically an algorithm that generates
     88   a stream of bytes after you give it a key. Just get a byte from it and
     89   xor it with your cleartext. To decrypt, just give it the same key again
     90   and start xorring.
    8891   
    89    The function above initializes the RC4 byte generator, the next function
    90    can be used to get bytes from the generator (and shuffle things a bit).
     92   The function above initializes the byte generator, the next function can
     93   be used to get bytes from the generator (and shuffle things a bit).
    9194*/
    9295
    93 unsigned char rc4_getbyte( struct rc4_state *st )
     96unsigned char arc_getbyte( struct arc_state *st )
    9497{
    9598        unsigned char tmp;
     
    108111   The following two functions can be used for reliable encryption and
    109112   decryption. Known plaintext attacks are prevented by adding some (6,
    110    by default) random bytes to the password before setting up the RC4
     113   by default) random bytes to the password before setting up the state
    111114   structures. These 6 bytes are also saved in the results, because of
    112    course we'll need them in rc4_decode().
     115   course we'll need them in arc_decode().
    113116   
    114117   Because the length of the resulting string is unknown to the caller,
     
    122125*/
    123126
    124 int rc4_encode( char *clear, int clear_len, unsigned char **crypt, char *password )
     127int arc_encode( char *clear, int clear_len, unsigned char **crypt, char *password )
    125128{
    126         struct rc4_state *st;
     129        struct arc_state *st;
    127130        unsigned char *key;
    128131        int key_len, i;
    129132       
    130         key_len = strlen( password ) + RC4_IV_LEN;
     133        key_len = strlen( password ) + ARC_IV_LEN;
    131134        if( clear_len <= 0 )
    132135                clear_len = strlen( clear );
    133136       
    134137        /* Prepare buffers and the key + IV */
    135         *crypt = g_malloc( clear_len + RC4_IV_LEN );
     138        *crypt = g_malloc( clear_len + ARC_IV_LEN );
    136139        key = g_malloc( key_len );
    137140        strcpy( (char*) key, password );
     
    139142        /* Add the salt. Save it for later (when decrypting) and, of course,
    140143           add it to the encryption key. */
    141         random_bytes( crypt[0], RC4_IV_LEN );
    142         memcpy( key + key_len - RC4_IV_LEN, crypt[0], RC4_IV_LEN );
     144        random_bytes( crypt[0], ARC_IV_LEN );
     145        memcpy( key + key_len - ARC_IV_LEN, crypt[0], ARC_IV_LEN );
    143146       
    144147        /* Generate the initial S[] from the IVed key. */
    145         st = rc4_keymaker( key, key_len, RC4_CYCLES );
     148        st = arc_keymaker( key, key_len, ARC_CYCLES );
    146149        g_free( key );
    147150       
    148151        for( i = 0; i < clear_len; i ++ )
    149                 crypt[0][i+RC4_IV_LEN] = clear[i] ^ rc4_getbyte( st );
     152                crypt[0][i+ARC_IV_LEN] = clear[i] ^ arc_getbyte( st );
    150153       
    151154        g_free( st );
    152155       
    153         return clear_len + RC4_IV_LEN;
     156        return clear_len + ARC_IV_LEN;
    154157}
    155158
    156 int rc4_decode( unsigned char *crypt, int crypt_len, char **clear, char *password )
     159int arc_decode( unsigned char *crypt, int crypt_len, char **clear, char *password )
    157160{
    158         struct rc4_state *st;
     161        struct arc_state *st;
    159162        unsigned char *key;
    160163        int key_len, clear_len, i;
    161164       
    162         key_len = strlen( password ) + RC4_IV_LEN;
    163         clear_len = crypt_len - RC4_IV_LEN;
     165        key_len = strlen( password ) + ARC_IV_LEN;
     166        clear_len = crypt_len - ARC_IV_LEN;
    164167       
    165168        if( clear_len < 0 )
     
    173176        key = g_malloc( key_len );
    174177        strcpy( (char*) key, password );
    175         for( i = 0; i < RC4_IV_LEN; i ++ )
    176                 key[key_len-RC4_IV_LEN+i] = crypt[i];
     178        for( i = 0; i < ARC_IV_LEN; i ++ )
     179                key[key_len-ARC_IV_LEN+i] = crypt[i];
    177180       
    178181        /* Generate the initial S[] from the IVed key. */
    179         st = rc4_keymaker( key, key_len, RC4_CYCLES );
     182        st = arc_keymaker( key, key_len, ARC_CYCLES );
    180183        g_free( key );
    181184       
    182185        for( i = 0; i < clear_len; i ++ )
    183                 clear[0][i] = crypt[i+RC4_IV_LEN] ^ rc4_getbyte( st );
     186                clear[0][i] = crypt[i+ARC_IV_LEN] ^ arc_getbyte( st );
    184187        clear[0][i] = 0; /* Nice to have for plaintexts. */
    185188       
  • lib/arc.h

    r9334cc2 ra7b5925  
    22*                                                                           *
    33*  BitlBee - An IRC to IM gateway                                           *
    4 *  Simple (but secure) RC4 implementation for safer password storage.       *
     4*  Simple (but secure) ArcFour implementation for safer password storage.   *
    55*                                                                           *
    6 *  Copyright 2006 Wilmer van der Gaast <wilmer@gaast.net>                   *
     6*  Copyright 2007 Wilmer van der Gaast <wilmer@gaast.net>                   *
    77*                                                                           *
    88*  This program is free software; you can redistribute it and/or modify     *
     
    2323
    2424
    25 /* See rc4.c for more information. */
     25/* See arc.c for more information. */
    2626
    27 struct rc4_state
     27struct arc_state
    2828{
    2929        unsigned char S[256];
     
    3131};
    3232
    33 struct rc4_state *rc4_keymaker( unsigned char *key, int kl, int cycles );
    34 unsigned char rc4_getbyte( struct rc4_state *st );
    35 int rc4_encode( char *clear, int clear_len, unsigned char **crypt, char *password );
    36 int rc4_decode( unsigned char *crypt, int crypt_len, char **clear, char *password );
     33struct arc_state *arc_keymaker( unsigned char *key, int kl, int cycles );
     34unsigned char arc_getbyte( struct arc_state *st );
     35int arc_encode( char *clear, int clear_len, unsigned char **crypt, char *password );
     36int arc_decode( unsigned char *crypt, int crypt_len, char **clear, char *password );
  • storage_xml.c

    r9334cc2 ra7b5925  
    2727#include "bitlbee.h"
    2828#include "base64.h"
    29 #include "rc4.h"
     29#include "arc.h"
    3030#include "md5.h"
    3131
     
    133133                char *protocol, *handle, *server, *password = NULL, *autoconnect;
    134134                char *pass_b64 = NULL;
    135                 unsigned char *pass_rc4 = NULL;
     135                unsigned char *pass_cr = NULL;
    136136                int pass_len;
    137137                struct prpl *prpl = NULL;
     
    152152                        g_set_error( error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
    153153                                     "Unknown protocol: %s", protocol );
    154                 else if( ( pass_len = base64_decode( pass_b64, (unsigned char**) &pass_rc4 ) ) &&
    155                                          rc4_decode( pass_rc4, pass_len, &password, xd->given_pass ) )
     154                else if( ( pass_len = base64_decode( pass_b64, (unsigned char**) &pass_cr ) ) &&
     155                                         arc_decode( pass_cr, pass_len, &password, xd->given_pass ) )
    156156                {
    157157                        xd->current_account = account_add( irc, prpl, handle, password );
     
    169169                }
    170170               
    171                 g_free( pass_rc4 );
     171                g_free( pass_cr );
    172172                g_free( password );
    173173        }
     
    424424        for( acc = irc->accounts; acc; acc = acc->next )
    425425        {
    426                 unsigned char *pass_rc4;
     426                unsigned char *pass_cr;
    427427                char *pass_b64;
    428428                int pass_len;
    429429               
    430                 pass_len = rc4_encode( acc->pass, strlen( acc->pass ), (unsigned char**) &pass_rc4, irc->password );
    431                 pass_b64 = base64_encode( pass_rc4, pass_len );
    432                 g_free( pass_rc4 );
     430                pass_len = arc_encode( acc->pass, strlen( acc->pass ), (unsigned char**) &pass_cr, irc->password );
     431                pass_b64 = base64_encode( pass_cr, pass_len );
     432                g_free( pass_cr );
    433433               
    434434                if( !xml_printf( fd, 1, "<account protocol=\"%s\" handle=\"%s\" password=\"%s\" autoconnect=\"%d\"", acc->prpl->name, acc->user, pass_b64, acc->auto_connect ) )
Note: See TracChangeset for help on using the changeset viewer.