Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
fc::em::detail::public_key_impl Class Reference

#include <_elliptic_em_impl_pub.hpp>

Collaboration diagram for fc::em::detail::public_key_impl:

Public Member Functions

 public_key_impl () BOOST_NOEXCEPT
 
 public_key_impl (const public_key_impl &cpy) BOOST_NOEXCEPT
 
 public_key_impl (public_key_impl &&cpy) BOOST_NOEXCEPT
 
 ~public_key_impl () BOOST_NOEXCEPT
 
public_key_imploperator= (const public_key_impl &pk) BOOST_NOEXCEPT
 
public_key_imploperator= (public_key_impl &&pk) BOOST_NOEXCEPT
 
 public_key_impl () BOOST_NOEXCEPT
 
 public_key_impl (const public_key_impl &cpy) BOOST_NOEXCEPT
 

Static Public Member Functions

static int ECDSA_SIG_recover_key_GFp (EC_KEY *eckey, ECDSA_SIG *ecsig, const unsigned char *msg, int msglen, int recid, int check)
 

Public Attributes

EC_KEY * _key = nullptr
 
public_key_data _key
 

Detailed Description

Definition at line 38 of file elliptic_em.cpp.

Constructor & Destructor Documentation

◆ public_key_impl() [1/5]

fc::em::detail::public_key_impl::public_key_impl ( )

Definition at line 11 of file elliptic_em_impl_pub.cpp.

12 {
13 _init_lib();
14 }
Here is the call graph for this function:

◆ public_key_impl() [2/5]

fc::em::detail::public_key_impl::public_key_impl ( const public_key_impl & cpy)

Definition at line 16 of file elliptic_em_impl_pub.cpp.

17 {
18 _init_lib();
19 *this = cpy;
20 }
Here is the call graph for this function:

◆ public_key_impl() [3/5]

fc::em::detail::public_key_impl::public_key_impl ( public_key_impl && cpy)

Definition at line 22 of file elliptic_em_impl_pub.cpp.

23 {
24 _init_lib();
25 *this = cpy;
26 }
Here is the call graph for this function:

◆ ~public_key_impl()

fc::em::detail::public_key_impl::~public_key_impl ( )

Definition at line 28 of file elliptic_em_impl_pub.cpp.

29 {
30 free_key();
31 }

◆ public_key_impl() [4/5]

fc::em::detail::public_key_impl::public_key_impl ( )
inline

Definition at line 41 of file elliptic_em.cpp.

42 {
43 _init_lib();
44 }
Here is the call graph for this function:

◆ public_key_impl() [5/5]

fc::em::detail::public_key_impl::public_key_impl ( const public_key_impl & cpy)
inline

Definition at line 46 of file elliptic_em.cpp.

47 : _key( cpy._key )
48 {
49 _init_lib();
50 }
Here is the call graph for this function:

Member Function Documentation

◆ ECDSA_SIG_recover_key_GFp()

int fc::em::detail::public_key_impl::ECDSA_SIG_recover_key_GFp ( EC_KEY * eckey,
ECDSA_SIG * ecsig,
const unsigned char * msg,
int msglen,
int recid,
int check )
static

Definition at line 68 of file elliptic_em_impl_pub.cpp.

