def encrypt_block(self, plaintext): """Return 8-word ciphertext, encrypted from plaintext. `plaintext` must be a list of 8 64-bit words. """ key = self.key tweak = self.tweak state = words(list(imap(add64, plaintext, key[:8]))) state[5] = add64(state[5], tweak[0]) state[6] = add64(state[6], tweak[1]) for r, s in izip(xrange(1, 19), cycle((0, 16))): for i in xrange(16): m, n = PERM[i] state[m] = add64(state[m], state[n]) state[n] = RotL_64(state[n], ROT[i + s]) state[n] = state[n] ^ state[m] for y in xrange(8): state[y] = add64(state[y], key[(r + y) % 9]) state[5] = add64(state[5], tweak[r % 3]) state[6] = add64(state[6], tweak[(r + 1) % 3]) state[7] = add64(state[7], r) return state
def encrypt_block(self, plaintext): """Return 8-word ciphertext, encrypted from plaintext. `plaintext` must be a list of 8 64-bit words. """ key = self.key tweak = self.tweak state = words(list(imap(add64, plaintext, key[:8]))) state[5] = add64(state[5], tweak[0]) state[6] = add64(state[6], tweak[1]) for r,s in izip(xrange(1,19),cycle((0,16))): for i in xrange(16): m,n = PERM[i] state[m] = add64(state[m], state[n]) state[n] = RotL_64(state[n], ROT[i+s]) state[n] = state[n] ^ state[m] for y in xrange(8): state[y] = add64(state[y], key[(r+y) % 9]) state[5] = add64(state[5], tweak[r % 3]) state[6] = add64(state[6], tweak[(r+1) % 3]) state[7] = add64(state[7], r) return state
def decrypt_block(self, ciphertext): """Return 8-word plaintext, decrypted from plaintext. `ciphertext` must be a list of 8 64-bit words. """ key = self.key tweak = self.tweak state = ciphertext[:] for r, s in izip(xrange(18, 0, -1), cycle((16, 0))): for y in xrange(8): state[y] = sub64(state[y], key[(r + y) % 9]) state[5] = sub64(state[5], tweak[r % 3]) state[6] = sub64(state[6], tweak[(r + 1) % 3]) state[7] = sub64(state[7], r) for i in xrange(15, -1, -1): m, n = PERM[i] state[n] = RotR_64(state[m] ^ state[n], ROT[i + s]) state[m] = sub64(state[m], state[n]) result = list(imap(sub64, state, key)) result[5] = sub64(result[5], tweak[0]) result[6] = sub64(result[6], tweak[1]) return result
def decrypt_block(self, ciphertext): """Return 8-word plaintext, decrypted from plaintext. `ciphertext` must be a list of 8 64-bit words. """ key = self.key tweak = self.tweak state = ciphertext[:] for r,s in izip(xrange(18,0,-1),cycle((16,0))): for y in xrange(8): state[y] = sub64(state[y], key[(r+y) % 9]) state[5] = sub64(state[5], tweak[r % 3]) state[6] = sub64(state[6], tweak[(r+1) % 3]) state[7] = sub64(state[7], r) for i in xrange(15,-1,-1): m,n = PERM[i] state[n] = RotR_64(state[m] ^ state[n], ROT[i+s]) state[m] = sub64(state[m], state[n]) result = list(imap(sub64, state, key)) result[5] = sub64(result[5], tweak[0]) result[6] = sub64(result[6], tweak[1]) return result