Skip to content

Commit

Permalink
Merge pull request #687 from zig-lang/sha2
Browse files Browse the repository at this point in the history
Add Sha2 functions
  • Loading branch information
andrewrk committed Jan 14, 2018
2 parents a2315cf + 9be9f1a commit e7e7625
Show file tree
Hide file tree
Showing 5 changed files with 717 additions and 7 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
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
@@ -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
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
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

0 comments on commit e7e7625

Please sign in to comment.