Skip to content

Commit eda11f0

Browse files
committed
cryptoutil: Clean up fixed_time_eq_asm()
1 parent ce25028 commit eda11f0

File tree

1 file changed

+15
-22
lines changed

1 file changed

+15
-22
lines changed

src/rust-crypto/cryptoutil.rs

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
// except according to those terms.
1010

1111
use std;
12-
use std::mem;
1312
use std::num::{One, Zero, CheckedAdd};
1413
use std::slice::bytes::{MutableByteVector, copy_memory};
1514

@@ -126,62 +125,56 @@ pub fn read_u32_be(input: &[u8]) -> u32 {
126125
#[cfg(target_arch = "x86")]
127126
#[cfg(target_arch = "x86_64")]
128127
#[inline(never)]
129-
#[allow(unused_variable)]
130128
#[allow(dead_assignment)]
131129
unsafe fn fixed_time_eq_asm(mut lhsp: *u8, mut rhsp: *u8, mut count: uint) -> bool {
132130
let mut result: u8 = 0;
133-
let mut tmp: u8 = mem::uninitialized();
134131

135132
asm!(
136133
"
137134
fixed_time_eq_loop:
138135
139-
mov ($1), $4
140-
xor ($2), $4
141-
or $4, $0
136+
mov ($1), %cl
137+
xor ($2), %cl
138+
or %cl, $0
142139
143140
inc $1
144141
inc $2
145142
dec $3
146143
jnz fixed_time_eq_loop
147144
"
148-
: "=&r" (result), "=&r" (lhsp), "=&r" (rhsp), "=&r" (count), "=&r" (tmp) // output
149-
: "0" (result), "1" (lhsp), "2" (rhsp), "3" (count) // input
150-
: "cc" // clobbers
151-
: // flags
145+
: "+r" (result), "+r" (lhsp), "+r" (rhsp), "+r" (count) // all input and output
146+
: // input
147+
: "cl", "cc" // clobbers
148+
: "volatile" // flags
152149
);
153150

154151
return result == 0;
155152
}
156153

157154
#[cfg(target_arch = "arm")]
158155
#[inline(never)]
159-
#[allow(unused_variable)]
160156
#[allow(dead_assignment)]
161157
unsafe fn fixed_time_eq_asm(mut lhsp: *u8, mut rhsp: *u8, mut count: uint) -> bool {
162158
let mut result: u8 = 0;
163-
let mut tmp1: u8 = mem::uninitialized();
164-
let mut tmp2: u8 = mem::uninitialized();
165159

166160
asm!(
167161
"
168162
fixed_time_eq_loop:
169163
170-
ldrb $4, [$1]
171-
ldrb $5, [$2]
172-
eor $4, $4, $5
173-
orr $0, $0, $4
164+
ldrb r4, [$1]
165+
ldrb r5, [$2]
166+
eor r4, r4, r5
167+
orr $0, $0, r4
174168
175169
add $1, $1, #1
176170
add $2, $2, #1
177171
subs $3, $3, #1
178172
bne fixed_time_eq_loop
179173
"
180-
// output
181-
: "=&r" (result), "=&r" (lhsp), "=&r" (rhsp), "=&r" (count), "=&r" (tmp1), "=&r" (tmp2)
182-
: "0" (result), "1" (lhsp), "2" (rhsp), "3" (count) // input
183-
: "cc" // clobbers
184-
: // flags
174+
: "+r" (result), "+r" (lhsp), "+r" (rhsp), "+r" (count) // all input and output
175+
: // input
176+
: "r4", "r5", "cc" // clobbers
177+
: "volatile" // flags
185178
);
186179

187180
return result == 0;

0 commit comments

Comments
 (0)