From aea6175f2fbba7f69aec1b6d6a31398c07c97efc Mon Sep 17 00:00:00 2001 From: Monica Moniot Date: Tue, 15 Aug 2023 18:51:22 -0400 Subject: [PATCH] changed digest order --- src/p384.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/p384.rs b/src/p384.rs index 3c926d4..4a0af87 100644 --- a/src/p384.rs +++ b/src/p384.rs @@ -73,13 +73,14 @@ unsafe impl Sync for P384PublicKey {} fn create_digest(domain: &[u8], data: &[&[u8]]) -> [u8; SHA384_HASH_SIZE] { debug_assert!(domain.len() <= u16::MAX as usize); let mut hasher = SHA384::new(); - if domain.len() > 0 { - hasher.update(&(domain.len() as u16).to_be_bytes()); - hasher.update(domain); - } for msg in data { hasher.update(msg); } + // We hash the domain last to mitigate some of the weaknesses of merkle-damgard. + if domain.len() > 0 { + hasher.update(domain); + hasher.update(&(domain.len() as u16).to_be_bytes()); + } hasher.finish() }