6

I am writing an application that will be run on bare metal, i.e. it will not run on a kernel and therefore cannot invoke system calls. There will also be no C runtime. Is there a crypto library I can use in such setting (or do libraries like crypto++, libsodium, etc. depend on C runtime)?

  • Bare metal = no new and no malloc? I'm pretty sure the cryptography libraries require those functions. – SEJPM Aug 18 '15 at 9:15
  • 1
    LibSodium doesn't need any dynamic memory allocations, but it uses a few standard library calls, like memmove. But those should be pretty easy to write by yourself. The biggest issue is how you want to generate secure random numbers. @SEJPM Since field arithmetic is often hardcoded for ECC, they don't need malloc. Symmetric crypto generally doesn't need it either. – CodesInChaos Aug 18 '15 at 19:26
  • @CodesInChaos, well I can't make a statement for libsodium, but Crypto++ requires CRT, as (un)aligned allocation functions are neccessary. CodeRef – SEJPM Aug 18 '15 at 19:51
3

I'm going to assume that you only need the most standard capabilities and nothing fancy, so at most things like standard authenticated encryption primitives and thelike. No secret sharing, no format preserving encryption and no password based key derivation or other fancy password hashing schemes.

So if you do indeed only need the basic schemes there are potentially three libraries that would fit your needs:

  • Cryptlib. Cryptlib is a per-node paid library that has a wide range of hardware support and from what I understand should be able to run on embedded devices as well. So if you want something with commercial support then this is your best option (and you probably should ask them before using whether it fits your specific needs). Also note that opposed to other libraries, Cryptlib has support for common high-level constructs like CMS and PGP.
  • BearSSL. BearSSL is the other really interesting choice. It has been designed and programmed for low-memory embedded devices and requires only a very minimal set of functions from the compiler, which is just memcpy, memmove and strlen and a few definitions. It does not make any syscalls at any point. However the downside is that you probably won't get commercial support and it's still technically in alpha, so the API may change on any version, but it's worth keeping in mind in the long-term. On the upside it supports all the cryptography a standard TLS library needs and it's all fast and constant-time which may be just enough for you.
  • mbedTLS. In theory mbedTLS should be the middle-ground between BearSSL and Cryptlib here, however I haven't properly assessed it so I can't say anything more than "it's out there and might be worth further evaluation".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy