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: thesis/chapters/04_constructions.tex
+4-3
Original file line number
Diff line number
Diff line change
@@ -22,8 +22,7 @@ \section{Goyal, Pandey, Sahai and Waters, 2006}
22
22
The GPSW scheme encrypts a message represented by a point of the bilinear pairing's target group $\mathbb{G}_T$.
23
23
It is a \gls{small-universe} construction.
24
24
25
-
The scheme is defined here exactly as it is implemented;
26
-
this differs from the original construction in the use of an asymmetric pairing ($e: \mathbb{G}_1\times\mathbb{G}_2\rightarrow\mathbb{G}_T$) instead of a symmetric pairing ($e: \mathbb{G}_1\times\mathbb{G}_1\rightarrow\mathbb{G}_T$).
25
+
The definition of the scheme in this chapter differs from the original construction in the use of an asymmetric pairing ($e: \mathbb{G}_1\times\mathbb{G}_2\rightarrow\mathbb{G}_T$) instead of a symmetric pairing ($e: \mathbb{G}_1\times\mathbb{G}_1\rightarrow\mathbb{G}_T$).
27
26
28
27
In the GPSW construction, the pairing is evaluated when the decryption algorithm encounters a leaf node (see below).
29
28
There, the curve point on one side comes from the ciphertext, and the point on the other side from the key.
@@ -39,7 +38,9 @@ \section{Goyal, Pandey, Sahai and Waters, 2006}
39
38
~\\
40
39
41
40
Let $\mathbb{G}_1$ and $\mathbb{G}_2$ be bilinear groups of prime order $q$. Let $P$ be a generator of $\mathbb{G}_1$ and $Q$ be a generator of $\mathbb{G}_2$. Let $e: \mathbb{G}_1\times\mathbb{G}_2\rightarrow\mathbb{G}_T$ be a bilinear map.
42
-
Note that $\mathbb{G}_1$ and $\mathbb{G}_2$ are written additively, but $\mathbb{G}_T$ is written using multiplicative notation.\\
41
+
42
+
Note that $\mathbb{G}_1$ and $\mathbb{G}_2$ are written additively, but $\mathbb{G}_T$ is written using multiplicative notation.
43
+
This corresponds to the interface of the bilinear pairing library used in this thesis.\\
Copy file name to clipboardExpand all lines: thesis/chapters/05_implementation.tex
+40-33
Original file line number
Diff line number
Diff line change
@@ -1,15 +1,17 @@
1
1
\chapter{Implementation}
2
2
3
-
This chapter describes how the schemes from chapter~\ref{chapter:constructions} were implemented on a lower level.
4
-
It shall make clear what challenges had to be overcome to run \acrlong{abe} on the sensor.
3
+
This chapter describes how the schemes from chapter~\ref{chapter:constructions} were implemented.
4
+
In addition to the structure of the implementation, it discusses the main challenges encountered and how they were overcome.
5
5
6
6
\section{Hardware}
7
7
8
-
The main goal of this project was to implement an \acrshort{abe} scheme on a constrained embedded ARM processor.
8
+
The main goal of this thesis was to implement an \acrshort{abe} scheme on a constrained embedded ARM processor.
9
9
More specifically, the chip used was a Nordic Semiconductor nRF52840 with a 64\,MHz Cortex M4 CPU, 256\,KB of RAM and 1\,MB of flash storage.
10
10
For the detailed specifications, see \cite{nordic_semiconductor_nrf52840_nodate}.
11
11
This SoC will be referred to simply as ``the SoC''.
12
12
13
+
Due to the constrained resources on the SoC, it does not run an operating system (i.e. ``bare-metal'' application).
14
+
13
15
For reference, the implementation was also tested on a standard laptop, referred to as ``the laptop''.
14
16
More specifically, this system has a 2.7\,GHz Intel i7-7500U CPU and 16\,GB of RAM.
15
17
It runs a Linux-based operating system.
@@ -18,31 +20,31 @@ \section{Programming language and libraries}
18
20
19
21
\subsection*{Rust}
20
22
21
-
Rust was chosen as programming language for this project.
23
+
Rust was chosen as programming language for a number of reasons.
22
24
First, it is a compiled language and thus incurs little overhead at runtime. Its speed is comparable to that of C/C++.
23
25
Second, it provides much stronger memory safety guarantees than other compiled languages (especially C/C++ where extreme care is required to avoid introducing exploitable vulnerabilities).
24
26
This is very attractive for security-critical components like an encryption library.
25
27
26
28
\subsection*{The \texttt{rabe-bn} library}
27
29
28
-
A Rust-only implementation of elliptic curves and a pairing is provided by the open-source library \texttt{rabe-bn}~\cite{bowe_rabe-bn_nodate}, a derivative of the \texttt{bn} library by Zcash~\cite{bowe_bn_2016}.
30
+
A Rust-only implementation of elliptic curves and a bilinear pairing is provided by the open-source library \texttt{rabe-bn}~\cite{bowe_rabe-bn_nodate}, a derivative of the \texttt{bn} library by Zcash~\cite{bowe_bn_2016}.
29
31
It implements a concrete pairing on 256-bit \emph{BN curves}.
30
32
BN curves are a family of pairing-friendly elliptic curves proposed by Barreto and Naehrig \cite{barreto_pairing-friendly_2006}.
31
33
32
-
The 256-bit modulus of the BN curve used in \texttt{rabe-bn} was originally believed to provide a security level of 128 bits~\cite{ben-sasson_succinct_2013}.
34
+
The 256-bit modulus of the BN curve used in \texttt{rabe-bn} was originally designed to provide a security level of 128 bits~\cite{ben-sasson_succinct_2013}.
33
35
Due to the discovery of better attacks on the underlying cryptographic assumptions, the estimate for the security level has been revised down to 100 bits~\cite{yonezawa_pairing-friendly_2019}.
34
36
35
37
The library provides four structs: \texttt{G1}, \texttt{G2} and \texttt{Gt}, elements of the groups $\mathbb{G}_1$, $\mathbb{G}_2$ and $\mathbb{G}_T$, respectively.
36
38
These groups all have the same order $r$.
37
39
\texttt{Fr} represents an element of the field $\mathbb{F}_r$.
38
40
39
-
For the elliptic curve groups (structs \texttt{G1} and \texttt{G2}), additive notation is used and the \texttt{*} operator is overloaded.
41
+
For the elliptic curve groups (structs \texttt{G1} and \texttt{G2}), additive notation is used and the \texttt{+} and \texttt{*} operators are overloaded.
40
42
This means that point-scalar multiplication can be simply written in Rust code as \verb$group_element * scalar$.
41
43
The target group (struct \texttt{Gt}) uses multiplicative notation.
42
44
For this reason, the description of the schemes in chapter~\ref{chapter:constructions} has also been adapted to use compatible notation.
43
45
44
46
\subsection*{nRF52840 HAL crate}
45
-
For easier access to the peripherals of the SoC, the \acrfull{hal} \gls{crate} \texttt{nrf52840-hal}~\cite{noauthor_nrf52840-hal_nodate} was also used.
47
+
For easier access to the peripherals of the SoC, the \acrfull{hal} \gls{crate} \texttt{nrf52840-hal}~\cite{noauthor_nrf52840-hal_nodate} was used.
46
48
It provides simplified access to the hardware \acrfull{rng} and hardware timers.
47
49
Access to the timers was not necessary for implementing the \acrshort{abe} library, but was used to measure the runtimes of the \acrshort{abe} algorithms.
The implementation of \texttt{rabe-bn} unfortunately relies on the standard library (mostly through the use of heap-allocated dynamic vectors, i.e. \texttt{std::vec::Vec}) and is thus not suited for bare-metal applications.
58
+
The implementation of \texttt{rabe-bn} unfortunately relies on the standard library (mostly through the use of heap-allocated dynamic vectors, i.e. \texttt{std::vec::Vec}) and is therefore not suited for bare-metal applications.
57
59
Rust provides the dependency-free and platform-agnostic \texttt{core} library as an alternative to the standard library.
58
60
This library does not depend on an operating system or dynamic memory allocation, and thus does not include heap-allocated data structures (like \texttt{std::vec::Vec}).
59
61
@@ -87,9 +89,9 @@ \section{Library API}
87
89
88
90
\texttt{setup()} requires the caller to create and pass a reference to two \texttt{FnvIndexMap}s to avoid passing these back on the stack.
89
91
90
-
\texttt{encrypt()} and \texttt{decrypt()} return a \texttt{Result} type because they can fail:
92
+
\texttt{encrypt()} and \texttt{decrypt()} return a \texttt{Result} type because they are not guaranteed to work:
93
+
Decryption might fail because the key is not satisfied by the attributes in the ciphertext.
91
94
With both, the underlying AES library might return an error, which is passed on to the caller of our library.
92
-
Decryption might also fail because the key is not satisfied by the attributes in the ciphertext.
93
95
94
96
\begin{lstlisting}[float=h!,caption={Exported function signatures of the GPSW scheme},label={lst:abe-signatures}]
95
97
pub fn setup<'attr, 'es>(
@@ -121,10 +123,10 @@ \section{Library API}
121
123
122
124
\section{Aspects common to both ABE schemes}
123
125
124
-
These aspects of the implementation are common to both ABE schemes and therefore outsourced into a separate \verb+abe_utils+ crate.
126
+
Some aspects of the implementation are common to both ABE schemes and therefore outsourced into a separate \verb+abe_utils+ crate.
125
127
126
128
\subsection{Representation of Access Trees}
127
-
The Rust type system is very well suited to represent the type of tree structures we need for \glspl{access-tree}.
129
+
The Rust type system is well suited to represent the type of tree structures we need for \glspl{access-tree}.
128
130
A simple implementation might look like the one in Listing~\ref{lst:access-tree-naive}.
129
131
130
132
\begin{lstlisting}[float=h,caption={Simple Implementation of \glspl{access-tree} (using the standard library)},label={lst:access-tree-naive}]
@@ -137,17 +139,20 @@ \subsection{Representation of Access Trees}
137
139
\end{lstlisting}
138
140
139
141
This, however, does not work when the \texttt{std::vec::Vec} is replaced by a stack-allocated \texttt{heapless::Vec}:
140
-
The \texttt{std::vec::Vec} is allocated on the heap and thus only a pointer to the vector needs to be stored in the \texttt{AccessTreeNode}.
142
+
The \texttt{std::vec::Vec} is allocated on the heap and thus only a pointer to the vector needs to be stored in the \texttt{Node}.
141
143
This pointer has constant size.
142
144
143
-
A \texttt{heapless::Vec} is not located on the heap, but directly inside the \texttt{AccessTreeNode}.
145
+
A \texttt{heapless::Vec} is not located on the heap, but directly inside the \texttt{Node}.
144
146
Even if there is a limit on the number of children a single inner node might have, there is no limit to the depth of the \gls{access-tree}.
145
-
Therefore, an\texttt{AccessTreeNode} has to be arbitrarily large because it might need to hold an arbitrary number of child nodes.
147
+
Therefore, a\texttt{Node} has to be arbitrarily large because it might need to hold an arbitrary number of child nodes.
146
148
147
149
Because of this, \glspl{access-tree} were implemented as a flat slice of nodes as in Listing~\ref{lst:access-tree-heapless}.
148
150
The vector of children doesn't hold references to the children themselves, but only their index within the vector of \gls{access-tree} nodes.
149
151
This again introduces an indirection (like the heap pointer in the simple implementation) and allows the enums to have constant size.
150
152
153
+
Listing~\ref{lst:access-tree-example} shows the \gls{access-tree} from Figure~\ref{fig:sample-access-tree} in this representation.
154
+
155
+
151
156
\begin{lstlisting}[float=h,caption={Refined implementation of \glspl{access-tree} (works without standard library)},label={lst:access-tree-heapless}]
152
157
type AccessTree<'a, 'b> = &'b [AccessNode<'a>];
153
158
enum AccessNode<'a> {
@@ -158,9 +163,7 @@ \subsection{Representation of Access Trees}
158
163
}
159
164
\end{lstlisting}
160
165
161
-
Listing~\ref{lst:access-tree-example} shows the \gls{access-tree} from Figure~\ref{fig:sample-access-tree} in this representation.
162
-
163
-
\begin{lstlisting}[float=h,caption={Sample \gls{access-tree} in the heapless Rust representation},label={lst:access-tree-example}]
166
+
\begin{lstlisting}[float=h,caption={\Gls{access-tree} from Figure~\ref{fig:sample-access-tree} in the heapless Rust representation},label={lst:access-tree-example}]
@@ -174,7 +177,11 @@ \subsection{Representation of Access Trees}
174
177
\subsection{Hybrid Encryption}
175
178
Both schemes encrypt a given plaintext using a hybrid approach:
176
179
Instead of encrypting the data with \acrshort{abe} directly, the plaintext is encrypted with AES and the key for AES is encrypted under \acrshort{abe}.
177
-
This results in faster encryption and decryption for long ciphertexts because AES is significantly faster than ABE.
180
+
181
+
The YCT scheme already uses AES according to its original definition in~\cite{yao_lightweight_2015}.
182
+
The GPSW scheme encrypts a message represented by an element of $\mathbb{G}_T$ in its original definition in~\cite{goyal_attribute-based_2006}.
183
+
However, encoding arbitrary messages as elements of $\mathbb{G}_T$ is cumbersome and slow.
184
+
Therefore, I also implemented hybrid encryption with the GPSW scheme.
178
185
179
186
% In our implementation, the \acrshort{abe} scheme generates a secret curve point (i.e. either \verb+rabe_bn::G1+ or \verb+rabe_bn::Gt+).
180
187
% From this, an AES key is derived and then used to encrypt the plaintext with AES-CCM.
@@ -239,7 +246,7 @@ \subsection{Random polynomials over $\mathbb{F}_r$}
239
246
It represents a polynomial over $\mathbb{F}_r$ as a vector of coefficients from $\mathbb{F}_r$.
240
247
Polynomial evaluation, random generation and Lagrange interpolation are implemented.
241
248
For reasons of simplicity, the latter is only implemented for $x=0$, i.e. the interpolation is immediately evaluated at $x=0$.
242
-
Evaluation at any other $x$ is not needed for the \acrshort{abe} implementation.
249
+
Evaluation at any other value is not needed for the \acrshort{abe} implementation.
243
250
244
251
\begin{lstlisting}[float=h,caption={Implementation of polynomials over $\mathbb{F}_r$},label={lst:polynomials}]
245
252
struct Polynomial(Vec<F, cons>);
@@ -264,14 +271,14 @@ \subsection{Random polynomials over $\mathbb{F}_r$}
264
271
265
272
\section{Implementation of the four \acrshort*{abe} algorithms}\label{sec:abe-algs-impl}
266
273
267
-
The implementation of the \acrshort{abe} algorithms Setup, Encrypt, KeyGen and Decrypt is directly carried over from chapter~\ref{chapter:constructions} for the most part.
274
+
The implementation of the \acrshort{abe} algorithms Setup, Encrypt, KeyGen and Decrypt is directly carried over from chapter~\ref{chapter:constructions}.
268
275
Further notable aspects are described here.
269
276
270
277
The general structure of the implementation is similar for both schemes.
271
278
This description will stick with the GPSW scheme unless there are notable differences.
272
279
273
280
\subsection{Setup}
274
-
See Listing~\ref{lst:struct-pubkey} for the structures holding the public and private parameters generated by Setup of GPSW.
281
+
Listing~\ref{lst:struct-pubkey} shows the structures holding the public and private parameters generated by Setup of GPSW.
275
282
Setup is implemented almost exactly as described in chapter~\ref{chapter:constructions}, except that generators of $\mathbb{G}_1$ and $\mathbb{G}_2$ are not fixed but chosen randomly.
276
283
277
284
\begin{lstlisting}[float=h,caption={Private and public system parameters structs for GPSW},label={lst:struct-pubkey}]
The GPSW scheme as described in chapter~\ref{chapter:constructions} encrypts a message encoded as an element of $\mathbb{G}_T$.
308
-
The hybrid encryption function therefore just samples a random element from \texttt{Gt}, encrypts it with GPSW and then encrypts the plaintext using AES with the key derived from the random \texttt{Gt}.
314
+
%The GPSW scheme as described in chapter~\ref{chapter:constructions} encrypts a message encoded as an element of $\mathbb{G}_T$.
315
+
%The hybrid encryption function therefore just samples a random element from \texttt{Gt}, encrypts it with GPSW and then encrypts the plaintext using AES with the key derived from the random \texttt{Gt}.
309
316
310
317
% \subsubsection{YCT}
311
-
The YCT scheme itself only generates a random curve point; it is not possible to specify which curve point should be used.
312
-
Practically, this makes little difference:
313
-
The curve point generated by YCT ($C'$ in the formal definition) is simply used as the symmetric key to encrypt the payload.
318
+
%The YCT scheme itself only generates a random curve point; it is not possible to specify which curve point should be used.
319
+
%Practically, this makes little difference:
320
+
%The curve point generated by YCT ($C'$ in the formal definition) is simply used as the symmetric key to encrypt the payload.
314
321
315
322
316
323
\subsection{KeyGen}
@@ -319,7 +326,7 @@ \subsection{KeyGen}
319
326
The actual decryption key is a set of secret shares, which are created whenever the key generation algorithm hits a leaf node.
320
327
% How exactly these are generated differs between the two schemes, but the general structure is the same.
321
328
322
-
To realize this, a recursive function \verb+decrypt_node()+ was implemented.
329
+
To realize this, a recursive function \verb+keygen_node()+ was implemented.
323
330
Listing~\ref{lst:keygen-node} shows its signature for the GPSW scheme.
324
331
325
332
\begin{lstlisting}[float=h,caption={Function signature of recursive key generation},label={lst:keygen-node}]
@@ -339,7 +346,7 @@ \subsection{KeyGen}
339
346
The function returns a list of secret shares created by the current node and its children.
340
347
These secret shares consist of an element of \texttt{G1} (the curve element) and a \texttt{u8}, which is the index of the leaf node that generated the secret share.
341
348
342
-
The public-facing \verb+keygen()+ function calls \verb+decrypt_node()+ on the root and combines the result with a reference to the \gls{access-tree} to form the actual decryption key.
349
+
The public-facing \verb+keygen()+ function calls \verb+keygen_node()+ on the root and combines the result with a reference to the \gls{access-tree} to form the actual decryption key.
343
350
See Listing~\ref{lst:struct-key} for the structure representing a decryption key in GPSW.
344
351
The decryption key for YCT only differs in the type of secret shares contained in the \texttt{FnvIndexMap} (\texttt{F} instead of \texttt{G2}).
345
352
@@ -361,15 +368,15 @@ \subsection{Decrypt}
361
368
) -> Option<Gt>;
362
369
\end{lstlisting}
363
370
364
-
The arguments \verb+tree_arr+ and \verb+tree_ptr+ are like in Listing~\ref{lst:keygen-node}.
371
+
The arguments \verb+tree_arr+ and \verb+tree_ptr+ are equivalent to those in Listing~\ref{lst:keygen-node}.
365
372
In \verb+secret_shares+, the secret shares corresponding to the leafs of the \gls{access-tree} are passed.
366
373
\verb+att_es+ contains the curve elements corresponding to the attributes associated with the ciphertext.
367
374
368
375
\verb+decrypt_node()+ returns an \verb+Option<Gt>+.
369
376
This is an optional type because decryption will fail if the \gls{access-tree} is not satisfied by the attributes associated with the ciphertext.
370
377
371
-
The public-facing\verb+decrypt()+ function receives both the combined ABE and symmetric ciphertext.
372
-
It calls \verb.decrypt_node. on the the root of the \gls{access-tree} to obtain the secret curve point.
378
+
The public \verb+decrypt()+ function receives combined ABE and symmetric ciphertext.
379
+
It calls \verb.decrypt_node(). on the the root of the \gls{access-tree} to obtain the secret curve point.
373
380
This is then run through \verb+kdf()+ to obtain the AES key.
374
381
The plaintext is decrypted in-place with AES-CCM and a reference to the (now successfully decrypted) data is returned.
0 commit comments