Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cipher+digest: migrate to hybrid array; MSRV 1.65 #1358

Merged
merged 3 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions .github/workflows/cipher.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
strategy:
matrix:
rust:
- 1.56.0 # MSRV
- 1.65.0 # MSRV
- stable
target:
- thumbv7em-none-eabi
Expand Down Expand Up @@ -57,7 +57,7 @@ jobs:
strategy:
matrix:
rust:
- 1.56.0 # MSRV
- 1.65.0 # MSRV
- stable
steps:
- uses: actions/checkout@v4
Expand Down
15 changes: 7 additions & 8 deletions .github/workflows/digest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
strategy:
matrix:
rust:
- 1.57.0 # MSRV
- 1.65.0 # MSRV
- stable
target:
- thumbv7em-none-eabi
Expand All @@ -34,21 +34,20 @@ jobs:
with:
toolchain: ${{ matrix.rust }}
targets: ${{ matrix.target }}
# Isolate this crate from workspace which is otherwise MSRV 1.56 due to 2021 edition crates
- run: rm ../Cargo.toml
- run: cargo build --target ${{ matrix.target }}

minimal-versions:
uses: RustCrypto/actions/.github/workflows/minimal-versions.yml@master
with:
working-directory: ${{ github.workflow }}
# TODO(tarcieri): re-enable after next `crypto-common` release
#minimal-versions:
# uses: RustCrypto/actions/.github/workflows/minimal-versions.yml@master
# with:
# working-directory: ${{ github.workflow }}

test:
runs-on: ubuntu-latest
strategy:
matrix:
rust:
- 1.57.0 # MSRV
- 1.65.0 # MSRV
- stable
steps:
- uses: actions/checkout@v4
Expand Down
63 changes: 28 additions & 35 deletions Cargo.lock

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

6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,9 @@ exclude = [
"crypto",
"elliptic-curve"
]

[patch.crates-io]
block-buffer = { git = "https://github.com/RustCrypto/utils.git" }
crypto-common = { path = "crypto-common" }
hybrid-array = { git = "https://github.com/RustCrypto/utils.git" }
inout = { git = "https://github.com/RustCrypto/utils.git" }
8 changes: 4 additions & 4 deletions cipher/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
[package]
name = "cipher"
description = "Traits for describing block ciphers and stream ciphers"
version = "0.4.4"
version = "0.5.0-pre"
authors = ["RustCrypto Developers"]
license = "MIT OR Apache-2.0"
readme = "README.md"
edition = "2021"
rust-version = "1.56"
rust-version = "1.65"
documentation = "https://docs.rs/cipher"
repository = "https://github.com/RustCrypto/traits"
keywords = ["crypto", "block-cipher", "stream-cipher", "trait"]
categories = ["cryptography", "no-std"]

[dependencies]
crypto-common = "0.1.6"
inout = "0.1"
crypto-common = "=0.2.0-pre"
inout = "=0.2.0-pre"

# optional dependencies
blobby = { version = "0.3", optional = true }
Expand Down
4 changes: 2 additions & 2 deletions cipher/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ implementations which use these traits.

## Minimum Supported Rust Version

Rust **1.56** or higher.
Rust **1.65** or higher.

Minimum supported Rust version can be changed in the future, but it will be
done with a minor version bump.
Expand Down Expand Up @@ -48,7 +48,7 @@ dual licensed as above, without any additional terms or conditions.
[docs-image]: https://docs.rs/cipher/badge.svg
[docs-link]: https://docs.rs/cipher/
[license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg
[rustc-image]: https://img.shields.io/badge/rustc-1.41+-blue.svg
[rustc-image]: https://img.shields.io/badge/rustc-1.65+-blue.svg
[chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg
[chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/260050-traits
[build-image]: https://github.com/RustCrypto/traits/workflows/cipher/badge.svg?branch=master&event=push
Expand Down
15 changes: 8 additions & 7 deletions cipher/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@
use crate::{ParBlocks, ParBlocksSizeUser};
#[cfg(all(feature = "block-padding", feature = "alloc"))]
use alloc::{vec, vec::Vec};
use crypto_common::BlockSizes;
#[cfg(feature = "block-padding")]
use inout::{
block_padding::{Padding, UnpadError},
InOutBufReserved, PadError,
};
use inout::{InOut, InOutBuf, NotEqualError};

pub use crypto_common::{generic_array::ArrayLength, typenum::Unsigned, Block, BlockSizeUser};
pub use crypto_common::{array::ArraySize, typenum::Unsigned, Block, BlockSizeUser};

/// Marker trait for block ciphers.
pub trait BlockCipher: BlockSizeUser {}
Expand Down Expand Up @@ -593,31 +594,31 @@ impl<Alg: BlockDecrypt> BlockDecrypt for &Alg {
}

/// Closure used in methods which operate over separate blocks.
struct BlockCtx<'inp, 'out, BS: ArrayLength<u8>> {
struct BlockCtx<'inp, 'out, BS: BlockSizes> {
block: InOut<'inp, 'out, Block<Self>>,
}

impl<'inp, 'out, BS: ArrayLength<u8>> BlockSizeUser for BlockCtx<'inp, 'out, BS> {
impl<'inp, 'out, BS: BlockSizes> BlockSizeUser for BlockCtx<'inp, 'out, BS> {
type BlockSize = BS;
}

impl<'inp, 'out, BS: ArrayLength<u8>> BlockClosure for BlockCtx<'inp, 'out, BS> {
impl<'inp, 'out, BS: BlockSizes> BlockClosure for BlockCtx<'inp, 'out, BS> {
#[inline(always)]
fn call<B: BlockBackend<BlockSize = BS>>(self, backend: &mut B) {
backend.proc_block(self.block);
}
}

/// Closure used in methods which operate over slice of blocks.
struct BlocksCtx<'inp, 'out, BS: ArrayLength<u8>> {
struct BlocksCtx<'inp, 'out, BS: BlockSizes> {
blocks: InOutBuf<'inp, 'out, Block<Self>>,
}

impl<'inp, 'out, BS: ArrayLength<u8>> BlockSizeUser for BlocksCtx<'inp, 'out, BS> {
impl<'inp, 'out, BS: BlockSizes> BlockSizeUser for BlocksCtx<'inp, 'out, BS> {
type BlockSize = BS;
}

impl<'inp, 'out, BS: ArrayLength<u8>> BlockClosure for BlocksCtx<'inp, 'out, BS> {
impl<'inp, 'out, BS: BlockSizes> BlockClosure for BlocksCtx<'inp, 'out, BS> {
#[inline(always)]
fn call<B: BlockBackend<BlockSize = BS>>(self, backend: &mut B) {
if B::ParBlocksSize::USIZE > 1 {
Expand Down
14 changes: 7 additions & 7 deletions cipher/src/dev/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ macro_rules! block_cipher_test {
#[test]
fn $name() {
use cipher::{
blobby::Blob3Iterator, generic_array::GenericArray, typenum::Unsigned,
BlockDecryptMut, BlockEncryptMut, BlockSizeUser, KeyInit,
array::Array, blobby::Blob3Iterator, typenum::Unsigned, BlockDecryptMut,
BlockEncryptMut, BlockSizeUser, KeyInit,
};

fn run_test(key: &[u8], pt: &[u8], ct: &[u8]) -> bool {
let mut state = <$cipher as KeyInit>::new_from_slice(key).unwrap();

let mut block = GenericArray::clone_from_slice(pt);
let mut block = Array::clone_from_slice(pt);
state.encrypt_block_mut(&mut block);
if ct != block.as_slice() {
return false;
Expand Down Expand Up @@ -105,8 +105,8 @@ macro_rules! block_mode_enc_test {
#[test]
fn $name() {
use cipher::{
blobby::Blob4Iterator, generic_array::GenericArray, inout::InOutBuf,
typenum::Unsigned, BlockEncryptMut, BlockSizeUser, KeyIvInit,
array::Array, blobby::Blob4Iterator, inout::InOutBuf, typenum::Unsigned,
BlockEncryptMut, BlockSizeUser, KeyIvInit,
};

fn run_test(key: &[u8], iv: &[u8], pt: &[u8], ct: &[u8]) -> bool {
Expand Down Expand Up @@ -164,8 +164,8 @@ macro_rules! block_mode_dec_test {
#[test]
fn $name() {
use cipher::{
blobby::Blob4Iterator, generic_array::GenericArray, inout::InOutBuf,
typenum::Unsigned, BlockDecryptMut, BlockSizeUser, KeyIvInit,
array::Array, blobby::Blob4Iterator, inout::InOutBuf, typenum::Unsigned,
BlockDecryptMut, BlockSizeUser, KeyIvInit,
};

fn run_test(key: &[u8], iv: &[u8], pt: &[u8], ct: &[u8]) -> bool {
Expand Down
4 changes: 2 additions & 2 deletions cipher/src/dev/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ macro_rules! stream_cipher_test {
($name:ident, $test_name:expr, $cipher:ty $(,)?) => {
#[test]
fn $name() {
use cipher::generic_array::GenericArray;
use cipher::array::Array;
use cipher::{blobby::Blob4Iterator, KeyIvInit, StreamCipher};

let data = include_bytes!(concat!("data/", $test_name, ".blb"));
Expand Down Expand Up @@ -43,7 +43,7 @@ macro_rules! stream_cipher_seek_test {
($name:ident, $cipher:ty) => {
#[test]
fn $name() {
use cipher::generic_array::GenericArray;
use cipher::array::Array;
use cipher::{KeyIvInit, StreamCipher, StreamCipherSeek};

fn get_cipher() -> $cipher {
Expand Down
2 changes: 1 addition & 1 deletion cipher/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ mod stream_wrapper;

pub use crate::{block::*, errors::*, stream::*, stream_core::*, stream_wrapper::*};
pub use crypto_common::{
generic_array,
array,
typenum::{self, consts},
AlgorithmName, Block, InnerIvInit, InvalidLength, Iv, IvSizeUser, Key, KeyInit, KeyIvInit,
KeySizeUser, ParBlocks, ParBlocksSizeUser,
Expand Down
Loading
Loading