Skip to content

Commit e7e7625

Browse files
authoredJan 14, 2018
Merge pull request #687 from zig-lang/sha2
Add Sha2 functions
·
0.15.20.2.0
2 parents a2315cf + 9be9f1a commit e7e7625

File tree

5 files changed

+717
-7
lines changed

5 files changed

+717
-7
lines changed
 

‎CMakeLists.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@ set(ZIG_STD_FILES
367367
"crypto/index.zig"
368368
"crypto/md5.zig"
369369
"crypto/sha1.zig"
370+
"crypto/sha2.zig"
370371
"cstr.zig"
371372
"debug/failing_allocator.zig"
372373
"debug/index.zig"

‎std/crypto/index.zig‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1-
pub const Sha1 = @import("md5.zig").Sha1;
21
pub const Md5 = @import("sha1.zig").Md5;
2+
pub const Sha1 = @import("md5.zig").Sha1;
3+
4+
const sha2 = @import("sha2.zig");
5+
pub const Sha224 = sha2.Sha224;
6+
pub const Sha256 = sha2.Sha256;
7+
pub const Sha384 = sha2.Sha384;
8+
pub const Sha512 = sha2.Sha512;
39

410
test "crypto" {
511
_ = @import("md5.zig");
612
_ = @import("sha1.zig");
13+
_ = @import("sha2.zig");
714
}

‎std/crypto/md5.zig‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ const endian = @import("../endian.zig");
44
const debug = @import("../debug/index.zig");
55

66
const RoundParam = struct {
7-
a: u32, b: u32, c: u32, d: u32,
8-
k: u32, s: u32, t: u32
7+
a: usize, b: usize, c: usize, d: usize,
8+
k: usize, s: u32, t: u32
99
};
1010

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

@@ -69,7 +69,8 @@ pub const Md5 = struct {
6969
mem.copy(u8, d.buf[d.buf_len..], b[off..]);
7070
d.buf_len += u8(b[off..].len);
7171

72-
d.total_len += b.len;
72+
// Md5 uses the bottom 64-bits for length padding
73+
d.total_len +%= b.len;
7374
}
7475

7576
pub fn final(d: &Self) -> u128 {

‎std/crypto/sha1.zig‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ const debug = @import("../debug/index.zig");
66
pub const u160 = @IntType(false, 160);
77

88
const RoundParam = struct {
9-
a: u32, b: u32, c: u32, d: u32, e: u32, i: u32,
9+
a: usize, b: usize, c: usize, d: usize, e: usize, i: u32,
1010
};
1111

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

‎std/crypto/sha2.zig‎

Lines changed: 701 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.