terl / lazysodium-java

A Java implementation of the Libsodium crypto library. For the lazy dev.
https://github.com/terl/lazysodium-java/wiki
Mozilla Public License 2.0
135 stars 48 forks source link

Modifying crypto_sign to use blake2b internally #19

Closed gurpreet- closed 6 years ago

schott12521 commented 6 years ago

I was able to get this to work. I used a fork'd version of libsodium to compile my .so files, then I imported them into my android project. Then I was able to use Lazy Sodium to call my blake2b versions of the signing algorithms. However, I found that I had to use the native functions offered by the Sodium class instead of the LazySodium classes, but then I was able to retrieve the desired result. Thanks for all of the help thus far, you've been awesome! Great library :D

gurpreet- commented 6 years ago

This is great news and some good information for future people to follow in your footsteps.

To anyone reading this, this section of the docs will hopefully have been completed so you can add/modify native functions with ease.

schott12521 commented 6 years ago

I should probably include some code since my project is still private, but this is how I got it to work:

fun getSignatureHelper(privateKey: ByteArray, message: ByteArray): String {

    // This is my custom *.so libsodium library that you can find here:
    // https://github.com/nebyark/libsodium/tree/stable
    // And the changed functions can be found here:
    // https://github.com/nebyark/libsodium/commit/57fe2dcc1320c0f888801e2ebd76bb2a84fa6b00
    val sodium = SodiumAndroid("sodiumMine")

    var signature = ByteArray(64)
    sodium.crypto_sign(signature, null, message, message.size.toLong(), privateKey)

    return byteArrayToHex(signature).toUpperCase()

}

I wasn't able to get either detached or lazy working, but this does give me the intended result so its good enough for now. Thanks @gurpreet- :D!