ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

crypt_arc4.c
Go to the documentation of this file.
00001 /*
00002  *  Copyright 2006 Mike McCormack
00003  *
00004  *  based on arc4.cpp - written and placed in the public domain by Wei Dai
00005  *
00006  *  This library is free software; you can redistribute it and/or
00007  *  modify it under the terms of the GNU Lesser General Public
00008  *  License as published by the Free Software Foundation; either
00009  *  version 2.1 of the License, or (at your option) any later version.
00010  *
00011  *  This library is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  *  Lesser General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU Lesser General Public
00017  *  License along with this library; if not, write to the Free Software
00018  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
00019  */
00020 /* http://cryptopp.sourceforge.net/docs/ref521/arc4_8cpp-source.html */
00021 
00022 #include <advapi32.h>
00023 
00024 void arc4_init(arc4_info *a4i, const BYTE *key, unsigned int keyLen)
00025 {
00026     unsigned int keyIndex = 0, stateIndex = 0;
00027     unsigned int i, a;
00028 
00029     a4i->x = a4i->y = 0;
00030 
00031     for (i=0; i<256; i++)
00032         a4i->state[i] = i;
00033 
00034     for (i=0; i<256; i++)
00035     {
00036         a = a4i->state[i];
00037         stateIndex += key[keyIndex] + a;
00038         stateIndex &= 0xff;
00039         a4i->state[i] = a4i->state[stateIndex];
00040         a4i->state[stateIndex] = a;
00041         if (++keyIndex >= keyLen)
00042             keyIndex = 0;
00043     }
00044 }
00045 
00046 void arc4_ProcessString(arc4_info *a4i, BYTE *inoutString, unsigned int length)
00047 {
00048     BYTE *const s=a4i->state;
00049     unsigned int x = a4i->x;
00050     unsigned int y = a4i->y;
00051     unsigned int a, b;
00052 
00053     while(length--)
00054     {
00055         x = (x+1) & 0xff;
00056         a = s[x];
00057         y = (y+a) & 0xff;
00058         b = s[y];
00059         s[x] = b;
00060         s[y] = a;
00061         *inoutString++ ^= s[(a+b) & 0xff];
00062     }
00063 
00064     a4i->x = x;
00065     a4i->y = y;
00066 }
00067 

Generated on Sun May 27 2012 04:22:38 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.