lvh / caesium

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

Unable to verify signatures created with a seed #22

Open talios opened 7 years ago

talios commented 7 years ago

Calling caesium.crypto.sign/keypair! with a byte[] seed seems to trigger verification failures with verify(sign ...)...).

I modified one of the test cases in sign-test.clj as seen in https://gist.github.com/talios/d0ea678b0ce5b044ec48c6074855cf6a which triggers the problem.

Is this not the correct way to generate a keypair with a common seed, which will survive VM restarts?

lvh commented 7 years ago

Thanks for your report! I'm looking into this.

lvh commented 7 years ago

The obvious problem is that the seed has to be seedbytes (is, to wit, 32), but that shouldn't matter for that example.

lvh commented 7 years ago

Looks like it's a length problem:

caesium.crypto.sign> (let [{pk :public sk :secret} (generate-signing-keys (.getBytes "secret"))]
      (verify (sign (.getBytes "hi") sk) (.getBytes "hi") pk)
    )
java.lang.RuntimeException: Signature validation failed
caesium.crypto.sign> (let [{pk :public sk :secret} (generate-signing-keys (.getBytes "YELLOW SUBMARINEYELLOW SUBMARINE"))]
      (verify (sign (.getBytes "hi") sk) (.getBytes "hi") pk))

not sure why it doesn't just read 32 bytes past the pointer, though... (Although it still wouldn't be repeatable)

talios commented 7 years ago

@lvh should that error out/throw an exception is < seedBytes? That'll let me move on my own issues tho.