<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>An Enhanced Dataflow Analysis to Automatically Tailor Side Channel Attack Countermeasures to Software Block Ciphers</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Alessandro Barenghi</string-name>
          <email>alessandro.barenghi@polimi.it</email>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Gerardo Pelosi</string-name>
          <email>gerardo.pelosi@polimi.it</email>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>Politecnico di Milano, Department of Electronics</institution>
          ,
          <addr-line>Information and Bioengineering - (DEIB)</addr-line>
          ,
          <country country="IT">Italy</country>
        </aff>
      </contrib-group>
      <pub-date>
        <year>2017</year>
      </pub-date>
      <fpage>8</fpage>
      <lpage>18</lpage>
      <abstract>
        <p>Protecting software implementations of block ciphers from side channel attacks is a significant concern to realize secure embedded computation platforms. The relevance of the issue calls for the automation of the side channel vulnerability assessment of a block cipher implementation, and the automated application of provably secure defenses. The most recent methodology in the field is an application of a specialized data-flow analysis, performed by means of the LLVM compiler framework, detecting in the AES cipher the portions of the code amenable to key extraction via side channel analysis. The contribution of this work is an enhancement to the existing data-flow analysis which extending it to tackle any block cipher implemented in software. In particular, the extended strategy takes fully into account the data dependencies present in the key schedule of a block cipher, regardless of its complexity, to obtain consistently sound results. This paper details the analysis strategy and presents new results on the tailored application of power and electro-magnetic emission analysis countermeasures, evaluating the performances on both the ARM Cortex-M and the MIPS ISA. The experimental evaluation reports a case study on two block ciphers: the first designed to achieve a high security margin at a non-negligible computational cost, and a lightweight one. The results show that, when side-channel-protected implementations are considered, the high-security block cipher is indeed more efficient than the lightweight one.</p>
      </abstract>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>Introduction</title>
      <p>
        Embedded systems have a high platform diversification in terms of both the available computational
resources on board, the actual instruction set architecture of the underlying computing core, and the
availability of both volatile and non volatile memory. Such significant differences result in
corresponding high engineering costs to realize functional, energy efficient and secure embedded systems. In
particular, providing sound security guarantees in the embedded system world is a crucial issue, as they
are increasingly in charge of critical tasks, and their expected long field life results in failures causing
concrete problems over potentially a decade’s worth of devices, especially in the Internet of Things and
automotive environments [
        <xref ref-type="bibr" rid="ref10">10</xref>
        ]. Among the most prominent threats to the security of embedded devices
relying on cryptographic techniques, Side-Channel Attacks (SCAs) have proven to be one of the most
consolidated and effective techniques [
        <xref ref-type="bibr" rid="ref15">15</xref>
        ]. SCAs break correct, specifications abiding implementations,
employing the information on the secret parameters, i.e., the cipher keys, which is unwillingly
transmitted as a change in environmental parameters of the computing device such as its power consumption or
radiated electromagnetic emissions. While sound countermeasure techniques against them are present
and consolidated in open literature [
        <xref ref-type="bibr" rid="ref14 ref8">8, 14</xref>
        ], their application to an unprotected implementation is still
largely performed by hand. Such an approach entails a significant effort, as the countermeasure
techniques are applied either to the assembly code of a software implementation, or to the low level netlist
representation of a soon to be implemented circuit. Recently, research efforts directed at automated,
design time, application of countermeasures have shown the feasibility of systematically applying them
to software implementations, employing the AES cipher as a case study [
        <xref ref-type="bibr" rid="ref1 ref2 ref3 ref4">1–4</xref>
        ].
      </p>
      <p>
        Contributions. We propose an improvement over the current state of the art of compiler-based
automated SCA countermeasure application. We provide accurate identification technique determining
the most effective choice of the key material (i.e., the user key and the expanded key computed during
the cipher keyschedule) to be retrieved when attacking via SCA a block cipher. Our contribution pushes
forward the abilities of the automated analysis proposed in [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ] examining new block ciphers, proposing
an efficient alternative which does not rely on modifying the runtime executed code as proposed in [
        <xref ref-type="bibr" rid="ref2 ref3 ref4">2–4</xref>
        ]
The relevance of the enhanced analysis is substantiated in an experimental evaluation applying tailored
countermeasures. The results show that the protected implementation of a high-security, general purpose
cipher achieves speedups in the 93×-190× range against the protected lightweight cipher.
2
      </p>
    </sec>
    <sec id="sec-2">
      <title>Background</title>
      <p>
        Given a block cipher implementation, the side channel attack (SCA) workflow is a known plaintext
attack, where the adversary knows both the plaintext and the ciphertext, and aims at retrieving the secret
key through examining multiple runs of the algorithm on different inputs [
        <xref ref-type="bibr" rid="ref12">12</xref>
        ]. The attacker knows all
the details of the implementation of the cipher and measures either the power consumption or the
electromagnetic emissions of the device to derive information regarding the secret key. The main strength of
an SCA lies in considering the effect of the secret key bits on the computation separately instead of as a
whole, leading to a significant lowering in the security margin of the primitive. A typical attack starts by
choosing an intermediate value of the cipher depending on a small key portion (e.g., 8 bits) and a known
quantity (e.g., the plaintext). The side channel is then measured during the aforementioned operation,
for a large set of randomly distributed input values. Subsequently, the attacker predicts the outcome of
the side channel measurement relying on the knowledge of the inputs and making an hypothesis for all
the possible values of the secret key portion taken into account. This yields a set of hypotheses: one for
each value possibly taken by the portion of the secret key under attack. Each hypothesis is compared
with the measured side channel, through the use of a statistical test (e.g., the Pearson’s correlation
coefficient), revealing the actual value of the secret key portion, as the prediction depending on it will best fit
the measurements. A direct consequence of this workflow is that the number of hypotheses to be made
grows exponentially in the number of secret key bits involved in the side channel prediction.
      </p>
      <p>
        Countermeasures aimed at protecting block cipher implementations can be classified ashiding [
        <xref ref-type="bibr" rid="ref12">12</xref>
        ],
