Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions c++/paymentrequest-create.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,40 +178,40 @@ bool decode_base58(const string& btcaddress, unsigned char& version, string& has
unsigned char decoded[25];

size_t nBytes = 0;
BIGNUM bn58, bn, bnChar;
BIGNUM *bn58, *bn, *bnChar;
BN_CTX *ctx;

ctx = BN_CTX_new();
BN_init(&bn58);
BN_init(&bn);
BN_init(&bnChar);
bn58 = BN_new();
bn = BN_new();
bnChar = BN_new();

BN_set_word(&bn58, 58);
BN_set_word(&bn, 0);
BN_set_word(bn58, 58);
BN_set_word(bn, 0);

for (unsigned int i = 0; i < btcaddress.length(); i++) {
const char *p1 = strchr(base58_chars, btcaddress[i]);
if (!p1) {
goto out;
}

BN_set_word(&bnChar, p1 - base58_chars);
BN_set_word(bnChar, p1 - base58_chars);

assert(BN_mul(&bn, &bn, &bn58, ctx));
assert(BN_add(&bn, &bn, &bnChar));
assert(BN_mul(bn, bn, bn58, ctx));
assert(BN_add(bn, bn, bnChar));
}

nBytes = BN_num_bytes(&bn);
nBytes = BN_num_bytes(bn);
if (nBytes == 0 || nBytes > 25)
return false;

std::fill(decoded, decoded+25, (unsigned char)0);
BN_bn2bin(&bn, &decoded[25-nBytes]);
BN_bn2bin(bn, &decoded[25-nBytes]);

out:
BN_clear_free(&bn58);
BN_clear_free(&bn);
BN_clear_free(&bnChar);
BN_clear_free(bn58);
BN_clear_free(bn);
BN_clear_free(bnChar);
BN_CTX_free(ctx);

version = decoded[0];
Expand Down
10 changes: 5 additions & 5 deletions c++/paymentrequest-dump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,12 @@ int main(int argc, char **argv) {
request.SerializeToString(&data_to_verify);
request.set_signature(signature);

EVP_MD_CTX ctx;
EVP_MD_CTX* ctx;
EVP_PKEY *pubkey = X509_get_pubkey(signing_cert);
EVP_MD_CTX_init(&ctx);
if (!EVP_VerifyInit_ex(&ctx, digestAlgorithm, NULL) ||
!EVP_VerifyUpdate(&ctx, data_to_verify.data(), data_to_verify.size()) ||
!EVP_VerifyFinal(&ctx, (const unsigned char*)signature.data(), signature.size(), pubkey)) {
ctx = EVP_MD_CTX_new();
if (!EVP_VerifyInit_ex(ctx, digestAlgorithm, NULL) ||
!EVP_VerifyUpdate(ctx, data_to_verify.data(), data_to_verify.size()) ||
!EVP_VerifyFinal(ctx, (const unsigned char*)signature.data(), signature.size(), pubkey)) {

printf("Bad signature, invalid PaymentRequest.\n");
}
Expand Down