mirror of
https://github.com/matrix-construct/construct
synced 2025-01-14 00:34:18 +01:00
ircd::openssl: Eliminate allocation of hashing ctx for oneshot ctor.
This commit is contained in:
parent
d41096cf15
commit
eb1d1c2482
2 changed files with 24 additions and 8 deletions
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue