2008-05-24 22:16:15 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2006 Mike McCormack
|
|
|
|
*
|
|
|
|
* based on arc4.cpp - written and placed in the public domain by Wei Dai
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
2013-12-06 15:04:04 +00:00
|
|
|
|
2008-05-24 22:16:15 +00:00
|
|
|
/* http://cryptopp.sourceforge.net/docs/ref521/arc4_8cpp-source.html */
|
|
|
|
|
2014-01-25 13:55:08 +00:00
|
|
|
#include "rc4.h"
|
Sync aclui, advapi32, atl, authz, kernel32, msi, oledlg, powrprof, qmgr, riched20, samlib to Wine 1.2rc5
Update some psdk Headers to get some more synched winetests build
svn path=/trunk/; revision=47930
2010-07-03 12:42:55 +00:00
|
|
|
|
2014-01-25 13:55:08 +00:00
|
|
|
void rc4_init(RC4_CONTEXT *a4i, const unsigned char *key, unsigned int keyLen)
|
2008-05-24 22:16:15 +00:00
|
|
|
{
|
|
|
|
unsigned int keyIndex = 0, stateIndex = 0;
|
|
|
|
unsigned int i, a;
|
|
|
|
|
|
|
|
a4i->x = a4i->y = 0;
|
|
|
|
|
|
|
|
for (i=0; i<256; i++)
|
|
|
|
a4i->state[i] = i;
|
|
|
|
|
|
|
|
for (i=0; i<256; i++)
|
|
|
|
{
|
|
|
|
a = a4i->state[i];
|
|
|
|
stateIndex += key[keyIndex] + a;
|
|
|
|
stateIndex &= 0xff;
|
|
|
|
a4i->state[i] = a4i->state[stateIndex];
|
|
|
|
a4i->state[stateIndex] = a;
|
|
|
|
if (++keyIndex >= keyLen)
|
|
|
|
keyIndex = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-25 13:55:08 +00:00
|
|
|
void rc4_crypt(RC4_CONTEXT *a4i, unsigned char *inoutString, unsigned int length)
|
2008-05-24 22:16:15 +00:00
|
|
|
{
|
2014-01-25 13:55:08 +00:00
|
|
|
unsigned char *const s=a4i->state;
|
2008-05-24 22:16:15 +00:00
|
|
|
unsigned int x = a4i->x;
|
|
|
|
unsigned int y = a4i->y;
|
|
|
|
unsigned int a, b;
|
|
|
|
|
|
|
|
while(length--)
|
|
|
|
{
|
|
|
|
x = (x+1) & 0xff;
|
|
|
|
a = s[x];
|
|
|
|
y = (y+a) & 0xff;
|
|
|
|
b = s[y];
|
|
|
|
s[x] = b;
|
|
|
|
s[y] = a;
|
|
|
|
*inoutString++ ^= s[(a+b) & 0xff];
|
|
|
|
}
|
|
|
|
|
|
|
|
a4i->x = x;
|
|
|
|
a4i->y = y;
|
|
|
|
}
|