# ACE Encrypt

ACE (advanced cryptographic engine) is the collection of units, implementing both a public key encryption scheme and a digital signature scheme. Corresponding names for these schemes — «ACE Encrypt» and «ACE Sign». Schemes are based on Cramer-Shoup public key encryption scheme and Cramer-Shoup signature scheme. Introduced variants of these schemes are intended to achieve a good balance between performance and security of the whole encryption system.

## Authors

All the algorithms, implemented in ACE are based on algorithms developed by Victor Shoup and Ronald Cramer. The full algorithms specification is written by Victor Shoup. Implementation of algorithms is done by Thomas Schweinberger and Mehdi Nassehi, its supporting and maintaining is done by Victor Shoup. Thomas Schweinberger participated in construction of ACE specification document and also wrote a user manual.
Ronald Cramer currently stays in the university of Aarhus, Denmark. He worked on the project of ACE Encrypt while his staying in ETH in Zürich, Switzerland.
Mehdi Nassehi and Thomas Schweinberger worked on ACE project in the IBM research lab in Zürich, Switzerland. Victor Shoup works in the IBM research lab in Zürich, Switzerland.

## Security

The encryption scheme in ACE can be proven secure under reasonable and natural intractability assumptions. These four assumptions are:
* The Decisional Diffie-Hellman (DDH) assumption
* Strong RSA assumption
* SHA-1 second preimage collision resistance
* MARS sum/counter mode pseudo-randomness

## Basic Terminology and Notation

Here we introduce some notations, being used in this article.

### Basic mathematical notation

$\mathbb {Z}$ — The set of integers. $F_{2}[T]$ — The set of univariate polynomials with coefficients in the finite field $F_{2}$ of cardinality 2. $A\operatorname {rem} n$ — integer $r\in \left\{0,\dots ,n-1\right\}$ such that $A\equiv r{\pmod {n}}$ for integer $n>0$ and $A\in \mathbb {Z}$. $A\operatorname {rem} f$ — polynomial $r\in F_{2}[T]$ with $\deg(r)<\deg(f)$ such that $A\equiv r{\pmod {f}}$ with $A,f\in F_{2}[T],f\neq 0$.

### Basic string notation

$A^{\ast }$ — The set of all strings. $A^{n}$ — The set of all strings with length n. For $x\in A^{\ast }L(x)$ — length of string $x$. The string of length zero is denoted $\lambda _{A}$. For $x,y\in A^{\ast }$ $x\|y$ — the result of $x$ and $y$ concatenation.

### Bits, Bytes, Words

$b{\overset {\text{def}}{=}}\left\{0,1\right\}$ — The set of bits. Let us take all sets of form $b,b^{n_{1}},(b^{n_{1}})^{n_{2}},...$. For such a set A we define the "zero element":
$0_{b}{\stackrel {\mathrm {def} }{=}}0\in b$
$0_{A^{n}}{\stackrel {\mathrm {def} }{=}}(0_{A},...,0_{A})\in A^{n}$
$n>0$
We define $B{\stackrel {\mathrm {def} }{=}}b^{8}$ as a set of bytes, and $W{\stackrel {\mathrm {def} }{=}}b^{32}$ as a set of words.
For $x\in A^{\ast }$ with $A\in \left\{b,B,W\right\}$ and $l>0$ we define a padding operator:
$pad_{l}(x){\stackrel {\mathrm {def} }{=}}{\begin{cases}x,&L(x)\geq l\\x||0_{A^{l-L(x)}},&L(x)<l\end{cases}}$

### Conversion operator

Conversion operator $I_{src}^{dst}:src\to dst$ makes a conversion between elements $Z,F_{2}[T],b^{\ast },B^{\ast },W^{\ast }$.

## Encryption Scheme
### Encryption Key Pair

The encryption scheme employs two key types: ACE public key: $(P,q,g_{1},g_{2},c,d,h_{1},h_{2},k_{1},k_{2})$. ACE private key: $(w,x,y,z_{1},z_{2})$. For a given size parameter $m$, such that $1024\leq m\leq 16384$, key components are defined as: $q$ — a 256-bit prime number. $P$ — a m-bit prime number, such that $P\equiv 1{\pmod {q}}$. $g_{1},g_{2},c,d,h_{1},h_{2}$ — elements $\left\{1,\dots ,P-1\right\}$ (whose multiplicative order modulo $P$ divides $q$). $w,x,y,z_{1},z_{2}$ — elements $\left\{0,\dots ,q-1\right\}$. $k_{1},k_{2}$ — elements $B^{\ast }$ with $L(k_{1})=20l'+64$ and $L(k_{2})=32\left\lceil l/16\right\rceil +40$, where $l=\left\lceil m/8\right\rceil$ and $l'=L_{b}(\left\lceil (2\left\lceil l/4\right\rceil +4)/16\right\rceil )$.

