A code generated C/C++ single file header for bitcoin-core/secp256k1's cryptography library
Go to file
2022-06-27 22:43:01 +10:00
secp256k1@44c2452fd3 Update secp256k1 to 44c2452fd387f7ca604ab42d73746e7d3a44d8a2 2022-06-27 22:43:01 +10: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 Update secp256k1 to 44c2452fd387f7ca604ab42d73746e7d3a44d8a2 2022-06-27 22:43:01 +10:00
bt_secp256k1_i128_x86_64_asm.h Update secp256k1 to 44c2452fd387f7ca604ab42d73746e7d3a44d8a2 2022-06-27 22:43:01 +10:00
bt_secp256k1_i128.h Update secp256k1 to 44c2452fd387f7ca604ab42d73746e7d3a44d8a2 2022-06-27 22:43:01 +10:00
bt_secp256k1_metaprogram.cpp Update readme with build details, license clarifications, reorder macros 2022-01-24 23:09:45 +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 Update readme with build details, license clarifications, reorder macros 2022-01-24 23:09:45 +11:00

bt_secp256k1 (Blockchain Tools - 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
#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.

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.

Build

The build is currently tested on Windows Visual Studio 2019's cl via build.bat which will build the metaprogram and generate the single header files.

Examples are built using build_examples.bat and optionally invoke clang-cl if it's available on the path.

License

The single file header code-generator metaprogram is provided under the Unlicense 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.

bitcoin-core/secp256k1 is provided under its original license and is embedded in the single-file-header.