<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Joseph Wilson on Medium]]></title>
        <description><![CDATA[Stories by Joseph Wilson on Medium]]></description>
        <link>https://medium.com/@joseph.wilson_17990?source=rss-9326ad4c51d1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*SzptVzm-JgQeWGZVYC15Ew.jpeg</url>
            <title>Stories by Joseph Wilson on Medium</title>
            <link>https://medium.com/@joseph.wilson_17990?source=rss-9326ad4c51d1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 18:11:58 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@joseph.wilson_17990/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Optical computing for computational fluid dynamics: An introduction to CFD]]></title>
            <link>https://medium.com/optalysys/computational-fluid-dynamics-and-optical-computing-5ad147c091d?source=rss-9326ad4c51d1------2</link>
            <guid isPermaLink="false">https://medium.com/p/5ad147c091d</guid>
            <category><![CDATA[energy-efficiency]]></category>
            <category><![CDATA[fluid-mechanics]]></category>
            <category><![CDATA[optical-computing]]></category>
            <dc:creator><![CDATA[Joseph Wilson]]></dc:creator>
            <pubDate>Fri, 26 Feb 2021 16:42:06 GMT</pubDate>
            <atom:updated>2021-02-26T16:42:35.464Z</atom:updated>
            <content:encoded><![CDATA[<p>Engineers predict the behaviour of things on a regular basis. “Will this bridge hold under load? Will it hold in high winds? Are there any unexpected structural harmonics that might lead to <a href="https://www.youtube.com/watch?v=mXTSnZgrfxM&amp;t=168s">undesirable instability</a>?” are examples of the kind of prediction-seeking questions that engineers ask on a regular basis.</p><p>One of the methods that engineers use to answer these questions is a very helpful tool called <em>computational fluid dynamics </em>(CFD for short), a technique for determining the behaviours and dynamics of fluids. This is a category that includes both liquids and gases but, under the right conditions, almost anything can flow like a fluid.</p><p>The need to understand and manipulate fluids touches almost every part of our lives, and CFD is correspondingly present in many fields of industrial design. From more fuel-efficient cars to laptop cooling systems, aircraft dynamics to air conditioning, vast amounts of computational effort are expended in the interests of keeping us safer, wealthier, and at a comfortable temperature. But how does this tool work? And crucially, can we make it work <em>better</em>?</p><p>Like many other tools in recent years, CFD can benefit from the ongoing revolution in computing. From new techniques to better hardware, a silent revolution is occurring that might sweep away huge sections of what was once considered to be the conceptual core of CFD in favour of something quite different indeed.</p><p>In this article, we aim to provide an illustration of where the field is now so that we can later talk in detail about where it might end up in the future. If you’re in a hurry, there’s a summary you can skip to at the end of this article. If not, we start by describing a method of making approximations for complex problems. We then describe what the problems are with that method and move on the specific techniques for performing CFD. We illustrate how the most common CFD technique works and some of the more important issues with it, and explain why it might be time for another method. We finish off by describing what these methods could be.</p><h3>Making predictions for complex mechanical problems</h3><p>Rather than leaping straight in to describing the fundamentals of CFD, we’ll start with a closely related approach in terms of the mechanics of solid materials. Making predictions is <em>relatively</em> straightforward when working with solid materials, because by definition they obey certain structural relationships. In many of the problems that we’d like to find solutions for, each “bit” of a solid material remains in roughly the same position relative to every other “bit” over time, making it easier to construct and solve problems.</p><h4>Big solutions from smaller problems</h4><p>Take the following example of a metal beam, supported at both ends, being subjected to a downwards vertical force.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/672/1*Yt9uZXmqoyJRaXpv-D8J_Q.png" /></figure><p>If the force is big enough, the beam will bend</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/672/1*yHm_lk161ujUiHFDd81g8w.png" /></figure><p>Finding the force needed to cause the beam to bend is a matter of knowing the yield conditions of the material and working out moments. What is <em>less </em>easy to work out is the exact shape that the beam will take after being bent. Fortunately, as we said earlier, each bit of a solid material tends to retain an overall consistent position with respect to each other bit.</p><p>This allows us to use a very useful technique in which we can <em>discretise </em>(break up)<em> </em>the beam into smaller pieces and then solve the equations of motion for each discrete “bit” or <em>element. </em>Here’s what it looks like when we divide the beam up into smaller pieces, which we collectively call a <em>grid </em>or <em>mesh</em>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/672/1*bu8wTWw8HREQv34bI6KC8w.png" /></figure><p>In this method, each element is completely filled with a fixed piece of the solid; no other material can enter the element, and no material leaves the element. However, the mesh elements can change shape in response to forces. If it helps, think of the beam as being made of <em>really hard </em>bits of blu-tack which are firmly stuck together. How strongly these pieces are stuck together and how they deform in response to forces is described by the <em>material model</em>, a collection of one or more mathematical relationships that tie these things together.</p><p>When we apply the same force as before, we now have a number of individual equations to solve across all the different bits of the beam; these will all have different solutions depending on where each element is on the beam:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/699/1*yh6_aMXgV8YhZKxaSKFCGQ.png" /><figcaption>Each element of the mesh now experiences different forces, resulting in different motions</figcaption></figure><p>And the final shape of the beam is given by the cumulative solutions to the motion of each individual element:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/672/1*vXHwXQWwNeWT2XljTQZlVg.png" /></figure><p>This gets us something close to the “correct” final shape of the beam, the shape that we would get if we did the same thing in real life (assuming that our simulation captured the relevant physical laws), but this is a tremendous amount of extra work! For a very basic 2-dimensional problem like the one above, solving all of the relevant equations by hand would take hours and be extremely repetitive. For larger and more complex geometries in 3D, it almost certainly wouldn’t be worth it.</p><h4>Timestepping</h4><p>To make matters worse, we can’t perform the solution in one go; to accurately reach the final state of the beam means that we have to take small steps in <em>time </em>as well as space.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*glNiSxUvpg_u-0ikZ9ltXw.png" /><figcaption>We can’t simply jump to the end solution; just like in real life, we have to move forwards through time. There are two distinctly different time-stepping techniques known as “implicit” and “explicit” methods. Implicit methods allow for larger time-steps but struggle with discontinuities (such as shockwaves), while explicit methods can capture shocks and other very fast events at the cost of much shorter timesteps.</figcaption></figure><p>While there are two different approaches to time-stepping, the general principle is the same; solutions of the system at earlier time-steps are used when calculating a solution over the next time-step. This is true of implicit methods (where the calculations also involve unknown or “<em>implicit” </em>future values) and explicit methods (where only currently-known or <em>“explicit”</em> values are used to calculate the next set of values).</p><p>Breaking the problem down into tiny pieces and timesteps means solving a phenomenal number of equations, but being able to predict these behaviours ahead of time is incredibly useful; not only is it cheaper and faster than repeatedly building physical prototypes, but in some cases, such as the design of large buildings or aircraft, many lives can depend on it. We therefore do what we always do when faced with a big, tedious task:</p><h4>We do it all with computers</h4><p>The computational load for working out a small problem like the one described above is still relatively large. The average laptop would probably take a minute or so to calculate the solution, assuming we wanted it to be <em>physically</em> accurate rather than just visually so. This isn’t a very<em> </em>long time, but it does give some indication of how much computing needs to be done. After all, in our daily lives, we’re used to computers completing “small” tasks more or less immediately.</p><p>When we scale this up to millions of elements (easily done, especially if we’re solving the problem in 3D), the amount of computation that needs to be performed increases drastically. Large-scale simulations are therefore almost exclusively the preserve of high-performance computing, in which hundreds or even thousands of processing cores work simultaneously on the solution.</p><p>This is expensive in three different ways; money, time and energy. First, you either need to buy and maintain a supercomputer, or at least rent the use of one. You’ll also need to pay for licenses for most engineering software packages.</p><p>Second, even with sufficient computing power, these techniques take a <em>lot </em>of time, because the timesteps have to be calculated in sequence. There’s also diminishing returns to be had from using more and more cores, a phenomenon known as <a href="https://en.wikipedia.org/wiki/Amdahl%27s_law">Amdahl’s law</a>. It’s therefore not unusual for large simulations to take weeks to run even on a powerful supercomputer.</p><p>Third, running these systems wastes a vast amount of energy. If you’re only interested in the <em>final</em> state of the solution, you still have to solve a significantly greater number of calculations getting to that final point, because you have to work your way forward through all the time-steps that lie between the start of the simulation and the end point. It’s very rare that you would need <em>all</em> of the data produced throughout a simulation, even if you want to investigate the dynamics over time. If you did want it, saving all the data produced by a very big simulation would require staggering amounts of storage space.</p><p>We’ll leave these issues for now, but it’s worth remembering them; these considerations will come up later when we start thinking about better methods.</p><h3>Basic computational methods for fluid simulation</h3><p>The method we described above for working out the deformation of the beam is known as the <em>finite element method</em>. The “finite” bit refers to the fact that the individual elements have a defined size. This is different to the way in which the mathematics we usually describe these problems with (calculus) deals with <em>infinitesimally</em> small elements.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/507/1*2iDqZfJ_BZdoYbtONZWTAw.png" /><figcaption>A comparison of the concept of a finite element, which has a defined side length, compared to the limit-based concept of an infinitesimal element as used in calculus</figcaption></figure><p>This introduces sources of error into our simulation because we’re now making a numerical <em>approximation</em> to the behaviour of the analytic solution.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/629/1*Ye6Uu_7gVObw6Zc_5Bfvgw.png" /><figcaption>A comparison between some analytic function f(x), an approximation to it using finite differences, and what happens as we start to approach an infinitesimal difference. The difference between the approximation and the analytic function (highlighted in green) is an error. As the size of the difference approaches an infinitesimal value, the “fit” of the approximation is better, until eventually we return to the analytic function in a way that can be worked on using calculus.</figcaption></figure><p>Some of this error is inescapable, because we need to break the problem up to work on it with a computer, and computers can only hold a limited number of values in memory.</p><p>Thus far we haven’t delved too deep into any mathematics because the finite element method <em>isn’t</em> a good method for working with fluids, although it is a good starting point for the general idea.</p><p>Solids (at least up to certain physical limits) obey relationships that mean we can break them down into individual elements that have their own dynamics. What about fluids? What happens when we try to solve fluid motion in the same way as we did the solid bar?</p><p>If we tried to treat a fluid in the same way, we’d start by dividing the fluid up into individual elements just as we did before. Each one of these elements contains a fixed amount of fluid; no other fluid can enter the element, and none can leave. Just like in the solid example above, if the element is subjected to forces, the shape of the element changes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/746/1*fHj0ZdZkJqQ_iT6C_Ddh6g.png" /><figcaption>A simple fluid-carrying pipe containing a small obstruction, a very basic (yet non-trivial) fluid flow environment. The fluid moves from left to right with a consistent flow rate, where more material is added at the leftmost inlet and is removed from the simulation at the outlet.</figcaption></figure><p>You can probably see that this is going to get <em>extremely</em> messy very quickly, because fluids do <em>not</em> work in the same way as solids; they can slide past each other, swirl around and so on. Fluids aren’t connected or constrained<em> </em>in the same way that elements in a solid body are.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/839/1*CDEyr7uTgYjIAi4Z0MKRuA.png" /><figcaption>An attempt to solve a fluid problem using the same method as for a solid body is doomed to rapidly experience what is known as “mesh tangling”; even the best solver packages will quickly fail due to extreme deformation and limits on numerical precision. Elements are coloured by velocity.</figcaption></figure><p>This approach using a connected mesh fails because of the incredible amounts of deformation a fluid element can undergo. But what if, instead of preserving the contents of each element and deforming the mesh, we do things the other way around; we keep the mesh shape consistent and allowing the <em>contents</em> to move between elements?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/839/1*FC51v7UAjFuEI3TE2X4jkw.png" /></figure><p>Much better! Although in practice the size of the mesh in the picture is much larger than we would normally use.</p><p>This kind of mesh, in which the structure of the mesh is fixed and material moves between elements, is known as an <em>Eulerian</em> mesh. The other kind, where material is embedded in the mesh and the mesh deforms with the material, is known as a <em>Lagrangian </em>mesh.</p><p>These two approaches are the most common solutions* for solving material simulation problems, although they aren’t the only methods. Some approaches, such as smooth-particle hydrodynamics, do away with meshes entirely. Picking the right technique for a problem isn’t always easy; it’s very dependent on the problem and the materials, but for most engineering problems in fluid dynamics the Eulerian approach is extremely popular.</p><p>However, thus far we’ve yet to answer an important question; what exactly is it that we are transporting between cells?</p><p>*(Despite their differences, Lagrangian and Eulerian meshes can also work together in the same simulation; in some cases, we can even switch between them on the fly. This is the basis of many approaches to solving fluid-structure interactions)</p><h3>The Navier-Stokes equations</h3><p>Fluid motion is famous for being complex, but the mathematical treatment of it arises from some very basic principles. Mass, momentum and energy have to be <em>conserved</em>; simply put, in any physical process, you can’t end up with more (or less!) matter and energy than you started with. Laws that reflect this fact are therefore known as <em>conservation laws</em>.</p><p>This section is more mathematically complex; if you’re not interested in these details, skip ahead to the next section, which deals with one of the biggest problems in fluid dynamics. For now, we can just say that we use a few mathematical tools to turn the laws of fluid motion into many smaller but simpler equations that allow us to calculate the transport of fluid properties (mass, momentum, energy and so on) between individual fluid volumes.</p><p>The most complete version of the conservation laws for fluids are known as the<em> Navier Stokes</em> equations for <em>compressible, viscid </em>flow. This is a mathematical model that accounts for the full range of conditions that can occur within a fluid.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-qA6gHXeCWVlrye9Fs0rLQ.png" /><figcaption>These are the Navier Stokes equations, written in what is known as the “conservation” form most usually associated with the Eulerian method outlined above. There’s no single definitive notation for these equations, so you may see them written differently elsewhere depending on how they are being used.</figcaption></figure><p>Despite their complexity, the general thrust of the Navier Stokes equations can be quite readily understood. We won’t go into exhaustive detail, but it’s helpful to understand that in each equation, the similar-looking terms</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/1*rZEXcGbeZcPSzfceQunPtQ.png" /></figure><p>all represent the <em>divergence</em> (the net inflow or outflow) of mass, momentum and total energy within the volume.</p><p>In the mass equation, the change in fluid density is directly related to the total mass flowing into and out of the volume. In the momentum equations, the bulk change in momentum is related to the different forces that can act on the fluid volume. The energy equation associates the bulk change in energy with changes in the sum of kinetic, potential and thermal energies in the volume.</p><p>The physical origins of the equations might be readily explicable, but the way they behave are not. From the perspective of the fundamental mathematics, the Navier-Stokes equations are a set of <em>partial differential </em>equations for which there is currently no analytic solution for most starting configurations!</p><p>In fact, simply finding a formal definition of the global solution space of the Navier-Stokes equations is one of the Clay Mathematics Institute Millenium Prize problems. There’s an associated prize of $1,000,000 if you can find an analytic method for mapping the velocity field of a fluid to the associated pressure field.</p><p>Fortunately, our approximation method means that we aren’t reliant on there being an analytic solution. However, we still need a way of turning these partial differential equations into something that a computer can work with.</p><p>There’s a very useful tool that allows us to relate the divergence of properties contained within the volume to the flow or “flux” of these values through the surface. It’s called <em>Gauss’s theorem</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/840/1*B55LOjOPR4zacvKS5bcBbQ.png" /><figcaption>Gauss’s theorem illustrated visually. The black arrows represent the divergence of a quantity contained within the blue cube. The red dots on the cube’s surface indicate where those lines of divergence pass through the surface of the volume. Drawn this way, we can see how divergence and the flux through a surface are related.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/1*DI0z2sZobMKJWJ8FoNFVfQ.png" /><figcaption>The mathematical interpretation of Gauss’s theorem. The volume integral of the divergence of a field is equivalent to the surface integral of the scalar product of the field and the surface normal.</figcaption></figure><p>Applying Gauss’s theorem to the Navier-Stokes equations allows us to write the entire system of equations as</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/829/1*mirmpdXZyEvGHjy8lPeIZQ.png" /></figure><p>Where the terms in bold represent vectors columns of flow quantities, broken up into <em>scalar </em>quantities <strong>W</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*91ib1sloW59lt3imHPBu1Q.png" /></figure><p>Vector quantities <strong>F</strong>, <strong>G</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aiU7HjQlx9YnxWuDKM8R-Q.png" /></figure><p>And body forces</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oJg5R_memODzl_fj8Xye6A.png" /></figure><p>From these individually simpler representations, we can begin constructing algorithms for <em>transporting</em> flow quantities at the interfaces between cells.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/463/1*6UsLVhjDWjlorunm1oefpw.png" /><figcaption>An illustration of the net direction of the transport of a fluid property (e.g mass) between Eulerian mesh cells in a 2-dimensional region. When calculated for all the relevant properties, the resulting changes across the flow domain should describe the associated fluid dynamics, just as solving the equations of motion for individual elements does for the solid body in the earlier example. The total value of these properties is conserved in accordance with the conservation laws that we used to derive the transport equations.</figcaption></figure><p>Because we have broken these quantities up into different vectors, this also means that we can apply different mathematical techniques to each, allowing us to use more carefully tailored calculation methods that yield more accurate results.</p><p>Eulerian meshes lie at the heart of most approaches to CFD, and flux transport schemes are what make them tick. However, there’s now another problem heading towards us, one that comes from this blending of meshes with fluid transport and threatens to stop us in our tracks if we try and do anything complicated.</p><p>It’s time to talk about <em>turbulence.</em></p><h4>Turbulence</h4><blockquote>“When I meet God, I am going to ask him two questions: Why relativity? And why turbulence? I really believe he will have an answer for the first one” — Apocryphal, attributed to Werner Heisenberg</blockquote><p>Turbulence is the unpredictable motion of a fluid. While it might be tempting to try and give a more “complete” definition, the truth is that the exact origins and behaviour of turbulence are still an unsolved problem.</p><p>However, there are some things that we <em>can</em> say about turbulence. Amongst other things, it is fundamentally chaotic and it is <em>very </em>hard to work out turbulent motion from first principles, even though the Navier-Stokes equations notionally give us everything we need to do so.</p><p>Secondly, turbulence is strongly associated with <em>rotation</em>. Turbulence manifests as swirling, rotating <em>eddies </em>or <em>vortices</em> in the flow, regions where the fluid isn’t flowing in a straight line but is instead rotating and mixing. Because the fluid now contains many of these rotating eddies, the velocity at any one point in a turbulent flow will fluctuate wildly.</p><p>This rotation is opposed by the viscosity of the fluid, a measure of how strongly it resists deformation. As an example, you can put your hand in a bucket of water and freely swirl it around, whereas this is somewhat harder to do if the bucket is full of syrup. Both are fluids, but the syrup is much more viscous.</p><p>Viscosity can be thought of as arising from the <em>friction</em> between fluid elements, which in turn introduces the idea of fluid <em>stresses</em>. These are represented in the Navier-Stokes equations as the terms containing 𝜏, with the interpretation of how these stresses interact with the surface of a fluid volume shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/314/1*dLRpfh6Id_jvPUJhYp0D-Q.png" /><figcaption>An infinitesimally small volume of fluid and the stresses that can act on the faces. The two stresses that lie in the same plane as each face are shear stresses. If you’ve ever used a pencil eraser to rub something out, the little sausage-shaped flecks left behind are the result of shear stresses and their tendency to rotate deformable materials.</figcaption></figure><p>So there’s a link between turbulence and fluid stress. It isn’t the whole story, but it’s a good place to start.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/954/1*4ZLQq684Wl4vAcdgVw7x7w.png" /><figcaption>Simplified view of the flow over a solid wall. The fluid in direct contact with the wall has no velocity at all. This creates friction with the layer of fluid directly above, which moves slowly. The layer above this experiences less friction and moves a little quicker, and so on until the flow reaches a “free stream” condition. In this case, each incredibly thin layer is moving in the same direction in a “laminar” flow.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/309/1*3OhcoqDfMJUTVqabjvof5A.png" /><figcaption>The velocity difference between layers (black arrows) causes “inertial” shear-stress forces (red arrows) to act on a small fluid element which is moving with the flow</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/309/1*ZfMhFJhFbsjkG3pzq1_ALA.png" /><figcaption>In a laminar flow, the viscous forces (blue arrows) resist deformation; the fluid element keeps going in a straight line in a laminar flow</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/309/1*kyF_846WqeRRfD_VKcvmEg.png" /><figcaption>If the ratio of inertial forces and viscous forces is not in balance, the fluid will also experience a net rotation or “vorticity”. This is the origin of “shear-induced” turbulence.</figcaption></figure><p>This relationship between the <em>inertial forces </em>and viscosity gives us a way of predicting the onset of turbulence through the <em>Reynolds number,</em> a dimensionless value that takes into account both the basic fluid properties and the scale of the flow.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*KqoG0OEt6db6AF_9HHwnvw.png" /><figcaption>The Reynolds number; ρ is the fluid density, <em>u is the velocity, L is the “characteristic lengthscale” of the flow and </em>μ is a measure of the fluid viscosity (in this example, specifically the “dynamic viscosity”)</figcaption></figure><p>If this ratio is small then the fluid moves as a laminar flow; however, above a “critical value” the forces start to become unbalanced and the flow quickly transitions into a turbulent flow.</p><p>Rotating flows <em>also</em> represent a velocity gradient, so larger vortices tend to “shed” <em>smaller</em> vortices, which in turn shed <em>even smaller </em>vortices! This process transfers rotational kinetic energy from the largest turbulent length-scales in the flow down to the smallest “dissipative” length-scales, and only ends when the vortices become small enough that the viscous and inertial forces are once again in balance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/788/1*9WjwHgF6D-xYR4QfacfbFA.png" /></figure><p>This “energy cascade” means that to properly maintain the continuity of energy in a simulation, we need to be able to capture the smallest rotational features of the flow. This sets a <em>very </em>small maximum size for our computational volumes, which in turn drastically increases the number of calculations we need to perform.</p><p>So how small do we need to go? We won’t go deep into the specifics, but for a 3 dimensional simulation the number of volume elements needed to capture the full turbulent cascade scales as the Reynolds number to the power of 2.25.</p><p>For a 20mm wide pipe containing water moving at 0.2 meters per second, the Reynolds number is ~4481. Resolving the turbulent flow <em>within a volume of around 20mm³ </em>would require approximately <em>164,275,036</em> individual volumes!</p><p>To make matters worse, the maximum (explicit) timestep that can be applied is limited by the grid scale. In explicit time-stepping, we can’t have a time-step where the distance travelled by the fluid could be greater than the smallest grid element; information from one volume can only travel to its immediate neighbours in a given timestep. This is known as the Courant stability condition</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/1*83a5ihDu7Hqxpwkn4ySqwQ.png" /></figure><p>where C must less than or equal to one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/389/1*LZBR3H81f8bVUaeRfptllQ.png" /><figcaption>Illustration of the difference between a timestep that doesn’t breach the Courant stability criteria and one that does. In the first case (C&lt;1), all the information from the leftmost cell is transferred to its neighbour on the right. In the second case, (C&gt;1), this information has essentially “skipped” the middle cell, a non-physical violation of causality.</figcaption></figure><p>From the grid sizing, the maximum timestep we could use would be around~18 microseconds; solving the flow over a period of just one second would therefore require us to solve the transport equations for those 164,275,036 individual volumes 55,555 times, or about 9 trillion complete sets of transport equations in total. All for a tiny section of pipe containing a very common fluid moving at relatively slow speeds.</p><p>This is still achievable with modern computers, but it is <em>incredibly</em> expensive and time consuming. If we’re going to use CFD for more complex flows and higher Reynolds numbers, we need something more efficient.</p><h3>The part where it gets complicated</h3><p>Until now, everything was working out. We had a method for managing big problems by breaking them down into smaller ones, which works very well for solid mechanics. We were able to adapt this to fluid dynamics by changing the way we thought about the mesh and work out the starting points for the transport equations between volumes.</p><p>Turbulence, and the tiny control volumes that are required to resolve it, introduces a problem which is not tractable for many fluid dynamics problems even in an age of extremely fast large-scale computing. Yet turbulence is vital to understanding fluid flow and making predictions using CFD, so how have we been doing it so far?</p><p>In some cases, we simply resign ourselves to the computational expense and directly resolve the turbulent lengthscales. You can see the outcome (and the incredible detail) of a 2-dimensional DNS simulation in the video below.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fc8zKWaxohng%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Dc8zKWaxohng&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2Fc8zKWaxohng%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/41d99dd2fd69a69c1c7846cd23a3589f/href">https://medium.com/media/41d99dd2fd69a69c1c7846cd23a3589f/href</a></iframe><p>However, for most practical purposes, we can also treat turbulence as a <em>mathematical model</em>, without having to provide enough spatial resolution to resolve the individual eddies.</p><h4>Turbulence as a mathematical model</h4><p>Turbulent flows are chaotic, which means that we can treat turbulence as a <em>statistical</em> phenomenon, allowing us to split the velocity field of a flow into a <em>mean</em> velocity (representing the overall bulk movement of the flow) and a <em>fluctuating</em> velocity that represents the statistical fluctuations of turbulence. Substituting this change in the representation of the velocity into the Navier-Stokes equations gives us the <em>Reynolds-averaged Navier-Stokes</em> (RANS) approach, which accounts for the bulk of practical “engineering” CFD simulations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/939/1*28JEllQQen4-9r12-fzfHg.png" /><figcaption>The momentum equation in the Reynolds-averaging approach. The values of velocity followed by a dash are the fluctuating velocity components, while the over-bar indicates the mean value over time.</figcaption></figure><p>Reynolds averaging leaves us with <em>Reynolds stresses </em>which relate the velocity fluctuations to the stress terms in the original Navier-Stokes equations</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/1*MafmZz6RsbeVvWOMTlcDCQ.png" /></figure><p>We now have some new values that we need to calculate in order to <em>close</em> the system of equations, so we need a way of calculating these Reynolds stresses. For “Newtonian” fluids (which includes things like air and water), the viscous stresses can be assumed to be proportional to the mean velocity gradient. This assumption is known as the Boussinesq hypothesis:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*O-us72nngmtWcgVecR2u4Q.png" /></figure><p>This in turn introduces several new terms:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*wKZh-ExmGmh3qcQq64bzKg.png" /><figcaption>The new terms from left to right; the “turbulent viscosity”, the turbulent kinetic energy, and the Kronecker delta, a value which is 1 if i=j and 0 otherwise, a sort of useful conditional statement that in this case can be thought of as being used as an identity matrix</figcaption></figure><p>Here, we’re particularly interested in <em>k</em>, the turbulent kinetic energy. Making a mathematical model for <em>k</em> gives us a way of calculating the generation (and the associated loss) of kinetic energy in a flow based on the other fluid properties. Not only that, but this also means that we can create an associated transport model for the properties of turbulence, allowing us to treat it just like the other properties such as mass, momentum and energy.</p><p>There are two main approaches to this kind of turbulence modelling, with the difference being how the <em>dissipation</em> of the turbulence is calculated. In the first, the “k-ε” (K-epsilon) model, ε is the rate at which <em>k</em> is converted into thermal energy. In the second, the “k-ω” (K-omega) model, ω is the “specific” dissipation rate per unit volume and time, proportional to the ratio of ε and k.</p><p>It might seem like we’ve included a lot of incredibly specific detail to get to this point, but it’s for a reason. These models, known as the “2-equation” RANS models, are by far the most common approach to CFD.</p><p>For the sake of completeness, sitting somewhere between the DNS approach and RANS models is <em>Large-Eddy Simulation</em> (LES), in which the larger turbulent lengthscales are resolved while the smaller lengthscales are filtered out with their contribution to the flow modelled in a similar fashion to the above. Each approach has their strengths and weaknesses, and it is up to the user to determine which is most appropriate.</p><p>In the case of the RANS models, one of these weaknesses is a further challenge; a model that works well in one flow environment might be inaccurate in another. As a basic example, the k-ε model is most accurate in the free-stream of the flow, while k-ω is the most accurate for flows close to boundaries. In many real fluid applications (such as flow through a pipe or over an aircraft wing), these different environments might be part of the <em>same problem</em>!<em> </em>Increasing accuracy in one flow type using a modelling approach has typically come at the cost of accuracy in another.</p><p>In some cases, the impact of these differences can be relatively trivial. In others, small inaccuracies can cause major problems. Some help is at hand; more recent techniques such as the k-ω Shear Stress Transport (SST) model can effectively switch between the behaviour of the different models depending on local flow conditions, but there’s still a considerable amount of expertise and physical data required to ensure that the results are valid and accurate.</p><p>Turbulence also isn’t the only problem that requires different methods and techniques. Compressible flows, and shockwaves in particular, also pose difficulties that require a more specialised treatment of flux transport that takes into account the flow direction.</p><p>Overcoming these problems currently can’t be done in a unified way, so rather than one single approach to CFD, what we’re left with is a fractured landscape of techniques and models, each with their own strengths and weaknesses. Awareness of this vast range of limitations and assumptions is currently critical for the successful (i.e useful, safe) application of CFD to real problems, which means that the number of people who can make use of CFD is considerably lower than the number of people and organisations who could benefit from it.</p><p>To sum up this problem in the words of NASA:</p><blockquote>“At the moment, CFD is not yet sufficiently predictive and automated to be used in critical/relevant engineering decisions by the non-expert user, particularly in situations where separated flows are present.” — <a href="https://ntrs.nasa.gov/api/citations/20140003093/downloads/20140003093.pdf">NASA CFD Vision 2030 study</a></blockquote><h3>CFD in brief: A summary</h3><p>We’ve covered a lot in this article, from the basic idea of making an approximate solution through to some of the big practical problems that current CFD methods encounter. Here’s a summary of what we’ve said.</p><ul><li>Some problems are complex enough that they can’t be solved through the use of<em> analytic </em>mathematical methods; we have to make numerical approximations.</li><li>Fluid dynamics is one of these problems.</li><li>Making approximations in fluid dynamics means taking the mathematical description of fluid behaviour, the Navier-Stokes equations, and converting them into a form that can be solved with computers</li><li>The approximate method means that the individual calculations are much simpler, but now we have to perform them repeatedly, over potentially millions of individual elements that describe a region of flow.</li><li>In practice there are many different ways of setting up these equations, which depend on the assumptions we make</li><li>CFD is therefore all about <em>trade-offs</em>; do we need the simulation to be 3D or will 2D do? Do we want full resolution of the turbulence or will a simplified engineering model do?</li><li>Answering these questions, selecting the best methods, and understanding what this means for the accuracy of the simulation requires specialist knowledge. Even the ability to construct a good quality mesh is highly dependent on understanding fluid dynamics and the methods you’re going to apply.</li><li>CFD is “expensive” in all respects; time, money and energy.</li></ul><p>The major reasons for this expense are:</p><ul><li>Timestepping: Outside of cases where the flow is in a <em>steady-state, </em>timestepping requires that we repeatedly solve problems that we aren’t necessarily interested in to reach the solutions that we are.</li><li>Scale: The need to break fluids up into many smaller elements means that large simulations require incredible amounts of processing power.</li><li>Complexity: Our current methods for performing CFD mostly rely on translating the differential equations that model fluid behaviour into something computers can work with. Because fluids aren’t simple, all but the most basic flows require us to use very expensive methods or a range of different modelling techniques.</li></ul><p>We’ve said a lot in this article and yet barely scratched the surface of CFD. We’ve described some of the most common methods used for the most common fluid types, but there’s a huge range of problems where further modification is required. This includes things like <em>non</em>-Newtonian fluids (where the Boussinesq hypothesis can’t be applied), multi-phase flows, chemically reacting flows and many more. For all that this article has contained a fair amount of technical complexity, the sheer scope of CFD is vastly more complex still.</p><p>So wouldn’t it be nice if there was <em>another</em> way of doing CFD, one that came from a completely different direction? One that could do away with some of the core difficulties and expenses?</p><p>In our next article, we explain what this approach might be. Best of all, the techniques used in this approach are also compatible with our next-generation optical processing hardware, and so we also demonstrate the first application of optical computing to this method.</p><p>For now, if you’d like to know more about our objectives and methods in this area or would like to suggest another application for our technology, you can always <a href="https://optalysys.com/contact-us">contact us</a> via our website.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5ad147c091d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/optalysys/computational-fluid-dynamics-and-optical-computing-5ad147c091d">Optical computing for computational fluid dynamics: An introduction to CFD</a> was originally published in <a href="https://medium.com/optalysys">Optalysys</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Optical Computing for Cryptography: Fully Homomorphic Encryption]]></title>
            <link>https://medium.com/optalysys/optical-computing-for-cryptography-fully-homomorphic-encryption-ee817ddc861c?source=rss-9326ad4c51d1------2</link>
            <guid isPermaLink="false">https://medium.com/p/ee817ddc861c</guid>
            <category><![CDATA[homomorphic-encryption]]></category>
            <category><![CDATA[post-quantum-cryptography]]></category>
            <category><![CDATA[optical-computing]]></category>
            <category><![CDATA[silicon-photonics]]></category>
            <dc:creator><![CDATA[Joseph Wilson]]></dc:creator>
            <pubDate>Fri, 15 Jan 2021 11:11:18 GMT</pubDate>
            <atom:updated>2022-08-05T09:10:39.105Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6Gw8RK3T5oVB4aiZPOkpOg.png" /></figure><p>With <a href="https://medium.com/u/f0fec005a59a">Florent Michel</a> and <a href="https://medium.com/u/2158f00e598e">Edward Cottle</a></p><p>Fourier-optical computing technology of the kind developed by <a href="https://medium.com/optalysys/optalysys-what-we-do-and-why-we-do-it-20ab416c5ad0">Optalysys</a> has the capacity to deliver tremendous improvements in the computational speed and power consumption needed for artificial intelligence algorithms, but that’s not the only field to which the technology can be applied. The Fourier transform is incredibly versatile, and there are many seemingly unrelated problems which can benefit from a faster method of performing it.</p><p>One of these fields is a category of new methods for performing <em>encryption, </em>the process by which information is mathematically scrambled for security purposes. It’s expected that quantum computing will <a href="https://medium.com/optalysys/optical-computing-for-post-quantum-cryptography-why-we-need-pqc-f39d21ae4466">pose a major risk</a> to some of the existing techniques that keep communications secret and secure, so we need new <em>post-quantum</em> encryption methods that don’t share the same mathematical vulnerabilities to quantum attacks.</p><p>While there have been a range of proposed alternatives for replacement methods, one of the most promising is known as <em>lattice-based</em> cryptography. In this approach, the mathematical security of the various cryptographic tools is provided by a range of “hard” problems on lattices, a class of mathematical objects with structures that repeat infinitely. We’ve described the basic security concepts of lattice-based cryptography in a <a href="https://medium.com/optalysys/optical-computing-for-cryptography-lattice-based-cryptography-a391d48ea6bf">previous article</a>.</p><p>One of the great things about lattice cryptography is its flexibility; not only can it be used to replace the parts of cryptography that are vulnerable to quantum attack, but certain constructions of it can be used to perform entirely <em>new</em> forms of cryptography, enabling us to do things that we couldn’t do before.</p><p>Crucially, one of these new uses is of <em>immense</em> value, both commercially and from the perspective of user privacy. It is a technique that allows for complete security at all stages of remote data processing, even when that data is being worked on.</p><p>This new model of cryptography is known as <em>Fully Homomorphic Encryption, </em>or<em> </em>FHE.</p><p>However, the computational complexity of FHE has meant that until recently it simply hasn’t been practical to use at scale.</p><p>That is now changing; a combination of ever more powerful computers and significant advances in technical implementation are placing the benefits of FHE within reach, and the race is on to be the first to bring these spectacular advantages into the wider world.</p><p>At Optalysys, our optical Fourier-transform hardware has the ability to shatter one of the key computational bottlenecks which is currently slowing FHE down. Other companies taking aim at the problem include <a href="https://zama.ai/">Zama</a>, the first company dedicated to the development of FHE, as well as the computing giants IBM and Microsoft.</p><p>In this article, we describe the basic idea of what FHE is and how it functions, and then show how we can apply our optical computing system in performing some of the key stages in this new model of cryptography</p><h3>Fully Homomorphic Encryption: What is it?</h3><p>Securing digital information has never been easy. The methods we use today work when applied correctly, but information breaches are still so common that news of a large cyber-attack or data theft is hardly surprising.</p><p>And while we provide a lot of information to various service providers without too many concerns, there are some things that we really want to keep secret. Most of us trust online services and sales portals with our credit card details because the damage that can be done with those is comparatively limited, but very few of us would be inclined to trust those same services with sensitive information such as medical or bank records.</p><p>This isn’t paranoia; most of us have some understanding of the dangers, even if only informally. We know that computers, computer software and encryption schemes are complex systems and that it is very hard to make such things definitively “secure”. We also know that not everyone is trustworthy; even if you trust a company, it only takes one corrupt employee for protected information to find its way into the wrong hands. And the numbers aren’t promising; in the US, <a href="https://www.securitymagazine.com/articles/92533-nearly-80-of-companies-experienced-a-cloud-data-breach-in-past-18-months">80% of 300 surveyed companies</a> working in the cloud sector indicated that they had suffered at least 1 data breach in the last 18 months.</p><p>Giving over sensitive information for processing needs something a step beyond what is currently on offer, where even the most secure approaches are ultimately backed only by good IT practice and trust. It requires not only the kind of mathematical guarantee that encryption provides, but expert knowledge to ensure that the technical implementation is robust.</p><p>FHE gives us a way of meeting these requirements. And by combining cutting edge methods developed by <a href="https://zama.ai/">Zama</a>, with the unprecedented power and utility of our Fourier-optical computing system, we can present a new way forward for a commercially viable implementation of FHE.</p><p>So what is FHE, and how does it help? A significant part of why information on the internet should always be considered insecure to some degree is because of the way that encryption works. When browsing the internet, you usually transmit information over a channel secured with transport layer security (TLS). If you send details to a website, they are (hopefully!) stored in an encrypted form so that even if they’re stolen, they cannot be read.</p><p>But right now, computers cannot <em>work</em> on data which has been encrypted. Performing calculations on data requires that the underlying <em>structure</em>, the mathematical relationship between each element, is preserved.</p><p>One of the most fundamental properties of relationship preservation is known as <em>homomorphism. </em>For the purposes of understanding FHE, this means that when you add or multiply things together, then everything changes in a consistent way. Current encryption methods don’t preserve this structure (either fully or at all), so any time a service needs to work on the information you send it, it must first decrypt the data, making it vulnerable in the process.</p><p>Data encrypted using fully homomorphic encryption doesn’t need to be decrypted in order to work on it. Through some very clever mathematical tricks, it allows us to perform <em>any</em> calculation on encrypted data that we would on unencrypted data, although at significant computational cost. It is this computational cost which has kept FHE from realising its full potential; despite the development of the first <em>fully</em> homomorphic encryption scheme in 2009 (partially homomorphic schemes have existed since the invention of RSA in 1977), it was simply too calculation-intensive to be practical.</p><p>That has changed; not only are more modern computers more powerful, but recent advances in the way that FHE schemes are designed have driven the computational requirements down significantly. It’s still slower compared to working with unencrypted data, but not so slow that it can’t be useful.</p><p>This is revolutionary. Now, even sensitive data can be sent to a third party cloud service and stored, worked on, or searched without ever revealing the actual <em>content</em> of that data, even to the hardware that is working on it! At all stages the data remains safely encrypted. Because FHE is based on post-quantum cryptographic constructions, it’s even secure against the next generation of computing threats.</p><h3>FHE: The basics</h3><p>So, where do we start? To make a <em>fully</em> homomorphic encryption scheme, we need a way of hiding information in a mathematically secure way that still allows us to perform two basic operations on it; addition and multiplication.</p><p>The idea is that we can take our unencrypted data (we call this the “plaintext”) and encrypt it using an FHE-friendly method, creating a “ciphertext”. As a consequence of the property of homomorphism, if we add or multiply the contents of two or more ciphertexts together, then when we <em>decrypt</em> the result the plaintext we retrieve should be the same as if we’d performed the operations on unencrypted information.</p><p>This might not sound particularly useful; after all, we said above that FHE allows us to perform <em>any</em> calculation that we like on encrypted data. This is still true though, because while addition and multiplication are simple operations, they are all that is needed to implement a system of <em>Boolean logic,</em> the mathematical system behind the workings of modern computers. In an integrated circuit (such as a CPU), combinations of transistors are used to create electronic gates that perform operations in Boolean logic such as AND, OR, NOT and so on.</p><p>By creating a system of Boolean logic using addition and multiplication (technically all we need is the ability to perform either a NAND or NOR operation, as all other gates can be constructed using combinations of these gates), we can build a circuit of homomorphic operations equivalent to those that would be applied to the unencrypted data if worked on by a CPU.</p><p>This is great, but it is also <em>incredibly</em> slow compared to working on unencrypted data; the processor now has to perform a huge number of calculations just to mimic the behaviour of a single gate-level operation, the kind of fundamental task which is performed billions of times a second on a modern CPU core.</p><p>However, until recently, there were even bigger performance issues preventing FHE from being practical.</p><h4><em>Learning with errors and the first FHE scheme</em></h4><p>Almost* all current FHE schemes are based on a post-quantum cryptographic tool called the <em>l</em><a href="https://cims.nyu.edu/~regev/papers/lwesurvey.pdf"><em>earning with errors</em></a><em> </em>(LWE)<em> </em>problem, in which the difficulty of recovering information hidden using LWE hinges on the difficulty of recovering a secret piece of information given only <em>approximate</em> solutions to vector problems that use that secret information.</p><p>LWE is a very versatile problem in cryptography; the mathematical security of LWE can be shown to be related to the difficulty of solving certain hard problems on lattices (and thus quantum-secure), and it preserves the all-important homomorphically additive and multiplicative properties that allows us to perform FHE. However, as a fundamental part of the LWE method, we have to add some random noise to the values we calculate using the secret information to make it secure.</p><p>This isn’t normally a problem for LWE (or the related r<em>ing-l</em>earning with errors problem; more on that in a bit), but it’s a major headache for FHE. It means that when we add or multiply two ciphertexts encrypted using an LWE method, the noise in the secret data also increases. This isn’t much of a problem for addition, but when we multiply, the noise increases <em>quadratically. </em>If we perform too many operations in a row, the noise becomes so great that we <em>cannot </em>reliably decrypt the information; it is lost forever. If we can only perform a limited number of operations before the information is lost, we can only evaluate circuits of limited depth. This is called a <em>somewhat</em> homomorphic encryption scheme.</p><p>It wasn’t until 2009 that Craig Gentry gave the world the <a href="https://crypto.stanford.edu/craig/craig-thesis.pdf">first working FHE system</a>, using lattice techniques which were closely (but not exactly) related to the learning with errors problem. Key to this development was Gentry recognising that the decryption process for an FHE scheme could <em>also </em>be converted into a circuit that can be performed using homomorphic operations. In essence, this allows an FHE scheme to execute it’s <em>own</em> decryption circuit!</p><p>Here’s why that’s useful. Under a normal LWE encryption scheme, we can decrypt the ciphertext to retrieve the plaintext, and this plaintext doesn’t have any noise in it at all.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/591/1*x1sGq3ZjQD6HGp_uGL7Ppw.png" /><figcaption>The normal way of decrypting a ciphertext, using a decryption circuit implemented on the CPU. Even if the data is encrypted using an LWE method, the plaintext contains no noise at all.</figcaption></figure><p>By passing the ciphertext and the decryption key through a decryption circuit executed using homomorphic operations, this produces a new ciphertext which has the same (or slightly higher) level of noise as a freshly-encrypted ciphertext. If it helps, think of the output of the homomorphic decryption circuit as a plaintext, albeit one which has been “decrypted” into a form which is <em>still encrypted</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/654/1*0iqjTZAnS72Yw-NIKPXH7A.png" /><figcaption>The decryption circuit as executed in an FHE scheme; everything inside the red box remains encrypted, including the output of the decryption circuit. This “box” concept was invented by Craig Gentry to help <a href="https://crypto.stanford.edu/craig/easy-fhe.pdf">explain his scheme</a></figcaption></figure><p>This means that we can repeatedly<em> </em>perform operations on the data, stopping every now and again to refresh the ciphertext. As long as we can perform at least one additional NAND operation before we need to perform the decryption circuit, this allows us to execute circuits of <em>any</em> depth without having to decrypt the information.</p><p>This process is known as “bootstrapping”, and it’s what made the first FHE scheme (denoted as [Gen09]) possible. The original [Gen09] scheme with bootstrapping is sometimes known as “pure” FHE. However, this also has a further big performance hit, as now most of our encrypted operations have to be reserved for performing the decryption circuit!</p><p>So under pure-FHE, not only do we have to perform calculations to mimic gates (which is inherently slower than working with unencrypted data), but most of those calculations have to be dedicated to something<em> </em>other than the <em>useful</em> things we want to do with the data.</p><p>We’d like it if things were faster. We need better methods and better hardware.</p><p>*The other problem on which FHE can be based is the <a href="https://eprint.iacr.org/2009/616.pdf">Approximate-Greatest Common Divisor</a> problem, which also uses lattice concepts</p><h3>Better methods through ring learning with errors</h3><p>There has been much progress in the field of FHE since [Gen09]. Brakerski, Gentry and Vaikuntanathan managed to create a scheme (<a href="https://eprint.iacr.org/2011/277.pdf">[BGV12]</a>) in which bootstrapping is optional, using a different and more efficient method of noise management called <em>modulus switching</em>. Both [BGV12] and a different scheme, [<a href="https://eprint.iacr.org/2016/421.pdf">CKKS16</a>], are implemented in IBM’s <a href="https://github.com/homenc/HElib">HELib</a> homomorphic encryption library. This library powers IBM’s <a href="https://www.ibm.com/blogs/research/2020/06/ibm-releases-fully-homomorphic-encryption-toolkit-for-macos-and-ios-linux-and-android-coming-soon/">developer toolkit</a> for FHE, which includes a demonstration of a <a href="https://eprint.iacr.org/2019/1113.pdf">machine-learning network working on encrypted data</a>.</p><p>However, for our purposes we are most interested in a scheme called <em>Toroidal</em> Learning with Errors, or <a href="https://eprint.iacr.org/2018/421.pdf">TLWE</a>. This is the scheme used in an open-source FHE library called <a href="https://github.com/zama-ai/concrete">Concrete</a>, which allows for the rapid development of complex FHE applications including encrypted AI. Concrete was developed by <a href="https://zama.ai/">Zama</a> and powers their own offerings in the field of encrypted AI.</p><p>[BGV12], [CKKS16] and TLWE can be constructed using a modified version of the learning with errors problem called <em>ring</em> learning with errors (RLWE). We won’t go too deep into the differences between LWE and RLWE in this article, but the main difference is that RLWE is a version of LWE in which the basic addition and multiplication operations are performed over abstract algebraic structures known as <em>rings</em>.</p><p>Rings are an extension of the idea of mathematical <em>sets. </em>Sets are one of the more fundamental concepts in mathematics, and formalise the idea of “collections” of things. Some sets are so common that they have individual names and symbols. The integers (the whole numbers over the range -infinity to +infinity) form a set that should be familiar, and this set is usually denoted by the letter Z:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*FqsXO-5FVgTH8wFM62jBNg.png" /><figcaption>The set of integers</figcaption></figure><p>Rings build on this idea by bringing the notions of addition and multiplication into set theory. Rings have a range of formal properties that we won’t fully explore here, but one particularly important property is that adding or multiplying two elements of the ring returns a value which is also an element of the ring.</p><p>Think about the integers; adding together two integers always returns another integer, and we can create any <em>other</em> integer in this way. We can say that <em>equipping</em> the set of integers with the abstract idea of addition and multiplication creates a ring.</p><p>We can also extend something conceptually similar to the idea of a <em>modulus </em>to ring operations. If you can read and interpret the time shown on a clock, you’re almost certainly familiar with arithmetic in modulus(12), modulus(24), and modulus(60). In brief, it’s the idea that you can define a maximum value beyond which a number larger than the modulus “wraps back around” to the start. This can also be seen as the remainder after the larger number is divided by the number that defines the modulus.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/264/1*_Vhq7IVU7CmGSwx_sPyUmg.png" /><figcaption>Some basic representations of modular integer arithmetic. The red blocks indicate how many times the modulus value fits completely within the number on the left hand side of the equations above, while the blue blocks indicate the remainder. When it comes to operations in modular arithmetic, the remainder is the important result.</figcaption></figure><p>When extended to the formalism of rings, we call the resulting mathematical structure a <em>quotient ring</em>. Because the integers can form a ring, we can use them again for another intuitive example; the basic modular arithmetic in mod(5) that we described above can also be viewed as taking place in the quotient ring:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/754/1*Jzq_vM9SeRUW4kSTmkAqAQ.png" /></figure><p>However, rings allow this idea to be extended to more complex mathematical structures too. This is tremendously helpful; in some cases the properties of modular arithmetic form part of the cryptographic basis for a scheme (as is the case for the RSA cryptosystem). More generally, the use of a modulus also allows us to ensure that we’re always working with numbers that a computer can manage efficiently, even when we’re performing operations involving <em>very </em>big numbers.</p><p>Ring learning with errors is a version of the learning with errors problem that restricts itself to working in <em>polynomial</em> rings. Polynomials are equations of the form</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rwJaKJMMwaPCQJvo_9DnvQ.png" /><figcaption>A basic polynomial, where n is the number of terms.</figcaption></figure><p>which have their own rules for addition and multiplication. Polynomial systems can also form rings; for example, multiplying the polynomials (3 + x) and (2+x) returns 6 + 5x + x² (which is another polynomial), while adding (3 + x) and (2+x) gives 5 + 2x (also a polynomial). Just as we did for the integers, we can also define a polynomial quotient ring. Particularly common quotient rings in RLWE are</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/754/1*DbtrGw_86ntVHKwiDhdv1w.png" /></figure><p>and</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/754/1*4zq2uF53qnJh9uEMj7NzvQ.png" /></figure><p>Polynomial multiplication is fairly simple for small polynomials, but can get complicated very quickly. If we’re using the method taught in schools, then the <em>algorithmic</em> complexity in multiplying two polynomials of the same length together is <em>O(n</em>²<em>)</em>. However, there’s a more efficient calculation method that uses the Fourier transform; multiplying two polynomials together is equivalent to:</p><ul><li>Taking the Fourier transform of each polynomial. In electronic systems, the Fourier transform has algorithmic complexity <em>O(n log(n))</em></li><li>Performing the <em>element-wise</em> multiplication of the two polynomials in Fourier space, an operation with algorithmic complexity <em>O(n)</em></li><li>Performing the inverse Fourier transform (also complexity <em>O(n log(n)) </em>in electronics<em>) </em>on the element-wise product, the output of which gives us the product of the two polynomials.</li></ul><p>Polynomial multiplication can therefore be thought of as equivalent to a <em>convolution </em>operation. Conventional electronic systems can perform these steps, but the mathematical construction of FHE means that an <em>astonishing</em> number of polynomial multiplications are required, and even with modern hardware this is the main impediment to timely and efficient FHE operations.</p><p>Our <a href="https://medium.com/optalysys/optalysys-what-we-do-and-why-we-do-it-20ab416c5ad0">optical system</a> was originally designed to perform high speed convolutions with efficiency beyond anything achievable with silicon electronics. While originally conceived of as a means of accelerating Convolutional Neural Networks, we can readily apply it to operations in cryptography too. Here’s our example.</p><h3>Better hardware with Fourier-optical computing</h3><p>To use our optical hardware for FHE encryption operations, we created our own FHE-supporting code based on a version of the learning with errors problem known as “canonical torus learning with errors” (CTLWE). This is the same method used by <a href="https://eprint.iacr.org/2018/421.pdf">Chillotti et al </a>to create the highly efficient <a href="https://tfhe.github.io/tfhe/">TFHE scheme</a>, which is itself based in part on the RLWE variant of the Gentry-Sahai-Waters [GSW13] system.</p><p>Our optical system works with 2-dimensional data, so we modified the TLWE method to operate with <em>multinomials, </em>which work like polynomials but with more than one unknown value. For the sake of simplicity, we use the <em>symmetric key</em> version of the scheme, in which there’s a single piece of secret information which is used to perform both encryption and decryption.</p><p>This is in contrast to the <em>asymmetric</em> key version in which we have two different pieces of information, one of which is used to perform encryption and the other used to perform decryption. The asymmetric key version is more useful because it allows us to create a <em>public-key</em> system for secure communication, but our choice isn’t particularly limiting; the same choice was made by the developers of HElib for the first public version, and by Microsoft for the SEAL library.</p><p>Other than these considerations, we’re following the original TFHE encryption method very closely. There’s a great write-up of the scheme by Chillotti, Joye and Pallier <a href="https://whitepaper.zama.ai/">here</a>, which (besides providing the background mathematics that describes how and why everything works) also describes a very clever use of the bootstrapping operation to perform tasks useful for artificial intelligence methods.</p><p>Central to this utility is the way in which TFHE provides a means of performing a multiplexing operation as part of the bootstrapping. This is more useful than it might sound; not only does this allows the bootstrapping phase to perform useful computation, but it allows <em>non-linear</em> operations (such as the RELU function in a convolutional neural network) to be performed natively, a task which would otherwise require a great many gate-level operations.</p><p>This <em>vastly</em> boosts the the speed of FHE-encrypted AI networks, making the Concrete library an excellent starting point for commercial application. Not only that, but the tasks involved in performing this bootstrapping stage are dominated by the need to perform a huge number of Fourier transforms, which is where our hardware can provide a benefit.</p><p>For now, we’ll demonstrate how our system can be used to perform the fundamental encryption and decryption operations. Because the maths is quite specialised, in this article we translate the encryption process into pictures.</p><p>We begin by generating a key and a set of random multinomial coefficients. In the TLWE case, the key is made of binary values drawn uniformly at random from the binary set {0,1}, while the random coefficients are uniformly random values <em>between</em> 0 and 1. Because we’re working with LWE (and therefore fundamentally working with lattices), it’s also helpful to think of the multinomial coefficients as a multidimensional vector of random values.</p><p>We’re working with our prototype Fourier-optical system (described <a href="https://medium.com/optalysys/optalysys-what-we-do-and-why-we-do-it-20ab416c5ad0">here</a>), which has a resolution of 5x5 light-emitting elements. To achieve a security parameter of 100 bits, we use 5 5x5 arrays for the key. Both the key and the random vector can therefore be represented as 3-dimensional 5x5x5 arrays as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*inQI04hgwUt3GSPOpHerBw.png" /><figcaption>The key and some random multinomial coefficients with values between 0 and 1, as shown visually. The random numbers used here are generated using a pseudorandom number generator.</figcaption></figure><p>We then want to efficiently multiply the key and the random multinomials together.</p><p>Normally, this would be the single most computationally expensive part of the encryption process. However, we can avoid<em> </em>this computational time and expense by using the <em>optical </em>Fourier transform, a process with <em>O(1)</em> algorithmic complexity!</p><p>To do so, we first use our optical system to perform a Fourier transform of each 2-dimensional layer in the key and the block of random multinomials, like so:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MvTy_7c7-AfYddQx2ojc9A.png" /><figcaption>Fourier transforming part of the key using the optical system. We convert each 2D layer of the key into an optical representation, which is then Fourier transformed by the lens and detected on the other side. We’re showing only the real parts of the Fourier transform here, but the output is a complex number.</figcaption></figure><p>We first perform the element-wise multiplication of the Fourier transform of each layer, and then perform the inverse Fourier transform using the optical system to complete the multiplication. We do this repeatedly to build up the product of the key and the random values. We also retain the original block of random multinomials for later use.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FVlp30auVtPoJMJ32LDxZA.png" /></figure><p>Once we have completed the multiplication process, we then sum the layers of this 3-dimensional product array to create a 2-dimensional array.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oqMWrs_FN2570lldaqff1g.png" /></figure><p>We add this 2-dimensional array to the 2-dimensional message that we want to send. The addition is performed in modulus(1).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1019/1*qs9ScDUhDKdfWYVi9Qhagg.png" /></figure><p>We then draw random noise from a Gaussian distribution on the segment [0,1) with periodic boundary conditions (topologically, this is equivalent to drawing from a Gaussian random distribution on the unit circle in the complex plane) and add it to this new 2-dimensional array.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CzVi8OYN0-4yUShj5YrEhA.png" /></figure><p>We then append this output array to the original array of random multinomials to create the final ciphertext.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mbLUcRTwJ7RRfLNhdXb1sQ.png" /></figure><p>We can now perform homomorphic operations on this ciphertext. Here’s what happened when we encrypted two messages using this technique, homomorphically added them (a simple addition of the respective elements in the two ciphertexts), and then decrypted the result. This is a real result, processed using our optical system.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*SdvmksJFisRslroHfEGaOw.png" /></figure><p>On decrypting the third cipher, we retrieve an output corresponding to what would have happened if we had directly added the two plaintexts together.</p><p>We then extended this process to work on more than 2 ciphertexts. To do so, we needed to generate some data. We created a set of probability distributions over a 5x5 grid like so:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/209/1*vzVbPzqjd2txrQXElfOkmQ.png" /></figure><p>And then used these probabilities to generate 100 random 5x5 messages of binary values with the condition that each element of the message would either be a 1 (with respect to the above probabilities) or a zero</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/587/1*L5_j0nPVePF8NmXcEqppgQ.png" /></figure><p>We encrypted these random messages using the above process, homomorphically added the ciphertexts together, and then decrypted the result. The decrypted results obeyed the statistical distribution used to generate the data, indicating that we had successfully performed a homomorphic <em>aggregation. </em>This is a method of collecting data and extracting statistics from it without ever revealing any single unencrypted input (for example the kind of data taken from individual users of a service, who might not want their individual habits revealed), and is becoming increasingly popular as a <a href="https://www.researchgate.net/publication/280031108_Secure_Data_Aggregation_with_Fully_Homomorphic_Encryption_in_Large-Scale_Wireless_Sensor_Networks">user security method</a> as more and more data is gathered from a multitude of devices and sensors.</p><p>We are currently adapting the larger Concrete library to use Fourier transforms generated using our optical system. Because Fourier-optical computing has a significant speed and efficiency advantage over current electronic methods (both in terms of algorithmic complexity and the physical speed at which an optical system can operate), such a system has major promise as a future hardware accelerator for FHE.</p><p>In future articles, we’ll be digging in to the background of post-quantum cryptography to explain why we need it, how it works, and demonstrating an application of our device in performing another post-quantum cryptographic scheme called NTRU. We’re also working on an implementation of the [BGV12] FHE cryptosystem, which we’ll be covering soon.</p><p>That’s all for this article. However, for the interested, we present some of the code we used to perform the encryption and decryption process using our optical system in the section below. If you’re interested in learning more about the way our optical computing system works or the problems that we can apply it to, check out the rest of our articles on Medium, or visit our website <a href="http://www.optalysys.com/">here</a>.</p><h3>Using the optical Fourier transform: A code snippet</h3><p>Here, we present the part of our C++ code that invokes our optical system. This is going to be a more technical section than those above, and assumes that you’re familiar with both C++ and some of the fundamental mathematics.</p><p>We first show the encryption function. Here, CTLWE is the name of the class and ‘v1D’, ‘v2D’ and ‘v3D’ are aliases for 1, 2 and 3-dimensional arrays (i.e vectors, vectors of vectors, and vectors of vectors of vectors). The integers ‘N1’ and ‘N2’ are the size of the multinomials in each direction (1 plus their degrees in the two variables) and ‘k’ is a parameter of the CTLWE scheme which can be interpreted as the depth of the key. (In the above example, these three parameters are equal to 5.)</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8161e10acafb8bc7e616a6bdea47d51b/href">https://medium.com/media/8161e10acafb8bc7e616a6bdea47d51b/href</a></iframe><p>After the first step, ‘a’ represents a set of random multinomials with coefficients chosen uniformly between 0 and 1 (the variable ‘u’ is the uniform distribution over the interval [0,1) and ‘gen’ is a Mersenne twister PRNG with period 2¹⁹⁹³⁷-1, initialised by the class constructor). The array ‘b’ is first computed as the sum of the message and dot product of the secret key with ‘a’. Some Gaussian noise with zero mean value is then added. The custom function ‘add_multinomial’ adds the second argument to the first, and ‘d’ is a Gaussian distribution with zero mean. The standard deviation of ‘d’ is one of the parameters of the CTLWE class. The custom function ‘modulo_1’ computes the value of a real number to mod(1), returning a value between 0 and 1.</p><p>While a quick look at the number of lines may lead us to think that the choice of ‘a’ or casting the coefficient modulo 1 is the main part of the function, the bottleneck is actually the call to the function ‘dot_product’, which performs the dot product of the key and the array of random multinomials. We will come back to it shortly.</p><p>Before that, let’s look at the decryption function</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/313bb377b6955705b3f11abf9a8bb031/href">https://medium.com/media/313bb377b6955705b3f11abf9a8bb031/href</a></iframe><p>Here, ‘M’ is the number of different possible values each coefficient can take (it is a parameter of the CTLWE scheme). While the operation of rounding the coefficients takes up several lines of code, it is in practice relatively fast. Converting the values 1 to 0 is fast too. Again, the bottleneck is the dot product function.</p><p>With that in mind, let us see how the dot_product function is implemented:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1b129aed7a590c9029b20b550b5ad640/href">https://medium.com/media/1b129aed7a590c9029b20b550b5ad640/href</a></iframe><p>It involves two operations on multinomials: addition and multiplication. The first process is much faster than the second one.</p><p>The function performing the multinomial multiplication is shown below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c7e06ebf3abe90c37f999aa44353ea15/href">https://medium.com/media/c7e06ebf3abe90c37f999aa44353ea15/href</a></iframe><p>In the full code, the function multinomial_multiplication first calls a wrapper function which turns each of the two arrays into an array of complex numbers. We then call the function mulMult, followed by a function to convert the complex array back into a real one. The conversions have a linear complexity in the number of coefficients, and we omit them here for conciseness. The type “co” is a custom complex type. The functions co_mult and co_exp compute, respectively, the product and exponential of complex numbers. The function mulMult proceeds in 5 steps:</p><p>1. add a phase to each coefficient,<br>2. compute the discrete Fourier transform of each multinomial,<br>3. perform a component-wise multiplication in Fourier space,<br>4. compute the inverse Fourier transform,<br>5. add a phase opposite to that of the first step.</p><p>Steps 1, 3, and 5 have a linear complexity. The first and last steps are required to ensure the multiplication is performed in the correct ring of multinomials: without the dephasing, the multiplication in Fourier space would yield a product in the modulus of (X^(N1))–1 and (Y^(N2)–1), where X and Y are the two variables. For the CTLWE algorithm, we want to compute products modulo (X^(N1)+1) and (Y^(N2)+1) instead, which requires a dephasing step. Steps 2 and 4 are the bottlenecks on electronic hardware, with complexity <em>O(n log n)</em> where <em>n</em> is the total number of coefficients (equal to the product of N1 and N2).</p><p>The optical computing system under development at Optalysys will be able to significantly accelerate the computation of the Fourier transform and its inverse, thus eliminating the main bottleneck in the encryption and decryption functions. We have already implemented these functions on the current demonstration optical system. While its speed does not reflect what the next device will be able to achieve, we obtained perfect decryption results, including after performing sums of tens of ciphers. This constitutes a proof of principle that the CTLWE scheme (or any cryptosystem relying on polynomial or multinomial multiplication) can be implemented optically, with the potential for significant acceleration and reduction in power usage that optical computing provides.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ee817ddc861c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/optalysys/optical-computing-for-cryptography-fully-homomorphic-encryption-ee817ddc861c">Optical Computing for Cryptography: Fully Homomorphic Encryption</a> was originally published in <a href="https://medium.com/optalysys">Optalysys</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Optical Computing for Cryptography: Lattice-based Cryptography]]></title>
            <link>https://medium.com/optalysys/optical-computing-for-cryptography-lattice-based-cryptography-a391d48ea6bf?source=rss-9326ad4c51d1------2</link>
            <guid isPermaLink="false">https://medium.com/p/a391d48ea6bf</guid>
            <category><![CDATA[cryptography]]></category>
            <category><![CDATA[lattice-cryptography]]></category>
            <category><![CDATA[optical-computing]]></category>
            <category><![CDATA[post-quantum-cryptography]]></category>
            <dc:creator><![CDATA[Joseph Wilson]]></dc:creator>
            <pubDate>Fri, 15 Jan 2021 10:56:55 GMT</pubDate>
            <atom:updated>2021-10-04T13:05:53.923Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*McIM86IMUeaVE2DLuYs66w.png" /></figure><p>With <a href="https://medium.com/u/f0fec005a59a">Florent Michel</a></p><p>In our <a href="https://medium.com/optalysys/optical-computing-for-post-quantum-cryptography-why-we-need-pqc-f39d21ae4466">previous</a> article on cryptography, we took a look at the concepts behind one of the most popular public-key cryptography schemes, and explained why we need an alternative because of the threat of quantum computing.</p><p>The security of one of the most popular public-key encryption schemes, RSA, is based on the difficulty of factoring large primes, a task which is anticipated to be much easier for quantum computers. One of the most promising routes for building quantum-secure cryptosystems is l<em>attice-based cryptography, </em>where the security of the scheme is based on the properties of mathematical objects called lattices.</p><p>When we say that a cryptosystem is “lattice-based”, we mean that breaking the security of the scheme can be shown to be fundamentally equivalent to solving certain difficult <em>computational </em>problems on lattices, not that lattices are themselves inherently cryptographically secure. There are many mathematical problems involving lattices which are perfectly solvable.</p><p>This might seem obvious, but it’s an important distinction to make. Lattice-based schemes are not secure just because they’re lattice based, and require the same oversight as any other cryptographic scheme. The United Kingdom’s Government Communications Headquarters (GCHQ) developed their own lattice-based cryptographic scheme that they called Soliloquy, only to <a href="https://docbox.etsi.org/Workshop/2014/201410_CRYPTO/S07_Systems_and_Attacks/S07_Groves_Annex.pdf">later abandon it</a> when they realised that there was an effective quantum computing attack against it.</p><p>Fortunately, while Soliloquy is an example of a lattice-based scheme that was vulnerable to a quantum attack, it also relied upon a very different “hard” problem to the ones that we’re going to look at today.</p><p>In this article, we take a look at the lattice problems which can be used to make cryptographic constructions that aren’t just secure against attacks from quantum computers, but can form the basis of many different <em>types</em> of cryptographic system. Some of these systems can themselves be used to construct ways of performing fully homomorphic encryption, a phenomenally useful concept that can revolutionise the way in which we handle and process sensitive data.</p><p>We’ll start by explaining what a lattice is, and then build on that to explain why certain problems involving these structures have the properties that we’re looking for in a mathematical problem on which to base public-key cryptography.</p><h3>Basic Lattice Ideas</h3><p>Lattices are mathematical structures that repeat infinitely in space. Here’s a basic 2-dimensional example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*Y8EJuq78d_d9A8p4N-DPOQ.png" /><figcaption>A simple triangular lattice in 2 dimensions. The black dots are the “points” of the lattice; the white space enclosed by the grey lines surrounding each point indicates the area which is closer to that point than any other.</figcaption></figure><p>Lattices can have more than two dimensions. Here’s a three-dimensional one:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*HV40XdcEEmYJTn-isvKxig.png" /><figcaption>A 3-dimensional cubic lattice</figcaption></figure><p>We can even define a lattice with a higher numbers of dimensions. While we can’t visualise them as easily, they work just the same mathematically.</p><p>Because lattices repeat themselves, we can use only a few very basic rules to define where every single point should be, even though they’re infinite in size. For a lattice of <em>n</em> dimensions, we can make this definition using only <em>n “</em>vectors”, collections of numbers that define both a direction and a magnitude. Let’s try this out by making a basic square lattice.</p><h4>Making a lattice</h4><p>There’s no point in the lattice which is more “important” than any other, so we can pick any position to start with:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/10/1*zp_OzAQariwc2DiXOMeP-Q.png" /></figure><p>We’re working in 2 dimensions, so we only need 2 vectors to define the rest of the lattice. We’re making a square lattice, so the vectors are at right-angles to one another. Starting with our initial lattice point, we can draw vectors out to define the position of two new points, like so:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/62/1*kGWVPflFATtlZaqWczXL4Q.png" /></figure><p>Then we can use one of these new points and the <em>same vectors </em>to draw out two more new points…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/114/1*5ktDN6op_C9228tulABm4A.png" /></figure><p>…and we can keep going…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/374/1*C6Fx_g47uYsbLkqN8vfSog.png" /></figure><p>… forever, in principle. Any new point in the lattice can be constructed as a straightforward <em>integer</em> multiplication of these simple vectors, so more generally we can say that a lattice is a <em>set</em> of integer combinations of linearly independent vectors.</p><p>This is a very simple concept, but there’s a fiendishly difficult problem hiding in plain sight. It’s called the <em>shortest vector problem.</em></p><h4>The Shortest Vector Problem</h4><p>When we made our lattice, we picked two very simple vectors as the <em>basis</em> for constructing our lattice. If you’re familiar with Pythagoras’s theorem, you can quickly see that these two were the <em>shortest</em> possible vectors from which to construct the square lattice. However, any lattice (apart from a 1-dimensional one) has an <em>infinite</em> number of possible bases. Take the triangular lattice we looked at earlier:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*pLX973mggeJ-lzBchEOh7A.png" /><figcaption>The shortest vectors in the triangular lattice (blue), and two longer vectors (purple). We can use either pair of vectors as the “basis” for constructing the lattice using the same method we described above. The purple vectors are a “bad” basis for building the lattice, while the blue ones (as the shortest vectors) are the most easy to work with.</figcaption></figure><p>If we multiply the longer basis vectors by whole numbers, they’ll also land on new points in the lattice. We can therefore use <em>any </em>pair of vectors to make a lattice as long as each vector terminates at a new lattice point.¹ Likewise for the 3-dimensional square lattice:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/827/1*h9geYEIsB7cLe0F8x3AHjQ.gif" /></figure><p>In principle, we can reconstruct the whole lattice from any basis we are given and find the shortest vectors. In practice, depending on the lattice and the basis vectors we choose, this problem can be very easy or it can be almost totally impossible.</p><p>If all the vectors in the basis are very long, finding the shortest vectors requires that we keep taking combinations of the very long vectors to try and reconstruct the lattice. That’s still fairly simple for a 2-dimensional lattice, but if we increase the <em>dimension </em>of the lattice, it becomes difficult.</p><p>The reason why this happens is because the number of possible combinations that we have to try increases <em>exponentially</em> with the number of dimensions. If we say that <em>a</em> is the typical length of the vector relative to the spacing of the lattice points and <em>d </em>is the dimension of the lattice, then the number of possible combinations we need to try is on the order of <em>(2a)</em>​<em>ᵈ</em> .</p><p>For the long bases shown in the 2-dimensional examples above, <em>a</em> is “about 4” and <em>d</em> =2, which from <em>(2a)</em>​<em>ᵈ</em> means that we have to try about 64 combinations before we can find the shortest vectors.</p><p>If we increase <em>a</em> to 100 and use a 50-dimensional lattice, <em>(2a)</em>​<em>ᵈ</em> &gt;10¹⁰⁰ different combinations. For reference, that’s more than the estimated number of atoms in the observable universe.</p><p>Of course, we have to be careful with what we’re saying here; there are clever techniques (such as the <a href="https://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.310.318">Lenstra-Lenstra-Lovasz algorithm</a>) that can be used to find short vectors on lattices without trying all the possible combinations. However, it’s still true that the complexity and size of the problem increases explosively with the number of dimensions, such that even the best known algorithms running on the fastest supercomputers cannot find the shortest vectors in high-dimensional lattices in an acceptable timeframe.</p><p>Just as large prime factorisation is very easy to undo if you know <em>which</em> large primes were multiplied together and (currently) nearly impossible otherwise, with only 50 vectors we can construct a problem with the same property; it’s easy to solve certain problems on the lattice if you know the shortest vectors and <em>unbelievably</em> difficult if you don’t.</p><p>And best of all, there’s no known quantum algorithm for solving this kind of lattice problem.</p><p>This is the thing that we were hoping for in the <a href="https://medium.com/optalysys/optical-computing-for-post-quantum-cryptography-why-we-need-pqc-f39d21ae4466">last article</a>; something that we can use as a cryptographic <em>trap-door </em>function that will allow us to encrypt something in such a way that we can decrypt it <em>only</em> if we know some other secret piece of information, and it’s also secure against quantum attacks!</p><p>This is great; there’s something here that we can use to make (amongst other things) a new post-quantum public-key cryptosystem, but now we need some practical way of using it. Fortunately, while the shortest vector problem is a great introduction to lattice security, it isn’t the only “hard” problem on which to base a scheme.</p><h3>More “Hard” Lattice Problems</h3><p>The two most important computational problems in lattice-based cryptography are the <em>shortest</em> vector problem and the <em>closest</em> vector problem. We covered the basic version of the shortest vector problem above, but we’ll give a few examples of some of the more important variations on the problem.</p><h4><strong>Approximate Shortest Vector Problems</strong></h4><p><strong>Search-Approximate</strong></p><p>In the <em>search</em> version of the approximate shortest-vector problem, we’re given a lattice and asked to find a vector whose length is <em>within </em>a factor<em> g </em>of the smallest possible value (i.e, whose length is at most <em>g </em>multiplied by the length of the shortest vector)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/704/1*k55rlNtZaXBE1HyprpUhIw.png" /><figcaption>An example of the search-Shortest Vector Problem. The grey area indicates all the possible vectors which are nearly the same length (to within a given factor) as the shortest vector, which is indicated in blue. The vector in green indicates one of these possible solutions, while the purple vectors indicate a “bad” basis that we are given.</figcaption></figure><p>If this factor is 1, the problem returns to being the original shortest vector problem.</p><p><strong>Decision-Approximate</strong></p><p>In the <em>decision</em> version of the approximate shortest-vector problem, we’re given a number <strong>d </strong>and asked to determine if the length of the shortest vector is smaller than <strong>d</strong>, larger than <strong>d, </strong>or “undetermined”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/962/1*UIUCURoanb2JsQ0keeG0JQ.png" /><figcaption>The decision-approximate shortest vector problem. d is a real number, shown here by a circle that represents all the possible vectors of length d. The blue vector is the shortest vector.</figcaption></figure><h4><strong>Closest Vector Problem</strong></h4><p>The closest-vector problem is the other significant category of computational problems on lattices. In this problem, we’re given a pair of “bad” (long) basis vectors, and then asked to find the lattice vector closest to another vector which <em>isn’t </em>part of the lattice.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bZVMwO4JPaVbC80J1lSEzQ.png" /><figcaption>Two “bad” basis vectors (purple) and a vector that isn’t part of the lattice (green). The closest lattice point to this vector is also highlighted in green.</figcaption></figure><p>This <em>looks</em> easy, because it’s easy to see where the closest lattice point is when they’re all drawn out. Indeed, it <em>is</em> easy if our lattice has a basis set which is orthogonal (at right-angles to one another, as in the case of our square lattice). However, many lattices don’t have an orthogonal basis, and if we take away the points…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EdlpxUqQVRyPKsqjuNJTMg.png" /></figure><p>…it gets tougher to see the correct solution, and a <em>lot</em> tougher if we increase the dimensions of the lattice.</p><p>The closest vector problem also has an approximate version, which can be used to build cryptosystems. It isn’t actually <em>provably</em> secure for all values of the approximation parameter, but it is a very close relative of a related (and demonstrably secure) problem called…</p><p><strong>The Bounded Distance Decoding Problem</strong></p><p>In the bounded-distance decoding problem (BDD), we’re now given a vector which isn’t in the lattice but does lie <em>within</em> a set distance from a point in the lattice, and we’re asked to find the closest lattice vector.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0e14jL5HvkcudjlW7vICSA.png" /><figcaption>The bounded distance decoding problem. As in the closest-vector problem, the aim is to find the lattice vector that lies closest to the green vector, where the green vector is known to lie within a given distance (in this case, half the length of the shortest vector in the lattice) from a lattice point.</figcaption></figure><p>This is very similar to the closest-vector problem, but as long as we pick an appropriate distance we are now guaranteed that there is a <em>unique</em> solution. When considering the cryptographic side of things, it’s helpful to put this problem in the context of communications theory<em>.</em></p><p>In communications theory, BDD can be used to retrieve information sent over a channel which contains white (random) noise with a Gaussian distribution. The information to be sent is stored in the form of a lattice vector, so the person receiving the message needs to be able to recover this original lattice vector from the noisy version that they receive.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/996/1*L96EbLghOP7djC42ypvZeA.png" /><figcaption>In communications theory, we can pick a lattice vector that represents part of a message, and send it over a “noisy” channel which alters the precise value of the vector. In the above, we can represent this noise as a Gaussian distribution around one of the lattice points; the green region indicates all the places where the vector <em>might be moved to by the noise.</em></figcaption></figure><p>Because we’re now guaranteed that there’s a solution, we can use BDD to recover the correct value as long as we pick a lattice with sensible parameters for a given amount of noise. From the above illustrations, it should be fairly clear that decoding to a “unique” point in the lattice is only possible when the radius of the noisy region is less than or equal to half the shortest vector. We can see this explicitly below, where we show bounding regions which have this maximum radius; if the regions were larger they would overlap, making it impossible to distinguish some vectors as belonging to a specific lattice point.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/233/1*8tAeRYlYjuSDBTeSW10j9w.png" /></figure><p>This might seem like a bit of a diversion, but in fact this combination of Gaussian noise and bounded-distance decoding is fundamental to a very important cryptographic construction known as the Learning with Errors (LWE) problem.</p><p>In our next article, we’ll be looking at an application of the learning with errors problem and another important extension of it, <em>ring</em>-learning with errors. This application, known as fully-homomorphic encryption or FHE, is a novel form of encryption that allows us to work on data even when it is encrypted. This means that even highly sensitive data can be sent to a cloud server for processing without ever risking that the data could be compromised.</p><p>We’ll be talking about how ring-learning with errors techniques can be performed using a Fourier-optical processing system, and then show how we applied our prototype system to performing encryption and decryption operations in an FHE scheme.</p><p>¹ There is an additional condition for the set of vectors to form a basis which is able to generate the whole lattice: the matrix relating it to the original basis must have a determinant equal to +1 or -1.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a391d48ea6bf" width="1" height="1" alt=""><hr><p><a href="https://medium.com/optalysys/optical-computing-for-cryptography-lattice-based-cryptography-a391d48ea6bf">Optical Computing for Cryptography: Lattice-based Cryptography</a> was originally published in <a href="https://medium.com/optalysys">Optalysys</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Optical Computing for Post-Quantum Cryptography: Why we need PQC]]></title>
            <link>https://medium.com/optalysys/optical-computing-for-post-quantum-cryptography-why-we-need-pqc-f39d21ae4466?source=rss-9326ad4c51d1------2</link>
            <guid isPermaLink="false">https://medium.com/p/f39d21ae4466</guid>
            <category><![CDATA[post-quantum-cryptography]]></category>
            <category><![CDATA[cryptography]]></category>
            <category><![CDATA[encryption]]></category>
            <category><![CDATA[optical-computing]]></category>
            <dc:creator><![CDATA[Joseph Wilson]]></dc:creator>
            <pubDate>Thu, 14 Jan 2021 13:43:41 GMT</pubDate>
            <atom:updated>2021-01-14T13:43:41.893Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A-vr21fZ_mffCWBnDgmDJQ.png" /></figure><h3>Optical Computing for Post-Quantum Cryptography: An Introduction</h3><p>These days, if you do any reading on the subject of information security, you don’t need to look very far to find a discussion of the problem of post-quantum security. It’s a well-known issue with the infrastructure of the modern internet; the cryptographic tools that keep information in transit secure from prying eyes and malicious activity are imminently at risk from an entirely new method of computing. The culprit, quantum computing, enables the use of new calculation techniques that can easily solve some of the fundamentally difficult mathematical problems on which these cryptographic tools are based.</p><p>There have been two major avenues of research into a solution to this problem. The first is to fight quantum mechanics with quantum mechanics, creating cryptographic schemes (such as <a href="https://journals.aps.org/prl/abstract/10.1103/PhysRevLett.67.661">E91</a>) that explicitly use quantum properties, typically entanglement, as a means of securing information. However, this approach requires dedicated quantum hardware.</p><p>The second approach is to find an alternative mathematical problems or features which are not known to be solvable even with a quantum computer. This is easier said than done; finding suitable mathematical problems for cryptography is not an easy task even without having to verify that they are also secure against quantum attacks, but there has been some exceptional progress in the field.</p><p>Amongst these alternatives is a very promising category of techniques collectively known as <em>lattice-based </em>cryptography. The fundamental mathematical problems that secure lattice based cryptography are extremely flexible; not only do they enable replacements for vulnerable cryptographic schemes, but they can be used to construct new and useful models of cryptography that allow us to do things that we couldn’t do before.</p><p>In future articles, we’ll be looking at how our <a href="https://medium.com/optalysys/optalysys-what-we-do-and-why-we-do-it-20ab416c5ad0">optical computing technology</a> can be used to accelerate key operations in cryptographic schemes based on these lattice methods. For now, in this article, we take a look at <em>why </em>we need alternatives. This isn’t an in-depth explanation of all cryptography, or how quantum computers work; rather, the aim is to provide an accessible understanding of the nature of the quantum threat to existing techniques. We’ll start with the (very) basics of how we can securely send messages, and go from there.</p><h3>Cryptography: The (Very) Basics</h3><p>Cryptography is the transformation of information for the purposes of security. This can take many different forms for many different applications, but for now we’re going to focus on methods which are used to obscure information from all but those authorised to see it.</p><p>Let’s take a classical example. We want to send a message to a friend, but we don’t want anybody else to be able to read it.</p><p>We can’t send this information in a readable form (known in cryptography as “plaintext”), so we want to transform the message into an encrypted <em>ciphertext</em>, a jumble of nonsense information created by taking the readable information and re-arranging it according to a set of rules.</p><p>How effective this process is varies. Let’s say that we want to encrypt a short plaintext message, such as</p><p>“Hello, how are you?”</p><p>We could try shifting all the letters by a certain number of steps in the alphabet; this basic form of encryption is called the <em>Caesar cipher</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OslgAzwtFLYrl4xU37grkw.png" /><figcaption>A basic Caesar cipher with a single right shift.</figcaption></figure><p>Shifting all the letters right by 1 position would give us a ciphertext of</p><p>“Ifmmp, ipx bsf zpv”</p><p>These are definitely not recognisable words, but it also isn’t the most complex cipher to break; once the simple rule that encrypts the message is figured out, it is trivial to reverse the operation and recover the message.</p><p>This rule, the number of steps that we shift the letters by, can be thought of as the <em>key</em> to both performing and reversing the encryption.</p><p>We refer to a key which both encrypts and decrypts information as a <em>symmetric </em>key. In the cipher above, it’s particularly easy to see why. Performing and reversing the encryption follows the same path, like so:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/40/1*RfhkIt4CtwACJ53_TX78JA.png" /></figure><p>The Caesar cipher is very simple and very easy to break, but there are much more secure symmetric key schemes. One of these, the Advanced Encryption Standard (AES), is frequently used to protect data which is in storage or “at rest”. For example, banks use AES to protect customer details stored on their servers so that even if these details are stolen, they’re unreadable.</p><p>The key that AES uses to encrypt information is much more complex than the one above. It’s a numerical value which typically has a length (known as the “security parameter”) of 128, 192 or 256 bits, which, at the top end, translates to 2²⁵⁶ or</p><p>115,792,089,237,316,195,423,570,985,008,687,907,853,269,984,665,640,564,039,457,584,007,913,129,639,936</p><p>different combinations. This value is used to swap, mix and substitute information in a block in a way which is designed to be easy to reverse if you know the key but impossible if you don’t.</p><p>There’s currently no clever method for finding the key outside of a “brute force” attack where every possible value is checked, a task which is functionally impossible to carry out in a useful time-frame even with access to the most powerful supercomputers. This is considerably more secure than the Caesar cipher, but we <em>still </em>can’t rely on AES (at least, not on it’s own) to securely send a message.</p><p>This is because if we want the recipient to be able to read the message when they receive it then we’d need to send the message <em>and the key! </em>Anybody intercepting that key could retrieve the message from the encrypted data. We can make this <em>practically</em> difficult for an attacker, but not in the same fundamental mathematical way that makes encryption secure.</p><p>Not only that, but you’d need to generate a new key if you wanted to communicate securely with someone else, otherwise a legitimate recipient of one key could read <em>all</em> of your messages to other people. If you were a big organisation (such as a bank), this would mean managing and protecting millions of individual keys.</p><p>We need a different method to keep our messages safe. We need an <em>asymmetric </em>key.</p><p>Asymmetric keys form the basis of public key cryptography. This is a process that allows anyone to encrypt<em> </em>a message using a “public” key, but only the holder of the “private” key is able to decrypt that message. The two keys do different things, hence the term “asymmetric”.</p><p>A great (not to mention common) analogy is that of a padlock. If the padlock is initially open, anyone can close the lock to secure a box containing a message, but only the person with the key can open the lock and retrieve the contents.</p><p>The thing that was missing from symmetric key cryptography was a secure method for <em>key distribution</em>. Public key cryptography gives us the solution.</p><p>If two people both create their own public-private key pair and then swap public keys, they can encrypt messages to send to each other (by using the other person’s public key) and decrypt messages sent to them by using their own private keys. If the public keys are intercepted, it doesn’t matter!</p><p>This is also very useful if you need to communicate with millions of people; you only need one public key for any number of people to be able to send you messages, and you only need to store their public keys if you want to send messages back. Even if those keys are stolen, they’re not useful. The only thing anybody needs to seriously protect is their single private key.</p><p>There are a number of existing schemes for public-key cryptography, but one of the most commonly-used is the Rivest-Shamir-Adleman (RSA) scheme, which has its roots in a very old problem in <em>number theory.</em></p><h4>Public Key Encryption and Number Theory</h4><p>Number theory is the branch of mathematics concerned with the properties of whole (integer) numbers. Despite having existed in some form for at least 3800 years, there are many mathematical problems in number theory which still don’t have an easy solution. We use the fact that people have been trying to crack these problems for thousands of years as a “proof” that these problems are very hard.</p><p>One of these problems is the <em>prime factoring</em> problem. The Greek mathematician Euclid proved that any number can be uniquely represented as a product of prime numbers, numbers which only divide by 1 and themselves.</p><p>If we multiply two very large (&gt;2048 bit) prime numbers <em>p</em> and <em>q</em> together, we get a larger number <em>N </em>for which<em> p </em>and<em> q </em>are the<em> unique </em>prime factors. This is an easy task for a computer, even if the numbers involved are big.</p><p>If we are given only <em>N </em>and<em> </em>one of the prime numbers <em>p</em>, it’s just as easy to find the other prime <em>q </em>by dividing <em>N</em> by <em>p. </em>This is also easy for computers.</p><p>However if we are only given <em>N</em>, finding <em>p</em> and <em>q</em> is hard and takes an impractically long time even for the most powerful supercomputers. Despite the fact that this problem has been known for a very long time, there still isn’t an <em>efficient</em> process for finding the prime factors of very large numbers!</p><p>The prime factoring problem is an example of a <em>trap-door</em> function. This is a mathematical operation where the result is very easy to calculate but nearly impossible to reverse <em>unless</em> you know at least one non-trivial piece of information.</p><p>Of course, having a mathematical operation with these properties is only half the battle. Even if the mathematical basis of an encryption scheme is secure, the actual computer code that executes the scheme may not be. It’s not helpful to encrypt data if someone can spy on the workings of your machine and determine the private key as it is generated, so a lot of effort goes into making the practical implementations of cryptography as secure as possible. Huge amounts of information are generated and transmitted by computers, so the computational process of carrying out the encryption and decryption needs to be fast and efficient<em> </em>too<em>.</em></p><p>RSA is based on the prime factoring problem. We won’t go <em>very</em> deep into the details of RSA here, but when it comes to understanding the threat posed by quantum computing, there are some important ideas that it’s helpful to understand.</p><h3>RSA</h3><blockquote>The era of “electronic mail” may soon be upon us; we must ensure that two important properties of the current “paper mail” system are preserved: (a) messages are private, and (b) messages can be signed.</blockquote><p>So opens the introduction of the <a href="https://people.csail.mit.edu/rivest/Rsapaper.pdf">original scientific paper</a> of Rivest, Shamir and Adleman, written in 1977, which defined the first <em>working </em>example of a public-key cryptosystem (the concept was originally invented by <a href="https://ee.stanford.edu/~hellman/publications/24.pdf">Diffie and Hellman</a>, who created one of the first key-exchange mechanisms). That RSA (with some minor adjustments) is still a dominant public-key cryptosystem today is testament to a winning combination of brilliant cryptographic design and computational efficiency. We’ll focus first on the mathematical core of RSA.</p><p>Fundamentally, RSA operates in what is known as <em>modular arithmetic</em>. If you can interpret a clock, you’re familiar with this idea. On a clock, the hours “wrap back” around to the start once you get past either 12 or 24, depending on how your clock displays time. In this case, we call either 12 or 24 the <em>modulus.</em></p><p>Because we can’t go past the modulus (there’s no 25 o’clock, for example), when we perform arithmetic operations where the result is larger than the modulus, the result also wraps around. This means that two different numbers can “match up” in a given modulus. We call this matching up <em>congruence</em>. For example, 8 and 23 are congruent in modulus 3. We can write this as <em>8 ≡ 23 mod(3) </em>where “<em>≡” </em>indicates congruence.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/257/1*E8NxUhGFEu1yz33KEI_NsQ.png" /><figcaption>A visual representation of the numbers 8 and 23 in mod(3). The red boxes show how many times 3 fits into each number, while the blue boxes indicate the remainder. In mod(3), 8 and 23 have the same remainder and are thus congruent.</figcaption></figure><p>In RSA, we pick two large primes and multiply them together to create a large number <em>N</em> that we use as a modulus. Information is encrypted by converting each character in a message into a number <em>m (</em>which is how computers internally represent characters anyway; they’re translated into human-readable text through standards such as ASCII), and then raising that number to the power of a number <em>e. </em>This produces a ciphertext <em>c ≡ mᵉ mod (N), </em>where<em> c </em>is the result of a large number <em>mᵉ</em> wrapping around the modulus <em>N </em>one or more times and stopping on a different value.</p><p>Something interesting happens in modular arithmetic when we raise a given number to an exponent. As the exponent increases, the remainder in the modulus starts to take on a repeating pattern. Because this pattern is repeating, we can say that it has a <em>period</em>, in much the same way that a sine wave does.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/187/1*iTMsNqcv8ioSn6XEUcwdpQ.png" /><figcaption>The value of increasing powers of 2 in mod(5) form a repeating pattern with a particular <em>period. If we change the modulus, this pattern and the associated period change too.</em></figcaption></figure><p>If our message integer <em>m</em> and modulus N are “co-prime” (don’t share any common factors beyond 1), then we can guarantee that as the exponent increases indefinitely, the result periodically returns to the original value.</p><p>Because exponentiation in modular arithmetic has this periodic behaviour, we can find another number <em>d</em> such that raising <em>m</em> to the power of <em>ed</em> produces a number that wraps around the modulus until it returns to the original value of the message<em> m. </em>We can see this in the image above, where<em> (2⁴)² mod(5)≡2⁸ mod(5).</em></p><p>Because<em> c ≡ mᵉ mod (N), </em>raising<em> c </em>to the power of<em> d </em>is the same as writing<em> (mᵉ)</em>ᵈ<em> mod (N) ≡ m mod(N). </em>Exploiting the properties of congruence and modular exponentiation is what allows us to both encrypt and <em>decrypt</em> the message!</p><p>In RSA, the public key is the values <em>e </em>and<em> N</em>, while the private key is <em>d</em>. The method for figuring out what <em>e</em> and <em>d </em>should be, how they are connected to <em>N, </em>and<em> </em>the other steps that must be performed to make the scheme truly <em>secure</em> are more complicated than we’ll get in this article, but you can find a comprehensive description <a href="https://www.comparitech.com/blog/information-security/rsa-encryption/">here</a>.</p><p>This part of RSA gives us a means of encrypting and decrypting messages, and that alone is very useful. However, this is only half of the full RSA system; the other half is the method used to validate the <em>origin</em> of encrypted information, allowing you to be sure that the person sending you a message is who they say they are. This is done through a <em>digital signature</em>.</p><h4>Digital signatures</h4><p>To talk about digital signatures, we’ll have to describe another cryptographic tool called a <em>hash function</em>. A hash function is a cryptographic process that takes a message of any length as an input, and outputs a value (known simply as a “hash”) of fixed length.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*in8b3NFjRaZur0j22ZLkbA.png" /><figcaption>An example of a hash function being used to turn a message into a hash. The message can be any data of any length; computer code (as above), a picture, a sound-file…</figcaption></figure><p>Hash functions are <em>deterministic</em>; given the same input, they should always produce the same output<em>. </em>At the same time, if even a single digital “bit” in the message changes, the hash function should output a completely different value, a property known as the “avalanche effect”. Hash functions are very quick to calculate, but it’s infeasible to directly reverse the process.</p><p>This is partly due to a mathematical argument called the Pigeonhole principle. Ideally we’d like a unique hash for each unique message, but because there are usually far more possible input messages than there are hash outputs of a fixed length, then it is guaranteed that it is possible to generate <em>collisions </em>between hash values, in which two messages produce the same hash output. In short, an attack on a hash function isn’t done by directly reversing the process, it has to come from another conceptual direction by finding messages that <em>could</em> produce that hash.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/860/1*Buf1EKjhYU3KGgiVCBf89Q.png" /><figcaption>A (very) simple illustration of the pigeonhole principle. It’s clear that, to assign each message (black square) to a pigeonhole (white square), some pigeonholes will have to contain more than one message. Likewise, for a hash function of fixed length, there are only so many hash outputs which can exist, and the number of possible messages is significantly greater than the number of hashes.</figcaption></figure><p>Collisions are unavoidable, but a good hash function should still be <em>resistant</em> to collisions, in the sense that collisions should be hard to find without using impractically slow and inefficient trial-and-error.</p><p>Why does this matter? If we’re using hash functions to verify the <em>content </em>of a message, then by finding collisions, an attacker could intercept our original message and replace it with a <em>different </em>message that still outputs the same hash.</p><p>While hash functions have many uses in verifying information (including as proof-of-work in the Bitcoin protocol), one of the most important is in creating digital signatures. This<em> </em>allows the author of a piece of information, be it a message or something more complex (such as a piece of software), to verify that they were the origin and integrity of that information. Here’s a basic example of how this works with RSA:</p><ul><li>The sender writes their message and then creates a hash of the message using a specific hash function, such as SHA-256</li><li>The sender then encrypts the hash using their RSA private key, creating a <em>digital signature. </em>They add this signature to the message.</li><li>This encryption can (via the public-private key relationship <em>(mᵉ)</em>ᵈ<em> mod (N) ≡ m mod(N)) </em>be reversed using the sender’s public key without revealing the private key in the process.</li><li>The sender then creates a single-use key and uses it to encrypt their message using a symmetric key scheme such as DES/Triple-DES or AES</li><li>The sender encrypts this single use key using RSA and the recipient’s public key</li><li>They send the RSA-encrypted symmetric key and the DES/AES encrypted message to the recipient.</li><li>The recipient decrypts the symmetric key using their RSA private key, and then decrypts the message and the encrypted hash function using the symmetric key</li><li>The recipient then further decrypts the digital signature using the sender’s public key to retrieve the original hash of the message</li><li>The recipient then applies the same hash function to the decrypted message and compares the output against the hash retrieved from the digital signature</li><li>If the hashes match, the recipient can be confident of two things: a) the person who sent the message holds the private key corresponding to the public key used to decrypt the signature, and b) that the message hasn’t been tampered with.</li></ul><p>In short, the above process is a way for the sender of a message to verify both their identity and message through a specific piece of secret information (their private key) <em>without </em>having to directly reveal that information. The same principle also forms the basis of the public-key certificate scheme used to validate the identity of websites on the internet, allowing for secure, trustworthy web browsing.</p><p>Why bother with the extra step of using hash functions or symmetric-key encryption when we could also “double-encrypt” the message, once with the sender’s private key and then again with the recipient’s public key? This would ultimately have the same authentication properties as the above method and is the signature scheme proposed in the original RSA paper.</p><p>While RSA works phenomenally well for public key encryption, it does have some limitations. While computers can easily perform the calculations needed for RSA, it’s still much more “expensive” than symmetric-key encryption. There’s also a maximum length to the message that we can encrypt in one go using RSA, which is not a problem for a symmetric key system that can work on as many “blocks” of information as we like. RSA is therefore used solely as a “key-encapsulation” scheme to securely exchange a single-use <em>session</em> key, which is then used with a more efficient symmetric-key “data-encapsulation” scheme to securely send the message.</p><p>As you can probably tell by this point, securely sending messages over the internet is <em>not easy</em>, and everything we’ve described so far took many years of development and testing to get right.</p><p>Which is why the quantum computing threat is, above all else, rather inconvenient.</p><h3>The Quantum Threat</h3><p>Large primes are difficult to factorise using a <em>classical </em>computer, and that’s what makes schemes based on their properties so secure. The term “classical” means a computer that uses binary logic to perform calculations using bits, individual pieces of information which can be either 1 or 0. This is the type of computer that you’re using right now in 2021. If this article is still around in 2040, there’s a chance that you might have (or at least have widely-available access to) a machine which is at least in part a <em>quantum</em> computer.</p><p>While modern digital electronics make use of material properties which are ultimately due to quantum effects (such as semiconductivity), the outcome of an operation using an electronic component is a behaviour from classical physics; the flow of an electrical current.</p><p>In a quantum computer, the outcome of an operation using a quantum bit or “qubit” is a quantum <em>state</em>, a probability distribution that describes the likely outcome of the measurement of one of the physical properties (e.g the spin) of the system.</p><p>This is conceptually quite similar to the operating principles of our optical computing system, in which we encode information into the phase and amplitude properties of light and then allow a physical process to perform the calculation for us. In the case of our optical processor, we leverage the natural Fourier transformation properties of light.</p><p>In quantum computing there are several unique properties (such as entanglement) that can be used to perform calculations. The most commonly given example of this is that a qubit can be in a state of quantum superposition with other qubits and be both 0 and 1 <em>at the same time </em>until we take a measurement<em>.</em></p><p>Like optical computing, quantum computing has some serious advantages over classical computing when it comes to certain calculations, and a range of quantum algorithms have been proposed that allow us to do things that we couldn’t previously.</p><p>Unfortunately for cryptography, one of those quantum algorithms is Shor’s algorithm.</p><h4>P vs NP</h4><p>Not every calculation can be run efficiently on a computer. Those that can are said to run in “polynomial” or “P” time. This means that, for <em>n </em>pieces of information, the time taken to both find a solution to the problem and <em>verify</em> that the solution is correct are related to a polynomial of <em>n, </em>such as <em>n².</em></p><p>If only the verification can be performed in polynomial time, the problem is said to be <em>non-deterministic polynomial</em> or “NP”. For example, the time taken to perform a brute-force search for an AES key has an exponential 2ⁿ time dependency where <em>n </em>is the key length. This exponential growth in search time for a linear increase in key length is what makes AES both practical and secure. If you <em>do </em>find the key (or have it already), you can still verify that you have been successful by undoing the encryption in polynomial time.</p><p>The large-prime factoring problem is an NP problem, in that it takes much longer to find a solution than it does to verify it and is therefore said to be computationally “hard”. Shor’s algorithm breaks this hardness by converting the factoring problem into a different form in which the answer can be found (in part) by finding the period of an operation carried out in modular arithmetic, the same period that we described above in the RSA cryptosystem!</p><p>The conversion part can be done using a classical computer while the unique superposition properties of a quantum computer are needed in order to perform the <em>quantum</em> Fourier transform that finds the period.</p><p>Using this method, Shor’s algorithm is expected to find prime factors in polynomial time. This is a catastrophe for prime-based security; a cryptographic system that can be broken in polynomial time is totally insecure.</p><p>And Shor’s algorithm isn’t the only quantum algorithm that poses a threat to cryptography. Grover’s search algorithm provides a means of speeding up a brute-force search such that it only takes root-<em>n</em> operations to search <em>n</em> possibilities. This poses a threat to hash functions by reducing the amount of searching that it takes to find a collision.</p><p>This even poses a threat to AES, albeit a limited one; Grover’s search algorithm can reduce the effective strength of a 256-bit AES key to 128 bits, although at a mere 340,282,366,920,938,463,463,374,607,431,768,211,456 different combinations, that’s still comfortably outside of the reach of the world’s supercomputers.</p><p>There is some good news. Because the kind of quantum computers that can perform Shor’s algorithm work directly with quantum states, they are <em>very</em> sensitive to noise (such as tiny thermal fluctuations) and it is hard to build a working system with a large number of qubits. A quantum computer with enough qubits to perform Shor’s algorithm on a large number doesn’t exist yet. Thus far, the largest number to which Shor’s algorithm has <a href="https://arxiv.org/abs/1111.4147">successfully been applied</a> is 21.</p><p>However, these problems are being overcome quickly, and the complexity of quantum computers appears to be growing at a doubly-exponential rate, an observation known as <a href="https://www.quantamagazine.org/does-nevens-law-describe-quantum-computings-rise-20190618/#:~:text=Neven&#39;s%20law%20states%20that%20quantum,supremacy%20is%20around%20the%20corner.">Neven’s law</a>. For reference, the phenomenal growth in classical computing power over time reflected in Moore’s law is only singly exponential. Quantum computers are not only getting better, they’re doing so with almost unreal speed.</p><p>And quantum computing is no longer the preserve of highly-specialised research groups. As these systems improve, the infrastructure and learning resources needed to work with them is also improving. Software interfaces and examples for working with quantum computers are now becoming openly accessible. If you want to see the code and mathematical explanation for how Shor’s algorithm can be run on a quantum computer, you don’t need to dive deep into the scientific literature; you can quite easily <a href="https://qiskit.org/textbook/ch-algorithms/shor.html">find it</a> on Google.</p><p>This is great news for quantum computing but bad news for cryptography. The era of quantum supremacy, the tipping point at which quantum computers can find answers to problems which are not possible on any classical computer, will soon be upon us.</p><p>In the face of these issues, we need alternative mathematical problems which not only have the same easy-to-perform, hard-to-reverse properties as large prime multiplication but which are also difficult even for quantum computers.</p><p>And we need them fast.</p><p>Fortunately, help is at hand. The global cryptographic community has risen to the challenge, investigating a wide range of novel quantum-secure techniques and testing them exhaustively for weaknesses. At the time of writing, a range of schemes covering the cryptographic tools needed for message encryption and authentication are undergoing a third and final round of selection by the <a href="https://csrc.nist.gov/projects/post-quantum-cryptography">US National Institute of Standards and Technology</a> (NIST).</p><p>Many of these schemes, such as NTRUEncrypt (for public-key cryptography) and NTRUSign (for digital signatures) are derived from lattice-based<em> </em>cryptography. Over the course of our articles on cryptography, we’re building towards an explanation as to how we can accelerate these schemes (and more besides) using our Fourier-optical computing system. In our next article, we’ll be looking at some of the mathematical problems that make lattice-based cryptography secure.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f39d21ae4466" width="1" height="1" alt=""><hr><p><a href="https://medium.com/optalysys/optical-computing-for-post-quantum-cryptography-why-we-need-pqc-f39d21ae4466">Optical Computing for Post-Quantum Cryptography: Why we need PQC</a> was originally published in <a href="https://medium.com/optalysys">Optalysys</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>