### Key Generation

Algorithm. Key Generation for ACE encryption scheme. Input: a size parameter $m$, such that $1024\leq m\leq 16384$. Output: a public/private key pair.
* Generate a random prime $q$, such that $2^{255}<q<2^{256}$.
* Generate a random prime $P$, $2^{m-1}<P<2^{m}$, such that $P\equiv 1(modq)$.
* Generate a random integer $g_{1}\in \left\{2,...,P-1\right\}$, such that $g_{1}^{q}\equiv 1(modP)$.
* Generate random integers $w\in \left\{1,...,q-1\right\}$ and $x,y,z_{1},z_{2}\in \left\{0,...,q-1\right\}$
* Compute the following integers in $\left\{1,...,P-1\right\}$:$g_{2}\leftarrow g_{1}^{w}remP$, $c\leftarrow g_{1}^{x}remP$, $d\leftarrow g_{1}^{y}remP$, $h_{1}\leftarrow g_{1}^{z_{1}}remP$, $h_{2}\leftarrow g_{1}^{z_{2}}remP$.
* Generate random byte strings $k_{1}\in B^{20l'+64}$ and $k_{2}\in B^{2\left\lceil l/16\right\rceil +40}$, where $l=L_{B}(P)$ and $l'=L_{B}(\left\lceil (2\left\lceil l/4\right\rceil +4)/16\right\rceil )$.
* Return the public key/private key pair $((P,q,g_{1},g_{2},c,d,h_{1},h_{2},k_{1},k_{2}),(w,x,y,z_{1},z_{2}))$

### Ciphertext Representation

A ciphertext of the ACE encryption scheme has the form
$(s,u_{1},u_{2},v,e)$
where the components are defined as: $u_{1},u_{2},v$ — integers from $\left\{1,...,P-1\right\}$ (whose multiplicative order modulo $P$ divides $q$). $s$ — element $W^{4}$. $e$ — element $B^{\ast }$. $s,u_{1},u_{2},v$ we call the preamble, and $e$ — the cryptogram. If a cleartext is a string consisting of $l$ байт, then the length of $e$ is equal to $l+16\left\lceil l/1024\right\rceil$. We need to introduce the function $CEncode$, which maps a ciphertext to its byte-string
representation, and the corresponding inverse function $CDecode$. For the integer $l>0$, word string $s\in W^{4}$, integers $0\leq u_{1},u_{2},v<256^{l}$, and byte string $e\in B^{\ast }$,
$CEncode(l,s,u_{1},u_{2},v,e){\stackrel {\mathrm {def} }{=}}I_{W^{\ast }}^{B^{\ast }}(s)||pad_{l}(I_{Z}^{B^{\ast }}(u_{1}))||pad_{l}(I_{Z}^{B^{\ast }}(u_{2}))||pad_{l}(I_{Z}^{B^{\ast }}(v))||e\in B^{\ast }$
For integer $l>0$, byte string $\psi \in B^{\ast }$, such that $L(\psi )\geq 3l+16$,
$CDecode(l,\psi ){\stackrel {\mathrm {def} }{=}}(I_{B^{\ast }}^{W^{\ast }}({\Bigl\psi {\Bigr ]}_{0}^{16}),I_{B^{\ast }}^{Z}({\Bigl\psi {\Bigr ]}_{16}^{16+l}),I_{B^{\ast }}^{Z}({\Bigl\psi {\Bigr ]}_{16+l}^{16+2l}),I_{B^{\ast }}^{Z}({\Bigl\psi {\Bigr ]}_{16+2l}^{16+3l}),{\Bigl\psi {\Bigr ]}_{16+3l}^{L(\psi )})\in W^{4}\times Z\times Z\times Z\times B^{\ast }$

### Encryption Process

Algorithm. ACE asymmetric encryption operation. input: public key $(P,q,g_{1},g_{2},c,d,h_{1},h_{2},k_{1},k_{2})$ and byte string $M\in B^{\ast }$. Output: byte string — ciphertext $\psi \$ of $M$.
* Generate $r\in \left\{0,...,q-1\right\}$ at random.
* Generate the ciphertext preamble:
** Generate $s\in W^{4}$ at random.
** Compute $u_{1}\leftarrow g_{1}^{r}remP$, $u_{2}\leftarrow g_{2}^{r}remP$.
** Compute $\alpha \ \leftarrow UOWHash^{\prime }(k_{1},L_{B}(P),s,u_{1},u_{2})\in Z$; note that $0<\alpha \ <2^{160}$.
** Compute $v\leftarrow c^{r}d^{\alpha \ r}remP$.
* Compute the key for the symmetric encryption operation:
** ${\tilde {h_{1}}}\leftarrow h_{1}^{r}remP$, ${\tilde {h_{2}}}\leftarrow h_{2}^{r}remP$.
** Compute $k\leftarrow ESHash(k,L_{B}(P),s,u_{1},u_{2},{\tilde {h_{1}}},{\tilde {h_{2}}})\in W^{8}$.
* Compute cryptogram $e\leftarrow SEnc(k,s,1024,M)$.
* Encode the ciphertext: $\psi \ \leftarrow CEncode(L_{B}(P),s,u_{1},u_{2},v,e)$.
* Return $\psi \$.
Before starting off the symmetric encryption process, the input message $M\in B^{\ast }$ is divided into blocks $M_{1},...,M_{t}$, where each of the block, possibly except the last one, is of 1024 bytes. Each block is encrypted by the stream cipher. For each encrypted block $E_{i}$ 16-byte message authentication code is computed. We get the cryptogram
$e=E_{1}||C_{1}||...||E_{t}||C_{t}$
$L(e)=L(M)+16\left\lceil L(M)/m\right\rceil$
Note that if $L(M)=0$, then $L(e)=0$.
Algorithm. ACE asymmetric encryption process. Input: $(k,s,M,m)\in W^{8}\times W^{4}\times Z\times B^{\ast }$ $m>0$ Output: $e\in B^{l}$, $l=L(M)+16\left\lceil L(N)/m\right\rceil$.
* If $M=\lambda _{B}$, then return $\lambda _{B}$.
* Initialize a pseudo-random generator state:$genState\leftarrow InitGen(k,s)\in GenState$
* Generate the key $k_{AXU}AXUHash$: $(k_{AXU},genState)\leftarrow GenWords((5L_{b}(\left\lceil m/64\right\rceil )+24),genState).$.
* $e\leftarrow \lambda _{B},i\leftarrow 0$.
* While $i<L(M)$, do the following:
** $r\leftarrow min(L(M)-i,m)$.
** Generate mask values for the encryption and MAC:
*** $(mask_{m},genState)\leftarrow GenWords(4,genState)$.
*** $(mask_{e},genState)\leftarrow GenWords(r,genState)$.
** Encrypt the plaintext: $enc\leftarrow {\BiglM{\Bigr ]}_{i}^{i+r}\oplus mask_{e}$.
** Generate the message authentication code:
*** If $i+r=L(M)$, then $lastBlock\leftarrow 1$; else $lastBlock\leftarrow 0$.
*** $mac\leftarrow AXUHash(k_{AXU},lastBlock,enc)\in W^{4}$.
** Update the ciphertext: $e\leftarrow e||enc||I_{W^{\ast }}^{B^{\ast }}(mac\oplus mask_{m})$.
** $i\leftarrow i+r$.
* Return $e$.

### Decryption process

Algorithm. ACE decryption process. Input: public key $(P,q,g_{1},g_{2},c,d,h_{1},h_{2},k_{1},k_{2})$ and corresponding private key $(w,x,y,z_{1},z_{2})$, byt e string $\psi \in B^{\ast }$. Output: Decrypted message $M\in B^{\ast }\cup {Reject}$.
* Decrypt the ciphertext:
** If $L(\psi )<3L_{B}(P)+16$, then return $Reject$.
** Compute: $(s,u_{1},u_{2},v,e)\leftarrow CDecode(L_{B}(P),\psi )\in W^{4}\times Z\times Z\times Z\times B^{\ast }$; note that $0\leq u_{1},u_{2},v<256^{l}$, where $l=L_{B}(P)$.
* Verify the ciphertext preamble:
** If $u_{1}\geq P$ or $u_{2}\geq P$ or $v\geq P$, then return $Reject$.
** If $u_{1}^{q}\neq 1remP$, then return $Reject$.
** $reject\leftarrow 0$.
** If $u_{2}\neq u_{1}^{w}remP$, then $reject\leftarrow 1$.
** Compute $\alpha \leftarrow UOWHash^{\prime }(k_{1},L_{B}(P),s,u_{1},u_{2})\in Z$; note that $0\leq \alpha \leq 2^{160}$.
** If $v\neq u_{1}^{x+{\alpha }y}remP$, then $reject\leftarrow 1$.
** If $reject=1$, then return $Reject$.
* Compute the key for the symmetric decryption operation:
** ${\tilde {h_{1}}}\leftarrow u_{1}^{z_{1}}remP$, ${\tilde {h_{2}}}\leftarrow u_{1}^{z_{2}}remP$.
** Compute $k\leftarrow ESHash(k_{2},L_{B}(P),s,u_{1},{\tilde {h_{1}}},{\tilde {h_{2}}})\in W^{8}$.
* Compute $M\leftarrow SDec(k,s,1024,e)$;note that $SDec$ can return $Reject$.
* Return $M$.
Algorithm. Decryption operation $SDec$. Input: $(k,s,m,e)\in W^{8}\times W^{4}\times Z\times B^{\ast }$ $m>0$ Output: Decrypted message $M\in B^{\ast }\cup {Reject}$.
* If $e=\lambda _{B}$, then return $\lambda _{B}$.
* Initialize a pseudo-random generator state: $genState\leftarrow InitGen(k,s)\in GenState$
* Generate the key $k_{AXU}AXUHash$: $(k_{AXU},genState^{\prime })\leftarrow GenWords((5L_{b}(\left\lceil m/64\right\rceil )+24),genState).$.
* $M\leftarrow \lambda _{B},i\leftarrow 0$.
* While $i<L(e)$, do the following:
** $r\leftarrow min(L(e)-i,m+16)-16$.
** If $r\leq 0$, then return $Reject$.
** Generate mask values for the encryption and MAC:
*** $(mask_{m},genState)\leftarrow GenWords(4,genState)$.
*** $(mask_{e},genState)\leftarrow GenWords(r,genState)$.
** Verify the message authentication code:
*** If $i+r+16=L(M)$, then $lastblock\leftarrow 1$; else $lastblock\leftarrow 0$.
*** $mac\leftarrow AXUHash(k_{AXU},lastBlock,{\Bigle{\Bigr ]}_{i}^{i+r})\in W^{4}$.
*** If ${\Bigle{\Big ]}r_{i+r}^{i+r+16}\neq I_{W^{\ast }}^{B^{\ast }}(mac\oplus mask_{m})$, then return $Reject$.
** Update the plaintext: $M\leftarrow M||({\Bigle{\Bigr ]}_{i}^{i+r})\oplus mask_{e})$.
** $i\leftarrow i+r+16$.
* Return $M$.

