| 442 | |
| 443 | |
| 444 | Try<Nothing> verify_rsa_sha256( |
| 445 | const string& message, |
| 446 | const string& signature, |
| 447 | shared_ptr<RSA> public_key) |
| 448 | { |
| 449 | unsigned char hash[SHA256_DIGEST_LENGTH]; |
| 450 | |
| 451 | SHA256( |
| 452 | reinterpret_cast<const unsigned char*>(message.c_str()), |
| 453 | message.size(), |
| 454 | hash); |
| 455 | |
| 456 | int success = RSA_verify( |
| 457 | NID_sha256, |
| 458 | hash, |
| 459 | SHA256_DIGEST_LENGTH, |
| 460 | reinterpret_cast<const unsigned char*>(signature.data()), |
| 461 | signature.size(), |
| 462 | public_key.get()); |
| 463 | |
| 464 | if (success == 0) { |
| 465 | const char* reason = ERR_reason_error_string(ERR_get_error()); |
| 466 | return Error("Failed to verify message signature" + |
| 467 | (reason == nullptr ? "" : ": " + string(reason))); |
| 468 | } |
| 469 | return Nothing(); |
| 470 | } |
| 471 | |
| 472 | } // namespace openssl { |
| 473 | } // namespace network { |