Skip to content

Commit

Permalink
aes-siv: bump aes crate to v0.8; MSRV 1.56+
Browse files Browse the repository at this point in the history
  • Loading branch information
tarcieri committed Jun 26, 2022
1 parent d93b4e0 commit cff552e
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 62 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/aes-siv.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
strategy:
matrix:
rust:
- 1.51.0 # MSRV
- 1.56.0 # MSRV
- stable
target:
- armv7a-none-eabi
Expand All @@ -43,7 +43,7 @@ jobs:
strategy:
matrix:
rust:
- 1.51.0 # MSRV
- 1.56.0 # MSRV
- stable
steps:
- uses: actions/checkout@v1
Expand Down
52 changes: 42 additions & 10 deletions Cargo.lock

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

16 changes: 9 additions & 7 deletions aes-siv/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "aes-siv"
version = "0.6.2"
version = "0.7.0-pre"
description = """
Pure Rust implementation of the AES-SIV Misuse-Resistant Authenticated
Encryption Cipher (RFC 5297) with optional architecture-specific
Expand All @@ -17,15 +17,17 @@ categories = ["cryptography", "no-std"]

[dependencies]
aead = "0.4"
aes = "0.7"
cipher = "0.3"
cmac = "0.6"
crypto-mac = "0.11"
ctr = "0.8"
aes = "0.8"
cipher = "0.4"
cmac = "0.7"
ctr = "0.9"
dbl = "0.3"
pmac = { version = "0.6", optional = true }
digest = { version = "0.10", features = ["mac"] }
zeroize = { version = "1", default-features = false }

# optional dependencies
pmac = { version = "0.7", optional = true }

[dev-dependencies]
blobby = "0.3"
hex-literal = "0.3"
Expand Down
2 changes: 1 addition & 1 deletion aes-siv/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ dual licensed as above, without any additional terms or conditions.
[docs-image]: https://docs.rs/aes-siv/badge.svg
[docs-link]: https://docs.rs/aes-siv/
[license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg
[rustc-image]: https://img.shields.io/badge/rustc-1.49+-blue.svg
[rustc-image]: https://img.shields.io/badge/rustc-1.56+-blue.svg
[codecov-image]: https://codecov.io/gh/RustCrypto/AEADs/branch/master/graph/badge.svg
[codecov-link]: https://codecov.io/gh/RustCrypto/AEADs
[chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg
Expand Down
37 changes: 18 additions & 19 deletions aes-siv/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,16 @@ use aead::{
AeadCore, AeadInPlace, Buffer, Error, NewAead,
};
use aes::{Aes128, Aes256};
use cipher::{NewCipher, StreamCipher};
use cipher::{BlockCipher, BlockEncryptMut, KeyInit, KeySizeUser};
use cmac::Cmac;
use core::{marker::PhantomData, ops::Add};
use crypto_mac::{Mac, NewMac};
use ctr::Ctr128BE;
use digest::{FixedOutputReset, Mac};

#[cfg(feature = "pmac")]
use pmac::Pmac;

/// Size of an AES-SIV key given a particular cipher
pub type KeySize<C> = <<C as NewCipher>::KeySize as Add>::Output;
pub type KeySize<C> = <<C as KeySizeUser>::KeySize as Add>::Output;

/// AES-SIV keys
pub type Key<KeySize> = GenericArray<u8, KeySize>;
Expand All @@ -119,22 +118,22 @@ pub type Tag = GenericArray<u8, U16>;
/// which accepts a key, nonce, and associated data when encrypting/decrypting.
pub struct SivAead<C, M>
where
C: NewCipher<NonceSize = U16> + StreamCipher,
M: Mac<OutputSize = U16>,
<C as NewCipher>::KeySize: Add,
C: BlockCipher<BlockSize = U16> + BlockEncryptMut + KeyInit + KeySizeUser,
M: Mac<OutputSize = U16> + FixedOutputReset + KeyInit,
<C as KeySizeUser>::KeySize: Add,
KeySize<C>: ArrayLength<u8>,
{
key: GenericArray<u8, KeySize<C>>,
mac: PhantomData<M>, // TODO(tarcieri): include `M` in `KeySize` calculation
}

/// SIV AEAD modes based on CMAC
pub type CmacSivAead<BlockCipher> = SivAead<Ctr128BE<BlockCipher>, Cmac<BlockCipher>>;
pub type CmacSivAead<BlockCipher> = SivAead<BlockCipher, Cmac<BlockCipher>>;

/// SIV AEAD modes based on PMAC
#[cfg(feature = "pmac")]
#[cfg_attr(docsrs, doc(cfg(feature = "pmac")))]
pub type PmacSivAead<BlockCipher> = SivAead<Ctr128BE<BlockCipher>, Pmac<BlockCipher>>;
pub type PmacSivAead<BlockCipher> = SivAead<BlockCipher, Pmac<BlockCipher>>;

/// AES-CMAC-SIV in AEAD mode with 256-bit key size (128-bit security)
pub type Aes128SivAead = CmacSivAead<Aes128>;
Expand All @@ -152,9 +151,9 @@ pub type Aes128PmacSivAead = PmacSivAead<Aes128>;
#[cfg_attr(docsrs, doc(cfg(feature = "pmac")))]
pub type Aes256PmacSivAead = PmacSivAead<Aes256>;

impl<M> NewAead for SivAead<Ctr128BE<Aes128>, M>
impl<M> NewAead for SivAead<Aes128, M>
where
M: Mac<OutputSize = U16>,
M: Mac<OutputSize = U16> + FixedOutputReset + KeyInit,
{
type KeySize = U32;

Expand All @@ -166,9 +165,9 @@ where
}
}

impl<M> NewAead for SivAead<Ctr128BE<Aes256>, M>
impl<M> NewAead for SivAead<Aes256, M>
where
M: Mac<OutputSize = U16>,
M: Mac<OutputSize = U16> + FixedOutputReset + KeyInit,
{
type KeySize = U64;

Expand All @@ -182,9 +181,9 @@ where

impl<C, M> AeadCore for SivAead<C, M>
where
C: NewCipher<NonceSize = U16> + StreamCipher,
M: Mac<OutputSize = U16> + NewMac,
<C as NewCipher>::KeySize: Add,
C: BlockCipher<BlockSize = U16> + BlockEncryptMut + KeyInit + KeySizeUser,
M: Mac<OutputSize = U16> + FixedOutputReset + KeyInit,
<C as KeySizeUser>::KeySize: Add,
KeySize<C>: ArrayLength<u8>,
{
// "If the nonce is random, it SHOULD be at least 128 bits in length"
Expand All @@ -197,9 +196,9 @@ where

impl<C, M> AeadInPlace for SivAead<C, M>
where
C: NewCipher<NonceSize = U16> + StreamCipher,
M: Mac<OutputSize = U16> + NewMac,
<C as NewCipher>::KeySize: Add,
C: BlockCipher<BlockSize = U16> + BlockEncryptMut + KeyInit + KeySizeUser,
M: Mac<OutputSize = U16> + FixedOutputReset + KeyInit,
<C as KeySizeUser>::KeySize: Add,
KeySize<C>: ArrayLength<u8>,
{
fn encrypt_in_place(
Expand Down
Loading

0 comments on commit cff552e

Please sign in to comment.