<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Arash Afshar</title>
    <description>The latest articles on Forem by Arash Afshar (@_aafshar_).</description>
    <link>https://forem.com/_aafshar_</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F168413%2Fda2bbb08-2854-4203-899e-4d2cc0ad5716.jpeg</url>
      <title>Forem: Arash Afshar</title>
      <link>https://forem.com/_aafshar_</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/_aafshar_"/>
    <language>en</language>
    <item>
      <title>Secure Machine Learning</title>
      <dc:creator>Arash Afshar</dc:creator>
      <pubDate>Sun, 16 Feb 2020 00:21:06 +0000</pubDate>
      <link>https://forem.com/_aafshar_/secure-machine-learning-3252</link>
      <guid>https://forem.com/_aafshar_/secure-machine-learning-3252</guid>
      <description>&lt;p&gt;In previous posts (&lt;a href="http://arash-afshar.github.io/absolute-security-with-no-trust/"&gt;Zero Trust&lt;/a&gt;, &lt;a href="http://arash-afshar.github.io/oblivious-transfer/"&gt;MPC-1&lt;/a&gt;), I described the importance of Secure Multiparty Computation and showed a simple use case for it, a secure weather application. In this post, I want to skip ahead to a far more advanced application to showcase the amazing things that one can do given the exisitng tools and libraries. More specifically, I will talk about secure machine learning. I will use a popular service such as Grammarly as an example and will described how one can approach implementing a more secure version of it.&lt;/p&gt;

&lt;p&gt;Grammarly can be installed as a browser plugin, it will montior the text that you type in any website and will find grammatical mistakes. It will then offer you fixes for those mistakes. It is a great product but, for their product to work, they need to collect all the content that you type and analyze them (see their &lt;a href="https://www.grammarly.com/privacy-policy"&gt;privacy policy&lt;/a&gt;). I am NOT accusing them of any bad intention, but the simple fact that they need to collect what I type means that I cannot use it for anything related to my work (writing emails, describing architectures, etc) which is the main usecase of their service for me. Therefore, I am in a situation where I have a need for such a product, but my privacy requirements prevent me from using it. Now the question is, is it possible to create such a product that satisfies my privacy requiremnts? I believe the answer is yes and I will describe the steps and tools that are needed in this post.&lt;/p&gt;

&lt;p&gt;Broadly speaking, products such as Grammarly are backed by a Machine Learning (ML) &lt;em&gt;model&lt;/em&gt;. This model needs to be trained on a huge dataset and constantly kept updated with new data. Once a model is trained, the model will be deployed and used to respond to queries from the users. Therefore, to implement a secure verion of this service, at the very least we need to secure each of these steps.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Secure Training: In the training phase, the data must be kept private&lt;/li&gt;
&lt;li&gt;Secure Model: The resulting trained model must not reveal anything about the private data&lt;/li&gt;
&lt;li&gt;Secure Querying: When querying the model, the query data must be private&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  Secure Training
&lt;/h1&gt;

&lt;p&gt;In the training phase, one or more parties have private data. In most cases, these data owners do not have the computational power to run the training and therefore, they will outsource their data to a "cloud". Thus, the goal is to make sure that the "cloud" does not learn the private input. Moreover, the cloud should be able to perform computation on those private data. This is a great use case for Secure Multiparty Computation. The current state-of-the-art papers (&lt;a href="https://eprint.iacr.org/2018/403.pdf"&gt;ABY3&lt;/a&gt;, &lt;a href="https://eprint.iacr.org/2018/442.pdf"&gt;SecureNN&lt;/a&gt;) propose a 3-party setting. In this setting many data owners will outsource their data to these parties (think of them as three "clouds") and these  parties will run the MPC protocls on behalf of the data owners. The &lt;strong&gt;important assumption&lt;/strong&gt; here is that these parties are non-colluding.&lt;/p&gt;

&lt;p&gt;If you are not interested in reading the papers and implementing them yourself, you can check out the great work done by the folks at &lt;a href="https://dropoutlabs.com/"&gt;Dropout Labs&lt;/a&gt;. They are working an a secure version of Tensorflow, called &lt;a href="https://tf-encrypted.io/"&gt;tf-encrypted&lt;/a&gt; which implements the above papers in addition to the &lt;a href="https://bristolcrypto.blogspot.com/2016/10/what-is-spdz-part-1-mpc-circuit.html"&gt;SPDZ&lt;/a&gt; protocol.&lt;/p&gt;

