Electroneum
Toggle main menu visibility
Loading...
Searching...
No Matches
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. */
16
static
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. */
19
static
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
*/
24
static
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
*/
29
static
SECP256K1_INLINE
void
secp256k1_u128_accum_u64(
secp256k1_uint128
*r,
uint64_t
a
);
30
31
/* Unsigned (logical) right shift.
32
* Non-constant time in n.
33
*/
34
static
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. */
37
static
SECP256K1_INLINE
uint64_t
secp256k1_u128_to_u64(
const
secp256k1_uint128
*
a
);
38
39
/* Return the high 64-bits of a 128-bit value as an unsigned 64-bit value. */
40
static
SECP256K1_INLINE
uint64_t
secp256k1_u128_hi_u64(
const
secp256k1_uint128
*
a
);
41
42
/* Write an unsigned 64-bit value to r. */
43
static
SECP256K1_INLINE
void
secp256k1_u128_from_u64(
secp256k1_uint128
*r,
uint64_t
a
);
44
45
/* Tests if r is strictly less than to 2^n.
46
* n must be strictly less than 128.
47
*/
48
static
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. */
51
static
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. */
54
static
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
*/
59
static
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. */
62
static
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
*/
67
static
SECP256K1_INLINE
void
secp256k1_i128_rshift(
secp256k1_int128
*r,
unsigned
int
b);
68
69
/* Return the input value modulo 2^64. */
70
static
SECP256K1_INLINE
uint64_t
secp256k1_i128_to_u64(
const
secp256k1_int128
*
a
);
71
72
/* Return the value as a signed 64-bit value.
73
* Requires the input to be between INT64_MIN and INT64_MAX.
74
*/
75
static
SECP256K1_INLINE
int64_t
secp256k1_i128_to_i64(
const
secp256k1_int128
*
a
);
76
77
/* Write a signed 64-bit value to r. */
78
static
SECP256K1_INLINE
void
secp256k1_i128_from_i64(
secp256k1_int128
*r,
int64_t
a
);
79
80
/* Compare two 128-bit values for equality. */
81
static
SECP256K1_INLINE
int
secp256k1_i128_eq_var(
const
secp256k1_int128
*
a
,
const
secp256k1_int128
*b);
82
83
/* Tests if r is equal to 2^n.
84
* n must be strictly less than 127.
85
*/
86
static
SECP256K1_INLINE
int
secp256k1_i128_check_pow2(
const
secp256k1_int128
*r,
unsigned
int
n);
87
88
#endif
89
90
#endif
util.h
int128_native.h
secp256k1_int128
int128_t secp256k1_int128
Definition
int128_native.h:17
int128_struct.h
a
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition
pointer.h:1124
SECP256K1_INLINE
#define SECP256K1_INLINE
Definition
secp256k1.h:131
int64_t
signed __int64 int64_t
Definition
stdint.h:135
uint64_t
unsigned __int64 uint64_t
Definition
stdint.h:136
secp256k1_uint128
Definition
int128_struct.h:7
external
secp256k1
src
int128.h
Generated on
for Electroneum by
1.17.0