JamesTheAwesomeDude / pypqc

Attempt to expose Wiggers and Stebila's PQClean via Python CFFI
Other
0 stars 1 forks source link

Don't statically link the "common" deps? #1

Open JamesTheAwesomeDude opened 6 months ago

JamesTheAwesomeDude commented 6 months ago

As it stands, the "hard-coded" def_extern() calls at import-time are messy and awkward.

It looks like maybe "out-of-line ABI mode" could be used for a cleaner, more modularized solution.

Something like this might work:

# at build-time
...
ffibuilder.set_source('pqc._lib.foo1', ...)
ffibuilder.cdef("""\
void shake256(
    uint8_t *output,
    size_t outlen,
    const uint8_t *input,
    size_t inlen
);
""")
...
# at import-time
from .._lib import foo1

lib_f = ctypes.util.find_library("pqc_fips202")
lib = foo1.ffi.dlopen(lib_f)  # ??? WILL THIS WORK?? https://stackoverflow.com/a/30824152/1874170
...
JamesTheAwesomeDude commented 6 months ago

As of version 0.0.0.9, we've ditched the cdef_extern and switched over just to compiling the sources inline.

JamesTheAwesomeDude commented 5 months ago

I looked into SWIG as an alternative (it would allow actually dynamically linking the common deps, and would also allow us to avoid the extra unnecessary copy when converting a mutable FFI allocation into a bytes for return by constructing the object in-place, which would be AWESOME), but *golly* their tooling is just awful; I couldn't figure it out