static void serpent_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) { struct serpent_ctx *ctx = crypto_tfm_ctx(tfm); const u32 *k = ((struct serpent_ctx *)ctx)->expkey; const __le32 *s = (const __le32 *)src; __le32 *d = (__le32 *)dst; u32 r0, r1, r2, r3, r4; r0 = le32_to_cpu(s[0]); r1 = le32_to_cpu(s[1]); r2 = le32_to_cpu(s[2]); r3 = le32_to_cpu(s[3]); K(r0,r1,r2,r3,32); SI7(r0,r1,r2,r3,r4); KL(r1,r3,r0,r4,r2,31); SI6(r1,r3,r0,r4,r2); KL(r0,r2,r4,r1,r3,30); SI5(r0,r2,r4,r1,r3); KL(r2,r3,r0,r4,r1,29); SI4(r2,r3,r0,r4,r1); KL(r2,r0,r1,r4,r3,28); SI3(r2,r0,r1,r4,r3); KL(r1,r2,r3,r4,r0,27); SI2(r1,r2,r3,r4,r0); KL(r2,r0,r4,r3,r1,26); SI1(r2,r0,r4,r3,r1); KL(r1,r0,r4,r3,r2,25); SI0(r1,r0,r4,r3,r2); KL(r4,r2,r0,r1,r3,24); SI7(r4,r2,r0,r1,r3); KL(r2,r1,r4,r3,r0,23); SI6(r2,r1,r4,r3,r0); KL(r4,r0,r3,r2,r1,22); SI5(r4,r0,r3,r2,r1); KL(r0,r1,r4,r3,r2,21); SI4(r0,r1,r4,r3,r2); KL(r0,r4,r2,r3,r1,20); SI3(r0,r4,r2,r3,r1); KL(r2,r0,r1,r3,r4,19); SI2(r2,r0,r1,r3,r4); KL(r0,r4,r3,r1,r2,18); SI1(r0,r4,r3,r1,r2); KL(r2,r4,r3,r1,r0,17); SI0(r2,r4,r3,r1,r0); KL(r3,r0,r4,r2,r1,16); SI7(r3,r0,r4,r2,r1); KL(r0,r2,r3,r1,r4,15); SI6(r0,r2,r3,r1,r4); KL(r3,r4,r1,r0,r2,14); SI5(r3,r4,r1,r0,r2); KL(r4,r2,r3,r1,r0,13); SI4(r4,r2,r3,r1,r0); KL(r4,r3,r0,r1,r2,12); SI3(r4,r3,r0,r1,r2); KL(r0,r4,r2,r1,r3,11); SI2(r0,r4,r2,r1,r3); KL(r4,r3,r1,r2,r0,10); SI1(r4,r3,r1,r2,r0); KL(r0,r3,r1,r2,r4,9); SI0(r0,r3,r1,r2,r4); KL(r1,r4,r3,r0,r2,8); SI7(r1,r4,r3,r0,r2); KL(r4,r0,r1,r2,r3,7); SI6(r4,r0,r1,r2,r3); KL(r1,r3,r2,r4,r0,6); SI5(r1,r3,r2,r4,r0); KL(r3,r0,r1,r2,r4,5); SI4(r3,r0,r1,r2,r4); KL(r3,r1,r4,r2,r0,4); SI3(r3,r1,r4,r2,r0); KL(r4,r3,r0,r2,r1,3); SI2(r4,r3,r0,r2,r1); KL(r3,r1,r2,r0,r4,2); SI1(r3,r1,r2,r0,r4); KL(r4,r1,r2,r0,r3,1); SI0(r4,r1,r2,r0,r3); K(r2,r3,r1,r4,0); d[0] = cpu_to_le32(r2); d[1] = cpu_to_le32(r3); d[2] = cpu_to_le32(r1); d[3] = cpu_to_le32(r4); }
void _stdcall serpent256_decrypt(const unsigned char *in, unsigned char *out, serpent256_key *key) { u32 *k = key->expkey; u32 r0, r1, r2, r3, r4; r0 = p32(in)[0]; r1 = p32(in)[1]; r2 = p32(in)[2]; r3 = p32(in)[3]; K(r0,r1,r2,r3,32); SI7(r0,r1,r2,r3,r4); KL(r1,r3,r0,r4,r2,31); SI6(r1,r3,r0,r4,r2); KL(r0,r2,r4,r1,r3,30); SI5(r0,r2,r4,r1,r3); KL(r2,r3,r0,r4,r1,29); SI4(r2,r3,r0,r4,r1); KL(r2,r0,r1,r4,r3,28); SI3(r2,r0,r1,r4,r3); KL(r1,r2,r3,r4,r0,27); SI2(r1,r2,r3,r4,r0); KL(r2,r0,r4,r3,r1,26); SI1(r2,r0,r4,r3,r1); KL(r1,r0,r4,r3,r2,25); SI0(r1,r0,r4,r3,r2); KL(r4,r2,r0,r1,r3,24); SI7(r4,r2,r0,r1,r3); KL(r2,r1,r4,r3,r0,23); SI6(r2,r1,r4,r3,r0); KL(r4,r0,r3,r2,r1,22); SI5(r4,r0,r3,r2,r1); KL(r0,r1,r4,r3,r2,21); SI4(r0,r1,r4,r3,r2); KL(r0,r4,r2,r3,r1,20); SI3(r0,r4,r2,r3,r1); KL(r2,r0,r1,r3,r4,19); SI2(r2,r0,r1,r3,r4); KL(r0,r4,r3,r1,r2,18); SI1(r0,r4,r3,r1,r2); KL(r2,r4,r3,r1,r0,17); SI0(r2,r4,r3,r1,r0); KL(r3,r0,r4,r2,r1,16); SI7(r3,r0,r4,r2,r1); KL(r0,r2,r3,r1,r4,15); SI6(r0,r2,r3,r1,r4); KL(r3,r4,r1,r0,r2,14); SI5(r3,r4,r1,r0,r2); KL(r4,r2,r3,r1,r0,13); SI4(r4,r2,r3,r1,r0); KL(r4,r3,r0,r1,r2,12); SI3(r4,r3,r0,r1,r2); KL(r0,r4,r2,r1,r3,11); SI2(r0,r4,r2,r1,r3); KL(r4,r3,r1,r2,r0,10); SI1(r4,r3,r1,r2,r0); KL(r0,r3,r1,r2,r4,9); SI0(r0,r3,r1,r2,r4); KL(r1,r4,r3,r0,r2,8); SI7(r1,r4,r3,r0,r2); KL(r4,r0,r1,r2,r3,7); SI6(r4,r0,r1,r2,r3); KL(r1,r3,r2,r4,r0,6); SI5(r1,r3,r2,r4,r0); KL(r3,r0,r1,r2,r4,5); SI4(r3,r0,r1,r2,r4); KL(r3,r1,r4,r2,r0,4); SI3(r3,r1,r4,r2,r0); KL(r4,r3,r0,r2,r1,3); SI2(r4,r3,r0,r2,r1); KL(r3,r1,r2,r0,r4,2); SI1(r3,r1,r2,r0,r4); KL(r4,r1,r2,r0,r3,1); SI0(r4,r1,r2,r0,r3); K(r2,r3,r1,r4,0); p32(out)[0] = r2; p32(out)[1] = r3; p32(out)[2] = r1; p32(out)[3] = r4; }
static void Sha256ProcessBlock(Sha256Ctx *Ctx, BYTE *block) { unsigned int i; DWORD w[64], temp1, temp2; DWORD a = Ctx->State[0]; DWORD b = Ctx->State[1]; DWORD c = Ctx->State[2]; DWORD d = Ctx->State[3]; DWORD e = Ctx->State[4]; DWORD f = Ctx->State[5]; DWORD g = Ctx->State[6]; DWORD h = Ctx->State[7]; for (i = 0; i < 16; i++) //w[ i ] = GET_UAA32BE(block, i); w[i] = BE32(((DWORD*)block)[i]); for (i = 16; i < 64; i++) w[ i ] = SI4(w[ i - 2 ]) + w[ i - 7 ] + SI3(w[ i - 15 ]) + w[ i - 16 ]; for (i = 0; i < 64; i++) { temp1 = h + SI2(e) + F0(e, f, g) + k[ i ] + w[ i ]; temp2 = SI1(a) + F1(a, b, c); h = g; g = f; f = e; e = d + temp1; d = c; c = b; b = a; a = temp1 + temp2; } Ctx->State[0] += a; Ctx->State[1] += b; Ctx->State[2] += c; Ctx->State[3] += d; Ctx->State[4] += e; Ctx->State[5] += f; Ctx->State[6] += g; Ctx->State[7] += h; }