Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ aead = { version = "0.6", default-features = false }
aes = { version = "0.9", default-features = false }
aes-gcm = { version = "0.11", default-features = false, features = ["aes", "alloc"] }
ccm = { version = "0.6.0-rc.3", default-features = false }
chacha20 = { version = "0.10", default-features = false }
chacha20poly1305 = { version = "0.11", default-features = false }
crypto-common = { version = "0.2", default-features = false }
der = { version = "0.8", default-features = false }
Expand Down
22 changes: 19 additions & 3 deletions src/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use alloc::boxed::Box;
use digest::{Digest, OutputSizeUser};
use paste::paste;
use rustls::crypto::{self, hash};
use sha2::{Sha256, Sha384};
use sha2::{Sha224, Sha256, Sha384, Sha512};

macro_rules! impl_hash {
($name:ident, $ty:ty, $algo:ty) => {
Expand Down Expand Up @@ -56,7 +56,23 @@ macro_rules! impl_hash {
};
}

// impl_hash! {SHA224, Sha224, hash::HashAlgorithm::SHA224}
impl_hash! {SHA224, Sha224, hash::HashAlgorithm::SHA224}
impl_hash! {SHA256, Sha256, hash::HashAlgorithm::SHA256}
impl_hash! {SHA384, Sha384, hash::HashAlgorithm::SHA384}
// impl_hash! {SHA512, Sha512, hash::HashAlgorithm::SHA512}
impl_hash! {SHA512, Sha512, hash::HashAlgorithm::SHA512}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn sha224_and_sha512_providers() {
assert_eq!(SHA224.output_len(), 28);
assert_eq!(SHA224.algorithm(), hash::HashAlgorithm::SHA224);
assert_eq!(SHA224.hash(b"abc").as_ref().len(), 28);

assert_eq!(SHA512.output_len(), 64);
assert_eq!(SHA512.algorithm(), hash::HashAlgorithm::SHA512);
assert_eq!(SHA512.hash(b"abc").as_ref().len(), 64);
}
}
18 changes: 16 additions & 2 deletions src/hmac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crypto_common::OutputSizeUser;
use hmac::{KeyInit, Mac};
use paste::paste;
use rustls::crypto;
use sha2::{Sha256, Sha384};
use sha2::{Sha256, Sha384, Sha512};

macro_rules! impl_hmac {
(
Expand Down Expand Up @@ -53,4 +53,18 @@ macro_rules! impl_hmac {

impl_hmac! {SHA256, Sha256}
impl_hmac! {SHA384, Sha384}
// impl_hmac! {SHA512, Sha512}
impl_hmac! {SHA512, Sha512}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn sha512_hmac_provider() {
assert_eq!(SHA512.hash_output_len(), 64);
let key = SHA512.with_key(b"key");
assert_eq!(key.tag_len(), 64);
let tag = key.sign_concat(b"a", &[], b"b");
assert_eq!(tag.as_ref().len(), 64);
}
}
14 changes: 8 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ pub const TLS13_AES_128_GCM_SHA256: SupportedCipherSuite =
},
hkdf_provider: &rustls::crypto::tls13::HkdfUsingHmac(hmac::SHA256),
aead_alg: &aead::gcm::Tls13Aes128Gcm,
quic: None,
quic: Some(quic::AES_128_GCM),
});

pub const TLS13_AES_256_GCM_SHA384: SupportedCipherSuite =
Expand All @@ -286,7 +286,7 @@ pub const TLS13_AES_256_GCM_SHA384: SupportedCipherSuite =
},
hkdf_provider: &rustls::crypto::tls13::HkdfUsingHmac(hmac::SHA384),
aead_alg: &aead::gcm::Tls13Aes256Gcm,
quic: None,
quic: Some(quic::AES_256_GCM),
});

pub const TLS13_AES_128_CCM_SHA256: SupportedCipherSuite =
Expand All @@ -298,7 +298,7 @@ pub const TLS13_AES_128_CCM_SHA256: SupportedCipherSuite =
},
hkdf_provider: &rustls::crypto::tls13::HkdfUsingHmac(hmac::SHA256),
aead_alg: &aead::ccm::Tls13Aes128Ccm,
quic: None,
quic: Some(quic::AES_128_CCM),
});

pub const TLS13_AES_128_CCM_8_SHA256: SupportedCipherSuite =
Expand Down Expand Up @@ -330,7 +330,7 @@ pub const TLS13_CHACHA20_POLY1305_SHA256: SupportedCipherSuite =
},
hkdf_provider: &rustls::crypto::tls13::HkdfUsingHmac(hmac::SHA256),
aead_alg: &aead::chacha20::Chacha20Poly1305,
quic: None,
quic: Some(quic::CHACHA20_POLY1305),
});

const TLS13_SUITES: &[SupportedCipherSuite] = misc::const_concat_slices!(
Expand All @@ -350,8 +350,10 @@ static ALL_CIPHER_SUITES: &[SupportedCipherSuite] = misc::const_concat_slices!(
);

mod aead;
mod hash;
mod hmac;
/// Hash algorithm providers (SHA-224/256/384/512).
pub mod hash;
/// HMAC providers (SHA-256/384/512).
pub mod hmac;
mod kx;
mod misc;
pub mod quic;
Expand Down
Loading
Loading