nasa / CryptoLib

Provide a software-only solution using the CCSDS Space Data Link Security Protocol - Extended Procedures (SDLS-EP) to secure communications between a spacecraft running the core Flight System (cFS) and a ground station.
Other
66 stars 25 forks source link

CFFI_EXCLUDE for KMC Compilation #220

Closed dccutrig closed 5 months ago

dccutrig commented 5 months ago

Email from Hayk, capturing here to test results:

When doing a KMC build with PR https://github.com/nasa/CryptoLib/pull/210 we ran into some problems with the CFFI code on the KMC side. Specifically with this line: https://github.jpl.nasa.gov/ASEC/AMMOS-CryptoLib/blob/master/kmc_sdls/kmc_sdls_python/_cffi_src/tasks.py#L29

If you don’t have access to the KMC repo it’s the output produced by the following GCC pre-processing line that CFFI can’t parse. gcc -E -Ikmc_sdls/public_inc -I/usr/local/include -I../../../CryptoLib/include ../../public_inc/kmc_sdls.h

The root cause turned out to be with these 2 lines in crypto_structs.h

include

include

https://github.com/nasa/CryptoLib/pull/210/files#diff-ff3b1a31169cc448e7dce70a6b076fdffe88b286df835bfdfeec10405dafde45R28 https://github.com/nasa/CryptoLib/pull/210/files#diff-ff3b1a31169cc448e7dce70a6b076fdffe88b286df835bfdfeec10405dafde45R29

When standard C libraries are included in the gcc -E (preprocessing) step, it includes the standard library contents in the pre processed output which the Python CFFI parsing code can’t handle.

One possible solution to this is to update the following block of code in https://github.com/nasa/CryptoLib/blob/dev/include/crypto_structs.h#L24 : FROM:

ifdef NOS3 // NOS3/cFS build is ready

include "common_types.h"

else // Assume build outside of NOS3/cFS infrastructure

include

include

include

endif


TO:

ifdef NOS3 // NOS3/cFS build is ready

include "common_types.h"

else // Assume build outside of NOS3/cFS infrastructure

#include <stdint.h>
#ifndef CFFI_EXCLUDE // Exclude libraries that CFFI parser can’t process
    #include <stdio.h>
    #include <stdlib.h>
#endif

endif


With the above update we can then run the GCC command with -D CFFI_EXCLUDE to exclude the standard libraries gcc -E -D CFFI_EXCLUDE -Ikmc_sdls/public_inc -I/usr/local/include -I../../../CryptoLib/include ../../public_inc/kmc_sdls.h

jlucas9 commented 5 months ago

Merged to dev