masking [
        <xref ref-type="bibr" rid="ref11 ref14">11, 14</xref>
        ] and morphing [
        <xref ref-type="bibr" rid="ref2 ref3 ref4">2–4</xref>
        ]. The masking countermeasures provide a formally proven lower
bound on the computational effort required to the attacker to subvert the protection. They invalidate
the correlation between the quantities employed to predict the power consumption and the actual values
processed by the underlying device. The principle is to add one or more random values (a.k.a., masks)
to every sensitive intermediate variable. Sensitive variables are the ones storing a value depending on a
portion of the cipher key.
      </p>
      <p>In a masked implementation, each sensitive intermediate value is represented as split in a number of
shares, s, which are all needed for its reconstruction For example, s shares are obtained as s−1 random
values and the xor combination of them with the original input. The target algorithm is modified to
perform the entire computation on the set of share-split values recombining them only at the end.</p>
      <p>The instantaneous power consumption is independent from the original (non-masked) value, as
unpredictable random values are newly generated at each run of the cipher. Typically, masking techniques
are categorized by the number of masks, d=s−1, employed for each sensitive value, which is known
as the order of the masking. A d-th-order masking can be broken by a (d+1)-th-order attack through
combining d+1 measurements of the computations of different shares during the same cipher execution.</p>
      <p>
        Currently, state of the art masking schemes are the Ishai-Sahai-Wagner (ISW masking) [
        <xref ref-type="bibr" rid="ref11">11</xref>
        ] and
Threshold Implementations (TIs) [
        <xref ref-type="bibr" rid="ref14">14</xref>
        ]. While the former has been proposed as a generic framework
to perform share-split computations of generic Boolean operators (and, not and xor), the latter was
explicitly designed to be employed in dedicated hardware implementations, ensuring that also
transitions stemming from signal glitches do not leak information. In [
        <xref ref-type="bibr" rid="ref14">14</xref>
        ] the ISW masking and the TIs
were proven equivalently provably secure in the case of software implementations (with careful register
reuse). The ISW masking scheme, employed to secure our case study ciphers, has an O(s2)
computational complexity in protecting ands and ors, an O(s) for xors, and an O(1) complexity for nots.
In addition to the computation of Boolean functions, to protect actual implementations of block ciphers
the share-splitting of load operations must be dealt with.
      </p>
      <p>
        The only provably secure scheme providing a constructive framework to perform secure table
lookups on share split values for any number of shares is described in [
        <xref ref-type="bibr" rid="ref8">8</xref>
        ], and relies on adding fresh
randomness to the entire contents of the s-way split table at each load. The proposed algorithm has
a computational complexity of O(n2), where n is the number of table elements. Finally, we recall that
protecting with a provably secure SCA countermeasure only the portion of the block cipher where less
than the entire key is required to compute an intermediate value was proven to have the same
computational security margin as protecting the entire cipher [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ]. The key intuition making the proof hold is
that leading a SCA exploiting the leakage coming from a computation involving the entire cipher key is
equivalent to sorting in order of likelihood of being correct the entire keyspace.
3
      </p>
    </sec>
    <sec id="sec-3">
      <title>Vulnerability Assessment Analysis</title>
      <p>
        In this section we provide the preliminary notions on data-flow analysis, and subsequently report the
enhanced key material identification allowing the analysis in [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ] to be applied to any block cipher.
Definition 3.1 (Control-Flow Graph). Given a program P as a sequence of statements, a Control-Flow
Graph (CFG) is a directed graph GC(V, AC) where each statement is a vertex in V , and the arcs are
ordered pairs of vertexes (v1, v2)∈AC, indicating that v1∈V precedes v2∈V in program order.
Definition 3.2 (Data-Flow Graph). Given a program P as a sequence of statements, a Data-Flow Graph
(DFG) is a directed graph GD(V, AD) where each statement is a vertex in V , and the arcs are ordered
pairs of vertexes (v1, v2)∈AD, indicating that the statement in v2 has as an operand (i.e., uses) a value
computed (i.e., defined) by v1.
      </p>
      <p>From now on, we will also indicate the elements of V as nodes and consider both GC(V, AC) and
GD(V, AD) as augmented graphs containing two additional nodes, vbegin, vend, such that vbegin acts
as the immediate predecessor of all the nodes which do not have one, and vend acts as the immediate
successor of all the nodes without successors. Moreover we will also consider the nodes of the graphs
to be composed of single operation statements. A static analysis of a program P , represented either as
its CFG or DFG, is called Data-Flow Analysis (DFA) if it aims to describe a well-defined property on
how P manipulates its data at runtime. Being a static technique a DFA will only be able to compute a
conservative approximation of the said property as no knowledge on the actual runtime execution flow
is available to it. More formally, the definition of a DFA is as follows.</p>
      <p>Definition 3.3 (Data-flow Analysis) . Let P be a program, represented as either GC(V, AC) or GD(V, AD).
