0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-02 18:18:56 +02:00

ircd::openssl: Eliminate allocation of hashing ctx for oneshot ctor.

This commit is contained in:
Jason Volk 2018-04-08 09:45:47 -07:00
parent d41096cf15
commit eb1d1c2482
2 changed files with 24 additions and 8 deletions

View file

@ -98,8 +98,8 @@ final
void finalize(const mutable_buffer &) override;
void update(const const_buffer &) override;
sha256(const mutable_buffer &, const const_buffer &);
sha256(const const_buffer &);
sha256(const mutable_buffer &, const const_buffer &); // note: finalizes
sha256(const const_buffer &); // note: finalizes
sha256();
~sha256() noexcept;
};
@ -127,8 +127,8 @@ final
void finalize(const mutable_buffer &) override;
void update(const const_buffer &) override;
ripemd160(const mutable_buffer &, const const_buffer &);
ripemd160(const const_buffer &);
ripemd160(const mutable_buffer &, const const_buffer &); // note: finalizes
ripemd160(const const_buffer &); // note: finalizes
ripemd160();
~ripemd160() noexcept;
};

View file

@ -1407,11 +1407,19 @@ ircd::crh::sha256::sha256(const const_buffer &in)
update(in);
}
/// One-shot functor. Immediately calls operator().
/// One-shot functor. Immediately calls operator(). NOTE: This hashing context
/// cannot be used again after this ctor. Dynamic allocation of the hashing
/// context is also avoided.
ircd::crh::sha256::sha256(const mutable_buffer &out,
const const_buffer &in)
:sha256{}
{
struct ctx ctx;
this->ctx.reset(&ctx);
const unwind release{[this]
{
this->ctx.release();
}};
operator()(out, in);
}
@ -1501,11 +1509,19 @@ ircd::crh::ripemd160::ripemd160(const const_buffer &in)
update(in);
}
/// One-shot functor. Immediately calls operator().
/// One-shot functor. Immediately calls operator(). NOTE: This hashing context
/// cannot be used again after this ctor. Dynamic allocation of the hashing
/// context is also avoided.
ircd::crh::ripemd160::ripemd160(const mutable_buffer &out,
const const_buffer &in)
:ripemd160{}
{
struct ctx ctx;
this->ctx.reset(&ctx);
const unwind release{[this]
{
this->ctx.release();
}};
operator()(out, in);
}