1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#![no_std]
#![deny(missing_docs)]
pub extern crate stream_cipher;
extern crate byteorder;
extern crate salsa20_core;
mod block;
mod cipher;
#[cfg(feature = "xsalsa20")]
mod xsalsa20;
use cipher::Cipher;
use stream_cipher::generic_array::typenum::{U32, U8};
use stream_cipher::generic_array::GenericArray;
use stream_cipher::{LoopError, NewStreamCipher, SyncStreamCipher, SyncStreamCipherSeek};
use salsa20_core::Ctr;
#[cfg(feature = "xsalsa20")]
pub use self::xsalsa20::XSalsa20;
#[derive(Debug)]
pub struct Salsa20(Ctr<Cipher>);
impl NewStreamCipher for Salsa20 {
type KeySize = U32;
type NonceSize = U8;
fn new(key: &GenericArray<u8, Self::KeySize>, iv: &GenericArray<u8, Self::NonceSize>) -> Self {
Salsa20(Ctr::new(Cipher::new(key, iv)))
}
}
impl SyncStreamCipherSeek for Salsa20 {
fn current_pos(&self) -> u64 {
self.0.current_pos()
}
fn seek(&mut self, pos: u64) {
self.0.seek(pos);
}
}
impl SyncStreamCipher for Salsa20 {
fn try_apply_keystream(&mut self, data: &mut [u8]) -> Result<(), LoopError> {
self.0.try_apply_keystream(data)
}
}