libtropic
C library for TROPIC01 chip
|
This section is for those who want to do something with the library itself.
Library architecture explained: core, examples, helpers, layers, hal, …
“Libtropic is standalone library expected to be used within a parent project”
To add a new embedded platform, follow these steps:
include/libtropic_port.h
For more inspiration check out our Integration examples.
As the libtropic was designed with extensibility in mind, it is possible to add a new backend for cryptographic operations.
The new backend has to support operations with:
To add a new backend (let's say mycrypto), you need to:
hal/crypto
called mycrypto
.lt_crypto_mycrypto_aesgcm.c
lt_crypto_mycrypto_ed25519.c
lt_crypto_mycrypto_sha256.c
lt_crypto_mycrypto_x25519.c
src/
:lt_aesgcm.h
: AES-GCM functions,lt_ed25519.h
: ED25519 functions,lt_sha256.h
: SHA256 functions,lt_x25519.h
: Curve25519 functions.lt_x25519.h
to lt_crypto_mycrypto_x25519.c
and provide implementations. You can use existing ports for inspiration.-DLT_CRYPTO_MYCRYPTO
to the CMake.In the Setup section, add new option:
At the bottom of the Setup section, there are checks for definition of cryptographic backend. Add your new backend to the checks:
In the Collect files section, add the new implementation files to compilation. Use this template, modify it accordingly, and paste it above the add new crypto sources above this line
comment:
At last, in the Compile and link section, compile and link dependencies to your new crypto backend:
For compiling in debug mode replace cmake ..
with cmake -DCMAKE_BUILD_TYPE=Debug ..
(this will allow to step through with a debugger).
Note: When compiling the library standalone as a static archive, a cryptography provider must be defined through cmake -D arguments
Compile libtropic
as a static archive under Unix:
Cross-compile libtropic
as a static archive:
Unit tests files are in tests/unit/
folder. They are written in Ceedling framework, install it like this:
Then make sure that you have correct version:
For now we support Ceedling version 0.31.1 only.
Once ceedling is installed, run tests and create code coverage report:
Some tests use a rudimentary randomization mechanism using standard C functions. The PRNG is normally seeded with current time. Used seed is always printed to stdout. You can find the seed in logs (build/gcov/results/...
).
To run tests with fixed seed, set RNG_SEED
parameter to your desired seed (either directly in the file, or in the project.yml section :defines:
). This is useful mainly to replicate a failed test run – just find out what seed was used and then set RNG_SEED
to this.
To run static analysis, follow these steps:
To build html documentation, you need Doxygen. The documentation is built using these commands:
The documentation will be built to: build/docs/doxygen/html
. Open index.html
in any recent web browser.
Notes:
Following instructions are applicable on linux based machines:
Choose version for your OS here, download it and extract it. Then add its path into your .bashrc
file:
Reload .bashrc
file:
Installed version might be checked like this:
For usage within VSCode, install clang-format
extension for VSCode and restart IDE. You can then run formatter by right clicking on the code and choosing Format document->Clang Format
.
To format particular folder use following prompt: