diff options
| author | Frank Denis <github@pureftpd.org> | 2020-10-16 19:10:20 +0200 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2020-10-17 18:53:08 -0400 |
| commit | fa17447090500b67c515c023376ab66201f8f088 (patch) | |
| tree | 5521ad832ded1b9c38a24fec0cc02871739bd630 /lib/std/crypto/poly1305.zig | |
| parent | 0011def2b24f63233f2ee24909701f92264c2ef5 (diff) | |
| download | zig-fa17447090500b67c515c023376ab66201f8f088.tar.gz zig-fa17447090500b67c515c023376ab66201f8f088.zip | |
std/crypto: make the whole APIs more consistent
- use `PascalCase` for all types. So, AES256GCM is now Aes256Gcm.
- consistently use `_length` instead of mixing `_size` and `_length` for the
constants we expose
- Use `minimum_key_length` when it represents an actual minimum length.
Otherwise, use `key_length`.
- Require output buffers (for ciphertexts, macs, hashes) to be of the right
size, not at least of that size in some functions, and the exact size elsewhere.
- Use a `_bits` suffix instead of `_length` when a size is represented as a
number of bits to avoid confusion.
- Functions returning a constant-sized slice are now defined as a slice instead
of a pointer + a runtime assertion. This is the case for most hash functions.
- Use `camelCase` for all functions instead of `snake_case`.
No functional changes, but these are breaking API changes.
Diffstat (limited to 'lib/std/crypto/poly1305.zig')
| -rw-r--r-- | lib/std/crypto/poly1305.zig | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/lib/std/crypto/poly1305.zig b/lib/std/crypto/poly1305.zig index c6613f64ba..5b1554b113 100644 --- a/lib/std/crypto/poly1305.zig +++ b/lib/std/crypto/poly1305.zig @@ -7,9 +7,9 @@ const std = @import("../std.zig"); const mem = std.mem; pub const Poly1305 = struct { - pub const block_size: usize = 16; + pub const block_length: usize = 16; pub const mac_length = 16; - pub const minimum_key_length = 32; + pub const key_length = 32; // constant multiplier (from the secret key) r: [3]u64, @@ -20,9 +20,9 @@ pub const Poly1305 = struct { // how many bytes are waiting to be processed in a partial block leftover: usize = 0, // partial block buffer - buf: [block_size]u8 align(16) = undefined, + buf: [block_length]u8 align(16) = undefined, - pub fn init(key: *const [minimum_key_length]u8) Poly1305 { + pub fn init(key: *const [key_length]u8) Poly1305 { const t0 = mem.readIntLittle(u64, key[0..8]); const t1 = mem.readIntLittle(u64, key[8..16]); return Poly1305{ @@ -49,7 +49,7 @@ pub const Poly1305 = struct { const s1 = r1 * (5 << 2); const s2 = r2 * (5 << 2); var i: usize = 0; - while (i + block_size <= m.len) : (i += block_size) { + while (i + block_length <= m.len) : (i += block_length) { // h += m[i] const t0 = mem.readIntLittle(u64, m[i..][0..8]); const t1 = mem.readIntLittle(u64, m[i + 8 ..][0..8]); @@ -84,14 +84,14 @@ pub const Poly1305 = struct { // handle leftover if (st.leftover > 0) { - const want = std.math.min(block_size - st.leftover, mb.len); + const want = std.math.min(block_length - st.leftover, mb.len); const mc = mb[0..want]; for (mc) |x, i| { st.buf[st.leftover + i] = x; } mb = mb[want..]; st.leftover += want; - if (st.leftover < block_size) { + if (st.leftover < block_length) { return; } st.blocks(&st.buf, false); @@ -99,8 +99,8 @@ pub const Poly1305 = struct { } // process full blocks - if (mb.len >= block_size) { - const want = mb.len & ~(block_size - 1); + if (mb.len >= block_length) { + const want = mb.len & ~(block_length - 1); st.blocks(mb[0..want], false); mb = mb[want..]; } @@ -120,7 +120,7 @@ pub const Poly1305 = struct { return; } var i = st.leftover; - while (i < block_size) : (i += 1) { + while (i < block_length) : (i += 1) { st.buf[i] = 0; } st.blocks(&st.buf); @@ -132,7 +132,7 @@ pub const Poly1305 = struct { var i = st.leftover; st.buf[i] = 1; i += 1; - while (i < block_size) : (i += 1) { + while (i < block_length) : (i += 1) { st.buf[i] = 0; } st.blocks(&st.buf, true); @@ -198,7 +198,7 @@ pub const Poly1305 = struct { std.mem.secureZero(u8, @ptrCast([*]u8, st)[0..@sizeOf(Poly1305)]); } - pub fn create(out: *[mac_length]u8, msg: []const u8, key: *const [minimum_key_length]u8) void { + pub fn create(out: *[mac_length]u8, msg: []const u8, key: *const [key_length]u8) void { var st = Poly1305.init(key); st.update(msg); st.final(out); |
