Skip to content

Commit e4afea5

Browse files
authored
salsa20: remove the SSE2 backend (#446)
Closes #445
1 parent 61457a5 commit e4afea5

File tree

4 files changed

+32
-209
lines changed

4 files changed

+32
-209
lines changed

salsa20/src/backends.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
11
pub(crate) mod soft;
2-
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
3-
pub(crate) mod sse2;

salsa20/src/backends/sse2.rs

Lines changed: 0 additions & 167 deletions
This file was deleted.

salsa20/src/lib.rs

Lines changed: 4 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,6 @@
7373
html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/media/8f1a9894/logo.svg"
7474
)]
7575
#![warn(missing_docs, rust_2018_idioms, trivial_casts, unused_qualifications)]
76-
77-
use cfg_if::cfg_if;
7876
pub use cipher;
7977

8078
use cipher::{
@@ -178,17 +176,6 @@ impl<R: Unsigned> KeyIvInit for SalsaCore<R> {
178176

179177
state[15] = CONSTANTS[3];
180178

181-
cfg_if! {
182-
if #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] {
183-
state = [
184-
state[0], state[5], state[10], state[15],
185-
state[4], state[9], state[14], state[3],
186-
state[8], state[13], state[2], state[7],
187-
state[12], state[1], state[6], state[11],
188-
];
189-
}
190-
}
191-
192179
Self {
193180
state,
194181
rounds: PhantomData,
@@ -203,15 +190,7 @@ impl<R: Unsigned> StreamCipherCore for SalsaCore<R> {
203190
rem.try_into().ok()
204191
}
205192
fn process_with_backend(&mut self, f: impl StreamCipherClosure<BlockSize = Self::BlockSize>) {
206-
cfg_if! {
207-
if #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] {
208-
unsafe {
209-
backends::sse2::inner::<R, _>(&mut self.state, f);
210-
}
211-
} else {
212-
f.call(&mut backends::soft::Backend(self));
213-
}
214-
}
193+
f.call(&mut backends::soft::Backend(self));
215194
}
216195
}
217196

@@ -220,28 +199,13 @@ impl<R: Unsigned> StreamCipherSeekCore for SalsaCore<R> {
220199

221200
#[inline(always)]
222201
fn get_block_pos(&self) -> u64 {
223-
cfg_if! {
224-
if #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] {
225-
(self.state[8] as u64) + ((self.state[5] as u64) << 32)
226-
}
227-
else {
228-
(self.state[8] as u64) + ((self.state[9] as u64) << 32)
229-
}
230-
}
202+
(self.state[8] as u64) + ((self.state[9] as u64) << 32)
231203
}
232204

233205
#[inline(always)]
234206
fn set_block_pos(&mut self, pos: u64) {
235-
cfg_if! {
236-
if #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] {
237-
self.state[8] = (pos & 0xffff_ffff) as u32;
238-
self.state[5] = ((pos >> 32) & 0xffff_ffff) as u32;
239-
}
240-
else {
241-
self.state[8] = (pos & 0xffff_ffff) as u32;
242-
self.state[9] = ((pos >> 32) & 0xffff_ffff) as u32;
243-
}
244-
}
207+
self.state[8] = (pos & 0xffff_ffff) as u32;
208+
self.state[9] = ((pos >> 32) & 0xffff_ffff) as u32;
245209
}
246210
}
247211

salsa20/tests/mod.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,34 @@ fn xsalsa20_encrypt_hello_world() {
176176
assert_eq!(buf, EXPECTED_XSALSA20_HELLO_WORLD);
177177
}
178178

179+
// Regression test for https://github.com/RustCrypto/stream-ciphers/issues/445
180+
#[test]
181+
fn salsa20_big_offset() {
182+
let mut cipher = Salsa20::new(&KEY1.into(), &IV1.into());
183+
184+
let pos = 1u64 << 40;
185+
186+
let mut buf1 = [0u8; 1000];
187+
cipher.seek(pos - 500);
188+
189+
cipher.write_keystream(&mut buf1);
190+
191+
let cur_pos: u64 = cipher.current_pos();
192+
assert_eq!(cur_pos, pos + 500);
193+
194+
let mut buf2 = [0u8; 1000];
195+
let (buf2l, buf2r) = buf2.split_at_mut(500);
196+
197+
cipher.seek(pos);
198+
cipher.write_keystream(buf2r);
199+
cipher.seek(pos - 500);
200+
cipher.write_keystream(buf2l);
201+
202+
assert_eq!(buf1, buf2);
203+
let cur_pos: u64 = cipher.current_pos();
204+
assert_eq!(cur_pos, pos);
205+
}
206+
179207
#[test]
180208
fn salsa20_regression_2024_03() {
181209
use salsa20::{

0 commit comments

Comments
 (0)