Add support back for SHA-384 DS records
authorMatt Corallo <git@bluematt.me>
Wed, 3 Apr 2024 08:21:37 +0000 (08:21 +0000)
committerMatt Corallo <git@bluematt.me>
Wed, 3 Apr 2024 09:14:24 +0000 (09:14 +0000)
While these are relatively unused, support for SHA-384 was recently
added in `bitcoin_hashes`, which we use here for DS validation.

Cargo.toml
src/crypto/hash.rs
src/validation.rs

index 93a9d80a85ed37491e6baed86f93b57a57b60418..7f8d352e41c5314d4d8d6c9bfd643d270a7e4428 100644 (file)
@@ -22,7 +22,7 @@ build_server = ["tokio", "tokio_crate/rt-multi-thread", "tokio_crate/macros"]
 
 [dependencies]
 ring = { version = "0.17", default-features = false, features = ["alloc"], optional = true }
-bitcoin_hashes = { version = "0.13", default-features = false, optional = true }
+bitcoin_hashes = { version = "0.14", default-features = false, optional = true }
 hex_lit = { version = "0.1", default-features = false, features = ["rust_v_1_46"], optional = true }
 tokio_crate = { package = "tokio", version = "1.0", default-features = false, optional = true }
 
index 8b913de223888192ae62732fc2542890fb622e41..2f86c8982aeec9e815f38589635f6aa54670d1b6 100644 (file)
@@ -5,11 +5,13 @@ use bitcoin_hashes::Hash;
 use bitcoin_hashes::HashEngine as _;
 use bitcoin_hashes::sha1::Hash as Sha1;
 use bitcoin_hashes::sha256::Hash as Sha256;
+use bitcoin_hashes::sha384::Hash as Sha384;
 use bitcoin_hashes::sha512::Hash as Sha512;
 
 pub(crate) enum Hasher {
        Sha1(<Sha1 as Hash>::Engine),
        Sha256(<Sha256 as Hash>::Engine),
+       Sha384(<Sha384 as Hash>::Engine),
        #[allow(unused)]
        Sha512(<Sha512 as Hash>::Engine),
 }
@@ -17,6 +19,7 @@ pub(crate) enum Hasher {
 pub(crate) enum HashResult {
        Sha1(Sha1),
        Sha256(Sha256),
+       Sha384(Sha384),
        Sha512(Sha512),
 }
 
@@ -25,6 +28,7 @@ impl AsRef<[u8]> for HashResult {
                match self {
                        HashResult::Sha1(hash) => hash.as_ref(),
                        HashResult::Sha256(hash) => hash.as_ref(),
+                       HashResult::Sha384(hash) => hash.as_ref(),
                        HashResult::Sha512(hash) => hash.as_ref(),
                }
        }
@@ -33,6 +37,7 @@ impl AsRef<[u8]> for HashResult {
 impl Hasher {
        pub(crate) fn sha1() -> Hasher { Hasher::Sha1(Sha1::engine()) }
        pub(crate) fn sha256() -> Hasher { Hasher::Sha256(Sha256::engine()) }
+       pub(crate) fn sha384() -> Hasher { Hasher::Sha384(Sha384::engine()) }
        #[allow(unused)]
        pub(crate) fn sha512() -> Hasher { Hasher::Sha512(Sha512::engine()) }
 
@@ -40,6 +45,7 @@ impl Hasher {
                match self {
                        Hasher::Sha1(hasher) => hasher.input(buf),
                        Hasher::Sha256(hasher) => hasher.input(buf),
+                       Hasher::Sha384(hasher) => hasher.input(buf),
                        Hasher::Sha512(hasher) => hasher.input(buf),
                }
        }
@@ -48,6 +54,7 @@ impl Hasher {
                match self {
                        Hasher::Sha1(hasher) => HashResult::Sha1(Sha1::from_engine(hasher)),
                        Hasher::Sha256(hasher) => HashResult::Sha256(Sha256::from_engine(hasher)),
+                       Hasher::Sha384(hasher) => HashResult::Sha384(Sha384::from_engine(hasher)),
                        Hasher::Sha512(hasher) => HashResult::Sha512(Sha512::from_engine(hasher)),
                }
        }
index c7f0450586b44cdad8461867fa16b983709bddef..e6b585fd44921c70b3c48a4f4e742f81423186bc 100644 (file)
@@ -202,7 +202,7 @@ where RI: IntoIterator<IntoIter = R>, R: Iterator<Item = &'r RRSig>,
                                let mut ctx = match ds.digest_type {
                                        1 if trust_sha1 => crypto::hash::Hasher::sha1(),
                                        2 => crypto::hash::Hasher::sha256(),
-                                       // TODO: 4 => crypto::hash::Hasher::sha384(),
+                                       4 => crypto::hash::Hasher::sha384(),
                                        _ => continue,
                                };
                                write_name(&mut ctx, &dnskey.name);