Skip to content

Commit

Permalink
update crypto dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
simonwicky committed Apr 18, 2024
1 parent f1df47c commit 91e82e0
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 21 deletions.
23 changes: 12 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,23 @@ readme = "README.md"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
aes = { version = "0.7.4", features = ["ctr"] }
bs58 = "0.4.0"
x25519-dalek = { version = "2.0.0", features = ["static_secrets", "getrandom"] }
hmac = "0.11.0"
digest = "0.9"
log = "0.4"
aes = "0.8.4"
ctr = "0.9.2"
bs58 = "0.5.1"
x25519-dalek = { version = "2.0.1", features = ["static_secrets", "getrandom"] }
hmac = "0.12.1"
digest = "0.10.7"
log = "0.4.21"
rand = "0.8.5"
rand_distr = "0.4.3"
sha2 = "0.9.1"
hkdf = "0.11.0"
sha2 = "0.10.8"
hkdf = "0.12.4"
lioness = "0.1.2"
arrayref = "0.3.5"
arrayref = "0.3.7"
chacha = "0.3.0"
blake2 = "0.8.0" # cannot be updated due to outdated dependency inside lioness
byteorder = "1.3.2"
subtle = "2.3.0"
byteorder = "1.5.0"
subtle = "2.5.0"


[dev-dependencies]
Expand Down
30 changes: 20 additions & 10 deletions src/crypto/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,19 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use aes::cipher::{NewCipher, StreamCipher};
use aes::Aes128Ctr;
use digest::generic_array::{ArrayLength, GenericArray};
use digest::{BlockInput, FixedOutput, Reset, Update};
use hmac::{crypto_mac, Hmac, Mac, NewMac};
use aes::{
cipher::{KeyIvInit, StreamCipher},
Aes128,
};
use digest::{
block_buffer::Eager,
consts::U256,
core_api::{BlockSizeUser, BufferKindUser, CoreProxy, FixedOutputCore},
generic_array::GenericArray,
typenum::{IsLess, Le, NonZero},
CtOutput, HashMarker,
};
use hmac::{Hmac, Mac};

//type export and aliasing to keep compatibility
pub use x25519_dalek::PublicKey;
Expand All @@ -27,8 +35,9 @@ pub type EphemeralSecret = x25519_dalek::StaticSecret;
pub const STREAM_CIPHER_KEY_SIZE: usize = 16;
pub const STREAM_CIPHER_INIT_VECTOR: [u8; 16] = [0u8; 16];

// Type alias for ease of use so that it would not require explicit import of crypto_mac or Hmac
pub type HmacOutput<D> = crypto_mac::Output<Hmac<D>>;
// Type alias for ease of use
pub type HmacOutput<D> = CtOutput<Hmac<D>>;
type Aes128Ctr = ctr::Ctr64BE<Aes128>;

pub fn generate_pseudorandom_bytes(
// TODO: those should use proper generic arrays to begin with!!
Expand All @@ -50,9 +59,10 @@ pub fn generate_pseudorandom_bytes(
/// Compute keyed hmac
pub fn compute_keyed_hmac<D>(key: &[u8], data: &[u8]) -> HmacOutput<D>
where
D: Update + BlockInput + FixedOutput + Reset + Default + Clone,
D::BlockSize: ArrayLength<u8>,
D::OutputSize: ArrayLength<u8>,
D: CoreProxy,
D::Core: HashMarker + FixedOutputCore + BufferKindUser<BufferKind = Eager> + Default + Clone,
<D::Core as BlockSizeUser>::BlockSize: IsLess<U256>,
Le<<D::Core as BlockSizeUser>::BlockSize, U256>: NonZero,
{
let mut hmac =
Hmac::<D>::new_from_slice(key).expect("HMAC should be able to take key of any size!");
Expand Down

0 comments on commit 91e82e0

Please sign in to comment.