# Add mem.timingSafeEql\(\) for constant-time array comparison · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/bd07154242664e9d25ba60333e1a497562aa7c27)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: bd07154242664e9d25ba60333e1a497562aa7c27

Requested commit: bd07154242664e9d25ba60333e1a497562aa7c27

Commit: bd07154242664e9d25ba60333e1a497562aa7c27

Tree: e636fb1dce620013b041a0226509ae0057d4939f

Author: Frank Denis

Committer: Frank Denis

## Message

```
Add mem.timingSafeEql() for constant-time array comparison

This is a trivial implementation that just does a or[xor] loop.

However, this pattern is used by virtually all crypto libraries and
in practice, even without assembly barriers, LLVM never turns it into
code with conditional jumps, even if one of the parameters is constant.

This has been verified to still be the case with LLVM 11.0.0.

```

## Parents

- [03ae77b8b02eef4da09a6b0de12d6fb0192b81d4](https://git.cafe/gitcafe/zig/commit/03ae77b8b02eef4da09a6b0de12d6fb0192b81d4?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/bd07154242664e9d25ba60333e1a497562aa7c27?format=markdown)
