-
ShaliDaliHaliDa commented at 7:21 pm on February 25, 2015: noneSorry if this is a silly question but after compilation how do I use it? I found the static lib in /usr/local/lib/libsecp256k1.a and I am able to reference it, are there any examples on how to use it from Xcode?
-
DavidEGrayson commented at 8:23 pm on February 25, 2015: none
Did you already find the documentation in the header file? If you are familiar with C and with some of the binary formats used for ECDSA, it should probably be enough:
https://github.com/bitcoin/secp256k1/blob/master/include/secp256k1.h
You might also want to look at my usage examples here, though they are written in Ruby and they use a future version of the library’s API (the one from pull request #208):
-
gmaxwell commented at 8:53 pm on February 25, 2015: contributorKeep in mind that this is currently an unreleased experimental library with a changing interfac. When it reaches a full release there will be better documentation. (DavidEGrayson’s comments about the headers are the right advice now currently.)
-
ShaliDaliHaliDa commented at 8:14 pm on February 26, 2015: none
Thanks for the info.Unfortunately getting a bunch of errors in Xcode when I try and use any of the mehtods. I have added reference to libsecp256k1.a , the include paths, and GMP is installed via brew yet looks like it can’t find GMP ? ___gmpn_gcdext?
Is there a better compiler / IDE I should be using instead of Xcode? QT? Or Eclipse perhaps?
0 "___gmpn_gcdext", referenced from: 1 2 _secp256k1_num_mod_inverse in libsecp256k1.a(libsecp256k1_la-secp256k1.o) 3 4 "___gmpn_get_str", referenced from: 5 6 _secp256k1_num_get_bin in libsecp256k1.a(libsecp256k1_la-secp256k1.o) 7 8 "___gmpn_set_str", referenced from: 9 10 _secp256k1_ecdsa_recover_compact in libsecp256k1.a(libsecp256k1_la-secp256k1.o) 11 12 _secp256k1_scalar_inverse_var in libsecp256k1.a(libsecp256k1_la-secp256k1.o) 13 14 _secp256k1_ge_set_all_gej_var in libsecp256k1.a(libsecp256k1_la-secp256k1.o) 15 16 "___gmpn_sub_n", referenced from: 17 18 _secp256k1_num_mod_inverse in libsecp256k1.a(libsecp256k1_la-secp256k1.o)
ld: symbol(s) not found for architecture x86_64
-
gmaxwell closed this on Aug 27, 2015
-
joshmg commented at 10:21 pm on January 22, 2018: none
@ShaliDaliHaliDa : You needed to add the GNU Multiple Precision Arithmetic Library to your build command. (via -lgmp)
Ex:
g++ -lgmp ../secp256k1/.libs/libsecp256k1.a main.cpp -o main
-
mrx23dot commented at 11:42 am on April 3, 2022: noneAnd how do I compile in the library as part of my project? (not as shared library) The library has many main() functions. Is there a simplified version? It seems to be huge.
-
elichai commented at 12:01 pm on April 3, 2022: contributor
And how do I compile in the library as part of my project? (not as shared library) The library has many main() functions. Is there a simplified version? It seems to be huge.
Depending on the build system of your project, but the best way would probably be to invoke the
autogen.sh
then run./configure
with whatever flags you need (schnorr/ecdh etc.) and then run the makefile viamake
and link to the resultinglibsecp256k1.a
-
mrx23dot commented at 12:06 pm on April 3, 2022: noneI mean compile secp256k1.c into my exe. I tried it but it gives seg fault on context creation.
-
elichai commented at 12:10 pm on April 3, 2022: contributor
I mean compile secp256k1.c into my exe. I tried it but it gives seg fault on context creation.
That’s exactly what I’ve talked about, you should compile
libsecp256k1
as a library and then link to it. Sounds like it is windows which I know nothing about, but maybe whatever bitcoin core is doing can help you: https://github.com/bitcoin/bitcoin/blob/master/build_msvc/libsecp256k1/libsecp256k1.vcxproj -
mrx23dot commented at 12:26 pm on April 3, 2022: noneOk, so it wasn’t designed to be used without linking in as a static library (.a) aka not as a black-box.
-
elichai commented at 1:21 pm on April 3, 2022: contributor
Ok, so it wasn’t designed to be used without linking in as a static library (.a) aka not as a black-box.
I don’t know what a “black box” means in the context of a library. But this is not a “header only library” and as such it needs to be compiled and linked (shared/static), We are trying to make this library compile more easily with a one line compiler call, but it’s still ongoing, See https://github.com/bitcoin-core/secp256k1/issues/929
-
mrx23dot commented at 3:41 pm on April 3, 2022: none
Ok so how can I use it as a “header only” library? Linking it in two steps doesn’t change a thing. gcc mymain.c secp256k1.c
Does it require some init code before I can call context init? Because it gave me segfault. As I saw the lib itself has main function.
-
sipa commented at 4:11 pm on April 3, 2022: contributor
This is not a headers only library, you can’t use it as such.
You’ll need to build the library, and link it into your application (either statically or dynamically). How to do that depends on the platform. I’m afraid I can’t help you with usage on Windows platforms.
-
mrx23dot commented at 9:32 pm on April 4, 2022: none
Could you explain how is it possible that all of these files have main() entry points and compile into .a object? precompute_ecmult.c precompute_ecmult_gen.c bench.c
I would assume linker would complain for anything anything more than one main, which would come from post linking with user app. I’m on linux.
-
sipa commented at 9:33 pm on April 4, 2022: contributor
Those are separate executables that are part of the project, but are not part of the library.
The library itself is compiled from secp256k1.c, plus a few other files with assembly and precomputed tables.
-
mrx23dot commented at 9:45 pm on April 5, 2022: none
I manage to build it as intended, copied over generated files, it compiles, give correct result. Weirdly secp256k1_ec_pubkey_create returns the public key (generated from private key) x_mirrored + y_mirrored byte array, which won’t work for the next sha256+RIPE160 step.
How do you develop/debug this lib with dbg? Is there an entry point for it? Or a script that prepares it for running by it’s own?
-
sipa commented at 9:47 pm on April 5, 2022: contributor@mrx23dot You need to call
secp256k1_ec_pubkey_serialize
to convert it to a stable format, as explained in the API documentation in secp256k1.h. You cannot do anything withsecp256k1_pubkey
objects other than passing them back to other libsecp256k1 functions, as there is no guarantee about its internal format (neither across platforms, or across versions of the library).
This is a metadata mirror of the GitHub repository bitcoin-core/secp256k1. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-11-22 01:15 UTC
More mirrored repositories can be found on mirror.b10c.me