You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: getting-started/implement-elgamal.md
+69-13Lines changed: 69 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,28 +5,84 @@ tpc: true
5
5
---
6
6
7
7
In this document, we show to to use the Cryptimeleon Craco and Cryptimeleon Math library to implement an example scheme, the Elgamal encryption scheme [Elg85].
8
-
Compared to the other tutorials, we also aim to showcase a possible class structure that could be used as well as introduce the library's intermediate serialization framework to you along the way.
8
+
Compared to the other tutorials, we also aim to showcase the class structure for a full implementatio (as opposed to "just" a toy implementation).
9
9
10
-
First, lets review how ElGamal encryption works:
10
+
First, let's review how ElGamal encryption works:
11
11
12
12
Let \\(G\\) be a cyclic group of prime order \\(q\\).
13
13
14
-
**\\(\operatorname{KeyGen}\\)**:
14
+
**\\(\\operatorname{Setup}\\)**:
15
+
The public parameters for this scheme consist of (1) a cyclic group \\(G\\) of prime order \\(p\\), and (2) a random generator \\(g\\leftarrow G\\setminus\\{1\\}\\).
15
16
16
-
1. Choose integer \\(a\\) from \\(\\{0, 1, \dots, q-1\\}\\) uniformly at random.
17
-
2. Choose generator \\(g \\leftarrow G\\) uniformly at random.
18
-
3. The secret key is \\(sk = (G, g, a, h=g^a)\\) and the public key is \\(pk = (G, g, h)\\).
17
+
**\\(\\operatorname{KeyGen}\\)**:
19
18
20
-
**\\(\operatorname{Encryption}(pk, m)\\)**:
19
+
1. Choose a random secret key \\(sk \\leftarrow \\{0, 1, \dots, p-1\\}\\).
20
+
2. Compute the corresponding public key \\(pk = g^{sk}\\)
21
21
22
-
1. Choose \\(r\\) from \\(\\{0, 1, \dots, q-1\\}\\) uniformly at random.
23
-
2. The ciphertext is \\(c = (c_1, c_2) = (g^r, m \cdot h^r)\\).
To follow along, check out [https://github.com/cryptimeleon/java-demo](our Java demo project) and create a new class `ElGamalEncryptionScheme` as outlined above.
81
+
82
+
## Implementing the Scheme fully with data classes and interfaces
83
+
Even though the implementation above can be considered complete, you may want to properly encapsulate the artifacts (keys, ciphertexts, etc.) into corresponding data classes.
84
+
For a simple construction such as ElGamal, this is a somewhat useless exercise. However, for larger constructions with more complicated key structures, this step makes a lot of sense.
85
+
For this reason, we showcase this step here.
30
86
31
87
We assume you have set up a new project in your IDE already, and added Craco as a dependency.
32
88
Craco already includes the math library so you don't need to add that explicitly.
@@ -289,4 +345,4 @@ Using `Objects.equals()` and `Objects.hash()` is the easiest way to do this. The
289
345
290
346
# References
291
347
292
-
[Elg85] T. Elgamal, "A public key cryptosystem and a signature scheme based on discrete logarithms," in *IEEE Transactions on Information Theory*, vol. 31, no. 4, pp. 469-472, July 1985.
348
+
[Elg85] T. Elgamal, "A public key cryptosystem and a signature scheme based on discrete logarithms," in *IEEE Transactions on Information Theory*, vol. 31, no. 4, pp. 469-472, July 1985.
0 commit comments