github.com/Asutorufa/yuhaiin@v0.3.6-0.20240502055049-7984da7023a0/pkg/net/proxy/shadowsocksr/cipher/camellia/camellia_ref.go (about) 1 // Use of this source code is governed by a license 2 // that can be found in the LICENSE file. 3 4 package camellia 5 6 // The camellia non-linear feistel function. 7 func f(r0, r1, r2, r3 *uint32, k0, k1 uint32) { 8 k0 ^= *r0 9 k1 ^= *r1 10 11 t := sbox4_4404[byte(k0)] 12 t ^= sbox3_3033[byte(k0>>8)] 13 t ^= sbox2_0222[byte(k0>>16)] 14 t ^= sbox1_1110[byte(k0>>24)] 15 *r3 ^= (t >> 8) | (t << (32 - 8)) 16 17 k0 = t 18 k0 ^= sbox1_1110[byte(k1)] 19 k0 ^= sbox4_4404[byte(k1>>8)] 20 k0 ^= sbox3_3033[byte(k1>>16)] 21 k0 ^= sbox2_0222[byte(k1>>24)] 22 23 *r2 ^= k0 24 *r3 ^= k0 25 } 26 27 // Note that n has to be less than 32. Rotations for larger amount 28 // of bits are achieved by "rotating" order of registers and 29 // adjusting n accordingly, e.g. RotLeft128(r1,r2,r3,r0,n-32). 30 func rotl128(r0, r1, r2, r3 *uint32, n uint) { 31 t := *r0 >> (32 - n) 32 *r0 = (*r0 << n) | (*r1 >> (32 - n)) 33 *r1 = (*r1 << n) | (*r2 >> (32 - n)) 34 *r2 = (*r2 << n) | (*r3 >> (32 - n)) 35 *r3 = (*r3 << n) | t 36 }