Bitcoin Core 28.99.0
P2P Digital Currency
int128.h
Go to the documentation of this file.
1#ifndef SECP256K1_INT128_H
2#define SECP256K1_INT128_H
3
4#include "util.h"
5
6#if defined(SECP256K1_WIDEMUL_INT128)
7# if defined(SECP256K1_INT128_NATIVE)
8# include "int128_native.h"
9# elif defined(SECP256K1_INT128_STRUCT)
10# include "int128_struct.h"
11# else
12# error "Please select int128 implementation"
13# endif
14
15/* Construct an unsigned 128-bit value from a high and a low 64-bit value. */
16static SECP256K1_INLINE void secp256k1_u128_load(secp256k1_uint128 *r, uint64_t hi, uint64_t lo);
17
18/* Multiply two unsigned 64-bit values a and b and write the result to r. */
19static SECP256K1_INLINE void secp256k1_u128_mul(secp256k1_uint128 *r, uint64_t a, uint64_t b);
20
21/* Multiply two unsigned 64-bit values a and b and add the result to r.
22 * The final result is taken modulo 2^128.
23 */
24static SECP256K1_INLINE void secp256k1_u128_accum_mul(secp256k1_uint128 *r, uint64_t a, uint64_t b);
25
26/* Add an unsigned 64-bit value a to r.
27 * The final result is taken modulo 2^128.
28 */
30
31/* Unsigned (logical) right shift.
32 * Non-constant time in n.
33 */
34static SECP256K1_INLINE void secp256k1_u128_rshift(secp256k1_uint128 *r, unsigned int n);
35
36/* Return the low 64-bits of a 128-bit value as an unsigned 64-bit value. */
38
39/* Return the high 64-bits of a 128-bit value as an unsigned 64-bit value. */
41
42/* Write an unsigned 64-bit value to r. */
44
45/* Tests if r is strictly less than to 2^n.
46 * n must be strictly less than 128.
47 */
48static SECP256K1_INLINE int secp256k1_u128_check_bits(const secp256k1_uint128 *r, unsigned int n);
49
50/* Construct an signed 128-bit value from a high and a low 64-bit value. */
51static SECP256K1_INLINE void secp256k1_i128_load(secp256k1_int128 *r, int64_t hi, uint64_t lo);
52
53/* Multiply two signed 64-bit values a and b and write the result to r. */
54static SECP256K1_INLINE void secp256k1_i128_mul(secp256k1_int128 *r, int64_t a, int64_t b);
55
56/* Multiply two signed 64-bit values a and b and add the result to r.
57 * Overflow or underflow from the addition is undefined behaviour.
58 */
59static SECP256K1_INLINE void secp256k1_i128_accum_mul(secp256k1_int128 *r, int64_t a, int64_t b);
60
61/* Compute a*d - b*c from signed 64-bit values and write the result to r. */
62static SECP256K1_INLINE void secp256k1_i128_det(secp256k1_int128 *r, int64_t a, int64_t b, int64_t c, int64_t d);
63
64/* Signed (arithmetic) right shift.
65 * Non-constant time in b.
66 */
67static SECP256K1_INLINE void secp256k1_i128_rshift(secp256k1_int128 *r, unsigned int b);
68
69/* Return the input value modulo 2^64. */
71
72/* Return the value as a signed 64-bit value.
73 * Requires the input to be between INT64_MIN and INT64_MAX.
74 */
76
77/* Write a signed 64-bit value to r. */
79
80/* Compare two 128-bit values for equality. */
82
83/* Tests if r is equal to sign*2^n (sign must be 1 or -1).
84 * n must be strictly less than 127.
85 */
86static SECP256K1_INLINE int secp256k1_i128_check_pow2(const secp256k1_int128 *r, unsigned int n, int sign);
87
88#endif
89
90#endif
int128_t secp256k1_int128
Definition: int128_native.h:17
static SECP256K1_INLINE void secp256k1_i128_load(secp256k1_int128 *r, int64_t hi, uint64_t lo)
static SECP256K1_INLINE void secp256k1_i128_det(secp256k1_int128 *r, int64_t a, int64_t b, int64_t c, int64_t d)
static SECP256K1_INLINE int secp256k1_u128_check_bits(const secp256k1_uint128 *r, unsigned int n)
static SECP256K1_INLINE void secp256k1_i128_rshift(secp256k1_int128 *r, unsigned int n)
static SECP256K1_INLINE uint64_t secp256k1_u128_hi_u64(const secp256k1_uint128 *a)
static SECP256K1_INLINE uint64_t secp256k1_i128_to_u64(const secp256k1_int128 *a)
static SECP256K1_INLINE void secp256k1_i128_from_i64(secp256k1_int128 *r, int64_t a)
static SECP256K1_INLINE void secp256k1_u128_from_u64(secp256k1_uint128 *r, uint64_t a)
static SECP256K1_INLINE int secp256k1_i128_eq_var(const secp256k1_int128 *a, const secp256k1_int128 *b)
static SECP256K1_INLINE int64_t secp256k1_i128_to_i64(const secp256k1_int128 *a)
static SECP256K1_INLINE void secp256k1_i128_mul(secp256k1_int128 *r, int64_t a, int64_t b)
static SECP256K1_INLINE void secp256k1_u128_rshift(secp256k1_uint128 *r, unsigned int n)
static SECP256K1_INLINE int secp256k1_i128_check_pow2(const secp256k1_int128 *r, unsigned int n, int sign)
static SECP256K1_INLINE void secp256k1_u128_accum_u64(secp256k1_uint128 *r, uint64_t a)
static SECP256K1_INLINE void secp256k1_i128_accum_mul(secp256k1_int128 *r, int64_t a, int64_t b)
static SECP256K1_INLINE void secp256k1_u128_accum_mul(secp256k1_uint128 *r, uint64_t a, uint64_t b)
static SECP256K1_INLINE void secp256k1_u128_load(secp256k1_uint128 *r, uint64_t hi, uint64_t lo)
static SECP256K1_INLINE void secp256k1_u128_mul(secp256k1_uint128 *r, uint64_t a, uint64_t b)
static SECP256K1_INLINE uint64_t secp256k1_u128_to_u64(const secp256k1_uint128 *a)
static int sign(const secp256k1_context *ctx, struct signer_secrets *signer_secrets, struct signer *signer, const secp256k1_musig_keyagg_cache *cache, const unsigned char *msg32, unsigned char *sig64)
Definition: musig.c:105
#define SECP256K1_INLINE
Definition: util.h:54