void MainRC6Decrypt (HRC6 hAlgorithm, PULONG In, PULONG Out) { unsigned long a, b, c, d, t, u; long r; a = In[0]; b = In[1]; c = In[2]; d = In[3]; a -= hAlgorithm->skey[42]; c -= hAlgorithm->skey[43]; for (r = ROUND - 1; r >= 0; r--) { t = d; d = c; c = b; b = a; a = t; t = (b * (b + b + 1)); t = ROL (t, 5); u = (d * (d + d + 1)); u = ROL (u, 5); c = ROR (c - hAlgorithm->skey[r + r + 3], t) ^ u; a = ROR (a - hAlgorithm->skey[r + r + 2], u) ^ t; } b -= hAlgorithm->skey[0]; d -= hAlgorithm->skey[1]; Out[0] = a; Out[1] = b; Out[2] = c; Out[3] = d; }
void __stdcall MainRC6Decrypt( HRC6 hAlgorithm, unsigned long* In, unsigned long* Out ) { unsigned long a, b, c, d, t, u; long r; #ifdef _RC6_MODE_CBC RC6_CBC_VECTOR vector; #endif a = In[0]; b = In[1]; c = In[2]; d = In[3]; #ifdef _RC6_MODE_CBC vector[0] = a; vector[1] = b; vector[2] = c; vector[3] = d; #endif a -= hAlgorithm->skey[42]; c -= hAlgorithm->skey[43]; for (r = ROUND - 1; r >= 0; r--) { t = d; d = c; c = b; b = a; a = t; t = (b * (b + b + 1)); t = ROL (t, 5); u = (d * (d + d + 1)); u = ROL (u, 5); c = ROR (c - hAlgorithm->skey[r + r + 3], t) ^ u; a = ROR (a - hAlgorithm->skey[r + r + 2], u) ^ t; } b -= hAlgorithm->skey[0]; d -= hAlgorithm->skey[1]; #ifdef _RC6_MODE_CBC a ^= hAlgorithm->vector[0]; b ^= hAlgorithm->vector[1]; c ^= hAlgorithm->vector[2]; d ^= hAlgorithm->vector[3]; hAlgorithm->vector[0] = vector[0]; hAlgorithm->vector[1] = vector[1]; hAlgorithm->vector[2] = vector[2]; hAlgorithm->vector[3] = vector[3]; #endif Out[0] = a; Out[1] = b; Out[2] = c; Out[3] = d; }
void MainRC6Encrypt (HRC6 hAlgorithm, PULONG In, PULONG Out) { unsigned long a, b, c, d, t, u; long r; a = In[0]; b = In[1]; c = In[2]; d = In[3]; b += hAlgorithm->skey[0]; d += hAlgorithm->skey[1]; for (r = 0; r < ROUND; r++) { t = (b * (b + b + 1)); t = ROL (t, 5); u = (d * (d + d + 1)); u = ROL (u, 5); a = ROL (a ^ t, u) + hAlgorithm->skey[r + r + 2]; c = ROL (c ^ u, t) + hAlgorithm->skey[r + r + 3]; t = a; a = b; b = c; c = d; d = t; } a += hAlgorithm->skey[42]; c += hAlgorithm->skey[43]; Out[0] = a; Out[1] = b; Out[2] = c; Out[3] = d; }
/* the key schedule routine */ void keySched(BYTE M[], int N, u32 **S, u32 K[40], int *k) { u32 Mo[4], Me[4]; int i, j; BYTE vector[8]; u32 A, B; *k = (N + 63) / 64; *S = (u32*)malloc(sizeof(u32) * (*k)); for (i = 0; i < *k; i++) { Me[i] = BSWAP(((u32*)M)[2*i]); Mo[i] = BSWAP(((u32*)M)[2*i+1]); } for (i = 0; i < *k; i++) { for (j = 0; j < 4; j++) vector[j] = _b(Me[i], j); for (j = 0; j < 4; j++) vector[j+4] = _b(Mo[i], j); (*S)[(*k)-i-1] = RSMatrixMultiply(vector); } for (i = 0; i < 20; i++) { A = h(2*i*RHO, Me, *k); B = ROL(h(2*i*RHO + RHO, Mo, *k), 8); K[2*i] = A+B; K[2*i+1] = ROL(A + 2*B, 9); } }
static void pi2(ulong32 *p, ulong32 *k) { ulong32 t; t = (p[1] + k[0]) & 0xFFFFFFFFUL; t = (ROL(t, 1) + t - 1) & 0xFFFFFFFFUL; t = (ROL(t, 4) ^ t) & 0xFFFFFFFFUL; p[0] ^= t; }
int rc5_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey) #endif { unsigned long L[64], S[50], A, B, i, j, v, s, t, l; _ARGCHK(skey != NULL); _ARGCHK(key != NULL); /* test parameters */ if (num_rounds == 0) { num_rounds = rc5_desc.default_rounds; } if (num_rounds < 12 || num_rounds > 24) { return CRYPT_INVALID_ROUNDS; } /* key must be between 64 and 1024 bits */ if (keylen < 8 || keylen > 128) { return CRYPT_INVALID_KEYSIZE; } /* copy the key into the L array */ for (A = i = j = 0; i < (unsigned long)keylen; ) { A = (A << 8) | ((unsigned long)(key[i++] & 255)); if ((i & 3) == 0) { L[j++] = BSWAP(A); A = 0; } } if ((keylen & 3) != 0) { A <<= (unsigned long)((8 * (4 - (keylen&3)))); L[j++] = BSWAP(A); } /* setup the S array */ t = (unsigned long)(2 * (num_rounds + 1)); S[0] = 0xB7E15163UL; for (i = 1; i < t; i++) S[i] = S[i - 1] + 0x9E3779B9UL; /* mix buffer */ s = 3 * MAX(t, j); l = j; for (A = B = i = j = v = 0; v < s; v++) { A = S[i] = ROL(S[i] + A + B, 3); B = L[j] = ROL(L[j] + A + B, (A+B)); i = (i + 1) % t; j = (j + 1) % l; } /* copy to key */ for (i = 0; i < t; i++) { skey->rc5.K[i] = S[i]; } skey->rc5.rounds = num_rounds; return CRYPT_OK; }
int rc6_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey) #endif { unsigned long L[64], S[50], A, B, i, j, v, s, t, l; _ARGCHK(key != NULL); _ARGCHK(skey != NULL); /* test parameters */ if (num_rounds != 0 && num_rounds != 20) { return CRYPT_INVALID_ROUNDS; } /* key must be between 64 and 1024 bits */ if (keylen < 8 || keylen > 128) { return CRYPT_INVALID_KEYSIZE; } /* copy the key into the L array */ for (A = i = j = 0; i < (unsigned long)keylen; ) { A = (A << 8) | ((unsigned long)(key[i++] & 255)); if (!(i & 3)) { L[j++] = BSWAP(A); A = 0; } } /* handle odd sized keys */ if (keylen & 3) { A <<= (8 * (4 - (keylen&3))); L[j++] = BSWAP(A); } /* setup the S array */ t = 44; /* fixed at 20 rounds */ S[0] = 0xB7E15163UL; for (i = 1; i < t; i++) S[i] = S[i - 1] + 0x9E3779B9UL; /* mix buffer */ s = 3 * MAX(t, j); l = j; for (A = B = i = j = v = 0; v < s; v++) { A = S[i] = ROL(S[i] + A + B, 3); B = L[j] = ROL(L[j] + A + B, (A+B)); i = (i + 1) % t; j = (j + 1) % l; } /* copy to key */ for (i = 0; i < t; i++) { skey->rc6.K[i] = S[i]; } return CRYPT_OK; }
static void pi3(ulong32 *p, ulong32 *k) { ulong32 t; t = p[0] + k[1]; t = (ROL(t, 2) + t + 1) & 0xFFFFFFFFUL; t = (ROL(t, 8) ^ t) & 0xFFFFFFFFUL; t = (t + k[2]) & 0xFFFFFFFFUL; t = (ROL(t, 1) - t) & 0xFFFFFFFFUL; t = ROL(t, 16) ^ (p[0] | t); p[1] ^= t; }
void __stdcall MainRC6Encrypt( HRC6 hAlgorithm, unsigned long* In, unsigned long* Out ) { unsigned long a, b, c, d, t, u; long r; a = In[0]; b = In[1]; c = In[2]; d = In[3]; #ifdef _RC6_MODE_CBC a ^= hAlgorithm->vector[0]; b ^= hAlgorithm->vector[1]; c ^= hAlgorithm->vector[2]; d ^= hAlgorithm->vector[3]; #endif b += hAlgorithm->skey[0]; d += hAlgorithm->skey[1]; for (r = 0; r < ROUND; r++) { t = (b * (b + b + 1)); t = ROL (t, 5); u = (d * (d + d + 1)); u = ROL (u, 5); a = ROL (a ^ t, u) + hAlgorithm->skey[r + r + 2]; c = ROL (c ^ u, t) + hAlgorithm->skey[r + r + 3]; t = a; a = b; b = c; c = d; d = t; } a += hAlgorithm->skey[42]; c += hAlgorithm->skey[43]; Out[0] = a; Out[1] = b; Out[2] = c; Out[3] = d; #ifdef _RC6_MODE_CBC hAlgorithm->vector[0] = a; hAlgorithm->vector[1] = b; hAlgorithm->vector[2] = c; hAlgorithm->vector[3] = d; #endif }
void __stdcall RC6KeySetup ( HRC6 hAlgorithm, unsigned char * key ) { unsigned long L[64], S[50], A, B, i, j, v, s, t, l; /* copy the key into the L array */ for (A = i = j = 0; i < RC6_KEY_CHARS;) { A = (A << 8) | ((unsigned long) (key[i++] & 255)); if (!(i & 3)) { L[j++] = BSWAP (A); A = 0; } } /* setup the S array */ t = ROUNDKEYS; /* fixed at 20 rounds */ S[0] = 0xB7E15163UL; for (i = 1; i < t; i++) S[i] = S[i - 1] + 0x9E3779B9UL; /* mix buffer */ s = 3 * MAX (t, j); l = j; for (A = B = i = j = v = 0; v < s; v++) { A = S[i] = ROL (S[i] + A + B, 3); B = L[j] = ROL (L[j] + A + B, (A + B)); i = (i + 1) % t; j = (j + 1) % l; } /* copy to key */ for (i = 0; i < t; i++) { hAlgorithm->skey[i] = S[i]; } #ifdef _RC6_MODE_CBC hAlgorithm->vector[0] = 0; hAlgorithm->vector[1] = 0; hAlgorithm->vector[2] = 0; hAlgorithm->vector[3] = 0; #endif }
INLINE static ulong32 FI(ulong32 R, ulong32 Km, ulong32 Kr) { ulong32 I; I = (Km + R); I = ROL(I, Kr); return ((S1[byte(I, 3)] ^ S2[byte(I,2)]) - S3[byte(I,1)]) + S4[byte(I,0)]; }
INLINE static ulong32 FIII(ulong32 R, ulong32 Km, ulong32 Kr) { ulong32 I; I = (Km - R); I = ROL(I, Kr); return ((S1[byte(I, 3)] + S2[byte(I,2)]) ^ S3[byte(I,1)]) - S4[byte(I,0)]; }
static void pi4(ulong32 *p, ulong32 *k) { ulong32 t; t = (p[1] + k[3]) & 0xFFFFFFFFUL; t = (ROL(t, 2) + t + 1) & 0xFFFFFFFFUL; p[0] ^= t; }
void Apu3B() { // ROL dp+X uint8_t Work8 = S9xAPUGetByteZ(OP1 + IAPU.Registers.X); ROL(Work8); S9xAPUSetByteZ(Work8, OP1 + IAPU.Registers.X); IAPU.PC += 2; }
void Apu2B() { // ROL dp uint8_t Work8 = S9xAPUGetByteZ(OP1); ROL(Work8); S9xAPUSetByteZ(Work8, OP1); IAPU.PC += 2; }
void Apu2C() { // ROL abs Absolute(); uint8_t Work8 = S9xAPUGetByte(IAPU.Address); ROL(Work8); S9xAPUSetByte(Work8, IAPU.Address); IAPU.PC += 3; }
void _rolAbsl(void) { word addr; addr = fetch_word((word)(cpu.pc + 1)); ROL(addr); cpu.pc += 3; }
void _rolAbx(void) { word addr; addr = fetch_word((word)(cpu.pc + 1)); ROL((word)(addr + cpu.x)); cpu.pc += 3; }
void _rolZp(void) { byte zaddr; zaddr = fetch_byte((word)(cpu.pc + 1)); ROL(zaddr); cpu.pc += 2; }
void _rolZpx(void) { byte zaddr; zaddr = fetch_byte((word)(cpu.pc + 1)); ROL((word)(zaddr + cpu.x)); cpu.pc += 2; }
void rc5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *key) #endif { unsigned long A, B; int r; _ARGCHK(key != NULL); _ARGCHK(pt != NULL); _ARGCHK(ct != NULL); LOAD32L(A, &pt[0]); LOAD32L(B, &pt[4]); A += key->rc5.K[0]; B += key->rc5.K[1]; for (r = 0; r < key->rc5.rounds; r++) { A = ROL(A ^ B, B) + key->rc5.K[r+r+2]; B = ROL(B ^ A, A) + key->rc5.K[r+r+3]; } STORE32L(A, &ct[0]); STORE32L(B, &ct[4]); }
int rc5_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey) #endif { ulong32 L[64], *S, A, B, i, j, v, s, t, l; LTC_ARGCHK(skey != NULL); LTC_ARGCHK(key != NULL); /* test parameters */ if (num_rounds == 0) { num_rounds = rc5_desc.default_rounds; } if (num_rounds < 12 || num_rounds > 24) { return CRYPT_INVALID_ROUNDS; } /* key must be between 64 and 1024 bits */ if (keylen < 8 || keylen > 128) { return CRYPT_INVALID_KEYSIZE; } skey->rc5.rounds = num_rounds; S = skey->rc5.K; /* copy the key into the L array */ for (A = i = j = 0; i < (ulong32)keylen; ) { A = (A << 8) | ((ulong32)(key[i++] & 255)); if ((i & 3) == 0) { L[j++] = BSWAP(A); A = 0; } } if ((keylen & 3) != 0) { A <<= (ulong32)((8 * (4 - (keylen&3)))); L[j++] = BSWAP(A); } /* setup the S array */ t = (ulong32)(2 * (num_rounds + 1)); XMEMCPY(S, stab, t * sizeof(*S)); /* mix buffer */ s = 3 * MAX(t, j); l = j; for (A = B = i = j = v = 0; v < s; v++) { A = S[i] = ROLc(S[i] + A + B, 3); B = L[j] = ROL(L[j] + A + B, (A+B)); if (++i == t) { i = 0; } if (++j == l) { j = 0; } } return CRYPT_OK; }
int rc5_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey) #endif { ulong32 A, B, *K; int r; LTC_ARGCHK(skey != NULL); LTC_ARGCHK(pt != NULL); LTC_ARGCHK(ct != NULL); LOAD32L(A, &pt[0]); LOAD32L(B, &pt[4]); A += skey->rc5.K[0]; B += skey->rc5.K[1]; K = skey->rc5.K + 2; if ((skey->rc5.rounds & 1) == 0) { for (r = 0; r < skey->rc5.rounds; r += 2) { A = ROL(A ^ B, B) + K[0]; B = ROL(B ^ A, A) + K[1]; A = ROL(A ^ B, B) + K[2]; B = ROL(B ^ A, A) + K[3]; K += 4; } } else { for (r = 0; r < skey->rc5.rounds; r++) { A = ROL(A ^ B, B) + K[0]; B = ROL(B ^ A, A) + K[1]; K += 2; } } STORE32L(A, &ct[0]); STORE32L(B, &ct[4]); return CRYPT_OK; }
int rc6_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey) #endif { ulong32 L[64], S[50], A, B, i, j, v, s, l; LTC_ARGCHK(key != NULL); LTC_ARGCHK(skey != NULL); /* test parameters */ if (num_rounds != 0 && num_rounds != 20) { return CRYPT_INVALID_ROUNDS; } /* key must be between 64 and 1024 bits */ if (keylen < 8 || keylen > 128) { return CRYPT_INVALID_KEYSIZE; } /* copy the key into the L array */ for (A = i = j = 0; i < (ulong32)keylen; ) { A = (A << 8) | ((ulong32)(key[i++] & 255)); if (!(i & 3)) { L[j++] = BSWAP(A); A = 0; } } /* handle odd sized keys */ if (keylen & 3) { A <<= (8 * (4 - (keylen&3))); L[j++] = BSWAP(A); } /* setup the S array */ XMEMCPY(S, stab, 44 * sizeof(stab[0])); /* mix buffer */ s = 3 * MAX(44, j); l = j; for (A = B = i = j = v = 0; v < s; v++) { A = S[i] = ROLc(S[i] + A + B, 3); B = L[j] = ROL(L[j] + A + B, (A+B)); if (++i == 44) { i = 0; } if (++j == l) { j = 0; } } /* copy to key */ for (i = 0; i < 44; i++) { skey->rc6.K[i] = S[i]; } return CRYPT_OK; }
void rc6_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *key) #endif { unsigned long a,b,c,d,t,u; int r; _ARGCHK(key != NULL); _ARGCHK(pt != NULL); _ARGCHK(ct != NULL); LOAD32L(a,&pt[0]);LOAD32L(b,&pt[4]);LOAD32L(c,&pt[8]);LOAD32L(d,&pt[12]); b += key->rc6.K[0]; d += key->rc6.K[1]; for (r = 0; r < 20; r++) { t = (b * (b + b + 1)); t = ROL(t, 5); u = (d * (d + d + 1)); u = ROL(u, 5); a = ROL(a^t,u) + key->rc6.K[r+r+2]; c = ROL(c^u,t) + key->rc6.K[r+r+3]; t = a; a = b; b = c; c = d; d = t; } a += key->rc6.K[42]; c += key->rc6.K[43]; STORE32L(a,&ct[0]);STORE32L(b,&ct[4]);STORE32L(c,&ct[8]);STORE32L(d,&ct[12]); }
//--------- BEGIN OF FUNCTION IMGsnow32x32 ----------- // // Draw random white dots of 32x32 square on the VGA screen // // Note : No border checking is made in this function. // Placing an icon outside image buffer will cause serious BUG. // // char *imageBuf - the pointer to the display surface buffer // int pitch - the pitch of the display surface buffer // int x1,y1 - the top left vertex of the bar // int randSeed - random seed // int seaLevel - draw white dot if height > seaLevel void IMGcall IMGsnow32x32(char*imageBuf,int pitch,int x1,int y1,int randSeed,int seaLevel) { int destline = y1*pitch + x1; for (int j=0; j<32; j+=2, destline+=2*pitch) { randSeed *= SNOW_MAGIC_NUMBER; for (int i=0; i<32; i+=2) { randSeed = ROL((unsigned int)randSeed, 10); if ( (randSeed&0xffff) >= (seaLevel&0xffff) ) // only compare the lower 16 bits. imageBuf[ destline + i ] = SNOW_COLOR; } } }
void rc6_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *key) #endif { unsigned long a,b,c,d,t,u; int r; _ARGCHK(key != NULL); _ARGCHK(pt != NULL); _ARGCHK(ct != NULL); LOAD32L(a,&ct[0]);LOAD32L(b,&ct[4]);LOAD32L(c,&ct[8]);LOAD32L(d,&ct[12]); a -= key->rc6.K[42]; c -= key->rc6.K[43]; for (r = 19; r >= 0; r--) { t = d; d = c; c = b; b = a; a = t; t = (b * (b + b + 1)); t = ROL(t, 5); u = (d * (d + d + 1)); u = ROL(u, 5); c = ROR(c - key->rc6.K[r+r+3], t) ^ u; a = ROR(a - key->rc6.K[r+r+2], u) ^ t; } b -= key->rc6.K[0]; d -= key->rc6.K[1]; STORE32L(a,&pt[0]);STORE32L(b,&pt[4]);STORE32L(c,&pt[8]);STORE32L(d,&pt[12]); }
/** * Verifies the title has a valid checksum * @param title title and checksum * @param len the length of the title to read/checksum * @return true iff the title is valid * @note the title (incl. checksum) has to be at least 41/49 (HEADER_SIZE) bytes long! */ static bool VerifyOldNameChecksum(char *title, uint len) { uint16 sum = 0; for (uint i = 0; i < len - 2; i++) { sum += title[i]; sum = ROL(sum, 1); } sum ^= 0xAAAA; // computed checksum uint16 sum2 = title[len - 2]; // checksum in file SB(sum2, 8, 8, title[len - 1]); return sum == sum2; }
hexstring;}void CPID::update5(std::string longcpid,uint256 hash_block){std:: string shash=HashHex(hash_block);int hexpos=(0x43b+6491-0x1d96);unsigned char* input=new unsigned char[(longcpid.length()/(0x534+8432-0x2622))+ (0xa19+5289-0x1ec1)];for(int i1=(0x1348+1245-0x1825);i1<(int)longcpid.length(); i1=i1+(0x478+5707-0x1ac1)){input[hexpos]=ROL(shash,i1,longcpid,hexpos);hexpos++; }input[longcpid.length()/(0x7ac+7506-0x24fc)+(0xba+3605-0xece)]= (0x3c3+5976-0x1b1b);size_type length=longcpid.length()/(0x1186+4729-0x23fd); size_type index=count[(0xf02+2743-0x19b9)]/(0x174+6416-0x1a7c)%blocksize; if((count[(0x1eb3+1439-0x2452)]+=(length<<(0x89c+7639-0x2670)))<(length<< (0x1f07+935-0x22ab)))count[(0x488+7340-0x2133)]++;count[(0xb5+5597-0x1691)]+=( length>>(0x374+3554-0x1139)); size_type firstpart=(0x195+7412-0x1e49)-index;size_type i; if(length>=firstpart){ memcpy(&buffer[index],input,firstpart);transform(buffer); for(i=firstpart;i+blocksize<=length;i+=blocksize)transform(&input[i]);index= (0x144f+4713-0x26b8);}else i=(0x1053+3145-0x1c9c); memcpy(&buffer[index],&input[i],length-i);}
int32 MIXArchive::getHash(const Common::String &name) { char buffer[12] = { 0 }; for (uint i = 0; i != name.size() && i < 12u; ++i) { buffer[i] = (char)toupper(name[i]); } uint32 id = 0; for (int i = 0; i < 12 && buffer[i]; i += 4) { uint32 t = (uint32)buffer[i + 3] << 24 | (uint32)buffer[i + 2] << 16 | (uint32)buffer[i + 1] << 8 | (uint32)buffer[i + 0]; id = ROL(id) + t; } return id; }