## Signature Scheme

The signature scheme employs two key types: ACE Signature public key: $(N,h,x,e',k',s)$. ACE Signature private key: $(p,q,a)$. For the given size parameter $m$, such that $1024\leq m\leq 16384$, key components are defined the following way: $p$ — $\left\lfloor m/2\right\rfloor$-bit prime number with $(p-1)/2$ — is also a prime number. $q$ — $\left\lfloor m/2\right\rfloor$-bit prime number with $(q-1)/2$ — is also a prime number. $N$ — $N=pq$and has either $m$ or $m-1$ бит. $h,x$ — elements $\left\{1,...,N-1\right\}$ (quadratic residues modulo $N$). $e'$ — 161-bit prime number. $a$ — element $\left\{0,...,(p-1)(q-1)/4-1\right\}$ $k'$ — elements $B^{184}$. $s$ — elements $B^{32}$.

### Key Generation

Algorithm. Key generation for the ACE public-key signature scheme. Input: size parameter $m$, such that $1024\leq m\leq 16384$. Output: public/private key pair.
* Generate random prime numbers$p,q$, such that $(p-1)/2$ and $(q-1)/2$ — is also a prime number, and $2^{m_{1}-1}<p<2^{m_{1}}$, $2^{m_{2}-1}<q<2^{m_{2}}$, и $p\neq q$, where$m_{1}=\left\lfloor m/2\right\rfloor$ and $m_{1}=\left\lceil m/2\right\rceil$.
* Set $N\leftarrow pq$.
* Generate random prime number $e'$, где $2^{160}\leq e'\leq 2^{161}$.
* Generate random $h'\in \left\{1,...,N-1\right\}$, taking into account $gcd(h',N)=1$ and $gcd(h'\pm 1,N)=1$, and compute $h\leftarrow (h')^{-2}remN$.
* Generate random $a\in \left\{0,...,(p-1)(q-1)/4-1\right\}$and compute $x\leftarrow h^{a}remN$.
* Generate random byte strings $k'\in B^{184}$, and $s\in B^{32}$.
* Return public key/private key pair $((N,h,x,e',k',s),(p,q,a))$.

