zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit ae7bb4ecc03d063acc75058f74fcf43b61b5a358 (tree)
parent fbe7d8c1cbb3fa6a6b080cad97067705cb7da1be
Author: lukechampine <luke.champine@gmail.com>
Date:   Tue,  5 Nov 2019 11:51:16 -0500

chacha20poly1305: verify tag in constant time

Diffstat:
Mlib/std/crypto/chacha20.zig | 10++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/lib/std/crypto/chacha20.zig b/lib/std/crypto/chacha20.zig @@ -503,8 +503,14 @@ pub fn chacha20poly1305Open(dst: []u8, ciphertext: []const u8, data: []const u8, var computedTag: [16]u8 = undefined; mac.final(computedTag[0..]); - // verify mac - if (!mem.eql(u8, polyTag, computedTag[0..])) { + // verify mac in constant time + // TODO: we can't currently guarantee that this will run in constant time. + // See https://github.com/ziglang/zig/issues/1776 + var acc: u8 = 0; + for (computedTag) |_, i| { + acc |= (computedTag[i] ^ polyTag[i]); + } + if (acc != 0) { return false; }