-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy paththesis.tex
2149 lines (1769 loc) · 145 KB
/
thesis.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
% fithesis2 with modifications used, please use local fithesis.cls file, not system-wide installed.
\documentclass[11pt,oneside,final]{fithesis2}
% \documentclass[oneside,final]{fithesis2}
% \usepackage[resetfonts]{cmap}
\usepackage{lmodern}
\usepackage[english]{babel}
\usepackage[utf8x]{inputenc}
%\usepackage[IL2]{fontenc}
\usepackage[T1]{fontenc}
\usepackage{hyperref}
\usepackage{graphicx}
\usepackage{color}
\usepackage{afterpage}
\usepackage{calc}
\usepackage{subfig}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{amsmath}
\usepackage{enumitem}
%\usepackage{titlesec}
% floating for figures H
\usepackage{float}
\restylefloat{figure}
% \usepackage{sistyle}
% some symbols in package
% \usepackage{textcomp}
% \usepackage{inputenx}
% text super/sub scripts
\usepackage{fixltx2e}
% % algpseudocode was not installed by default; http://ctan.org/pkg/algorithmicx
% % http://tex.stackexchange.com/questions/38978/how-can-i-manually-install-a-latex-package-debian-ubuntu-linux
% % http://ftp.cstug.cz/pub/tex/CTAN/macros/latex/contrib/algorithmicx/algorithmicx.pdf
\usepackage{algpseudocode}
% \usepackage[options]{algorithm2e}
\usepackage{algorithm}
%\usepackage{algorithmic}
% nicefrac
\usepackage{units}
\def\R{\mbox{\sffamily\bfseries R}}
\DeclareGraphicsExtensions{.pdf,.png,.jpg,.gif}
\thesislang{en}
\thesistitle{White-box attack resistant cryptography}
%\thesistitle{Cryptography in an untrusted environment}
\thesissubtitle{Diploma thesis}
\thesisstudent{Dušan Klinec}
\thesiswoman{false}
\thesisfaculty{fi}
% \thesiswords{slov: 628}
% \thesisstudentuco{UČO: 325219}
\thesisyear{2013}
\thesisadvisor{RNDr.\,Petr Švenda,\,Ph.D.}
\newcommand{\reci}[1]{\frac{1}{#1}}
\newcommand{\hypot}[2]{\sqrt{#1^2+#2^2}}
\newcommand{\cbrt}[1]{\sqrt[3]{#1}}
% protocols & commands
\newcommand{\comproto}[1]{\emph{#1}}
\newcommand{\protocommand}[1]{\emph{\uppercase{#1}}}
\newcommand{\protoparam}[1]{\emph{#1}}
%\underset{x}{\operatorname{argmin}}
% some math & modulo
\newtheorem{mydef}{Definition}
\newtheorem{myprop}{Proposition}
\newtheorem{mytheorem}{Theorem}
\makeatletter
\def\imod#1{\allowbreak\mkern10mu({\operator@font mod}\,\,#1)}
\makeatother
\newcommand{\gfe}{\ensuremath{\text{GF}\left(2^8\right)}}
\newcommand{\gf}{\ensuremath{\text{GF}\left(2\right)}}
% bibtex
% Czech bibtex citation norms
% http://www.abclinuxu.cz/blog/Drobnosti/2007/3/csplainnat.bst-nbsp-cesky-styl-pro-bibtex-dle-iso-nbsp-690
% svn://kraken.pedf.cuni.cz/csplainnat/
% http://www.fit.vutbr.cz/~martinek/latex/czechiso.html.cs.iso-8859-2
% http://repo.or.cz/w/csplainnat.git
% http://www.root.cz/clanky/odborny-text-v-lyx-matematika-a-bibliografie/nazory/418552/
\usepackage{url}
\usepackage[numbers]{natbib}
\bibliographystyle{unsrtnat}
%\bibliographystyle{plain}
\usepackage{fancyhdr}
\pagestyle{plain}
% multi-row
\usepackage{multirow}
\usepackage{color, colortbl}
\definecolor{Gray}{gray}{0.85}
\newcommand{\clg}{\cellcolor{Gray}}
\newcommand{\eal}{\emph{et~al.}}
% \fancyhead[LE,RO]{\slshape \rightmark}
% \fancyhead[LO,RE]{\slshape \leftmark}
% \fancyfoot[C]{\thepage}
\hyphenation{how-to}
\begin{document}
\newenvironment{atribut_description}
{\begin{description}
\renewcommand{\makelabel}[1]{\texttt{\hspace{6pt}##1 $-$}}%
\setlength{\itemsep}{1pt}
\setlength{\parskip}{0pt}
\setlength{\parsep}{0pt}}
{\end{description}}
\renewcommand{\tiny}{\fontsize{7.7}{9.7}\selectfont}
\FrontMatter
\ThesisTitlePage
% BEGINNING OF THESIS ASSIGNEMENT
% % \begin{alwayssingle}
% % \afterpage{
% % \clearpage
% % \begin{figure*}[ht!]
% \begin{center}
% \leavevmode
% \scalebox{1.00}{\includegraphics[trim=100 100 100 40]{bpThesisAssignement_corr.pdf}}
% \end{center}
% % \caption{Pôdorys študovne so vzdialenosťami objektov \cite{img_skm_studyroom}}
% % \label{fig:studyroom_distances}
% % \end{figure*}
% % }
% % \afterpage{\clearpage}
% % \end{alwayssingle}
% END OF THESIS ASSIGNEMENT
\begin{ThesisDeclaration}
\DeclarationText
\AdvisorName
\end{ThesisDeclaration}
\begin{ThesisThanks}
I would like to express my gratitude to my thesis advisor, RNDr. Petr Švenda, Ph.D., for his guidance, helpfull ideas, patience and
non-negligible time invested in consultations what made this thesis possible. I am also grateful to people form
Laboratory of Security and Applied Cryptography of the Faculty of Informatics of Masaryk University, for their valuable comments,
especially to RNDr. Jiří Kůr.
I would like to thank my parents for their constant support and to my girlfriend, Martina Bošková, for her encouragement and inspiration.
I am also thankfull to all my close friends for their advices and support.
% [TODO] Thanks here
\end{ThesisThanks}
\begin{ThesisAbstract}
This thesis is focused on a study of security issues related to an execution of cryptographic algorithms in an untrusted environment.
It mainly studies whitebox cryptography methods of transforming algorithms in such a way they resist attacks like key-extraction and inverting in some extent.
Particularly it examines whitebox transformations of AES cipher and attacks on these transformations. Transformations construction and implementation is described.
In the thesis was discovered the known attack works also on AES transformation using dual ciphers by Karroumi \citep{Karroumi:2010:PWA:2041036.2041060}
that was supposed to resist the attack.
The new improvements for increasing a resistance of transformations to known attacks were proposed.
\end{ThesisAbstract}
% BEGINING OF ENGLISH ABSTRACT
% \begin{alwayssingle}
% \chapter*{\AbstractTitleen}
% \par\vfil\null
% \end{alwayssingle}
% \newpage
% END OF ENGLISH ABSTRACT
\begin{ThesisKeyWords}
whitebox attack resistant cryptography, AES, dual ciphers, whitebox cipher implementation
\end{ThesisKeyWords}
\MainMatter
\renewcommand{\contentsname}{Table of contents}
\tableofcontents
% with this - there are no decorative lines in page header
%\pagestyle{plain}
\chapter{Introduction}
In the last few decades we have been witnessing a development in a field of outsourced computations and storage.
The rising prevalence of this computing model slightly changes the classical attacker model
that cryptography used to dealt with, what gave rise to a \emph{mobile cryptography}.
The classical goals the cryptography addresses~are confidentiality, data integrity, authentication~and non-repundation~\citep{Menezes:1996:HAC:548089}.
From the data confidentiality perspective, the typical scenario is two remote parties, Alice and Bob, want to communicate via untrusted channel, while the
computations on both sides are considered as trusted. A potential attacker resides in a communication link.
A bunch of cryptography primitives addressing security issues in this scenario
was invented, analyzed and widely used, e.g. symmetric and asymmetric cryptosystems, digital signatures, authentication protocols, etc...
But with the expansion of outsourced computations and storage we are getting to a situation that Alice does not trust even to Bob, but wants
to use Bob's resources for her own purpose. Such outsourcing rises concerns about the loss of privacy of private data what poses the potential
barrier in adopting cloud services widely. To ensure the privacy, data is encrypted. The major problem with this model
is that in order to evaluate a function over data, e.g. searching in an encrypted database, data has to be decrypted first. This poses an another additional
overhead. The \emph{fully homomorphic encryption} provides a solution for these issues.
Another major part of use cases is the protecting a private function computed in an untrusted environment. A typical example
of the function to be protected is the license code verification embedded in a software or it is a software that provides access
to some protected material, e.g. copyrighted content. The major goal is to protect these
functions from analysis, tampering or extraction of a cryptographic material. Software protection techniques like an \emph{obfuscation}
addressing these issues are used in practice. This thesis is devoted to a \emph{whitebox cryptography}, the field of
cryptography that studies the level of security of cryptographic algorithms executed in an untrusted environment.
This thesis studies in particular a transformation of the AES~\citep{2002-daemen} implementation in such a way that they provide some
level of security when executed in an untrusted environment. This transformed implementation has embedded a symmetric key inside
and the main goal of the transformation is to resist practical attacks attempting its extraction. The thesis covers an introduction
to whitebox cryptography, describes a first such transformation published together with cryptanalysis. It also analyzes a new
proposed transformation that should resist a key extraction. The thesis states also a proof that this scheme can be broken
using an already existing attack. In the end, some improvements are suggested.
Chapter 2 describes mobile cryptography concepts and state of the art in this field mainly with focus on the obfuscation and the homomorphic encryption.
In chapter 3 the whitebox cryptography is introduced, followed by an explanation of basic building blocks used for transformations. The first proposed scheme
by Chow~\eal~\citep{Chow02white-boxcryptography} is described in detail together with the following cryptanalysis by Billet~\eal~\citep{Billet:2004:CWB:2080787.2080809}.
Chapter 4 covers a new whitebox scheme for AES by Karroumi~\citep{Karroumi:2010:PWA:2041036.2041060} in a detail.
A description of the schemes and the attack implementation follow.
In chapter 5, improvements for whitebox schemes are proposed with their analysis. The last two chapters are devoted to possible further
research directions and conclusion.
I declare this thesis is my own work, but I consulted the problems and proposed solutions together with people from the
Laboratory of Security and Applied Cryptography of the
Faculty of Informatics of Masaryk University, and from this reason is a personal pronoun ``we'' used instead of ``I''.
\chapter{Area overview}\label{sec:theory}
\section{Overview}
Computing in an untrusted environment is closely related to the notion of \emph{mobile cryptography}~\citep{mobile_cryptography} which was established two decades ago.
It analyzes security problems raised by a concept of mobility of an executable code. The executable code that acts autonomously on behalf a user in collecting
and processing information is denoted as a \emph{mobile agent}. Mobile cryptography mainly studies two security threats:
\begin{enumerate}
\item protection of the host from malicious mobile code
\item protection of mobile code from the malicious host
\end{enumerate}
The former threat can be mitigated to an acceptable level with countermeasures like sandboxing, virtualization and code signing~\citep{Menezes:1996:HAC:548089},
what is widely adopted by current anti-virus protection software and operating systems.
The latter is much difficult
to address. Existing techniques provide protection to some extent, making tampering the code on malicious host difficult for ordinary attacker,
but there are no guarantees of protection against very strong and determined attacker with enough resources to invest in the attack.
In order to make tampering of the software very difficult, specialized, tamper-resistant hardware is often used.
It is designed with security concerns in mind so that very advanced techniques and a large amount of resources is needed in order to attack such device,
making it practically impossible for an ordinary attacker. For an example hardware security modules used by banks or certification
authorities protecting their secret cryptographic material. Another example is a cryptographic smart card, widely used in use
cases with high security requirements.
However, the tamper-resistant hardware is not suitable for many applications, due to its cost and physical nature, e.g. need to be distributed somehow,
can be lost, forgotten, unintentionally damaged, etc...
Then it is preferable to use software-based protection techniques for their low cost and flexibility. The downside of this approach is a limited strength.
\section{Obfuscation}\label{sec:obfuscation}
An \emph{obfuscation} is another technique addressing the same problem, protecting a software implementation.
Roughly speaking, the major principle is the transformation of the code to a form, that is very difficult
to analyze and eventually to modify. The potential attacker should not be able to gain any extra knowledge\footnote{besides input/output behavior}
from the running program, in the ideal case, while the original functionality of the program is preserved.
The program obfuscation received an attention when Barak~\eal\ formalized the notion of obfuscation
in~\citep{Barak:2012:POP:2160158.2160159}, providing significant theoretical result
that it is impossible to create a generic obfuscator. They did so by showing the existence of a (contrived) family of functions that
are unobfuscatable, i.e. the family of functions always leaking some information. They used assumption of existence of one-way functions.
On the other hand,
later was published a first positive result~\citep{Lynn04positiveresults} claiming it is possible to construct some provably
secure obfuscators for \emph{point functions}. Point function accepts a single input string and reject all other inputs.
It was used to obfuscate complex access control functionalities.
The first positive obfuscation result for a traditional cryptographic functionality (that is significantly more complicated that point functions)
was presented by Hohenberger~\eal~\citep{Hohenberger:2007:SOR:1760749.1760767}.
They used slightly modified definition of obfuscation in order to construct a secure obfuscator for
re-encryption\footnote{This functionality takes a ciphertext for message $m$ encrypted under Alice’s public key and transforms it into a
ciphertext for the same message $m$ under Bob’s public key. \citep{Hohenberger:2007:SOR:1760749.1760767}}.
The question whether there exist a family of potentially interesting functions for which exist provably secure obfuscators and how to construct them,
is a subject of a further research. But the work of Goldwasser~\eal~\citep{Goldwasser:2005:IOA:1097112.1097490} suggest it is unlikely.
Namely they state that there exist many natural classes of functions that cannot be obfuscated w.r.t. auxiliary input.
An \emph{approximate obfuscation} defined by Barak~\eal~\citep{Barak:2012:POP:2160158.2160159} is a relaxation of the functionality
requirement of the obfuscated program. They presented impossibility result in the case when an obfuscated program deviates from the original
program only with a negligible probability and allows this event to depend only on the coin tosses of the obfuscator. Recently
Bitansky~\eal~\citep{journals/iacr/BitanskyP12} improved this impossibility result by hardening the requirements.
They showed there exist families of robust unobfuscatable functions for which even approximate obfuscation is impossible.
According to their definition, obfuscated program is only required to agree with the original one with probability slightly more than $0.5$
on a uniformly sampled input, what was the open problem till then.
In a practice, the obfuscation is widely used as a software protection technique that provides some level of protection from attackers, but
it often lacks some proof of security. In major cases it is collection of techniques that makes the static and/or run-time analysis of a program
significantly more difficult, but it does not rule out the probability of an successful attack by a strong and determined attacker.
A rich collection of state of the art obfuscation techniques, protecting from static and run-time analysis can be found in the dissertation thesis
of J. Cappaert \citep{codeObfuscation}.
The concept of obfuscation is closely related to \emph{computing with a private function}.
\section{Computing with encrypted data}
As is mentioned in the introduction, the fundamental question whether data can be manipulated without being
decrypted has been attracting attention for a long time.
\subsection{Secure multiparty communication}
The first positive results on this question make use of \emph{interaction}. The concept of a \emph{secure multiparty communication} was
introduced by Yao~\citep{Yao:1982:PSC:1398511.1382751} in 1982. Roughly speaking, it enables to evaluate a function over a private
data of remote parties, while keeping the private data still confidential. For this, both parties have to follow some protocol.
A typical toy example is a well-known
Yao's Millionaire's Problem. In this problem two millionaires, Alice and Bob, want to know which is richer, without
disclosing their actual wealth. Note the first protocol solving this problem had exponential time, space and communication complexity.
This problem has direct applications in e-commerce, e.g. on-line bidding and auctions and data mining \citep{smcBook}.
Many protocols for secure multiparty schemes are based on \emph{arithmetic circuits}. This is also a one of cornerstones
used in the following chapter, so it is important to describe it.
The function $\mathcal{F}$ is transformed to a network, that forms a directed acyclic graph, of gates performing addition
and multiplication operation, what forms an arithmetic circuit that is able to evaluate the function $\mathcal{F}$.
It is known that considering arithmetic circuits is without a loss of generality, i.e. any function that is feasible to compute
at all can be specified as a polynomial-size Boolean circuit using \emph{and} and \emph{negation}. Note that any such circuit
can be simulated by operations in $\mathbb{F}$: Boolean values \emph{true} or \emph{false} can be encoded as 1 resp. 0. Then
\emph{negation} of a bit $b$ is $1-b$ and \emph{and} of bits $b,\;c$ is $b\cdot c$ \citep{smcBook}. The resulting
circuit is then evaluated by remote parties in order to compute function $\mathcal{F}$ over their private data.
A \emph{depth} of a circuit is the longest path in the circuit.
Ishai~\eal\citep{Ishai:2008:FCO:1429103.1429148} in 2008 demonstrated a two-party computation protocol of a function
$\mathcal{F}$ while communication overhead is a fixed constant factor larger than circuit size of $\mathcal{F}$.
% ================================== FINISHME
% -multiparty security scheme
% -communicational and computational overhead.
%
% Later homomorphic schemes were designed.
% \section{Computing with encrypted data/functions}
\subsection{Fully homomorphic encryption}\label{sec:fhe}
A cryptosystem is denoted as a fully homomorphic if it supports evaluation of two operations, \emph{addition} and \emph{multiplication}, on ciphertexts
where the result after decryption matches the same operation on corresponding plaintexts.
\begin{subequations}
\begin{align}
a + b &\equiv D\left(E\left(a\right) \oplus E\left(b\right)\right) \\
a \cdot b &\equiv D\left(E\left(a\right) \odot E\left(b\right)\right)
\end{align}
\end{subequations}
The power of the the fully homomorphic system is in its ability to evaluate an arbitrary function over
encrypted data, without actually decrypting the data. This is exactly the situation where Alice wants to outsource some computations
to Bob, but doesn't want Bob to learn her information. When the function is evaluated homomorphically, the result is again encrypted,
so only Alice is able to read it. This is done by using the concept from the previous chapter, \emph{arithmetic circuits}.
The function $\mathcal{F}$ that Alive wants to compute, is converted into the \emph{arithmetic circuit} that computes the same function. This circuit evaluated
over plaintext gives the wanted result, but note that it can be evaluated also over ciphertexts using the homomorphic property of
the cryptosystem. Intuitively, Alice sends circuit representing $\mathcal{F}$ to Bob, Bob evaluates the circuit on ciphertext and returns a result to Alice.
When Alice decrypts the result from Bob, obtains the result of $\mathcal{F}$.
It is important to emphasize that in this use case, the cryptosystem becomes a computational platform, thus the possible space/time overheads slow down entire computation.
\paragraph*{History.}
The concept of \emph{computing with encrypted data} was first proposed by Rivest~\eal~\citep{Rivest1978} in~1978, a few months ago
before introduction of RSA implementation. They suggested that a fully homomorphic encryption may be possible, but were unable to find
such scheme. The question whether it is possible to construct a fully homomorphic scheme was an open problem for 30 years.
Some partially homomorphic schemes were known, for example RSA supports homomorphic evaluation of multiplication.
There were also some limited homomorphic schemes published, for example \citep{Boneh:2005:EFC:2140004.2140029} in 2005.
Their cryptosystem is based on elliptic curves and supports unlimited number of additions and one multiplication operation. Even this restricted
scheme has interesting applications, for example efficient election system, as proposed in their paper.
The breakthrough in this field was done by Gentry in 2009 \citep{Gentry:2009:FHE:1536414.1536440}. He demonstrated the fully
homomorphic encryption (FHE) scheme is possible to construct, using \emph{ideal lattices}. Since then this field is undergoing a rapid development.
\paragraph*{Key ideas.}
Gentry first constructed ``\emph{somewhat homomorphic}'' scheme that supports evaluating of low-degree polynomials on ciphertexts
(corresponds to evaluating an arithmetic circuit of a small depth).
To protect the information (plaintext), it is hidden in a large amount of \emph{noise}. Without going into further details, the main problem
is the addition doubles and the multiplication squares the noise level. Once the level exceeds acceptable boundary,
decryption is ambiguous even for Alice.
The ingenious idea of a noise reduction is called \emph{refreshing}. It is a process of evaluating decryption circuit
homomorphically. Note that such evaluation produces again ciphertext, since the result of homomorphic operation is still encrypted, but the level of noise is normalized.
Using this idea, Gentry built the FHE from the somewhat homomorphic scheme, by periodically applying the refreshing
operation when the noise reached the acceptable level.
Both symmetric and asymmetric schemes were proposed.
\paragraph*{Recent advances.}
There are three main FHE schemes known to date:
\begin{enumerate}
\item Gentry's original scheme based on ideal lattices. The implementation was introduced
by Gentry~\eal\ in \citep{Gentry:2011:IGF:2008684.2008697}. The public key has a size $2.3$~GB, refreshing operation takes 30 minutes.
\item Dijk's~\eal\ \citep{vanDijk:2010:FHE:2163822.2163825} scheme DGHV, based on a problem from number theory, approximate Greatest Common Divisor (GCD).
\begin{itemize}
\item Simpler that previous scheme.
\item The latest results by Coron~\eal\ \citep{Coron:2012:PKC:2260849.2260886} from 2012, significantly reduced the public key size
to $10.3$~MB, refreshing operation takes $11$ minutes.
\item The result from 2013 by Coron~\eal\ \citep{DBLP:journals/iacr/CoronLT13}
added support for performing \emph{batch} operations with plaintexts. %, meaning it is possible to do the same operation simultaneously
% on a vector of plaintext by just applying the operation in one ciphertext. The ciphertext has so-called plaintext slots embedded inside.
\item The fully homomorphic evaluation of AES encryption was performed, with amortized cost 12 minutes per
AES block on a standard desktop computer with 32~GB RAM \citep{DBLP:journals/iacr/CoronLT13}.
\end{itemize}
%
% The latest results by Coron~\eal\ \citep{Coron:2012:PKC:2260849.2260886} from 2012, significantly reduced the public key size
% to $10.3$~MB, refreshing operation takes $11$ minutes. The result from 2013 by Coron~\eal\ \citep{DBLP:journals/iacr/CoronLT13}
% added support for performing \emph{batch} operations with plaintexts, meaning it is possible to do the same operation simultaneously
% on a vector of plaintext by just applying the operation in one ciphertext. The ciphertext has so-called plaintext slots embedded inside.
% The fully homomorphic evaluation of AES encryption was performed, with amortized cost 12 minutes per
% AES block on a standard desktop computer.
\item Brakerski~\eal\ \citep{Brakerski:2011:FHE:2033036.2033075} Ring Learning With Errors (RLWE) scheme, adaptation of previous Learning With Errors (LWE) scheme.
The LWE hard problem is to recover $s \in \mathbb{Z}^n_q$ given a sequence of approximate random linear equations of $s$.
\begin{itemize}
\item The improvement by Brakerski~\eal\ \citep{Brakerski:2012:FHE:2090236.2090262} changed the noise
management via \emph{modulus switching}. The refreshing procedure as used by Gentry is not necessary in this case. The noise is reduced
gradually after each multiplication, protecting from growing exponentially.
\item Improvement by Gentry~\eal\ \citep{Gentry:2012:RSB:2414993.2414996} adds batch operation, using a \emph{cyclotomic number field}\footnote{\url{http://www.math.harvard.edu/~erickson/pdfs/cyclotomic_fields_part_iii.pdf}}.
\item The fully homomorphic evaluation of AES encryption was performed \citep{journals/iacr/GentryHS12} with amortized time 37 minutes per
AES block on a standard desktop computer with 256~GB RAM.
\end{itemize}
% The improvement by Brakerski~\eal\ \citep{Brakerski:2012:FHE:2090236.2090262} changed the noise
% management via \emph{modulus switching}. The refreshing procedure as used by Gentry is not necessary in this case. The noise is reduced
% gradually after each multiplication, protecting from growing exponentially. This scheme also supports batch operations as previous one.
% The fully homomorphic evaluation of AES encryption was performed \citep{journals/iacr/GentryHS12} with amortized time 37 minutes per
% AES block on a standard desktop computer with 256~GB RAM.
\end{enumerate}
\paragraph*{Batch operation,} also called plaintext ``packing'', is a technique where multiple independent plaintexts slots are embedded into a single ciphertext,
using a proper algebraic structure. Then when an operation is performed on the ciphertext, it has effect
like it is performed on the whole vector of plaintexts embedded in the ciphertext.
This strongly resembles Single-Instruction-Multiple-Data (SIMD) architecture of a paralell computer.
This adds significant improvement, since multiple blocks (like in AES case) are computed simultaneously, what gives better amortized running time
of algorithms. Recall that in the original Gentry's scheme,
the plaintext space size was only 1 bit.
As an illustration\footnote{Example taken from \citep{gentryAfrica}} consider that a plaintext space is a group $Z_{15} = Z_3 \times Z_5$, from Chinese Remainder Theorem.
Using this structure we obtain 2 slots for plaintext of size 3 and 5. Let's have two ciphertexts $c, c^{\prime}$
with $(p_3, p_5)$ and $(p_3^{\prime}, p_5^{\prime})$ in their plaintext slots respectively.
Then after ADD$(c,c^{\prime})$ the plaintext slots are $(p_3 + p_3^{\prime}, p_5 + p_5^{\prime})$. The analogy holds also for
MULT$(c,c^{\prime})$ then the plaintext slots are $(p_3 \cdot p_3^{\prime}, p_5 \cdot p_5^{\prime})$.
The batching mechanism proposed in \citep{Brakerski:2012:FHE:2090236.2090262} is based on the similar idea but uses
ring that optimizes number of plaintext slots in ciphertext, by choosing a more appropriate algebraic structure.
\paragraph*{Somewhat homomorphic encryption schemes.}
FHE schemes is a very active area of research nowadays, with still better and better improvements on a performance of the schemes,
but in spite of this, the practical use of FHE is still out of question due to its computational complexity.
Naehrig~\eal\ \citep{Naehrig:2011:HEP:2046660.2046682} proposed to sacrifice ``fully'' property and use just \emph{somewaht homomorphic schemes} (SWHM),
with limited number of multiplications. In this setup it is not possible to evaluate arbitrary function, but some families of functions can still be
useful. They give examples of an application in medical, financial sectors and advertising.
Boneh~\eal\ \citep{swhm-db01} designed and implemented a protocol for private database queries using somewhat homomorphic encryption.
\chapter{Whitebox cryptography}
\section{Introduction}
Whitebox cryptography studies security issues related to an execution of cryptographic algorithms in an untrusted environment, it is
than said to be executed in a \emph{whitebox context}.
% Key Recovery under Chosen Plaintext Attack (KR-CPA) and Plaintext recovery under chosen plaintext attack (PR-CPA), i.e.
% the cipher invertibility.
% A cryptographic algorithm executed in an untrusted environment is said to be executed in a whitebox context.
%
% % Whitebox def
% In this part of a cryptography we are studying the cryptographic algorithms with a~much stronger attacker model, saying it is executed in a~whitebox context.
% attacker def
\emph{Whitebox context} (also abbreviated as WBC) is itself defined by the attacker model, which was introduced by Chow \emph{et~al.}~\citep{Chow02white-boxcryptography} in 2002.
The WBC attacker has a full control over execution of the particular algorithm. Namely attacker has the following abilities:
\begin{itemize}
\item can observe execution:
\begin{itemize}
\item access to the instructions processing at the moment of the computation
\item trace the algorithm flow
\item sees the memory used
\end{itemize}
\item controls the execution environment - runtime modification:
\begin{itemize}
\item tamper the program memory
\item execute only a specified part of the algorithm (one round of the cipher)
\item modify if-conditions
\item change cycle counters
\item fault induction
\end{itemize}
\end{itemize}
It is in contrast to a \emph{blackbox context} (also abreviated as BBC), the standard cryptographic model, where attacker has only access to the output of the cryptographic algorithm.
In the BBC the cryptographic algorithm is considered as an oracle/blackbox evaluating some function (an analogy to executing algorithm in secure environment).
Depending on a finer granularity of an attacker model, one can have
access only to the algorithm output (ciphertext), or attacker can also query an oracle (chosen plain-text attack) and so on, but has no access to the computation itself.
The cryptographic algorithms (we are mainly interested in symmetric ciphers in this thesis) were extensively studied for attacks in the BBC in past.
They were originaly designed to resist attacks considering only the BBC. But if the context is wrong, it can be a possible entry point for an attacker.
Typical example is DRM \footnote{Digital rights management, \textless\url{http://en.wikipedia.org/wiki/Digital_rights_management}}, where software of a~vendor
(representing the rights owner) is executed in a potentially hostile environment, where user can have motivation to extract protected content without
restrictions added by DRM software. In this situation we cannot consider DRM software to be executed in the BBC.
Let's take some symmetric block cipher as an another example. Usually, it is constructed as a~keyed permutation (round function) that is repeated
several times to add randomness and to improve statistical results of the cipher, increasing security. But if we can inspect such execution, it is
very easy to extract encryption keys, since we can read memory during the execution or trace the algorithm flow.
One such whitebox attack is the \emph{Key Whitening Attack} \cite{Kerins06acautionary}. Key whitening is a technique intended to increase the security of the iterated block cipher.
It is typically implemented as adding a~key material to the data (usually by simple operation, such as XOR) in the first and the last round. Such key whitening
is used by Twofish~\citep{Schneier98twofish:a} and in a modified version (only adding the key material in the last round) also by AES~\citep{2002-daemen}. In Key Whitening Attack
cipher's binary is modified (we are in whitebox context) in such a~way that the output of the cipher will be the key material itself.
Main two attacks in whitebox context are: (1) Key Recovery, i.e. an extraction of a embedded symmetric key. (2) Plaintext recovery under Chosen Plaintext Attack (PR-CPA), e.g. perform decryption with
implementation of cipher with embedded encryption that is supposed to be able only to perform encryption.
% The main goals of a~whitebox attack is to extract a~key material (usually the symmetric key) or to build an inverse cipher i.e. perform decryption
% with tables for encryption with a~embedded key.
Whitebox cryptography is closely related to the \emph{obfuscation} mentioned in the section \ref{sec:obfuscation}. It is also a program transformation,
but obfuscation, as defined in the literature, is too restrictive and does not take specific security notios, e.g. cipher invertibility
a.k.a. PR-CPA, into account.
The definition of whitebox cryptography could be:
``The challenge that white-box cryptography aims to address is to implement a~cryptographic algorithm in
software in such a~way that cryptographic assets remain secure even when subject to white-box attacks.
Software implementations that resist such white-box attacks are denoted white-box implementations.'' \cite{hiding_keys}.
\section{History}
% History overview, oorschot, billet, imposibility of obfuscation, generic attacks on AES, DES
Whitebox cryptography is a quite new field of cryptography. The study of the whitebox implementation of the ciphers started by first
whitebox implementation of AES~\citep{Chow02white-boxcryptography} and DES~\citep{Chow02awhite-box} by Chow~\eal\ in~2002.
At first, the cryptanalysis of DES focused on its simplified variant. The first published in 2002 by Jacob~\eal\
uses fault injection~\citep{conf/ccs/JacobBF02}, another one published in 2005 by Link~\eal\ uses statistical analysis~\citep{Link:2005:COI:1058430.1059147}.
Later cryptanalysis of fully encoded variant of DES was published by Wyseur~\eal\ in~2007 using truncated differentials.
The similar case holds for AES. Two years after publishing the whitebox AES scheme the successful cryptanalysis~\citep{Billet:2004:CWB:2080787.2080809} was
published by Billet~\eal~that enabled to recover embedded symmetric
key in less that $2^{30}$ steps. Later, in 2008, the generalized version of the previous attack
was published~\citep{Michiels:2007:MST:1314276.1314291} by Michiels~\eal\ affecting the larger family of ciphers using the same structure as AES.
There were also attempts to fix whitebox AES scheme by adding additional linear mappings and increasing size of the implementation in~\citep{XiaoLai}
as a~response to the Billet's attack.
The attack against improved scheme using a linear equivalence algorithm was published in 2012 \cite{conf/sacrypt/MulderRP12}.
The another attempt, how to fix whitebox AES, was introducing random perturbations~\citep{journals/iacr/BringerCD06a},
complicating algebraic cryptanalysis, but the effective attack was published by Mulder~\eal~\citep{conf/indocrypt/MulderWP10}.
Last, but not least a whitebox AES scheme using dual ciphers~\citep{Karroumi:2010:PWA:2041036.2041060} was published in 2011. The paper claimed
the scheme is robust enough to resist practical attacks on the implementation. We proved this assumption false by finding out the published attack
works in the same way on this implementation as on the original one, for the proof see the section \ref{sec:attacking_dual_aes}.
This thesis is mainly focused on the scheme using dual ciphers, note it is generalization of the first whitebox AES scheme.
\section{Whitebox AES scheme}
% Schemes used with AES, DES. Some techniques used in whiteboxing the cipher (input output encodings, mixing bijections - diffusion layers)
The first whitebox AES implementation, published by Chow~\eal~\citep{Chow02white-boxcryptography} is based on the look-up tables implementation, that was also
mentioned in original AES paper~\citep{2002-daemen}. Note that it is easy to transform AES with an embedded encryption key
to a~network of look-up tables and to use these computed tables for an encryption (or a decryption). But this implementation is vulnerable in the WBC,
since it is possible to extract the encryption key with algebraic analysis of the look-up tables. Recall that all the building blocks (except key schedule) of AES are key-independent
and publicly available. Thus these look-up tables have to be further protected to resist algebraic attacks.
We are mainly focused on AES-128, for simplicity, but the same strategy can be applied also to AES-192 and AES-256.
For further explanation we will need the following definitions:
\begin{mydef}\label{def:linear_mapping}
Linear mapping is a mapping $L\left(x\right)$ over $\text{GF}(2)^n$ that satisfies $\forall \; x,y \in \text{GF}(2)^n \; : \; L(x+y) = L(x) + L(y).$
\end{mydef}
\begin{mydef}\label{def:affine_mapping}
Affine mapping is a mapping $A(x)$ over $\text{GF}(2)^n$ such that $A(x) = L(x) + c, c \in \text{GF}(2)^n$ and $L(x)$ is the linear mapping.
\end{mydef}
\subsection{AES-128}
A brief introduction of AES is required for further understanding of the whitebox implementation and the implementation based on dual AES in section \ref{sec:wb_dual_aes_sec}.
AES-128 is a~symmetric, iterated, block cipher that maps $128 \rightarrow 128$ bits (block length) using a 128-bit encryption key. It has 10 rounds and operates
over $4\times4$ byte array. AES works with $\gfe$ and operations used in AES have quite algebraic nature. For each round is generated a key material called round keys
by key-schedule routine from encryption key.
The key-schedule is not an important operation from our perspective and can be abstracted in further explanations. Important fact about the key-schedule is that it is reversible i.e.
if we have round keys from 2 consecutive rounds it is possible to derive all other round keys, even the encryption key (the encryption key is used as a round key in the first round).
Besides the key-schedule there are 4 operations used in main AES body:
\begin{itemize}
\item \emph{AddRoundKey} adds round keys to the state array. It is simple XOR of two $4\times4$ byte arrays.
\item \emph{ShiftRows} performs a simple shift of each row of the state array to the left, by the row index (indexing from 0).
\item \emph{SubByte} is $8 \rightarrow 8$ bijection, the only non-linear operation, performing
\emph{confusion}\footnote{\emph{Confusion} is a~property of secure cipher defined by Shannon~\citep{shannon-otp}, it should make relation between ciphertext and symmetric encryption
key complex.}. It uses inversion in $\gfe$.
\item \emph{MixColum} is the main \emph{diffusion}\footnote{\emph{Diffusion} is a~property of secure cipher defined by Shannon~\citep{shannon-otp}, it should make relation between
ciphertext and plaintext complex, dissipating small change into large range. Diffusion contributes to the avalanche effect. } operation. It corresponds to a matrix multiplication in $\gfe$.
State array column is multiplied from left by MixColumn $4 \times 4$ matrix (also denoted as MC). Due to this operation, after one round of the cipher,
one byte of the state array depends on 4 bytes of the input state array.
\end{itemize}
\subsection{AES table implementation}\label{sec:aes_table}
Algorithm \ref{alg:AESalg} is AES in a~form suitable for the whitebox implementation, i.e. some operations were regrouped in such a~way that \emph{AddRoundKey}
is right before \emph{SubByte} operation. This enables to merge these two operations to one $8\times8$ look-up table as is described in equation \ref{eq:tboxes}.
Resulting tables following this construction are called T-boxes.
\begin{equation} \label{eq:tboxes}
\begin{aligned}
T^r_{i,j}(x) &= S\left(x \oplus k^r_{i,j}\right)\\
T^{9}_{i,j}(x) &= S\left(x \oplus k^{9}_{i,j}\right) \oplus k^{10}_{i,j}
\end{aligned}
\end{equation}
\begin{algorithm}
\caption{AES algorithm, form suitable for whitebox implementation}
\begin{algorithmic}[1]
\Function{AES}{$plaintext, k$} \Comment{k is array of round keys}
\State $state \gets plaintext$ \Comment{state is $4 \times 4$ byte array}
\For{$r\gets 0, $ to $8$}
\State $\text{ShiftRows}(state)$
\State $\text{AddRoundKey}(state, k_{r})$
\State $\text{SubByte}(state)$
\State $\text{MixColumn}(state)$
\EndFor
\State $\text{ShiftRows}(state)$
\State $\text{AddRoundKey}(state, k_{9})$
\State $\text{SubByte}(state)$
\State $\text{AddRoundKey}(state, k_{10})$
\State \textbf{return} $state$
\EndFunction
\end{algorithmic}
\label{alg:AESalg}
\end{algorithm}
\emph{ShiftRows} has no counter-part in
table implementation, it is implemented as the way how tables between rounds are connected together (taking \emph{ShiftRows} into account).
The \emph{MixColumn} is problematic to transform into a look-up table
since it is $32 \rightarrow 32$ mapping. A naive transformation would take $2^{32}\cdot4 = 16$~GB. Thus linearity of a matrix multiplication is used, as
illustrates equation \ref{eq:mmul_linearity}.
Let
\begin{equation}
MC = \begin{bmatrix}
a_{0,0} & a_{0,1} & a_{0,2} & a_{0,3} \\
a_{1,0} & a_{1,1} & a_{1,2} & a_{1,3} \\
a_{2,0} & a_{2,1} & a_{2,2} & a_{2,3} \\
a_{3,0} & a_{3,1} & a_{3,2} & a_{3,3}
\end{bmatrix}% = \begin{bmatrix}
% MC_0 & MC_1 & MC_2 & MC_3
% \end{bmatrix}
\end{equation}
Then from linearity holds:
\begin{equation} \label{eq:mmul_linearity}
\begin{aligned}
MC \cdot \begin{bmatrix}
x_0\\
x_1\\
x_2\\
x_3
\end{bmatrix} &= MC \cdot \begin{bmatrix} x_0 \\ 0 \\ 0 \\ 0 \end{bmatrix} \oplus
MC \cdot \begin{bmatrix} 0 \\ x_1 \\ 0 \\ 0 \end{bmatrix} \oplus
MC \cdot \begin{bmatrix} 0 \\ 0 \\ x_2 \\ 0 \end{bmatrix} \oplus
MC \cdot \begin{bmatrix} 0 \\ 0 \\ 0 \\ x_3 \end{bmatrix} \\
&= x_0 \cdot \begin{bmatrix} a_{0,0} \\ a_{1,0} \\ a_{2,0} \\ a_{3,0} \end{bmatrix} \oplus
x_1 \cdot \begin{bmatrix} a_{0,1} \\ a_{1,1} \\ a_{2,1} \\ a_{3,1} \end{bmatrix} \oplus
x_2 \cdot \begin{bmatrix} a_{0,2} \\ a_{1,2} \\ a_{2,2} \\ a_{3,2} \end{bmatrix} \oplus
x_3 \cdot \begin{bmatrix} a_{0,3} \\ a_{1,3} \\ a_{2,3} \\ a_{3,3} \end{bmatrix} \\
&= x_0 \cdot MC_0 \oplus
x_1 \cdot MC_1 \oplus
x_2 \cdot MC_2 \oplus
x_3 \cdot MC_3
\end{aligned}
\end{equation}
Thus the $32\rightarrow32$ linear mapping represented by a~matrix multiplication is decomposed to four $8\rightarrow32$ look-up tables
connected by three 32-bit XOR tables. The tables performing this operation are denoted as $T_y$ tables in a further text.
Figure \ref{fig:table_aes} illustrates an evaluation of the AES round function using look-up tables for one column of state array.
\begin{figure*}[!htb]
\begin{center}
\leavevmode
\centerline{\scalebox{1.0}{\includegraphics{AES_table.pdf}}}
\end{center}
\caption{Table AES implementation - rounds 2--8, taken from~\citep{Muir_atutorial}}
\label{fig:table_aes}
\end{figure*}
\subsection{Whitebox AES}\label{sec:whitebox_aes_scheme_chow}
As mentioned before, special techniques are needed to protect look-up tables from algebraic attacks. The most important ones
are described in following paragraphs.
\paragraph*{Input/output bijections.}
One of the techniques used in whitebox implementation is a use of \emph{input/output bijections} (also abbreviated as IO bijections).
According to Chow~\eal~\citep{Chow02white-boxcryptography} IO bijection is a~random $n\rightarrow n$ bijection\footnote{usually $n=4$}.
Consider $n\rightarrow n$ IO~bijections $F_1,\dots,F_k$, they can be \emph{concatenated} to form a~$kn \rightarrow kn$ bijection
$F_1||\dots || F_k$. This concatenation enables to build a~large bijections with small look-up tables. In a~further explanations the size of basic
IO~bijection is $4 \rightarrow 4$.
Consider the table implementation of AES as mentioned in the section \ref{sec:aes_table}. To protect the tables, each table is wrapped by
the concatenated IO bijections in such a~way the composition of two connected tables cancels the effect of IO bijections as illustrates
equation \ref{eq:ioenc_network}.
\begin{subequations}\label{eq:ioenc_network}
\begin{align}
T' &= g \circ T \circ f^{-1} \\
R' &= h \circ R \circ g^{-1} \\
R' \circ T' &= \left(h \circ R \circ g^{-1}\right) \circ \left(g \circ T \circ f^{-1}\right) = h \circ (R \circ T) \circ f^{-1}
\end{align}
\end{subequations}
Where $T,\; R$ are look-up tables, $g,\; h$ are IO bijections, realizing confusion step and making an analysis of a~single table harder.
\paragraph*{Mixing bijections.}\label{sec:mixingBijections01}
Another whitebox building block is a~\emph{mixing bijection}. It is a~linear transformation (represented as a~multiplication by a~non-singluar mixing bijection matrix)
that realizes the diffusion. It is used together with the IO~bijections to increase a~security level of the concatenated bijections, since it diffuses a~single change
in the one sub-bijection to the whole range of the concatenated bijection. In order to fulfill this purpose properly, the mixing bijections have to be constructed
in a~special way. Zhou~\eal\ in~\citep{journals/iacr/XiaoZ02} describe the algorithm that generates large random non-singular matrices with blocks of a~full-rank.
The size of the sub-blocks is $4$ what matches the size of basic IO bijection what gives good diffusion properties for the concatenated bijections.
Note that full-rank property of matrix blocks provides good level of the diffusion. It lies somewhere between two extreme cases: (1) random non-singular matrices without any
requirements on a diffusion power and (2) parity-check matrices of MDS\footnote{$(n, k, d)$-code is Maximum Distance Separable if $d=n-k+1$, \url{http://www.mth.msu.edu/~jhall/classes/codenotes/Linear.pdf}}
codes that have an optimal diffusion power (for a~linear transformation), but it is harder to generate them systematically. Note that MDS matrices are often used
as a~diffusion element in ciphers.
\paragraph*{External input/output encoding.}
Consider AES protected with aforementioned whitebox techniques. A possible place where to attack is an input and an output of the algorithm, since it is not protected
from a~whitebox attack. To mitigate this weakness Chow~\eal\ also introduces an \emph{external encoding} that wraps whole AES. Usually the cipher is not a standalone element,
but a part of the system. This technique helps to tie AES to its context and to prevent from using the cipher separately as an oracle.
Whitebox implementation computes:
\begin{equation}
H \circ AES \circ G^{-1}
\end{equation}
If AES is used as a~part of the~system, a~previous element has to apply transformation $G$ on data before passing them to the WB AES. Similarly, the next element has to apply
$H^{-1}$ to cancel the effect of the previous transformation.
Usually $G, H$ are defined as a~multiplication by $128\times128$-bit matrix followed by the $128 \rightarrow 128$ concatenated bijection.
\paragraph*{Table types.} To fully transform AES to the WB AES the following 4 table types are needed.
As mentioned above, the external encoding uses a $128\times128$ matrix multiplication to protect the input and the output of the cipher.
The matrix decomposition technique introduced in section \ref{sec:aes_table} is used to make table implementation feasible. Figure \ref{fig:aes_t1} depicts
$8\rightarrow128$ table used in the first and the last round for the external encoding.
\begin{figure*}[!htb]
\begin{center}
\leavevmode
\centerline{\scalebox{1.0}{\includegraphics{AES_T1.pdf}}}
\end{center}
\caption{Table type I, $8\rightarrow128$ mapping, used for external encoding, taken from~\citep{wyseurPhd}}
\label{fig:aes_t1}
\end{figure*}
Recall already mentioned T-boxes in section \ref{sec:aes_table} that perform \emph{SubByte} and \emph{AddRoundKey} operations. The \emph{MixColumn} operation
is implemented by the matrix multiplication decomposition, these $8\times32$ tables are called $T_y$ boxes. In order to save space
$T$ and $T_y$ boxes are composed to resulting type II table as illustrates figure \ref{fig:aes_t2}.
\begin{figure*}[!htb]
\begin{center}
\leavevmode
\centerline{\scalebox{1.0}{\includegraphics{AES_T2.pdf}}}
\end{center}
\caption{Table type II, $8\rightarrow32$ mapping, taken from~\citep{wyseurPhd}}
\label{fig:aes_t2}
\end{figure*}
Note $32\times32$ mixing bijection added after the \emph{MixColumn} operation to increase a diffusion. To cancel this transformation the table
type III is used as illustrates figure \ref{fig:aes_t3_t4}. Also recall the matrix multiplication decomposition requires addition operation. This is done
by exclusive-OR (XOR), a cascade of table type IV is used for this purpose. Note that performing XOR by table look-up is rather ineffective, but it is required to
protect look-up tables by IO bijections and mixing bijections (to form a protected network of look-up tables without revealing true values on
table boundaries).
\begin{figure*}[!htb]
\begin{center}
\leavevmode
\centerline{\scalebox{1.0}{\includegraphics{AES_T3_T4.pdf}}}
\end{center}
\caption{Table type III and IV, taken from~\citep{wyseurPhd}}
\label{fig:aes_t3_t4}
\end{figure*}
\paragraph*{Overall scheme.}
Figure \ref{fig:wbaes} illustrates how the round function of whitebox AES implementation for one column looks, using aforementioned tables.
\begin{figure*}
\begin{center}
\leavevmode
\centerline{\scalebox{1.0}{\includegraphics{WBAES_PQ.pdf}}}
\end{center}
\caption{The whitebox AES implementation - round \#2, based on diagram from~\citep{Muir_atutorial}}
\label{fig:wbaes}
\end{figure*}
On the diagram in figure \ref{fig:wbaes} are the following mappings:
\begin{itemize}
\item MB stands for Mixing Bijection. It is $32 \times 32$ matrix with coefficients from $\text{GF}(2)$, representing linear transformation over $\gf^8$.
$\text{MB}^{-1}_{\{0,1,2,3\}}$ are then column stripes of the corresponding MB inverse matrix (the matrix multiplication decomposition).
This transformation cancels out within one round.
\item L stands also for Mixing Bijection but in this case it is $8 \times 8$ matrix.
\item Q,P. These are random IO bijections. It holds that $P^{r+1}_{i,j} \circ Q^{r}_{i,j} = id$
\end{itemize}
\subsection{Cipher invertibility}\label{sec:cipher_invertibility}
One of the requirements on the whitebox cipher implementation is usually a~\emph{non-invertibility}. It means that given an encryption part of the cipher
with an embedded key, one should not be able to use it also for decryption and vice versa. This property is especially useful if one wants to use a symmetric
cipher to simulate an asymmetric. But it is important to realize that this goal is difficult to achieve in the whitebox context.
As an example take AES whitebox implementation.
Inverting the cipher in the blackbox context is rather computationally difficult. Using brute-force one would
need $2^{128}$ operations to invert the cipher. The whitebox context, is in contrast to the blackbox, advantageous for an attacker. One of the problems here is
that \emph{ShiftRows} operation can be very easily canceled in whitebox context and that attacker can execute only particular round of the cipher.
We propose some improvement addressing this problem in section \ref{sec:cipher_invert_improvement}.
There are 4 columns of the state array within one round, independent on each other.
Thus the cipher can be easily inverted running it backwards and finding an inversion for the each column separately, assuming $128\times128$ external mixing bijections
are $I_{128}$. Thus the task is to find an
inversion of a 32-bit wide function representing one round of the cipher on one column of the state array, by running through the space $\text{GF}\left(2^8\right)^4$,
evaluating the round function and comparing with the wanted result.
A computational complexity to invert the cipher
is $10 \cdot 4 \cdot 2^{32}$ operations \footnote{ $10$ (rounds) $\cdot 4$ (columns) $ \cdot 2^{32}$ (column function input space size)}.
One can also pre-compute tables for inverted cipher, that would occupy $10 \cdot 4 \cdot (2^{32} \cdot 4)\;\text{B} \approx 69\;\text{GB}$.
We have implemented an algorithm that inverts the WB AES, i.e. performing plaintext recovery attack.
In the non-optimized version it takes 13 hours on my hardware\footnote{For hardware specifications see \ref{appendix:hw_spec}}
to invert the WB AES with negligible memory requirements.
\section{The BGE attack}\label{sec:bge_attack}
The paper~\citep{Billet:2004:CWB:2080787.2080809} by Billet~\eal\ demonstrated that the whitebox AES implementation, as described in the previous section, is vulnerable
to an algebraic attack. The attack is named after initials of authors, the BGE attack. It recovers the symmetric key from the whitebox AES implementation and
negligible memory requirements in $2^{30}$ computational steps.
The BGE attack does not analyze look-up tables locally, but instead the whole AES round function is analyzed as a~single look-up table. This has few benefits:
\begin{itemize}
\item the structure of the round function is fixed and well-known, thus it is easy to model it as an algebraic equation.
\item $32\times32$ mixing bijections $MB$ are canceled within one round, so they can be neglected.
\item $8\times8$ mixing bijection $L$ can be easily merged with the IO bijections on round boundary, what simplifies further algebraic analysis.
\end{itemize}
Figure \ref{fig:aes_round_bge} illustrates the round function of AES for one column from the BGE attack perspective. Depicted function can
be described as a~mapping $\left(x_0, x_1, x_2, x_3\right) \xrightarrow{R^r_j} \left(y_0, y_1, y_2, y_3\right), \; j=0,\dots,3$.
\begin{figure*}
\begin{center}
\leavevmode
\centerline{\scalebox{1.0}{\includegraphics{BGE_round.pdf}}}
\end{center}
\caption{AES round function from the BGE attack perspective, taken from~\citep{Billet:2004:CWB:2080787.2080809}}
\label{fig:aes_round_bge}
\end{figure*}
Since the transformation $L$, $L^{-1}$ is performed byte-wise on the state array, it can be composed with corresponding IO bijections, as in equation \ref{eq:ioencoding_abstract_q}.
\begin{subequations} \label{eq:ioencoding_abstract_q}
\begin{align}
Q^{r \; \prime}_{i,j} &= Q^{r}_{i,j} \circ L^{r+1}_{j} \\
P^{r \; \prime}_{i,j} &= (L^{r}_{j})^{-1} \circ P^{r}_{i,j}
\end{align}
\end{subequations}
The IO bijections are generally non-linear, thus composing then with an another linear transformation (L) results again in a non-linear bijection. Note that in the BGE
attack, IO bijections are considered to be general $8\rightarrow8$ bijections, neglecting the fact they are concatenated from 2 $4\rightarrow4$ bijections what allows
composition with L.
The BGE attack proceeds in three steps:
\begin{enumerate}
\item Transform the non-linear IO bijections $Q^{r}_{i,j}$ to unknown $\gf$-affine transformation (i.e. determine a non-linear part up to unknown affine part).
\item Fully determine $Q^{r}_{i,j}$ bijection, using the algebraic analysis and the known form of the round function.
\item Obtain round keys from 2 consecutive rounds and recover the symmetric key using reversibility of the AES key-schedule.
\end{enumerate}
\subsection{Recovering non-linear parts}
This step is particularly interesting because of its universality. It could be applied on a different whitebox implementation.
The main goal of this step is to recover non-linear parts of $\left(Q^r_i\right)_{i=0,\dots,3}$. Consider $y_0$ as a~function of $\left(x_0, x_1, x_2, x_3\right)$.
If $x_1, x_2, x_3$ are fixed as constants $c_1, c_2, c_3$, it is easy to see that there exist $\alpha, \beta_{c_1,c_2,c_3} \in \gfe$ such that the following holds:
\begin{equation} \label{eq:y0}
\begin{aligned}
y_0\left(x_0, c_1, c_2, c_3 \right) &= Q^r_{0,j} \left(\alpha T^r_{0,j}\left(P^r_{0,j}\left(x\right)\right) \oplus \beta_{c_1,c_2,c_3}\right) \\
&= Q^r_{0,j} \circ \oplus_{\beta_{c_1,c_2,c_3}} \circ \alpha \cdot T^r_{0,j} \circ P^r_{0,j} \left(x\right)
\end{aligned}
\end{equation}
The function $y_0$ from the equation \ref{eq:y0} now takes only $256$ input values, thus the functions $y_0$ and $y_0^{-1}$
can be easily evaluated (as look-up tables). For the rest of the chapter consider constants $c_2, c_3$ fixed, without loss
of generality let $c_2=c_3=0$. For the simplification the $r$ superscript is dropped from the
equations if it is clear from the context.
Now assume $c^{\prime}_1 \neq c_1$, also denote $\beta_{0} = \beta_{c_1,c_2,c_3}, \beta_{1} = \beta_{c^{\prime}_1,c_2,c_3}$, it is visible that:
\begin{subequations}
\begin{align}
& y_0\left(x_0, c^{\prime}_1, c_2, c_3 \right) \circ y_0^{-1}\left(x_0, c_1, c_2, c_3 \right) = \nonumber \\
&= \left( Q_{0,j} \circ \oplus_{\beta_1} \circ \alpha \cdot T_{0,j} \circ P_{0,j} \right) \nonumber
\circ \left( P^{-1}_{0,j} \circ \left(\alpha \cdot T_{0,j}\right)^{-1} \circ \oplus_{\beta_0} \circ Q^{-1}_{0,j}\right) \nonumber \\
&= Q_{0,j} \circ \oplus_{\beta_1} \circ \oplus_{\beta_0} \circ Q^{-1}_{0,j} \nonumber \\
&= Q_{0,j} \circ \oplus_{\left(\beta_0 \oplus \beta_1\right)} \circ Q^{-1}_{0,j} \nonumber
\end{align}
\end{subequations}
Thus by fixing $c_1$ and iterating $c^{\prime}_1$ we obtain the set of 256 bijections, represented as look-up tables,
of the form $Q_{0,j} \circ \oplus_{\beta} \circ Q^{-1}_{0,j}$, where $\beta$ takes all values from $\gfe$.
\begin{mytheorem}\label{prop:bge1}
Given a~set of functions $\mathcal{S} = \{Q \circ \oplus_{\beta} \circ Q^{-1}\}_{\beta \in \gfe}$ given by values,
where $Q$ is a~permutation of $\gfe$ and the $\oplus_{\beta}$ is the translation by $\beta$ in $\gfe$, one can construct a~particular
solution $\widetilde{Q}$ such that there exists an affine mapping $A$ so that $\widetilde{Q} = Q \circ A$.
\end{mytheorem}
For the proof see the original paper~\citep{Billet:2004:CWB:2080787.2080809}. In order to recover a non-linear part of the IO bijection it is needed to generate
the set $\mathcal{S}$ (by evaluating $y_0$ functions) and to apply the theorem.
Note that the set $\mathcal{S}$ contains $256$ functions, but only as look-up tables so the $\beta$ is unknown. One easily verifies the set
$\mathcal{S}$ together with the operation of a function composition form a~group.
Observe there exists isomorphism $\varphi:\; $
\begin{center}
\begin{tabular}{ r c c c }
\multirow{2}{*}{$\varphi \; :$} & $\mathcal{S}$ & $\longrightarrow$ & $\gf^2$ \\
& $Q \circ \oplus_{\beta} \circ Q^{-1} $ & $\longmapsto$ & $\left[ \beta \right]$
\end{tabular}
\end{center}
Since we don't know the values $\beta$ for the functions in $\mathcal{S}$ the $\varphi$ cannot be constructed directly, however it is possible to
recover $\varphi$ up to unknown linear transformation $L$ i.e. $\psi = L^{-1} \circ \varphi$. Without going into the details, the
$\psi$ is determined by finding base functions $f_1,\dots,f_8$ that span the whole $\mathcal{S}$ under composition. Mapping $\psi$ is then constructed by assigning
standard basis vectors $e_1,\dots,e_8 \in \gf^8$ to these functions.
It is then possible to obtain $\widetilde{Q}$ by using the mapping $\psi$ from the theorem \ref{prop:bge1} according to the following formula:
\begin{equation}\label{eq:Qtilde}
\widetilde{Q}\left(\psi\left(g\right)\right) = g\left(0\right),\; g \in \mathcal{S}
\end{equation}
Note that the value $g\left(0\right)$ is known, the function was evaluated during $\psi$ construction. The term $\psi\left(g\right)$ is also easy to
evaluate, since we have constructed mapping $\psi$. Thus in order to recover $\widetilde{Q}$ as a~look-up table we just run over the set $\mathcal{S}$
and compute the values of mapping $\widetilde{Q}$ according to the equation \ref{eq:Qtilde}.
\subsection{Recovering the symmetric key}
As the rest of the BGE attack is very AES and implementation specific, it is not covered in detail. In this phase, we are still in situation as
is depicted in figure \ref{fig:aes_round_bge} with a difference $\left(Q^r_i\right)_{i=0,\dots,3}$ and $\left(P^{r+1}_i\right)_{i=0,\dots,3}$
are affine, still matching, bijections. This fact makes further algebraic analysis of round function possible.
Consider following useful proposition:
\begin{myprop}\label{prop:bge_prop1}
For any pair $\left(y_i, y_j\right)$ exists a unique linear mapping $L$ and a unique constant $c$ such that:
\begin{equation}
\forall x_0 \in \gfe:\; y_i\left(x_0, 0, 0, 0\right) = L \left(y_j \left(x_0, 0, 0, 0 \right) \right) \oplus c
\end{equation}
\end{myprop}
By using Theorem \ref{prop:bge_prop1} one can obtain the linear parts of $Q_1, Q_2, Q_3$ from the knowledge of the $Q_0$ linear part in $2^{16}$ steps by simple
running over $c$ and testing the resulting mapping for linearity in $2^8$ steps. Thus the rest of the attack focuses on $Q_0$ determination.
First of all, the linear part of $Q_0$ up to $\left[\gamma\right], \gamma \in \gfe \setminus \{0\}$ is determined, where $\left[\gamma\right]$ denotes the
matrix in $\gf$ corresponding to multiplication by $\gamma$ in $\gfe$. For more details see appendix \ref{appendix:mult_matrix}.
Then $\gamma$ and a constant part $q_0$ of $Q_0$ are determined. During these steps, the public knowledge of S-boxes and MixColumn matrix coefficients is used.
With completely determined $Q_0$ the round keys are extracted.
The attack ends using the fact the key-schedule of AES is reversible, so from two consecutive round keys one can derive original symmetric key.
\chapter{WBCAR AES using dual ciphers}\label{sec:wb_dual_aes_sec}
WBCAR stands for the whitebox context attack resistant, meaning cipher implementation should resist attacks like key-extraction, cipher inversion
and others against attacker in the whitebox context.
In this chapter we describe a whitebox scheme proposed in~\citep{Karroumi:2010:PWA:2041036.2041060} that make use of AES dual ciphers. It is supposed
that using dual AES, different in each round, will increase security of the whitebox implementation of the cipher. The paper says that this modification
results in raising BGE attack~\citep{Billet:2004:CWB:2080787.2080809} complexity to $2^{91}$ computational steps, making it unfeasible to perform it in practice. It is shown in section
\ref{sec:attacking_dual_aes} that this assumption is false due to existence of an attack we performed.
\section{Scheme}
In the original paper~\citep{Karroumi:2010:PWA:2041036.2041060} the explanation how to obtain dual AES ciphers and how to construct mapping from one
to another is not given. This is
important part since it plays a crucial role in a~proof that this scheme is vulnerable. At first is described the generalization of the AES and how to construct
mappings between them.
\subsection{Ciphers duality}
This section introduces a notion of dual ciphers used in this chapter. Dual ciphers have interesting properties and are used in a construction
of the scheme that is described by this chapter. Consider the following definition.
\begin{mydef}\label{def:dual_cipher}
Two ciphers $E$ and $E'$ are called Dual Ciphers, if they are
isomorphic, i.e., if there exist invertible transformations $f$, $g$ and $h$ such
that