diff --git a/include/ircd/m/event/event.h b/include/ircd/m/event/event.h index 618a679f2..81f445194 100644 --- a/include/ircd/m/event/event.h +++ b/include/ircd/m/event/event.h @@ -45,7 +45,6 @@ namespace ircd::m event signatures(const mutable_buffer &, const m::event &); event essential(event, const mutable_buffer &content); - bool verify_sha256b64(const event &, const string_view &); bool verify_hash(const event &, const sha256::buf &); bool verify_hash(const event &); diff --git a/matrix/event.cc b/matrix/event.cc index a8d8a94cc..1d6233a43 100644 --- a/matrix/event.cc +++ b/matrix/event.cc @@ -237,20 +237,7 @@ ircd::m::verify_hash(const event &event) bool ircd::m::verify_hash(const event &event, - const sha256::buf &hash) -{ - static constexpr size_t hashb64sz - { - size_t(sha256::digest_size * 1.34) + 1 - }; - - thread_local char b64buf[hashb64sz]; - return verify_sha256b64(event, b64::encode_unpadded(b64buf, hash)); -} - -bool -ircd::m::verify_sha256b64(const event &event, - const string_view &b64) + const sha256::buf &actual) try { const json::object &object @@ -263,7 +250,14 @@ try object.at("sha256") }; - return hash == b64; + thread_local char buf[32]; + const auto claim + { + b64::decode(buf, hash) + }; + + static_assert(sizeof(buf) == sizeof(actual)); + return memcmp(buf, ircd::data(actual), sizeof(buf)) == 0; } catch(const json::not_found &) {