Skip to content
Draft
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
59 changes: 35 additions & 24 deletions Cargo.lock

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

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);
}
}
6 changes: 4 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,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