Can I use group or field actions with the library? #1085

issue lightbulb128 opened this issue on March 11, 2022
  1. lightbulb128 commented at 7:47 AM on March 11, 2022: none

    I would like to use the field and group implementations of the secp256k1 library, so that I could experiment on the features of the elliptic curve, but I do not know how to include the correct header files. Is there a simple way? For example I want to achieve that I should be able to compile a single file

    #include "./src/group.h"
    int main() {
      secp256k1_ge someVariable;
      return 0;
    }
    

    Thanks in advance!

  2. lightbulb128 commented at 8:38 AM on March 11, 2022: none

    Well I seem to have figured out a way to do it

    #include "./src/libsecp256k1-config.h"
    #include "./src/secp256k1.c"
    #include "./include/secp256k1.h"
    #include "./src/assumptions.h"
    #include "./src/util.h"
    #include "./src/scalar_impl.h"
    #include "./src/field_impl.h"
    #include "./src/group_impl.h"
    #include "./src/ecmult_impl.h"
    #include "./src/ecmult_const_impl.h"
    #include "./src/ecmult_gen_impl.h"
    #include "./src/ecdsa_impl.h"
    #include "./src/eckey_impl.h"
    #include "./src/hash_impl.h"
    #include "./src/scratch_impl.h"
    #include "./src/precomputed_ecmult.c"
    #include "./src/precomputed_ecmult_gen.c"
    #include "random.h"
    #include <stdio.h>
    
    int main() {
      // create context
      secp256k1_context* ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY);
      // create secret key
      unsigned char seckey[32];
      while (1) {
        fill_random(seckey, sizeof(seckey));
        if (secp256k1_ec_seckey_verify(ctx, seckey)) break;
      }
      // create public key
      secp256k1_pubkey pubkey;
      secp256k1_ec_pubkey_create(ctx, &pubkey, seckey);
      
      unsigned char msg[32];
      for (int i=0; i<32; i++) msg[i] = 0;
      msg[31] = 0x12;
      unsigned char nonce[32];
      secp256k1_scalar nonce_scalar;
      secp256k1_scalar_set_b32_seckey(&nonce_scalar, nonce);
      secp256k1_nonce_function_default(nonce, msg, seckey, NULL, NULL, 0);
      print_hex(nonce, sizeof(nonce));
      secp256k1_gej rp;
      secp256k1_ecmult_gen(&ctx->ecmult_gen_ctx, &rp, &nonce_scalar);
      printf("Returning 0\n");
      return 0;
    }
    

    and compile it with

    gcc test.c -lsecp256k1 -o a.out
    

    The including at the beginning is a bit tiresome, though. Thanks anyway!

  3. jonasnick commented at 9:26 PM on March 11, 2022: contributor

    Hi @1286482110. This library is not a general purpose crypto library and therefore does not expose field or group operations. If you only want to experiment, you've apparently figured out how to get it to work. Alternatively, you can play with tests.c and run the binary with make && ./tests. If you want to implement your own cryptographic scheme, the best way is to fork the library and add a custom module.

  4. jonasnick closed this on Mar 11, 2022


github-metadata-mirror

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: 2026-04-27 04:15 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me