projects
/
rust-lightning
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Pass the current time through `ScoreUpDate` methods
[rust-lightning]
/
lightning
/
src
/
util
/
chacha20.rs
diff --git
a/lightning/src/util/chacha20.rs
b/lightning/src/util/chacha20.rs
index f46b344f2ce144c235e40e041743e707570e43a5..865a09fa0401f2d705cf989e9c16d346e7e7f964 100644
(file)
--- a/
lightning/src/util/chacha20.rs
+++ b/
lightning/src/util/chacha20.rs
@@
-21,6
+21,7
@@
mod real_chacha {
struct u32x4(pub u32, pub u32, pub u32, pub u32);
impl ::core::ops::Add for u32x4 {
type Output = u32x4;
struct u32x4(pub u32, pub u32, pub u32, pub u32);
impl ::core::ops::Add for u32x4 {
type Output = u32x4;
+ #[inline]
fn add(self, rhs: u32x4) -> u32x4 {
u32x4(self.0.wrapping_add(rhs.0),
self.1.wrapping_add(rhs.1),
fn add(self, rhs: u32x4) -> u32x4 {
u32x4(self.0.wrapping_add(rhs.0),
self.1.wrapping_add(rhs.1),
@@
-30,6
+31,7
@@
mod real_chacha {
}
impl ::core::ops::Sub for u32x4 {
type Output = u32x4;
}
impl ::core::ops::Sub for u32x4 {
type Output = u32x4;
+ #[inline]
fn sub(self, rhs: u32x4) -> u32x4 {
u32x4(self.0.wrapping_sub(rhs.0),
self.1.wrapping_sub(rhs.1),
fn sub(self, rhs: u32x4) -> u32x4 {
u32x4(self.0.wrapping_sub(rhs.0),
self.1.wrapping_sub(rhs.1),
@@
-39,23
+41,27
@@
mod real_chacha {
}
impl ::core::ops::BitXor for u32x4 {
type Output = u32x4;
}
impl ::core::ops::BitXor for u32x4 {
type Output = u32x4;
+ #[inline]
fn bitxor(self, rhs: u32x4) -> u32x4 {
u32x4(self.0 ^ rhs.0, self.1 ^ rhs.1, self.2 ^ rhs.2, self.3 ^ rhs.3)
}
}
fn bitxor(self, rhs: u32x4) -> u32x4 {
u32x4(self.0 ^ rhs.0, self.1 ^ rhs.1, self.2 ^ rhs.2, self.3 ^ rhs.3)
}
}
- impl ::core::ops::Shr<u
32x4
> for u32x4 {
+ impl ::core::ops::Shr<u
8
> for u32x4 {
type Output = u32x4;
type Output = u32x4;
- fn shr(self, rhs: u32x4) -> u32x4 {
- u32x4(self.0 >> rhs.0, self.1 >> rhs.1, self.2 >> rhs.2, self.3 >> rhs.3)
+ #[inline]
+ fn shr(self, shr: u8) -> u32x4 {
+ u32x4(self.0 >> shr, self.1 >> shr, self.2 >> shr, self.3 >> shr)
}
}
}
}
- impl ::core::ops::Shl<u
32x4
> for u32x4 {
+ impl ::core::ops::Shl<u
8
> for u32x4 {
type Output = u32x4;
type Output = u32x4;
- fn shl(self, rhs: u32x4) -> u32x4 {
- u32x4(self.0 << rhs.0, self.1 << rhs.1, self.2 << rhs.2, self.3 << rhs.3)
+ #[inline]
+ fn shl(self, shl: u8) -> u32x4 {
+ u32x4(self.0 << shl, self.1 << shl, self.2 << shl, self.3 << shl)
}
}
impl u32x4 {
}
}
impl u32x4 {
+ #[inline]
fn from_bytes(bytes: &[u8]) -> Self {
assert_eq!(bytes.len(), 4*4);
Self (
fn from_bytes(bytes: &[u8]) -> Self {
assert_eq!(bytes.len(), 4*4);
Self (
@@
-118,31
+124,25
@@
mod real_chacha {
macro_rules! round{
($state: expr) => {{
$state.a = $state.a + $state.b;
macro_rules! round{
($state: expr) => {{
$state.a = $state.a + $state.b;
- rotate!($state.d, $state.a,
S
16);
+ rotate!($state.d, $state.a, 16);
$state.c = $state.c + $state.d;
$state.c = $state.c + $state.d;
- rotate!($state.b, $state.c,
S
12);
+ rotate!($state.b, $state.c, 12);
$state.a = $state.a + $state.b;
$state.a = $state.a + $state.b;
- rotate!($state.d, $state.a,
S
8);
+ rotate!($state.d, $state.a, 8);
$state.c = $state.c + $state.d;
$state.c = $state.c + $state.d;
- rotate!($state.b, $state.c,
S
7);
+ rotate!($state.b, $state.c, 7);
}}
}
macro_rules! rotate {
}}
}
macro_rules! rotate {
- ($a: expr, $b: expr, $
c:
expr) => {{
+ ($a: expr, $b: expr, $
rot:
expr) => {{
let v = $a ^ $b;
let v = $a ^ $b;
- let r =
S32 - $c
;
+ let r =
32 - $rot
;
let right = v >> r;
let right = v >> r;
- $a = (v << $
c
) ^ right
+ $a = (v << $
rot
) ^ right
}}
}
}}
}
- const S32:u32x4 = u32x4(32, 32, 32, 32);
- const S16:u32x4 = u32x4(16, 16, 16, 16);
- const S12:u32x4 = u32x4(12, 12, 12, 12);
- const S8:u32x4 = u32x4(8, 8, 8, 8);
- const S7:u32x4 = u32x4(7, 7, 7, 7);
-
impl ChaCha20 {
pub fn new(key: &[u8], nonce: &[u8]) -> ChaCha20 {
assert!(key.len() == 16 || key.len() == 32);
impl ChaCha20 {
pub fn new(key: &[u8], nonce: &[u8]) -> ChaCha20 {
assert!(key.len() == 16 || key.len() == 32);