- 6B2389129DEC411D013D754EAEBC169A23F60B2169DC41CCED21248A603CED46DFDC64E016C082A154AF87784049333BE75C91FB08265306A3BDC2BC0AF2E6C5
+ AFE71ADE56FAE65B970FF3DFB3F14EDACEE0AF497AE57E2D2502C9A4B4F49F3336F9D3794B72A87D185B92FC01F1A5077E1CCD63A61AC4FA9C4464C6224FD1E4
bitcoin/src/key.h
(291 . 12)(291 . 46)
32 bool Sign(uint256 hash, std::vector<unsigned char>& vchSig)
33 {
34 vchSig.clear();
35 unsigned char pchSig[10000];
36 unsigned int nSize = 0;
37 if (!ECDSA_sign(0, (unsigned char*)&hash, sizeof(hash), pchSig, &nSize, pkey))
38 ECDSA_SIG *sig = ECDSA_do_sign((unsigned char *) &hash, sizeof(hash), pkey);
39
40 if (sig == NULL)
41 {
42 printf("ERROR, ECDSA_sign failed in key.h:Sign()\n");
43 return false;
44 vchSig.resize(nSize);
45 memcpy(&vchSig[0], pchSig, nSize);
46 }
47
48 BN_CTX *ctx = BN_CTX_new();
49 BN_CTX_start(ctx);
50 const EC_GROUP *group = EC_KEY_get0_group(pkey);
51 BIGNUM *order = BN_CTX_get(ctx);
52 BIGNUM *halforder = BN_CTX_get(ctx);
53 EC_GROUP_get_order(group, order, ctx);
54 BN_rshift1(halforder, order);
55
56 if (fHighS && (BN_cmp(sig->s, halforder) < 0))
57 {
58 // enforce high S values
59 BN_sub(sig->s, order, sig->s);
60 }
61
62 if (fLowS && (BN_cmp(sig->s, halforder) > 0))
63 {
64 // enforce low S values
65 BN_sub(sig->s, order, sig->s);
66 }
67
68 BN_CTX_end(ctx);
69 BN_CTX_free(ctx);
70 unsigned int nSize = ECDSA_size(pkey);
71 vchSig.resize(nSize); // Make sure it is big enough
72 unsigned char *pos = &vchSig[0];
73 nSize = i2d_ECDSA_SIG(sig, &pos);
74 //printf("DEBUG DER R: 0x%s\n", BN_bn2hex(sig->r));
75 //printf("DEBUG DER R: %s\n", BN_bn2dec(sig->r));
76 //printf("DEBUG DER S: 0x%s\n", BN_bn2hex(sig->s));
77 //printf("DEBUG DER S: %s\n", BN_bn2dec(sig->s));
78 ECDSA_SIG_free(sig);
79 vchSig.resize(nSize); // Shrink to fit actual size
80 return true;
81 }
82