@@ -43,16 +43,16 @@ mod real_chacha {
43
43
u32x4 ( self . 0 ^ rhs. 0 , self . 1 ^ rhs. 1 , self . 2 ^ rhs. 2 , self . 3 ^ rhs. 3 )
44
44
}
45
45
}
46
- impl :: core:: ops:: Shr < u32x4 > for u32x4 {
46
+ impl :: core:: ops:: Shr < u8 > for u32x4 {
47
47
type Output = u32x4 ;
48
- fn shr ( self , rhs : u32x4 ) -> u32x4 {
49
- u32x4 ( self . 0 >> rhs . 0 , self . 1 >> rhs . 1 , self . 2 >> rhs . 2 , self . 3 >> rhs . 3 )
48
+ fn shr ( self , shr : u8 ) -> u32x4 {
49
+ u32x4 ( self . 0 >> shr , self . 1 >> shr , self . 2 >> shr , self . 3 >> shr )
50
50
}
51
51
}
52
- impl :: core:: ops:: Shl < u32x4 > for u32x4 {
52
+ impl :: core:: ops:: Shl < u8 > for u32x4 {
53
53
type Output = u32x4 ;
54
- fn shl ( self , rhs : u32x4 ) -> u32x4 {
55
- u32x4 ( self . 0 << rhs . 0 , self . 1 << rhs . 1 , self . 2 << rhs . 2 , self . 3 << rhs . 3 )
54
+ fn shl ( self , shl : u8 ) -> u32x4 {
55
+ u32x4 ( self . 0 << shl , self . 1 << shl , self . 2 << shl , self . 3 << shl )
56
56
}
57
57
}
58
58
impl u32x4 {
@@ -118,31 +118,25 @@ mod real_chacha {
118
118
macro_rules! round{
119
119
( $state: expr) => { {
120
120
$state. a = $state. a + $state. b;
121
- rotate!( $state. d, $state. a, S16 ) ;
121
+ rotate!( $state. d, $state. a, 16 ) ;
122
122
$state. c = $state. c + $state. d;
123
- rotate!( $state. b, $state. c, S12 ) ;
123
+ rotate!( $state. b, $state. c, 12 ) ;
124
124
$state. a = $state. a + $state. b;
125
- rotate!( $state. d, $state. a, S8 ) ;
125
+ rotate!( $state. d, $state. a, 8 ) ;
126
126
$state. c = $state. c + $state. d;
127
- rotate!( $state. b, $state. c, S7 ) ;
127
+ rotate!( $state. b, $state. c, 7 ) ;
128
128
} }
129
129
}
130
130
131
131
macro_rules! rotate {
132
- ( $a: expr, $b: expr, $c : expr) => { {
132
+ ( $a: expr, $b: expr, $rot : expr) => { {
133
133
let v = $a ^ $b;
134
- let r = S32 - $c ;
134
+ let r = 32 - $rot ;
135
135
let right = v >> r;
136
- $a = ( v << $c ) ^ right
136
+ $a = ( v << $rot ) ^ right
137
137
} }
138
138
}
139
139
140
- const S32 : u32x4 = u32x4 ( 32 , 32 , 32 , 32 ) ;
141
- const S16 : u32x4 = u32x4 ( 16 , 16 , 16 , 16 ) ;
142
- const S12 : u32x4 = u32x4 ( 12 , 12 , 12 , 12 ) ;
143
- const S8 : u32x4 = u32x4 ( 8 , 8 , 8 , 8 ) ;
144
- const S7 : u32x4 = u32x4 ( 7 , 7 , 7 , 7 ) ;
145
-
146
140
impl ChaCha20 {
147
141
pub fn new ( key : & [ u8 ] , nonce : & [ u8 ] ) -> ChaCha20 {
148
142
assert ! ( key. len( ) == 16 || key. len( ) == 32 ) ;
0 commit comments