From 4db360f1560a13c4101ea257563fa646d0f3b9d7 Mon Sep 17 00:00:00 2001 From: "Y. T. Chung" Date: Tue, 27 Jan 2015 22:51:58 +0800 Subject: [PATCH] use the definition in libsodium --- src/crypto/cipher.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/crypto/cipher.rs b/src/crypto/cipher.rs index 1090eed6..35d142c8 100644 --- a/src/crypto/cipher.rs +++ b/src/crypto/cipher.rs @@ -196,6 +196,8 @@ pub enum CipherType { impl CipherType { pub fn block_size(&self) -> usize { + use libsodium_ffi::{crypto_stream_chacha20_NONCEBYTES, crypto_stream_salsa20_NONCEBYTES}; + match *self { CipherType::Table => 0, @@ -236,12 +238,14 @@ impl CipherType { #[cfg(feature = "cipher-rc4")] CipherType::Rc4Md5 => 16, #[cfg(feature = "cipher-seed-cfb")] CipherType::SeedCfb => 16, - #[cfg(feature = "cipher-chacha20")] CipherType::ChaCha20 => 8, - #[cfg(feature = "cipher-salsa20")] CipherType::Salsa20 => 8, + #[cfg(feature = "cipher-chacha20")] CipherType::ChaCha20 => crypto_stream_chacha20_NONCEBYTES as usize, + #[cfg(feature = "cipher-salsa20")] CipherType::Salsa20 => crypto_stream_salsa20_NONCEBYTES as usize, } } pub fn key_size(&self) -> usize { + use libsodium_ffi::{crypto_stream_chacha20_KEYBYTES, crypto_stream_salsa20_KEYBYTES}; + match *self { CipherType::Table => 0, @@ -282,8 +286,8 @@ impl CipherType { #[cfg(feature = "cipher-rc4")] CipherType::Rc4Md5 => 16, #[cfg(feature = "cipher-seed-cfb")] CipherType::SeedCfb => 16, - #[cfg(feature = "cipher-chacha20")] CipherType::ChaCha20 => 32, - #[cfg(feature = "cipher-salsa20")] CipherType::Salsa20 => 32, + #[cfg(feature = "cipher-chacha20")] CipherType::ChaCha20 => crypto_stream_chacha20_KEYBYTES as usize, + #[cfg(feature = "cipher-salsa20")] CipherType::Salsa20 => crypto_stream_salsa20_KEYBYTES as usize, } }