diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2023-04-29 00:19:55 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-29 00:19:55 -0700 |
| commit | d65b42e07caa00dfe2f2fbf221c593ce57882784 (patch) | |
| tree | 7926cbea1499e0affe930bf6d7455dc24adf014e /lib/std/crypto/sha2.zig | |
| parent | fd6200eda6d4fe19c34a59430a88a9ce38d6d7a4 (diff) | |
| parent | fa200ca0cad2705bad40eb723dedf4e3bf11f2ff (diff) | |
| download | zig-d65b42e07caa00dfe2f2fbf221c593ce57882784.tar.gz zig-d65b42e07caa00dfe2f2fbf221c593ce57882784.zip | |
Merge pull request #15481 from ziglang/use-mem-intrinsics
actually use the new memory intrinsics
Diffstat (limited to 'lib/std/crypto/sha2.zig')
| -rw-r--r-- | lib/std/crypto/sha2.zig | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/lib/std/crypto/sha2.zig b/lib/std/crypto/sha2.zig index ad99079852..bd5a7cc5d4 100644 --- a/lib/std/crypto/sha2.zig +++ b/lib/std/crypto/sha2.zig @@ -118,7 +118,7 @@ fn Sha2x32(comptime params: Sha2Params32) type { // Partial buffer exists from previous update. Copy into buffer then hash. if (d.buf_len != 0 and d.buf_len + b.len >= 64) { off += 64 - d.buf_len; - mem.copy(u8, d.buf[d.buf_len..], b[0..off]); + @memcpy(d.buf[d.buf_len..][0..off], b[0..off]); d.round(&d.buf); d.buf_len = 0; @@ -130,7 +130,8 @@ fn Sha2x32(comptime params: Sha2Params32) type { } // Copy any remainder for next pass. - mem.copy(u8, d.buf[d.buf_len..], b[off..]); + const b_slice = b[off..]; + @memcpy(d.buf[d.buf_len..][0..b_slice.len], b_slice); d.buf_len += @intCast(u8, b[off..].len); d.total_len += b.len; @@ -143,7 +144,7 @@ fn Sha2x32(comptime params: Sha2Params32) type { pub fn final(d: *Self, out: *[digest_length]u8) void { // The buffer here will never be completely full. - mem.set(u8, d.buf[d.buf_len..], 0); + @memset(d.buf[d.buf_len..], 0); // Append padding bits. d.buf[d.buf_len] = 0x80; @@ -152,7 +153,7 @@ fn Sha2x32(comptime params: Sha2Params32) type { // > 448 mod 512 so need to add an extra round to wrap around. if (64 - d.buf_len < 8) { d.round(&d.buf); - mem.set(u8, d.buf[0..], 0); + @memset(d.buf[0..], 0); } // Append message length. @@ -609,7 +610,7 @@ fn Sha2x64(comptime params: Sha2Params64) type { // Partial buffer exists from previous update. Copy into buffer then hash. if (d.buf_len != 0 and d.buf_len + b.len >= 128) { off += 128 - d.buf_len; - mem.copy(u8, d.buf[d.buf_len..], b[0..off]); + @memcpy(d.buf[d.buf_len..][0..off], b[0..off]); d.round(&d.buf); d.buf_len = 0; @@ -621,7 +622,8 @@ fn Sha2x64(comptime params: Sha2Params64) type { } // Copy any remainder for next pass. - mem.copy(u8, d.buf[d.buf_len..], b[off..]); + const b_slice = b[off..]; + @memcpy(d.buf[d.buf_len..][0..b_slice.len], b_slice); d.buf_len += @intCast(u8, b[off..].len); d.total_len += b.len; @@ -634,7 +636,7 @@ fn Sha2x64(comptime params: Sha2Params64) type { pub fn final(d: *Self, out: *[digest_length]u8) void { // The buffer here will never be completely full. - mem.set(u8, d.buf[d.buf_len..], 0); + @memset(d.buf[d.buf_len..], 0); // Append padding bits. d.buf[d.buf_len] = 0x80; @@ -643,7 +645,7 @@ fn Sha2x64(comptime params: Sha2Params64) type { // > 896 mod 1024 so need to add an extra round to wrap around. if (128 - d.buf_len < 16) { d.round(d.buf[0..]); - mem.set(u8, d.buf[0..], 0); + @memset(d.buf[0..], 0); } // Append message length. |