Let BVn be an n-dimensional Boolean lattice, n ≥ 1, endowed with a partial ordering relation closed
with respect to two operations, named as meet (t) and join (u), which yield the minimum and
maximum of any pair of elements in BVn. A Data-Flow Analysis decorates each node of GC(V, AC) (resp.
GD(V, AD)) with an element of BVn and describes a well-defined property of P through computing the
solution of a set of simultaneous equations over the elements of BVn.
A practical example of DFA is the computation of a program property known as reaching definitions ,
i.e.: the identification of all the possible points on the CFG of the program,GC(V, AC), where a variable
visible from a program statement may have been defined. In this context, the semantics of an element
of BVn map each one of its Boolean components to a the definition point of a program variable on the
CFG. The solution of the set of simultaneous equations checked by the DFA consists in the values in
BVn (one for each node of CFG), which are expected to have a bit set if the corresponding definition
point is visible from the statement to which the element of BVn at hand is bound.</p>
      <p>Depending on the nature of the program property which is being computed, it is commonplace to
categorize data-flow analyses into forward DFAs or backward DFAs. Furthermore, the aforementioned
set of simultaneous equations is expressed using use of the concepts of In-Set and Out-set, which are
formally defined as follows.</p>
      <p>Definition 3.4 (In-Set, Out-Set). Given a CFG GC(V, AC), In(v) is defined for each statement v∈V
the input set as the collection of elements in BVn associated to all immediate predecessors of v:
In(v)={ dv0 ∈BVn | dv0 is bound to v0, v0∈pred(v) }. The output set of a statement v, denoted as
Out(v) is defined as In(v)∪{dv}, where dv is the element of BVn bound to v.</p>
      <p>For each node v of the CFG (resp. the DFG) of a program, the data-flow equations describing the
property at hand can be specified as follows:</p>
      <sec id="sec-3-1">
        <title>F orward</title>
        <p>(Out(v)</p>
        <p>In(v)
= fv(In(v))
= Fp∈pred(v) Out(p)</p>
      </sec>
      <sec id="sec-3-2">
        <title>Backward</title>
        <p>(In(v)</p>
        <p>Out(v)
= fv0 (Out(v))
= Fs∈succ(v) In(s)
where pred(v) and succ(v) denote the sets of immediate predecessors and the immediate successors of
v, while fv(·) and fv0 (·) are functions depending on the nature of the considered property which specify
the local computations to be performed on the values in BVn associated with In(v) and Out(v).</p>
        <p>The program property is computed by the DFA through applying iteratively the data-flow equations
to an initial assignment of the values dv∈BVn for each node v in GC(V, AC) (resp. GD(V, AD)) until a
fixed point is reached. Usually, a DFA solver implements an iterative visiting strategy of the CFG (resp.
DFG) which keeps a worklist of nodes. Such a list is initialized with all v∈V and, until it is empty, a
node is evicted to apply the data-flow equations to its In-set and Out-set. Once done so, all the nodes
having their In-set or Out-set modified as a result are added to the worklist. Sound data-flow analyses
have a proof of termination which is provided in terms of the existence of a fixed point for each possible
initial assignment to the program nodes.
3.1</p>
        <p>Security oriented DFA
To define a resistance metric against SCA for each instruction of a block cipher, we consider the data
dependencies holding between the user key loading instructions and the outputs of every other
instruction of the program. We model these data dependencies binding to each output bit of an instruction as
an element b∈BV|k|, where |k| is the size in bits of the user key of the block cipher. The result of our
DFA sets the i-th component of b to one if the associated output bit of the instruction depends on the
i-th user key bit. It is useful to group all the elements of BV|k| bound to the output bits of a given node
v of the CFG as a |v| × |k| Boolean matrix, where |v| is the size (in bits) of the output of the node. The
SCA resistance of an instruction is formalized as follows.</p>
        <p>Definition 3.5 (SCA resistance). Let v be a CFG node to which is associated a |v|×|k| Boolean matrix
and let COUNT(j) be the count of the components of the j-th row of the matrix set to one, i.e., the number
of user key bits on which the j-th output bit of v depends on. The SCA resistance of v, r(v), is defined as
minj (COUNT(j)) if COUNT(j)&gt;0 for at least one value of j, or ⊥ if the entire output of the instruction
does not depend on the user key.
Source Code
Front-end</p>
        <p>Extended
Intermediate
Representation</p>
        <p>(IR)
Optimization</p>
        <p>Passes
Targeted Key</p>
        <p>Material
Identification
SCA Resistance</p>
        <p>Computation
Forward DFA</p>
        <p>with
Targeted Key</p>
        <p>Backward DFA</p>
        <p>with
Targeted Key</p>
        <p>Decorated IR
Countermeasure</p>
        <p>Application
Protected IR
Back-end
Protected
Binary Code</p>
        <p>We note that, given the SCA resistance of an instruction v, r(v), an adversary will require a
computational effort Ω(2r(v)) to perform a key retrieval guessing r(v) bits. The computation of the SCA
resistance is performed through a sequence of static code analyses and transformations performed by
the front-end and middle-end of the LLVM compiler infrastructure as depicted in Figure 1.
Compiler Front-End and Optimization Passes. First of all, we modified theclang LLVM front-end
to recognize three attributes with the standard GNU syntax, which are employed by the programmer to
mark i) the variables containing the block cipher input and ii) user key, and iii) the tabulated nonlinear
functions named substitution boxes (SBoxes). To tag instructions in a way that survives the optimization
passes of LLVM, we employ the input and key values as arguments of opaque intrinsics, defined to have
memory affecting side effects. We run the entire set of optimizations of the middle end (-O3), bar the
ones able to identify patterns in the code which can be substituted with a call to the C standard library
(e.g., replacing a memory copy with a call to memcpy). The LLVM Intermediate Representation (IR)
emitted by the front-end is in Single Static Assignment form: a 1:1 binding between an instruction v∈V
and its defined variable is present. We will employ the two concepts interchangeably from now on, and
consider the IR as the program P out of which GC(V, AC) and GD(V, AD) are built.</p>
        <p>User Key Dependency Propagation. The user key dependency propagation pass is the first one of
