From e5888a1ffdae813d7575f5fb02275c6bb07e5199 Mon Sep 17 00:00:00 2001 From: Taru Karttunen Date: Wed, 30 Mar 2011 15:46:40 +0300 Subject: Import sources from 2011-03-30 iso image --- sys/src/cmd/unix/drawterm/libsec/rc4.c | 104 +++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100755 sys/src/cmd/unix/drawterm/libsec/rc4.c (limited to 'sys/src/cmd/unix/drawterm/libsec/rc4.c') diff --git a/sys/src/cmd/unix/drawterm/libsec/rc4.c b/sys/src/cmd/unix/drawterm/libsec/rc4.c new file mode 100755 index 000000000..beafa4868 --- /dev/null +++ b/sys/src/cmd/unix/drawterm/libsec/rc4.c @@ -0,0 +1,104 @@ +#include "os.h" +#include + +void +setupRC4state(RC4state *key, uchar *start, int n) +{ + int t; + int index2; + uchar *state; + uchar *p, *e, *sp, *se; + + state = key->state; + se = &state[256]; + for(sp = state; sp < se; sp++) + *sp = sp - state; + + key->x = 0; + key->y = 0; + index2 = 0; + e = start + n; + p = start; + for(sp = state; sp < se; sp++) + { + t = *sp; + index2 = (*p + t + index2) & 255; + *sp = state[index2]; + state[index2] = t; + if(++p >= e) + p = start; + } +} + +void +rc4(RC4state *key, uchar *p, int len) +{ + int tx, ty; + int x, y; + uchar *state; + uchar *e; + + x = key->x; + y = key->y; + state = &key->state[0]; + for(e = p + len; p < e; p++) + { + x = (x+1)&255; + tx = state[x]; + y = (y+tx)&255; + ty = state[y]; + state[x] = ty; + state[y] = tx; + *p ^= state[(tx+ty)&255]; + } + key->x = x; + key->y = y; +} + +void +rc4skip(RC4state *key, int len) +{ + int tx, ty; + int x, y; + uchar *state; + int i; + + x = key->x; + y = key->y; + state = &key->state[0]; + for(i=0; ix = x; + key->y = y; +} + +void +rc4back(RC4state *key, int len) +{ + int tx, ty; + int x, y; + uchar *state; + int i; + + x = key->x; + y = key->y; + state = &key->state[0]; + for(i=0; ix = x; + key->y = y; +} -- cgit v1.2.3