0

I am having trouble figuring out how to use libsodium on an embedded Petalinux device (specifically an Arty-Z7-10).

I followed the instructions under "Build a Recipe from meta-example with PetaLinux Tools" in this webpage to add "libsodium" to the relevant build files. When I built the project, I saw compile messages containing "libsodium" (seemingly using the recipe at /opt/pkg/petalinux/components/yocto/source/arm/layers/meta-oe/recipes-support/libsodium/libsodium_1.0.11.bb). I verified that the embedded device contained a libsodium library, but it does not contain the library headers.

However, I am not sure how to include and use the library in Petalinux. Directly writing #include <sodium.h> resulted in compilation errors due to the compiler not being able to find the headers. The build process seemed to ignore any libsodium project I created with petalinux-create -t apps -n libsodium, making it impossible to bundle my own version instead of using the system recipe. How do I include and use the library on Petalinux?

If you want to set this up on a local environment the basis of the code comes from https://github.com/mitre-cyber-academy/2019-ectf-insecure-example, and I am trying to #include <sodium.h> in the Arty-Z7-10/components/ext_sources/u-boot-ectf/common/mesh.c file.

Tom Rini
  • 2,058
  • 8
  • 11
rlee827
  • 1,853
  • 2
  • 13
  • 32
  • Library headers are required only at build time, not at run time. I would not expect them to be installed on the device. – John Bollinger Feb 03 '19 at 03:25
  • I am new to Petalinux, so my root concern is that `petalinux-build` is unable to find the sodium headers when compiling the project. The headers probably don't need to be on the embedded device but I thought I would check anyway. – rlee827 Feb 03 '19 at 03:28
  • Regularly speaking, you can't just use random libraries in your bootloader as it's not at all a standard C environment. So even once you fix the missing dependencies on the OpenEmbedded side of Petalinux so that U-Boot DEPENDS on libsodium you're going to run into real problems. – Tom Rini Feb 03 '19 at 12:43
  • The recipe which the build process was using to build libsodium came installed with Petalinux. Does the existence of this built-in recipe provide any guarantees about the ability to use it in an embedded application? – rlee827 Feb 03 '19 at 15:03
  • The bootloader, in this case U-Boot, is similar to the kernel in that you cannot just try and make use of arbitrary libraries with them. They are a wholly different run-time environment and do not pretend to have a full standard C library available to them. If you want to port libsodium in then you have to explicitly do that as it won't work out of the box. My advice for the eCTF competition would be to look at the existing U-Boot mechanisms for cryptographic lockdown, they are there and documented. – Tom Rini Feb 04 '19 at 18:25

0 Answers0