| author | |
| committer | |
| log | f614d94faa3b2a259c3a82cd66f167029f20d224 |
| tree | 1ecaaeda6c54d626ff3898d109c99d30152483fd |
| parent | 1d7861a36e1bcd8f7bfdb53716ef53467704922b |
| signature |
13 files changed, 108 insertions(+), 119 deletions(-)
lib/std/crypto/aes.zig+19-19| ... | ... | @@ -15,10 +15,10 @@ fn rotw(w: u32) u32 { |
| 15 | 15 | |
| 16 | 16 | // Encrypt one block from src into dst, using the expanded key xk. |
| 17 | 17 | fn encryptBlock(xk: []const u32, dst: []u8, src: []const u8) void { |
| 18 | var s0 = mem.readIntSliceBig(u32, src[0..4]); | |
| 19 | var s1 = mem.readIntSliceBig(u32, src[4..8]); | |
| 20 | var s2 = mem.readIntSliceBig(u32, src[8..12]); | |
| 21 | var s3 = mem.readIntSliceBig(u32, src[12..16]); | |
| 18 | var s0 = mem.readIntBig(u32, src[0..4]); | |
| 19 | var s1 = mem.readIntBig(u32, src[4..8]); | |
| 20 | var s2 = mem.readIntBig(u32, src[8..12]); | |
| 21 | var s3 = mem.readIntBig(u32, src[12..16]); | |
| 22 | 22 | |
| 23 | 23 | // First round just XORs input with key. |
| 24 | 24 | s0 ^= xk[0]; |
| ... | ... | @@ -58,18 +58,18 @@ fn encryptBlock(xk: []const u32, dst: []u8, src: []const u8) void { |
| 58 | 58 | s2 ^= xk[k + 2]; |
| 59 | 59 | s3 ^= xk[k + 3]; |
| 60 | 60 | |
| 61 | mem.writeIntSliceBig(u32, dst[0..4], s0); | |
| 62 | mem.writeIntSliceBig(u32, dst[4..8], s1); | |
| 63 | mem.writeIntSliceBig(u32, dst[8..12], s2); | |
| 64 | mem.writeIntSliceBig(u32, dst[12..16], s3); | |
| 61 | mem.writeIntBig(u32, dst[0..4], s0); | |
| 62 | mem.writeIntBig(u32, dst[4..8], s1); | |
| 63 | mem.writeIntBig(u32, dst[8..12], s2); | |
| 64 | mem.writeIntBig(u32, dst[12..16], s3); | |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | // Decrypt one block from src into dst, using the expanded key xk. |
| 68 | 68 | pub fn decryptBlock(xk: []const u32, dst: []u8, src: []const u8) void { |
| 69 | var s0 = mem.readIntSliceBig(u32, src[0..4]); | |
| 70 | var s1 = mem.readIntSliceBig(u32, src[4..8]); | |
| 71 | var s2 = mem.readIntSliceBig(u32, src[8..12]); | |
| 72 | var s3 = mem.readIntSliceBig(u32, src[12..16]); | |
| 69 | var s0 = mem.readIntBig(u32, src[0..4]); | |
| 70 | var s1 = mem.readIntBig(u32, src[4..8]); | |
| 71 | var s2 = mem.readIntBig(u32, src[8..12]); | |
| 72 | var s3 = mem.readIntBig(u32, src[12..16]); | |
| 73 | 73 | |
| 74 | 74 | // First round just XORs input with key. |
| 75 | 75 | s0 ^= xk[0]; |
| ... | ... | @@ -109,10 +109,10 @@ pub fn decryptBlock(xk: []const u32, dst: []u8, src: []const u8) void { |
| 109 | 109 | s2 ^= xk[k + 2]; |
| 110 | 110 | s3 ^= xk[k + 3]; |
| 111 | 111 | |
| 112 | mem.writeIntSliceBig(u32, dst[0..4], s0); | |
| 113 | mem.writeIntSliceBig(u32, dst[4..8], s1); | |
| 114 | mem.writeIntSliceBig(u32, dst[8..12], s2); | |
| 115 | mem.writeIntSliceBig(u32, dst[12..16], s3); | |
| 112 | mem.writeIntBig(u32, dst[0..4], s0); | |
| 113 | mem.writeIntBig(u32, dst[4..8], s1); | |
| 114 | mem.writeIntBig(u32, dst[8..12], s2); | |
| 115 | mem.writeIntBig(u32, dst[12..16], s3); | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | fn xorBytes(dst: []u8, a: []const u8, b: []const u8) usize { |
| ... | ... | @@ -154,8 +154,8 @@ fn AES(comptime keysize: usize) type { |
| 154 | 154 | var n: usize = 0; |
| 155 | 155 | while (n < src.len) { |
| 156 | 156 | ctx.encrypt(keystream[0..], ctrbuf[0..]); |
| 157 | var ctr_i = std.mem.readIntSliceBig(u128, ctrbuf[0..]); | |
| 158 | std.mem.writeIntSliceBig(u128, ctrbuf[0..], ctr_i +% 1); | |
| 157 | var ctr_i = std.mem.readIntBig(u128, ctrbuf[0..]); | |
| 158 | std.mem.writeIntBig(u128, ctrbuf[0..], ctr_i +% 1); | |
| 159 | 159 | |
| 160 | 160 | n += xorBytes(dst[n..], src[n..], &keystream); |
| 161 | 161 | } |
| ... | ... | @@ -251,7 +251,7 @@ fn expandKey(key: []const u8, enc: []u32, dec: []u32) void { |
| 251 | 251 | var i: usize = 0; |
| 252 | 252 | var nk = key.len / 4; |
| 253 | 253 | while (i < nk) : (i += 1) { |
| 254 | enc[i] = mem.readIntSliceBig(u32, key[4 * i .. 4 * i + 4]); | |
| 254 | enc[i] = mem.readIntBig(u32, key[4 * i ..][0..4]); | |
| 255 | 255 | } |
| 256 | 256 | while (i < enc.len) : (i += 1) { |
| 257 | 257 | var t = enc[i - 1]; |
lib/std/crypto/blake2.zig+4-7| ... | ... | @@ -123,8 +123,7 @@ fn Blake2s(comptime out_len: usize) type { |
| 123 | 123 | const rr = d.h[0 .. out_len / 32]; |
| 124 | 124 | |
| 125 | 125 | for (rr) |s, j| { |
| 126 | // TODO https://github.com/ziglang/zig/issues/863 | |
| 127 | mem.writeIntSliceLittle(u32, out[4 * j .. 4 * j + 4], s); | |
| 126 | mem.writeIntLittle(u32, out[4 * j ..][0..4], s); | |
| 128 | 127 | } |
| 129 | 128 | } |
| 130 | 129 | |
| ... | ... | @@ -135,8 +134,7 @@ fn Blake2s(comptime out_len: usize) type { |
| 135 | 134 | var v: [16]u32 = undefined; |
| 136 | 135 | |
| 137 | 136 | for (m) |*r, i| { |
| 138 | // TODO https://github.com/ziglang/zig/issues/863 | |
| 139 | r.* = mem.readIntSliceLittle(u32, b[4 * i .. 4 * i + 4]); | |
| 137 | r.* = mem.readIntLittle(u32, b[4 * i ..][0..4]); | |
| 140 | 138 | } |
| 141 | 139 | |
| 142 | 140 | var k: usize = 0; |
| ... | ... | @@ -358,8 +356,7 @@ fn Blake2b(comptime out_len: usize) type { |
| 358 | 356 | const rr = d.h[0 .. out_len / 64]; |
| 359 | 357 | |
| 360 | 358 | for (rr) |s, j| { |
| 361 | // TODO https://github.com/ziglang/zig/issues/863 | |
| 362 | mem.writeIntSliceLittle(u64, out[8 * j .. 8 * j + 8], s); | |
| 359 | mem.writeIntLittle(u64, out[8 * j ..][0..8], s); | |
| 363 | 360 | } |
| 364 | 361 | } |
| 365 | 362 | |
| ... | ... | @@ -370,7 +367,7 @@ fn Blake2b(comptime out_len: usize) type { |
| 370 | 367 | var v: [16]u64 = undefined; |
| 371 | 368 | |
| 372 | 369 | for (m) |*r, i| { |
| 373 | r.* = mem.readIntSliceLittle(u64, b[8 * i .. 8 * i + 8]); | |
| 370 | r.* = mem.readIntLittle(u64, b[8 * i ..][0..8]); | |
| 374 | 371 | } |
| 375 | 372 | |
| 376 | 373 | var k: usize = 0; |
lib/std/crypto/chacha20.zig+30-31| ... | ... | @@ -61,8 +61,7 @@ fn salsa20_wordtobyte(out: []u8, input: [16]u32) void { |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | for (x) |_, i| { |
| 64 | // TODO https://github.com/ziglang/zig/issues/863 | |
| 65 | mem.writeIntSliceLittle(u32, out[4 * i .. 4 * i + 4], x[i] +% input[i]); | |
| 64 | mem.writeIntLittle(u32, out[4 * i ..][0..4], x[i] +% input[i]); | |
| 66 | 65 | } |
| 67 | 66 | } |
| 68 | 67 | |
| ... | ... | @@ -73,10 +72,10 @@ fn chaCha20_internal(out: []u8, in: []const u8, key: [8]u32, counter: [4]u32) vo |
| 73 | 72 | |
| 74 | 73 | const c = "expand 32-byte k"; |
| 75 | 74 | const constant_le = [_]u32{ |
| 76 | mem.readIntSliceLittle(u32, c[0..4]), | |
| 77 | mem.readIntSliceLittle(u32, c[4..8]), | |
| 78 | mem.readIntSliceLittle(u32, c[8..12]), | |
| 79 | mem.readIntSliceLittle(u32, c[12..16]), | |
| 75 | mem.readIntLittle(u32, c[0..4]), | |
| 76 | mem.readIntLittle(u32, c[4..8]), | |
| 77 | mem.readIntLittle(u32, c[8..12]), | |
| 78 | mem.readIntLittle(u32, c[12..16]), | |
| 80 | 79 | }; |
| 81 | 80 | |
| 82 | 81 | mem.copy(u32, ctx[0..], constant_le[0..4]); |
| ... | ... | @@ -120,19 +119,19 @@ pub fn chaCha20IETF(out: []u8, in: []const u8, counter: u32, key: [32]u8, nonce: |
| 120 | 119 | var k: [8]u32 = undefined; |
| 121 | 120 | var c: [4]u32 = undefined; |
| 122 | 121 | |
| 123 | k[0] = mem.readIntSliceLittle(u32, key[0..4]); | |
| 124 | k[1] = mem.readIntSliceLittle(u32, key[4..8]); | |
| 125 | k[2] = mem.readIntSliceLittle(u32, key[8..12]); | |
| 126 | k[3] = mem.readIntSliceLittle(u32, key[12..16]); | |
| 127 | k[4] = mem.readIntSliceLittle(u32, key[16..20]); | |
| 128 | k[5] = mem.readIntSliceLittle(u32, key[20..24]); | |
| 129 | k[6] = mem.readIntSliceLittle(u32, key[24..28]); | |
| 130 | k[7] = mem.readIntSliceLittle(u32, key[28..32]); | |
| 122 | k[0] = mem.readIntLittle(u32, key[0..4]); | |
| 123 | k[1] = mem.readIntLittle(u32, key[4..8]); | |
| 124 | k[2] = mem.readIntLittle(u32, key[8..12]); | |
| 125 | k[3] = mem.readIntLittle(u32, key[12..16]); | |
| 126 | k[4] = mem.readIntLittle(u32, key[16..20]); | |
| 127 | k[5] = mem.readIntLittle(u32, key[20..24]); | |
| 128 | k[6] = mem.readIntLittle(u32, key[24..28]); | |
| 129 | k[7] = mem.readIntLittle(u32, key[28..32]); | |
| 131 | 130 | |
| 132 | 131 | c[0] = counter; |
| 133 | c[1] = mem.readIntSliceLittle(u32, nonce[0..4]); | |
| 134 | c[2] = mem.readIntSliceLittle(u32, nonce[4..8]); | |
| 135 | c[3] = mem.readIntSliceLittle(u32, nonce[8..12]); | |
| 132 | c[1] = mem.readIntLittle(u32, nonce[0..4]); | |
| 133 | c[2] = mem.readIntLittle(u32, nonce[4..8]); | |
| 134 | c[3] = mem.readIntLittle(u32, nonce[8..12]); | |
| 136 | 135 | chaCha20_internal(out, in, k, c); |
| 137 | 136 | } |
| 138 | 137 | |
| ... | ... | @@ -147,19 +146,19 @@ pub fn chaCha20With64BitNonce(out: []u8, in: []const u8, counter: u64, key: [32] |
| 147 | 146 | var k: [8]u32 = undefined; |
| 148 | 147 | var c: [4]u32 = undefined; |
| 149 | 148 | |
| 150 | k[0] = mem.readIntSliceLittle(u32, key[0..4]); | |
| 151 | k[1] = mem.readIntSliceLittle(u32, key[4..8]); | |
| 152 | k[2] = mem.readIntSliceLittle(u32, key[8..12]); | |
| 153 | k[3] = mem.readIntSliceLittle(u32, key[12..16]); | |
| 154 | k[4] = mem.readIntSliceLittle(u32, key[16..20]); | |
| 155 | k[5] = mem.readIntSliceLittle(u32, key[20..24]); | |
| 156 | k[6] = mem.readIntSliceLittle(u32, key[24..28]); | |
| 157 | k[7] = mem.readIntSliceLittle(u32, key[28..32]); | |
| 149 | k[0] = mem.readIntLittle(u32, key[0..4]); | |
| 150 | k[1] = mem.readIntLittle(u32, key[4..8]); | |
| 151 | k[2] = mem.readIntLittle(u32, key[8..12]); | |
| 152 | k[3] = mem.readIntLittle(u32, key[12..16]); | |
| 153 | k[4] = mem.readIntLittle(u32, key[16..20]); | |
| 154 | k[5] = mem.readIntLittle(u32, key[20..24]); | |
| 155 | k[6] = mem.readIntLittle(u32, key[24..28]); | |
| 156 | k[7] = mem.readIntLittle(u32, key[28..32]); | |
| 158 | 157 | |
| 159 | 158 | c[0] = @truncate(u32, counter); |
| 160 | 159 | c[1] = @truncate(u32, counter >> 32); |
| 161 | c[2] = mem.readIntSliceLittle(u32, nonce[0..4]); | |
| 162 | c[3] = mem.readIntSliceLittle(u32, nonce[4..8]); | |
| 160 | c[2] = mem.readIntLittle(u32, nonce[0..4]); | |
| 161 | c[3] = mem.readIntLittle(u32, nonce[4..8]); | |
| 163 | 162 | |
| 164 | 163 | const block_size = (1 << 6); |
| 165 | 164 | // The full block size is greater than the address space on a 32bit machine |
| ... | ... | @@ -463,8 +462,8 @@ pub fn chacha20poly1305Seal(dst: []u8, plaintext: []const u8, data: []const u8, |
| 463 | 462 | mac.update(zeros[0..padding]); |
| 464 | 463 | } |
| 465 | 464 | var lens: [16]u8 = undefined; |
| 466 | mem.writeIntSliceLittle(u64, lens[0..8], data.len); | |
| 467 | mem.writeIntSliceLittle(u64, lens[8..16], plaintext.len); | |
| 465 | mem.writeIntLittle(u64, lens[0..8], data.len); | |
| 466 | mem.writeIntLittle(u64, lens[8..16], plaintext.len); | |
| 468 | 467 | mac.update(lens[0..]); |
| 469 | 468 | mac.final(dst[plaintext.len..]); |
| 470 | 469 | } |
| ... | ... | @@ -500,8 +499,8 @@ pub fn chacha20poly1305Open(dst: []u8, msgAndTag: []const u8, data: []const u8, |
| 500 | 499 | mac.update(zeros[0..padding]); |
| 501 | 500 | } |
| 502 | 501 | var lens: [16]u8 = undefined; |
| 503 | mem.writeIntSliceLittle(u64, lens[0..8], data.len); | |
| 504 | mem.writeIntSliceLittle(u64, lens[8..16], ciphertext.len); | |
| 502 | mem.writeIntLittle(u64, lens[0..8], data.len); | |
| 503 | mem.writeIntLittle(u64, lens[8..16], ciphertext.len); | |
| 505 | 504 | mac.update(lens[0..]); |
| 506 | 505 | var computedTag: [16]u8 = undefined; |
| 507 | 506 | mac.final(computedTag[0..]); |
lib/std/crypto/md5.zig+1-2| ... | ... | @@ -112,8 +112,7 @@ pub const Md5 = struct { |
| 112 | 112 | d.round(d.buf[0..]); |
| 113 | 113 | |
| 114 | 114 | for (d.s) |s, j| { |
| 115 | // TODO https://github.com/ziglang/zig/issues/863 | |
| 116 | mem.writeIntSliceLittle(u32, out[4 * j .. 4 * j + 4], s); | |
| 115 | mem.writeIntLittle(u32, out[4 * j ..][0..4], s); | |
| 117 | 116 | } |
| 118 | 117 | } |
| 119 | 118 |
lib/std/crypto/poly1305.zig+14-15| ... | ... | @@ -3,11 +3,11 @@ |
| 3 | 3 | // https://monocypher.org/ |
| 4 | 4 | |
| 5 | 5 | const std = @import("../std.zig"); |
| 6 | const builtin = @import("builtin"); | |
| 6 | const builtin = std.builtin; | |
| 7 | 7 | |
| 8 | 8 | const Endian = builtin.Endian; |
| 9 | const readIntSliceLittle = std.mem.readIntSliceLittle; | |
| 10 | const writeIntSliceLittle = std.mem.writeIntSliceLittle; | |
| 9 | const readIntLittle = std.mem.readIntLittle; | |
| 10 | const writeIntLittle = std.mem.writeIntLittle; | |
| 11 | 11 | |
| 12 | 12 | pub const Poly1305 = struct { |
| 13 | 13 | const Self = @This(); |
| ... | ... | @@ -59,19 +59,19 @@ pub const Poly1305 = struct { |
| 59 | 59 | { |
| 60 | 60 | var i: usize = 0; |
| 61 | 61 | while (i < 1) : (i += 1) { |
| 62 | ctx.r[0] = readIntSliceLittle(u32, key[0..4]) & 0x0fffffff; | |
| 62 | ctx.r[0] = readIntLittle(u32, key[0..4]) & 0x0fffffff; | |
| 63 | 63 | } |
| 64 | 64 | } |
| 65 | 65 | { |
| 66 | 66 | var i: usize = 1; |
| 67 | 67 | while (i < 4) : (i += 1) { |
| 68 | ctx.r[i] = readIntSliceLittle(u32, key[i * 4 .. i * 4 + 4]) & 0x0ffffffc; | |
| 68 | ctx.r[i] = readIntLittle(u32, key[i * 4 ..][0..4]) & 0x0ffffffc; | |
| 69 | 69 | } |
| 70 | 70 | } |
| 71 | 71 | { |
| 72 | 72 | var i: usize = 0; |
| 73 | 73 | while (i < 4) : (i += 1) { |
| 74 | ctx.pad[i] = readIntSliceLittle(u32, key[i * 4 + 16 .. i * 4 + 16 + 4]); | |
| 74 | ctx.pad[i] = readIntLittle(u32, key[i * 4 + 16 ..][0..4]); | |
| 75 | 75 | } |
| 76 | 76 | } |
| 77 | 77 | |
| ... | ... | @@ -168,10 +168,10 @@ pub const Poly1305 = struct { |
| 168 | 168 | const nb_blocks = nmsg.len >> 4; |
| 169 | 169 | var i: usize = 0; |
| 170 | 170 | while (i < nb_blocks) : (i += 1) { |
| 171 | ctx.c[0] = readIntSliceLittle(u32, nmsg[0..4]); | |
| 172 | ctx.c[1] = readIntSliceLittle(u32, nmsg[4..8]); | |
| 173 | ctx.c[2] = readIntSliceLittle(u32, nmsg[8..12]); | |
| 174 | ctx.c[3] = readIntSliceLittle(u32, nmsg[12..16]); | |
| 171 | ctx.c[0] = readIntLittle(u32, nmsg[0..4]); | |
| 172 | ctx.c[1] = readIntLittle(u32, nmsg[4..8]); | |
| 173 | ctx.c[2] = readIntLittle(u32, nmsg[8..12]); | |
| 174 | ctx.c[3] = readIntLittle(u32, nmsg[12..16]); | |
| 175 | 175 | polyBlock(ctx); |
| 176 | 176 | nmsg = nmsg[16..]; |
| 177 | 177 | } |
| ... | ... | @@ -210,11 +210,10 @@ pub const Poly1305 = struct { |
| 210 | 210 | const uu2 = (uu1 >> 32) + ctx.h[2] + ctx.pad[2]; // <= 2_00000000 |
| 211 | 211 | const uu3 = (uu2 >> 32) + ctx.h[3] + ctx.pad[3]; // <= 2_00000000 |
| 212 | 212 | |
| 213 | // TODO https://github.com/ziglang/zig/issues/863 | |
| 214 | writeIntSliceLittle(u32, out[0..], @truncate(u32, uu0)); | |
| 215 | writeIntSliceLittle(u32, out[4..], @truncate(u32, uu1)); | |
| 216 | writeIntSliceLittle(u32, out[8..], @truncate(u32, uu2)); | |
| 217 | writeIntSliceLittle(u32, out[12..], @truncate(u32, uu3)); | |
| 213 | writeIntLittle(u32, out[0..4], @truncate(u32, uu0)); | |
| 214 | writeIntLittle(u32, out[4..8], @truncate(u32, uu1)); | |
| 215 | writeIntLittle(u32, out[8..12], @truncate(u32, uu2)); | |
| 216 | writeIntLittle(u32, out[12..16], @truncate(u32, uu3)); | |
| 218 | 217 | |
| 219 | 218 | ctx.secureZero(); |
| 220 | 219 | } |
lib/std/crypto/sha1.zig+1-2| ... | ... | @@ -109,8 +109,7 @@ pub const Sha1 = struct { |
| 109 | 109 | d.round(d.buf[0..]); |
| 110 | 110 | |
| 111 | 111 | for (d.s) |s, j| { |
| 112 | // TODO https://github.com/ziglang/zig/issues/863 | |
| 113 | mem.writeIntSliceBig(u32, out[4 * j .. 4 * j + 4], s); | |
| 112 | mem.writeIntBig(u32, out[4 * j ..][0..4], s); | |
| 114 | 113 | } |
| 115 | 114 | } |
| 116 | 115 |
lib/std/crypto/sha3.zig+2-3| ... | ... | @@ -120,7 +120,7 @@ fn keccak_f(comptime F: usize, d: []u8) void { |
| 120 | 120 | var c = [_]u64{0} ** 5; |
| 121 | 121 | |
| 122 | 122 | for (s) |*r, i| { |
| 123 | r.* = mem.readIntSliceLittle(u64, d[8 * i .. 8 * i + 8]); | |
| 123 | r.* = mem.readIntLittle(u64, d[8 * i ..][0..8]); | |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | comptime var x: usize = 0; |
| ... | ... | @@ -167,8 +167,7 @@ fn keccak_f(comptime F: usize, d: []u8) void { |
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | for (s) |r, i| { |
| 170 | // TODO https://github.com/ziglang/zig/issues/863 | |
| 171 | mem.writeIntSliceLittle(u64, d[8 * i .. 8 * i + 8], r); | |
| 170 | mem.writeIntLittle(u64, d[8 * i ..][0..8], r); | |
| 172 | 171 | } |
| 173 | 172 | } |
| 174 | 173 |
lib/std/crypto/x25519.zig+20-21| ... | ... | @@ -7,8 +7,8 @@ const builtin = @import("builtin"); |
| 7 | 7 | const fmt = std.fmt; |
| 8 | 8 | |
| 9 | 9 | const Endian = builtin.Endian; |
| 10 | const readIntSliceLittle = std.mem.readIntSliceLittle; | |
| 11 | const writeIntSliceLittle = std.mem.writeIntSliceLittle; | |
| 10 | const readIntLittle = std.mem.readIntLittle; | |
| 11 | const writeIntLittle = std.mem.writeIntLittle; | |
| 12 | 12 | |
| 13 | 13 | // Based on Supercop's ref10 implementation. |
| 14 | 14 | pub const X25519 = struct { |
| ... | ... | @@ -255,16 +255,16 @@ const Fe = struct { |
| 255 | 255 | |
| 256 | 256 | var t: [10]i64 = undefined; |
| 257 | 257 | |
| 258 | t[0] = readIntSliceLittle(u32, s[0..4]); | |
| 259 | t[1] = @as(u32, readIntSliceLittle(u24, s[4..7])) << 6; | |
| 260 | t[2] = @as(u32, readIntSliceLittle(u24, s[7..10])) << 5; | |
| 261 | t[3] = @as(u32, readIntSliceLittle(u24, s[10..13])) << 3; | |
| 262 | t[4] = @as(u32, readIntSliceLittle(u24, s[13..16])) << 2; | |
| 263 | t[5] = readIntSliceLittle(u32, s[16..20]); | |
| 264 | t[6] = @as(u32, readIntSliceLittle(u24, s[20..23])) << 7; | |
| 265 | t[7] = @as(u32, readIntSliceLittle(u24, s[23..26])) << 5; | |
| 266 | t[8] = @as(u32, readIntSliceLittle(u24, s[26..29])) << 4; | |
| 267 | t[9] = (@as(u32, readIntSliceLittle(u24, s[29..32])) & 0x7fffff) << 2; | |
| 258 | t[0] = readIntLittle(u32, s[0..4]); | |
| 259 | t[1] = @as(u32, readIntLittle(u24, s[4..7])) << 6; | |
| 260 | t[2] = @as(u32, readIntLittle(u24, s[7..10])) << 5; | |
| 261 | t[3] = @as(u32, readIntLittle(u24, s[10..13])) << 3; | |
| 262 | t[4] = @as(u32, readIntLittle(u24, s[13..16])) << 2; | |
| 263 | t[5] = readIntLittle(u32, s[16..20]); | |
| 264 | t[6] = @as(u32, readIntLittle(u24, s[20..23])) << 7; | |
| 265 | t[7] = @as(u32, readIntLittle(u24, s[23..26])) << 5; | |
| 266 | t[8] = @as(u32, readIntLittle(u24, s[26..29])) << 4; | |
| 267 | t[9] = (@as(u32, readIntLittle(u24, s[29..32])) & 0x7fffff) << 2; | |
| 268 | 268 | |
| 269 | 269 | carry1(h, t[0..]); |
| 270 | 270 | } |
| ... | ... | @@ -544,15 +544,14 @@ const Fe = struct { |
| 544 | 544 | ut[i] = @bitCast(u32, @intCast(i32, t[i])); |
| 545 | 545 | } |
| 546 | 546 | |
| 547 | // TODO https://github.com/ziglang/zig/issues/863 | |
| 548 | writeIntSliceLittle(u32, s[0..4], (ut[0] >> 0) | (ut[1] << 26)); | |
| 549 | writeIntSliceLittle(u32, s[4..8], (ut[1] >> 6) | (ut[2] << 19)); | |
| 550 | writeIntSliceLittle(u32, s[8..12], (ut[2] >> 13) | (ut[3] << 13)); | |
| 551 | writeIntSliceLittle(u32, s[12..16], (ut[3] >> 19) | (ut[4] << 6)); | |
| 552 | writeIntSliceLittle(u32, s[16..20], (ut[5] >> 0) | (ut[6] << 25)); | |
| 553 | writeIntSliceLittle(u32, s[20..24], (ut[6] >> 7) | (ut[7] << 19)); | |
| 554 | writeIntSliceLittle(u32, s[24..28], (ut[7] >> 13) | (ut[8] << 12)); | |
| 555 | writeIntSliceLittle(u32, s[28..], (ut[8] >> 20) | (ut[9] << 6)); | |
| 547 | writeIntLittle(u32, s[0..4], (ut[0] >> 0) | (ut[1] << 26)); | |
| 548 | writeIntLittle(u32, s[4..8], (ut[1] >> 6) | (ut[2] << 19)); | |
| 549 | writeIntLittle(u32, s[8..12], (ut[2] >> 13) | (ut[3] << 13)); | |
| 550 | writeIntLittle(u32, s[12..16], (ut[3] >> 19) | (ut[4] << 6)); | |
| 551 | writeIntLittle(u32, s[16..20], (ut[5] >> 0) | (ut[6] << 25)); | |
| 552 | writeIntLittle(u32, s[20..24], (ut[6] >> 7) | (ut[7] << 19)); | |
| 553 | writeIntLittle(u32, s[24..28], (ut[7] >> 13) | (ut[8] << 12)); | |
| 554 | writeIntLittle(u32, s[28..32], (ut[8] >> 20) | (ut[9] << 6)); | |
| 556 | 555 | |
| 557 | 556 | std.mem.secureZero(i64, t[0..]); |
| 558 | 557 | } |
lib/std/hash/siphash.zig+3-3| ... | ... | @@ -39,8 +39,8 @@ fn SipHashStateless(comptime T: type, comptime c_rounds: usize, comptime d_round |
| 39 | 39 | pub fn init(key: []const u8) Self { |
| 40 | 40 | assert(key.len >= 16); |
| 41 | 41 | |
| 42 | const k0 = mem.readIntSliceLittle(u64, key[0..8]); | |
| 43 | const k1 = mem.readIntSliceLittle(u64, key[8..16]); | |
| 42 | const k0 = mem.readIntLittle(u64, key[0..8]); | |
| 43 | const k1 = mem.readIntLittle(u64, key[8..16]); | |
| 44 | 44 | |
| 45 | 45 | var d = Self{ |
| 46 | 46 | .v0 = k0 ^ 0x736f6d6570736575, |
| ... | ... | @@ -111,7 +111,7 @@ fn SipHashStateless(comptime T: type, comptime c_rounds: usize, comptime d_round |
| 111 | 111 | fn round(self: *Self, b: []const u8) void { |
| 112 | 112 | assert(b.len == 8); |
| 113 | 113 | |
| 114 | const m = mem.readIntSliceLittle(u64, b[0..]); | |
| 114 | const m = mem.readIntLittle(u64, b[0..8]); | |
| 115 | 115 | self.v3 ^= m; |
| 116 | 116 | |
| 117 | 117 | // TODO this is a workaround, should be able to supply the value without a separate variable |
lib/std/hash/wyhash.zig+1-1| ... | ... | @@ -11,7 +11,7 @@ const primes = [_]u64{ |
| 11 | 11 | |
| 12 | 12 | fn read_bytes(comptime bytes: u8, data: []const u8) u64 { |
| 13 | 13 | const T = std.meta.IntType(false, 8 * bytes); |
| 14 | return mem.readIntSliceLittle(T, data[0..bytes]); | |
| 14 | return mem.readIntLittle(T, data[0..bytes]); | |
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | fn read_8bytes_swapped(data: []const u8) u64 { |
lib/std/mem.zig+2-4| ... | ... | @@ -824,8 +824,7 @@ pub const readIntBig = switch (builtin.endian) { |
| 824 | 824 | pub fn readIntSliceNative(comptime T: type, bytes: []const u8) T { |
| 825 | 825 | const n = @divExact(T.bit_count, 8); |
| 826 | 826 | assert(bytes.len >= n); |
| 827 | // TODO https://github.com/ziglang/zig/issues/863 | |
| 828 | return readIntNative(T, @ptrCast(*const [n]u8, bytes.ptr)); | |
| 827 | return readIntNative(T, bytes[0..n]); | |
| 829 | 828 | } |
| 830 | 829 | |
| 831 | 830 | /// Asserts that bytes.len >= T.bit_count / 8. Reads the integer starting from index 0 |
| ... | ... | @@ -863,8 +862,7 @@ pub fn readInt(comptime T: type, bytes: *const [@divExact(T.bit_count, 8)]u8, en |
| 863 | 862 | pub fn readIntSlice(comptime T: type, bytes: []const u8, endian: builtin.Endian) T { |
| 864 | 863 | const n = @divExact(T.bit_count, 8); |
| 865 | 864 | assert(bytes.len >= n); |
| 866 | // TODO https://github.com/ziglang/zig/issues/863 | |
| 867 | return readInt(T, @ptrCast(*const [n]u8, bytes.ptr), endian); | |
| 865 | return readInt(T, bytes[0..n], endian); | |
| 868 | 866 | } |
| 869 | 867 | |
| 870 | 868 | test "comptime read/write int" { |
lib/std/rand.zig+1-1| ... | ... | @@ -5,7 +5,7 @@ |
| 5 | 5 | // ``` |
| 6 | 6 | // var buf: [8]u8 = undefined; |
| 7 | 7 | // try std.crypto.randomBytes(buf[0..]); |
| 8 | // const seed = mem.readIntSliceLittle(u64, buf[0..8]); | |
| 8 | // const seed = mem.readIntLittle(u64, buf[0..8]); | |
| 9 | 9 | // |
| 10 | 10 | // var r = DefaultPrng.init(seed); |
| 11 | 11 | // |
lib/std/unicode.zig+10-10| ... | ... | @@ -251,12 +251,12 @@ pub const Utf16LeIterator = struct { |
| 251 | 251 | pub fn nextCodepoint(it: *Utf16LeIterator) !?u21 { |
| 252 | 252 | assert(it.i <= it.bytes.len); |
| 253 | 253 | if (it.i == it.bytes.len) return null; |
| 254 | const c0: u21 = mem.readIntSliceLittle(u16, it.bytes[it.i .. it.i + 2]); | |
| 254 | const c0: u21 = mem.readIntLittle(u16, it.bytes[it.i..][0..2]); | |
| 255 | 255 | if (c0 & ~@as(u21, 0x03ff) == 0xd800) { |
| 256 | 256 | // surrogate pair |
| 257 | 257 | it.i += 2; |
| 258 | 258 | if (it.i >= it.bytes.len) return error.DanglingSurrogateHalf; |
| 259 | const c1: u21 = mem.readIntSliceLittle(u16, it.bytes[it.i .. it.i + 2]); | |
| 259 | const c1: u21 = mem.readIntLittle(u16, it.bytes[it.i..][0..2]); | |
| 260 | 260 | if (c1 & ~@as(u21, 0x03ff) != 0xdc00) return error.ExpectedSecondSurrogateHalf; |
| 261 | 261 | it.i += 2; |
| 262 | 262 | return 0x10000 + (((c0 & 0x03ff) << 10) | (c1 & 0x03ff)); |
| ... | ... | @@ -630,11 +630,11 @@ test "utf8ToUtf16LeWithNull" { |
| 630 | 630 | } |
| 631 | 631 | } |
| 632 | 632 | |
| 633 | /// Converts a UTF-8 string literal into a UTF-16LE string literal. | |
| 634 | pub fn utf8ToUtf16LeStringLiteral(comptime utf8: []const u8) *const [calcUtf16LeLen(utf8) :0] u16 { | |
| 633 | /// Converts a UTF-8 string literal into a UTF-16LE string literal. | |
| 634 | pub fn utf8ToUtf16LeStringLiteral(comptime utf8: []const u8) *const [calcUtf16LeLen(utf8):0]u16 { | |
| 635 | 635 | comptime { |
| 636 | 636 | const len: usize = calcUtf16LeLen(utf8); |
| 637 | var utf16le: [len :0]u16 = [_ :0]u16{0} ** len; | |
| 637 | var utf16le: [len:0]u16 = [_:0]u16{0} ** len; | |
| 638 | 638 | const utf16le_len = utf8ToUtf16Le(&utf16le, utf8[0..]) catch |err| @compileError(err); |
| 639 | 639 | assert(len == utf16le_len); |
| 640 | 640 | return &utf16le; |
| ... | ... | @@ -660,8 +660,8 @@ fn calcUtf16LeLen(utf8: []const u8) usize { |
| 660 | 660 | } |
| 661 | 661 | |
| 662 | 662 | test "utf8ToUtf16LeStringLiteral" { |
| 663 | { | |
| 664 | const bytes = [_:0]u16{ 0x41 }; | |
| 663 | { | |
| 664 | const bytes = [_:0]u16{0x41}; | |
| 665 | 665 | const utf16 = utf8ToUtf16LeStringLiteral("A"); |
| 666 | 666 | testing.expectEqualSlices(u16, &bytes, utf16); |
| 667 | 667 | testing.expect(utf16[1] == 0); |
| ... | ... | @@ -673,19 +673,19 @@ test "utf8ToUtf16LeStringLiteral" { |
| 673 | 673 | testing.expect(utf16[2] == 0); |
| 674 | 674 | } |
| 675 | 675 | { |
| 676 | const bytes = [_:0]u16{ 0x02FF }; | |
| 676 | const bytes = [_:0]u16{0x02FF}; | |
| 677 | 677 | const utf16 = utf8ToUtf16LeStringLiteral("\u{02FF}"); |
| 678 | 678 | testing.expectEqualSlices(u16, &bytes, utf16); |
| 679 | 679 | testing.expect(utf16[1] == 0); |
| 680 | 680 | } |
| 681 | 681 | { |
| 682 | const bytes = [_:0]u16{ 0x7FF }; | |
| 682 | const bytes = [_:0]u16{0x7FF}; | |
| 683 | 683 | const utf16 = utf8ToUtf16LeStringLiteral("\u{7FF}"); |
| 684 | 684 | testing.expectEqualSlices(u16, &bytes, utf16); |
| 685 | 685 | testing.expect(utf16[1] == 0); |
| 686 | 686 | } |
| 687 | 687 | { |
| 688 | const bytes = [_:0]u16{ 0x801 }; | |
| 688 | const bytes = [_:0]u16{0x801}; | |
| 689 | 689 | const utf16 = utf8ToUtf16LeStringLiteral("\u{801}"); |
| 690 | 690 | testing.expectEqualSlices(u16, &bytes, utf16); |
| 691 | 691 | testing.expect(utf16[1] == 0); |