1 /* 2 Copyright (C) 2009-2013 DeSmuME team 3 4 This file is free software: you can redistribute it and/or modify 5 it under the terms of the GNU General Public License as published by 6 the Free Software Foundation, either version 2 of the License, or 7 (at your option) any later version. 8 9 This file is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 GNU General Public License for more details. 13 14 You should have received a copy of the GNU General Public License 15 along with the this software. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 18 #ifndef _ENCRYPT_H_ 19 #define _ENCRYPT_H_ 20 #include "types.h" 21 #include <string.h> 22 23 struct _KEY1 24 { _KEY1_KEY125 _KEY1(const u8 *inKeyBufPtr) 26 { 27 if (keyBuf) delete keyBuf; 28 keyBuf = new u32 [0x412]; 29 memset(keyBuf, 0x00, 0x412 * sizeof(u32)); 30 memset(&keyCode[0], 0, sizeof(keyCode)); 31 this->keyBufPtr = inKeyBufPtr; 32 } 33 ~_KEY1_KEY134 ~_KEY1() 35 { 36 if (keyBuf) 37 { 38 delete keyBuf; 39 keyBuf = NULL; 40 } 41 } 42 43 u32 *keyBuf; 44 u32 keyCode[3]; 45 const u8 *keyBufPtr; 46 47 void init(u32 idcode, u8 level, u8 modulo); 48 void applyKeycode(u8 modulo); 49 void decrypt(u32 *ptr); 50 void encrypt(u32 *ptr); 51 }; 52 53 struct _KEY2 54 { 55 private: 56 u64 seed0; 57 u64 seed1; 58 u64 x; 59 u64 y; 60 61 u64 bitsReverse39(u64 key); 62 63 public: _KEY2_KEY264 _KEY2() : seed0(0x58C56DE0E8ULL), 65 seed1(0x5C879B9B05ULL) 66 {} 67 68 void applySeed(u8 PROCNUM); 69 u8 apply(u8 data); 70 }; 71 72 #endif