lvh / caesium

Modern cryptography (libsodium/NaCl) for Clojure
Eclipse Public License 1.0
180 stars 28 forks source link

Bindings for Ed25519 to Curve25519 #40

Closed davidwalker closed 6 years ago

davidwalker commented 6 years ago

I was going to add bindings for the ed25519 to curve25519 key conversion functions (https://download.libsodium.org/doc/advanced/ed25519-curve25519.html). Is that something you'd be happy to take a pull request for?

If so maybe you can help me with an error I'm getting:

clojure.lang.Compiler$CompilerException: java.lang.IllegalArgumentException: More than one matching method found: crypto_sign_ed25519_pk_to_curve25519, compiling:(.../caesium/src/caesium/crypto/sign/ed25519.clj:16:5)

in binding.clj I've added:

    [^int crypto_sign_ed25519_pk_to_curve25519
     [^bytes ^{Pinned {}} curve25519_pk
      ^bytes ^{Pinned {}} ed25519_pk]]

then to call it

    (b/call! crypto_sign_ed25519_pk_to_curve25519
             (bb/->indirect-byte-buf curve_pk)
             (bb/->indirect-byte-buf pk))

Any idea what I'm doing wrong?

davidwalker commented 6 years ago

I think I've figured out my problem, the name of the arguments used for the call! macro must match the name of the parameter in the binding.

lvh commented 6 years ago

Yep, that is correct -- that's how it maps the arguments to the C arguments (it could do it positionally, but that seems brittle), which it needs to do in order to add the appropriate type annotations.

Thanks for working on this!