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
136 stars 49 forks source link

Documentation plan #18

Closed gurpreet- closed 6 years ago

gurpreet- commented 6 years ago

Many parts of the docs still need completing, such as the collaborator's guide and how to add native functions. I think the best plan of action is to centralise the documentation into one place.

Plan of action:

gurpreet- commented 6 years ago

New documentation available at:

Only need to transfer documentation now.

schott12521 commented 6 years ago

Do you have any more examples of handling the .so files for android? I compiled libsodium with my changes for all of the ABIs, now I put them in my project's src/main/jniLibs and I should be able to use that in my path correct?

Currently, I am adding the files by saying:

sourceSets {
    main {
        jniLibs.srcDirs 'src/main/jniLibs/'
    }
}

and I have my files laid out like:

Project/app/src/main/jniLibs/arm-X Project/app/src/main/jniLibs/x86 etc for each ABI

But when I try to call val sodium = SodiumAndroid("/src/main/jniLibs/")

But I'm getting an UnsatisfiedLinkError that it could not find the library. Any help would be awesome!

Cool, I almost got it to work. For this curious, I simply changed the name of my libsodium.so files to libsodiumMine.so for every ABI, and then for the path I just provided "sodiumMine". Turns out I compiled libsodium off the wrong branch, so I have to fix that but then we should be making progress!

gurpreet- commented 6 years ago

Hello @schott12521.

If you have the compiled libsodium.so files in their relevant ABI folders in the jniLibs folder then I think those libsodium.so files will be added automatically to your path. So I think the solution to your problem is simply to omit the path altogether:

val sodium = SodiumAndroid()
val lazySodium = LazySodium(sodium, StandardCharsets.UTF_8)

Let me know if that works out for you.

I will add this to the docs too.

gurpreet- commented 6 years ago

Or if that doesn't work then you could initialise it with your libsodium.so file renamed to libmysodium.so:

// Make sure libmysodium.so is in jniLibs
val sodium = SodiumAndroid("mysodium")
val lazySodium = LazySodium(sodium, StandardCharsets.UTF_8)
gurpreet- commented 6 years ago

Another way could be to include the libsodium.so in your resources folder and then when the app starts copy it from your resources to a temporary location in the storage. Then load it via Native.register(Sodium.class, "path/to/libsodium.so").

Long-winded 😱

schott12521 commented 6 years ago

Correct, I think I got it to work just by assigning a new name to it. Not exactly sure what I am doing wrong now, the fork of libsodium that I use basically just changed the crypto_sign functions to use blake2b internally for hashing, but im not getting the expected hash when I use the LazySign method.

gurpreet- commented 6 years ago

Are you performing a crypto_sign then a crypto_generichash_blake2b or are you doing the hashing first and then the signing?

If you're getting a hash back, then it's a good sign that you're on the right tracks. It may be that you're not providing the correct lengths to crypto_sign or crypto_generichash_blake2b?

Could you show me some code? Any C and Java code that you've modified and added would be helpful.

Also I've created a new issue for you, let's continue the conversation there #19.