### Signature Representation

The signature in the ACE signature scheme has the form $(d,w,y,y',{\tilde {k}})$, where the components are defined the following way: $d$ — element $B^{64}$. $w$ — integer, such that $2^{160}\leq w\leq 2^{161}$. $y,y'$ — elements $\left\{1,...,N-1\right\}$. ${\tilde {k}}$ — element $B^{\ast }$;note that $L({\tilde {k}})=64+20L_{B}(\left\lceil (L(M)+8)/64\right\rceil )$, where $M$ — message being signed.
We need to introduce the $SEncode$ function, which maps a signature into its byte string representation, and the corresponding inverse function $SDecode$. For integer $l>0$, byte string $d\in B^{64}$, integers $0\leq w\leq 256^{21}$ and $0\leq y,y'<256^{l}$, and byte string ${\tilde {k}}\in B^{\ast }$,
$SEncode(l,d,w,y,y',{\tilde {k}}){\stackrel {\mathrm {def} }{=}}d||pad_{21}(I_{Z}^{B^{\ast }}(w))||pad_{l}(I_{Z}^{B^{\ast }}(y))||pad_{l}(I_{Z}^{B^{\ast }}(y'))||{\tilde {k}}\in B^{\ast }$
For integer $l>0$, byte string $\sigma \in B^{\ast }$, where $L(\sigma )\geq 2l+53$,
$CSecode(l,\sigma ){\stackrel {\mathrm {def} }{=}}({\Bigl\sigma {\Bigr ]}_{0}^{64},I_{B^{\ast }}^{Z}({\Bigl\sigma {\Bigr ]}_{64}^{85}),I_{B^{\ast }}^{Z}({\Bigl\sigma {\Bigr ]}_{85}^{85+l}),I_{B^{\ast }}^{Z}({\Bigl\sigma {\Bigr ]}_{85+l}^{85+2l}),{\Bigl\sigma {\Bigr ]}_{85+2l}^{L(\sigma )})\in B^{64}\times Z\times Z\times Z\times B^{\ast }$

