A code generated C/C++ single file header for bitcoin-core/secp256k1's cryptography library
Go to file
2022-01-24 00:41:51 +11:00
secp256k1@c8aa516b57 Initial commit 2022-01-23 16:51:29 +11:00
_clang-format Initial commit 2022-01-23 16:51:29 +11:00
.gitignore Initial commit 2022-01-23 16:51:29 +11:00
.gitmodules Initial commit 2022-01-23 16:51:29 +11:00
bt_secp256k1_example.c Code generate secp256k1 modules into header files 2022-01-24 00:41:51 +11:00
bt_secp256k1_i64.h Code generate secp256k1 modules into header files 2022-01-24 00:41:51 +11:00
bt_secp256k1_i128_x86_64_asm.h Code generate secp256k1 modules into header files 2022-01-24 00:41:51 +11:00
bt_secp256k1_i128.h Code generate secp256k1 modules into header files 2022-01-24 00:41:51 +11:00
bt_secp256k1_metaprogram.cpp Code generate secp256k1 modules into header files 2022-01-24 00:41:51 +11:00
build_examples.bat Code generate secp256k1 modules into header files 2022-01-24 00:41:51 +11:00
build.bat Code generate secp256k1 modules into header files 2022-01-24 00:41:51 +11:00
LICENSE.txt Initial commit 2022-01-23 16:51:29 +11:00
README.md Code generate secp256k1 modules into header files 2022-01-24 00:41:51 +11:00

Blockchain Tools - secp256k1 (bt_secp256k1)

A code-generated single file header for bitcoin-core/secp256k1, an optimized C library for ECDSA signatures and secret/public key operations on curve secp256k1.

Using bt_secp256k1

The header files are generated from a metaprogram that is included in this repository. To use the library you only need 1 header file of which, 3 variants are provided,

  • bt_secp256k1_i64.h (USE_FORCE_WIDEMUL_INT64 is defined)
  • bt_secp256k1_i128.h (USE_FORCE_WIDEMUL_IN128 is defined)
  • bt_secp256k1_i128_x86_64_asm.h (USE_FORCE_WIDEMUL_IN128 & USE_ASM_X86_64 is defined)

Given the 3 variants, for optimal performance choose the most featureful variant that your platform supports.

In exactly one .c or .cpp file that includes bt_secp256k1.h define BT_SECP256K1_IMPLEMENTATION as per follows (with additional options to configure the library via macros, see the single file headers for more definitive explanations).

#define BT_SECP256K1_IMPLEMENTATION
// NOTE: The 2 following defines are optional! We provide a default value if
// these are not defined before the implementation
#define ECMULT_GEN_PREC_BITS 4
#define ECMULT_WINDOW_SIZE 15
#include "bt_secp256k1_i64.h"

Details

The metaprogram provided in bt_secp256k1_metaprogam.cpp is responsible for collating code files and patching source files to ensure the project can be combined into a single header file, generating the output files.

The code generated header files vendored in the repository correspond to the current commit hash checked out from the secp256k1 submodule.

The single file header code-generator metaprogram is provided under the Unlicense license.

An example program bt_secp256k1_example.c is provided that implements a basic secp256k1 keypair generator for reference and testing the single header file compilation.

License

This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means.