Commit 9be9f1ad20

Marc Tiehuis <marctiehuis@gmail.com>
2018-01-13 21:58:30
Disable win32 tests for Sha2 + correct lengths
1 parent 1f3ed5c
Changed files (2)
std
std/crypto/md5.zig
@@ -69,7 +69,8 @@ pub const Md5 = struct {
         mem.copy(u8, d.buf[d.buf_len..], b[off..]);
         d.buf_len += u8(b[off..].len);
 
-        d.total_len += b.len;
+        // Md5 uses the bottom 64-bits for length padding
+        d.total_len +%= b.len;
     }
 
     pub fn final(d: &Self) -> u128 {
std/crypto/sha2.zig
@@ -2,6 +2,7 @@ const mem = @import("../mem.zig");
 const math = @import("../math/index.zig");
 const endian = @import("../endian.zig");
 const debug = @import("../debug/index.zig");
+const builtin = @import("builtin");
 
 /////////////////////
 // Sha224 + Sha256
@@ -269,12 +270,22 @@ fn Sha2_32(comptime params: Sha2Params32) -> type { return struct {
 };}
 
 test "sha224 single" {
+    if (builtin.os == builtin.Os.windows and builtin.arch == builtin.Arch.i386) {
+        // https://github.com/zig-lang/zig/issues/537
+        return;
+    }
+
     debug.assert(0xd14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f == Sha224.hash(""));
     debug.assert(0x23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7 == Sha224.hash("abc"));
     debug.assert(0xc97ca9a559850ce97a04a96def6d99a9e0e0e2ab14e6b8df265fc0b3 == Sha224.hash("abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"));
 }
 
 test "sha224 streaming" {
+    if (builtin.os == builtin.Os.windows and builtin.arch == builtin.Arch.i386) {
+        // https://github.com/zig-lang/zig/issues/537
+        return;
+    }
+
     var h = Sha224.init();
 
     debug.assert(0xd14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f == h.final());
@@ -291,12 +302,22 @@ test "sha224 streaming" {
 }
 
 test "sha256 single" {
+    if (builtin.os == builtin.Os.windows and builtin.arch == builtin.Arch.i386) {
+        // https://github.com/zig-lang/zig/issues/537
+        return;
+    }
+
     debug.assert(0xe3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 == Sha256.hash(""));
     debug.assert(0xba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad == Sha256.hash("abc"));
     debug.assert(0xcf5b16a778af8380036ce59e7b0492370b249b11e8f07a51afac45037afee9d1 == Sha256.hash("abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"));
 }
 
 test "sha256 streaming" {
+    if (builtin.os == builtin.Os.windows and builtin.arch == builtin.Arch.i386) {
+        // https://github.com/zig-lang/zig/issues/537
+        return;
+    }
+
     var h = Sha256.init();
 
     debug.assert(0xe3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 == h.final());
@@ -373,7 +394,7 @@ fn Sha2_64(comptime params: Sha2Params64) -> type { return struct {
     // Streaming Cache
     buf: [128]u8,
     buf_len: u8,
-    total_len: u64,
+    total_len: u128,
 
     pub fn init() -> Self {
         var d: Self = undefined;
@@ -600,6 +621,11 @@ fn Sha2_64(comptime params: Sha2Params64) -> type { return struct {
 };}
 
 test "sha384 single" {
+    if (builtin.os == builtin.Os.windows and builtin.arch == builtin.Arch.i386) {
+        // https://github.com/zig-lang/zig/issues/537
+        return;
+    }
+
     const h1 = 0x38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b;
     debug.assert(h1 == Sha384.hash(""));
 
@@ -611,6 +637,11 @@ test "sha384 single" {
 }
 
 test "sha384 streaming" {
+    if (builtin.os == builtin.Os.windows and builtin.arch == builtin.Arch.i386) {
+        // https://github.com/zig-lang/zig/issues/537
+        return;
+    }
+
     var h = Sha384.init();
 
     const h1 = 0x38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b;
@@ -630,6 +661,11 @@ test "sha384 streaming" {
 }
 
 test "sha512 single" {
+    if (builtin.os == builtin.Os.windows and builtin.arch == builtin.Arch.i386) {
+        // https://github.com/zig-lang/zig/issues/537
+        return;
+    }
+
     const h1 = 0xcf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e;
     debug.assert(h1 == Sha512.hash(""));
 
@@ -641,6 +677,11 @@ test "sha512 single" {
 }
 
 test "sha512 streaming" {
+    if (builtin.os == builtin.Os.windows and builtin.arch == builtin.Arch.i386) {
+        // https://github.com/zig-lang/zig/issues/537
+        return;
+    }
+
     var h = Sha512.init();
 
     const h1 = 0xcf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e;