### Signature Generation Process

Algorithm. ACE Signature Generation Process. Input: public key $(N,h,x,e',k',s)$ and corresponding private key $(p,q,a)$ and byte string $M\in B^{\ast }$, $0\leq L(M)\leq 2^{64}$. Output: byte string — digital signature $\sigma \in B^{\ast }$.
* Perform the following steps to hash the input data:
** Generate a hash key ${\tilde {k}}\in B^{20m+64}$ at random, such that $m=L_{b}(\left\lceil (L(M)+8)/64\right\rceil )$.
** Compute $m_{h}\leftarrow I_{W^{\ast }}^{Z}(UOWHash^{\prime \prime }({\tilde {k}},M))$.
* Select ${\tilde {y}}\in \left\{1,...,N-1\right\}$ at random, and compute $y'\leftarrow {\tilde {y}}^{2}remN$.
* Compute $x'\leftarrow (y')^{r'}h^{m_{h}}remN$.
* Generate a random prime $e$, $2^{160}\leq e\leq 2^{161}$, and its certificate of correctness $(w,d)$: $(e,w,d)\leftarrow GenCertPrime(s)$. Repeat this step until $e\neq e'$.
* Set $r\leftarrow UOWHash^{\prime \prime \prime }(k',L_{B}(N),x',{\tilde {k}})\in Z$; note that $0\leq r<2^{160}$.
* Compute $y\leftarrow h^{b}remN$, where $b\leftarrow e^{-1}(a-r)rem(p'q')$, and where $p'=(p-1)/2$ and $q'=(q-1)/2$.
* Encode the signature: $\sigma \leftarrow SEncode(L_{B}(N),d,w,y,y',{\tilde {k}})$.
* Return $\sigma$