&lt;p&gt;If you want to implement the protocols yourself, you can checkout the &lt;a href="https://github.com/MPC-SoK/frameworks"&gt;MPC-SoK&lt;/a&gt; repository. Marcella Hastings, et al have done an amazing job of collectiong, compiling, documenting, and comparing most of the existing MPC frameworks.&lt;/p&gt;

&lt;h1&gt;
  
  
  Secure Model
&lt;/h1&gt;

&lt;p&gt;From the above, we have a model that has been computed in a secure manner and is shared between three non-colluding parties. But that is not enough! A model that is trained in this fashion can still leak information. An example of an attack that can reveal information about the private inputs from the model is "Model Inversion" attack (e.g., &lt;a href="https://arxiv.org/pdf/1802.08232.pdf"&gt;Secret Sharer&lt;/a&gt;). Assume Alice is a data owner and one of the inputs she has sent to cloud has this format: "Alice A, credit card number: 1234-5678". Now the attacker can start a brute-force attack by querying the model with "Alice A, credit card number: XXX-XXX" where XXX-XXX is brute-forced. In other applications, this would be even worse. Consider an attacker that types "Alice A, credit card number: 123-" and the model auto-completes the rest of the credit card number for the attacker!&lt;/p&gt;

&lt;p&gt;There are different techinques to defend against this kind of attack, including sanitizing the data, anonymizing the data, or using techniques such as &lt;a href="https://en.wikipedia.org/wiki/Differential_privacy"&gt;Differential Privacy&lt;/a&gt; (DP).&lt;/p&gt;

&lt;h1&gt;
  
  
  Secure Querying
&lt;/h1&gt;

&lt;p&gt;Given a secure training phase and assuming that the model itself does not leak any information, we can focus on the deployment. In terms of security of the implementation, this is very similar to the training phase in that MPC can be used to ensure the priavcy of the query data.&lt;/p&gt;

&lt;h2&gt;
  
  
  Final Words
&lt;/h2&gt;

&lt;p&gt;Of course, as I have mentioned in my &lt;a href="http://arash-afshar.github.io/absolute-security-with-no-trust/"&gt;previous post&lt;/a&gt;, having the theoretical solution is not enough and there many more more things that need to be considered before such an application can be ready for secure production use.&lt;/p&gt;

&lt;p&gt;I encourage you to checkout the tutorials on &lt;a href="https://github.com/tf-encrypted/tf-encrypted/tree/master/examples/notebooks/keras-classification"&gt;tf-encrypted with keras and DP&lt;/a&gt; and &lt;a href="https://github.com/OpenMined/PySyft/tree/dev/examples/tutorials"&gt;PySyft&lt;/a&gt; for a more hands-on experience.&lt;/p&gt;

</description>
      <category>security</category>
      <category>machinelearning</category>
      <category>cryptography</category>
    </item>
    <item>
      <title>MPC Part 1: Oblivious Transfer</title>
      <dc:creator>Arash Afshar</dc:creator>
      <pubDate>Mon, 20 May 2019 18:22:00 +0000</pubDate>
      <link>https://forem.com/_aafshar_/mpc-part-1-oblivious-transfer-3ebk</link>
      <guid>https://forem.com/_aafshar_/mpc-part-1-oblivious-transfer-3ebk</guid>
      <description>&lt;p&gt;Consider a weather app that you have on your phone. For most users, this app records the current GPS location, sends it to a server and receives and displays the temperature of the user's location. This means that if the server chooses to, it can create a profile of the user location history and track their movement which is a breach of privacy for most users. Therefore, a privacy-aware user might want to obtain weather information without sharing their location. Let's call this &lt;em&gt;User Security Property&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Designing an application that satisfies this security property is very easy. In fixed intervals, the server sends all the weather information it has for all the cities and regions from all over the world to the user's device and the user does a local lookup to find the weather information that is interesting to them. As you can see, with this approach the server has no way of knowing the user's location. Unfortunately, this approach has two main problems.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The amount of data that is sent to the user's device is too large.&lt;/li&gt;
