Bitcoin ABC 0.26.3
P2P Digital Currency
Loading...
Searching...
No Matches
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 "scalar.h"
13#include "field.h"
14#include "group.h"
15#include "ecmult_gen.h"
16
17static int secp256k1_eckey_pubkey_parse(secp256k1_ge *elem, const unsigned char *pub, size_t size) {
18 if (size == 33 && (pub[0] == SECP256K1_TAG_PUBKEY_EVEN || pub[0] == SECP256K1_TAG_PUBKEY_ODD)) {
22 secp256k1_fe x, y;
23 if (!secp256k1_fe_set_b32(&x, pub+1) || !secp256k1_fe_set_b32(&y, pub+33)) {
24 return 0;
25 }
29 return 0;
30 }
32 } else {
33 return 0;
34 }
35}
36
37static int secp256k1_eckey_pubkey_serialize(secp256k1_ge *elem, unsigned char *pub, size_t *size, int compressed) {
39 return 0;
40 }
44 if (compressed) {
45 *size = 33;
47 } else {
48 *size = 65;
50 secp256k1_fe_get_b32(&pub[33], &elem->y);
51 }
52 return 1;
53}
54
59
63 secp256k1_gej_set_ge(&pt, key);
65 secp256k1_ecmult(ctx, &pt, &pt, &one, tweak);
66
68 return 0;
69 }
70 secp256k1_ge_set_gej(key, &pt);
71 return 1;
72}
73
81
86 return 0;
87 }
88
90 secp256k1_gej_set_ge(&pt, key);
91 secp256k1_ecmult(ctx, &pt, &pt, tweak, &zero);
92 secp256k1_ge_set_gej(key, &pt);
93 return 1;
94}
95
96#endif /* SECP256K1_ECKEY_IMPL_H */
secp256k1_context * ctx
static int secp256k1_eckey_pubkey_tweak_mul(const secp256k1_ecmult_context *ctx, secp256k1_ge *key, const secp256k1_scalar *tweak)
Definition eckey_impl.h:82
static int secp256k1_eckey_privkey_tweak_add(secp256k1_scalar *key, const secp256k1_scalar *tweak)
Definition eckey_impl.h:55
static int secp256k1_eckey_privkey_tweak_mul(secp256k1_scalar *key, const secp256k1_scalar *tweak)
Definition eckey_impl.h:74
static int secp256k1_eckey_pubkey_tweak_add(const secp256k1_ecmult_context *ctx, secp256k1_ge *key, const secp256k1_scalar *tweak)
Definition eckey_impl.h:60
static int secp256k1_eckey_pubkey_parse(secp256k1_ge *elem, const unsigned char *pub, size_t size)
Definition eckey_impl.h:17
static int secp256k1_eckey_pubkey_serialize(secp256k1_ge *elem, unsigned char *pub, size_t *size, int compressed)
Definition eckey_impl.h:37
static void secp256k1_ecmult(const secp256k1_ecmult_context *ctx, secp256k1_gej *r, const secp256k1_gej *a, const secp256k1_scalar *na, const secp256k1_scalar *ng)
Double multiply: R = na*A + ng*G.
static void secp256k1_fe_normalize_var(secp256k1_fe *r)
Normalize a field element, without constant-time guarantee.
static int secp256k1_fe_is_odd(const secp256k1_fe *a)
Check the "oddness" of a field element.
static int secp256k1_fe_set_b32(secp256k1_fe *r, const unsigned char *a)
Set a field element equal to 32-byte big endian value.
static void secp256k1_fe_get_b32(unsigned char *r, const secp256k1_fe *a)
Convert a field element to a 32-byte big endian value.
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.
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
Definition random.h:85
static int secp256k1_scalar_is_zero(const secp256k1_scalar *a)
Check whether a scalar equals zero.
static void secp256k1_scalar_set_int(secp256k1_scalar *r, unsigned int v)
Set a scalar to an unsigned integer.
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).
#define SECP256K1_TAG_PUBKEY_EVEN
Prefix byte used to tag various encoded curvepoints for specific purposes.
Definition secp256k1.h:183
#define SECP256K1_TAG_PUBKEY_HYBRID_ODD
Definition secp256k1.h:187
#define SECP256K1_TAG_PUBKEY_HYBRID_EVEN
Definition secp256k1.h:186
#define SECP256K1_TAG_PUBKEY_UNCOMPRESSED
Definition secp256k1.h:185
#define SECP256K1_TAG_PUBKEY_ODD
Definition secp256k1.h:184
A group element of the secp256k1 curve, in affine coordinates.
Definition group.h:13
A group element of the secp256k1 curve, in jacobian coordinates.
Definition group.h:23
A scalar modulo the group order of the secp256k1 curve.
Definition scalar_4x64.h:13