Skip to content

Conversation

@zacstewart
Copy link

Adds a definition of rust_crypto_util_fixed_time_eq_asm for ARMv8. It's exactly the same as for ARMv7, except that it uses ARMv8 names for registers (wN instead of rN).

[Fixes #383]

Adds a definition of rust_crypto_util_fixed_time_eq_asm for ARMv8. It's
exactly the same as for ARMv7, except that it uses ARMv8 names for
registers (wN instead of rN).
@xanecs
Copy link

xanecs commented Mar 1, 2017

I have just tried to compile this with clang but it didn't work.
The section should be

#ifdef __aarch64__
uint32_t rust_crypto_util_fixed_time_eq_asm(uint8_t* lhsp, uint8_t* rhsp, size_t count) {
    if (count == 0) {
        return 1;
    }
    uint8_t result = 0;
    asm(
        " \
            1: \
            \
            ldrb w4, [%1]; \
            ldrb w5, [%2]; \
            eor w4, w4, w5; \
            orr %w0, %w0, w4; \
            \
            add %w1, %w1, #1; \
            add %w2, %w2, #1; \
            subs %w3, %w3, #1; \
            bne 1b; \
        "
        : "+&r" (result), "+&r" (lhsp), "+&r" (rhsp), "+&r" (count) // all input and output
        : // input
        : "w4", "w5", "cc" // clobbers
    );
    
    return result;
}
#endif

this compiled on my test system.

@tungthanhnguyen
Copy link

tungthanhnguyen commented Jul 9, 2017

rust_crypto_util_fixed_time_eq_asm is called in util.rs. I've modified a bit to work with ARMv8. Performance is same to the original assembly code.

pub fn fixed_time_eq(lhs: &[u8], rhs: &[u8]) -> bool {
    if lhs.len() != rhs.len() {
        false
    } else {
        // let count = lhs.len() as libc::size_t;
        // unsafe {
        //     let lhsp = lhs.get_unchecked(0);
        //     let rhsp = rhs.get_unchecked(0);
        //     rust_crypto_util_fixed_time_eq_asm(lhsp, rhsp, count) == 0
        // }
        // Replace with...
        lhs.iter().zip(rhs).all(|(a, b)| a == b)
    }
}

I'm using Rust 1.18

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Symbol rust_crypto_util_fixed_time_eq_asm missing for aarch64 builds

3 participants