Skip to content

Commit e71aa44

Browse files
committed
Merge pull request #76 from DaGenix/fix-windows
Fix windows
2 parents 5d03c41 + 70b3089 commit e71aa44

File tree

4 files changed

+31
-40
lines changed

4 files changed

+31
-40
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ bin
1919

2020
# Output files
2121
rust-crypto-test
22+
rust-crypto-test.exe
2223
rust-crypto-util
24+
rust-crypto-util.exe
2325

2426
# mvn build files
2527
tools/rust-crypto-tester/target/

rust.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ clean-$$($(1)_rust_crate_name):
5656
@rm -f $$($(1)_rust_crate_out)
5757
@rm -f $$($(1)_rust_crate_main).d
5858
@rm -f $$($(1)_rust_crate_name)-test
59+
@rm -f $$($(1)_rust_crate_name)-test.exe
5960
@rm -f $$($(1)_rust_crate_test).d
6061
@rm -f $$($(1)_rust_crate_dir)/*.o
6162
endif

src/rust-crypto/aesni.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -448,33 +448,33 @@ fn encrypt_block_aseni(rounds: uint, input: &[u8], round_keys: &[u8], output: &m
448448

449449
asm!(
450450
"
451-
/* Copy the data to encrypt to xmm15 */
452-
movdqu ($2), %xmm15
451+
/* Copy the data to encrypt to xmm1 */
452+
movdqu ($2), %xmm1
453453
454454
/* Perform round 0 - the whitening step */
455455
movdqu ($1), %xmm0
456456
add $$0x10, $1
457-
pxor %xmm0, %xmm15
457+
pxor %xmm0, %xmm1
458458
459459
/* Perform all remaining rounds (except the final one) */
460460
enc_round:
461461
movdqu ($1), %xmm0
462462
add $$0x10, $1
463-
aesenc %xmm0, %xmm15
463+
aesenc %xmm0, %xmm1
464464
sub $$0x01, $0
465465
cmp $$0x01, $0
466466
jne enc_round
467467
468468
/* Perform the last round */
469469
movdqu ($1), %xmm0
470-
aesenclast %xmm0, %xmm15
470+
aesenclast %xmm0, %xmm1
471471
472-
/* Finally, move the result from xmm15 to outp */
473-
movdqu %xmm15, ($3)
472+
/* Finally, move the result from xmm1 to outp */
473+
movdqu %xmm1, ($3)
474474
"
475475
: "=r" (rounds), "=r" (round_keysp) // outputs
476476
: "r" (inp), "r" (outp), "0" (rounds), "1" (round_keysp) // inputs
477-
: "xmm0", "xmm15", "memory", "cc" // clobbers
477+
: "xmm0", "xmm1", "memory", "cc" // clobbers
478478
: "volatile" // options
479479
);
480480
}
@@ -491,33 +491,33 @@ fn decrypt_block_aseni(rounds: uint, input: &[u8], round_keys: &[u8], output: &m
491491

492492
asm!(
493493
"
494-
/* Copy the data to decrypt to xmm15 */
495-
movdqu ($2), %xmm15
494+
/* Copy the data to decrypt to xmm1 */
495+
movdqu ($2), %xmm1
496496
497497
/* Perform round 0 - the whitening step */
498498
movdqu ($1), %xmm0
499499
sub $$0x10, $1
500-
pxor %xmm0, %xmm15
500+
pxor %xmm0, %xmm1
501501
502502
/* Perform all remaining rounds (except the final one) */
503503
dec_round:
504504
movdqu ($1), %xmm0
505505
sub $$0x10, $1
506-
aesdec %xmm0, %xmm15
506+
aesdec %xmm0, %xmm1
507507
sub $$0x01, $0
508508
cmp $$0x01, $0
509509
jne dec_round
510510
511511
/* Perform the last round */
512512
movdqu ($1), %xmm0
513-
aesdeclast %xmm0, %xmm15
513+
aesdeclast %xmm0, %xmm1
514514
515-
/* Finally, move the result from xmm15 to outp */
516-
movdqu %xmm15, ($3)
515+
/* Finally, move the result from xmm1 to outp */
516+
movdqu %xmm1, ($3)
517517
"
518518
: "=r" (rounds), "=r" (round_keysp) // outputs
519519
: "r" (inp), "r" (outp), "0" (rounds), "1" (round_keysp) // inputs
520-
: "xmm0", "xmm15", "memory", "cc" // clobbers
520+
: "xmm0", "xmm1", "memory", "cc" // clobbers
521521
: "volatile" // options
522522
);
523523
}

src/rust-crypto/util.rs

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,26 @@
44
// option. This file may not be copied, modified, or distributed
55
// except according to those terms.
66

7-
// This should go in either 'sys' or 'os'
87
#[cfg(target_arch = "x86")]
98
#[cfg(target_arch = "x86_64")]
10-
#[allow(dead_assignment)]
11-
fn cpuid(func: u32) -> (u32, u32, u32, u32) {
12-
let mut a = 0u32;
13-
let mut b = 0u32;
14-
let mut c = 0u32;
15-
let mut d = 0u32;
16-
9+
pub fn supports_aesni() -> bool {
10+
let mut flags: u32;
1711
unsafe {
1812
asm!(
1913
"
20-
mov $4, %eax;
14+
mov $$1, %eax;
2115
cpuid;
22-
mov %eax, $0;
23-
mov %ebx, $1;
24-
mov %ecx, $2;
25-
mov %edx, $3;
16+
mov %ecx, $0;
2617
"
27-
: "=r" (a), "=r" (b), "=r" (c), "=r" (d)
28-
: "r" (func)
29-
: "eax", "ebx", "ecx", "edx"
18+
: "=r" (flags) // output
19+
: // input
20+
: "eax", "ebx", "ecx", "edx" // clobbers
3021
)
22+
// No idea why, but on 32-bit targets, the compiler complains
23+
// about not having enough registers. Adding in this dummy
24+
// section, however, seems to fix it.
25+
asm!("")
3126
}
3227

33-
return (a, b, c, d);
34-
}
35-
36-
#[cfg(target_arch = "x86")]
37-
#[cfg(target_arch = "x86_64")]
38-
pub fn supports_aesni() -> bool {
39-
let (_, _, c, _) = cpuid(1);
40-
return (c & 0x02000000) != 0;
28+
return (flags & 0x02000000) != 0;
4129
}

0 commit comments

Comments
 (0)