&lt;li&gt;More importantly, the user learns all the weather information which is the backbone of the business that the server is running.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Therefore, we are interested in a solution that is fast and efficient enough to be used in practice (this is a very subjective criterion and depends on the use case). We are also interested in a solution that protects the privacy of the server and only sends the temperature of the city that the user has asked for. Let's call this &lt;em&gt;Server Security Property&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;To sum up, we have two parties a server and a user. The server has a list of private temperature data and the user has a private input which indicates the city that the user is interested in. We would like to offer this functionality such that the &lt;em&gt;User Security Property&lt;/em&gt; and &lt;em&gt;Server Security Property&lt;/em&gt; are satisfied and that the solution is more efficient than sending all the server data to the user.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--97uQsWPE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://arash-afshar.github.io/assets/ot_requirements.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--97uQsWPE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://arash-afshar.github.io/assets/ot_requirements.png" alt="requirements.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://crypto.stanford.edu/pbc/notes/crypto/ot.html"&gt;Oblivious Transfer&lt;/a&gt; can help with achieving this goal. To describe Oblivious Transfer (OT), we first consider a simple case where the server only holds the weather information about &lt;strong&gt;two&lt;/strong&gt; cites and the user chooses one of those cities. This case is called &lt;em&gt;1-out-of-2 OT&lt;/em&gt;. In what follows, I'll describe the theory and some code snippets and then describe how to extend it to more than two cities.&lt;/p&gt;

&lt;h1&gt;
  
  
  Theory
&lt;/h1&gt;

&lt;p&gt;One of the simplest OTs (specially if you know Diffie-Hellman key exchange protocol) is proposed by &lt;a href="https://eprint.iacr.org/2015/267.pdf"&gt;Chou, Orlandi 2015&lt;/a&gt;. The overall protocol is shown in the figure below. But it is not immediately clear what is happening there and what are &lt;code&gt;a&lt;/code&gt;, &lt;code&gt;b&lt;/code&gt;, &lt;code&gt;g&lt;/code&gt;, &lt;code&gt;Hash&lt;/code&gt;,&lt;code&gt;Encrypt&lt;/code&gt;, and &lt;code&gt;Decrypt&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9QkgoyCX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://arash-afshar.github.io/assets/simple_ot.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9QkgoyCX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://arash-afshar.github.io/assets/simple_ot.png" alt="simple_ot.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What is &lt;code&gt;g&lt;/code&gt;?
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;g&lt;/code&gt; is the generator of a "simple group" of prime order &lt;code&gt;p&lt;/code&gt;. For example, consider the group of Z11 which is a group of prime order 11 and therefore has &lt;code&gt;11-1&lt;/code&gt; members &lt;code&gt;{1,2,...,10}&lt;/code&gt;. This is a cyclic group if you consider &lt;code&gt;g=2&lt;/code&gt; since you can create all the members of the group by starting from 2 and keep multiplying it by 2. In other words {2&lt;sup&gt;1&lt;/sup&gt;,2&lt;sup&gt;2&lt;/sup&gt;,2&lt;sup&gt;3&lt;/sup&gt;, ..., 2&lt;sup&gt;10&lt;/sup&gt;} module 10 produces the same set as &lt;code&gt;{1,2,...,10}&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;To see it for yourself, run the following program.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;generate_group&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
  &lt;span class="c1"&gt;# Using list to show that there are not duplications
&lt;/span&gt;  &lt;span class="n"&gt;members&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;list&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nb"&gt;xrange&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;members&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;sorted&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;members&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;generate_group&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;11&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;# =&amp;gt; prints [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  What are &lt;code&gt;a&lt;/code&gt; and &lt;code&gt;b&lt;/code&gt;?
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;a&lt;/code&gt; and &lt;code&gt;b&lt;/code&gt; are two integers that are selected at random from the Z11. Note that both of these values appear as the exponents of &lt;code&gt;g&lt;/code&gt; and therefore g&lt;sup&gt;a&lt;/sup&gt; and g&lt;sup&gt;b&lt;/sup&gt; result in a member of the cyclic group.&lt;/p&gt;

&lt;h2&gt;
  
  
  What are &lt;code&gt;Hash&lt;/code&gt; and &lt;code&gt;Encrypt/Decrypt&lt;/code&gt;?
&lt;/h2&gt;

