Bitcoin Core
31.1.0
P2P Digital Currency
Toggle main menu visibility
Loading...
Searching...
No Matches
src
secp256k1
src
eckey_impl.h
Go to the documentation of this file.
1
/***********************************************************************
2
* Copyright (c) 2013, 2014 Pieter Wuille *
3
* Distributed under the MIT software license, see the accompanying *
4
* file COPYING or https://www.opensource.org/licenses/mit-license.php.*
5
***********************************************************************/
6
7
#ifndef SECP256K1_ECKEY_IMPL_H
8
#define SECP256K1_ECKEY_IMPL_H
9
10
#include "
eckey.h
"
11
12
#include "
util.h
"
13
#include "
scalar.h
"
14
#include "
field.h
"
15
#include "
group.h
"
16
#include "
ecmult_gen.h
"
17
18
static
int
secp256k1_eckey_pubkey_parse
(
secp256k1_ge
*elem,
const
unsigned
char
*pub,
size_t
size) {
19
if
(size == 33 && (pub[0] ==
SECP256K1_TAG_PUBKEY_EVEN
|| pub[0] ==
SECP256K1_TAG_PUBKEY_ODD
)) {
20
secp256k1_fe
x;
21
return
secp256k1_fe_set_b32_limit
(&x, pub+1) && secp256k1_ge_set_xo_var(elem, &x, pub[0] ==
SECP256K1_TAG_PUBKEY_ODD
);
22
}
else
if
(size == 65 && (pub[0] ==
SECP256K1_TAG_PUBKEY_UNCOMPRESSED
|| pub[0] ==
SECP256K1_TAG_PUBKEY_HYBRID_EVEN
|| pub[0] ==
SECP256K1_TAG_PUBKEY_HYBRID_ODD
)) {
23
secp256k1_fe
x, y;
24
if
(!
secp256k1_fe_set_b32_limit
(&x, pub+1) || !
secp256k1_fe_set_b32_limit
(&y, pub+33)) {
25
return
0;
26
}
27
secp256k1_ge_set_xy(elem, &x, &y);
28
if
((pub[0] ==
SECP256K1_TAG_PUBKEY_HYBRID_EVEN
|| pub[0] ==
SECP256K1_TAG_PUBKEY_HYBRID_ODD
) &&
29
secp256k1_fe_is_odd
(&y) != (pub[0] ==
SECP256K1_TAG_PUBKEY_HYBRID_ODD
)) {
30
return
0;
31
}
32
return
secp256k1_ge_is_valid_var(elem);
33
}
else
{
34
return
0;
35
}
36
}
37
38
static
void
secp256k1_eckey_pubkey_serialize33
(
secp256k1_ge
*elem,
unsigned
char
*pub33) {
39
VERIFY_CHECK
(!secp256k1_ge_is_infinity(elem));
40
41
secp256k1_fe_normalize_var
(&elem->
x
);
42
secp256k1_fe_normalize_var
(&elem->
y
);
43
pub33[0] =
secp256k1_fe_is_odd
(&elem->
y
) ?
SECP256K1_TAG_PUBKEY_ODD
:
SECP256K1_TAG_PUBKEY_EVEN
;
44
secp256k1_fe_get_b32
(&pub33[1], &elem->
x
);
45
}
46
47
static
void
secp256k1_eckey_pubkey_serialize65
(
secp256k1_ge
*elem,
unsigned
char
*pub65) {
48
VERIFY_CHECK
(!secp256k1_ge_is_infinity(elem));
49
50
secp256k1_fe_normalize_var
(&elem->
x
);
51
secp256k1_fe_normalize_var
(&elem->
y
);
52
pub65[0] =
SECP256K1_TAG_PUBKEY_UNCOMPRESSED
;
53
secp256k1_fe_get_b32
(&pub65[1], &elem->
x
);
54
secp256k1_fe_get_b32
(&pub65[33], &elem->
y
);
55
}
56
57
static
int
secp256k1_eckey_privkey_tweak_add
(
secp256k1_scalar
*key,
const
secp256k1_scalar
*
tweak
) {
58
secp256k1_scalar_add(key, key,
tweak
);
59
return
!secp256k1_scalar_is_zero(key);
60
}
61
62
static
int
secp256k1_eckey_pubkey_tweak_add
(
secp256k1_ge
*key,
const
secp256k1_scalar
*
tweak
) {
63
secp256k1_gej
pt;
64
secp256k1_gej_set_ge(&pt, key);
65
secp256k1_ecmult(&pt, &pt, &secp256k1_scalar_one,
tweak
);
66
67
if
(secp256k1_gej_is_infinity(&pt)) {
68
return
0;
69
}
70
secp256k1_ge_set_gej(key, &pt);
71
return
1;
72
}
73
74
static
int
secp256k1_eckey_privkey_tweak_mul
(
secp256k1_scalar
*key,
const
secp256k1_scalar
*
tweak
) {
75
int
ret
;
76
ret
= !secp256k1_scalar_is_zero(
tweak
);
77
78
secp256k1_scalar_mul(key, key,
tweak
);
79
return
ret
;
80
}
81
82
static
int
secp256k1_eckey_pubkey_tweak_mul
(
secp256k1_ge
*key,
const
secp256k1_scalar
*
tweak
) {
83
secp256k1_gej
pt;
84
if
(secp256k1_scalar_is_zero(
tweak
)) {
85
return
0;
86
}
87
88
secp256k1_gej_set_ge(&pt, key);
89
secp256k1_ecmult(&pt, &pt,
tweak
, &secp256k1_scalar_zero);
90
secp256k1_ge_set_gej(key, &pt);
91
return
1;
92
}
93
94
#endif
/* SECP256K1_ECKEY_IMPL_H */
ret
int ret
Definition
bitcoin-cli.cpp:1350
eckey.h
secp256k1_eckey_pubkey_serialize65
static void secp256k1_eckey_pubkey_serialize65(secp256k1_ge *elem, unsigned char *pub65)
Serialize a group element (that is not allowed to be infinity) to an uncompressed public key (65 byte...
secp256k1_eckey_privkey_tweak_add
static int secp256k1_eckey_privkey_tweak_add(secp256k1_scalar *key, const secp256k1_scalar *tweak)
secp256k1_eckey_pubkey_tweak_mul
static int secp256k1_eckey_pubkey_tweak_mul(secp256k1_ge *key, const secp256k1_scalar *tweak)
secp256k1_eckey_pubkey_tweak_add
static int secp256k1_eckey_pubkey_tweak_add(secp256k1_ge *key, const secp256k1_scalar *tweak)
secp256k1_eckey_privkey_tweak_mul
static int secp256k1_eckey_privkey_tweak_mul(secp256k1_scalar *key, const secp256k1_scalar *tweak)
secp256k1_eckey_pubkey_serialize33
static void secp256k1_eckey_pubkey_serialize33(secp256k1_ge *elem, unsigned char *pub33)
Serialize a group element (that is not allowed to be infinity) to a compressed public key (33 bytes).
secp256k1_eckey_pubkey_parse
static int secp256k1_eckey_pubkey_parse(secp256k1_ge *elem, const unsigned char *pub, size_t size)
ecmult_gen.h
field.h
secp256k1_fe_is_odd
#define secp256k1_fe_is_odd
Definition
field.h:85
secp256k1_fe_normalize_var
#define secp256k1_fe_normalize_var
Definition
field.h:80
secp256k1_fe_set_b32_limit
#define secp256k1_fe_set_b32_limit
Definition
field.h:88
secp256k1_fe_get_b32
#define secp256k1_fe_get_b32
Definition
field.h:89
group.h
tweak
static int tweak(const secp256k1_context *ctx, secp256k1_xonly_pubkey *agg_pk, secp256k1_musig_keyagg_cache *cache)
Definition
musig.c:64
scalar.h
util.h
VERIFY_CHECK
#define VERIFY_CHECK(cond)
Definition
util.h:159
SECP256K1_TAG_PUBKEY_EVEN
#define SECP256K1_TAG_PUBKEY_EVEN
Prefix byte used to tag various encoded curvepoints for specific purposes.
Definition
secp256k1.h:228
SECP256K1_TAG_PUBKEY_HYBRID_ODD
#define SECP256K1_TAG_PUBKEY_HYBRID_ODD
Definition
secp256k1.h:232
SECP256K1_TAG_PUBKEY_HYBRID_EVEN
#define SECP256K1_TAG_PUBKEY_HYBRID_EVEN
Definition
secp256k1.h:231
SECP256K1_TAG_PUBKEY_UNCOMPRESSED
#define SECP256K1_TAG_PUBKEY_UNCOMPRESSED
Definition
secp256k1.h:230
SECP256K1_TAG_PUBKEY_ODD
#define SECP256K1_TAG_PUBKEY_ODD
Definition
secp256k1.h:229
secp256k1_fe
This field implementation represents the value as 10 uint32_t limbs in base 2^26.
Definition
field_10x26.h:14
secp256k1_ge
A group element in affine coordinates on the secp256k1 curve, or occasionally on an isomorphic curve ...
Definition
group.h:16
secp256k1_ge::x
secp256k1_fe x
Definition
group.h:17
secp256k1_ge::y
secp256k1_fe y
Definition
group.h:18
secp256k1_gej
A group element of the secp256k1 curve, in jacobian coordinates.
Definition
group.h:28
secp256k1_scalar
A scalar modulo the group order of the secp256k1 curve.
Definition
scalar_4x64.h:13
Generated on
for Bitcoin Core by
1.18.0