finalize pre-hash before initializing a new hash

we only have one hash engine in hardware, and we want to use
hardware hashing at boot to speed things up as much as possible
and reduce code size of the bootloader.

This patch causes the pre-hash to finalize before a new hash
is initialized which folds in all the other key parameters.
This commit is contained in:
bunnie 2024-01-05 16:07:23 +08:00
parent 41b654fe83
commit d88e446a33

View file

@ -189,7 +189,9 @@ impl PublicKey {
D: Digest<OutputSize = U64>,
{
let signature = InternalSignature::try_from(signature)?;
// The prehash needs to be finalized before we create a new hasher instance. We
// only have one hardware hasher available.
let prehash = prehashed_message.finalize();
let mut h: Sha512 = Sha512::default();
let R: EdwardsPoint;
let k: Scalar;
@ -205,7 +207,7 @@ impl PublicKey {
h.update(ctx);
h.update(signature.R.as_bytes());
h.update(self.as_bytes());
h.update(prehashed_message.finalize().as_slice());
h.update(prehash.as_slice());
k = Scalar::from_hash(h);
R = EdwardsPoint::vartime_double_scalar_mul_basepoint(&k, &(minus_A), &signature.s);