Skip to content

Commit dc25b01

Browse files
committed
Sandesh feedback chap5
1 parent 0612ac0 commit dc25b01

File tree

3 files changed

+44
-36
lines changed

3 files changed

+44
-36
lines changed

thesis/build/main.pdf

-95 Bytes
Binary file not shown.

thesis/chapters/04_constructions.tex

+4-3
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ \section{Goyal, Pandey, Sahai and Waters, 2006}
2222
The GPSW scheme encrypts a message represented by a point of the bilinear pairing's target group $\mathbb{G}_T$.
2323
It is a \gls{small-universe} construction.
2424

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$).
2726

2827
In the GPSW construction, the pairing is evaluated when the decryption algorithm encounters a leaf node (see below).
2928
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}
3938
~\\
4039

4140
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.\\
4344

4445
\noindent \emph{Setup}~\cite{goyal_attribute-based_2006}.
4546
The attribute universe is defined as $\text{U} = \{1, 2, \dots, n\}$ and is fixed.

thesis/chapters/05_implementation.tex

+40-33
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
\chapter{Implementation}
22

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.
55

66
\section{Hardware}
77

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.
99
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.
1010
For the detailed specifications, see \cite{nordic_semiconductor_nrf52840_nodate}.
1111
This SoC will be referred to simply as ``the SoC''.
1212

13+
Due to the constrained resources on the SoC, it does not run an operating system (i.e. ``bare-metal'' application).
14+
1315
For reference, the implementation was also tested on a standard laptop, referred to as ``the laptop''.
1416
More specifically, this system has a 2.7\,GHz Intel i7-7500U CPU and 16\,GB of RAM.
1517
It runs a Linux-based operating system.
@@ -18,31 +20,31 @@ \section{Programming language and libraries}
1820

1921
\subsection*{Rust}
2022

21-
Rust was chosen as programming language for this project.
23+
Rust was chosen as programming language for a number of reasons.
2224
First, it is a compiled language and thus incurs little overhead at runtime. Its speed is comparable to that of C/C++.
2325
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).
2426
This is very attractive for security-critical components like an encryption library.
2527

2628
\subsection*{The \texttt{rabe-bn} library}
2729

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}.
2931
It implements a concrete pairing on 256-bit \emph{BN curves}.
3032
BN curves are a family of pairing-friendly elliptic curves proposed by Barreto and Naehrig \cite{barreto_pairing-friendly_2006}.
3133

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}.
3335
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}.
3436

3537
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.
3638
These groups all have the same order $r$.
3739
\texttt{Fr} represents an element of the field $\mathbb{F}_r$.
3840

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.
4042
This means that point-scalar multiplication can be simply written in Rust code as \verb$group_element * scalar$.
4143
The target group (struct \texttt{Gt}) uses multiplicative notation.
4244
For this reason, the description of the schemes in chapter~\ref{chapter:constructions} has also been adapted to use compatible notation.
4345

4446
\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.
4648
It provides simplified access to the hardware \acrfull{rng} and hardware timers.
4749
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.
4850

@@ -53,7 +55,7 @@ \subsection*{\texttt{heapless} crate}
5355

5456
\section{Porting \texttt{rabe-bn} to the SoC}
5557

56-
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.
5759
Rust provides the dependency-free and platform-agnostic \texttt{core} library as an alternative to the standard library.
5860
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}).
5961

@@ -87,9 +89,9 @@ \section{Library API}
8789

8890
\texttt{setup()} requires the caller to create and pass a reference to two \texttt{FnvIndexMap}s to avoid passing these back on the stack.
8991

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.
9194
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.
9395

9496
\begin{lstlisting}[float=h!,caption={Exported function signatures of the GPSW scheme},label={lst:abe-signatures}]
9597
pub fn setup<'attr, 'es>(
@@ -121,10 +123,10 @@ \section{Library API}
121123

122124
\section{Aspects common to both ABE schemes}
123125

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.
125127

126128
\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}.
128130
A simple implementation might look like the one in Listing~\ref{lst:access-tree-naive}.
129131

130132
\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}
137139
\end{lstlisting}
138140

139141
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}.
141143
This pointer has constant size.
142144

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}.
144146
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.
146148

147149
Because of this, \glspl{access-tree} were implemented as a flat slice of nodes as in Listing~\ref{lst:access-tree-heapless}.
148150
The vector of children doesn't hold references to the children themselves, but only their index within the vector of \gls{access-tree} nodes.
149151
This again introduces an indirection (like the heap pointer in the simple implementation) and allows the enums to have constant size.
150152

