# SNARK-friendly Symmetric Encryption

### Problem Statement <a href="#pdf-page-irv4kkrrgx0wknv1rljw-problem-statement" id="pdf-page-irv4kkrrgx0wknv1rljw-problem-statement"></a>

We want an encryption scheme that would work well in arithmetic circuits (for SNARKS). So both the key and the input to the encryption should be $$m∈\mathbb{F}^n$$ vectors (with $$\mathbb{F}$$ being the field).

### Solution <a href="#pdf-page-irv4kkrrgx0wknv1rljw-solution" id="pdf-page-irv4kkrrgx0wknv1rljw-solution"></a>

**Keygen**: generate key $$x∈\mathbb{F}$$ uniformly at random

**Encrypt:**

* **Input:** message $$m\in\mathbb{F}^n$$, key $$x\in\mathbb{F}$$
* Sample a nonce $$k\in\mathbb{F}$$ uniformly at random. Compute $$a=hash(k,x)\in\mathbb{F}$$
* Compute $$r\_i​=hash(a,i)$$ for $$i=1,2,…,n$$ and let $$r\in\mathbb{F}^n$$ be the resulting vector
* Compute $$e=m+r$$ (note $$e\in\mathbb{F}^n$$)
* Output $$(k,e)$$

**Decrypt:**

* **Input:** ciphertext $$(k,e)$$, key $$x\in\mathbb{F}$$,
* Compute $$r\in\mathbb{F}^n$$ based on $$k,x$$ as above
* compute $$m=e−r$$
* Output $$m$$

Total cost for encryption and decryption is: $$≈n⋅G\_{hash}$$​ where $$G\_{hash}$$​ is the number of gates one hashing costs.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.blanksquare.io/protocol-details/cryptography/snark-friendly-symmetric-encryption.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
