PK.H (4427B)
1 // 2 // Copyright 2020 Electronic Arts Inc. 3 // 4 // TiberianDawn.DLL and RedAlert.dll and corresponding source code is free 5 // software: you can redistribute it and/or modify it under the terms of 6 // the GNU General Public License as published by the Free Software Foundation, 7 // either version 3 of the License, or (at your option) any later version. 8 9 // TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed 10 // in the hope that it will be useful, but with permitted additional restrictions 11 // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT 12 // distributed with this program. You should have received a copy of the 13 // GNU General Public License along with permitted additional restrictions 14 // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection 15 16 /* $Header: /CounterStrike/PK.H 1 3/03/97 10:25a Joe_bostic $ */ 17 /*********************************************************************************************** 18 *** 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 *** 19 *********************************************************************************************** 20 * * 21 * Project Name : Command & Conquer * 22 * * 23 * File Name : PK.H * 24 * * 25 * Programmer : Joe L. Bostic * 26 * * 27 * Start Date : 07/03/96 * 28 * * 29 * Last Update : July 3, 1996 [JLB] * 30 * * 31 *---------------------------------------------------------------------------------------------* 32 * Functions: * 33 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 34 35 #ifndef PK_H 36 #define PK_H 37 38 #include "int.h" 39 40 /* 41 ** This class holds a public or private key used in Public Key Cryptography. It also serves 42 ** as the conduit for encrypting/decrypting data using that key. Cryptography, using this 43 ** method, has a couple of characteristics that affect how it is used. One, the process of 44 ** encrypting/decrypting is very slow. This limits the effective quantity of data that can 45 ** be processed. Two, the ciphertext is larger than the plaintext. This property generally 46 ** limits its use to streaming data as opposed to random access data. The data is processed 47 ** in blocks. The size of the ciphertext and plaintext blocks can be determined only from 48 ** the key itself. 49 ** 50 ** A reasonable use of this technology would be to encrypt only critical data such as the 51 ** password for a fast general purpose cryptographic algorithm. 52 */ 53 class PKey 54 { 55 public: 56 PKey(void) : Modulus(0), Exponent(0), BitPrecision(0) {} 57 PKey(void const * exponent, void const * modulus); // DER initialization. 58 59 int Encrypt(void const * source, int slen, void * dest) const; 60 int Decrypt(void const * source, int slen, void * dest) const; 61 62 static void Generate(Straw & random, int bits, PKey & fastkey, PKey & slowkey); 63 64 int Plain_Block_Size(void) const {return((BitPrecision-1)/8);} 65 int Crypt_Block_Size(void) const {return(Plain_Block_Size()+1);} 66 int Block_Count(int plaintext_length) const {return((((plaintext_length-1)/Plain_Block_Size())+1));} 67 68 int Encode_Modulus(void * buffer) const; 69 int Encode_Exponent(void * buffer) const; 70 71 void Decode_Modulus(void * buffer); 72 void Decode_Exponent(void * buffer); 73 74 static long Fast_Exponent(void) {return(65537L);} 75 76 private: 77 78 // p*q 79 BigInt Modulus; 80 81 // 65537 or 82 // inverse of (p-1)(q-1). 83 BigInt Exponent; 84 85 // Maximum bits allowed for block. 86 int BitPrecision; 87 }; 88 89 90 #endif