It is a common pattern in this package to accept a h func() hash.Hash argument, call ch := h(), use ch to know the hash type being used and then discard ch without performing any hash. Cumbersome, but it's what it is to be compatible with the upstream boring API. For example from the HKDF implementation:
This process is currently allocating one slice and and calling a cgo function that will not be used at all, which hurts the performance across the board.
This PR refactors how hashes are implemented so that newHashX only initialize what is really necessary to identify the hash algorithm, defering other steps to when it is really needed.
It is a common pattern in this package to accept a
h func() hash.Hash
argument, callch := h()
, usech
to know the hash type being used and then discardch
without performing any hash. Cumbersome, but it's what it is to be compatible with the upstream boring API. For example from the HKDF implementation:This process is currently allocating one slice and and calling a cgo function that will not be used at all, which hurts the performance across the board.
This PR refactors how hashes are implemented so that
newHashX
only initialize what is really necessary to identify the hash algorithm, defering other steps to when it is really needed.While here, fix PBKDF2 benchmarks.