-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
libsecp256k1_jni shared lib (continued) #248
Conversation
Also silence an unnecessary warning.
jni headers will be used if possible, otherwise jni support is disabled
- Don't error if not found - Don't use AC_CHECK_FILE which is disabled on cross - Check for darwin path
…xplain when it should be used.
Chatting with @apoelstra a bit on IRC, it seems that the JNI is a pretty low level interface, and to help keep that layer free of bugs, we were discussing possibly using rust-libsecp256k1 as the native interface, instead of JNI. I didn't want to pull in a whole bunch of new dependencies, but its starting to feel like this PR is getting rather large. I'm not exactly sure what makes sense to do, since calling Rust from Java entails using JNA (which itself has a really good mapping from native types to Java types) which would be yet another dependency to grab. (However, we might also be okay with just using JNA, and relying on their mappings) I suppose I'm looking for a bit of direction here, since I'd like to avoid pointer/low-level errors, while also providing a high-quality interface for Java users, and so I'm very open to doing things in the most sensible way with minimal upkeep. |
[wip] Added support for
will be shooting for reviewable later this week as i have still to implement tweak_* , context copy and synch locking. |
I've added support for the rest of the library including synchronized access for context_destroy and randomize(), and I think I'm comfortable seeing what others think about this now that it's further along than it was the other week. There should be some more updates periodically while new PRs are merged in (#250) and rebases happen, but nothing major now. |
I'm all for using JNA. That would simplify things for bitcoinj users quite a bit, I think. JNA is pretty similar to what the Java team want to integrate directly into the platform, so it's clearly the way to go. And it's available on Android so there should be no issue there if the ARM port is committed. |
I have a rebase scheduled to keep up with API changes soon. I still am not sure if this would be better maintained downstream in a private repo, but for now its here. A JNA refactor might very well be something that I might do after the API changes are merged in, I think JNA's automatic type conversions are what I'm looking to include, I trust my untested JNI code less than what JNA probably does out-of-the-box and with tests. |
@faizkhan00 The synchronization you're doing is not enough. You can't allow a call to randomize to happen at the same time as one to verify. The recommended model is a read/write lock: destroy and randomize then acquire a write lock, all the rest acquires a read lock. An alternative is only calling randomize once at creation, and only making the context object available afterwards. |
@sipa Understood. Thanks for looking this over; I'll be working on a patch over the next few days as I do have a few other updates to catch up on from the newer API changes, hopefully including r/w lock support to that list. |
the Since that would prevent all multithreading whatsoever, you want another mechanism. Go have a look at that readwrite lock. |
@faizkhan00 Still interested in working on this? |
Yes, I'm running a bit behind on this, with most of the breaking API changes updated in a local tree. I've just got the locking mechnism to finish up, and with that conceptually understood, I just need to make those changes, which really should not take long. EDIT: Locking mechanism, and possibly more testing and updating the pending API-BREAK PRs, too. |
…her classes and utils, add comments
@faizkhan00 I'm useless at figuring out how to rebase this, but I may be able to help complete this post-rebase. I'm hoping the api changes have slowed down enough to get this finished. |
@instagibbs Yeah, my thoughts as well, I was waiting for release/api changes to slow a bit but i can take a look soon about getting it up-to-date. There are still a few rough edges in this, I left a few comments as |
It looks like it's steadying a bit. I usually wait for dependent tests to crash and burn - until then, there's nothing to worry about - and it's been some time since the last break! |
…ods for loading native sig/pubkey objects. Add TODO notes and stubs for rest of API addtiions
@instagibbs I've updated the API to match the latest code (haven't rebased, maybe when we're closer to merging) and added a few new TODO's and stubs (mainly for schnorr support) that I plan to look at soon (maybe today even) if you're interested in taking a look there @afk11 Yup, although I wonder if there will be an api break for handling secret keys, which seem to be the only data not encapsulated by the api quite yet |
@faizkhan00 Indeed, perhaps msg32's as well! I'm curious about the safest way of handling these and keys, I've been rejecting input where len != 32. Might be worth opening an issue.. |
superceded by #364, which I tested and can confirm is passing (with schnorr/ecdh tests as well) |
This is a continuation of #64 where @theuni proposed expansions to the JNI shared lib, several improvements have been added to the PR. With @theuni 's efforts, we've expanded the original featureset to include:
*Makefile support for the JNI library
*Tests + harness
*sign/verify/create support
*Travis buildbot support
A note: I'm still working on expanding this, with several function implementations listed
TODO
and support for thread synchronization needed as well. I'm opening this here to keep the discussion moving from #64 and to be able to close that stale thread.From the latter part of #64, I was addressing concerns on ignoring the retValue which I believe are now fixed by passing a jObjectArray (a 2d byte array) into the Java side, extracting the hex value and performing a final assert (never exposing this to the user) @ 3ce6181
edit: I haven't squashed this yet since its a WIP, technically, but I could do that once things settle a bit more and we get closer to a merge.