/* GCNcrypt - Gamecube AR Crypto Program * * Copyright notice for this file: * Copyright (C) 2003-2004 Parasyte * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "encrypt.h" void scramble1(u32 *addr, u32 *val) { u32 tmp; *addr = rotate_left(*addr,4); tmp = ((*addr^*val)&0xF0F0F0F0); *val ^= tmp; *addr = rotate_right((*addr^tmp),0x14); tmp = ((*addr^*val)&0xFFFF0000); *val ^= tmp; *addr = rotate_right((*addr^tmp),0x12); tmp = ((*addr^*val)&0x33333333); *val ^= tmp; *addr = rotate_right((*addr^tmp),6); tmp = ((*addr^*val)&0x00FF00FF); *val ^= tmp; *addr = rotate_left((*addr^tmp),9); tmp = ((*addr^*val)&0xAAAAAAAA); *val = rotate_left((*val^tmp),1); *addr ^= tmp; } void scramble2(u32 *addr, u32 *val) { u32 tmp; *addr = rotate_right(*addr,1); tmp = ((*addr^*val)&0xAAAAAAAA); *addr ^= tmp; *val = rotate_right((*val^tmp),9); tmp = ((*addr^*val)&0x00FF00FF); *addr ^= tmp; *val = rotate_left((*val^tmp),6); tmp = ((*addr^*val)&0x33333333); *addr ^= tmp; *val = rotate_left((*val^tmp),0x12); tmp = ((*addr^*val)&0xFFFF0000); *addr ^= tmp; *val = rotate_left((*val^tmp),0x14); tmp = ((*addr^*val)&0xF0F0F0F0); *addr ^= tmp; *val = rotate_right((*val^tmp),4); } void encryptcode(u32 *seeds, u32 *code) { u32 addr,val; u32 tmp,tmp2; int i=31; getcode(code,&val,&addr); scramble1(&addr,&val); while (i >= 0) { tmp2 = (addr^seeds[i--]); tmp = (rotate_right(addr,4)^seeds[i--]); val ^= (table6[tmp&0x3F]^table4[(tmp>>8)&0x3F]^table2[(tmp>>16)&0x3F]^table0[(tmp>>24)&0x3F]^table7[tmp2&0x3F]^table5[(tmp2>>8)&0x3F]^table3[(tmp2>>16)&0x3F]^table1[(tmp2>>24)&0x3F]); tmp2 = (val^seeds[i--]); tmp = (rotate_right(val,4)^seeds[i--]); addr ^= (table6[tmp&0x3F]^table4[(tmp>>8)&0x3F]^table2[(tmp>>16)&0x3F]^table0[(tmp>>24)&0x3F]^table7[tmp2&0x3F]^table5[(tmp2>>8)&0x3F]^table3[(tmp2>>16)&0x3F]^table1[(tmp2>>24)&0x3F]); } scramble2(&addr,&val); setcode(code,addr,val); } u8 batchencrypt(u32 *codes, u16 size) { u32 tmp,*ptr=codes; if (codes[0]>>28) return 0; // not required // if (size & 1) return 0; // if (!size) return 0; codes[0] |= (verifycode(codes,size)<<28); tmp = (size >> 1); while (tmp--) { encryptcode(genseeds,ptr); ptr+=2; } return 1; //unfinished }