Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
blowfish.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/***********************************************************************************************
20 *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
21 ***********************************************************************************************
22 * *
23 * Project Name : Command & Conquer *
24 * *
25 * $Archive:: /Commando/Library/BLOWFISH.H $*
26 * *
27 * $Author:: Greg_h $*
28 * *
29 * $Modtime:: 7/22/97 11:37a $*
30 * *
31 * $Revision:: 1 $*
32 * *
33 *---------------------------------------------------------------------------------------------*
34 * Functions: *
35 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
36
37#ifndef BLOWFISH_H
38#define BLOWFISH_H
39
40#include <limits.h>
41
42
43/*
44** The "bool" integral type was defined by the C++ committee in
45** November of '94. Until the compiler supports this, use the following
46** definition.
47*/
48#include "bool.h"
49
50
51/*
52** This engine will process data blocks by encryption and decryption.
53** The "Blowfish" algorithm is in the public domain. It uses
54** a Feistal network (similar to IDEA). It has no known
55** weaknesses, but is still relatively new. Blowfish is particularly strong
56** against brute force attacks. It is also quite strong against linear and
57** differential cryptanalysis. Unlike public key encription, it is very
58** fast at encryption, as far as cryptography goes. Its weakness is that
59** it takes a relatively long time to set up with a new key (1/100th of
60** a second on a P6-200). The time to set up a key is equivalent to
61** encrypting 4240 bytes.
62*/
64 public:
65 BlowfishEngine(void) : IsKeyed(false) {}
66 ~BlowfishEngine(void);
67
68 void Submit_Key(void const * key, int length);
69
70 int Encrypt(void const * plaintext, int length, void * cyphertext);
71 int Decrypt(void const * cyphertext, int length, void * plaintext);
72
73 /*
74 ** This is the maximum key length supported.
75 */
76 enum {MAX_KEY_LENGTH=56};
77
78 private:
79 bool IsKeyed;
80
81 void Sub_Key_Encrypt(unsigned long & left, unsigned long & right);
82
83 void Process_Block(void const * plaintext, void * cyphertext, unsigned long const * ptable);
84 void Initialize_Tables(void);
85
86 enum {
87 ROUNDS = 16, // Feistal round count (16 is standard).
88 BYTES_PER_BLOCK=8 // The number of bytes in each cypher block (don't change).
89 };
90
91 /*
92 ** Initialization data for sub keys. The initial values are constant and
93 ** filled with a number generated from pi. Thus they are not random but
94 ** they don't hold a weak pattern either.
95 */
96 static unsigned long const P_Init[ROUNDS+2];
97 static unsigned long const S_Init[4][UCHAR_MAX+1];
98
99 /*
100 ** Permutation tables for encryption and decryption.
101 */
102 unsigned long P_Encrypt[ROUNDS+2];
103 unsigned long P_Decrypt[ROUNDS+2];
104
105 /*
106 ** S-Box tables (four).
107 */
108 unsigned long bf_S[4][UCHAR_MAX+1];
109};
110
111#endif
112
@ false
Definition bool.h:59
BlowfishEngine(void)
Definition blowfish.h:65
void Submit_Key(void const *key, int length)
Definition blowfish.cpp:113
int Encrypt(void const *plaintext, int length, void *cyphertext)
Definition blowfish.cpp:213
int Decrypt(void const *cyphertext, int length, void *plaintext)
Definition blowfish.cpp:279
~BlowfishEngine(void)
Definition blowfish.cpp:81