Commit
Author: Mauro D [mauro@stalw.art]
Committer: GitHub [noreply@github.com] Thu, 26 Jan 2023 21:27:08 +0000
Hash: b7b1b4d98a746a3d93a15e76c3020889a95e5786
Timestamp: Thu, 26 Jan 2023 21:27:08 +0000 (1 year ago)

+5 -5 +/-1 browse
Merge pull request #11 from InstantDomain/ed25519-prehashed
Merge pull request #11 from InstantDomain/ed25519-prehashed

Prehash Ed25519 input for verification
1diff --git a/src/common/crypto/ring_impls.rs b/src/common/crypto/ring_impls.rs
2index 7c454b6..284bf1c 100644
3--- a/src/common/crypto/ring_impls.rs
4+++ b/src/common/crypto/ring_impls.rs
5 @@ -120,9 +120,9 @@ impl SigningKey for Ed25519Key {
6 type Hasher = Sha256;
7
8 fn sign(&self, input: impl Writable) -> Result<Vec<u8>> {
9- let mut data = Vec::with_capacity(256);
10+ let mut data = Sha256::hasher();
11 input.write(&mut data);
12- Ok(self.inner.sign(&data).as_ref().to_vec())
13+ Ok(self.inner.sign(data.complete().as_ref()).as_ref().to_vec())
14 }
15
16 fn algorithm(&self) -> Algorithm {
17 @@ -250,10 +250,10 @@ impl VerifyingKey for Ed25519PublicKey {
18 return Err(Error::IncompatibleAlgorithms);
19 }
20
21- let mut data = Vec::with_capacity(256);
22- canonicalization.canonicalize_headers(headers, &mut data);
23+ let mut hasher = Sha256::hasher();
24+ canonicalization.canonicalize_headers(headers, &mut hasher);
25 self.inner
26- .verify(&data, signature)
27+ .verify(hasher.complete().as_ref(), signature)
28 .map_err(|err| Error::CryptoError(err.to_string()))
29 }
30 }