Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ set(ZIG_STD_FILES
"crypto/index.zig"
"crypto/md5.zig"
"crypto/sha1.zig"
"crypto/sha2.zig"
"cstr.zig"
"debug/failing_allocator.zig"
"debug/index.zig"
Expand Down
9 changes: 8 additions & 1 deletion std/crypto/index.zig
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
pub const Sha1 = @import("md5.zig").Sha1;
pub const Md5 = @import("sha1.zig").Md5;
pub const Sha1 = @import("md5.zig").Sha1;

const sha2 = @import("sha2.zig");
pub const Sha224 = sha2.Sha224;
pub const Sha256 = sha2.Sha256;
pub const Sha384 = sha2.Sha384;
pub const Sha512 = sha2.Sha512;

test "crypto" {
_ = @import("md5.zig");
_ = @import("sha1.zig");
_ = @import("sha2.zig");
}
9 changes: 5 additions & 4 deletions std/crypto/md5.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ const endian = @import("../endian.zig");
const debug = @import("../debug/index.zig");

const RoundParam = struct {
a: u32, b: u32, c: u32, d: u32,
k: u32, s: u32, t: u32
a: usize, b: usize, c: usize, d: usize,
k: usize, s: u32, t: u32
};

fn Rp(a: u32, b: u32, c: u32, d: u32, k: u32, s: u5, t: u32) -> RoundParam {
fn Rp(a: usize, b: usize, c: usize, d: usize, k: usize, s: u32, t: u32) -> RoundParam {
return RoundParam { .a = a, .b = b, .c = c, .d = d, .k = k, .s = s, .t = t };
}

Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions std/crypto/sha1.zig
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ const debug = @import("../debug/index.zig");
pub const u160 = @IntType(false, 160);

const RoundParam = struct {
a: u32, b: u32, c: u32, d: u32, e: u32, i: u32,
a: usize, b: usize, c: usize, d: usize, e: usize, i: u32,
};

fn Rp(a: u32, b: u32, c: u32, d: u32, e: u32, i: u32) -> RoundParam {
fn Rp(a: usize, b: usize, c: usize, d: usize, e: usize, i: u32) -> RoundParam {
return RoundParam { .a = a, .b = b, .c = c, .d = d, .e = e, .i = i };
}

Expand Down
Loading