Browse Source

serial: Remove blake2b_simd references

parazyd 2 years ago
parent
commit
50572d88eb
4 changed files with 4 additions and 123 deletions
  1. 2 2
      Cargo.lock
  2. 0 4
      Cargo.toml
  3. 1 2
      src/serial/Cargo.toml
  4. 1 115
      src/serial/src/types/hash.rs

+ 2 - 2
Cargo.lock

@@ -782,7 +782,8 @@ dependencies = [
 [[package]]
 name = "blake2b_simd"
 version = "1.0.2"
-source = "git+https://github.com/parazyd/blake2_simd?branch=impl-common#035b663023e49606c2d26411a22b222fb64e27eb"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "23285ad32269793932e830392f2fe2f83e26488fd3ec778883a93c8323735780"
 dependencies = [
  "arrayref",
  "arrayvec",
@@ -1811,7 +1812,6 @@ name = "darkfi-serial"
 version = "0.4.1"
 dependencies = [
  "async-trait",
- "blake2b_simd",
  "blake3",
  "bridgetree",
  "darkfi-derive",

+ 0 - 4
Cargo.toml

@@ -319,7 +319,3 @@ zkas = [
 [patch.crates-io]
 halo2_proofs = {git="https://github.com/parazyd/halo2", branch="v4"}
 halo2_gadgets = {git="https://github.com/parazyd/halo2", branch="v4"}
-# arti-client = {git="https://gitlab.torproject.org/tpo/core/arti", rev="029eac8fe7f51e5bbaf65d9c8355cd7504668b9a"}
-# tor-hscrypto = {git="https://gitlab.torproject.org/tpo/core/arti", rev="029eac8fe7f51e5bbaf65d9c8355cd7504668b9a"}
-# tor-error = {git="https://gitlab.torproject.org/tpo/core/arti", rev="029eac8fe7f51e5bbaf65d9c8355cd7504668b9a"}
-blake2b_simd = {git="https://github.com/parazyd/blake2_simd", branch="impl-common"}

+ 1 - 2
src/serial/Cargo.toml

@@ -14,7 +14,6 @@ futures-lite = {version = "2.0.1", optional = true}
 async-trait = {version = "0.1.74", optional = true}
 
 # Supported types for encoding
-blake2b_simd = {version = "1.0.2", optional = true}
 blake3 = {version = "1.5.0", optional = true}
 bridgetree = {version = "0.4.0", optional = true}
 pasta_curves = {version = "0.5.1", optional = true}
@@ -29,4 +28,4 @@ async = ["futures-lite", "async-trait", "darkfi-derive/async"]
 
 collections = []
 crypto = ["collections", "hash", "bridgetree", "pasta_curves"]
-hash = ["blake2b_simd", "blake3"]
+hash = ["blake3"]

+ 1 - 115
src/serial/src/types/hash.rs

@@ -16,7 +16,7 @@
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 
-use std::io::{Error, ErrorKind, Read, Result, Write};
+use std::io::{Read, Result, Write};
 
 #[cfg(feature = "async")]
 use crate::{
@@ -26,88 +26,6 @@ use crate::{
 
 use crate::{Decodable, Encodable, ReadExt, WriteExt};
 
-#[cfg(feature = "blake2b_simd")]
-impl Encodable for blake2b_simd::Hash {
-    fn encode<S: Write>(&self, mut s: S) -> Result<usize> {
-        // The hash can be of variable output length.
-        // We'll support 16, 32, and 64 bytes, otherwise panic.
-        // This means we need 1 byte to tell the length.
-        let len = self.as_bytes().len();
-        if len != 16 && len != 32 && len != 64 {
-            panic!("blake2b serialization supports only 16, 32, or 64 bytes");
-        }
-
-        s.write_u8(len as u8)?;
-        s.write_slice(self.as_bytes())?;
-        Ok(len + 1)
-    }
-}
-
-#[cfg(all(feature = "blake2b_simd", feature = "async"))]
-#[async_trait]
-impl AsyncEncodable for blake2b_simd::Hash {
-    async fn encode_async<S: AsyncWrite + Unpin + Send>(&self, s: &mut S) -> Result<usize> {
-        // The hash can be of variable output length.
-        // We'll support 16, 32 and 64 bytes, otherwise panic.
-        // This means we need 1 byte to tell the length.
-        let len = self.as_bytes().len();
-        if len != 16 && len != 32 && len != 64 {
-            panic!("blake2b serialization supports only 16, 32, or 64 bytes");
-        }
-
-        s.write_u8_async(len as u8).await?;
-        s.write_slice_async(self.as_bytes()).await?;
-        Ok(len)
-    }
-}
-
-#[cfg(feature = "blake2b_simd")]
-impl Decodable for blake2b_simd::Hash {
-    fn decode<D: Read>(mut d: D) -> Result<Self> {
-        let len = d.read_u8()?;
-
-        if len == 16 {
-            let mut bytes = [0u8; 16];
-            d.read_slice(&mut bytes)?;
-            Ok(blake2b_simd::Hash::from(bytes))
-        } else if len == 32 {
-            let mut bytes = [0u8; 32];
-            d.read_slice(&mut bytes)?;
-            Ok(blake2b_simd::Hash::from(bytes))
-        } else if len == 64 {
-            let mut bytes = [0u8; 64];
-            d.read_slice(&mut bytes)?;
-            Ok(blake2b_simd::Hash::from(bytes))
-        } else {
-            Err(Error::new(ErrorKind::Other, "Unsupported blake2b hash length"))
-        }
-    }
-}
-
-#[cfg(all(feature = "blake2b_simd", feature = "async"))]
-#[async_trait]
-impl AsyncDecodable for blake2b_simd::Hash {
-    async fn decode_async<D: AsyncRead + Unpin + Send>(d: &mut D) -> Result<Self> {
-        let len = d.read_u8_async().await?;
-
-        if len == 16 {
-            let mut bytes = [0u8; 16];
-            d.read_slice_async(&mut bytes).await?;
-            Ok(blake2b_simd::Hash::from(bytes))
-        } else if len == 32 {
-            let mut bytes = [0u8; 32];
-            d.read_slice_async(&mut bytes).await?;
-            Ok(blake2b_simd::Hash::from(bytes))
-        } else if len == 64 {
-            let mut bytes = [0u8; 64];
-            d.read_slice_async(&mut bytes).await?;
-            Ok(blake2b_simd::Hash::from(bytes))
-        } else {
-            Err(Error::new(ErrorKind::Other, "Unsupported blake2b hash length"))
-        }
-    }
-}
-
 #[cfg(feature = "blake3")]
 impl Encodable for blake3::Hash {
     fn encode<S: Write>(&self, mut s: S) -> Result<usize> {
@@ -143,35 +61,3 @@ impl AsyncDecodable for blake3::Hash {
         Ok(bytes.into())
     }
 }
-
-#[cfg(test)]
-mod tests {
-    use crate::{deserialize, serialize};
-
-    #[test]
-    fn serialize_deserialize_blake2b() {
-        let hash16 =
-            blake2b_simd::Params::new().hash_length(16).to_state().update(b"foo").finalize();
-        let hash16_ser = serialize(&hash16);
-        assert!(hash16_ser.len() == 17);
-
-        let hash16_de: blake2b_simd::Hash = deserialize(&hash16_ser).unwrap();
-        assert!(hash16 == hash16_de);
-
-        let hash32 =
-            blake2b_simd::Params::new().hash_length(32).to_state().update(b"foo").finalize();
-        let hash32_ser = serialize(&hash32);
-        assert!(hash32_ser.len() == 33);
-
-        let hash32_de: blake2b_simd::Hash = deserialize(&hash32_ser).unwrap();
-        assert!(hash32 == hash32_de);
-
-        let hash64 =
-            blake2b_simd::Params::new().hash_length(64).to_state().update(b"foo").finalize();
-        let hash64_ser = serialize(&hash64);
-        assert!(hash64_ser.len() == 65);
-
-        let hash64_de: blake2b_simd::Hash = deserialize(&hash64_ser).unwrap();
-        assert!(hash64 == hash64_de);
-    }
-}