# Cyclic Rotation in BFV

**URL:** https://openfhe.discourse.group/t/cyclic-rotation-in-bfv/468
**Category:** FHE Questions
**Created:** [April 17, 2023, 4:35am UTC](https://openfhe.discourse.group/t/cyclic-rotation-in-bfv/468 "2023-04-17T04:35:45Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![somnus](https://avatars.discourse-cdn.com/v4/letter/s/ccd318/32.png) [@somnus](https://openfhe.discourse.group/u/somnus)
#### Post date: [April 17, 2023, 4:35am UTC](https://openfhe.discourse.group/t/cyclic-rotation-in-bfv/468/1 "2023-04-17T04:35:45Z")

</div>

Hi guys,

I’m studying the rotation in RLWE, especially in BFV. May I know why the rotations must be cyclic, i.e., the values are kept in order? Is it because of the key-switching? Can we generate rotation keys for all the possible permutations in advance and map an arbitrary permutation (which may not be cyclic) to its rotation keys during key-switching? It would be great if anyone could explain a bit. Thanks in advance!

---

<div class="post-metadata">

### Author: ![ypolyakov](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/ypolyakov/32/47_2.png) [@ypolyakov](https://openfhe.discourse.group/u/ypolyakov)
#### Post date: [April 17, 2023, 5:15pm UTC](https://openfhe.discourse.group/t/cyclic-rotation-in-bfv/468/2 "2023-04-17T17:15:23Z")

</div>

The motivation for cyclic rotations is to add an ability to rotate/extract specific indices of an encrypted SIMD vector. Conventional Somewhat Homomorphic Encryption (SHE) defines additions and multiplications. When we add SIMD packing, i.e., operate on vectors of encrypted numbers, it is important to enable rotations/extraction of indices. This is why the generators are chosen in BFV in a way that cyclic rotations (over half the ring dimension) are enabled.

One could use different generators/automorphism indices to support other permutations. For instance, `EvalAutomorphism` along with `EvalautomorphismKeyGen` in OpenFHE could be used for this by more advanced users.

Also, permutations could be built by applying rotations + multiplying by binary bit masks, e.g., using permutation matrices. Linear transformations in the HE context are described in [https://eprint.iacr.org/2018/244.pdf](https://eprint.iacr.org/2018/244.pdf). Permutation matrices are explained in [Permutation matrix - Wikipedia](https://en.wikipedia.org/wiki/Permutation_matrix#Definition)

---

<div class="post-metadata">

### Author: ![somnus](https://avatars.discourse-cdn.com/v4/letter/s/ccd318/32.png) [@somnus](https://openfhe.discourse.group/u/somnus)
#### Post date: [April 18, 2023, 7:44pm UTC](https://openfhe.discourse.group/t/cyclic-rotation-in-bfv/468/3 "2023-04-18T19:44:44Z")

</div>

Thanks for the reply! A follow up question: is that possible to perform the Two-dimensional rotations in openfhe as described in Section 3.1.2.2 (page 12) of [https://www.shoup.net/papers/helib-design.pdf](https://www.shoup.net/papers/helib-design.pdf)?

---

<div class="post-metadata">

### Author: ![ypolyakov](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/ypolyakov/32/47_2.png) [@ypolyakov](https://openfhe.discourse.group/u/ypolyakov)
#### Post date: [April 20, 2023, 12:42am UTC](https://openfhe.discourse.group/t/cyclic-rotation-in-bfv/468/4 "2023-04-20T00:42:40Z")

</div>

Currently homomorphic rotations are supported only for power-of-two cyclotomics. This implies the slots are partitioned into two halves. Elements are rotated within each half and, separately, the halves can be swapped. In other words, we deal with two-dimensional arrays. The first dimension is [ring dimension]/2. The second dimension is 2. See [Rotation in BFV](https://openfhe.discourse.group/t/rotation-in-bfv/416) for more information.

We are discussing the option of adding more general cyclotomic rings for crypto schemes. It is most beneficial for BGV/BFV applications with bootstrapping.
