Code Monkey home page Code Monkey logo

Comments (16)

joshmg avatar joshmg commented on July 30, 2024 4

@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

from secp256k1.

sipa avatar sipa commented on July 30, 2024 1

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.

from secp256k1.

sipa avatar sipa commented on July 30, 2024 1

@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 with secp256k1_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).

from secp256k1.

DavidEGrayson avatar DavidEGrayson commented on July 30, 2024

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):

https://github.com/DavidEGrayson/secp256k1-rb

from secp256k1.

gmaxwell avatar gmaxwell commented on July 30, 2024

Keep 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.)

from secp256k1.

ShaliDaliHaliDa avatar ShaliDaliHaliDa commented on July 30, 2024

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?

 "___gmpn_gcdext", referenced from:

  _secp256k1_num_mod_inverse in libsecp256k1.a(libsecp256k1_la-secp256k1.o)

  "___gmpn_get_str", referenced from:

  _secp256k1_num_get_bin in libsecp256k1.a(libsecp256k1_la-secp256k1.o)

 "___gmpn_set_str", referenced from:

  _secp256k1_ecdsa_recover_compact in libsecp256k1.a(libsecp256k1_la-secp256k1.o)

  _secp256k1_scalar_inverse_var in libsecp256k1.a(libsecp256k1_la-secp256k1.o)

  _secp256k1_ge_set_all_gej_var in libsecp256k1.a(libsecp256k1_la-secp256k1.o)

  "___gmpn_sub_n", referenced from:

  _secp256k1_num_mod_inverse in libsecp256k1.a(libsecp256k1_la-secp256k1.o)

ld: symbol(s) not found for architecture x86_64

from secp256k1.

mrx23dot avatar mrx23dot commented on July 30, 2024

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.

from secp256k1.

elichai avatar elichai commented on July 30, 2024

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 via make and link to the resulting libsecp256k1.a

from secp256k1.

mrx23dot avatar mrx23dot commented on July 30, 2024

I mean compile secp256k1.c into my exe. I tried it but it gives seg fault on context creation.

from secp256k1.

elichai avatar elichai commented on July 30, 2024

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

from secp256k1.

mrx23dot avatar mrx23dot commented on July 30, 2024

Ok, so it wasn't designed to be used without linking in as a static library (.a) aka not as a black-box.

from secp256k1.

elichai avatar elichai commented on July 30, 2024

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 #929

from secp256k1.

mrx23dot avatar mrx23dot commented on July 30, 2024

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.

from secp256k1.

mrx23dot avatar mrx23dot commented on July 30, 2024

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.

from secp256k1.

sipa avatar sipa commented on July 30, 2024

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.

from secp256k1.

mrx23dot avatar mrx23dot commented on July 30, 2024

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?

from secp256k1.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.