bool bp_pubkey_checklowS(const void *sig_, size_t sig_len) { secp256k1_ecdsa_signature sig; secp256k1_context *ctx = get_secp256k1_context(); if (!ctx) { return false; } if (!ecdsa_signature_parse_der_lax(ctx, &sig, sig_, sig_len)) { return false; } return (!secp256k1_ecdsa_signature_normalize(ctx, NULL, &sig)); }
bool bp_verify(const struct bp_key *key, const void *data, size_t data_len, const void *sig_, size_t sig_len) { if (32 != data_len) { return false; } secp256k1_ecdsa_signature sig; secp256k1_context *ctx = get_secp256k1_context(); if (!ctx) { return false; } if (ecdsa_signature_parse_der_lax(ctx, &sig, sig_, sig_len)) { secp256k1_ecdsa_signature_normalize(ctx, &sig, &sig); return secp256k1_ecdsa_verify(ctx, &sig, data, &key->pubkey); } return false; }
bool parse_signature(ec_signature& out, const der_signature& der_signature, bool strict) { if (der_signature.empty()) return false; bool valid; secp256k1_ecdsa_signature parsed; const auto context = verification.context(); if (strict) valid = secp256k1_ecdsa_signature_parse_der(context, &parsed, der_signature.data(), der_signature.size()) == 1; else valid = ecdsa_signature_parse_der_lax(context, &parsed, der_signature.data(), der_signature.size()) == 1; if (valid) std::copy(std::begin(parsed.data), std::end(parsed.data), out.begin()); return valid; }
void Sec256SignatureEx::Parse(RCSpan cbuf) { if (!ecdsa_signature_parse_der_lax(g_sec256Ctx, &m_sig, cbuf.data(), cbuf.size())) throw CryptoException(make_error_code(ExtErr::Crypto), "Invalid Signature"); secp256k1_ecdsa_signature_normalize(g_sec256Ctx, &m_sig, &m_sig); }