Skip to content
Merged
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
20 changes: 10 additions & 10 deletions .github/workflows/chacha20.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
strategy:
matrix:
rust:
- 1.41.0 # MSRV
- 1.49.0 # MSRV
- stable
target:
- thumbv7em-none-eabi
Expand All @@ -52,15 +52,15 @@ jobs:
include:
# 32-bit Linux
- target: i686-unknown-linux-gnu
rust: 1.41.0 # MSRV
rust: 1.49.0 # MSRV
deps: sudo apt update && sudo apt install gcc-multilib
- target: i686-unknown-linux-gnu
rust: stable
deps: sudo apt update && sudo apt install gcc-multilib

# 64-bit Linux
- target: x86_64-unknown-linux-gnu
rust: 1.41.0 # MSRV
rust: 1.49.0 # MSRV
- target: x86_64-unknown-linux-gnu
rust: stable
steps:
Expand Down Expand Up @@ -89,15 +89,15 @@ jobs:
include:
# 32-bit Linux
- target: i686-unknown-linux-gnu
rust: 1.41.0 # MSRV
rust: 1.49.0 # MSRV
deps: sudo apt update && sudo apt install gcc-multilib
- target: i686-unknown-linux-gnu
rust: stable
deps: sudo apt update && sudo apt install gcc-multilib

# 64-bit Linux
- target: x86_64-unknown-linux-gnu
rust: 1.41.0 # MSRV
rust: 1.49.0 # MSRV
- target: x86_64-unknown-linux-gnu
rust: stable
steps:
Expand All @@ -117,23 +117,23 @@ jobs:
- run: cargo test --target ${{ matrix.target }} --release --features zeroize
- run: cargo test --target ${{ matrix.target }} --release --all-features

# Tests for the portable software backend
# Tests for the portable software backend (i.e. `force-soft`)
soft:
runs-on: ubuntu-latest
strategy:
matrix:
include:
# 32-bit Linux
- target: i686-unknown-linux-gnu
rust: 1.41.0 # MSRV
rust: 1.49.0 # MSRV
deps: sudo apt update && sudo apt install gcc-multilib
- target: i686-unknown-linux-gnu
rust: stable
deps: sudo apt update && sudo apt install gcc-multilib

# 64-bit Linux
- target: x86_64-unknown-linux-gnu
rust: 1.41.0 # MSRV
rust: 1.49.0 # MSRV
- target: x86_64-unknown-linux-gnu
rust: stable
steps:
Expand All @@ -159,13 +159,13 @@ jobs:
include:
# ARM64
- target: aarch64-unknown-linux-gnu
rust: 1.41.0 # MSRV
rust: 1.49.0 # MSRV
- target: aarch64-unknown-linux-gnu
rust: stable

# PPC32
- target: powerpc-unknown-linux-gnu
rust: 1.41.0 # MSRV
rust: 1.49.0 # MSRV
- target: powerpc-unknown-linux-gnu
rust: stable

Expand Down
8 changes: 5 additions & 3 deletions .github/workflows/workspace.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ jobs:
- uses: actions/checkout@v1
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: 1.41.0 # MSRV
toolchain: 1.49.0 # MSRV (highest in repo)
components: clippy
override: true
profile: minimal
- run: cargo clippy --all -- -D warnings

rustfmt:
Expand All @@ -30,9 +31,10 @@ jobs:
- name: Install stable toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
components: rustfmt
override: true
profile: minimal

- name: Run cargo fmt
uses: actions-rs/cargo@v1
Expand Down
4 changes: 2 additions & 2 deletions chacha20/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ stream cipher itself) are designed to execute in constant time.

## Minimum Supported Rust Version

Rust **1.41** or higher.
Rust **1.49** 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 @@ -94,7 +94,7 @@ dual licensed as above, without any additional terms or conditions.
[docs-image]: https://docs.rs/chacha20/badge.svg
[docs-link]: https://docs.rs/chacha20/
[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.49+-blue.svg
[chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg
[chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/260049-stream-ciphers
[build-image]: https://github.com/RustCrypto/stream-ciphers/workflows/chacha20/badge.svg?branch=master&event=push
Expand Down
21 changes: 11 additions & 10 deletions chacha20/src/backend/autodetect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use crate::{rounds::Rounds, IV_SIZE, KEY_SIZE, BLOCK_SIZE};
use super::{avx2, sse2};
use core::mem::ManuallyDrop;

/// Size of buffers passed to `generate` and `apply_keystream` for this
/// backend, which operates on two blocks in parallel for optimal performance.
Expand All @@ -18,8 +19,8 @@ pub struct Core<R: Rounds> {
}

union Inner<R: Rounds> {
avx2: avx2::Core<R>,
sse2: sse2::Core<R>,
avx2: ManuallyDrop<avx2::Core<R>>,
sse2: ManuallyDrop<sse2::Core<R>>,
}

impl<R: Rounds> Core<R> {
Expand All @@ -31,11 +32,11 @@ impl<R: Rounds> Core<R> {

let inner = if avx2_present {
Inner {
avx2: avx2::Core::new(key, iv),
avx2: ManuallyDrop::new(avx2::Core::new(key, iv)),
}
} else {
Inner {
sse2: sse2::Core::new(key, iv),
sse2: ManuallyDrop::new(sse2::Core::new(key, iv)),
}
};

Expand All @@ -46,9 +47,9 @@ impl<R: Rounds> Core<R> {
#[inline]
pub fn generate(&self, counter: u64, output: &mut [u8]) {
if self.token.get() {
unsafe { self.inner.avx2.generate(counter, output) }
unsafe { (*self.inner.avx2).generate(counter, output) }
} else {
unsafe { self.inner.sse2.generate(counter, output) }
unsafe { (*self.inner.sse2).generate(counter, output) }
}
}

Expand All @@ -57,9 +58,9 @@ impl<R: Rounds> Core<R> {
#[cfg(feature = "cipher")]
pub fn apply_keystream(&self, counter: u64, output: &mut [u8]) {
if self.token.get() {
unsafe { self.inner.avx2.apply_keystream(counter, output) }
unsafe { (*self.inner.avx2).apply_keystream(counter, output) }
} else {
unsafe { self.inner.sse2.apply_keystream(counter, output) }
unsafe { (*self.inner.sse2).apply_keystream(counter, output) }
}
}
}
Expand All @@ -68,11 +69,11 @@ impl<R: Rounds> Clone for Core<R> {
fn clone(&self) -> Self {
let inner = if self.token.get() {
Inner {
avx2: unsafe { self.inner.avx2 },
avx2: ManuallyDrop::new(unsafe { (*self.inner.avx2).clone() }),
}
} else {
Inner {
sse2: unsafe { self.inner.sse2 },
sse2: ManuallyDrop::new(unsafe { (*self.inner.sse2).clone() }),
}
};

Expand Down
2 changes: 1 addition & 1 deletion chacha20/src/backend/avx2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use core::arch::x86_64::*;

/// The ChaCha20 core function (AVX2 accelerated implementation for x86/x86_64)
// TODO(tarcieri): zeroize?
#[derive(Copy, Clone)]
#[derive(Clone)]
pub(crate) struct Core<R: Rounds> {
v0: __m256i,
v1: __m256i,
Expand Down
2 changes: 1 addition & 1 deletion chacha20/src/backend/sse2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use core::arch::x86_64::*;

/// The ChaCha20 core function (SSE2 accelerated implementation for x86/x86_64)
// TODO(tarcieri): zeroize?
#[derive(Copy, Clone)]
#[derive(Clone)]
pub struct Core<R: Rounds> {
v0: __m128i,
v1: __m128i,
Expand Down