Bitcoin Core 29.99.0
P2P Digital Currency
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
18static 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)) {
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);
30 return 0;
31 }
32 return secp256k1_ge_is_valid_var(elem);
33 } else {
34 return 0;
35 }
36}
37
38static int secp256k1_eckey_pubkey_serialize(secp256k1_ge *elem, unsigned char *pub, size_t *size, int compressed) {
39 VERIFY_CHECK(compressed == 0 || compressed == 1);
40
41 if (secp256k1_ge_is_infinity(elem)) {
42 return 0;
43 }
46 secp256k1_fe_get_b32(&pub[1], &elem->x);
47 if (compressed) {
48 *size = 33;
50 } else {
51 *size = 65;
53 secp256k1_fe_get_b32(&pub[33], &elem->y);
54 }
55 return 1;
56}
57
59 secp256k1_scalar_add(key, key, tweak);
60 return !secp256k1_scalar_is_zero(key);
61}
62
65 secp256k1_gej_set_ge(&pt, key);
67
69 return 0;
70 }
71 secp256k1_ge_set_gej(key, &pt);
72 return 1;
73}
74
76 int ret;
78
79 secp256k1_scalar_mul(key, key, tweak);
80 return ret;
81}
82
86 return 0;
87 }
88
89 secp256k1_gej_set_ge(&pt, key);
91 secp256k1_ge_set_gej(key, &pt);
92 return 1;
93}
94
95#endif /* SECP256K1_ECKEY_IMPL_H */
int ret
static int secp256k1_eckey_privkey_tweak_add(secp256k1_scalar *key, const secp256k1_scalar *tweak)
Definition: eckey_impl.h:58
static int secp256k1_eckey_pubkey_tweak_mul(secp256k1_ge *key, const secp256k1_scalar *tweak)
Definition: eckey_impl.h:83
static int secp256k1_eckey_pubkey_tweak_add(secp256k1_ge *key, const secp256k1_scalar *tweak)
Definition: eckey_impl.h:63
static int secp256k1_eckey_privkey_tweak_mul(secp256k1_scalar *key, const secp256k1_scalar *tweak)
Definition: eckey_impl.h:75
static int secp256k1_eckey_pubkey_parse(secp256k1_ge *elem, const unsigned char *pub, size_t size)
Definition: eckey_impl.h:18
static int secp256k1_eckey_pubkey_serialize(secp256k1_ge *elem, unsigned char *pub, size_t *size, int compressed)
Definition: eckey_impl.h:38
static void secp256k1_ecmult(secp256k1_gej *r, const secp256k1_gej *a, const secp256k1_scalar *na, const secp256k1_scalar *ng)
Double multiply: R = na*A + ng*G.
#define secp256k1_fe_is_odd
Definition: field.h:85
#define secp256k1_fe_normalize_var
Definition: field.h:80
#define secp256k1_fe_set_b32_limit
Definition: field.h:88
#define secp256k1_fe_get_b32
Definition: field.h:89
static int secp256k1_gej_is_infinity(const secp256k1_gej *a)
Check whether a group element is the point at infinity.
static void secp256k1_ge_set_xy(secp256k1_ge *r, const secp256k1_fe *x, const secp256k1_fe *y)
Set a group element equal to the point with given X and Y coordinates.
static int secp256k1_ge_set_xo_var(secp256k1_ge *r, const secp256k1_fe *x, int odd)
Set a group element (affine) equal to the point with the given X coordinate, and given oddness for Y.
static int secp256k1_ge_is_valid_var(const secp256k1_ge *a)
Check whether a group element is valid (i.e., on the curve).
static void secp256k1_ge_set_gej(secp256k1_ge *r, secp256k1_gej *a)
Set a group element equal to another which is given in jacobian coordinates.
static int secp256k1_ge_is_infinity(const secp256k1_ge *a)
Check whether a group element is the point at infinity.
static void secp256k1_gej_set_ge(secp256k1_gej *r, const secp256k1_ge *a)
Set a group element (jacobian) equal to another which is given in affine coordinates.
static int tweak(const secp256k1_context *ctx, secp256k1_xonly_pubkey *agg_pk, secp256k1_musig_keyagg_cache *cache)
Definition: musig.c:64
static int secp256k1_scalar_is_zero(const secp256k1_scalar *a)
Check whether a scalar equals zero.
static int secp256k1_scalar_add(secp256k1_scalar *r, const secp256k1_scalar *a, const secp256k1_scalar *b)
Add two scalars together (modulo the group order).
static void secp256k1_scalar_mul(secp256k1_scalar *r, const secp256k1_scalar *a, const secp256k1_scalar *b)
Multiply two scalars (modulo the group order).
static const secp256k1_scalar secp256k1_scalar_zero
Definition: scalar_impl.h:28
static const secp256k1_scalar secp256k1_scalar_one
Definition: scalar_impl.h:27
#define VERIFY_CHECK(cond)
Definition: util.h:159
#define SECP256K1_TAG_PUBKEY_EVEN
Prefix byte used to tag various encoded curvepoints for specific purposes.
Definition: secp256k1.h:216
#define SECP256K1_TAG_PUBKEY_HYBRID_ODD
Definition: secp256k1.h:220
#define SECP256K1_TAG_PUBKEY_HYBRID_EVEN
Definition: secp256k1.h:219
#define SECP256K1_TAG_PUBKEY_UNCOMPRESSED
Definition: secp256k1.h:218
#define SECP256K1_TAG_PUBKEY_ODD
Definition: secp256k1.h:217
This field implementation represents the value as 10 uint32_t limbs in base 2^26.
Definition: field_10x26.h:14
A group element in affine coordinates on the secp256k1 curve, or occasionally on an isomorphic curve ...
Definition: group.h:16
secp256k1_fe x
Definition: group.h:17
secp256k1_fe y
Definition: group.h:18
A group element of the secp256k1 curve, in jacobian coordinates.
Definition: group.h:28
A scalar modulo the group order of the secp256k1 curve.
Definition: scalar_4x64.h:13