MCPcopy Create free account
hub / github.com/JeanLucPons/VanitySearch / DecodePrivateKey

Method DecodePrivateKey

SECP256K1.cpp:205–274  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

203}
204
205Int Secp256K1::DecodePrivateKey(char *key,bool *compressed) {
206
207 Int ret;
208 ret.SetInt32(0);
209 std::vector<unsigned char> privKey;
210
211 if(key[0] == '5') {
212
213 // Not compressed
214 DecodeBase58(key,privKey);
215 if(privKey.size() != 37) {
216 printf("Invalid private key, size != 37 (size=%d)!\n",(int)privKey.size());
217 ret.SetInt32(-1);
218 return ret;
219 }
220
221 if(privKey[0] != 0x80) {
222 printf("Invalid private key, wrong prefix !\n");
223 return ret;
224 }
225
226 int count = 31;
227 for(int i = 1; i < 33; i++)
228 ret.SetByte(count--,privKey[i]);
229
230 // Compute checksum
231 unsigned char c[4];
232 sha256_checksum(privKey.data(), 33, c);
233
234 if( c[0]!=privKey[33] || c[1]!=privKey[34] ||
235 c[2]!=privKey[35] || c[3]!=privKey[36] ) {
236 printf("Warning, Invalid private key checksum !\n");
237 }
238
239 *compressed = false;
240 return ret;
241
242 } else if(key[0] == 'K' || key[0] == 'L') {
243
244 // Compressed
245 DecodeBase58(key,privKey);
246 if(privKey.size() != 38) {
247 printf("Invalid private key, size != 38 (size=%d)!\n",(int)privKey.size());
248 ret.SetInt32(-1);
249 return ret;
250 }
251
252 int count = 31;
253 for(int i = 1; i < 33; i++)
254 ret.SetByte(count--,privKey[i]);
255
256 // Compute checksum
257 unsigned char c[4];
258 sha256_checksum(privKey.data(), 34, c);
259
260 if( c[0]!=privKey[34] || c[1]!=privKey[35] ||
261 c[2]!=privKey[36] || c[3]!=privKey[37] ) {
262 printf("Warning, Invalid private key checksum !\n");

Callers 3

CheckAddressFunction · 0.80
reconstructAddFunction · 0.80
mainFunction · 0.80

Calls 4

DecodeBase58Function · 0.85
sha256_checksumFunction · 0.85
SetInt32Method · 0.80
SetByteMethod · 0.80

Tested by

no test coverage detected