EuCrypt: Compilation Sheet

March 8th, 2018 by Diana Coman

~ This is part of the EuCrypt series. Start with Introducing EuCrypt. ~

First of all, you’ll need V, the republican versioning system, there is no way around this and I won’t provide any way around it either. Grab yourself a copy of V and learn to use it or implement your own copy, as you prefer. If you need some help with that, go first through the gentle introduction to V by Ben Vulpes and if you are still stuck after that come and ask intelligent questions in #trilema on irc.

Once you have V in working order, head to my Reference Code Shelf and download the .vpatches for EuCrypt and their signatures. Alternatively, you should be able to get the same from btcbase’s mirror of EuCrypt, possibly 1 with some other signatures as well if that helps. Press to the .vpatch you want, but make sure you do include the fixes at least for the components you are interested in. Just saying. Then you’re ready for building the lib itself.

EuCrypt can be built in 2 main ways:

  • as a single, aggregate library, including therefore all the components: mpi, smg_keccak, smg_bit_keccak, smg_rsa, smg_serpent; you’ll get one static library with everything, ready to be used; current size of the resulting file is 215K when built with AdaCore’s GNAT 2016 and gcc 4.9.4.
  • component by component, picking and choosing only what you need; current sizes when built with AdaCore’s GNAT 2016 and gcc 4.9.4: mpi 109K; smg_bit_keccak 17K; smg_keccak 42K; smg_rsa 19K; smg_serpent 20K – 31K (depending on level of optimisation chosen). NOTE: smg_rsa uses smg_keccak and mpi!

EuCrypt is written in Ada (Serpent and Keccak components) and C (mpi and rsa components). Therefore you’ll need a tool chain that supports multi-language libraries. My personal recommendation is to use AdaCore’s GNAT – it is currently the only tool I know to actually work out of the box for everything that EuCrypt needs 2 and it includes directly the rather powerful GPRBuild tool 3 for automatic builds of multi-language projects of all sorts. Given this lack of alternatives that I could recommend, I’ll mirror here the precise version of AdaCore’s GNAT that I am currently using and that I recommend you use too for building EuCrypt:

To compile, simply go to the eucrypt folder and run gprbuild. This will build EuCrypt as an aggregate library. To build any separate component, go to its own folder and run gprbuild there.

EuCrypt has been built successfully so far on the following systems:

  • CentOS 6.8, AdaCore’s GNAT GPL 2016 (gcc 4.9.4)
  • Ubuntu 14.04, AdaCore’s GNAT GPL 2016 (gcc 4.9.4)

I’ll gladly add to the above list any other systems/configurations that I become aware of – just tell me in the comments below what you compiled it on or even better – write it up on your blog and drop me a link in the comments below (a trackback is good too – just make sure it works!).

Note that the building of EuCrypt as a multi-language, C and Ada project should be quite pain-free with gprbuild. However, there is quite a lot of pain at writing code time when you need to interface between the two languages and especially when you need to pass strings and/or pointers. You can see such interfacing in action in Chapter 12 of EuCrypt (the wrapper for using Keccak OAEP + RSA directly from C code) but I fully recommend in any case that you read as well the very clear account of sending array of octets between C and Ada, by ave1. At the moment EuCrypt uses a more basic method to accomplish the same task, namely copying octet by octet an array of characters from Ada to C or from C to Ada, as required. Feel free to change that (as anything else), of course and let me know how it goes – there is no better way of understanding some code than trying to make a meaningful change to it!

  1. hopefully, at some point not that distant into the future[]
  2. You CAN supposedly use any other version of GNAT, most notably whatever comes with your gcc and/or specific OS distribution but it seems to lag behind for one thing and to be rather prone to trouble due for instance (among other troubles) to various version mismatch between all the different moving parts; so if you DO use a different GNAT and get it to work correctly, please document your work, write it up on your blog and drop me a link – I’ll be happy to read it and add it as known working alternative![]
  3. This is NEEDED if you want to build eucrypt as a standalone aggregate library! While you CAN build the components separately with gnatmake for instance, you won’t be able to build aggregate library with it as gnatmake simply doesn’t support this at the moment as far as I’m aware.[]