Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
rc4.h
Go to the documentation of this file.
1/*
2** Command & Conquer Generals Zero Hour(tm)
3** Copyright 2025 Electronic Arts Inc.
4**
5** This program is free software: you can redistribute it and/or modify
6** it under the terms of the GNU General Public License as published by
7** the Free Software Foundation, either version 3 of the License, or
8** (at your option) any later version.
9**
10** This program is distributed in the hope that it will be useful,
11** but WITHOUT ANY WARRANTY; without even the implied warranty of
12** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13** GNU General Public License for more details.
14**
15** You should have received a copy of the GNU General Public License
16** along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19#ifndef RC4_H
20#define RC4_H
21
22//
23// RC4.h - Implementation of RC4 encryption
24//
25// RC4 is a stream cypher. This means that it basically produces a stream of
26// random bytes that you XOR with your data. Each key is somewhat like a
27// one time pad.
28//
29// Just as you should never re-use a one time pad, you should never re-use a key.
30//
31// If you can't re-exchange a secret key before every message you could keep a
32// partial secret key and then include the other part of the key in plaintext.
33// The key would be the concatenation of the two parts of the key.
34//
35
37{
38public:
39
40 RC4Class();
41
42 //
43 // Key length can be 0..256 bytes
44 // Key preparation takes about 0.015 Ms on a 1Ghz PC
45 // It's 3x faster if your keylen is 8 or 16 bytes!
46 //
47 void Prepare_Key(const unsigned char *key_data_ptr, int key_data_len);
48
49 //
50 // In-place encryption. Call Prepare_Key first!
51 // Only a few clock cycles per byte (9 or so...)
52 //
53 void RC4(unsigned char *buffer_ptr, int buffer_len);
54
55
56 //
57 // Copy state & key
58 //
59 RC4Class &operator=(const RC4Class &other);
60
61
62 void Print_State(void);
63
64private:
65 void Prepare_Key_16bytes(const unsigned char *key_data_ptr);
66 void Prepare_Key_8bytes(const unsigned char *key_data_ptr);
67
68 struct RC4Key
69 {
70 unsigned char State[256];
71 unsigned char X;
72 unsigned char Y;
73 };
74
75 RC4Key Key;
76};
77
78#endif
RC4Class()
Definition rc4.cpp:95
void Print_State(void)
Definition rc4.cpp:142
void Prepare_Key(const unsigned char *key_data_ptr, int key_data_len)
Definition rc4.cpp:107
RC4Class & operator=(const RC4Class &other)
Definition rc4.cpp:188
void RC4(unsigned char *buffer_ptr, int buffer_len)
Definition rc4.cpp:158