Skip to content

Commit

Permalink
int128: Tidy #includes of int128.h and int128_impl.h
Browse files Browse the repository at this point in the history
After this commit, int128.h and int128_impl.h are included as follows:
 - .c files which use int128 include int128_impl.h (after util.h)
 - .h files which use int128 include int128.h (after util.h)

This list is exhaustive. util.h needs to included first because it sets
up necessary #defines.
  • Loading branch information
real-or-random authored and roconnor-blockstream committed Nov 7, 2022
1 parent 2914bcc commit dceaa1f
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 23 deletions.
2 changes: 2 additions & 0 deletions src/field_5x52_int128_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

#include <stdint.h>

#include "int128.h"

#ifdef VERIFY
#define VERIFY_BITS(x, n) VERIFY_CHECK(((x) >> (n)) == 0)
#define VERIFY_BITS_128(x, n) VERIFY_CHECK(secp256k1_u128_check_bits((x), (n)))
Expand Down
21 changes: 10 additions & 11 deletions src/int128.h
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
#ifndef SECP256K1_INT128_H
#define SECP256K1_INT128_H

#if defined HAVE_CONFIG_H
#include "libsecp256k1-config.h"
#endif

#include "util.h"

#if defined(SECP256K1_INT128_NATIVE)
#include "int128_native.h"
#elif defined(SECP256K1_INT128_STRUCT)
#include "int128_struct.h"
#else
#error "Please select int128 implementation"
#endif
#if defined(SECP256K1_WIDEMUL_INT128)
# if defined(SECP256K1_INT128_NATIVE)
# include "int128_native.h"
# elif defined(SECP256K1_INT128_STRUCT)
# include "int128_struct.h"
# else
# error "Please select int128 implementation"
# endif

/* Multiply two unsigned 64-bit values a and b and write the result to r. */
static SECP256K1_INLINE void secp256k1_u128_mul(secp256k1_uint128 *r, uint64_t a, uint64_t b);
Expand Down Expand Up @@ -78,3 +75,5 @@ static SECP256K1_INLINE int secp256k1_i128_eq_var(const secp256k1_int128 *a, con
static SECP256K1_INLINE int secp256k1_i128_check_pow2(const secp256k1_int128 *r, unsigned int n);

#endif

#endif
19 changes: 9 additions & 10 deletions src/int128_impl.h
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
#ifndef SECP256K1_INT128_IMPL_H
#define SECP256K1_INT128_IMPL_H

#include "int128.h"
#include "util.h"

#if defined HAVE_CONFIG_H
#include "libsecp256k1-config.h"
#endif
#include "int128.h"

#if defined(SECP256K1_INT128_NATIVE)
#include "int128_native_impl.h"
#elif defined(SECP256K1_INT128_STRUCT)
#include "int128_struct_impl.h"
#else
#error "Please select int128 implementation"
#if defined(SECP256K1_WIDEMUL_INT128)
# if defined(SECP256K1_INT128_NATIVE)
# include "int128_native_impl.h"
# elif defined(SECP256K1_INT128_STRUCT)
# include "int128_struct_impl.h"
# else
# error "Please select int128 implementation"
# endif
#endif

#endif
3 changes: 1 addition & 2 deletions src/modinv64_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
#ifndef SECP256K1_MODINV64_IMPL_H
#define SECP256K1_MODINV64_IMPL_H

#include "int128.h"
#include "modinv64.h"

#include "int128_impl.h"

/* This file implements modular inversion based on the paper "Fast constant-time gcd computation and
* modular inversion" by Daniel J. Bernstein and Bo-Yin Yang.
*
Expand Down
3 changes: 3 additions & 0 deletions src/precompute_ecmult.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@
#endif

#include "../include/secp256k1.h"

#include "assumptions.h"
#include "util.h"

#include "field_impl.h"
#include "group_impl.h"
#include "int128_impl.h"
#include "ecmult.h"
#include "ecmult_compute_table_impl.h"

Expand Down
3 changes: 3 additions & 0 deletions src/precompute_ecmult_gen.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@
#include <stdio.h>

#include "../include/secp256k1.h"

#include "assumptions.h"
#include "util.h"

#include "group.h"
#include "int128_impl.h"
#include "ecmult_gen.h"
#include "ecmult_gen_compute_table_impl.h"

Expand Down
1 change: 1 addition & 0 deletions src/scalar_4x64_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#ifndef SECP256K1_SCALAR_REPR_IMPL_H
#define SECP256K1_SCALAR_REPR_IMPL_H

#include "int128.h"
#include "modinv64_impl.h"

/* Limbs of the secp256k1 order. */
Expand Down
2 changes: 2 additions & 0 deletions src/secp256k1.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "assumptions.h"
#include "util.h"

#include "field_impl.h"
#include "scalar_impl.h"
#include "group_impl.h"
Expand All @@ -31,6 +32,7 @@
#include "ecdsa_impl.h"
#include "eckey_impl.h"
#include "hash_impl.h"
#include "int128_impl.h"
#include "scratch_impl.h"
#include "selftest.h"

Expand Down

0 comments on commit dceaa1f

Please sign in to comment.