153+
Listing~\ref{lst:access-tree-example} shows the \gls{access-tree} from Figure~\ref{fig:sample-access-tree} in this representation.
154+
155+
151156
\begin{lstlisting}[float=h,caption={Refined implementation of \glspl{access-tree} (works without standard library)},label={lst:access-tree-heapless}]
152157
type AccessTree<'a, 'b> = &'b [AccessNode<'a>];
153158
enum AccessNode<'a> {
@@ -158,9 +163,7 @@ \subsection{Representation of Access Trees}
158163
}
159164
\end{lstlisting}
160165

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}]
164167
let access_tree: AccessTree = &[
165168
AccessNode::Node(2, Vec::from_slice(&[1, 2, 3]).unwrap()),
166169
AccessNode::Leaf("A"),
@@ -174,7 +177,11 @@ \subsection{Representation of Access Trees}
174177
\subsection{Hybrid Encryption}
175178
Both schemes encrypt a given plaintext using a hybrid approach:
176179
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.
178185

179186
% In our implementation, the \acrshort{abe} scheme generates a secret curve point (i.e. either \verb+rabe_bn::G1+ or \verb+rabe_bn::Gt+).
180187
% 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$}
239246
It represents a polynomial over $\mathbb{F}_r$ as a vector of coefficients from $\mathbb{F}_r$.
240247
Polynomial evaluation, random generation and Lagrange interpolation are implemented.
241248
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.
243250

244251
\begin{lstlisting}[float=h,caption={Implementation of polynomials over $\mathbb{F}_r$},label={lst:polynomials}]
245252
struct Polynomial(Vec<F, cons>);
@@ -264,14 +271,14 @@ \subsection{Random polynomials over $\mathbb{F}_r$}
264271

265272
\section{Implementation of the four \acrshort*{abe} algorithms}\label{sec:abe-algs-impl}
266273

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}.
268275
Further notable aspects are described here.
269276

270277
The general structure of the implementation is similar for both schemes.
271278
This description will stick with the GPSW scheme unless there are notable differences.
272279

273280
\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.
275282
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.
276283

277284
\begin{lstlisting}[float=h,caption={Private and public system parameters structs for GPSW},label={lst:struct-pubkey}]
@@ -304,13 +311,13 @@ \subsection{Encrypt}
304311
pub struct GpswAbeCiphertext<'attr, 'data>(GpswAbeGroupCiphertext<'attr>, kem::Ciphertext<'data>);
305312
\end{lstlisting}
306313
% \subsubsection{GPSW}
307-
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}.
309316

310317
% \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.
314321

315322

316323
\subsection{KeyGen}
@@ -319,7 +326,7 @@ \subsection{KeyGen}
319326
The actual decryption key is a set of secret shares, which are created whenever the key generation algorithm hits a leaf node.
320327
% How exactly these are generated differs between the two schemes, but the general structure is the same.
321328

322-
To realize this, a recursive function \verb+decrypt_node()+ was implemented.
329+
To realize this, a recursive function \verb+keygen_node()+ was implemented.
323330
Listing~\ref{lst:keygen-node} shows its signature for the GPSW scheme.
324331

325332
\begin{lstlisting}[float=h,caption={Function signature of recursive key generation},label={lst:keygen-node}]
@@ -339,7 +346,7 @@ \subsection{KeyGen}
339346
The function returns a list of secret shares created by the current node and its children.
340347
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.
341348

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.
343350
See Listing~\ref{lst:struct-key} for the structure representing a decryption key in GPSW.
344351
The decryption key for YCT only differs in the type of secret shares contained in the \texttt{FnvIndexMap} (\texttt{F} instead of \texttt{G2}).
345352

@@ -361,15 +368,15 @@ \subsection{Decrypt}
361368
) -> Option<Gt>;
362369
\end{lstlisting}
363370

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}.
365372
In \verb+secret_shares+, the secret shares corresponding to the leafs of the \gls{access-tree} are passed.
366373
\verb+att_es+ contains the curve elements corresponding to the attributes associated with the ciphertext.
367374

368375
\verb+decrypt_node()+ returns an \verb+Option<Gt>+.
369376
This is an optional type because decryption will fail if the \gls{access-tree} is not satisfied by the attributes associated with the ciphertext.
370377

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.
373380
This is then run through \verb+kdf()+ to obtain the AES key.
374381
The plaintext is decrypted in-place with AES-CCM and a reference to the (now successfully decrypted) data is returned.
375382

0 commit comments

Comments
 (0)