our analysis. Its purpose is to compute the data dependency of the entire cipher and key schedule from
the user (i.e., non expanded) key. To this end, we compute a partition of the nodes of GC(V, AC) in
three subsets, Vks, Vc, Va according to whether they belong to the key schedule, the cipher body, or to
eventual ancillary code, respectively. Such a partition is computed as a simple forward DFA, of which
the property is constituted by a two bit vector, the first one indicating if the node lies in Vks, and the
second one if it is in Vc. The function of the DFA equations sets the first bit only if all the nodes having
their result used by the current instruction are in Vks, while the second bit is set if at least one of the
operands is in Vc. The initial state of the data-flow marks as belonging to Vc all the instructions tagged
with our intrinsics, while the key schedule bit is set only on the key-load ones. The results of this
analysis will be employed by the Forward/Backward DFA with Targeted Key passes (see Figure 1).</p>
        <p>Subsequently, a second DFA computes the data dependency of each operation from the user key.
To this end, the computed property is described as a |v|×|k| Boolean matrix Uv. The DFA solver
initializes, for all v∈V , the Uv matrices to zero, save for the ones bound to user key-load instructions,
which have the appropriate |v|×|v| submatrix set to the identity matrix, to represent the 1:1 dependency
of a user key bit from itself. The fv(·) function of the forward DFA considers the user key dependencies
Algorithm 3.1: Target Key Material Identification</p>
        <p>Input: GC(V, AC): CFG of a block cipher with a |k| bits user key; δs(v) : V →{0, . . . , dmax}: map of a node v∈V to its distance
from vbegin of GD(V, AD); dmax is the height of the DFG; Uv: matrix of user key dependencies for v ∈ V
Output: T : set of elements of Vks containing target key material, ⊥ if no viable assignment
Data: f , o, b: bit vectors of size |k|; 0, 1: constant |k| bit vectors, zero- and one-filled.</p>
        <p>
          F : Set of triples (v, c, l) where v ∈ V , where c, l are Boolean vectors of length |k| containing the subkey bits bound to v and
left over as a result of an unconstrained choice
1 b ← 0; T ← ∅; F ← ∅
2 for d ← 1 to dmax do
3 foreach v ∈ V s.t. δ(v) = d do
4 f ← ORROWWISE(Uv) ∧ ¬b
5 o, F ← GREEDYOPTIMIZE(v, Uv, f , F )
6 if o 6= 0 then
7 b ← b ∨ CHECKCONSTRAINTS(v, f , o, F )
8 T ← T ∪ {v}
9 if b = 1 then return T
10 return ⊥
of the operands of v, and sets its Uv combining the ones of its operands. The user key dependencies of
a single bit of the output of v, i.e., a row of Uv, are obtained computing the elementwise Boolean-or
combination of the rows corresponding to the bits of the operands required to compute it. If v is a bitwise
operation, its fv(·) function derives Uv matrix as the row-wise or of the matrices of its operands. By
contrast, the fv(·) for arithmetic operations take into account also the effects of borrows and carries. For
an in-depth description of the individual fv(·) functions we refer the reader to [
          <xref ref-type="bibr" rid="ref1">1</xref>
          ].
        </p>
        <p>
          Target Key Material Identification. Once the first pass of the analysis has computed the contents of
the U matrices for all the instructions, we proceed to the identification of the subkey bits which yield
the best adversary choice during an attack. While such an identification is easy in the case of AES,
as reported in [
          <xref ref-type="bibr" rid="ref1">1</xref>
          ], due to the nature of the cipher keyschedule, it is not always immediate to determine
which set of intermediate variables are the most favorable to be guessed by the adversary to derive
the user key when a generic cipher is considered. To compute this set, we rely on the conservative
simplification that the keyschedule of the cipher is always invertible, assuming that the adversary knows
an amount of key material which is both equal to the user key size and depending on all of it. Such a
simplification favors the adversary, which, in case the aforementioned assumption does not hold, will
be required to extract the entire key material produced by the keyschedule via SCA.
        </p>
        <p>Consequentially, the set of key material bits which will be the target of the actual SCA needs to
fulfill the following properties: i) its size is greater or equal than the user key size, ii) for each user
key bit, at least one of its members depends on it, iii) the entirety of its members are not dominated
by the remaining key material on the GD(V, AD), iv) its size is minimized. Conditions i) and ii) ensure
the computation of the user key employing the retrieved key material, while condition iii) ensures the
minimization of the adversary effort. Condition iv) is imposed so that no key material which cannot be
derived from SCA extracted one, is selected.</p>
        <p>To derive the set of instructions T ⊂Vks containing the target key material as output, the first step is
