<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>p4bl0's blog rss feed</title>
    <link>https://p4bl0.net/shebang/</link>
    <description>5 last published articles</description>
    <generator>fugitive - https://clandest.in/fugitive</generator>
    <lastBuildDate>2019-08-13</lastBuildDate>
    <item>
      <title><![CDATA[Liberty vs security: a human-sized case]]></title>
      <link>https://p4bl0.net/shebang/liberty-vs-security.html</link>
      <description><![CDATA[
<p>
  Security has a price. When talking about computer security, this price can be
  paid in different ways, such as performance or ease of use (or both). When
  talking about meatspace security, whether it is nation-wide or individually,
  the price is paid in freedom and privacy. I claim that the loss in freedom is
  usually much higher than the gain in security. Of course I'm far from being
  the only one to claim that. However it is quite difficult to convince people
  that this is true, because most of the time the discussion is about
  nation-wide political decisions, and it is hard to grasp all the whys and the
  wherefores of their implications.
</p>
<p>
  I don't want to wave hands explaining how massive surveillance is a bigger
  loss in individual freedom <i>and</i> collective freedom than it is a win in
  security. I've tried that before and it doesn't really work on the people who
  need to be convinced. Instead, I'm going to tell you a story, a real story,
  that happened to me a bit more than two years ago, and which I think is a
  perfect analogy of our topic, except it is a human-sized story so it is
  easier to grasp all the implications and identify the problems. As it turns
  out, the story is not only an analogy of the security versus liberty
  trade-off, but also to the differences between proprietary and free (as in
  freedom) software, or between closed and open formats, showing that openness
  is necessary for liberty and privacy.
</p>
<p>
  It all begins in the summer of 2012. I had just finished my master degree and
  I would be starting my PhD soon. I had to move out of my room at the student
  dorms and find a new place to live for three years, in the Paris area. Even
  in the suburbs of Paris, the prices of real estate are so high that one PhD
  funding is not sufficient on its own to pay for decent housing for three
  years. Getting together with roommates is the obvious solution. Two of my
  friends were in the same situation and would do their PhD in the same area,
  so we decided to look for an apartment together.
</p>
<p>
  After long weeks of searching and dealing with real estate agencies (trust me
  in the Paris area it is anything but pleasant to deal with those), we found a
  very nice place in our price range, so we decided to go for it.
</p>
<p>
  We moved in on August 20. As I said, we were three roommates. The problem is,
  we had only two keys of the apartment. What's the problem you say? Just go
  make a duplicate (or more!) of the key and you're all set. We wish.
</p>
<p>
  It happens that the door of the apartment is a fancy security door, and that
  its lock is a fancy security lock… and that the keys thus have to be fancy
  security keys. What does &quot;fancy security&quot; means?
</p>
<p>
  It means that the door and the lock are very strong and hard to break, and
  that the keys are very difficult to reproduce. Actually, only the company
  that issued the whole system in the first place can do it. Let's call them
  FancySec.
</p>
<p>
  For the real estate agency, it means that we can't get burglarized (yeah,
  because burglars always come in through the front door, <i>it is known
  khaleesi</i>). It also means that they know exactly how many keys we have:
  since they are the only possible interlocutor of FancySec, we have to go
  though them if we want any additional keys.
</p>
<p>
  For us, it is supposed to make us feel safe and happy. In practice, not so
  much.
</p>
<ul>
  <li>
    <em>We can't make a duplicate when we want.</em> With regular keys if we
    want to host some friends for more than one night or if one of us want to
    give a key to his girlfriend or boyfriend, we just go to any locksmith, and
    that's it. Instead we are forced to ask the real estate agency (thanks for
    our privacy) and it can take weeks before we get the new key.
  </li>
  <li>
    <em>This kind of keys is expensive.</em> Regular keys for regular doors
    cost less than 10€ to duplicate, these keys are almost 70€. Seven times
    more expensive. Given the price to reinstall a new FancySec lock and get a
    bunch of new FancySec keys, it would be better if none of us accidentally
    lose his key.
  </li>
  <li>
    <em>What is the added security, really?</em> What are the odds that there
    is someone in the world with the aim to rob our apartment, knowing that
    this person did not manage to steal one of our keys, would have to enter
    our building using a code and then a key to get to the elevator or stairs
    which lead to our apartment, and then try to open our door? I believe the
    odds of that are so small that the probability that we get robbed would not
    even change if we had a regular door with regular convenient keys.<br />
    The main idea here is that the door is not the limiting factor: even if the
    FancySec door is a thousand times more resistant, it does not matter
    because the probability someone tries to break in is extremely small.
  </li>
  <li>
    <em>What if FancySec goes out of business?</em> Or if they just stop
    supporting our key models? That's not an entirely absurd supposition, it
    happens that FancySec is closed for vacation in August, so when we moved in
    our apartment we had to wait for fifteen days before the real estate agency
    could order an additional duplicate of the key from them and it took ten
    more days to finally get the key. In the meantime we had to juggle with two
    keys for the three of us so most of the time when we weren't home there was
    one of our FancySec keys in our mailbox which I bet can be opened with a
    screwdriver…<br /> This is something that needs to be emphasized: strong
    security is often so inconvenient that the necessary workarounds actually
    lessen the overall security.
  </li>
</ul>
<p>
  So what conclusions can we draw from this story? First, that what we have is
  actually not additional security, but rather the illusion of additional
  security. Second, that we pay for this illusion of security with a lot of
  inconveniences, and with loss of freedom and privacy, and that both can
  result in weakening the actual security level. Third, that closed proprietary
  formats are a bad thing, even away from the digital world.
</p>
<p>
  Just replace the real estate agency with a government, the burglars with
  terrorists, FancySec with the army / intelligence agencies / big private
  companies, and for instance our door with an airport or our keys with
  surveillance cameras. You'll get the big picture. The trade-offs are the
  same. We lose a freakin' lot of freedom and convenience to get a security
  improvement that is irrelevant most of the time. It is important to
  struggle for our freedom and not let the security rhetoric get to us.
</p>
]]></description>
      <author>p4bl0</author>
      <guid>https://p4bl0.net/shebang/liberty-vs-security.html</guid>
      <pubDate>2015-02-19 12:57:33 +0100</pubDate>
    </item>
    <item>
      <title><![CDATA[PhD midterm report: Formal Software Methods for Cryptosystems' Implementation Security]]></title>
      <link>https://p4bl0.net/shebang/phd-midterm-formal-software-methods-cyrptosystems-implementation-security.html</link>
      <description><![CDATA[
<p>
  What follows is the content of my PhD midterm report. I'm posting it here
  because I sometimes feel like there is a bad <i>a priori</i> about doing a
  PhD. At least in communities like Hacker News and some subreddits, there are
  regularly stories where someone tells how bad it was for him or her to do a
  PhD. Well, I know that as a single individual I'm as statistically
  insignificant as them, but I really, truly enjoy my life as a PhD student. I
  like doing research. I like teaching. I'm happy. And I guess I feel like
  sharing, so that there are not bad stories only about what doing a PhD is
  like. Here I'm only talking about the research part, but I hope the text will
  reflect how much I'm enjoying myself :-).
</p>
<div class="math">
<h2 class="noc">Introduction</h2>
<p>
  My PhD started in October 2012. Since then, I have been working
  with <a href="http://perso.telecom-paristech.fr/~guilley">Sylvain Guilley</a>
  and <a href="http://perso.telecom-paristech.fr/~danger">Jean-Luc Danger</a>
  in the field of <em>implementation security</em>. More precisely, I try to
  increase the use of <a href="https://en.wikipedia.org/wiki/Formal_methods"
  class="wikipedia"><em>formal methods</em></a> in this field, at the software
  level since it is what I know and where I come from in my previous studies.
  Implementation security is a very young subject (approximately 15 years old),
  and a very practical one: a lot of industrial research-and-development /
  engineering participate to the field, which explains why the use of formal
  methods is not widespread, to say the least. I will explain why and how I aim
  to spread the use formal methods, but first I will give a quick overview of
  what is implementation security.
</p>
<p>
  When we say <strong>implementation security</strong>, we talk about actual,
  physical implementations, but the security we are talking about is the one of
  what is implemented<sup><a href="#note-1" id="note-1-back">1</a></sup>. Of
  course, we work on systems which security is important,
  namely <a href="https://en.wikipedia.org/wiki/Cryptosystem"
  class="wikipedia"><em>cryptosystems</em></a>. It is obvious that
  cryptographic implementations should not leak any information about the
  secrets that they are trying to protect. What is less obvious however, is
  that even a perfect cryptographic algorithm can leak information once it is
  implemented on a physical device, because of the properties of the physical
  device itself: computing needs resources, and the usage of these resources
  may give information on the computation. Indeed,
  so-called <em>side-channels</em> such as power consumption, time,
  temperature, or electro-magnetic radiation may directly depend on the running
  computation. Attacks exploiting such bias are
  called <a href="https://en.wikipedia.org/wiki/Side_channel_attack"
  class="wikipedia"><em>side-channel attacks</em></a>. They work very well in
  practice; for instance, on an
  unprotected <a href="https://en.wikipedia.org/wiki/Advanced_Encryption_Standard"
  class="wikipedia">AES</a> cryptoprocessor, it is possible to extract the full
  key in about 1000 side-channel measurements (refer to
  <a href="http://www.dpacontest.org/v2/">DPA Contest v2</a>). Thus, it is
  mandatory to implement <em>countermeasures</em> against them. Side-channel
  attacks are <em>passive attacks</em>, meaning that only observation is needed
  to carry them out. When the attacker is able to have an impact on the system,
  it is also possible to conduct <em>active attacks</em>. For instance in the
  case of <em>fault injection attacks</em>, the goal is to modify the result of
  the computation to get something which will leak information if the attacker
  knows how to interpret it. Such attacks can be more or
  less <em>invasive</em>: faults can be injected by voluntarily glitching the
  clock or the voltage (non-invasive) or by using a laser to modify values in
  memory or registers at some point in the computation (invasive).
</p>
<p>
  The use of <strong>formal methods</strong> to study these attacks and the
  countermeasures against them to be able to trust the cryptosystems seems
  obvious. Yet, their use in our domain is timidly beginning only now. This can
  be explained by several facts. First, this domain is very practical, and many
  advances come from the industry rather than the academia, which means that
  they are more of an engineering effort than research result. Indeed, many
  countermeasures are developed by trial-and-error until they reach some sort
  of fixed-point, at which time they are put in production. Most of the time,
  this is satisfactory enough from an engineering point of view. Also, formal
  analysis requires a formal model of the studied system, but there is a
  discrepancy between a proper modelization and the complexity of an actual
  physical system which may seem like an obstacle.
</p>
<p>
  This covers why I think it is important to spread the use formal methods in
  the field of implementation security. I intend my PhD to be a substantial
  participation toward this end. This means my goals are to address the reasons
  why formal methods are not widely used yet. I aim at doing so by lifting
  several scientific and technological barriers:
</p>
<ul>
  <li>
    Develop models adapted to the study of side-channel and fault injection
    attacks and countermeasures, finding ways to avoid the discrepancy between
    the model and the actual implementation;
  </li>
  <li>
    Use these models to develop methods, and the tools which implement them,
    that are easy to comprehend and use, and &quot;sexy&quot; enough to make
    people want to use or mimic them;
  </li>
  <li>
    Show the necessity of formal methods by using the tools to break, prove,
    and/or optimize existing countermeasures, thereby improving the
    state-of-the-art.
  </li>
</ul>
<p>
  In the rest of this report I will present the work I have done since the
  beginning of my PhD and how I intend to pursue it in the coming months.
</p>
<h2 class="noc">Formally Proved Security of Assembly Code Against Power Analysis</h2>
<p>
  I started my work with the study
  of <a href="https://en.wikipedia.org/wiki/Power_analysis"
  class="wikipedia"><em>power analysis</em></a> software countermeasures. My
  goal was to have a tool which would be able to automatically protect
  arbitrary assembly code against power analysis attacks, while provably
  preserving the semantics of the code, and which would output a provably
  protected code.
</p>
<p>
  Power consumption is traditionally modeled by Hamming weight of values or
  Hamming distance of updates of values [<a href="#KJJ99">KJJ99</a>]. This
  modelization is not perfect but it works well enough in practice and is used
  to carry out real-world power analysis attacks.
</p>
<p>
  There are two main types of countermeasures against power analysis:
  &quot;palliative&quot; versus &quot;curative&quot;. The two defense
  strategies are 1. to make the leakage constant, irrespective of the
  manipulated data (<em>hiding</em>
  or <em>balancing</em> [<a href="#MOP06">MOP06</a>, Chp. 7] strategy), or 2.
  to make the leakage as decorrelated from the manipulated data
  (<em>masking</em> [<a href="#MOP06">MOP06</a>, Chp. 9] strategy) as possible.
  The second strategy, masking, relies on randomness which is a strong
  requirement and is hard to capture formally. The first strategy, balancing,
  appears to have a clear invariant (constant leakage) and a software
  implementation of balancing using <em>dual-rail with precharge logic</em>
  (DPL [<a href="#TV06">TV06</a>]) had been developed by our
  lab [<a href="#HDD11">HDD11</a>]. So I naturally went with the DPL balancing
  option.
</p>
<p>
  The DPL countermeasure consists in computing on a redundant representation:
  each bit <i>b</i> is implemented as a pair <i>(y<sub>False</sub>,
  y<sub>True</sub>)</i>. The bit pair is then used in a protocol made up of two
  phases:
</p>
<ol>
  <li>
    a <em>precharge</em> phase, during which all the bit pairs are
    zeroized <i>(y<sub>False</sub>, y<sub>True</sub>) = (0, 0)</i>, such that
    the computation starts from a known reference state;
  </li>
  <li>
    an <em>evaluation</em> phase, during which the pair <i>(y<sub>False</sub>,
    y<sub>True</sub>)</i> is equal to <i>(1, 0)</i> if it carries the logical
    value <i>0</i>, or <i>(0, 1)</i> if it carries the logical value <i>1</i>.
  </li>
</ol>
<p>
  The DPL has mostly been used as a hardware-level countermeasure, as it was
  developed as such. However, it is possible to implement it in software, by
  working at the bit level. By replacing each sensitive instruction with a
  <em>DPL macro</em> which uses a look-up table to compute the same result as the
  original instruction while respecting the DPL protocol.
</p>
<h4>Results</h4>
<p>
  I defined a <em>generic assembly language</em> and
  its <a href="https://en.wikipedia.org/wiki/Semantics_%28computer_science%29"
  class="wikipedia">semantics</a>. It is generic in that it uses a restricted
  set of very generic instructions that can be mapped one-to-one to and from
  virtually any actual assembly language. This makes it possible to work with a
  single assembly language, while still working on the actual implementation,
  thus avoiding the discrepancy between it and the model. It permitted to
  develop a tool, called
  <span class="sf">paioli</span>, that is able to automatically DPLize
  any <a href="https://en.wikipedia.org/wiki/Bit_slicing"
  class="wikipedia"><em>bitsliced</em></a> assembly code.
  Many <a href="https://en.wikipedia.org/wiki/Block_cipher"
  class="wikipedia"><em>block-ciphers</em></a> are already available bitsliced
  as it is a common optimization technique [<a href="#Bih97">Bih97</a>]. The
  transformation has been proved to be <em>semantics preserving</em>. Another
  part of the tool does
  a <a href="https://en.wikipedia.org/wiki/Symbolic_execution"
  class="wikipedia"><em>symbolic execution</em></a> of the resulting code
  which <a href="https://en.wikipedia.org/wiki/Static_program_analysis"
  class="wikipedia"><em>statically</em></a> verifies that the <em>security
  invariant</em> is well respected. The symbolic execution of the assembly code
  is carried out using sets of possible values instead of actual values. Each
  bit of the sensitive data (the <em>clear text</em> of the message and
  the <a href="https://en.wikipedia.org/wiki/Key_%28cryptography%29"
  class="wikipedia"><em>encryption key</em></a>) starts with a value
  of <i><i>{</i>0, 1<i>}</i></i> (or their DPL encoded counterparts) and each
  instruction computes all the possible results given the sets of values of its
  operands. After each cycle, the security invariant is verified: for each
  register, memory cell, and address bus that has changed, the Hamming distance
  between any of its previous possible values and any of its new possible
  values should be constant. If everything goes well, the code is formally
  proved to be well-balanced.
</p>
<p>
  Using this tool we were able to produce a provably protected implementation
  of the <a href="https://en.wikipedia.org/wiki/PRESENT_%28cipher%29"
  class="wikipedia"><em>PRESENT</em></a> [<a href="#BKL+07">BKL+07</a>]
  block-cipher's encryption algorithm. However, this is a software level proof,
  and when the code is run on actual, non-idealized hardware, not all the bits
  leak the same amount (some physical bit may consume more power than others).
  Thus, before DPLizing a code, it is important to <em>profile</em> the
  hardware on which it will be implemented. This profiling allows to choose the
  two bits which leak the more similarly, which will then be used as
  the <i>y<sub>True</sub></i> and <i>y<sub>False</sub></i> in the DPL protocol
  to guarantee maximum security. I am currently working on this with
  <a href="http://www.informatik.uni-trier.de/~ley/pers/hd/n/Najm:Zakaria.html">Zakaria
  Najm</a> using the DPL balanced PRESENT on an
  AVR <a href="https://en.wikipedia.org/wiki/Smart_card"
  class="wikipedia">smartcard</a>. Preliminary results are very promising. This
  work shows that it is feasible to use formal methods in the field of
  implementation security even when the security properties are physical rather
  than functional.
</p>
<h4>Publications</h4>
<p>
  I gave a talk at the 2013 edition of
  the <a href="http://cosade.org/">COSADE</a> conference, and presented a
  poster at the 2013 edition of
  the <a href="http://www.chesworkshop.org/">CHES</a> conference. We posted a
  preliminary version of the paper on the IACR ePrint
  Archive [<a href="#RGN13">RGN13</a>]. Each of these received a warm welcome
  and attracted the interest of researchers who are already waiting for the
  final version of the paper to be published. The final paper is soon to be
  completed and will be submitted to the 2014 edition of the CHES conference.
</p>
<h4>Future work</h4>
<p>
  I need to clean/rewrite the code and make it usable as it is currently
  &quot;research code&quot; and no one except me can be expected to use it as
  is. I will also make an attempt at automated bitslicing of arbitrary assembly
  code, it will be interesting to explore what can be done automatically with a
  reasonable complexity. Another interesting path to follow would be to try to
  find optimizations which do not break the DPL protocol of balanced code,
  since we have a tool able to statically verify the respect of the security
  invariant.
</p>
<h2 class="noc">Formal Proofs of CRT-RSA Countermeasures Against BellCoRe Attacks</h2>
<p>
  Another subject I worked on is the formal proof of countermeasures against
  the <a href="https://en.wikipedia.org/wiki/Bellcore"
  class="wikipedia"><em>BellCoRe</em></a> fault injection attack
  on <a href="https://en.wikipedia.org/wiki/RSA_%28cryptosystem%29#Using_the_Chinese_remainder_algorithm"
  class="wikipedia"><em>CRT-RSA</em></a> (RSA [<a href="#RSA78">RSA78</a>]
  optimized for memory usage and computation time using
  the <a href="https://en.wikipedia.org/wiki/Chinese_remainder_theorem"
  class="wikipedia"><em>Chinese remainder theorem</em></a>).
</p>
<p>
  RSA is both an <a href="https://en.wikipedia.org/wiki/Encryption"
  class="wikipedia"><em>encryption</em></a> and
  a <a href="https://en.wikipedia.org/wiki/Digital_signature"
  class="wikipedia"><em>signature</em></a> scheme. It relies on the identity
  that for all message <i>0 ≤ M &lt; N</i>,
  <i>(M<sup>d</sup>)<sup>e</sup> ≡ M <i>mod</i> N</i>, where
  <i>d ≡ e<sup>-1</sup> <i>mod</i> φ(N)</i>,
  by <a href="https://en.wikipedia.org/wiki/Euler%27s_theorem"
  class="wikipedia">Euler's theorem</a>. For example, if Alice generates the
  signature <i>S = M<sup>d</sup> <i>mod</i> N</i>, then Bob can verify it by
  computing <i>S<sup>e</sup> <i>mod</i> N</i>, which must be equal to <i>M</i>
  unless Alice is only pretending to know <i>d</i>. Therefore <i>(N, d)</i> is
  called the <a href="https://en.wikipedia.org/wiki/Private_key"
  class="wikipedia">private key</a>, and <i>(N, e)</i>
  the <a href="https://en.wikipedia.org/wiki/Public_key"
  class="wikipedia">public key</a>.
</p>
<p>
  In CRT-RSA, the private key is a more rich structure than simply <i>(N,
  d)</i>: it is actually a 5-tuple <i>(p, q, d<sub>p</sub>, d<sub>q</sub>,
  i<sub>q</sub>)</i>, where:
</p>
<ul>
  <li>
    <i>d<sub>p</sub> &middot; d <i>mod</i> (p-1)</i>,
  </li>
  <li>
    <i>d<sub>q</sub> &middot; d <i>mod</i> (q-1)</i>, and
  </li>
  <li>
    <i>i<sub>q</sub> &middot; q<sup>-1</sup> <i>mod</i> p</i>.
  </li>
</ul>
<p>
  The algorithm is presented below:
</p>
<pre><strong>Input:</strong> Message M, key (p, q, d<sub>p</sub>, d<sub>q</sub>, i<sub>q</sub>).
<strong>Output:</strong> Signature M<sup>d</sup> mod N.
 
S<sub>p</sub> = M<sup>d<sub>p</sub></sup> mod p
S<sub>q</sub> = M<sup>d<sub>q</sub></sup> mod q
S = S<sub>q</sub> + q &middot; (i<sub>q</sub> &middot; (S<sub>p</sub> - S<sub>q</sub>) mod p)
<b>return</b> S</pre>
<p>
  Injecting faults during the computation of CRT-RSA can yield malformed
  signatures that expose the prime factors (<i>p</i> and <i>q</i>) of the
  public modulus (<i>N = p &middot; q</i>) [<a href="#BLK97">BLK97</a>]. If the
  intermediate variable <i>S<sub>p</sub></i> (resp. <i>S<sub>q</sub></i>) is
  returned faulted as <i style="color:red;">S<sub>p</sub></i>
  (resp. <i style="color:red;">S<sub>q</sub></i>), then the attacker gets an
  erroneous signature <i style="color:red;">S</i>, and is able to
  recover <i>p</i> (resp. <i>q</i>) as <i><i>gcd</i>(N, S
  - <span style="color:red;">S</span>)</i>.
</p>
<p>
  Notwithstanding, computing without the fourfold acceleration conveyed by the
  CRT is definitely not an option in practical applications. Therefore, many
  countermeasures have appeared that consist in step-wise internal checks
  during the CRT computation.
</p>
<h4>Results</h4>
<p>
  I wrote a tool called
  <a href="http://pablorauzy.fr/sensi/finja.html"><span class="sf">finja</span></a>
  which works within the framework
  of <a href="https://en.wikipedia.org/wiki/Modular_arithmetic"
  class="wikipedia"><em>modular arithmetic</em></a>, which is the mathematical
  framework of CRT-RSA computations. The tool allows a full fault coverage of
  CRT-RSA algorithm, thereby keeping the proof valid even if the code is
  transformed (<i>e.g.</i>, optimized, compiled, partitioned in
  software/hardware, or equipped with dedicated countermeasures). The general
  idea is to represent the computation term as a tree (just like
  the <a href="https://en.wikipedia.org/wiki/Abstract_syntax_tree"
  title="Abstract syntax tree" class="wikipedia">AST</a> in
  a <a href="https://en.wikipedia.org/wiki/Compiler"
  class="wikipedia">compiler</a>
  or <a href="https://en.wikipedia.org/wiki/Interpreter"
  class="wikipedia">interpreter</a>) which encodes the computation properties.
  This term is then simplified by our tool. The simplification works like a
  naive interpreter would, except that it is a pure <em>symbolic
  interpretation</em> using rules from arithmetic in
  the <i>ℤ</i> <a href="https://en.wikipedia.org/wiki/Ring_%28mathematics%29"
  class="wikipedia">ring</a> and
  its <i>ℤ<sub>n</sub></i> <a href="https://en.wikipedia.org/wiki/Subring"
  class="wikipedia">subrings</a>. The tool also know about a few theorems,
  namely <a href="https://en.wikipedia.org/wiki/Fermat%27s_little_theorem"
  class="wikipedia"><em>Fermat's little theorem</em></a>, its
  generalization <em>Euler's theorem</em>, the <em>Chinese remainder
  theorem</em>, and a particular case of
  the <a href="https://en.wikipedia.org/wiki/Binomial_theorem"
  class="wikipedia"><em>binomial theorem</em></a>. Fault injections in the
  computation term are simulated by changing the properties of a subterm, thus
  impacting the simplification process. The computation is given in a
  convenient high-level input language. Indeed, the model of the computation
  can remain as abstract as pseudocode such as it is usually employed in
  papers, especially for the computational parts<sup><a href="#note-2"
  id="note-2-back">2</a></sup>. An attack success condition is also given and
  used on the term resulting from the simplification to check whether the
  corresponding attack works on it.
</p>
<p>
  The tool was used to break implementations which were known to be broken and
  to formally prove two others: that of Aumüller <i>et
  al.</i> [<a href="#ABF+02">ABF+02</a>], and that of
  Vigilant [<a href="#Vig08">Vig08</a>] (a repaired version by Coron
  <i>et al.</i> [<a href="#CGM+10">CGM+10</a>]). Prior to this work no existing
  BellCoRe countermeasures had been proved, except for a specific
  implementation of the latter [<a href="#CCGV13">CCGV13</a>], but we found
  that the repaired version included fixes for weaknesses that did not exist in
  the original version. Indeed, these weaknesses had been introduced by eager
  speed-oriented <a href="https://en.wikipedia.org/wiki/Optimization"
  class="wikipedia">optimizations</a>. We also found that 2 out of its 9
  verifications were useless, and that some added security against power
  analysis actually weaken the fault injections resistance. This work shows the
  importance of using formal methods in the field of implementation security,
  not only to be able to really trust cryptosystems, but also to enable speed
  and security oriented optimizations.
</p>
<h4>Publications</h4>
<p>
  A first paper [<a href="#RG13">RG13</a>] was accepted at the 2013 edition of
  the <a href="http://www.proofs-workshop.org/">PROOFS</a> workshop and an
  extended version will appear in a future issue of the
  <a href="https://www.springer.com/computer/security+and+cryptology/journal/13389">JCEN</a>
  journal. We have recently submitted a second paper, which is currently under
  review.
</p>
<h4>Future work</h4>
<p>
  The
  <a href="http://pablorauzy.fr/sensi/finja.html"><span class="sf">finja</span></a>
  tool is only able to inject faults in the data and cannot fault instructions
  yet, it would be interesting to explore this kind of fault
  injections [<a href="#HMER13">HMER13</a>]. The tool would also benefit a lot
  from the <a href="https://en.wikipedia.org/wiki/Parallel_computing"
  class="wikipedia">parallelization</a> of its computations: multiple-fault
  attacks can take very long to compute and the different possible faults
  injections are entirely independent.
</p>
<p>
  If possible I will work with
  <a href="http://software.imdea.org/~gbarthe/">Gilles Barthe</a>
  and <a href="http://fdupress.net/">François Dupressoir</a> at the
  <a href="http://www.imdea.org/">IMDEA</a> lab (Madrid, Spain) in the
  beginning of 2014 as they showed an interest in my work on fault injection.
  We will try to use the
  <a href="http://www.easycrypt.info/">EasyCrypt</a> [<a href="#BGZB09">BGZB09</a>]
  tool that they work on to do the same kind of formal proofs, and also to use
  <a href="https://en.wikipedia.org/wiki/Program_synthesis"
  class="wikipedia">program synthesis</a> techniques to automatically find
  countermeasures.
</p>
<p>
  Sylvain and I will also work on a high-order variation of the Aumüller
  countermeasure which would be customizable to resist any order (multiple
  faults) of fault injection attacks.
</p>
<h2 class="noc">Other Perspectives</h2>
<p>
  I would like to use
  <a href="http://pablorauzy.fr/sensi/finja.html"><span class="sf">finja</span></a>
  to formally study fault injection attacks and countermeasures on other
  cryptosystems than CRT-RSA, and to use <span class="sf">paioli</span> to
  protect at least one other block-cipher, such as AES, on another hardware
  platform.
</p>
<p>
  Apart from this and the future work I listed for the two subjects that I
  already started to tackle, I have two ideas that I'd like to investigate:
</p>
<ul>
  <li>
    try to model the caching behavior of microprocessors and use the same kind
    of symbolic execution techniques to formally study timing attacks;
  </li>
  <li>
    try to use a <a href="https://en.wikipedia.org/wiki/Homomorphic_encryption"
    class="wikipedia">homomorphic</a> cryptosystem such as the one
    of <a href="https://en.wikipedia.org/wiki/Paillier_cryptosystem"
    class="wikipedia">Paillier</a> to mask (against power analysis) its own
    computation.
  </li>
</ul>
<hr />
<h2 class="noc">References</h2>
<dl>
  <dt id="ABF+02">ABF+02</dt>
  <dd>
    Christian Aumüller, Peter Bier, Wieland Fischer, Peter Hofreiter, and
    Jean-Pierre Seifert. <em>Fault Attacks on RSA with CRT: Concrete Results
    and Practical Countermeasures</em>. In Burton S. Kaliski, Jr., Cetin Kaya
    Koç, and Christof Paar, editors, CHES, volume 2523 of <em>Lecture Notes in
    Computer Science</em>, pages 260–275. Springer, 2002.
  </dd>
  <dt id="BDL97">BDL97</dt>
  <dd>
    Dan Boneh, Richard A. DeMillo, and Richard J. Lipton. <em>On the Importance
    of Checking Cryptographic Protocols for Faults</em>. In <em>Proceedings of
    Eurocrypt’97</em>, volume 1233 of LNCS, pages 37–51. Springer, May 11-15 1997.
    Konstanz, Germany. DOI: 10.1007/3-540-69053-0 4.
  </dd>
  <dt id="BGZB09">BGZB09</dt>
  <dd>
    Gilles Barthe, Benjamin Grégoire, and Santiago Zanella-Béguelin. <em>Formal
    certification of code-based cryptographic proofs</em>. In <em>36th ACM
    SIGPLAN-SIGACT Symposium on Principles of Programming Languages</em>, POPL
    2009, pages 90–101. ACM, 2009.
  </dd>
  <dt id="Bih97">Bih97</dt>
  <dd>
    Eli Biham. <em>A Fast New DES Implementation in Software</em>. In Eli
    Biham, editor, FSE, volume 1267 of <em>Lecture Notes in Computer
    Science</em>, pages 260–272. Springer, 1997.
  </dd>
  <dt id="BKL+07">BKL+07</dt>
  <dd>
    Andrey Bogdanov, Lars R. Knudsen, Gregor Leander, Christof Paar, Axel
    Poschmann, Matthew J. B. Robshaw, Yannick Seurin, and Charlotte Vikkelsoe.
    <em>PRESENT: An Ultra-Lightweight Block Cipher</em>. In <em>CHES</em>,
    volume 4727 of LNCS, pages 450–466. Springer, September 10-13 2007. Vienna,
    Austria.
  </dd>
  <dt id="CCGV13">CCGV13</dt>
  <dd>
    Maria Christofi, Boutheina Chetali, Louis Goubin, and David Vigilant.
    <em>Formal verification of an implementation of CRT-RSA Vigilant’s
    algorithm</em>. <em>Journal of Cryptographic Engineering</em>, 3(3), 2013.
    DOI: 10.1007/s13389-013-0049-3.
  </dd>
  <dt id="CGM+10">CGM+10</dt>
  <dd>
    Jean-Sébastien Coron, Christophe Giraud, Nicolas Morin, Gilles Piret, and
    David Vigilant. <em>Fault Attacks and Countermeasures on Vigilant’s RSA-CRT
    Algorithm</em>. In Luca Breveglieri, Marc Joye, Israel Koren, David
    Naccache, and Ingrid Verbauwhede, editors, <em>FDTC</em>, pages 89–96. IEEE
    Computer Society, 2010.
  </dd>
  <dt id="HDD11">HDD11</dt>
  <dd>
    Philippe Hoogvorst, Jean-Luc Danger, and Guillaume Duc. <em>Software
    Implementation of Dual-Rail Representation</em>. In <em>COSADE</em>,
    February 24-25 2011. Darmstadt, Germany.
  </dd>
  <dt id="HMER13">HMER13</dt>
  <dd>
    Karine Heydemann, Nicolas Moro, Emmanuelle Encrenaz, and Bruno Robisson.
    <em>Formal Verification of a Software Countermeasure Against Instruction Skip
    Attacks</em>. Cryptology ePrint Archive, Report 2013/679, 2013.
    http://eprint.iacr.org/.
  </dd>
  <dt id="KJJ99">KJJ99</dt>
  <dd>
    Paul C. Kocher, Joshua Jaffe, and Benjamin Jun. <em>Differential Power
    Analysis</em>. In <em>Proceedings of CRYPTO’99</em>, volume 1666 of LNCS,
    pages 388–397. Springer-Verlag, 1999.
  </dd>
  <dt id="MOP06">MOP06</dt>
  <dd>
    Stefan Mangard, Elisabeth Oswald, and Thomas Popp. <em>Power Analysis
    Attacks: Revealing the Secrets of Smart Cards</em>. Springer, December
    2006. ISBN 0-387-30857- 1, http://www.dpabook.org/.
  </dd>
  <dt id="RG13">RG13</dt>
  <dd>
    Pablo Rauzy and Sylvain Guilley. <em>A Formal Proof of Countermeasures
    Against Fault Injection Attacks on CRT-RSA</em>. Cryptology ePrint Archive,
    Report 2013/506, 2013. http://eprint.iacr.org/.
  </dd>
  <dt id="RGN13">RGN13</dt>
  <dd>
    Pablo Rauzy, Sylvain Guilley, and Zakaria Najm. <em>Formally Proved
    Security of Assembly Code Against Power Analysis</em>. Cryptology ePrint
    Archive, Report 2013/554, 2013. http://eprint.iacr.org/.
  </dd>
  <dt id="RSA78">RSA78</dt>
  <dd>
    Ronald L. Rivest, Adi Shamir, and Leonard M. Adleman. <em>A Method for
    Obtaining Digital Signatures and Public-Key Cryptosystems</em>. Commun.
    ACM, 21(2):120–126, 1978.
  </dd>
  <dt id="TV06">TV06</dt>
  <dd>
    Kris Tiri and Ingrid Verbauwhede. <em>A digital design flow for secure
    integrated circuits</em>. IEEE Trans. on CAD of Integrated Circuits and
    Systems, 25(7):1197–1208, 2006.
  </dd>
  <dt id="Vig08">Vig08</dt>
  <dd>
    David Vigilant. <em>RSA with CRT: A New Cost-Effective Solution to Thwart
    Fault Attacks</em>. In Elisabeth Oswald and Pankaj Rohatgi,
    editors, <em>CHES</em>, volume 5154 of LNCS, pages 130–145. Springer, 2008.
  </dd>
</dl>
<hr />
<ol class="footnotes">
  <li id="note-1">
    Note however that in some threat-models the security of the implemented
    system and the physical security of the device which implements it are tied
    together, but that's not at all what I'm working on.
    <a href="#note-1-back">&uarr;</a>
  </li>
  <li id="note-2">
    For example, a fault in the implementation of the multiplication is either
    inoffensive, and we do not need to care about it, or it affects the result
    of the multiplication, and our model takes it into account without going
    into the details of how the multiplication is computed.
    <a href="#note-2-back">&uarr;</a>
  </li>
</ol>
</div>
]]></description>
      <author>p4bl0</author>
      <guid>https://p4bl0.net/shebang/phd-midterm-formal-software-methods-cyrptosystems-implementation-security.html</guid>
      <pubDate>2013-11-18 19:01:19 +0100</pubDate>
    </item>
    <item>
      <title><![CDATA[Using AutoProxy to browse Onions, EepSites, and the clearweb with Firefox]]></title>
      <link>https://p4bl0.net/shebang/autoproxy-i2p-eepsites-tor-onions-firefox.html</link>
      <description><![CDATA[
<p>
  I've been using <a href="http://www.torproject.org/">Tor</a> for a long time,
  and I recently started to use <a href="http://www.i2p2.de/">I2P</a> too.
  Before that I used to launch a new instance of my browser which would tunnel
  all its requests through Tor SOCKS proxy when I wanted to use Tor. But when I
  want to test things with Tor and I2P it becomes very inefficient to have
  multiple browser windows which look all the same but use different proxies.
</p>
<p>
  I quickly found out about the FoxyProxy Firefox addon, which can do just what
  I needed. It allows Firefox to select a proxy depending on URL patterns. But
  FoxyProxy is a proprietary software, which I was not happy with. In addition
  to that it more or less tries to sell you HTTP proxies access, which I don't
  need.
</p>
<p>
  And then I found
  <a href="https://addons.mozilla.org/en-us/firefox/addon/autoproxy/">AutoProxy</a>,
  which can do the same job, but is free as in freedom! Yay.
</p>
<p>
  However, AutoProxy has a less user friendly interface. It uses the same
  syntax for its URL based rules as AdBlock+, so if you are familiar with that
  it's easy to configure. I was not, since I use AdBlock+ only with the
  EasyList+FR subscription and never added custom rules.
</p>
<p>
  For those of you who would like to use AutoProxy to be able to browse the web
  and Tor Hidden Services and EepSites seamlessly, here is how to setup
  AutoProxy:
</p>
<p>
  You will need two rule groups, one for the I2P proxy, and one for the Tor
  one. The I2P proxy is an HTTP proxy running on localhost:4444 with the
  default configuration. The Tor proxy is a SOCKS v5 proxy running on
  localhost:9050 with the default configuration.
</p>
<p>
  Then you will have to add a rule in each group. For the Tor group, the rule
  is <code>||*.onion^</code>. For the I2P group, you guessed it right, the rule
  is <code>||*.i2p^</code>. The <code>||</code> means &quot;beginning of the domain
  name&quot;, <code>^</code> means &quot;end of the domain name&quot,
  and as usual <code>*</code> is a wildcard.
<p>
  AutoProxy will display a red exclamation mark on each of these rules' line
  because it estimates that these rules are slow. Don't worry about that, with
  only two rules you'll never feel any difference in terms of speed.
</p>
<p>
  Once you have AutoProxy configured like this, congratulation, you can now
  browse the <a href="http://pablorauzy.fr/">clearweb</a>,
  <a href="http://pablo7c5rgvkxe6a.onion/">Tor Hidden Services</a>,
  and <a href="http://p4bl0.i2p/">EepSites</a> seamlessly in Firefox,
  using only free software!
</p>
]]></description>
      <author>p4bl0</author>
      <guid>https://p4bl0.net/shebang/autoproxy-i2p-eepsites-tor-onions-firefox.html</guid>
      <pubDate>2013-07-18 22:56:43 +0200</pubDate>
    </item>
    <item>
      <title><![CDATA[outline-presentation-mode for Emacs]]></title>
      <link>https://p4bl0.net/shebang/emacs-outline-presentation-mode.html</link>
      <description><![CDATA[
<h2>Context</h2>
<p><small>Feel free to <a href="#outline-presentation">skip</a> this
      section.</small></p>
<p>
  Two weeks ago my <a href="http://www.comelec.enst.fr/recherche/sen">research
  group</a> asked for a practical introduction to
  <a href="http://git-scm.com/">Git</a> for the following week and I
  volunteered for this task. I usually use
  <a href="https://bitbucket.org/rivanvx/beamer">Beamer</a> to make my
  presentations, but I always start by making a plan in a plain text file using
  <a href="https://gnu.org/s/emacs">Emacs</a>
  <a href="https://www.gnu.org/software/emacs/manual/html_node/emacs/Outline-Mode.html">outline-mode</a>.
  Then I generally use a few Emacs
  <a href="https://www.gnu.org/software/emacs/manual/html_node/emacs/Keyboard-Macros.html">keyboard
  macros</a> to put the necessary LaTeX markup
  (<code>\section</code>, <code>\subsection</code>, etc.) around the sections
  titles, then I insert that in my beamer skeleton and start writing the
  content of the slides.
</p>
<p>
  But this time, I don't really know why, I started to fill in the slide
  contents in outline-mode. Naturally, I then wanted to generate my
  presentation directly from that. And as a normal Emacs user (if you allow me
  that oxymoron), I decided that I should be able to do my presentation
  directly from within Emacs. I googled a bit and found, as I expected, tools
  that generate LaTeX from <a href="http://orgmode.org/">org-mode</a> files,
  but also an attempt to do exactly what I wanted on
  <a href="https://github.com/candera/emacs/blob/8b2641318b4bcf91eb22a7d1b1f21c73102e1b61/candera/outline-presentation.el">github</a>.
   I tried it and even though it didn't work quite well and didn't have the
   features I wanted, it was a good starting point. So I started hacking it to
   make it do what I want.
</p>
<h2 id="outline-presentation">outline-presentation-mode</h2>
<h3>Introduction</h3>
<p>
  Let me introduce you to
  <strong><a href="https://code.up8.edu/snippets/1">outline-presentation-mode</a></strong>,
  which is a minor mode for making presentations with outline-mode files. Here
  is how it interprets outline's headings:
</p>
<ul>
  <li>Headings at level 1, 2, and 3 are slides.</li>
  <li>Headings at level greater than 3 are considered like titles inside the
    slides. For the rest of the article I consider them part of the text entry
    of headings at level 1, 2, and 3.</li>
  <li>Headings at level 1 are considered sections. Their slides show their text
    entry plus the level 2 and 3 sub-headings they might have.</li>
  <li>Headings at level 2 and 3 are considered normal slides, so only their
    text entry are shown.</li>
</ul>
<h3>Installation</h3>
<p>
  To install outline-presentation-mode, you need to put
  the <a href="https://code.up8.edu/snippets/1">outline-presentation.el</a>
  elisp file in your Emacs <code>load-path</code> and load it. This can be
  automatized by putting <code>(require 'outline-presentation)</code> in your
  .emacs file. You can of course <kbd>M-x&nbsp;byte-compile-file</kbd> this
  elisp file.
</p>
<h3>Usage</h3>
<p>
  To start a presentation, you simply turn on the minor mode
  using <kbd>M-x&nbsp;outline-presentation-mode</kbd>. The presentation
  starts with the slides that contained the caret.
</p>
<p>
  I want to be able to edit slides even in presentation mode so I use unusual
  keybindings to avoid overriding existing ones. Here are available actions:
</p>
<ul>
  <li><kbd>A-M-n</kbd> moves to the next slide;</li>
  <li><kbd>A-M-p</kbd> moves to the previous slide;</li>
  <li><kbd>A-M-f</kbd> moves to the next section slide (corresponding to an
    outline level 1 heading);</li>
  <li><kbd>A-M-b</kbd> moves to the previous section slide;</li>
  <li><kbd>A-M-a</kbd> moves to the first slide;</li>
  <li><kbd>A-M-t</kbd> displays only the section titles (table of contents);</li>
  <li><kbd>A-M-y</kbd> displays only the slide titles (table of
    contents);</li>
  <li><kbd>A-M-s</kbd> displays the slide which contains the caret (use it in
    one of the two &quot;table of contents&quot; displays);</li>
  <li><kbd>A-M-r</kbd> resumes to the slide from which you jumped to the
    table of contents (this can be used recursively);</li>
  <li><kbd>A-M-q</kbd> quits the presentation mode and goes back to
    outline-mode.</li>
</ul>
<p>
  While the outline-presentation minor mode in on, the position part of the
  modeline contains your position in the presentation (for instance
  &quot;13/42&quot; if you are currently displaying the 13th of 42 slides) in
  addition to the usual position information. If you are displaying the table
  of contents (using <kbd>A-M-t</kbd> or <kbd>A-M-y</kbd> described above),
  this is replaced by &quot;ToC&quot;.
</p>
<p>
  As an example, you can find 
  <a href="http://pablorauzy.fr/files/sen-meeting_2013-01-17.outline">here</a>
  the introduction to git that I gave to my research group. I don't know if the
  slides alone are very useful though. During the presentation I also had a
  terminal opened where I instantly demonstrated everything I talk about in the
  slides.
</p>
<h3>Hooks</h3>
<p>
  You can tell Emacs to increase text size with
  <kbd>M-x&nbsp;text-scale-adjust</kbd> which is bound to
  <kbd>C-x&nbsp;=</kbd> by default. This is useful when using a videoprojector
  to give your presentation. You can do that automatically by adding a hook
  in <code>outline-presentation-mode-hook</code>. Like in this snippet
  from my init.el file:
</p>
<pre><span class="comment-delimiter">;; </span><span class="comment">outline-mode
</span>(add-to-list 'auto-mode-alist
  '(<span class="string">&quot;\\.outline\\'&quot;</span> . outline-mode))
(<span class="keyword">require</span> '<span class="constant">outline-presentation</span>)
(add-hook 'outline-presentation-mode-hook
          (<span class="keyword">lambda</span> () (text-scale-increase <span class="constant">3</span>)))</pre>
<h3>Tips</h3>
<p>
  You can use <kbd>M-x&nbsp;center-line</kbd>
  and <kbd>M-x&nbsp;center-region</kbd> for your title slides. Do not forget
  about <kbd>M-x&nbsp;artist-mode</kbd> either.
</p>
]]></description>
      <author>p4bl0</author>
      <guid>https://p4bl0.net/shebang/emacs-outline-presentation-mode.html</guid>
      <pubDate>2013-01-21 01:01:14 +0100</pubDate>
    </item>
    <item>
      <title><![CDATA[&lambda;-virus]]></title>
      <link>https://p4bl0.net/shebang/lambda-virus.html</link>
      <description><![CDATA[
<p>
  What is a &lambda;-virus? It's a virus in the
  <a href="http://en.wikimedia.org/wiki/Lambda_calculus">&lambda;-calculus</a>!
  The idea comes from a question asked to
  <a href="http://www.naccache.fr/research/">David Naccache</a> by one of his
  former students. They were talking about our
  <a href="http://www.hpl.hp.com/personal/Liqun_Chen/IMACC11-home.htm">IMACC</a>
  article, <q><a href="http://eprint.iacr.org/2011/497">Can a Program
  Reverse-Engineer Itself?</a></q>. In which we define a notion of equivalence
  between a function and an obfuscated version of it, and then show a
  construction to protect functions from obfuscation (i.e., we can retreive
  their original code and also repair them in the environment). The student
  asked if the construction used by <em>oximoron</em> (the implementation of
  the article) could be a protection against a &lambda;-virus. Pr. Naccache
  then asked <a href="http://a3nm.net/">Antoine</a> and me our opinion about
  this idea.
</p>
<p>
  The first thing to do was to define what a &lambda;-virus would actually be.
  I came up with an informal but satisfactory definition of what is an infected
  (i.e., contaminated and contagious) &lambda;-term for a given &lambda;-virus.
  If <var>T</var> is a &lambda;-term then we call <var>T<sub>V</sub></var> the
  &lambda;-term &quot;<var>T</var> infected by the &lambda;-virus
  <var>V</var>&quot;:
</p>
<ul>
  <li>
    If <var>T</var> is a &lambda;-abstraction (which we can see as a function
    or a program), then for any &lambda;-term <var>E</var>,
    <var>(T<sub>V</sub>&nbsp;E)</var> is <var>(T&nbsp;E)<sub>V</sub></var>.
  </li>
  <li>
    If <var>T</var> isn't a &lambda;-abstraction (we can see it as some data,
    e.g., the final result of a computation), then <var>T<sub>V</sub></var> is
    the value of <var>(V*&nbsp;T)</var>, where <var>V*</var> is an arbitrary
    &lambda;-abstraction defined by the creator of <var>V</var>.
  </li>
</ul>
<p>
  The first point, for &lambda;-abstraction, defines how the virus propagates.
  The second one defines how it acts. For instance we can imagine a virus which
  propagates until it infects a function which returns an integer and make this
  function <a href="http://www.xkcd.com/221/">always return 4</a>.
</p>
<p>
  At this stage we can already say that <em>oximoron</em> doesn't protect
  against this kind of attacks (it wasn't supposed to, but it would have been
  cool if it did). But let's forget about that, the idea of a &lambda;-virus is
  fun enough in itself.
</p>
<p>
  One thing we can remark with our definition of &lambda;-virus is that the
  original form of a virus <var>V</var>, the &lambda;-term whose only feature
  is to inoculate the virus to other &lambda;-terms (i.e., <var>Ṽ</var> such
  that for any &lambda;-term <var>T</var>, <var>(Ṽ T)</var> is
  <var>T<sub>V</sub></var>) is simply <var>Id<sub>V</sub></var>. I know it is
  obvious but I find that quite beautiful at the same time.
</p>
<p>
  At first I tought that I would need to use a
  <a href="http://en.wikimedia.org/wiki/Quine_%28computing%29">quine</a>-based
  construction to create the virus, as we did in
  <a href="http://eprint.iacr.org/2011/099"><abbr title="Polymorphic Application System to Transform Internal Signatures"
  style="font-variant:small-caps;">Pastis</abbr></a> and <em>oximoron</em>. It
  would be true if the implementation was actually in &lambda;-calculus, or at
  least working with S-expressions as <em>oximoron</em> does. But we can
  actually implement this notion of virus very easily in any language which has
  <a href="http://en.wikimedia.org/wiki/Closure_%28computer_science%29">closure</a>
  (<a href="http://en.wikimedia.org/wiki/Closure_%28psychology%29">pun</a>
  intended). I did it in Scheme (<a href="http://racket-lang.org/">Racket</a>)
  and I implemented the possibility of adding side effects when the virus
  propagates:
</p>
<pre>(<span class="keyword">define</span> (<span class="function-name">create-virus</span> side-effect tweak)
  (<span class="keyword">define</span> (<span class="function-name">infect</span> target)
    (<span class="keyword">if</span> (procedure? target)
        (<span class="keyword">lambda</span> args
          (side-effect target)
          (infect (apply target args)))
        (tweak target)))
  (infect (<span class="keyword">lambda</span> (x) x)))</pre>
<p>
  The two arguments of <code>create-virus</code> have to be functions. The
  first one is for the side effects the virus creator might want to add. The
  second one is the function the virus should apply to results (the <var>V*</var>
  from earlier).
</p>
<pre>(create-virus (<span class="keyword">lambda</span> (x) null) identity)
<span class="comment">;; will propagate but won't do anything at all</span></pre>
<pre>(<span class="keyword">define</span> tatltuae
  (create-virus
    (<span class="keyword">lambda</span> (x) (displayln <span class="string">&quot;Infected!&quot;</span>))
    (<span class="keyword">lambda</span> (x) (<span class="keyword">if</span> (number? x) <span class="constant">42</span> x))))
<span class="comment">;; will propagate, systematically print &quot;Infected!&quot; on
;; the current output port and replace any integral
;; return value by 42</span></pre>
<pre>&gt; (<span class="keyword">define</span> addn (tatltuae (<span class="keyword">lambda</span> (n) (<span class="keyword">lambda</span> (x) (+ n x)))))
Infected!
&gt; (<span class="keyword">define</span> add13 (addn <span class="constant">13</span>))
Infected!
&gt; (add13 <span class="constant">38</span>) <span class="comment">;; should return 51</span>
Infected!
42</pre>
]]></description>
      <author>p4bl0</author>
      <guid>https://p4bl0.net/shebang/lambda-virus.html</guid>
      <pubDate>2011-09-27 19:16:42 +0200</pubDate>
    </item>
  </channel>
</rss>
