crypto icon indicating copy to clipboard operation
crypto copied to clipboard

Error in example crypto/examples/signing-ec

Open aymanosman opened this issue 3 years ago • 2 comments

I get an error running the example crypto/examples/signing-ec under OSX.

BC

generate-private-key: could not get implementation
  algorithm: 'ec
  context...:
   /Users/ayman/Library/Racket/8.1-bc/pkgs/crypto-lib/main.rkt:708:0: generate-private-key
   "/Users/ayman/Library/Racket/8.1-bc/pkgs/crypto-doc/examples/signing-ec.rkt": [running body]

CS

racket(27006,0x10acd3e00) malloc: *** error for object 0x10a5a5548: pointer being realloc'd was not allocated
racket(27006,0x10acd3e00) malloc: *** set a breakpoint in malloc_error_break to debug
[1]    27006 abort      racket -l crypto/examples/signing-ec

libnettle is installed on my system, although I don't know whether it is 3.6 (as brew reports) or 8 as the filename would suggest.

Racket BC doesn't find the library, while Racket CS seems to find it fine.

$ /Applications/Racket\ v8.1/bin/racket
Welcome to Racket v8.1 [bc].
> (require crypto/private/nettle/ffi)
> libnettle
#f
> nettle-load-error
"ffi-lib: couldn't open \"libnettle.8.dylib\" (dlopen(libnettle.8.dylib, 6): image not found)"

$ racket
Welcome to Racket v8.1.0.6 [cs].
> (require crypto/private/nettle/ffi)
> libnettle
#<ffi-lib>

I've tried hardcoding the library path for BC to see if I can change its behaviour, but it still gives me the same error, so I may be barking up the wrong tree.

aymanosman avatar May 29 '21 21:05 aymanosman

Is it possible that you have configured the Racket library search paths differently for the two versions of Racket? Could you try running (begin (require setup/dirs) (get-lib-search-dirs)) on both and see if CS reports extra directories (like /usr/local/lib, for example)? Another possibility is that you've copied the nettle library to your CS lib directory. Try running the example with the environment variable PLTSTDERR=debug@ffi-lib and see what each version says about libnettle.

Regarding the malloc error on CS: I'll look into it.

rmculpepper avatar Jun 15 '21 13:06 rmculpepper

The malloc error seems to happen because the (system/homebrew) libnettle and libhogweed are linked to the system/homebrew version of libgmp, but the Racket gmp package (used by the crypto library) is linked to Racket's copy of libgmp.

Replacing Racket's libgmp with a symlink to the system/homebrew libgmp seems to work, but that's probably not a good solution.

rmculpepper avatar Jun 24 '21 23:06 rmculpepper