&lt;p&gt;The proper definition of the &lt;code&gt;Hash&lt;/code&gt; and &lt;code&gt;Encrypt&lt;/code&gt; functions can be found in the paper, but for our purposes assume &lt;code&gt;Hash&lt;/code&gt; is &lt;code&gt;SHA1&lt;/code&gt; and &lt;code&gt;Encrypt/Decrypt&lt;/code&gt; is a symmetric key encryption scheme such as &lt;code&gt;AES&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Does the Protocol Work?
&lt;/h2&gt;

&lt;p&gt;To show that this protocol is doing what it claims, let's follow it with an example. In this example, we use the same group Z11 and with &lt;code&gt;g=2&lt;/code&gt; as its generator. Also, assume that &lt;code&gt;a=4&lt;/code&gt; is &lt;a href="https://xkcd.com/221/"&gt;chosen uniformly at random&lt;/a&gt; and similarly, &lt;code&gt;b=7&lt;/code&gt; is chosen uniformly at random. The following code computes the steps required for the user to obtain k and for the server to obtain k0 and k1. You will notice that if the user sets &lt;code&gt;c=0&lt;/code&gt;, then k will be the same as k0 and if the user sets &lt;code&gt;c=1&lt;/code&gt;, then k will be equal to k1. Therefore, the user can either decrypt e0 or e1 based on their choice, but they CANNOT decrypt both.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# multiplies x to the inverse of y
&lt;/span&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;div&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
  &lt;span class="n"&gt;xp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;
  &lt;span class="n"&gt;yip&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;pow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;xp&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;yip&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;examine_case_c_0&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
  &lt;span class="n"&gt;A&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;pow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="n"&gt;B&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;pow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;pow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;A&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="n"&gt;k0&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;pow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;B&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="n"&gt;k1&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;pow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;div&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;B&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;A&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;k0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;k1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;k&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;k0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;examine_case_c_1&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
  &lt;span class="n"&gt;A&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;pow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="n"&gt;B&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;A&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nb"&gt;pow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;
  &lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;pow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;A&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="n"&gt;k0&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;pow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;B&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="n"&gt;k1&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;pow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;div&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;B&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;A&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;k0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;k1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;k&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;k1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;examine_case_c_0&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;11&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;# =&amp;gt; (3, 3, 4, True)
&lt;/span&gt;
&lt;span class="n"&gt;examine_case_c_1&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;11&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;# =&amp;gt; (3, 5, 3, True)
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;So far, we have &lt;em&gt;demonstrated&lt;/em&gt; that the protocol is correct. To actually &lt;em&gt;prove&lt;/em&gt; its correctness, you can just write down the formulas and go through the math. Next, we will talk about the security of the protocol and try to argue that it satisfies both of the security requirements.&lt;/p&gt;

&lt;h2&gt;
  
  
  Is the Protocol Secure?
&lt;/h2&gt;

&lt;p&gt;To examine the security of the protocol, imagine that you are the attacker and see what you can do! For example, let's assume that you are the server and your goal is to find out the user's choice of the city. Looking at the protocol, you'll notice that as the server you are getting only one message. Depending on the user choice, you either get B=g&lt;sup&gt;b&lt;/sup&gt; or B=Ag&lt;sup&gt;b&lt;/sup&gt;. Therefore, if you can somehow identify which message you got, you have succeeded in your attack. Let's consider a couple of different ways that you can perform your attack. In other words, we want to find ways that we can violate &lt;em&gt;User Security Properties&lt;/em&gt;. Our attacks will involve finding or guessing &lt;code&gt;b&lt;/code&gt;. Note that both the user and the server know &lt;code&gt;g&lt;/code&gt;. Therefore, if we can find/guess &lt;code&gt;b&lt;/code&gt;, then we can compute g&lt;sup&gt;b&lt;/sup&gt; and compare the result with B. If they are the same, we know that the user has chosen city0. We (the server) can perform this attack in two ways.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;By finding a flaw in the way &lt;code&gt;b&lt;/code&gt; is generated: if the user chooses &lt;code&gt;b&lt;/code&gt; randomly and implement the random gen code properly, then the user is safe against this type of attack. Therefore, we define&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;em&gt;User Security Requirement 1: Use secure random to choose "b" and do not reuse "b"&lt;/em&gt;.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;By trying all possible values of &lt;code&gt;b&lt;/code&gt; (i.e., a brute-force attack). If our cyclic group is big enough, then this attack would be impractical. Therefore, we define&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;em&gt;User Security Requirement 2: Choose a large enough cyclic group such that brute-forcing "b" is impractical for the duration that "b" is valid.&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;We can also make the same kind of arguments about the requirements for satisfying &lt;em&gt;Server Security Property&lt;/em&gt; which I leave for you to explore and think about. In particular, I encourage you to read about the hardness property of the &lt;a href="https://crypto.stanford.edu/pbc/notes/crypto/factoring.html"&gt;discrete logarithm problem&lt;/a&gt; and how it relates to Diffie-Hellman problem.&lt;/p&gt;

&lt;p&gt;From the above arguments, we have identified that to satisfy &lt;em&gt;User Security Property&lt;/em&gt;, the protocol implementation must be configured such that it satisfies the following requirements.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The implementation must generate &lt;code&gt;b&lt;/code&gt; using secure random every time.&lt;/li&gt;
&lt;li&gt;The implementation must use a cyclic group with a very large size to prohibit the brute-force attack.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now, are these arguments enough to prove security and more importantly, is the approach that we have taken so far a good approach for proving security? The above arguments are informal and are not accurate. For example, we have not defined the "large enough" size for the cyclic group, nor have we defined the "hardness" property of the discrete logarithm in the cyclic group. Moreover, we have described the random number generator as "secure" without specifying what it means. Nevertheless, this approach towards proving security is a correct approach and it is how real proofs look like. Namely, going over each message that a party receives and proving that the message leaks no information about the private input of the parties. I will write about the proof model in a separate post, in the meantime, you can read about them in a concise &lt;a href="https://eprint.iacr.org/2016/046.pdf"&gt;tutorial by Yehuda Lindell&lt;/a&gt;, or get a more in-depth knowledge by reading the wonderful books by Oded Goldreich, Foundations of Cryptography, Vol I and II.&lt;/p&gt;

&lt;h1&gt;
  
  
  Back to the Application
&lt;/h1&gt;

&lt;p&gt;We started with the goal of creating a weather reporting service that preserves the privacy of the user and the server and introduced Oblivious Transfer (OT) as a potential solution. We then showed how an OT protocol can be designed for the case where the server has only two city temperatures and the user chooses one of them (1-out-of-2 OT). Now, we want to &lt;strong&gt;extend&lt;/strong&gt; this to a 1-out-of-n OT for some large n. A naive approach is to create a network of 1-out-of-2 OTs, where each pair of initial temperatures are fed to an OT and then create another layer of OTs such the output of each pair of OTs from the first layer is fed to an OT in the second layer and so on. This forms a binary tree and requires approximately n OTs. There are much faster &lt;a href="https://eprint.iacr.org/2016/799.pdf"&gt;solutions&lt;/a&gt; which can achieve this with a constant number of 1-out-2 OTs.&lt;/p&gt;

&lt;p&gt;At last, the following code shows an implementation of this application using &lt;a href="https://github.com/osu-crypto/libOTe"&gt;libOTe&lt;/a&gt;. You can find a docker file which sets up and runs this program on &lt;a href="https://github.com/Arash-Afshar/secure_multiparty_computation_examples/blob/master/weather_app_with_ot"&gt;my repo&lt;/a&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  Final Remarks
&lt;/h1&gt;

&lt;p&gt;Similar to the previous post, just implementing a secure protocol is not enough and there are much more things that one need to take into account. For example, on preserving the privacy of the user, note that the user's location can be found (or at least estimated) through the source IP or network delays. Moreover, based on the frequency of the weather checks and the requests to the server, the server can guess whether the user is traveling on the road or not. Nevertheless, using a secure protocol is far better than a non-secure one.&lt;/p&gt;

</description>
      <category>security</category>
      <category>cryptography</category>
    </item>
    <item>
      <title>Absolute Security with No Trust</title>
      <dc:creator>Arash Afshar</dc:creator>
      <pubDate>Fri, 17 May 2019 02:35:39 +0000</pubDate>
      <link>https://forem.com/_aafshar_/absolute-security-with-no-trust-p55</link>
      <guid>https://forem.com/_aafshar_/absolute-security-with-no-trust-p55</guid>
      <description>&lt;p&gt;I have started a &lt;a href="https://arash-afshar.github.io/"&gt;blog&lt;/a&gt; on Theoretical Security and Software Engineering. Here is my first post. I hope you enjoy it :)&lt;/p&gt;

&lt;p&gt;Designing and implementing secure software solutions usually involves a discussion about the level of security and the effort and cost of achieving that level of security. The cost and effort are a function of the upfront cost of development, time to market, and the cost of fixing the security problem when they are exploited. Depending on the product, the company, and the severity of the problem, the later cost could also involve regaining the trust of the customers (e.g., numerous security breaches of &lt;a href="https://techcrunch.com/2018/09/28/everything-you-need-to-know-about-facebooks-data-breach-affecting-50m-users/"&gt;Facebook&lt;/a&gt;) or losing a significant part of the business as in the case of &lt;a href="https://krebsonsecurity.com/2019/02/email-provider-vfemail-suffers-catastrophic-hack/"&gt;VFEmail&lt;/a&gt;. Based on the risk tolerance and other factors, software products fall somewhere in the following spectrum of security.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;No security! It is fast, easy, and cheap to develop but carries significant risk and will require a huge cost to make it secure later.&lt;/li&gt;
&lt;li&gt;Some levels of security have been considered and implemented and the rest is protected with NDAs or other non-technical means.&lt;/li&gt;
&lt;li&gt;Absolute security without trusting any third-party (more formally known as Information-theoretic security or Unconditional security).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In this post, I will talk about the last item and discuss how feasible or practical it is. I will argue that although absolute security is not possible in practice, it is important that we put the effort in research in fields such as "Secure Multiparty Computation" to provide the tools necessary for making a reasonable compromise with regard to the security of the product and the number of things that we have to trust.&lt;/p&gt;

&lt;p&gt;Let's start with a simple example to demonstrate if absolute security is achievable or not. In this example, we have a &lt;code&gt;client&lt;/code&gt; which wants to encrypt a &lt;code&gt;secret file&lt;/code&gt; and outsource it to a &lt;code&gt;cloud&lt;/code&gt; for storage such that the cloud can never find the content of the file.&lt;/p&gt;

&lt;h2&gt;
  
  
  Theory
&lt;/h2&gt;

&lt;p&gt;You can achieve information-theoretic security by using a simple &lt;code&gt;XOR&lt;/code&gt; function. Consider the case where the content of the &lt;code&gt;secret file&lt;/code&gt; is a binary string &lt;code&gt;101010&lt;/code&gt;. Now assume the client has picked a password which is also a binary string, say &lt;code&gt;100101&lt;/code&gt;. The client XORs the file content with the password (using the following function) and sends the result to the cloud.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;encrypt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;content&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;password&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
  &lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;content&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="n"&gt;k&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;password&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="o"&gt;^&lt;/span&gt; &lt;span class="n"&gt;k&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s"&gt;"{0:b}"&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;format&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;zfill&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;encrypt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"101010"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"100101"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;#=&amp;gt; prints '001111'
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Why is this way of encryption secure?&lt;/em&gt; Assume you are the cloud and you have received &lt;code&gt;001111&lt;/code&gt; from the client. Also assume that you have unlimited CPU and memory and you decide to try all possible passwords (i.e., perform a brute-force attack) to find the content of the secret file. You notice that the message is 6 characters long and therefore you try all the passwords between &lt;code&gt;000000&lt;/code&gt; to &lt;code&gt;111111&lt;/code&gt; using the following function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;brute_force&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;secret&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
  &lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;secret&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="n"&gt;possible_results&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;
  &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;possible_password&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nb"&gt;xrange&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"111111"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;possibility&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"{0:b}"&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;format&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;possible_password&lt;/span&gt; &lt;span class="o"&gt;^&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;possible_results&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;possibility&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;zfill&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;possible_results&lt;/span&gt;

&lt;span class="n"&gt;brute_force&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"001111"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;#=&amp;gt; Can you guess what it prints?
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;If you run this function, you will notice that it is printing all values between &lt;code&gt;000000&lt;/code&gt; and &lt;code&gt;111111&lt;/code&gt;. In other words, it will print all the possible contents of the secret file! This means that brute-forcing did not help at all and you (i.e., the cloud) still have no idea which of the possibilities is more likely! This is what we call information-theoretic security: regardless of your computation power, the best you can do is &lt;strong&gt;guess&lt;/strong&gt; which one of all the possible contents is the answer.&lt;/p&gt;

