mirror of
https://github.com/transmission/transmission
synced 2024-12-24 00:34:04 +00:00
d'oh! openssl has rc4 already.
This commit is contained in:
parent
c0e872f5b8
commit
0fb5d03514
3 changed files with 1 additions and 93 deletions
|
@ -1,77 +0,0 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <inttypes.h>
|
||||
#include "rc4.h"
|
||||
|
||||
struct tr_rc4_s
|
||||
{
|
||||
uint8_t x;
|
||||
uint8_t y;
|
||||
uint8_t state[256];
|
||||
};
|
||||
|
||||
static void
|
||||
swapByte( uint8_t* a, uint8_t* b )
|
||||
{
|
||||
const uint8_t tmp = *a;
|
||||
*a = *b;
|
||||
*b = tmp;
|
||||
}
|
||||
|
||||
tr_rc4_t *
|
||||
tr_rc4New ( const uint8_t * key,
|
||||
int keylen )
|
||||
{
|
||||
uint8_t index1 = 0;
|
||||
uint8_t index2 = 0;
|
||||
uint8_t * state;
|
||||
int i;
|
||||
tr_rc4_t * ret = calloc( 1, sizeof(tr_rc4_t) );
|
||||
|
||||
/* initialize the state array */
|
||||
state = ret->state;
|
||||
for( i=0; i<256; ++i )
|
||||
state[i] = (uint8_t)i;
|
||||
|
||||
ret->x = 0;
|
||||
ret->y = 0;
|
||||
for( i=0; i<256; ++i )
|
||||
{
|
||||
index2 = (key[index1] + state[i] + index2) % 256;
|
||||
swapByte (state+i, state+index2);
|
||||
index1 = (index1 + 1) % keylen;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void
|
||||
tr_rc4Free( tr_rc4_t * rc4 )
|
||||
{
|
||||
free( rc4 );
|
||||
}
|
||||
|
||||
void
|
||||
tr_rc4Step( tr_rc4_t * key,
|
||||
uint8_t * buf,
|
||||
int buflen )
|
||||
{
|
||||
uint8_t x = key->x;
|
||||
uint8_t y = key->y;
|
||||
uint8_t * state = key->state;
|
||||
uint8_t xorIndex;
|
||||
int i;
|
||||
|
||||
for( i=0; i<buflen; ++i )
|
||||
{
|
||||
x = (x + 1) % 256;
|
||||
y = (state[x] + y) % 256;
|
||||
swapByte( state+x, state+y );
|
||||
xorIndex = (state[x] + state[y]) % 256;
|
||||
buf[i] ^= state[xorIndex];
|
||||
}
|
||||
|
||||
key->x = x;
|
||||
key->y = y;
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
#ifndef TR_RC4_H
|
||||
#define TR_RC4_H
|
||||
|
||||
typedef struct tr_rc4_s tr_rc4_t;
|
||||
|
||||
tr_rc4_t * tr_rc4New ( const uint8_t * key,
|
||||
int keylen );
|
||||
|
||||
void tr_rc4Step ( tr_rc4_t * rc4,
|
||||
uint8_t * buf,
|
||||
int buflen );
|
||||
|
||||
void tr_rc4Free ( tr_rc4_t * rc4 );
|
||||
|
||||
#endif
|
|
@ -5,7 +5,7 @@ include ../mk/common.mk
|
|||
|
||||
SRCS = bencode.c choking.c clients.c completion.c fastresume.c fdlimit.c \
|
||||
http.c inout.c ipcparse.c makemeta.c metainfo.c natpmp.c net.c \
|
||||
peer.c platform.c ratecontrol.c rc4.c sha1.c shared.c strlcat.c \
|
||||
peer.c platform.c ratecontrol.c sha1.c shared.c strlcat.c \
|
||||
strlcpy.c torrent.c tracker.c transmission.c upnp.c utils.c xml.c
|
||||
|
||||
OBJS = $(SRCS:%.c=%.o)
|
||||
|
|
Loading…
Reference in a new issue