71 {
72 if (!eckey) FC_THROW_EXCEPTION( exception, "null key" );
73
74 int ret = 0;
75 BN_CTX *ctx = NULL;
76
77 BIGNUM *x = NULL;
78 BIGNUM *e = NULL;
79 BIGNUM *order = NULL;
80 BIGNUM *sor = NULL;
81 BIGNUM *eor = NULL;
82 BIGNUM *field = NULL;
83 EC_POINT *R = NULL;
84 EC_POINT *O = NULL;
85 EC_POINT *Q = NULL;
86 BIGNUM *rr = NULL;
87 BIGNUM *zero = NULL;
88 int n = 0;
89 int i = recid / 2;
90
91 const EC_GROUP *group = EC_KEY_get0_group(eckey);
92 if ((ctx = BN_CTX_new()) == NULL) { ret = -1; goto err; }
93 BN_CTX_start(ctx);
94 order = BN_CTX_get(ctx);
95 if (!EC_GROUP_get_order(group, order, ctx)) { ret = -2; goto err; }
96 x = BN_CTX_get(ctx);
97 if (!BN_copy(x, order)) { ret=-1; goto err; }
98 if (!BN_mul_word(x, i)) { ret=-1; goto err; }
99 if (!BN_add(x, x, ecsig->r)) { ret=-1; goto err; }
100 field = BN_CTX_get(ctx);
101 if (!EC_GROUP_get_curve_GFp(group, field, NULL, NULL, ctx)) { ret=-2; goto err; }
102 if (BN_cmp(x, field) >= 0) { ret=0; goto err; }
103 if ((R = EC_POINT_new(group)) == NULL) { ret = -2; goto err; }
104 if (!EC_POINT_set_compressed_coordinates_GFp(group, R, x, recid % 2, ctx)) { ret=0; goto err; }
105 if (check)
106 {
107 if ((O = EC_POINT_new(group)) == NULL) { ret = -2; goto err; }
108 if (!EC_POINT_mul(group, O, NULL, R, order, ctx)) { ret=-2; goto err; }
109 if (!EC_POINT_is_at_infinity(group, O)) { ret = 0; goto err; }
110 }
111 if ((Q = EC_POINT_new(group)) == NULL) { ret = -2; goto err; }
112 n = EC_GROUP_get_degree(group);
113 e = BN_CTX_get(ctx);
114 if (!BN_bin2bn(msg, msglen, e)) { ret=-1; goto err; }
115 if (8*msglen > n) BN_rshift(e, e, 8-(n & 7));
116 zero = BN_CTX_get(ctx);
117 if (!BN_zero(zero)) { ret=-1; goto err; }
118 if (!BN_mod_sub(e, zero, e, order, ctx)) { ret=-1; goto err; }
119 rr = BN_CTX_get(ctx);
120 if (!BN_mod_inverse(rr, ecsig->r, order, ctx)) { ret=-1; goto err; }
121 sor = BN_CTX_get(ctx);
122 if (!BN_mod_mul(sor, ecsig->s, rr, order, ctx)) { ret=-1; goto err; }
123 eor = BN_CTX_get(ctx);
124 if (!BN_mod_mul(eor, e, rr, order, ctx)) { ret=-1; goto err; }
125 if (!EC_POINT_mul(group, Q, eor, R, sor, ctx)) { ret=-2; goto err; }
126 if (!EC_KEY_set_public_key(eckey, Q)) { ret=-2; goto err; }
127
128 ret = 1;
129
130 err:
131 if (ctx) {
132 BN_CTX_end(ctx);
133 BN_CTX_free(ctx);
134 }
135 if (R != NULL) EC_POINT_free(R);
136 if (O != NULL) EC_POINT_free(O);
137 if (Q != NULL) EC_POINT_free(Q);
138 return ret;
139 }
#define FC_THROW_EXCEPTION(EXCEPTION, FORMAT,...)
ehm field
bignum_st BIGNUM
Definition bigint.hpp:7
#define R
CK_RV ret

◆ operator=() [1/2]

public_key_impl & fc::em::detail::public_key_impl::operator= ( const public_key_impl & pk)

Definition at line 33 of file elliptic_em_impl_pub.cpp.

34 {
35 if (pk._key == nullptr)
36 {
37 free_key();
38 } else if ( _key == nullptr ) {
39 _key = EC_KEY_dup( pk._key );
40 } else {
41 EC_KEY_copy( _key, pk._key );
42 }
43 return *this;
44 }

◆ operator=() [2/2]

public_key_impl & fc::em::detail::public_key_impl::operator= ( public_key_impl && pk)

Definition at line 46 of file elliptic_em_impl_pub.cpp.

47 {
48 if ( this != &pk ) {
49 free_key();
50 _key = pk._key;
51 pk._key = nullptr;
52 }
53 return *this;
54 }

Member Data Documentation

◆ _key [1/2]

EC_KEY* fc::em::detail::public_key_impl::_key = nullptr

Definition at line 27 of file _elliptic_em_impl_pub.hpp.

◆ _key [2/2]

public_key_data fc::em::detail::public_key_impl::_key

Definition at line 52 of file elliptic_em.cpp.


The documentation for this class was generated from the following files: