179 {
180 try {
183
185 while( true )
186 {
187 ecdsa_sig sig = ECDSA_do_sign((
unsigned char*)&
digest,
sizeof(
digest), my->_key);
188
189 if (sig==nullptr)
191
193
194
195 int nBitsR = BN_num_bits(sig->r);
196 int nBitsS = BN_num_bits(sig->s);
197 if (nBitsR <= 256 && nBitsS <= 256)
198 {
199 int nRecId = -1;
200 EC_KEY* key = EC_KEY_new_by_curve_name( NID_secp256k1 );
202 EC_KEY_set_conv_form( key, POINT_CONVERSION_COMPRESSED );
203 for (int i=0; i<4; i++)
204 {
205 if (detail::public_key_impl::ECDSA_SIG_recover_key_GFp(key, sig, (
unsigned char*)&
digest,
sizeof(
digest), i, 1) == 1)
206 {
207 unsigned char* buffer = (unsigned char*) key_data.begin();
208 i2o_ECPublicKey( key, &buffer );
209 if ( key_data == my_pub_key )
210 {
211 nRecId = i;
212 break;
213 }
214 }
215 }
216 EC_KEY_free( key );
217
218 if (nRecId == -1)
219 {
221 }
222 unsigned char* result = nullptr;
223 auto bytes = i2d_ECDSA_SIG( sig, &result );
224 auto lenR = result[3];
225 auto lenS = result[5+lenR];
226
227 if( lenR != 32 ) { free(result); continue; }
228 if( lenS != 32 ) { free(result); continue; }
229
230
231
232 memcpy( &csig.data[1], &result[4], lenR );
233 memcpy( &csig.data[33], &result[6+lenR], lenS );
234
235
236 free(result);
237
238 csig.data[0] = nRecId+27+4;
239
240
241
242
243
244
245 }
246 return csig;
247 }
249 }
public_key get_public_key() const
public_key_data serialize() const
#define FC_RETHROW_EXCEPTIONS(LOG_LEVEL, FORMAT,...)
Catchs all exception's, std::exceptions, and ... and rethrows them after appending the provided log m...
fc::array< char, 33 > public_key_data
fc::array< unsigned char, 65 > compact_signature
std::vector< char > bytes
memcpy((char *) pInfo->slotDescription, s, l)