Merge bitcoin-core/secp256k1#1231: Move SECP256K1_INLINE
macro definition out from include/secp256k1.h
8e142ca4102ade1b90dcb06d6c78405ef3220599 Move `SECP256K1_INLINE` macro definition out from `include/secp256k1.h` (Hennadii Stepanov)
77445898a5852ecd38ab95cfb329333a82673115 Remove `SECP256K1_INLINE` usage from examples (Hennadii Stepanov)
Pull request description:
From [IRC](https://gnusha.org/secp256k1/2023-01-31.log):
> 06:29 \< hebasto\> What are reasons to define the `SECP256K1_INLINE` macro in user's `include/secp256k1.h` header, while it is used internally only?
> 06:32 \< hebasto\> I mean, any other (or a new dedicated) header in `src` looks more appropriate, no?
> 06:35 \< sipa\> I think it may just predate any "utility" internal headers.
> 06:42 \< sipa\> I think it makes sense to move it to util.h
Pros:
- it is a step in direction to better organized headers (in context of #924, #1039)
Cons:
- code duplication for `SECP256K1_GNUC_PREREQ` macro
ACKs for top commit:
sipa:
utACK 8e142ca4102ade1b90dcb06d6c78405ef3220599
real-or-random:
utACK 8e142ca410
Tree-SHA512: 180e0ba7c2ef242b765f20698b67d06c492b7b70866c21db27c18d8b2e85c3e11f86c6cb99ffa88bbd23891ce3ee8a24bc528f2c91167ec2fddc167463f78eac
This commit is contained in:
commit
a6f4bcf6e1
@ -77,7 +77,7 @@ static void print_hex(unsigned char* data, size_t size) {
|
|||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
#endif
|
#endif
|
||||||
/* Cleanses memory to prevent leaking sensitive info. Won't be optimized out. */
|
/* Cleanses memory to prevent leaking sensitive info. Won't be optimized out. */
|
||||||
static SECP256K1_INLINE void secure_erase(void *ptr, size_t len) {
|
static void secure_erase(void *ptr, size_t len) {
|
||||||
#if defined(_MSC_VER)
|
#if defined(_MSC_VER)
|
||||||
/* SecureZeroMemory is guaranteed not to be optimized out by MSVC. */
|
/* SecureZeroMemory is guaranteed not to be optimized out by MSVC. */
|
||||||
SecureZeroMemory(ptr, len);
|
SecureZeroMemory(ptr, len);
|
||||||
|
@ -122,18 +122,6 @@ typedef int (*secp256k1_nonce_function)(
|
|||||||
# endif
|
# endif
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
# if (!defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L) )
|
|
||||||
# if SECP256K1_GNUC_PREREQ(2,7)
|
|
||||||
# define SECP256K1_INLINE __inline__
|
|
||||||
# elif (defined(_MSC_VER))
|
|
||||||
# define SECP256K1_INLINE __inline
|
|
||||||
# else
|
|
||||||
# define SECP256K1_INLINE
|
|
||||||
# endif
|
|
||||||
# else
|
|
||||||
# define SECP256K1_INLINE inline
|
|
||||||
# endif
|
|
||||||
|
|
||||||
/* When this header is used at build-time the SECP256K1_BUILD define needs to be set
|
/* When this header is used at build-time the SECP256K1_BUILD define needs to be set
|
||||||
* to correctly setup export attributes and nullness checks. This is normally done
|
* to correctly setup export attributes and nullness checks. This is normally done
|
||||||
* by secp256k1.c but to guard against this header being included before secp256k1.c
|
* by secp256k1.c but to guard against this header being included before secp256k1.c
|
||||||
|
@ -14,6 +14,8 @@
|
|||||||
#ifndef SECP256K1_FIELD_INNER5X52_IMPL_H
|
#ifndef SECP256K1_FIELD_INNER5X52_IMPL_H
|
||||||
#define SECP256K1_FIELD_INNER5X52_IMPL_H
|
#define SECP256K1_FIELD_INNER5X52_IMPL_H
|
||||||
|
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
SECP256K1_INLINE static void secp256k1_fe_mul_inner(uint64_t *r, const uint64_t *a, const uint64_t * SECP256K1_RESTRICT b) {
|
SECP256K1_INLINE static void secp256k1_fe_mul_inner(uint64_t *r, const uint64_t *a, const uint64_t * SECP256K1_RESTRICT b) {
|
||||||
/**
|
/**
|
||||||
* Registers: rdx:rax = multiplication accumulator
|
* Registers: rdx:rax = multiplication accumulator
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "int128.h"
|
#include "int128.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
#ifdef VERIFY
|
#ifdef VERIFY
|
||||||
#define VERIFY_BITS(x, n) VERIFY_CHECK(((x) >> (n)) == 0)
|
#define VERIFY_BITS(x, n) VERIFY_CHECK(((x) >> (n)) == 0)
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
#include "field.h"
|
#include "field.h"
|
||||||
#include "group.h"
|
#include "group.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
/* Begin of section generated by sage/gen_exhaustive_groups.sage. */
|
/* Begin of section generated by sage/gen_exhaustive_groups.sage. */
|
||||||
#define SECP256K1_G_ORDER_7 SECP256K1_GE_CONST(\
|
#define SECP256K1_G_ORDER_7 SECP256K1_GE_CONST(\
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#define SECP256K1_INT128_NATIVE_IMPL_H
|
#define SECP256K1_INT128_NATIVE_IMPL_H
|
||||||
|
|
||||||
#include "int128.h"
|
#include "int128.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
static SECP256K1_INLINE void secp256k1_u128_load(secp256k1_uint128 *r, uint64_t hi, uint64_t lo) {
|
static SECP256K1_INLINE void secp256k1_u128_load(secp256k1_uint128 *r, uint64_t hi, uint64_t lo) {
|
||||||
*r = (((uint128_t)hi) << 64) + lo;
|
*r = (((uint128_t)hi) << 64) + lo;
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#define SECP256K1_INT128_STRUCT_IMPL_H
|
#define SECP256K1_INT128_STRUCT_IMPL_H
|
||||||
|
|
||||||
#include "int128.h"
|
#include "int128.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
#if defined(_MSC_VER) && (defined(_M_X64) || defined(_M_ARM64)) /* MSVC */
|
#if defined(_MSC_VER) && (defined(_M_X64) || defined(_M_ARM64)) /* MSVC */
|
||||||
# include <intrin.h>
|
# include <intrin.h>
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
#include "../../../include/secp256k1.h"
|
#include "../../../include/secp256k1.h"
|
||||||
#include "../../../include/secp256k1_extrakeys.h"
|
#include "../../../include/secp256k1_extrakeys.h"
|
||||||
|
#include "../../util.h"
|
||||||
|
|
||||||
static SECP256K1_INLINE int secp256k1_xonly_pubkey_load(const secp256k1_context* ctx, secp256k1_ge *ge, const secp256k1_xonly_pubkey *pubkey) {
|
static SECP256K1_INLINE int secp256k1_xonly_pubkey_load(const secp256k1_context* ctx, secp256k1_ge *ge, const secp256k1_xonly_pubkey *pubkey) {
|
||||||
return secp256k1_pubkey_load(ctx, ge, (const secp256k1_pubkey *) pubkey);
|
return secp256k1_pubkey_load(ctx, ge, (const secp256k1_pubkey *) pubkey);
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#include "checkmem.h"
|
#include "checkmem.h"
|
||||||
#include "int128.h"
|
#include "int128.h"
|
||||||
#include "modinv64_impl.h"
|
#include "modinv64_impl.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
/* Limbs of the secp256k1 order. */
|
/* Limbs of the secp256k1 order. */
|
||||||
#define SECP256K1_N_0 ((uint64_t)0xBFD25E8CD0364141ULL)
|
#define SECP256K1_N_0 ((uint64_t)0xBFD25E8CD0364141ULL)
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
#include "checkmem.h"
|
#include "checkmem.h"
|
||||||
#include "modinv32_impl.h"
|
#include "modinv32_impl.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
/* Limbs of the secp256k1 order. */
|
/* Limbs of the secp256k1 order. */
|
||||||
#define SECP256K1_N_0 ((uint32_t)0xD0364141UL)
|
#define SECP256K1_N_0 ((uint32_t)0xD0364141UL)
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
#include "checkmem.h"
|
#include "checkmem.h"
|
||||||
#include "scalar.h"
|
#include "scalar.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
@ -7,6 +7,8 @@
|
|||||||
#ifndef SECP256K1_TESTRAND_H
|
#ifndef SECP256K1_TESTRAND_H
|
||||||
#define SECP256K1_TESTRAND_H
|
#define SECP256K1_TESTRAND_H
|
||||||
|
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
/* A non-cryptographic RNG used only for test infrastructure. */
|
/* A non-cryptographic RNG used only for test infrastructure. */
|
||||||
|
|
||||||
/** Seed the pseudorandom number generator for testing. */
|
/** Seed the pseudorandom number generator for testing. */
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
#include "testrand.h"
|
#include "testrand.h"
|
||||||
#include "hash.h"
|
#include "hash.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
static uint64_t secp256k1_test_state[4];
|
static uint64_t secp256k1_test_state[4];
|
||||||
static uint64_t secp256k1_test_rng_integer;
|
static uint64_t secp256k1_test_rng_integer;
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
#include "testrand_impl.h"
|
#include "testrand_impl.h"
|
||||||
#include "ecmult_compute_table_impl.h"
|
#include "ecmult_compute_table_impl.h"
|
||||||
#include "ecmult_gen_compute_table_impl.h"
|
#include "ecmult_gen_compute_table_impl.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
static int count = 2;
|
static int count = 2;
|
||||||
|
|
||||||
|
14
src/util.h
14
src/util.h
@ -7,6 +7,8 @@
|
|||||||
#ifndef SECP256K1_UTIL_H
|
#ifndef SECP256K1_UTIL_H
|
||||||
#define SECP256K1_UTIL_H
|
#define SECP256K1_UTIL_H
|
||||||
|
|
||||||
|
#include "../include/secp256k1.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@ -17,6 +19,18 @@
|
|||||||
#define DEBUG_CONFIG_MSG(x) "DEBUG_CONFIG: " x
|
#define DEBUG_CONFIG_MSG(x) "DEBUG_CONFIG: " x
|
||||||
#define DEBUG_CONFIG_DEF(x) DEBUG_CONFIG_MSG(#x "=" STR(x))
|
#define DEBUG_CONFIG_DEF(x) DEBUG_CONFIG_MSG(#x "=" STR(x))
|
||||||
|
|
||||||
|
# if (!defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L) )
|
||||||
|
# if SECP256K1_GNUC_PREREQ(2,7)
|
||||||
|
# define SECP256K1_INLINE __inline__
|
||||||
|
# elif (defined(_MSC_VER))
|
||||||
|
# define SECP256K1_INLINE __inline
|
||||||
|
# else
|
||||||
|
# define SECP256K1_INLINE
|
||||||
|
# endif
|
||||||
|
# else
|
||||||
|
# define SECP256K1_INLINE inline
|
||||||
|
# endif
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
void (*fn)(const char *text, void* data);
|
void (*fn)(const char *text, void* data);
|
||||||
const void* data;
|
const void* data;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user