potatosalad / erlang-keccakf1600

Keccak-f[1600] NIF with timeslice reductions for Erlang and Elixir.
MIT License
16 stars 30 forks source link

module :keccakf1600 is not available (FreeBSD) #2

Open roynalnaruto opened 5 years ago

roynalnaruto commented 5 years ago

Hello

I am using the exth_crypto dependency, which uses the libsecp256k1 and keccakf1600 libraries.

{:libsecp256k1, "~> 0.1.9"}
{:keccakf1600, "~> 2.0.0", hex: :keccakf1600_orig}

logs when run mix deps.compile:

===> Compiling keccakf1600
gmake: Entering directory '/usr/home/appuser/assets_explorer/deps/keccakf1600/c_src'
 C      decaf-utils.c
 C      keccakf1600_nif.c
 C      shake.c
/usr/home/appuser/assets_explorer/deps/keccakf1600/c_src/shake.c:64:12: warning: 'le64toh' macro redefined [-Wmacro-redefined]
#   define le64toh(x) letoh64(x)
           ^
/usr/include/sys/endian.h:80:9: note: previous definition is here
#define le64toh(x)      ((uint64_t)(x))
        ^
/usr/home/appuser/assets_explorer/deps/keccakf1600/c_src/shake.c:139:30: warning: implicit declaration of function 'letoh64' is invalid in C99 [-Wimplicit-function-declaration]
        for (i=0; i<25; i++) a[i] = le64toh(a[i]);
                                    ^
/usr/home/appuser/assets_explorer/deps/keccakf1600/c_src/shake.c:64:23: note: expanded from macro 'le64toh'
#   define le64toh(x) letoh64(x)
                      ^
2 warnings generated.
 LD     keccakf1600.so
gmake: Leaving directory '/usr/home/appuser/assets_explorer/deps/keccakf1600/c_src'

But when I start the application:

[warn] The on_load function for module keccakf1600 returned:
{:error, {:load_failed, 'Failed to load NIF library: \'/usr/home/appuser/my_project/_build/dev/lib/keccakf1600/priv/keccakf1600.so: Undefined symbol "letoh64"\''}}

[info] Application my_project_core exited: AssetsExplorerCore.Application.start(:normal, []) returned an error: shutdown: failed to start child: MyProjectCore.SomeModule
    ** (EXIT) an exception was raised:
        ** (UndefinedFunctionError) function :keccakf1600.sha3_256/1 is undefined (module :keccakf1600 is not available)

Details

Any help in getting this to work?

potatosalad commented 5 years ago

This was fixed a while ago in erlang-libdecaf, but I must have forgotten to back-port things to this project.

FreeBSD has (or had in the past) some odd incompatibilities with le64toh and letoh64 in the past which required some adjusting of the defined types/macros to make it compatible with other systems.

In short: these lines in shake.c probably need to be updated to match portable_endian.h.

potatosalad commented 5 years ago

@roynalnaruto This should hopefully be fixed in version 3.0.0. Could you give that version a try to see if it works for you?

roynalnaruto commented 5 years ago

@potatosalad Yes, it works with version 3.0.0. Thanks a lot!