to compute a map δs(·) :V →N which expresses the distance of a given instruction from vbegin in the
GD(V, AD). Subsequently a map δe(·) :V →N which expresses the distance from vend is also computed.
Such maps can be computed performing a breadth first visit ofGD(V, AD), following the definition-use
chains in it. Two maps are required, as the optimal choice of an adversary for the target key material is
different, depending on whether the data available to her is the input or the output of the cipher. For the
sake of clarity, we consider from now on the former case, noting that the latter is analogous, provided
that care is taken to reverse the direction of the analyses. Once the δs(·) map is available, the target key
identification pass proceeds to employ Algorithm 3.1 to compute the setT , initializing it as empty (line
1). To determine 1:1 binding between the user key bits and the target key material bits satisfying
conditions i) and ii), a |k|-bit sized vector b is employed to keep track of which user key bits have already
been bound. Such a vector is initially set to 0 (line 1). The examination of the user key dependency
matrix Uv of an instruction v may have a significant degree of freedom in choosing which user key bits
should be bound to the target key material ones. Indeed, its |v|-bit output may depend on all the |k|&gt;|v|
user key bits. Since a bijection is desired, Algorithm 3.1 will perform an arbitrary choice locally, and
memorize it in the form of a triple (v, c, l) containing the instruction v, which user key bits were chosen
to be bound c, and which ones to be left l, respectively. Such an information is stored in the set F ,
initially empty (line 1), which is exploited to optimize the target key material selection process.</p>
        <p>After initializing b, T and F , Algorithm 3.1 examines the elements of Vks starting from the ones
closer to vbegin in GD(V, AD) (lines 2-10) and tries to bind all the user key bits as soon as possible. To
this end, the computation starts with determining which of the user key bits, on which the output of v
depends, are still free from binding (line 4). Such bits, which are deduced removing the bound ones
from the row-wise Boolean-or reduction of Uv, are stored in the |k|-bit long vector: f .</p>
        <p>Subsequently, to the GREEDYOPTIMIZE procedure attempts to ameliorate the current user key
dependency choice Uv for the current node v exploiting the information on which bindings have already
been made, and which ones had freedom of choice in being done as memorized in f and F In particular,
for each element (v0, c, l) of F , GREEDYOPTIMIZE checks if a) some of the bits bound to v0 can also
be bound to the output of v, and b) some of the unbound bits in v0 cannot be bound to v. If this is the
case, it is possible to optimize the decision of the bits to be bound to the output of v having it relieve
v0 of some of its arbitrarily assigned bits, in exchange for v0 taking care of bits which cannot be bound
in v. Since the nodes of v are visited in increasing depth order, GREEDYOPTIMIZE effectively realizes
swaps which guarantee condition iii), i.e., no set of target key material bits dominates strictly the chosen
one on the DFG. GREEDYOPTIMIZE returns both an optimized choice bit vector o, and the updated set
F . If the optimized binding selection contained in o suggests that at least a user key bit should be bound
to the output of v, i.e., o6=0, (line 6) Algorithm 3.1 proceeds to add the contents of o to the bound bits
contained in b after verifying the feasibility of the binding invoking the CHECKCONSTRAINTS
function. The CHECKCONSTRAINTS verifies that the amount of user key bits which should be bound in the
outputs of v does not exceed |v|, and, if that is the case, limits the amount of the bound bits to |v|, adding
an element to the F set to memorize the choice made. Upon completing the visit of all the nodes with
a given depth, Algorithm 3.1 checks whether all the user key bits are bound (line 9) and, if that is the
case, returns the set T . The reason for checking this condition at the end of the visit of the set of nodes
having the same depth is to allow the possible optimization of all last level assignment to take place.
Forward/Backward DFA with Targeted Key and SCA Resistance Computation. After computing
the set of target key material, the analysis passes proceed with the computation of the data dependencies
of all the nodes in Vc from the selected target subkey bits. Such a computation is performed employing
the same DFA used to determine the dependencies from the user key, taking care of considering the
target key material data dependencies as the ones to be propagated. The analysis is performed both in
the form of a forward DFA, and a backward one considering the data dependencies of the inverse
operations, starting from the cipher output. The final result of the computation are two Boolean matrices,
Fv and Bv, containing the data dependencies of each instruction from the target subkey bits. To the
end of computing the SCA resistance of an instruction v, the analysis computes the minimum, non null,
number of key bits which depend on a single output bit of v across both matrices. We note that having
an instruction output bit which depends on no key bits results in the value being irrelevant for SCAs, as
it does not contain any key.</p>
        <p>
          Countermeasure Application. Finally, after the computation of the per-instruction SCA security
margin, we realized a code transformation pass applying systematically the ISW masking scheme [
          <xref ref-type="bibr" rid="ref11">11</xref>
          ] to all
the instructions having a SCA resistance strictly lower than the key size of the cipher. The same pass also
employs the countermeasure proposed by Coron [
          <xref ref-type="bibr" rid="ref9">9</xref>
          ] to secure load operations from SBoxes, exploiting
Instruction Resistance
(a) MISTY1(8 rounds)
(b) Simon (68 rounds)
(c) Serpent (32 rounds)
the intrinsic markers to locate them. Share splitting and recombination instructions are automatically
inserted at the borders of the region of the program to be protected.
4
        </p>
      </sec>
    </sec>
    <sec id="sec-4">
      <title>Experimental Evaluation</title>
      <p>In our case study, we chose a general purpose block cipher, Serpent, and two lightweight ones, MISTY1
and Simon, implemented in C language without any architecture-specific optimization.</p>
      <p>
        We chose Serpent due to its significant security margin, which resulted in the design being selected
as a finalist in the AES contest [
        <xref ref-type="bibr" rid="ref5">5</xref>
        ]. Serpent is a substitution-permutation network, with a128-, 192- or
256-bit key, operating on a 128-bit block in 32 rounds. We will consider the 128-bit key for the sake of
comparison. Serpent is endowed with a substitution stage which allows a bitsliced implementation (no
SBoxes), while its diffusion layer achieves complete diffusion in a single round.
      </p>
      <p>
        MISTY1 is a lightweight cipher designed in 1995, and described in the IETF RFC 2994 [
        <xref ref-type="bibr" rid="ref13">13</xref>
        ]. It has
a Feistel network structure with a 128-bit key, a 64-bit block and an advised number of rounds equal to
8. Whilst being subject to some cryptanalytic attacks, MISTY1 forms the mainstay of KASUMI, later
standardized as A5/3, the cipher used to encrypt third generation mobile networks.
      </p>
      <p>
        Simon is a lightweight block cipher released in 2013 by Beaulieu et al. from the U.S.A. National
Security Agency [
        <xref ref-type="bibr" rid="ref7">7</xref>
        ] and intended to provide sound security in constrained environments. It is a Feistel
network with a very simple F-function, made of a single bitwise and, an exclusive-or, and three
bitwise rotations, plus a key addition. It may act on a variable block size, and with a variable key size:
we consider the 128-bit block, 128-bit key, 68 rounds variant.
      </p>
      <p>
        Figure 2 reports the graphical representation of the results of our security oriented data-flow analysis
on Serpent, MISTY1 and Simon. The ciphers are represented as a sequences of colored tiles, one per
instruction, organized in program order from left to right, and from top to bottom. The figure shows the
SCA resistance of each instruction executed during a cipher run, with colors ranging over a chromatic
scale from 1 (red) to 128 (blue). The higher the resistance value, the higher the computational effort
required to perform a secret key retrieval. The maximum resistance value (128 in our case) corresponds
to the computational effort required for an exhaustive user key search [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ]. In Figure 2, a row represents
one cipher round for both Serpent and MISTY1, while it represents two for Simon. From Figure 2
(a), it appears that the internal structure of MISTY1 is unfriendly towards tailored protection against
SCA. Indeed, if a security margin against SCAs matching the one against theoretical attacks is desired,
the vast majority of cipher instructions requires the application of countermeasures. By contrast, both
Simon and Serpent exhibit a very fast combination of the entire key material with the cipher state,
leading to the need of protecting only 16 rounds and 4 rounds out of 68 and 32, respectively. Such a
gap in requirements is due to the sound diffusion strategy adopted by both ciphers, which turns out to
be more effective in the case of Serpent thanks to its well structured linear diffusion layer. The slower
diffusion in Simon is to be expected as the only operations performing it are the bitwise rotations of its
F-function.
      </p>
      <p>
        Performance Evaluation. We conducted our performance evaluation measuring both implementations
of the aforementioned three ciphers plus the one of AES-128 cipher. To provide a fair comparison with
the results of [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ], which used a different protection scheme for the SBoxes, we collected the results for
AES employing the same protection scheme employed for the other ciphers, i.e., [
        <xref ref-type="bibr" rid="ref9">9</xref>
        ] (see Section 3).
Our enhanced analysis identified the target key material in AES-128 matching the selection in [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ].
      </p>
      <p>The first evaluation platform is the STM32F4Discovery board equipped with a STM32F407 μC
based on a 120MHz ARMv7 Cortex-M4, and endowed with 128kiB of SRAM, 1MiB of Flash and a
hardware Random Number Generator (RNG). The binaries are run on the bare metal, and the timings
are gathered measuring the time between the assertion and deassertion of a GPIO on 30 runs of the
cipher. The second platform is an Imagination Creator CI20 board equipped with an Ingenic JZ4780
SoC. The SoC is based on a dual core MIPS32 clocked at 1.2GHz, with a 32k L1 I- and D-cache, a
512k L2 I&amp;D cache, and 1GiB of DDR3 RAM, running Debian wheezy. Timing measurements where
collected using the Linux kernel timer CLOCK_PROCESS_CPUTIME_ID, which only accounts for cycles
attributed to the current process. To compensate for the higher variability of the environment, timings
have been averaged over 104 measurements. To supply random values for the masking countermeasures,
we employed the hardware RNG on the Cortex-M4, and the system-wide RNG on the MIPS based one.</p>
      <p>
        Table 1 reports the results of our experimental campaign. Applying tailored SCA countermeasures,
i.e., applying them to all instructions with a SCA resistance lower than the key size, allows to obtain
significant performance improvements over a fully protected implementation. Block ciphers which
employ lookup tables, i.e., AES and MISTY1 have the largest absolute gain in execution time, although the
smallest relative one. Moreover, block ciphers which do not use lookup tables for non-linear functions
are significantly faster when endowed with SCA countermeasures. It is worth noting that both Serpent
and Simon, which are slower than MISTY1 in their unprotected implementation, are at least one order
of magnitude faster when protected. Indeed, it is interesting how Serpent outperforms Simon on both
platforms if tailored SCA countermeasures are applied, despite the latter being explicitly designed as a
lightweight cipher, and the former not being so. Finally, it is interesting to note how the 10× difference
in clock speed between the two platforms yields only moderate speedups for the fully protected variants
of AES and MISTY1. This behavior is caused by the increase in the size of the lookup tables required
by the share splitting of [
        <xref ref-type="bibr" rid="ref8">8</xref>
        ], which adversely effects caches. Table 1 reports also the figures obtained
measuring the size of the .text segment of the emitted binaries for both platforms. Such a metric,
which is typically critical in code-memory constrained devices such as μCs is still relevant on high-end
embedded platforms, as a small code segment fits more easily in the L1 instruction cache. Considering
this metric, MISTY1 exhibits the interesting feature of having substantially the same code size,
regardless of the fact that a tailored or a complete application of SCA countermeasures is made. This is due to
the cost of the share splitting and recombination instructions which are needed when a transition from
an protected instruction to an unprotected one is made. However, despite retaining the smallest code
size among fully protected implementations, MISTY1 is bested by both Simon and Serpent if a tailored
protection is applied. In particular, a third-order tailored masking applied to Serpent results in a code
size smaller than the one of a first-order protected AES on both platforms.
5
      </p>
    </sec>
    <sec id="sec-5">
      <title>Concluding Remarks</title>
      <p>
        In this work we presented an enhancement to the existing security oriented data-flow technique, which
allows the automatic identification of the target key material in a block cipher. Such an enhanced
analysis allowed us to analyze block ciphers with nontrivial target key material choices, and to
evaluate a tailored protection to their implementation as a secure alternative to a code morphing approach
such as [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ]. The relevance of the extended analysis is witnessed by the experimental results showing
how a high-security, general purpose cipher, Serpent, which is outperformed by a factor of four by a
lightweight one, MISTY1, achieves speedups up in the 93×–190× range when protected
implementations are considered, without losses on the overall computational security margin [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ].
      </p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          [1]
          <string-name>
            <given-names>Giovanni</given-names>
            <surname>Agosta</surname>
          </string-name>
          , Alessandro Barenghi, Massimo Maggi, and
          <string-name>
            <given-names>Gerardo</given-names>
            <surname>Pelosi</surname>
          </string-name>
          .
          <article-title>Compiler-based side channel vulnerability analysis and optimized countermeasures application</article-title>
          .
          <source>In The 50th Annual Design Automation Conference</source>
          <year>2013</year>
          , DAC '
          <volume>13</volume>
          , Austin, TX, USA, May 29 - June 07,
          <year>2013</year>
          , pages
          <fpage>81</fpage>
          :
          <fpage>1</fpage>
          -
          <lpage>81</lpage>
          :
          <fpage>6</fpage>
          ,
          <year>2013</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          [2]
          <string-name>
            <given-names>Giovanni</given-names>
            <surname>Agosta</surname>
          </string-name>
          , Alessandro Barenghi, and
          <string-name>
            <given-names>Gerardo</given-names>
            <surname>Pelosi</surname>
          </string-name>
          .
          <article-title>A code morphing methodology to automate power analysis countermeasures</article-title>
          . In Patrick Groeneveld, Donatella Sciuto, and Soha Hassoun, editors,
          <source>The 49th Annual Design Automation Conference</source>
          <year>2012</year>
          , DAC '
          <fpage>12</fpage>
          , San Francisco, CA, USA, June 3-7,
          <year>2012</year>
          , pages
          <fpage>77</fpage>
          -
          <lpage>82</lpage>
          . ACM,
          <year>2012</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          [3]
          <string-name>
            <given-names>Giovanni</given-names>
            <surname>Agosta</surname>
          </string-name>
          , Alessandro Barenghi, Gerardo Pelosi, and
          <string-name>
            <given-names>Michele</given-names>
            <surname>Scandale</surname>
          </string-name>
          .
          <article-title>A Multiple Equivalent Execution Trace Approach to Secure Cryptographic Embedded Software</article-title>
          .
          <source>In The 51st Annual Design Automation Conference</source>
          <year>2014</year>
          , DAC '
          <fpage>14</fpage>
          , San Francisco, CA, USA, June 1-5,
          <year>2014</year>
          , pages
          <fpage>210</fpage>
          :
          <fpage>1</fpage>
          -
          <lpage>210</lpage>
          :
          <fpage>6</fpage>
          . ACM,
          <year>2014</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          [4]
          <string-name>
            <given-names>Giovanni</given-names>
            <surname>Agosta</surname>
          </string-name>
          , Alessandro Barenghi, Gerardo Pelosi, and
          <string-name>
            <given-names>Michele</given-names>
            <surname>Scandale</surname>
          </string-name>
          .
          <article-title>The MEET approach: Securing cryptographic embedded software against side channel attacks</article-title>
          .
          <source>IEEE Trans. on CAD of Integrated Circuits and Systems</source>
          ,
          <volume>34</volume>
          (
          <issue>8</issue>
          ):
          <fpage>1320</fpage>
          -
          <lpage>1333</lpage>
          ,
          <year>2015</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          [5]
          <string-name>
            <given-names>Ross</given-names>
            <surname>Anderson</surname>
          </string-name>
          ,
          <string-name>
            <given-names>Eli</given-names>
            <surname>Biham</surname>
          </string-name>
          , and
          <string-name>
            <given-names>Lars</given-names>
            <surname>Knudsen</surname>
          </string-name>
          .
          <article-title>Serpent: A proposal for the advanced encryption standard</article-title>
          .
          <source>NIST AES Proposal</source>
          ,
          <volume>174</volume>
          ,
          <year>1998</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          [6]
          <string-name>
            <given-names>Alessandro</given-names>
            <surname>Barenghi</surname>
          </string-name>
          and
          <string-name>
            <given-names>Gerardo</given-names>
            <surname>Pelosi</surname>
          </string-name>
          .
          <article-title>On the Security of Partially Masked Software Implementations</article-title>
          . In Pierangela Samarati, editor,
          <source>SECRYPT 2014 - Proceedings of the 11th International Conference on Security and Cryptography</source>
          , Vienna, Austria,
          <fpage>28</fpage>
          -
          <issue>30</issue>
          <year>August</year>
          ,
          <year>2014</year>
          , pages
          <fpage>138</fpage>
          :
          <fpage>1</fpage>
          -
          <lpage>138</lpage>
          :
          <fpage>8</fpage>
          . SciTePress,
          <year>2014</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          [7]
          <string-name>
            <given-names>Ray</given-names>
            <surname>Beaulieu</surname>
          </string-name>
          , Douglas Shors,
          <string-name>
            <given-names>Jason</given-names>
            <surname>Smith</surname>
          </string-name>
          ,
          <string-name>
            <surname>Stefan</surname>
          </string-name>
          Treatman-Clark,
          <article-title>Bryan Weeks, and Louis Wingers. The SIMON and SPECK families of lightweight block ciphers</article-title>
          .
          <source>IACR Cryptology ePrint Archive</source>
          ,
          <year>2013</year>
          :
          <volume>404</volume>
          ,
          <year>2013</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          [8]
          <string-name>
            <surname>Jean-Sébastien Coron</surname>
          </string-name>
          .
          <article-title>Higher Order Masking of Look-Up Tables</article-title>
          .
          <source>In EUROCRYPT</source>
          <year>2014</year>
          , volume
          <volume>8441</volume>
          <source>of LNCS</source>
          , pages
          <fpage>441</fpage>
          -
          <lpage>458</lpage>
          . Springer,
          <year>2014</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>
          [9]
          <string-name>
            <surname>Jean-Sébastien</surname>
            <given-names>Coron</given-names>
          </string-name>
          , Johann Großschädl, and Praveen Kumar Vadnala.
          <article-title>Secure conversion between boolean and arithmetic masking of any order</article-title>
          .
          <source>In CHES 2014</source>
          , pages
          <fpage>188</fpage>
          -
          <lpage>205</lpage>
          . Springer,
          <year>2014</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref10">
        <mixed-citation>
          [10]
          <string-name>
            <surname>Flavio</surname>
            <given-names>D.</given-names>
          </string-name>
          <string-name>
            <surname>Garcia</surname>
            , David Oswald,
            <given-names>Timo</given-names>
          </string-name>
          <string-name>
            <surname>Kasper</surname>
            , and
            <given-names>Pierre</given-names>
          </string-name>
          <string-name>
            <surname>Pavlidès</surname>
          </string-name>
          .
          <article-title>Lock it and still lose it - on the (in)security of automotive remote keyless entry systems</article-title>
          .
          <source>In USENIX Security 16</source>
          , USA, Aug.,
          <year>2016</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref11">
        <mixed-citation>
          [11]
          <string-name>
            <surname>Yuval</surname>
            <given-names>Ishai</given-names>
          </string-name>
          , Amit Sahai, and David Wagner. Private Circuits:
          <article-title>Securing Hardware against Probing Attacks</article-title>
          . In D. Boneh, editor,
          <source>CRYPTO</source>
          , volume
          <volume>2729</volume>
          <source>of LNCS</source>
          , pages
          <fpage>463</fpage>
          -
          <lpage>481</lpage>
          . Springer,
          <year>2003</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref12">
        <mixed-citation>
          [12]
          <string-name>
            <surname>Stefan</surname>
            <given-names>Mangard</given-names>
          </string-name>
          , Elisabeth Oswald, and Thomas Popp.
          <source>Power Analysis Attacks - Revealing the Secrets of Smart Cards</source>
          . Springer,
          <year>2007</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref13">
        <mixed-citation>
          [13]
          <string-name>
            <given-names>Mitsuru</given-names>
            <surname>Matsui</surname>
          </string-name>
          and
          <string-name>
            <given-names>Hidenori</given-names>
            <surname>Ohta</surname>
          </string-name>
          .
          <article-title>A description of the MISTY1 encryption algorithm</article-title>
          ,
          <year>2000</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref14">
        <mixed-citation>
          [14]
          <string-name>
            <surname>Oscar</surname>
            <given-names>Reparaz</given-names>
          </string-name>
          , Begül Bilgin, Svetla Nikova, Benedikt Gierlichs, and
          <string-name>
            <given-names>Ingrid</given-names>
            <surname>Verbauwhede</surname>
          </string-name>
          .
          <article-title>Consolidating masking schemes</article-title>
          .
          <source>In Advances in Cryptology-CRYPTO</source>
          <year>2015</year>
          , pages
          <fpage>764</fpage>
          -
          <lpage>783</lpage>
          . Springer,
          <year>2015</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref15">
        <mixed-citation>
          [15]
          <string-name>
            <surname>Daehyun</surname>
            <given-names>Strobel</given-names>
          </string-name>
          , David Oswald, Bastian Richter, Falk Schellenberg, and
          <string-name>
            <given-names>Christof</given-names>
            <surname>Paar</surname>
          </string-name>
          .
          <article-title>Microcontrollers as (in)security devices for pervasive computing applications</article-title>
          .
          <source>Proceedings of the IEEE</source>
          ,
          <volume>102</volume>
          (
          <issue>8</issue>
          ):
          <fpage>1157</fpage>
          -
          <lpage>1173</lpage>
          ,
          <year>2014</year>
          .
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>