From 6261c1373168b265047db5704d9d0fd5f2e458f2 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 26 Apr 2023 13:57:08 -0700 Subject: update codebase to use `@memset` and `@memcpy` --- lib/std/crypto/ecdsa.zig | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'lib/std/crypto/ecdsa.zig') diff --git a/lib/std/crypto/ecdsa.zig b/lib/std/crypto/ecdsa.zig index 37ae57a7e6..e552af2e26 100644 --- a/lib/std/crypto/ecdsa.zig +++ b/lib/std/crypto/ecdsa.zig @@ -102,8 +102,8 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type { /// Return the raw signature (r, s) in big-endian format. pub fn toBytes(self: Signature) [encoded_length]u8 { var bytes: [encoded_length]u8 = undefined; - mem.copy(u8, bytes[0 .. encoded_length / 2], &self.r); - mem.copy(u8, bytes[encoded_length / 2 ..], &self.s); + @memcpy(bytes[0 .. encoded_length / 2], &self.r); + @memcpy(bytes[encoded_length / 2 ..], &self.s); return bytes; } @@ -325,11 +325,11 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type { fn reduceToScalar(comptime unreduced_len: usize, s: [unreduced_len]u8) Curve.scalar.Scalar { if (unreduced_len >= 48) { var xs = [_]u8{0} ** 64; - mem.copy(u8, xs[xs.len - s.len ..], s[0..]); + @memcpy(xs[xs.len - s.len ..], s[0..]); return Curve.scalar.Scalar.fromBytes64(xs, .Big); } var xs = [_]u8{0} ** 48; - mem.copy(u8, xs[xs.len - s.len ..], s[0..]); + @memcpy(xs[xs.len - s.len ..], s[0..]); return Curve.scalar.Scalar.fromBytes48(xs, .Big); } @@ -345,14 +345,13 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type { const m_x = m[m_v.len + 1 + noise_length ..][0..secret_key.len]; const m_h = m[m.len - h.len ..]; - mem.set(u8, m_v, 0x01); + @memset(m_v, 0x01); m_i.* = 0x00; - if (noise) |n| mem.copy(u8, m_z, &n); - mem.copy(u8, m_x, &secret_key); - mem.copy(u8, m_h, &h); + if (noise) |n| @memcpy(m_z, &n); + @memcpy(m_x, &secret_key); + @memcpy(m_h, &h); Hmac.create(&k, &m, &k); Hmac.create(m_v, m_v, &k); - mem.copy(u8, m_v, m_v); m_i.* = 0x01; Hmac.create(&k, &m, &k); Hmac.create(m_v, m_v, &k); @@ -361,10 +360,9 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type { while (t_off < t.len) : (t_off += m_v.len) { const t_end = @min(t_off + m_v.len, t.len); Hmac.create(m_v, m_v, &k); - std.mem.copy(u8, t[t_off..t_end], m_v[0 .. t_end - t_off]); + @memcpy(t[t_off..t_end], m_v[0 .. t_end - t_off]); } if (Curve.scalar.Scalar.fromBytes(t, .Big)) |s| return s else |_| {} - mem.copy(u8, m_v, m_v); m_i.* = 0x00; Hmac.create(&k, m[0 .. m_v.len + 1], &k); Hmac.create(m_v, m_v, &k); -- cgit v1.2.3