首页
社区
课程
招聘
请教RC4算法原理[求助]
发表于: 2004-12-23 14:14 15616

请教RC4算法原理[求助]

2004-12-23 14:14
15616
各位达人,我想了解一下RC4算法,但在BAIDU和GOOGLE上没有找到实现原理和具体流程,想请大家帮帮忙,谢谢!!!

[招生]科锐逆向工程师培训(2024年11月15日实地,远程教学同时开班, 第51期)

收藏
免费 1
支持
分享
最新回复 (10)
雪    币: 398
活跃值: (343)
能力值: (RANK:650 )
在线值:
发帖
回帖
粉丝
2
不是吧,我google第一页就查到了
RC4 ENCRYPTION

The RC4 encryption algorithm is stream cipher, which can use variable length keys. The algorithm was developed in 1987 by Ron Rivest, for RSA Data Security, and was a propriety algorithm until 1994.

In the algorithm the keystream is completely independent of the plaintext used. An 8 * 8 S-Box (S0 S255), each of the entries is a permutation of the numbers 0 to 255, and the permutation is a function of the variable length key. There are two counters i, and j, both initialised to 0 used in the algorithm.

The S-Box is easily generated, using the following:

Fill S1 to S255 linearly (i.e. S0 = 0; S1 = 1 ... S255 = 255)

Another 256 byte array is then filled with the key, the key is repeated as necessary to fill the entire array.

The index j is then set to 0

for (i = 0 to i = 255)
     j = (j + Si + ki) MOD 256
    Swap Si and Sj
fi

The following is used to generate a random byte:

i = (i + 1) MOD 256
j = (j + Si) MOD 256
Swap Si and Sj
t = (Si + Sj) MOD 256
K = St

K is the XORed with the plaintext to produce the ciphertext, or the ciphertext to produce the plaintext.

RSA claims that the algorithm is immune to differential and linear cryptanalysis. The algorithm can also be changed from the 8-bit used above to 16-bit by using a 16 * 16 S-Box, and a 16-bit word. The initial set-up would need to be repeated 65,536 times to keep with the design, but it should be faster.
2004-12-23 14:21
0
雪    币: 240
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
3
晕倒,我是以rc4 加密算法搜的
谢谢shoooo

btw:工业强度的RC4是指RC4-40还是RC4-128?
2004-12-23 14:53
0
雪    币: 398
活跃值: (343)
能力值: (RANK:650 )
在线值:
发帖
回帖
粉丝
4
最初由 ferrari_fei 发布
晕倒,我是以rc4 加密算法搜的
谢谢shoooo

btw:工业强度的RC4是指RC4-40还是RC4-128?


RC4我也不是很懂,好像号称有漏洞,问问版主们吧
#include <stdio.h>

#define buf_size 1024

typedef struct rc4_key
{      
   unsigned char state[256];      
   unsigned char x;        
   unsigned char y;
} rc4_key;

#define swap_byte(x,y) t = *(x); *(x) = *(y); *(y) = t

void prepare_key(unsigned char *key_data_ptr, int key_data_len, rc4_key *key)
{
  int i;
  unsigned char t;
  unsigned char swapByte;
  unsigned char index1;
  unsigned char index2;
  unsigned char* state;
  short counter;

  state = &key->state[0];
  for(counter = 0; counter < 256; counter++)
  state[counter] = counter;
  key->x = 0;
  key->y = 0;
  index1 = 0;
  index2 = 0;
  for(counter = 0; counter < 256; counter++)
  {
    index2 = (key_data_ptr[index1] + state[counter] + index2) % 256;
    swap_byte(&state[counter], &state[index2]);
    index1 = (index1 + 1) % key_data_len;
  }
}

void rc4(unsigned char *buffer_ptr, int buffer_len, rc4_key *key)
{
  unsigned char t;
  unsigned char x;
  unsigned char y;
  unsigned char* state;
  unsigned char xorIndex;
  short counter;

  x = key->x;
  y = key->y;
  state = &key->state[0];
  for(counter = 0; counter < buffer_len; counter++)
  {
    x = (x + 1) % 256;
    y = (state[x] + y) % 256;
    swap_byte(&state[x], &state[y]);
    xorIndex = (state[x] + state[y]) % 256;
    buffer_ptr[counter] ^= state[xorIndex];
  }
  key->x = x;
  key->y = y;
}

int main(int argc, char* argv[])
{
  char seed[256];
  char data[512];
  char buf[buf_size];
  char digit[5];
  int hex, rd,i;
  int n;
  rc4_key key;

  if (argc < 2)
  {
    fprintf(stderr,"%s key <in >out\n",argv[0]);
    exit(1);
  }
  strcpy(data,argv[1]);
  n = strlen(data);
  if (n&1)
  {
    strcat(data,"0");
    n++;
  }
  n/=2;
  strcpy(digit,"AA");
  for (i=0;i<n;i++)
  {
    digit[2] = data[i*2];
    digit[3] = data[i*2+1];
    sscanf(digit,"%x",&hex);
    seed[i] = hex;
  }

  prepare_key(seed,n,&key);
  rd = fread(buf,1,buf_size,stdin);
  while (rd>0)
  {
    rc4(buf,rd,&key);
    fwrite(buf,1,rd,stdout);
    rd = fread(buf,1,buf_size,stdin);
  }
}
2004-12-23 14:57
0
雪    币: 397
活跃值: (799)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
wsy
5
rc4算法过去用得比较多的是40比特密钥
因此是不安全的

该算法在特定情况下有漏洞
一般情况下的漏洞(知道大量的输出,反求密钥)我也很想知道
有谁知道,告诉我,我会非常感激
2004-12-23 15:27
0
雪    币: 211
活跃值: (55)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
6
以上的算法好象都是基于8*8的S盒,RSA数据安全公司生成它对差分和线性分析是免疫的,但是特定的情况下好象有弱点。但是16*16的S盒加上128位以上的密钥应该是比较安全的
2004-12-26 12:51
0
雪    币: 203
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
7
好象RC4不是真正的分组算法,因为密钥短,运行快,
所以和blowfish一样运行在一些秘密程度不高的
实时通讯的协议中,如WEP,它最大的危险不在
密钥的长度,而在密钥的重复使用.
2004-12-26 17:05
0
雪    币: 397
活跃值: (799)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
wsy
8
rc4 是序列密码(也称流密码)
密钥可长可短

blowfish一般不能用于密钥频繁变换的实时通信
2004-12-27 16:40
0
雪    币: 240
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
9
8*8 S-BOX 怎么会是S0-----S255呢?
2004-12-28 13:54
0
雪    币: 211
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
10
目前还是比较安全的,IE的ssl,tls都是。
2004-12-28 16:40
0
雪    币: 211
活跃值: (55)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
11
最初由 ferrari_fei 发布
8*8 S-BOX 怎么会是S0-----S255呢?

8个二进制位可以表示0--255的无符号索引,每个元素是一个8位的字节
如果是16*16的就是2的16次方个元素的S盒,每个元素用一个字来表示,即16个二进制位
2004-12-30 22:00
0
游客
登录 | 注册 方可回帖
返回
//