Skip to content

It would be nice if libnettle.a could be built out-of-the-box #51

@niels-moller

Description

@niels-moller

This is what I'm trying to do, and it almost works:

$ mkdir nettle-tkey
$ cd nettle-tkey
$ ~/hack/nettle/configure --host=riscv32-unknown-none CC='clang-15 --target=riscv32-unknown-none-elf -march=rv32iczmmul -mabi=ilp32 -mcmodel=medany -nostdlib -fno-common -fno-builtin-printf -fno-builtin-putchar -mno-relax -O2 -Wall' --disable-shared --enable-mini-gmp --with-include-path=/home/nisse/hack/tkey/tkey-libs/include:/home/nisse/hack/tkey/include-hack
$ make libnettle.a

Not sure what's the intention, but I want to put tkey-libs/include on my include path, so that tkey-specific headers would be used as #include <tkey/foo.h> in application code.

I got this to work, with only a few header files added in the above include-hack directory. Details:

  • assert.h: Just include tkey/assert.h. I think this file should be moved one level up, from include/tkey/.

  • stdio.h: Dummy definition of FILE, stderr and fprintf:

typedef struct {} FILE;
#define stderr NULL
static inline int fprintf(FILE *f, const char *format, ...) { (void) f; (void) format; return -1; }

Not sure what would actually make sense for tkey-libs, but a fprintf function always returning -1 might be reasonable?

  • stdlib.h: Include tkey/lib.h (for stddef.h and stdint.h, provided by clang). Dummy definitions of realloc (always return NULL), free (do nothing) and abort.

The abort function is an interesting case. Ideally, it should terminate application, with some way for firmware to tell the host that the app aborted. If that's not doable, maybe abort() should be an infinite loop, so it at least doesn't return.

  • string.h: Include tkey/lib.h, for memset/memcpy. Define strcmp and memcmp.

In my hack string.h, I did strcmp and memcmp as static inline functions. I think it would make sense to add proper definitions of strcmp and memcmp to tkey-libs.

And that's all, with just those tweaks, it compiles successfully. Compiling the public-key things in nettle (the code which goes into libhogweed.a) will be more challenging, even with --enable-minigmp, since the bignum operations unfortunately depend on working malloc/realloc/free.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions