This demo shows how to use Microsoft SEAL for .NET to perform homomorphic operations in Azure Functions.
Azure Functions is a solution for easily running small pieces of code, or "functions", in the cloud. You can write just the code you need for the problem at hand, without worrying about a whole application or the infrastructure to run it. Functions can make development even more productive, and you can use your programming language of choice, such as C#, F#, Node.js, Java, or PHP. You pay only for the time your code runs and trust Azure to scale as needed. Azure Functions lets you develop serverless applications on Microsoft Azure. Learn more by following this link.
The demonstration implements basic matrix operations: addition, subtraction, and multiplication.
One of the projects (CloudBasedFunctions/CloudBasedFunctions.sln
) implements these operations in Azure Functions,
receiving as input a pair of ciphertexts. The other project (ClientBasedFunctions/ClientBasedFunctions.sln
)
provides a user interface that allows entering matrices, encrypting them, sending them to the cloud functions,
receiving the result, decrypting the result, and finally showing it to the user. The user interface has an option
to show the actual data that is being sent and received from the cloud functions.
Matrix addition and subtraction is implemented by converting the matrices to vectors (using BatchEncoder
class in Microsoft SEAL),
and then performing element-wise operations in the resulting ciphertexts. Matrix multiplication is slightly
more complicated and is explained in detail in this file.
- Download 64-bit Azure Functions Command Line Interface.
- Install to known directory, for example:
D:\Progs\Azure.Functions.Cli.win-x64.2.3.199
. - Open CloudBasedFunctions solution.
- Right click on CloudBasedFunctions project and select
Properties
. - Go to
Debug
tab in project properties. - In
Executable
, browse forfunc.exe
on the 64-bit Azure Functions Command Line download, for example:D:\Progs\Azure.Functions.Cli.win-x64.2.3.199\func.exe
. - In
Application arguments
, add:host start
. - In
Working directory
, type$(TargetDir)
. - Now you should be able to debug the CloudBasedFunctions project locally.
- Open CloudBasedFunctions solution.
- Right click on CloudBasedFunctions project and select
Publish...
. - You will be asked to select a publish target, select Azure Function App.
- After clicking
Publish
you might have to enter your Azure credentials. - Once the functions are published, go to the Azure Portal.
- Select
Function Apps
. - Select your newly published Function App.
- Select
Platform features
tab. - Under
General Settings
, selectApplication Settings
. - Change the
Platform
to 64 bit, save your changes. - After this change, Functions should be enabled and running.
- Open CloudBasedFunctions solution.
- Start CloudBasedFnctions project, functions should run locally. A command
window will appear and after some initialization the available Azure Functions
will be printed, as well as the http address where they are available, for
example:
http://localhost:7071/api/Addition
. - Open ClientBasedFunctions solution.
- Start ClientBasedFunctions project.
- The app window will appear. At the top there is a text box to specify the base
address of the Azure Functions. To connect to the Azure Functions in step 2 above,
for example, the textbox should contain:
http://localhost:7071
.
- Please follow the instructions in the CloudBasedFunctions solution to deploy the functions to Azure..
- Go to Azure Portal.
- Select "Function Apps".
- Select your Function App.
- In the right part of the screen you will see the URL you need to use to access
the Azure Functions, for example:
https://sealazurefuncdemoXXXX.azurewebsites.net
. - In the left part of the screen you will see a tree structure. The root node is
your Function App, its first child node is
Functions
, and below this your will find theAddition
,Subtraction
andMultiplication
functions. - For each function we need to obtain the function key needed to be able to call
the API. When you select a function in the tree, the right part of the screen
will show the contents of the
function.json
file that configures the function. At the top you will see a link called</> Get function URL
. - Clicking
</> Get function URL
will show a dialog showing the complete URL needed to access the function. Make suredefault (Function key)
is selected in the combo box, and copy only the value of the function key. This is the text after?code=
. - Open ClientBasedFunctions solution.
- In the ClientBasedFunctions project, open the file
GlobalProperties.cs
. - Update the constants under
GlobalProperties.Codes
with the function keys from your Function App. - Run the ClientBasedFunctions project, and in the top textbox enter the URL from
step 4, for example:
https://sealazurefuncdemoXXXX.azurewebsites.net
. - This will enable the client to connect to the Azure Functions running in Azure.