A few months ago I thought I was going to need to use RELIC (RELIC is an Efficient LIbrary for Cryptography) to be able to help port (get running on) a secure wire protocol to the Raspberry Pi and while I liked RELIC quite a lot in the end it turned out that I don’t actually need to use RELIC as other simpler libs will do for the base CryptSet & openssl & libsodium should work for the more advanced (read: more complicated & secure) CryptSets and are already used in other ports. However, as I don’t want the hours I spent reading the docs & fiddling with the source & build process to go to waste I thought i’d knock up a quick blog post of some of my notes.
RELIC relies on CMake so the 1st thing you’ll need to do if you haven’t already installed it on your Raspberry Pi is to install that.
sudo apt-get install cmake
Once you’ve installed Cmake you’ll want to download the stable version of RELIC. The current stable is nearly a year old but with things like crypto it’s better to stick to the stable version rather than any development versions unless you really know quite a bit about cryptography, know a lot about the programming language the library is written in and are willing to write a lot of bug reports and make lots of patches. The current stable/maint release of RELIC is 0.3.5 so that’s the version I would suggest using.
RELIC comes with a lot of defines and options some of with are incompatible with each other so you really should read the docs however the docs don’t exist until you’ve successfully built RELIC so you are in a bit of a catch 22 especially if you don’t at least look at the wiki or notice that they’ve helpfully made a tarball of the docs especially if you are building on the Raspberry Pi, or on ARM in general as the default build process builds for 64bit x86 unless you pass the options
to CMake. So I don’t forget, and because those were the options I needed to start with I wrote a couple of one-liners (ok 2 liners due to the hashbang line). One is just a generic one that I can use for messing around with and tweaking.
#!/bin/bash cmake -DARCH=ARM -DWORD=32 -DOPSYS=LINUX -DARITH=easy -DDOCUM=on "$@"
and one that is setup for my actual needs and will at least give me a workable lib to base changes on when and if i need them
#!/bin/bashcmake -DARCH=ARM -DWORD=32 -DOPSYS=LINUX -DSEED=LIBC -DSHLIB=OFF -DSTBIN=ON -DTIMER=NONE -DWITH="DV;BN;FP;EP;EC;CP;MD" -DBENCH=0 -DTESTS=0 -DCHECK=off -DVERBS=off -DSTRIP=on -DQUIET=on -DARITH=easy -DFP_PRIME=256 -DBN_METHD="COMBA;COMBA;MONTY;SLIDE;BASIC;BASIC" -DFP_METHD="INTEG;INTEG;INTEG;QUICK;BASIC;BASIC" -DEP_METHD="PROJC;BASIC;LWNAF;INTER" -DBN_PRECI=1024 -DBN_MAGNI=DOUBLE -DEP_PRECO=on -DEP_MIXED=off -DEP_KBLTZ=off -DEP_ORDIN=on -DEP_SUPER=off -DEC_METHD="PRIME" ./CMakeLists.txt
The above when combined with reading the docs & wiki should give you a good starting point for using RELIC in your projects and as RELIC is usable on several platforms including x86, Arduino/AVR & MSP430 as well as ARM you should be able to use it in a lot of projects where cryptography would be useful.
Addendum: Just for laughs before writing this blog post I decided to have a go at building the current dev version of RELIC using my existing one-liners. I managed to build a working library but I had to change two lines in src/arch/relic_arch_arm.c
lines 55 & 83 need to be changed from
#ifdef __ARM_ARCH_6J__ || __ARM_ARCH_6ZK__
to #if defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6Z__) || defined(__ARM_ARCH_6ZK__) || defined(__ARM_ARCH_6T2__)