&lt;p&gt;Alright, we have achieved information-theoretic security and we are done, right? No! We have yet to examine the practical side.&lt;/p&gt;

&lt;h2&gt;
  
  
  Practice
&lt;/h2&gt;

&lt;p&gt;In our brute-force example, the cloud is looking for the correct answer among all the possibilities. An observant reader might have noticed that the content of the &lt;code&gt;secret file&lt;/code&gt; is &lt;code&gt;101010&lt;/code&gt; or &lt;code&gt;42&lt;/code&gt; and of course &lt;a href="https://en.wikipedia.org/wiki/The_Hitchhiker%27s_Guide_to_the_Galaxy"&gt;42 is the answer&lt;/a&gt;! Joking aside, this shows an attack when the attacker has some knowledge about the form of the secret. Even if we do not consider this type of attack, there can still be problems with the implementations. For example, consider the following implementation of the encryption function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;bad_encrypt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;content&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;password&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
  &lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;content&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="n"&gt;k&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;password&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="o"&gt;^&lt;/span&gt; &lt;span class="n"&gt;k&lt;/span&gt;
  &lt;span class="k"&gt;print&lt;/span&gt; &lt;span class="s"&gt;"DEBUG: Encrypting {0} with {1} resulting in {2}"&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;format&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s"&gt;"{0:b}"&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;format&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;zfill&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;bad_encrypt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"101010"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"100101"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;#=&amp;gt; prints DEBUG: Encrypting 42 with 37 resulting in 15
#          '001111'
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;hmmm, that does not look very secure! As is evident, even when using algorithms that give you information-theoretic security, you are still &lt;em&gt;trusting&lt;/em&gt; that the developers have implemented a secure program. Now, let's assume that the program is written securely and there is no vulnerability in the code. The next question is where to store the password. If an attacker can find the password, then all bets are off. Therefore, even with theoretically secure algorithms and &lt;em&gt;assuming&lt;/em&gt; that your programs have no vulnerabilities, you are still &lt;em&gt;trusting&lt;/em&gt; that your operational security is perfect!&lt;/p&gt;

&lt;p&gt;Now, assume that your code is secure and your operational practices are secure, and you have no malicious insider that is leaking your secrets, would you choose the XOR function for your encryption needs? Probably not! Note that to encrypt a message of length 6, you needed to create a password of length 6. Similarly, to encrypt 10 Terabyte of data that you are outsourcing to a cloud, you would need to store 10 Terabytes of passwords locally! Which is a huge and pointless price to pay to achieve information-theoretic security.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reality
&lt;/h2&gt;

&lt;p&gt;At this point, you might be wondering why are we even bothering with theoretical security! Well, the picture that I painted so far was an extreme case to make a point about the importance of security in all aspects of software development and also to point out that high level of security is not cheap and in the vast majority of cases you pay it through more computation or more memory/network usage. The solution is research on making theoretical approaches more efficient and to find reasonable compromises on practical security. In the past few decades, there have been significant researches that are bringing us &lt;a href="https://eprint.iacr.org/2018/450.pdf"&gt;closer&lt;/a&gt; to an efficient and reasonable theoretical and practical security.&lt;/p&gt;

&lt;p&gt;In my PhD thesis, I have done a small part in furthering such research (&lt;a href="https://link.springer.com/content/pdf/10.1007/978-3-642-55220-5_22.pdf"&gt;AMPR14&lt;/a&gt;,&lt;a href="https://link.springer.com/content/pdf/10.1007/978-3-662-46800-5_27.pdf"&gt;AHMR15&lt;/a&gt;, &lt;a href="https://eprint.iacr.org/2017/062.pdf"&gt;AMR17&lt;/a&gt;) in the field of "Secure Multiparty Computation" and I believe it is one the most promising fields. In my future blog posts, I will introduce this field from the point of view of a Software Engineer with the goal of encouraging other Software Engineers to adapt and use the results of the amazing research that is being done in this field.&lt;/p&gt;

</description>
      <category>security</category>
      <category>cryptography</category>
    </item>
  </channel>
</rss>
