authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-07-12 20:55:48-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-07-13 18:26:13+02:00
loge7b18a7ce69f30c85f21ec8ad6a70211abf5f24b
tree0206b7273a6f7516ae96d44f98afcf1912164c12
parentf97baca6f6288eb786fe3546292465ef76310810

std.crypto: remove `inline` from most functions

To quote the language reference, It is generally better to let the compiler decide when to inline a function, except for these scenarios: * To change how many stack frames are in the call stack, for debugging purposes. * To force comptime-ness of the arguments to propagate to the return value of the function, as in the above example. * Real world performance measurements demand it. Don't guess! Note that inline actually restricts what the compiler is allowed to do. This can harm binary size, compilation speed, and even runtime performance. `zig run lib/std/crypto/benchmark.zig -OReleaseFast` [-before-] vs {+after+} md5: [-990-] {+998+} MiB/s sha1: [-1144-] {+1140+} MiB/s sha256: [-2267-] {+2275+} MiB/s sha512: [-762-] {+767+} MiB/s sha3-256: [-680-] {+683+} MiB/s sha3-512: [-362-] {+363+} MiB/s shake-128: [-835-] {+839+} MiB/s shake-256: [-680-] {+681+} MiB/s turboshake-128: [-1567-] {+1570+} MiB/s turboshake-256: [-1276-] {+1282+} MiB/s blake2s: [-778-] {+789+} MiB/s blake2b: [-1071-] {+1086+} MiB/s blake3: [-1148-] {+1137+} MiB/s ghash: [-10044-] {+10033+} MiB/s polyval: [-9726-] {+10033+} MiB/s poly1305: [-2486-] {+2703+} MiB/s hmac-md5: [-991-] {+998+} MiB/s hmac-sha1: [-1134-] {+1137+} MiB/s hmac-sha256: [-2265-] {+2288+} MiB/s hmac-sha512: [-765-] {+764+} MiB/s siphash-2-4: [-4410-] {+4438+} MiB/s siphash-1-3: [-7144-] {+7225+} MiB/s siphash128-2-4: [-4397-] {+4449+} MiB/s siphash128-1-3: [-7281-] {+7374+} MiB/s aegis-128x4 mac: [-73385-] {+74523+} MiB/s aegis-256x4 mac: [-30160-] {+30539+} MiB/s aegis-128x2 mac: [-66662-] {+67267+} MiB/s aegis-256x2 mac: [-16812-] {+16806+} MiB/s aegis-128l mac: [-33876-] {+34055+} MiB/s aegis-256 mac: [-8993-] {+9087+} MiB/s aes-cmac: 2036 MiB/s x25519: [-20670-] {+16844+} exchanges/s ed25519: [-29763-] {+29576+} signatures/s ecdsa-p256: [-4762-] {+4900+} signatures/s ecdsa-p384: [-1465-] {+1500+} signatures/s ecdsa-secp256k1: [-5643-] {+5769+} signatures/s ed25519: [-21926-] {+21721+} verifications/s ed25519: [-51200-] {+50880+} verifications/s (batch) chacha20Poly1305: [-1189-] {+1109+} MiB/s xchacha20Poly1305: [-1196-] {+1107+} MiB/s xchacha8Poly1305: [-1466-] {+1555+} MiB/s xsalsa20Poly1305: [-660-] {+620+} MiB/s aegis-128x4: [-76389-] {+78181+} MiB/s aegis-128x2: [-53946-] {+53495+} MiB/s aegis-128l: [-27219-] {+25621+} MiB/s aegis-256x4: [-49351-] {+49542+} MiB/s aegis-256x2: [-32390-] {+32366+} MiB/s aegis-256: [-8881-] {+8944+} MiB/s aes128-gcm: [-6095-] {+6205+} MiB/s aes256-gcm: [-5306-] {+5427+} MiB/s aes128-ocb: [-8529-] {+13974+} MiB/s aes256-ocb: [-7241-] {+9442+} MiB/s isapa128a: [-204-] {+214+} MiB/s aes128-single: [-133857882-] {+134170944+} ops/s aes256-single: [-96306962-] {+96408639+} ops/s aes128-8: [-1083210101-] {+1073727253+} ops/s aes256-8: [-762042466-] {+767091778+} ops/s bcrypt: 0.009 s/ops scrypt: [-0.018-] {+0.017+} s/ops argon2: [-0.037-] {+0.060+} s/ops kyber512d00: [-206057-] {+205779+} encaps/s kyber768d00: [-156074-] {+150711+} encaps/s kyber1024d00: [-116626-] {+115469+} encaps/s kyber512d00: [-181149-] {+182046+} decaps/s kyber768d00: [-136965-] {+135676+} decaps/s kyber1024d00: [-101307-] {+100643+} decaps/s kyber512d00: [-123624-] {+123375+} keygen/s kyber768d00: [-69465-] {+70828+} keygen/s kyber1024d00: [-43117-] {+43208+} keygen/s

26 files changed, 161 insertions(+), 161 deletions(-)

lib/std/crypto.zig+1-1
...@@ -386,7 +386,7 @@ test "issue #4532: no index out of bounds" {...@@ -386,7 +386,7 @@ test "issue #4532: no index out of bounds" {
386386
387/// Sets a slice to zeroes.387/// Sets a slice to zeroes.
388/// Prevents the store from being optimized out.388/// Prevents the store from being optimized out.
389pub inline fn secureZero(comptime T: type, s: []volatile T) void {389pub fn secureZero(comptime T: type, s: []volatile T) void {
390 @memset(s, 0);390 @memset(s, 0);
391}391}
392392
lib/std/crypto/25519/curve25519.zig+2-2
...@@ -15,12 +15,12 @@ pub const Curve25519 = struct {...@@ -15,12 +15,12 @@ pub const Curve25519 = struct {
15 x: Fe,15 x: Fe,
1616
17 /// Decode a Curve25519 point from its compressed (X) coordinates.17 /// Decode a Curve25519 point from its compressed (X) coordinates.
18 pub inline fn fromBytes(s: [32]u8) Curve25519 {18 pub fn fromBytes(s: [32]u8) Curve25519 {
19 return .{ .x = Fe.fromBytes(s) };19 return .{ .x = Fe.fromBytes(s) };
20 }20 }
2121
22 /// Encode a Curve25519 point.22 /// Encode a Curve25519 point.
23 pub inline fn toBytes(p: Curve25519) [32]u8 {23 pub fn toBytes(p: Curve25519) [32]u8 {
24 return p.x.toBytes();24 return p.x.toBytes();
25 }25 }
2626
lib/std/crypto/25519/edwards25519.zig+3-3
...@@ -138,7 +138,7 @@ pub const Edwards25519 = struct {...@@ -138,7 +138,7 @@ pub const Edwards25519 = struct {
138 }138 }
139139
140 /// Flip the sign of the X coordinate.140 /// Flip the sign of the X coordinate.
141 pub inline fn neg(p: Edwards25519) Edwards25519 {141 pub fn neg(p: Edwards25519) Edwards25519 {
142 return .{ .x = p.x.neg(), .y = p.y, .z = p.z, .t = p.t.neg() };142 return .{ .x = p.x.neg(), .y = p.y, .z = p.z, .t = p.t.neg() };
143 }143 }
144144
...@@ -190,14 +190,14 @@ pub const Edwards25519 = struct {...@@ -190,14 +190,14 @@ pub const Edwards25519 = struct {
190 return q;190 return q;
191 }191 }
192192
193 inline fn cMov(p: *Edwards25519, a: Edwards25519, c: u64) void {193 fn cMov(p: *Edwards25519, a: Edwards25519, c: u64) void {
194 p.x.cMov(a.x, c);194 p.x.cMov(a.x, c);
195 p.y.cMov(a.y, c);195 p.y.cMov(a.y, c);
196 p.z.cMov(a.z, c);196 p.z.cMov(a.z, c);
197 p.t.cMov(a.t, c);197 p.t.cMov(a.t, c);
198 }198 }
199199
200 inline fn pcSelect(comptime n: usize, pc: *const [n]Edwards25519, b: u8) Edwards25519 {200 fn pcSelect(comptime n: usize, pc: *const [n]Edwards25519, b: u8) Edwards25519 {
201 var t = Edwards25519.identityElement;201 var t = Edwards25519.identityElement;
202 comptime var i: u8 = 1;202 comptime var i: u8 = 1;
203 inline while (i < pc.len) : (i += 1) {203 inline while (i < pc.len) : (i += 1) {
lib/std/crypto/25519/field.zig+11-11
...@@ -56,7 +56,7 @@ pub const Fe = struct {...@@ -56,7 +56,7 @@ pub const Fe = struct {
56 pub const edwards25519sqrtam2 = Fe{ .limbs = .{ 1693982333959686, 608509411481997, 2235573344831311, 947681270984193, 266558006233600 } };56 pub const edwards25519sqrtam2 = Fe{ .limbs = .{ 1693982333959686, 608509411481997, 2235573344831311, 947681270984193, 266558006233600 } };
5757
58 /// Return true if the field element is zero58 /// Return true if the field element is zero
59 pub inline fn isZero(fe: Fe) bool {59 pub fn isZero(fe: Fe) bool {
60 var reduced = fe;60 var reduced = fe;
61 reduced.reduce();61 reduced.reduce();
62 const limbs = reduced.limbs;62 const limbs = reduced.limbs;
...@@ -64,7 +64,7 @@ pub const Fe = struct {...@@ -64,7 +64,7 @@ pub const Fe = struct {
64 }64 }
6565
66 /// Return true if both field elements are equivalent66 /// Return true if both field elements are equivalent
67 pub inline fn equivalent(a: Fe, b: Fe) bool {67 pub fn equivalent(a: Fe, b: Fe) bool {
68 return a.sub(b).isZero();68 return a.sub(b).isZero();
69 }69 }
7070
...@@ -168,7 +168,7 @@ pub const Fe = struct {...@@ -168,7 +168,7 @@ pub const Fe = struct {
168 }168 }
169169
170 /// Add a field element170 /// Add a field element
171 pub inline fn add(a: Fe, b: Fe) Fe {171 pub fn add(a: Fe, b: Fe) Fe {
172 var fe: Fe = undefined;172 var fe: Fe = undefined;
173 comptime var i = 0;173 comptime var i = 0;
174 inline while (i < 5) : (i += 1) {174 inline while (i < 5) : (i += 1) {
...@@ -178,7 +178,7 @@ pub const Fe = struct {...@@ -178,7 +178,7 @@ pub const Fe = struct {
178 }178 }
179179
180 /// Subtract a field element180 /// Subtract a field element
181 pub inline fn sub(a: Fe, b: Fe) Fe {181 pub fn sub(a: Fe, b: Fe) Fe {
182 var fe = b;182 var fe = b;
183 comptime var i = 0;183 comptime var i = 0;
184 inline while (i < 4) : (i += 1) {184 inline while (i < 4) : (i += 1) {
...@@ -197,17 +197,17 @@ pub const Fe = struct {...@@ -197,17 +197,17 @@ pub const Fe = struct {
197 }197 }
198198
199 /// Negate a field element199 /// Negate a field element
200 pub inline fn neg(a: Fe) Fe {200 pub fn neg(a: Fe) Fe {
201 return zero.sub(a);201 return zero.sub(a);
202 }202 }
203203
204 /// Return true if a field element is negative204 /// Return true if a field element is negative
205 pub inline fn isNegative(a: Fe) bool {205 pub fn isNegative(a: Fe) bool {
206 return (a.toBytes()[0] & 1) != 0;206 return (a.toBytes()[0] & 1) != 0;
207 }207 }
208208
209 /// Conditonally replace a field element with `a` if `c` is positive209 /// Conditonally replace a field element with `a` if `c` is positive
210 pub inline fn cMov(fe: *Fe, a: Fe, c: u64) void {210 pub fn cMov(fe: *Fe, a: Fe, c: u64) void {
211 const mask: u64 = 0 -% c;211 const mask: u64 = 0 -% c;
212 var x = fe.*;212 var x = fe.*;
213 comptime var i = 0;213 comptime var i = 0;
...@@ -248,7 +248,7 @@ pub const Fe = struct {...@@ -248,7 +248,7 @@ pub const Fe = struct {
248 }248 }
249 }249 }
250250
251 inline fn _carry128(r: *[5]u128) Fe {251 fn _carry128(r: *[5]u128) Fe {
252 var rs: [5]u64 = undefined;252 var rs: [5]u64 = undefined;
253 comptime var i = 0;253 comptime var i = 0;
254 inline while (i < 4) : (i += 1) {254 inline while (i < 4) : (i += 1) {
...@@ -321,17 +321,17 @@ pub const Fe = struct {...@@ -321,17 +321,17 @@ pub const Fe = struct {
321 }321 }
322322
323 /// Square a field element323 /// Square a field element
324 pub inline fn sq(a: Fe) Fe {324 pub fn sq(a: Fe) Fe {
325 return _sq(a, false);325 return _sq(a, false);
326 }326 }
327327
328 /// Square and double a field element328 /// Square and double a field element
329 pub inline fn sq2(a: Fe) Fe {329 pub fn sq2(a: Fe) Fe {
330 return _sq(a, true);330 return _sq(a, true);
331 }331 }
332332
333 /// Multiply a field element with a small (32-bit) integer333 /// Multiply a field element with a small (32-bit) integer
334 pub inline fn mul32(a: Fe, comptime n: u32) Fe {334 pub fn mul32(a: Fe, comptime n: u32) Fe {
335 const sn = @as(u128, @intCast(n));335 const sn = @as(u128, @intCast(n));
336 var fe: Fe = undefined;336 var fe: Fe = undefined;
337 var x: u128 = 0;337 var x: u128 = 0;
lib/std/crypto/25519/ristretto255.zig+5-5
...@@ -42,7 +42,7 @@ pub const Ristretto255 = struct {...@@ -42,7 +42,7 @@ pub const Ristretto255 = struct {
42 }42 }
4343
44 /// Reject the neutral element.44 /// Reject the neutral element.
45 pub inline fn rejectIdentity(p: Ristretto255) IdentityElementError!void {45 pub fn rejectIdentity(p: Ristretto255) IdentityElementError!void {
46 return p.p.rejectIdentity();46 return p.p.rejectIdentity();
47 }47 }
4848
...@@ -141,24 +141,24 @@ pub const Ristretto255 = struct {...@@ -141,24 +141,24 @@ pub const Ristretto255 = struct {
141 }141 }
142142
143 /// Double a Ristretto255 element.143 /// Double a Ristretto255 element.
144 pub inline fn dbl(p: Ristretto255) Ristretto255 {144 pub fn dbl(p: Ristretto255) Ristretto255 {
145 return .{ .p = p.p.dbl() };145 return .{ .p = p.p.dbl() };
146 }146 }
147147
148 /// Add two Ristretto255 elements.148 /// Add two Ristretto255 elements.
149 pub inline fn add(p: Ristretto255, q: Ristretto255) Ristretto255 {149 pub fn add(p: Ristretto255, q: Ristretto255) Ristretto255 {
150 return .{ .p = p.p.add(q.p) };150 return .{ .p = p.p.add(q.p) };
151 }151 }
152152
153 /// Subtract two Ristretto255 elements.153 /// Subtract two Ristretto255 elements.
154 pub inline fn sub(p: Ristretto255, q: Ristretto255) Ristretto255 {154 pub fn sub(p: Ristretto255, q: Ristretto255) Ristretto255 {
155 return .{ .p = p.p.sub(q.p) };155 return .{ .p = p.p.sub(q.p) };
156 }156 }
157157
158 /// Multiply a Ristretto255 element with a scalar.158 /// Multiply a Ristretto255 element with a scalar.
159 /// Return error.WeakPublicKey if the resulting element is159 /// Return error.WeakPublicKey if the resulting element is
160 /// the identity element.160 /// the identity element.
161 pub inline fn mul(p: Ristretto255, s: [encoded_length]u8) (IdentityElementError || WeakPublicKeyError)!Ristretto255 {161 pub fn mul(p: Ristretto255, s: [encoded_length]u8) (IdentityElementError || WeakPublicKeyError)!Ristretto255 {
162 return .{ .p = try p.p.mul(s) };162 return .{ .p = try p.p.mul(s) };
163 }163 }
164164
lib/std/crypto/25519/scalar.zig+2-2
...@@ -50,7 +50,7 @@ pub fn reduce64(s: [64]u8) CompressedScalar {...@@ -50,7 +50,7 @@ pub fn reduce64(s: [64]u8) CompressedScalar {
5050
51/// Perform the X25519 "clamping" operation.51/// Perform the X25519 "clamping" operation.
52/// The scalar is then guaranteed to be a multiple of the cofactor.52/// The scalar is then guaranteed to be a multiple of the cofactor.
53pub inline fn clamp(s: *CompressedScalar) void {53pub fn clamp(s: *CompressedScalar) void {
54 s[0] &= 248;54 s[0] &= 248;
55 s[31] = (s[31] & 127) | 64;55 s[31] = (s[31] & 127) | 64;
56}56}
...@@ -514,7 +514,7 @@ pub const Scalar = struct {...@@ -514,7 +514,7 @@ pub const Scalar = struct {
514 }514 }
515515
516 /// Square a scalar `n` times516 /// Square a scalar `n` times
517 inline fn sqn(x: Scalar, comptime n: comptime_int) Scalar {517 fn sqn(x: Scalar, comptime n: comptime_int) Scalar {
518 var i: usize = 0;518 var i: usize = 0;
519 var t = x;519 var t = x;
520 while (i < n) : (i += 1) {520 while (i < n) : (i += 1) {
lib/std/crypto/aegis.zig+2-2
...@@ -104,7 +104,7 @@ fn State128X(comptime degree: u7) type {...@@ -104,7 +104,7 @@ fn State128X(comptime degree: u7) type {
104 return state;104 return state;
105 }105 }
106106
107 inline fn update(state: *State, d1: AesBlockVec, d2: AesBlockVec) void {107 fn update(state: *State, d1: AesBlockVec, d2: AesBlockVec) void {
108 const blocks = &state.blocks;108 const blocks = &state.blocks;
109 const tmp = blocks[7];109 const tmp = blocks[7];
110 comptime var i: usize = 7;110 comptime var i: usize = 7;
...@@ -413,7 +413,7 @@ fn State256X(comptime degree: u7) type {...@@ -413,7 +413,7 @@ fn State256X(comptime degree: u7) type {
413 return state;413 return state;
414 }414 }
415415
416 inline fn update(state: *State, d: AesBlockVec) void {416 fn update(state: *State, d: AesBlockVec) void {
417 const blocks = &state.blocks;417 const blocks = &state.blocks;
418 const tmp = blocks[5].encrypt(blocks[0]);418 const tmp = blocks[5].encrypt(blocks[0]);
419 comptime var i: usize = 5;419 comptime var i: usize = 5;
lib/std/crypto/aes/aesni.zig+26-26
...@@ -17,24 +17,24 @@ pub const Block = struct {...@@ -17,24 +17,24 @@ pub const Block = struct {
17 repr: Repr,17 repr: Repr,
1818
19 /// Convert a byte sequence into an internal representation.19 /// Convert a byte sequence into an internal representation.
20 pub inline fn fromBytes(bytes: *const [16]u8) Block {20 pub fn fromBytes(bytes: *const [16]u8) Block {
21 const repr = mem.bytesToValue(Repr, bytes);21 const repr = mem.bytesToValue(Repr, bytes);
22 return Block{ .repr = repr };22 return Block{ .repr = repr };
23 }23 }
2424
25 /// Convert the internal representation of a block into a byte sequence.25 /// Convert the internal representation of a block into a byte sequence.
26 pub inline fn toBytes(block: Block) [16]u8 {26 pub fn toBytes(block: Block) [16]u8 {
27 return mem.toBytes(block.repr);27 return mem.toBytes(block.repr);
28 }28 }
2929
30 /// XOR the block with a byte sequence.30 /// XOR the block with a byte sequence.
31 pub inline fn xorBytes(block: Block, bytes: *const [16]u8) [16]u8 {31 pub fn xorBytes(block: Block, bytes: *const [16]u8) [16]u8 {
32 const x = block.repr ^ fromBytes(bytes).repr;32 const x = block.repr ^ fromBytes(bytes).repr;
33 return mem.toBytes(x);33 return mem.toBytes(x);
34 }34 }
3535
36 /// Encrypt a block with a round key.36 /// Encrypt a block with a round key.
37 pub inline fn encrypt(block: Block, round_key: Block) Block {37 pub fn encrypt(block: Block, round_key: Block) Block {
38 return Block{38 return Block{
39 .repr = asm (39 .repr = asm (
40 \\ vaesenc %[rk], %[in], %[out]40 \\ vaesenc %[rk], %[in], %[out]
...@@ -46,7 +46,7 @@ pub const Block = struct {...@@ -46,7 +46,7 @@ pub const Block = struct {
46 }46 }
4747
48 /// Encrypt a block with the last round key.48 /// Encrypt a block with the last round key.
49 pub inline fn encryptLast(block: Block, round_key: Block) Block {49 pub fn encryptLast(block: Block, round_key: Block) Block {
50 return Block{50 return Block{
51 .repr = asm (51 .repr = asm (
52 \\ vaesenclast %[rk], %[in], %[out]52 \\ vaesenclast %[rk], %[in], %[out]
...@@ -58,7 +58,7 @@ pub const Block = struct {...@@ -58,7 +58,7 @@ pub const Block = struct {
58 }58 }
5959
60 /// Decrypt a block with a round key.60 /// Decrypt a block with a round key.
61 pub inline fn decrypt(block: Block, inv_round_key: Block) Block {61 pub fn decrypt(block: Block, inv_round_key: Block) Block {
62 return Block{62 return Block{
63 .repr = asm (63 .repr = asm (
64 \\ vaesdec %[rk], %[in], %[out]64 \\ vaesdec %[rk], %[in], %[out]
...@@ -70,7 +70,7 @@ pub const Block = struct {...@@ -70,7 +70,7 @@ pub const Block = struct {
70 }70 }
7171
72 /// Decrypt a block with the last round key.72 /// Decrypt a block with the last round key.
73 pub inline fn decryptLast(block: Block, inv_round_key: Block) Block {73 pub fn decryptLast(block: Block, inv_round_key: Block) Block {
74 return Block{74 return Block{
75 .repr = asm (75 .repr = asm (
76 \\ vaesdeclast %[rk], %[in], %[out]76 \\ vaesdeclast %[rk], %[in], %[out]
...@@ -82,17 +82,17 @@ pub const Block = struct {...@@ -82,17 +82,17 @@ pub const Block = struct {
82 }82 }
8383
84 /// Apply the bitwise XOR operation to the content of two blocks.84 /// Apply the bitwise XOR operation to the content of two blocks.
85 pub inline fn xorBlocks(block1: Block, block2: Block) Block {85 pub fn xorBlocks(block1: Block, block2: Block) Block {
86 return Block{ .repr = block1.repr ^ block2.repr };86 return Block{ .repr = block1.repr ^ block2.repr };
87 }87 }
8888
89 /// Apply the bitwise AND operation to the content of two blocks.89 /// Apply the bitwise AND operation to the content of two blocks.
90 pub inline fn andBlocks(block1: Block, block2: Block) Block {90 pub fn andBlocks(block1: Block, block2: Block) Block {
91 return Block{ .repr = block1.repr & block2.repr };91 return Block{ .repr = block1.repr & block2.repr };
92 }92 }
9393
94 /// Apply the bitwise OR operation to the content of two blocks.94 /// Apply the bitwise OR operation to the content of two blocks.
95 pub inline fn orBlocks(block1: Block, block2: Block) Block {95 pub fn orBlocks(block1: Block, block2: Block) Block {
96 return Block{ .repr = block1.repr | block2.repr };96 return Block{ .repr = block1.repr | block2.repr };
97 }97 }
9898
...@@ -112,7 +112,7 @@ pub const Block = struct {...@@ -112,7 +112,7 @@ pub const Block = struct {
112 };112 };
113113
114 /// Encrypt multiple blocks in parallel, each their own round key.114 /// Encrypt multiple blocks in parallel, each their own round key.
115 pub inline fn encryptParallel(comptime count: usize, blocks: [count]Block, round_keys: [count]Block) [count]Block {115 pub fn encryptParallel(comptime count: usize, blocks: [count]Block, round_keys: [count]Block) [count]Block {
116 comptime var i = 0;116 comptime var i = 0;
117 var out: [count]Block = undefined;117 var out: [count]Block = undefined;
118 inline while (i < count) : (i += 1) {118 inline while (i < count) : (i += 1) {
...@@ -122,7 +122,7 @@ pub const Block = struct {...@@ -122,7 +122,7 @@ pub const Block = struct {
122 }122 }
123123
124 /// Decrypt multiple blocks in parallel, each their own round key.124 /// Decrypt multiple blocks in parallel, each their own round key.
125 pub inline fn decryptParallel(comptime count: usize, blocks: [count]Block, round_keys: [count]Block) [count]Block {125 pub fn decryptParallel(comptime count: usize, blocks: [count]Block, round_keys: [count]Block) [count]Block {
126 comptime var i = 0;126 comptime var i = 0;
127 var out: [count]Block = undefined;127 var out: [count]Block = undefined;
128 inline while (i < count) : (i += 1) {128 inline while (i < count) : (i += 1) {
...@@ -132,7 +132,7 @@ pub const Block = struct {...@@ -132,7 +132,7 @@ pub const Block = struct {
132 }132 }
133133
134 /// Encrypt multiple blocks in parallel with the same round key.134 /// Encrypt multiple blocks in parallel with the same round key.
135 pub inline fn encryptWide(comptime count: usize, blocks: [count]Block, round_key: Block) [count]Block {135 pub fn encryptWide(comptime count: usize, blocks: [count]Block, round_key: Block) [count]Block {
136 comptime var i = 0;136 comptime var i = 0;
137 var out: [count]Block = undefined;137 var out: [count]Block = undefined;
138 inline while (i < count) : (i += 1) {138 inline while (i < count) : (i += 1) {
...@@ -142,7 +142,7 @@ pub const Block = struct {...@@ -142,7 +142,7 @@ pub const Block = struct {
142 }142 }
143143
144 /// Decrypt multiple blocks in parallel with the same round key.144 /// Decrypt multiple blocks in parallel with the same round key.
145 pub inline fn decryptWide(comptime count: usize, blocks: [count]Block, round_key: Block) [count]Block {145 pub fn decryptWide(comptime count: usize, blocks: [count]Block, round_key: Block) [count]Block {
146 comptime var i = 0;146 comptime var i = 0;
147 var out: [count]Block = undefined;147 var out: [count]Block = undefined;
148 inline while (i < count) : (i += 1) {148 inline while (i < count) : (i += 1) {
...@@ -152,7 +152,7 @@ pub const Block = struct {...@@ -152,7 +152,7 @@ pub const Block = struct {
152 }152 }
153153
154 /// Encrypt multiple blocks in parallel with the same last round key.154 /// Encrypt multiple blocks in parallel with the same last round key.
155 pub inline fn encryptLastWide(comptime count: usize, blocks: [count]Block, round_key: Block) [count]Block {155 pub fn encryptLastWide(comptime count: usize, blocks: [count]Block, round_key: Block) [count]Block {
156 comptime var i = 0;156 comptime var i = 0;
157 var out: [count]Block = undefined;157 var out: [count]Block = undefined;
158 inline while (i < count) : (i += 1) {158 inline while (i < count) : (i += 1) {
...@@ -162,7 +162,7 @@ pub const Block = struct {...@@ -162,7 +162,7 @@ pub const Block = struct {
162 }162 }
163163
164 /// Decrypt multiple blocks in parallel with the same last round key.164 /// Decrypt multiple blocks in parallel with the same last round key.
165 pub inline fn decryptLastWide(comptime count: usize, blocks: [count]Block, round_key: Block) [count]Block {165 pub fn decryptLastWide(comptime count: usize, blocks: [count]Block, round_key: Block) [count]Block {
166 comptime var i = 0;166 comptime var i = 0;
167 var out: [count]Block = undefined;167 var out: [count]Block = undefined;
168 inline while (i < count) : (i += 1) {168 inline while (i < count) : (i += 1) {
...@@ -200,7 +200,7 @@ pub fn BlockVec(comptime blocks_count: comptime_int) type {...@@ -200,7 +200,7 @@ pub fn BlockVec(comptime blocks_count: comptime_int) type {
200 pub const block_length: usize = blocks_count * 16;200 pub const block_length: usize = blocks_count * 16;
201201
202 /// Convert a byte sequence into an internal representation.202 /// Convert a byte sequence into an internal representation.
203 pub inline fn fromBytes(bytes: *const [blocks_count * 16]u8) Self {203 pub fn fromBytes(bytes: *const [blocks_count * 16]u8) Self {
204 var out: Self = undefined;204 var out: Self = undefined;
205 inline for (0..native_words) |i| {205 inline for (0..native_words) |i| {
206 out.repr[i] = mem.bytesToValue(Repr, bytes[i * native_word_size ..][0..native_word_size]);206 out.repr[i] = mem.bytesToValue(Repr, bytes[i * native_word_size ..][0..native_word_size]);
...@@ -209,7 +209,7 @@ pub fn BlockVec(comptime blocks_count: comptime_int) type {...@@ -209,7 +209,7 @@ pub fn BlockVec(comptime blocks_count: comptime_int) type {
209 }209 }
210210
211 /// Convert the internal representation of a block vector into a byte sequence.211 /// Convert the internal representation of a block vector into a byte sequence.
212 pub inline fn toBytes(block_vec: Self) [blocks_count * 16]u8 {212 pub fn toBytes(block_vec: Self) [blocks_count * 16]u8 {
213 var out: [blocks_count * 16]u8 = undefined;213 var out: [blocks_count * 16]u8 = undefined;
214 inline for (0..native_words) |i| {214 inline for (0..native_words) |i| {
215 out[i * native_word_size ..][0..native_word_size].* = mem.toBytes(block_vec.repr[i]);215 out[i * native_word_size ..][0..native_word_size].* = mem.toBytes(block_vec.repr[i]);
...@@ -218,7 +218,7 @@ pub fn BlockVec(comptime blocks_count: comptime_int) type {...@@ -218,7 +218,7 @@ pub fn BlockVec(comptime blocks_count: comptime_int) type {
218 }218 }
219219
220 /// XOR the block vector with a byte sequence.220 /// XOR the block vector with a byte sequence.
221 pub inline fn xorBytes(block_vec: Self, bytes: *const [blocks_count * 16]u8) [blocks_count * 16]u8 {221 pub fn xorBytes(block_vec: Self, bytes: *const [blocks_count * 16]u8) [blocks_count * 16]u8 {
222 var x: Self = undefined;222 var x: Self = undefined;
223 inline for (0..native_words) |i| {223 inline for (0..native_words) |i| {
224 x.repr[i] = block_vec.repr[i] ^ mem.bytesToValue(Repr, bytes[i * native_word_size ..][0..native_word_size]);224 x.repr[i] = block_vec.repr[i] ^ mem.bytesToValue(Repr, bytes[i * native_word_size ..][0..native_word_size]);
...@@ -227,7 +227,7 @@ pub fn BlockVec(comptime blocks_count: comptime_int) type {...@@ -227,7 +227,7 @@ pub fn BlockVec(comptime blocks_count: comptime_int) type {
227 }227 }
228228
229 /// Apply the forward AES operation to the block vector with a vector of round keys.229 /// Apply the forward AES operation to the block vector with a vector of round keys.
230 pub inline fn encrypt(block_vec: Self, round_key_vec: Self) Self {230 pub fn encrypt(block_vec: Self, round_key_vec: Self) Self {
231 var out: Self = undefined;231 var out: Self = undefined;
232 inline for (0..native_words) |i| {232 inline for (0..native_words) |i| {
233 out.repr[i] = asm (233 out.repr[i] = asm (
...@@ -241,7 +241,7 @@ pub fn BlockVec(comptime blocks_count: comptime_int) type {...@@ -241,7 +241,7 @@ pub fn BlockVec(comptime blocks_count: comptime_int) type {
241 }241 }
242242
243 /// Apply the forward AES operation to the block vector with a vector of last round keys.243 /// Apply the forward AES operation to the block vector with a vector of last round keys.
244 pub inline fn encryptLast(block_vec: Self, round_key_vec: Self) Self {244 pub fn encryptLast(block_vec: Self, round_key_vec: Self) Self {
245 var out: Self = undefined;245 var out: Self = undefined;
246 inline for (0..native_words) |i| {246 inline for (0..native_words) |i| {
247 out.repr[i] = asm (247 out.repr[i] = asm (
...@@ -255,7 +255,7 @@ pub fn BlockVec(comptime blocks_count: comptime_int) type {...@@ -255,7 +255,7 @@ pub fn BlockVec(comptime blocks_count: comptime_int) type {
255 }255 }
256256
257 /// Apply the inverse AES operation to the block vector with a vector of round keys.257 /// Apply the inverse AES operation to the block vector with a vector of round keys.
258 pub inline fn decrypt(block_vec: Self, inv_round_key_vec: Self) Self {258 pub fn decrypt(block_vec: Self, inv_round_key_vec: Self) Self {
259 var out: Self = undefined;259 var out: Self = undefined;
260 inline for (0..native_words) |i| {260 inline for (0..native_words) |i| {
261 out.repr[i] = asm (261 out.repr[i] = asm (
...@@ -269,7 +269,7 @@ pub fn BlockVec(comptime blocks_count: comptime_int) type {...@@ -269,7 +269,7 @@ pub fn BlockVec(comptime blocks_count: comptime_int) type {
269 }269 }
270270
271 /// Apply the inverse AES operation to the block vector with a vector of last round keys.271 /// Apply the inverse AES operation to the block vector with a vector of last round keys.
272 pub inline fn decryptLast(block_vec: Self, inv_round_key_vec: Self) Self {272 pub fn decryptLast(block_vec: Self, inv_round_key_vec: Self) Self {
273 var out: Self = undefined;273 var out: Self = undefined;
274 inline for (0..native_words) |i| {274 inline for (0..native_words) |i| {
275 out.repr[i] = asm (275 out.repr[i] = asm (
...@@ -283,7 +283,7 @@ pub fn BlockVec(comptime blocks_count: comptime_int) type {...@@ -283,7 +283,7 @@ pub fn BlockVec(comptime blocks_count: comptime_int) type {
283 }283 }
284284
285 /// Apply the bitwise XOR operation to the content of two block vectors.285 /// Apply the bitwise XOR operation to the content of two block vectors.
286 pub inline fn xorBlocks(block_vec1: Self, block_vec2: Self) Self {286 pub fn xorBlocks(block_vec1: Self, block_vec2: Self) Self {
287 var out: Self = undefined;287 var out: Self = undefined;
288 inline for (0..native_words) |i| {288 inline for (0..native_words) |i| {
289 out.repr[i] = block_vec1.repr[i] ^ block_vec2.repr[i];289 out.repr[i] = block_vec1.repr[i] ^ block_vec2.repr[i];
...@@ -292,7 +292,7 @@ pub fn BlockVec(comptime blocks_count: comptime_int) type {...@@ -292,7 +292,7 @@ pub fn BlockVec(comptime blocks_count: comptime_int) type {
292 }292 }
293293
294 /// Apply the bitwise AND operation to the content of two block vectors.294 /// Apply the bitwise AND operation to the content of two block vectors.
295 pub inline fn andBlocks(block_vec1: Self, block_vec2: Self) Self {295 pub fn andBlocks(block_vec1: Self, block_vec2: Self) Self {
296 var out: Self = undefined;296 var out: Self = undefined;
297 inline for (0..native_words) |i| {297 inline for (0..native_words) |i| {
298 out.repr[i] = block_vec1.repr[i] & block_vec2.repr[i];298 out.repr[i] = block_vec1.repr[i] & block_vec2.repr[i];
...@@ -301,7 +301,7 @@ pub fn BlockVec(comptime blocks_count: comptime_int) type {...@@ -301,7 +301,7 @@ pub fn BlockVec(comptime blocks_count: comptime_int) type {
301 }301 }
302302
303 /// Apply the bitwise OR operation to the content of two block vectors.303 /// Apply the bitwise OR operation to the content of two block vectors.
304 pub inline fn orBlocks(block_vec1: Self, block_vec2: Block) Self {304 pub fn orBlocks(block_vec1: Self, block_vec2: Block) Self {
305 var out: Self = undefined;305 var out: Self = undefined;
306 inline for (0..native_words) |i| {306 inline for (0..native_words) |i| {
307 out.repr[i] = block_vec1.repr[i] | block_vec2.repr[i];307 out.repr[i] = block_vec1.repr[i] | block_vec2.repr[i];
lib/std/crypto/aes/armcrypto.zig+26-26
...@@ -12,18 +12,18 @@ pub const Block = struct {...@@ -12,18 +12,18 @@ pub const Block = struct {
12 repr: Repr,12 repr: Repr,
1313
14 /// Convert a byte sequence into an internal representation.14 /// Convert a byte sequence into an internal representation.
15 pub inline fn fromBytes(bytes: *const [16]u8) Block {15 pub fn fromBytes(bytes: *const [16]u8) Block {
16 const repr = mem.bytesToValue(Repr, bytes);16 const repr = mem.bytesToValue(Repr, bytes);
17 return Block{ .repr = repr };17 return Block{ .repr = repr };
18 }18 }
1919
20 /// Convert the internal representation of a block into a byte sequence.20 /// Convert the internal representation of a block into a byte sequence.
21 pub inline fn toBytes(block: Block) [16]u8 {21 pub fn toBytes(block: Block) [16]u8 {
22 return mem.toBytes(block.repr);22 return mem.toBytes(block.repr);
23 }23 }
2424
25 /// XOR the block with a byte sequence.25 /// XOR the block with a byte sequence.
26 pub inline fn xorBytes(block: Block, bytes: *const [16]u8) [16]u8 {26 pub fn xorBytes(block: Block, bytes: *const [16]u8) [16]u8 {
27 const x = block.repr ^ fromBytes(bytes).repr;27 const x = block.repr ^ fromBytes(bytes).repr;
28 return mem.toBytes(x);28 return mem.toBytes(x);
29 }29 }
...@@ -31,7 +31,7 @@ pub const Block = struct {...@@ -31,7 +31,7 @@ pub const Block = struct {
31 const zero = @Vector(2, u64){ 0, 0 };31 const zero = @Vector(2, u64){ 0, 0 };
3232
33 /// Encrypt a block with a round key.33 /// Encrypt a block with a round key.
34 pub inline fn encrypt(block: Block, round_key: Block) Block {34 pub fn encrypt(block: Block, round_key: Block) Block {
35 return Block{35 return Block{
36 .repr = (asm (36 .repr = (asm (
37 \\ mov %[out].16b, %[in].16b37 \\ mov %[out].16b, %[in].16b
...@@ -45,7 +45,7 @@ pub const Block = struct {...@@ -45,7 +45,7 @@ pub const Block = struct {
45 }45 }
4646
47 /// Encrypt a block with the last round key.47 /// Encrypt a block with the last round key.
48 pub inline fn encryptLast(block: Block, round_key: Block) Block {48 pub fn encryptLast(block: Block, round_key: Block) Block {
49 return Block{49 return Block{
50 .repr = (asm (50 .repr = (asm (
51 \\ mov %[out].16b, %[in].16b51 \\ mov %[out].16b, %[in].16b
...@@ -58,7 +58,7 @@ pub const Block = struct {...@@ -58,7 +58,7 @@ pub const Block = struct {
58 }58 }
5959
60 /// Decrypt a block with a round key.60 /// Decrypt a block with a round key.
61 pub inline fn decrypt(block: Block, inv_round_key: Block) Block {61 pub fn decrypt(block: Block, inv_round_key: Block) Block {
62 return Block{62 return Block{
63 .repr = (asm (63 .repr = (asm (
64 \\ mov %[out].16b, %[in].16b64 \\ mov %[out].16b, %[in].16b
...@@ -72,7 +72,7 @@ pub const Block = struct {...@@ -72,7 +72,7 @@ pub const Block = struct {
72 }72 }
7373
74 /// Decrypt a block with the last round key.74 /// Decrypt a block with the last round key.
75 pub inline fn decryptLast(block: Block, inv_round_key: Block) Block {75 pub fn decryptLast(block: Block, inv_round_key: Block) Block {
76 return Block{76 return Block{
77 .repr = (asm (77 .repr = (asm (
78 \\ mov %[out].16b, %[in].16b78 \\ mov %[out].16b, %[in].16b
...@@ -85,17 +85,17 @@ pub const Block = struct {...@@ -85,17 +85,17 @@ pub const Block = struct {
85 }85 }
8686
87 /// Apply the bitwise XOR operation to the content of two blocks.87 /// Apply the bitwise XOR operation to the content of two blocks.
88 pub inline fn xorBlocks(block1: Block, block2: Block) Block {88 pub fn xorBlocks(block1: Block, block2: Block) Block {
89 return Block{ .repr = block1.repr ^ block2.repr };89 return Block{ .repr = block1.repr ^ block2.repr };
90 }90 }
9191
92 /// Apply the bitwise AND operation to the content of two blocks.92 /// Apply the bitwise AND operation to the content of two blocks.
93 pub inline fn andBlocks(block1: Block, block2: Block) Block {93 pub fn andBlocks(block1: Block, block2: Block) Block {
94 return Block{ .repr = block1.repr & block2.repr };94 return Block{ .repr = block1.repr & block2.repr };
95 }95 }
9696
97 /// Apply the bitwise OR operation to the content of two blocks.97 /// Apply the bitwise OR operation to the content of two blocks.
98 pub inline fn orBlocks(block1: Block, block2: Block) Block {98 pub fn orBlocks(block1: Block, block2: Block) Block {
99 return Block{ .repr = block1.repr | block2.repr };99 return Block{ .repr = block1.repr | block2.repr };
100 }100 }
101101
...@@ -105,7 +105,7 @@ pub const Block = struct {...@@ -105,7 +105,7 @@ pub const Block = struct {
105 pub const optimal_parallel_blocks = 6;105 pub const optimal_parallel_blocks = 6;
106106
107 /// Encrypt multiple blocks in parallel, each their own round key.107 /// Encrypt multiple blocks in parallel, each their own round key.
108 pub inline fn encryptParallel(comptime count: usize, blocks: [count]Block, round_keys: [count]Block) [count]Block {108 pub fn encryptParallel(comptime count: usize, blocks: [count]Block, round_keys: [count]Block) [count]Block {
109 comptime var i = 0;109 comptime var i = 0;
110 var out: [count]Block = undefined;110 var out: [count]Block = undefined;
111 inline while (i < count) : (i += 1) {111 inline while (i < count) : (i += 1) {
...@@ -115,7 +115,7 @@ pub const Block = struct {...@@ -115,7 +115,7 @@ pub const Block = struct {
115 }115 }
116116
117 /// Decrypt multiple blocks in parallel, each their own round key.117 /// Decrypt multiple blocks in parallel, each their own round key.
118 pub inline fn decryptParallel(comptime count: usize, blocks: [count]Block, round_keys: [count]Block) [count]Block {118 pub fn decryptParallel(comptime count: usize, blocks: [count]Block, round_keys: [count]Block) [count]Block {
119 comptime var i = 0;119 comptime var i = 0;
120 var out: [count]Block = undefined;120 var out: [count]Block = undefined;
121 inline while (i < count) : (i += 1) {121 inline while (i < count) : (i += 1) {
...@@ -125,7 +125,7 @@ pub const Block = struct {...@@ -125,7 +125,7 @@ pub const Block = struct {
125 }125 }
126126
127 /// Encrypt multiple blocks in parallel with the same round key.127 /// Encrypt multiple blocks in parallel with the same round key.
128 pub inline fn encryptWide(comptime count: usize, blocks: [count]Block, round_key: Block) [count]Block {128 pub fn encryptWide(comptime count: usize, blocks: [count]Block, round_key: Block) [count]Block {
129 comptime var i = 0;129 comptime var i = 0;
130 var out: [count]Block = undefined;130 var out: [count]Block = undefined;
131 inline while (i < count) : (i += 1) {131 inline while (i < count) : (i += 1) {
...@@ -135,7 +135,7 @@ pub const Block = struct {...@@ -135,7 +135,7 @@ pub const Block = struct {
135 }135 }
136136
137 /// Decrypt multiple blocks in parallel with the same round key.137 /// Decrypt multiple blocks in parallel with the same round key.
138 pub inline fn decryptWide(comptime count: usize, blocks: [count]Block, round_key: Block) [count]Block {138 pub fn decryptWide(comptime count: usize, blocks: [count]Block, round_key: Block) [count]Block {
139 comptime var i = 0;139 comptime var i = 0;
140 var out: [count]Block = undefined;140 var out: [count]Block = undefined;
141 inline while (i < count) : (i += 1) {141 inline while (i < count) : (i += 1) {
...@@ -145,7 +145,7 @@ pub const Block = struct {...@@ -145,7 +145,7 @@ pub const Block = struct {
145 }145 }
146146
147 /// Encrypt multiple blocks in parallel with the same last round key.147 /// Encrypt multiple blocks in parallel with the same last round key.
148 pub inline fn encryptLastWide(comptime count: usize, blocks: [count]Block, round_key: Block) [count]Block {148 pub fn encryptLastWide(comptime count: usize, blocks: [count]Block, round_key: Block) [count]Block {
149 comptime var i = 0;149 comptime var i = 0;
150 var out: [count]Block = undefined;150 var out: [count]Block = undefined;
151 inline while (i < count) : (i += 1) {151 inline while (i < count) : (i += 1) {
...@@ -155,7 +155,7 @@ pub const Block = struct {...@@ -155,7 +155,7 @@ pub const Block = struct {
155 }155 }
156156
157 /// Decrypt multiple blocks in parallel with the same last round key.157 /// Decrypt multiple blocks in parallel with the same last round key.
158 pub inline fn decryptLastWide(comptime count: usize, blocks: [count]Block, round_key: Block) [count]Block {158 pub fn decryptLastWide(comptime count: usize, blocks: [count]Block, round_key: Block) [count]Block {
159 comptime var i = 0;159 comptime var i = 0;
160 var out: [count]Block = undefined;160 var out: [count]Block = undefined;
161 inline while (i < count) : (i += 1) {161 inline while (i < count) : (i += 1) {
...@@ -187,7 +187,7 @@ pub fn BlockVec(comptime blocks_count: comptime_int) type {...@@ -187,7 +187,7 @@ pub fn BlockVec(comptime blocks_count: comptime_int) type {
187 pub const block_length: usize = blocks_count * 16;187 pub const block_length: usize = blocks_count * 16;
188188
189 /// Convert a byte sequence into an internal representation.189 /// Convert a byte sequence into an internal representation.
190 pub inline fn fromBytes(bytes: *const [blocks_count * 16]u8) Self {190 pub fn fromBytes(bytes: *const [blocks_count * 16]u8) Self {
191 var out: Self = undefined;191 var out: Self = undefined;
192 inline for (0..native_words) |i| {192 inline for (0..native_words) |i| {
193 out.repr[i] = Block.fromBytes(bytes[i * native_word_size ..][0..native_word_size]);193 out.repr[i] = Block.fromBytes(bytes[i * native_word_size ..][0..native_word_size]);
...@@ -196,7 +196,7 @@ pub fn BlockVec(comptime blocks_count: comptime_int) type {...@@ -196,7 +196,7 @@ pub fn BlockVec(comptime blocks_count: comptime_int) type {
196 }196 }
197197
198 /// Convert the internal representation of a block vector into a byte sequence.198 /// Convert the internal representation of a block vector into a byte sequence.
199 pub inline fn toBytes(block_vec: Self) [blocks_count * 16]u8 {199 pub fn toBytes(block_vec: Self) [blocks_count * 16]u8 {
200 var out: [blocks_count * 16]u8 = undefined;200 var out: [blocks_count * 16]u8 = undefined;
201 inline for (0..native_words) |i| {201 inline for (0..native_words) |i| {
202 out[i * native_word_size ..][0..native_word_size].* = block_vec.repr[i].toBytes();202 out[i * native_word_size ..][0..native_word_size].* = block_vec.repr[i].toBytes();
...@@ -205,7 +205,7 @@ pub fn BlockVec(comptime blocks_count: comptime_int) type {...@@ -205,7 +205,7 @@ pub fn BlockVec(comptime blocks_count: comptime_int) type {
205 }205 }
206206
207 /// XOR the block vector with a byte sequence.207 /// XOR the block vector with a byte sequence.
208 pub inline fn xorBytes(block_vec: Self, bytes: *const [blocks_count * 16]u8) [32]u8 {208 pub fn xorBytes(block_vec: Self, bytes: *const [blocks_count * 16]u8) [32]u8 {
209 var out: Self = undefined;209 var out: Self = undefined;
210 inline for (0..native_words) |i| {210 inline for (0..native_words) |i| {
211 out.repr[i] = block_vec.repr[i].xorBytes(bytes[i * native_word_size ..][0..native_word_size]);211 out.repr[i] = block_vec.repr[i].xorBytes(bytes[i * native_word_size ..][0..native_word_size]);
...@@ -214,7 +214,7 @@ pub fn BlockVec(comptime blocks_count: comptime_int) type {...@@ -214,7 +214,7 @@ pub fn BlockVec(comptime blocks_count: comptime_int) type {
214 }214 }
215215
216 /// Apply the forward AES operation to the block vector with a vector of round keys.216 /// Apply the forward AES operation to the block vector with a vector of round keys.
217 pub inline fn encrypt(block_vec: Self, round_key_vec: Self) Self {217 pub fn encrypt(block_vec: Self, round_key_vec: Self) Self {
218 var out: Self = undefined;218 var out: Self = undefined;
219 inline for (0..native_words) |i| {219 inline for (0..native_words) |i| {
220 out.repr[i] = block_vec.repr[i].encrypt(round_key_vec.repr[i]);220 out.repr[i] = block_vec.repr[i].encrypt(round_key_vec.repr[i]);
...@@ -223,7 +223,7 @@ pub fn BlockVec(comptime blocks_count: comptime_int) type {...@@ -223,7 +223,7 @@ pub fn BlockVec(comptime blocks_count: comptime_int) type {
223 }223 }
224224
225 /// Apply the forward AES operation to the block vector with a vector of last round keys.225 /// Apply the forward AES operation to the block vector with a vector of last round keys.
226 pub inline fn encryptLast(block_vec: Self, round_key_vec: Self) Self {226 pub fn encryptLast(block_vec: Self, round_key_vec: Self) Self {
227 var out: Self = undefined;227 var out: Self = undefined;
228 inline for (0..native_words) |i| {228 inline for (0..native_words) |i| {
229 out.repr[i] = block_vec.repr[i].encryptLast(round_key_vec.repr[i]);229 out.repr[i] = block_vec.repr[i].encryptLast(round_key_vec.repr[i]);
...@@ -232,7 +232,7 @@ pub fn BlockVec(comptime blocks_count: comptime_int) type {...@@ -232,7 +232,7 @@ pub fn BlockVec(comptime blocks_count: comptime_int) type {
232 }232 }
233233
234 /// Apply the inverse AES operation to the block vector with a vector of round keys.234 /// Apply the inverse AES operation to the block vector with a vector of round keys.
235 pub inline fn decrypt(block_vec: Self, inv_round_key_vec: Self) Self {235 pub fn decrypt(block_vec: Self, inv_round_key_vec: Self) Self {
236 var out: Self = undefined;236 var out: Self = undefined;
237 inline for (0..native_words) |i| {237 inline for (0..native_words) |i| {
238 out.repr[i] = block_vec.repr[i].decrypt(inv_round_key_vec.repr[i]);238 out.repr[i] = block_vec.repr[i].decrypt(inv_round_key_vec.repr[i]);
...@@ -241,7 +241,7 @@ pub fn BlockVec(comptime blocks_count: comptime_int) type {...@@ -241,7 +241,7 @@ pub fn BlockVec(comptime blocks_count: comptime_int) type {
241 }241 }
242242
243 /// Apply the inverse AES operation to the block vector with a vector of last round keys.243 /// Apply the inverse AES operation to the block vector with a vector of last round keys.
244 pub inline fn decryptLast(block_vec: Self, inv_round_key_vec: Self) Self {244 pub fn decryptLast(block_vec: Self, inv_round_key_vec: Self) Self {
245 var out: Self = undefined;245 var out: Self = undefined;
246 inline for (0..native_words) |i| {246 inline for (0..native_words) |i| {
247 out.repr[i] = block_vec.repr[i].decryptLast(inv_round_key_vec.repr[i]);247 out.repr[i] = block_vec.repr[i].decryptLast(inv_round_key_vec.repr[i]);
...@@ -250,7 +250,7 @@ pub fn BlockVec(comptime blocks_count: comptime_int) type {...@@ -250,7 +250,7 @@ pub fn BlockVec(comptime blocks_count: comptime_int) type {
250 }250 }
251251
252 /// Apply the bitwise XOR operation to the content of two block vectors.252 /// Apply the bitwise XOR operation to the content of two block vectors.
253 pub inline fn xorBlocks(block_vec1: Self, block_vec2: Self) Self {253 pub fn xorBlocks(block_vec1: Self, block_vec2: Self) Self {
254 var out: Self = undefined;254 var out: Self = undefined;
255 inline for (0..native_words) |i| {255 inline for (0..native_words) |i| {
256 out.repr[i] = block_vec1.repr[i].xorBlocks(block_vec2.repr[i]);256 out.repr[i] = block_vec1.repr[i].xorBlocks(block_vec2.repr[i]);
...@@ -259,7 +259,7 @@ pub fn BlockVec(comptime blocks_count: comptime_int) type {...@@ -259,7 +259,7 @@ pub fn BlockVec(comptime blocks_count: comptime_int) type {
259 }259 }
260260
261 /// Apply the bitwise AND operation to the content of two block vectors.261 /// Apply the bitwise AND operation to the content of two block vectors.
262 pub inline fn andBlocks(block_vec1: Self, block_vec2: Self) Self {262 pub fn andBlocks(block_vec1: Self, block_vec2: Self) Self {
263 var out: Self = undefined;263 var out: Self = undefined;
264 inline for (0..native_words) |i| {264 inline for (0..native_words) |i| {
265 out.repr[i] = block_vec1.repr[i].andBlocks(block_vec2.repr[i]);265 out.repr[i] = block_vec1.repr[i].andBlocks(block_vec2.repr[i]);
...@@ -268,7 +268,7 @@ pub fn BlockVec(comptime blocks_count: comptime_int) type {...@@ -268,7 +268,7 @@ pub fn BlockVec(comptime blocks_count: comptime_int) type {
268 }268 }
269269
270 /// Apply the bitwise OR operation to the content of two block vectors.270 /// Apply the bitwise OR operation to the content of two block vectors.
271 pub inline fn orBlocks(block_vec1: Self, block_vec2: Block) Self {271 pub fn orBlocks(block_vec1: Self, block_vec2: Block) Self {
272 var out: Self = undefined;272 var out: Self = undefined;
273 inline for (0..native_words) |i| {273 inline for (0..native_words) |i| {
274 out.repr[i] = block_vec1.repr[i].orBlocks(block_vec2.repr[i]);274 out.repr[i] = block_vec1.repr[i].orBlocks(block_vec2.repr[i]);
lib/std/crypto/aes/soft.zig+22-22
...@@ -14,7 +14,7 @@ pub const Block = struct {...@@ -14,7 +14,7 @@ pub const Block = struct {
14 repr: Repr align(16),14 repr: Repr align(16),
1515
16 /// Convert a byte sequence into an internal representation.16 /// Convert a byte sequence into an internal representation.
17 pub inline fn fromBytes(bytes: *const [16]u8) Block {17 pub fn fromBytes(bytes: *const [16]u8) Block {
18 const s0 = mem.readInt(u32, bytes[0..4], .little);18 const s0 = mem.readInt(u32, bytes[0..4], .little);
19 const s1 = mem.readInt(u32, bytes[4..8], .little);19 const s1 = mem.readInt(u32, bytes[4..8], .little);
20 const s2 = mem.readInt(u32, bytes[8..12], .little);20 const s2 = mem.readInt(u32, bytes[8..12], .little);
...@@ -23,7 +23,7 @@ pub const Block = struct {...@@ -23,7 +23,7 @@ pub const Block = struct {
23 }23 }
2424
25 /// Convert the internal representation of a block into a byte sequence.25 /// Convert the internal representation of a block into a byte sequence.
26 pub inline fn toBytes(block: Block) [16]u8 {26 pub fn toBytes(block: Block) [16]u8 {
27 var bytes: [16]u8 = undefined;27 var bytes: [16]u8 = undefined;
28 mem.writeInt(u32, bytes[0..4], block.repr[0], .little);28 mem.writeInt(u32, bytes[0..4], block.repr[0], .little);
29 mem.writeInt(u32, bytes[4..8], block.repr[1], .little);29 mem.writeInt(u32, bytes[4..8], block.repr[1], .little);
...@@ -33,7 +33,7 @@ pub const Block = struct {...@@ -33,7 +33,7 @@ pub const Block = struct {
33 }33 }
3434
35 /// XOR the block with a byte sequence.35 /// XOR the block with a byte sequence.
36 pub inline fn xorBytes(block: Block, bytes: *const [16]u8) [16]u8 {36 pub fn xorBytes(block: Block, bytes: *const [16]u8) [16]u8 {
37 const block_bytes = block.toBytes();37 const block_bytes = block.toBytes();
38 var x: [16]u8 = undefined;38 var x: [16]u8 = undefined;
39 comptime var i: usize = 0;39 comptime var i: usize = 0;
...@@ -44,7 +44,7 @@ pub const Block = struct {...@@ -44,7 +44,7 @@ pub const Block = struct {
44 }44 }
4545
46 /// Encrypt a block with a round key.46 /// Encrypt a block with a round key.
47 pub inline fn encrypt(block: Block, round_key: Block) Block {47 pub fn encrypt(block: Block, round_key: Block) Block {
48 const s0 = block.repr[0];48 const s0 = block.repr[0];
49 const s1 = block.repr[1];49 const s1 = block.repr[1];
50 const s2 = block.repr[2];50 const s2 = block.repr[2];
...@@ -69,7 +69,7 @@ pub const Block = struct {...@@ -69,7 +69,7 @@ pub const Block = struct {
69 }69 }
7070
71 /// Encrypt a block with a round key *WITHOUT ANY PROTECTION AGAINST SIDE CHANNELS*71 /// Encrypt a block with a round key *WITHOUT ANY PROTECTION AGAINST SIDE CHANNELS*
72 pub inline fn encryptUnprotected(block: Block, round_key: Block) Block {72 pub fn encryptUnprotected(block: Block, round_key: Block) Block {
73 const s0 = block.repr[0];73 const s0 = block.repr[0];
74 const s1 = block.repr[1];74 const s1 = block.repr[1];
75 const s2 = block.repr[2];75 const s2 = block.repr[2];
...@@ -114,7 +114,7 @@ pub const Block = struct {...@@ -114,7 +114,7 @@ pub const Block = struct {
114 }114 }
115115
116 /// Encrypt a block with the last round key.116 /// Encrypt a block with the last round key.
117 pub inline fn encryptLast(block: Block, round_key: Block) Block {117 pub fn encryptLast(block: Block, round_key: Block) Block {
118 const s0 = block.repr[0];118 const s0 = block.repr[0];
119 const s1 = block.repr[1];119 const s1 = block.repr[1];
120 const s2 = block.repr[2];120 const s2 = block.repr[2];
...@@ -140,7 +140,7 @@ pub const Block = struct {...@@ -140,7 +140,7 @@ pub const Block = struct {
140 }140 }
141141
142 /// Decrypt a block with a round key.142 /// Decrypt a block with a round key.
143 pub inline fn decrypt(block: Block, round_key: Block) Block {143 pub fn decrypt(block: Block, round_key: Block) Block {
144 const s0 = block.repr[0];144 const s0 = block.repr[0];
145 const s1 = block.repr[1];145 const s1 = block.repr[1];
146 const s2 = block.repr[2];146 const s2 = block.repr[2];
...@@ -165,7 +165,7 @@ pub const Block = struct {...@@ -165,7 +165,7 @@ pub const Block = struct {
165 }165 }
166166
167 /// Decrypt a block with a round key *WITHOUT ANY PROTECTION AGAINST SIDE CHANNELS*167 /// Decrypt a block with a round key *WITHOUT ANY PROTECTION AGAINST SIDE CHANNELS*
168 pub inline fn decryptUnprotected(block: Block, round_key: Block) Block {168 pub fn decryptUnprotected(block: Block, round_key: Block) Block {
169 const s0 = block.repr[0];169 const s0 = block.repr[0];
170 const s1 = block.repr[1];170 const s1 = block.repr[1];
171 const s2 = block.repr[2];171 const s2 = block.repr[2];
...@@ -210,7 +210,7 @@ pub const Block = struct {...@@ -210,7 +210,7 @@ pub const Block = struct {
210 }210 }
211211
212 /// Decrypt a block with the last round key.212 /// Decrypt a block with the last round key.
213 pub inline fn decryptLast(block: Block, round_key: Block) Block {213 pub fn decryptLast(block: Block, round_key: Block) Block {
214 const s0 = block.repr[0];214 const s0 = block.repr[0];
215 const s1 = block.repr[1];215 const s1 = block.repr[1];
216 const s2 = block.repr[2];216 const s2 = block.repr[2];
...@@ -236,7 +236,7 @@ pub const Block = struct {...@@ -236,7 +236,7 @@ pub const Block = struct {
236 }236 }
237237
238 /// Apply the bitwise XOR operation to the content of two blocks.238 /// Apply the bitwise XOR operation to the content of two blocks.
239 pub inline fn xorBlocks(block1: Block, block2: Block) Block {239 pub fn xorBlocks(block1: Block, block2: Block) Block {
240 var x: Repr = undefined;240 var x: Repr = undefined;
241 comptime var i = 0;241 comptime var i = 0;
242 inline while (i < 4) : (i += 1) {242 inline while (i < 4) : (i += 1) {
...@@ -246,7 +246,7 @@ pub const Block = struct {...@@ -246,7 +246,7 @@ pub const Block = struct {
246 }246 }
247247
248 /// Apply the bitwise AND operation to the content of two blocks.248 /// Apply the bitwise AND operation to the content of two blocks.
249 pub inline fn andBlocks(block1: Block, block2: Block) Block {249 pub fn andBlocks(block1: Block, block2: Block) Block {
250 var x: Repr = undefined;250 var x: Repr = undefined;
251 comptime var i = 0;251 comptime var i = 0;
252 inline while (i < 4) : (i += 1) {252 inline while (i < 4) : (i += 1) {
...@@ -256,7 +256,7 @@ pub const Block = struct {...@@ -256,7 +256,7 @@ pub const Block = struct {
256 }256 }
257257
258 /// Apply the bitwise OR operation to the content of two blocks.258 /// Apply the bitwise OR operation to the content of two blocks.
259 pub inline fn orBlocks(block1: Block, block2: Block) Block {259 pub fn orBlocks(block1: Block, block2: Block) Block {
260 var x: Repr = undefined;260 var x: Repr = undefined;
261 comptime var i = 0;261 comptime var i = 0;
262 inline while (i < 4) : (i += 1) {262 inline while (i < 4) : (i += 1) {
...@@ -353,7 +353,7 @@ pub fn BlockVec(comptime blocks_count: comptime_int) type {...@@ -353,7 +353,7 @@ pub fn BlockVec(comptime blocks_count: comptime_int) type {
353 pub const block_length: usize = blocks_count * 16;353 pub const block_length: usize = blocks_count * 16;
354354
355 /// Convert a byte sequence into an internal representation.355 /// Convert a byte sequence into an internal representation.
356 pub inline fn fromBytes(bytes: *const [blocks_count * 16]u8) Self {356 pub fn fromBytes(bytes: *const [blocks_count * 16]u8) Self {
357 var out: Self = undefined;357 var out: Self = undefined;
358 for (0..native_words) |i| {358 for (0..native_words) |i| {
359 out.repr[i] = Block.fromBytes(bytes[i * native_word_size ..][0..native_word_size]);359 out.repr[i] = Block.fromBytes(bytes[i * native_word_size ..][0..native_word_size]);
...@@ -362,7 +362,7 @@ pub fn BlockVec(comptime blocks_count: comptime_int) type {...@@ -362,7 +362,7 @@ pub fn BlockVec(comptime blocks_count: comptime_int) type {
362 }362 }
363363
364 /// Convert the internal representation of a block vector into a byte sequence.364 /// Convert the internal representation of a block vector into a byte sequence.
365 pub inline fn toBytes(block_vec: Self) [blocks_count * 16]u8 {365 pub fn toBytes(block_vec: Self) [blocks_count * 16]u8 {
366 var out: [blocks_count * 16]u8 = undefined;366 var out: [blocks_count * 16]u8 = undefined;
367 for (0..native_words) |i| {367 for (0..native_words) |i| {
368 out[i * native_word_size ..][0..native_word_size].* = block_vec.repr[i].toBytes();368 out[i * native_word_size ..][0..native_word_size].* = block_vec.repr[i].toBytes();
...@@ -371,7 +371,7 @@ pub fn BlockVec(comptime blocks_count: comptime_int) type {...@@ -371,7 +371,7 @@ pub fn BlockVec(comptime blocks_count: comptime_int) type {
371 }371 }
372372
373 /// XOR the block vector with a byte sequence.373 /// XOR the block vector with a byte sequence.
374 pub inline fn xorBytes(block_vec: Self, bytes: *const [blocks_count * 16]u8) [32]u8 {374 pub fn xorBytes(block_vec: Self, bytes: *const [blocks_count * 16]u8) [32]u8 {
375 var out: Self = undefined;375 var out: Self = undefined;
376 for (0..native_words) |i| {376 for (0..native_words) |i| {
377 out.repr[i] = block_vec.repr[i].xorBytes(bytes[i * native_word_size ..][0..native_word_size]);377 out.repr[i] = block_vec.repr[i].xorBytes(bytes[i * native_word_size ..][0..native_word_size]);
...@@ -380,7 +380,7 @@ pub fn BlockVec(comptime blocks_count: comptime_int) type {...@@ -380,7 +380,7 @@ pub fn BlockVec(comptime blocks_count: comptime_int) type {
380 }380 }
381381
382 /// Apply the forward AES operation to the block vector with a vector of round keys.382 /// Apply the forward AES operation to the block vector with a vector of round keys.
383 pub inline fn encrypt(block_vec: Self, round_key_vec: Self) Self {383 pub fn encrypt(block_vec: Self, round_key_vec: Self) Self {
384 var out: Self = undefined;384 var out: Self = undefined;
385 for (0..native_words) |i| {385 for (0..native_words) |i| {
386 out.repr[i] = block_vec.repr[i].encrypt(round_key_vec.repr[i]);386 out.repr[i] = block_vec.repr[i].encrypt(round_key_vec.repr[i]);
...@@ -389,7 +389,7 @@ pub fn BlockVec(comptime blocks_count: comptime_int) type {...@@ -389,7 +389,7 @@ pub fn BlockVec(comptime blocks_count: comptime_int) type {
389 }389 }
390390
391 /// Apply the forward AES operation to the block vector with a vector of last round keys.391 /// Apply the forward AES operation to the block vector with a vector of last round keys.
392 pub inline fn encryptLast(block_vec: Self, round_key_vec: Self) Self {392 pub fn encryptLast(block_vec: Self, round_key_vec: Self) Self {
393 var out: Self = undefined;393 var out: Self = undefined;
394 for (0..native_words) |i| {394 for (0..native_words) |i| {
395 out.repr[i] = block_vec.repr[i].encryptLast(round_key_vec.repr[i]);395 out.repr[i] = block_vec.repr[i].encryptLast(round_key_vec.repr[i]);
...@@ -398,7 +398,7 @@ pub fn BlockVec(comptime blocks_count: comptime_int) type {...@@ -398,7 +398,7 @@ pub fn BlockVec(comptime blocks_count: comptime_int) type {
398 }398 }
399399
400 /// Apply the inverse AES operation to the block vector with a vector of round keys.400 /// Apply the inverse AES operation to the block vector with a vector of round keys.
401 pub inline fn decrypt(block_vec: Self, inv_round_key_vec: Self) Self {401 pub fn decrypt(block_vec: Self, inv_round_key_vec: Self) Self {
402 var out: Self = undefined;402 var out: Self = undefined;
403 for (0..native_words) |i| {403 for (0..native_words) |i| {
404 out.repr[i] = block_vec.repr[i].decrypt(inv_round_key_vec.repr[i]);404 out.repr[i] = block_vec.repr[i].decrypt(inv_round_key_vec.repr[i]);
...@@ -407,7 +407,7 @@ pub fn BlockVec(comptime blocks_count: comptime_int) type {...@@ -407,7 +407,7 @@ pub fn BlockVec(comptime blocks_count: comptime_int) type {
407 }407 }
408408
409 /// Apply the inverse AES operation to the block vector with a vector of last round keys.409 /// Apply the inverse AES operation to the block vector with a vector of last round keys.
410 pub inline fn decryptLast(block_vec: Self, inv_round_key_vec: Self) Self {410 pub fn decryptLast(block_vec: Self, inv_round_key_vec: Self) Self {
411 var out: Self = undefined;411 var out: Self = undefined;
412 for (0..native_words) |i| {412 for (0..native_words) |i| {
413 out.repr[i] = block_vec.repr[i].decryptLast(inv_round_key_vec.repr[i]);413 out.repr[i] = block_vec.repr[i].decryptLast(inv_round_key_vec.repr[i]);
...@@ -416,7 +416,7 @@ pub fn BlockVec(comptime blocks_count: comptime_int) type {...@@ -416,7 +416,7 @@ pub fn BlockVec(comptime blocks_count: comptime_int) type {
416 }416 }
417417
418 /// Apply the bitwise XOR operation to the content of two block vectors.418 /// Apply the bitwise XOR operation to the content of two block vectors.
419 pub inline fn xorBlocks(block_vec1: Self, block_vec2: Self) Self {419 pub fn xorBlocks(block_vec1: Self, block_vec2: Self) Self {
420 var out: Self = undefined;420 var out: Self = undefined;
421 for (0..native_words) |i| {421 for (0..native_words) |i| {
422 out.repr[i] = block_vec1.repr[i].xorBlocks(block_vec2.repr[i]);422 out.repr[i] = block_vec1.repr[i].xorBlocks(block_vec2.repr[i]);
...@@ -425,7 +425,7 @@ pub fn BlockVec(comptime blocks_count: comptime_int) type {...@@ -425,7 +425,7 @@ pub fn BlockVec(comptime blocks_count: comptime_int) type {
425 }425 }
426426
427 /// Apply the bitwise AND operation to the content of two block vectors.427 /// Apply the bitwise AND operation to the content of two block vectors.
428 pub inline fn andBlocks(block_vec1: Self, block_vec2: Self) Self {428 pub fn andBlocks(block_vec1: Self, block_vec2: Self) Self {
429 var out: Self = undefined;429 var out: Self = undefined;
430 for (0..native_words) |i| {430 for (0..native_words) |i| {
431 out.repr[i] = block_vec1.repr[i].andBlocks(block_vec2.repr[i]);431 out.repr[i] = block_vec1.repr[i].andBlocks(block_vec2.repr[i]);
...@@ -434,7 +434,7 @@ pub fn BlockVec(comptime blocks_count: comptime_int) type {...@@ -434,7 +434,7 @@ pub fn BlockVec(comptime blocks_count: comptime_int) type {
434 }434 }
435435
436 /// Apply the bitwise OR operation to the content of two block vectors.436 /// Apply the bitwise OR operation to the content of two block vectors.
437 pub inline fn orBlocks(block_vec1: Self, block_vec2: Block) Self {437 pub fn orBlocks(block_vec1: Self, block_vec2: Block) Self {
438 var out: Self = undefined;438 var out: Self = undefined;
439 for (0..native_words) |i| {439 for (0..native_words) |i| {
440 out.repr[i] = block_vec1.repr[i].orBlocks(block_vec2.repr[i]);440 out.repr[i] = block_vec1.repr[i].orBlocks(block_vec2.repr[i]);
lib/std/crypto/aes_ocb.zig+3-3
...@@ -28,7 +28,7 @@ fn AesOcb(comptime Aes: anytype) type {...@@ -28,7 +28,7 @@ fn AesOcb(comptime Aes: anytype) type {
28 table: [56]Block align(16) = undefined,28 table: [56]Block align(16) = undefined,
29 upto: usize,29 upto: usize,
3030
31 inline fn double(l: Block) Block {31 fn double(l: Block) Block {
32 const l_ = mem.readInt(u128, &l, .big);32 const l_ = mem.readInt(u128, &l, .big);
33 const l_2 = (l_ << 1) ^ (0x87 & -%(l_ >> 127));33 const l_2 = (l_ << 1) ^ (0x87 & -%(l_ >> 127));
34 var l2: Block = undefined;34 var l2: Block = undefined;
...@@ -244,7 +244,7 @@ fn AesOcb(comptime Aes: anytype) type {...@@ -244,7 +244,7 @@ fn AesOcb(comptime Aes: anytype) type {
244 };244 };
245}245}
246246
247inline fn xorBlocks(x: Block, y: Block) Block {247fn xorBlocks(x: Block, y: Block) Block {
248 var z: Block = x;248 var z: Block = x;
249 for (&z, 0..) |*v, i| {249 for (&z, 0..) |*v, i| {
250 v.* = x[i] ^ y[i];250 v.* = x[i] ^ y[i];
...@@ -252,7 +252,7 @@ inline fn xorBlocks(x: Block, y: Block) Block {...@@ -252,7 +252,7 @@ inline fn xorBlocks(x: Block, y: Block) Block {
252 return z;252 return z;
253}253}
254254
255inline fn xorWith(x: *Block, y: Block) void {255fn xorWith(x: *Block, y: Block) void {
256 for (x, 0..) |*v, i| {256 for (x, 0..) |*v, i| {
257 v.* ^= y[i];257 v.* ^= y[i];
258 }258 }
lib/std/crypto/ascon.zig+4-4
...@@ -157,7 +157,7 @@ pub fn State(comptime endian: std.builtin.Endian) type {...@@ -157,7 +157,7 @@ pub fn State(comptime endian: std.builtin.Endian) type {
157 }157 }
158158
159 /// Apply a reduced-round permutation to the state.159 /// Apply a reduced-round permutation to the state.
160 pub inline fn permuteR(state: *Self, comptime rounds: u4) void {160 pub fn permuteR(state: *Self, comptime rounds: u4) void {
161 const rks = [16]u64{ 0x3c, 0x2d, 0x1e, 0x0f, 0xf0, 0xe1, 0xd2, 0xc3, 0xb4, 0xa5, 0x96, 0x87, 0x78, 0x69, 0x5a, 0x4b };161 const rks = [16]u64{ 0x3c, 0x2d, 0x1e, 0x0f, 0xf0, 0xe1, 0xd2, 0xc3, 0xb4, 0xa5, 0x96, 0x87, 0x78, 0x69, 0x5a, 0x4b };
162 inline for (rks[rks.len - rounds ..]) |rk| {162 inline for (rks[rks.len - rounds ..]) |rk| {
163 state.round(rk);163 state.round(rk);
...@@ -165,13 +165,13 @@ pub fn State(comptime endian: std.builtin.Endian) type {...@@ -165,13 +165,13 @@ pub fn State(comptime endian: std.builtin.Endian) type {
165 }165 }
166166
167 /// Apply a full-round permutation to the state.167 /// Apply a full-round permutation to the state.
168 pub inline fn permute(state: *Self) void {168 pub fn permute(state: *Self) void {
169 state.permuteR(12);169 state.permuteR(12);
170 }170 }
171171
172 /// Apply a permutation to the state and prevent backtracking.172 /// Apply a permutation to the state and prevent backtracking.
173 /// The rate is expressed in bytes and must be a multiple of the word size (8).173 /// The rate is expressed in bytes and must be a multiple of the word size (8).
174 pub inline fn permuteRatchet(state: *Self, comptime rounds: u4, comptime rate: u6) void {174 pub fn permuteRatchet(state: *Self, comptime rounds: u4, comptime rate: u6) void {
175 const capacity = block_bytes - rate;175 const capacity = block_bytes - rate;
176 debug.assert(capacity > 0 and capacity % 8 == 0); // capacity must be a multiple of 64 bits176 debug.assert(capacity > 0 and capacity % 8 == 0); // capacity must be a multiple of 64 bits
177 var mask: [capacity / 8]u64 = undefined;177 var mask: [capacity / 8]u64 = undefined;
...@@ -181,7 +181,7 @@ pub fn State(comptime endian: std.builtin.Endian) type {...@@ -181,7 +181,7 @@ pub fn State(comptime endian: std.builtin.Endian) type {
181 }181 }
182182
183 // Core Ascon permutation.183 // Core Ascon permutation.
184 inline fn round(state: *Self, rk: u64) void {184 fn round(state: *Self, rk: u64) void {
185 const x = &state.st;185 const x = &state.st;
186 x[2] ^= rk;186 x[2] ^= rk;
187187
lib/std/crypto/blake3.zig+3-3
...@@ -61,7 +61,7 @@ const CompressVectorized = struct {...@@ -61,7 +61,7 @@ const CompressVectorized = struct {
61 const Lane = @Vector(4, u32);61 const Lane = @Vector(4, u32);
62 const Rows = [4]Lane;62 const Rows = [4]Lane;
6363
64 inline fn g(comptime even: bool, rows: *Rows, m: Lane) void {64 fn g(comptime even: bool, rows: *Rows, m: Lane) void {
65 rows[0] +%= rows[1] +% m;65 rows[0] +%= rows[1] +% m;
66 rows[3] ^= rows[0];66 rows[3] ^= rows[0];
67 rows[3] = math.rotr(Lane, rows[3], if (even) 8 else 16);67 rows[3] = math.rotr(Lane, rows[3], if (even) 8 else 16);
...@@ -70,13 +70,13 @@ const CompressVectorized = struct {...@@ -70,13 +70,13 @@ const CompressVectorized = struct {
70 rows[1] = math.rotr(Lane, rows[1], if (even) 7 else 12);70 rows[1] = math.rotr(Lane, rows[1], if (even) 7 else 12);
71 }71 }
7272
73 inline fn diagonalize(rows: *Rows) void {73 fn diagonalize(rows: *Rows) void {
74 rows[0] = @shuffle(u32, rows[0], undefined, [_]i32{ 3, 0, 1, 2 });74 rows[0] = @shuffle(u32, rows[0], undefined, [_]i32{ 3, 0, 1, 2 });
75 rows[3] = @shuffle(u32, rows[3], undefined, [_]i32{ 2, 3, 0, 1 });75 rows[3] = @shuffle(u32, rows[3], undefined, [_]i32{ 2, 3, 0, 1 });
76 rows[2] = @shuffle(u32, rows[2], undefined, [_]i32{ 1, 2, 3, 0 });76 rows[2] = @shuffle(u32, rows[2], undefined, [_]i32{ 1, 2, 3, 0 });
77 }77 }
7878
79 inline fn undiagonalize(rows: *Rows) void {79 fn undiagonalize(rows: *Rows) void {
80 rows[0] = @shuffle(u32, rows[0], undefined, [_]i32{ 1, 2, 3, 0 });80 rows[0] = @shuffle(u32, rows[0], undefined, [_]i32{ 1, 2, 3, 0 });
81 rows[3] = @shuffle(u32, rows[3], undefined, [_]i32{ 2, 3, 0, 1 });81 rows[3] = @shuffle(u32, rows[3], undefined, [_]i32{ 2, 3, 0, 1 });
82 rows[2] = @shuffle(u32, rows[2], undefined, [_]i32{ 3, 0, 1, 2 });82 rows[2] = @shuffle(u32, rows[2], undefined, [_]i32{ 3, 0, 1, 2 });
lib/std/crypto/chacha20.zig+6-6
...@@ -151,7 +151,7 @@ fn ChaChaVecImpl(comptime rounds_nb: usize, comptime degree: comptime_int) type...@@ -151,7 +151,7 @@ fn ChaChaVecImpl(comptime rounds_nb: usize, comptime degree: comptime_int) type
151 }151 }
152 }152 }
153153
154 inline fn chacha20Core(x: *BlockVec, input: BlockVec) void {154 fn chacha20Core(x: *BlockVec, input: BlockVec) void {
155 x.* = input;155 x.* = input;
156156
157 const m0 = switch (degree) {157 const m0 = switch (degree) {
...@@ -215,7 +215,7 @@ fn ChaChaVecImpl(comptime rounds_nb: usize, comptime degree: comptime_int) type...@@ -215,7 +215,7 @@ fn ChaChaVecImpl(comptime rounds_nb: usize, comptime degree: comptime_int) type
215 }215 }
216 }216 }
217217
218 inline fn hashToBytes(comptime dm: usize, out: *[64 * dm]u8, x: BlockVec) void {218 fn hashToBytes(comptime dm: usize, out: *[64 * dm]u8, x: BlockVec) void {
219 for (0..dm) |d| {219 for (0..dm) |d| {
220 for (0..4) |i| {220 for (0..4) |i| {
221 mem.writeInt(u32, out[64 * d + 16 * i + 0 ..][0..4], x[i][0 + 4 * d], .little);221 mem.writeInt(u32, out[64 * d + 16 * i + 0 ..][0..4], x[i][0 + 4 * d], .little);
...@@ -226,7 +226,7 @@ fn ChaChaVecImpl(comptime rounds_nb: usize, comptime degree: comptime_int) type...@@ -226,7 +226,7 @@ fn ChaChaVecImpl(comptime rounds_nb: usize, comptime degree: comptime_int) type
226 }226 }
227 }227 }
228228
229 inline fn contextFeedback(x: *BlockVec, ctx: BlockVec) void {229 fn contextFeedback(x: *BlockVec, ctx: BlockVec) void {
230 x[0] +%= ctx[0];230 x[0] +%= ctx[0];
231 x[1] +%= ctx[1];231 x[1] +%= ctx[1];
232 x[2] +%= ctx[2];232 x[2] +%= ctx[2];
...@@ -365,7 +365,7 @@ fn ChaChaNonVecImpl(comptime rounds_nb: usize) type {...@@ -365,7 +365,7 @@ fn ChaChaNonVecImpl(comptime rounds_nb: usize) type {
365 };365 };
366 }366 }
367367
368 inline fn chacha20Core(x: *BlockVec, input: BlockVec) void {368 fn chacha20Core(x: *BlockVec, input: BlockVec) void {
369 x.* = input;369 x.* = input;
370370
371 const rounds = comptime [_]QuarterRound{371 const rounds = comptime [_]QuarterRound{
...@@ -394,7 +394,7 @@ fn ChaChaNonVecImpl(comptime rounds_nb: usize) type {...@@ -394,7 +394,7 @@ fn ChaChaNonVecImpl(comptime rounds_nb: usize) type {
394 }394 }
395 }395 }
396396
397 inline fn hashToBytes(out: *[64]u8, x: BlockVec) void {397 fn hashToBytes(out: *[64]u8, x: BlockVec) void {
398 for (0..4) |i| {398 for (0..4) |i| {
399 mem.writeInt(u32, out[16 * i + 0 ..][0..4], x[i * 4 + 0], .little);399 mem.writeInt(u32, out[16 * i + 0 ..][0..4], x[i * 4 + 0], .little);
400 mem.writeInt(u32, out[16 * i + 4 ..][0..4], x[i * 4 + 1], .little);400 mem.writeInt(u32, out[16 * i + 4 ..][0..4], x[i * 4 + 1], .little);
...@@ -403,7 +403,7 @@ fn ChaChaNonVecImpl(comptime rounds_nb: usize) type {...@@ -403,7 +403,7 @@ fn ChaChaNonVecImpl(comptime rounds_nb: usize) type {
403 }403 }
404 }404 }
405405
406 inline fn contextFeedback(x: *BlockVec, ctx: BlockVec) void {406 fn contextFeedback(x: *BlockVec, ctx: BlockVec) void {
407 for (0..16) |i| {407 for (0..16) |i| {
408 x[i] +%= ctx[i];408 x[i] +%= ctx[i];
409 }409 }
lib/std/crypto/codecs/base64_hex_ct.zig+7-7
...@@ -280,34 +280,34 @@ pub const base64 = struct {...@@ -280,34 +280,34 @@ pub const base64 = struct {
280 return DecoderWithIgnore{ .ignored_chars = ignored_chars };280 return DecoderWithIgnore{ .ignored_chars = ignored_chars };
281 }281 }
282282
283 inline fn eq(x: u8, y: u8) u8 {283 fn eq(x: u8, y: u8) u8 {
284 return ~@as(u8, @truncate((0 -% (@as(u16, x) ^ @as(u16, y))) >> 8));284 return ~@as(u8, @truncate((0 -% (@as(u16, x) ^ @as(u16, y))) >> 8));
285 }285 }
286286
287 inline fn gt(x: u8, y: u8) u8 {287 fn gt(x: u8, y: u8) u8 {
288 return @truncate((@as(u16, y) -% @as(u16, x)) >> 8);288 return @truncate((@as(u16, y) -% @as(u16, x)) >> 8);
289 }289 }
290290
291 inline fn ge(x: u8, y: u8) u8 {291 fn ge(x: u8, y: u8) u8 {
292 return ~gt(y, x);292 return ~gt(y, x);
293 }293 }
294294
295 inline fn lt(x: u8, y: u8) u8 {295 fn lt(x: u8, y: u8) u8 {
296 return gt(y, x);296 return gt(y, x);
297 }297 }
298298
299 inline fn le(x: u8, y: u8) u8 {299 fn le(x: u8, y: u8) u8 {
300 return ge(y, x);300 return ge(y, x);
301 }301 }
302302
303 inline fn charFromByte(x: u8, comptime urlsafe: bool) u8 {303 fn charFromByte(x: u8, comptime urlsafe: bool) u8 {
304 return (lt(x, 26) & (x +% 'A')) |304 return (lt(x, 26) & (x +% 'A')) |
305 (ge(x, 26) & lt(x, 52) & (x +% 'a' -% 26)) |305 (ge(x, 26) & lt(x, 52) & (x +% 'a' -% 26)) |
306 (ge(x, 52) & lt(x, 62) & (x +% '0' -% 52)) |306 (ge(x, 52) & lt(x, 62) & (x +% '0' -% 52)) |
307 (eq(x, 62) & '+') | (eq(x, 63) & if (urlsafe) '_' else '/');307 (eq(x, 62) & '+') | (eq(x, 63) & if (urlsafe) '_' else '/');
308 }308 }
309309
310 inline fn byteFromChar(c: u8, comptime urlsafe: bool) u8 {310 fn byteFromChar(c: u8, comptime urlsafe: bool) u8 {
311 const x =311 const x =
312 (ge(c, 'A') & le(c, 'Z') & (c -% 'A')) |312 (ge(c, 'A') & le(c, 'Z') & (c -% 'A')) |
313 (ge(c, 'a') & le(c, 'z') & (c -% 'a' +% 26)) |313 (ge(c, 'a') & le(c, 'z') & (c -% 'a' +% 26)) |
lib/std/crypto/ghash_polyval.zig+5-5
...@@ -89,7 +89,7 @@ fn Hash(comptime endian: std.builtin.Endian, comptime shift_key: bool) type {...@@ -89,7 +89,7 @@ fn Hash(comptime endian: std.builtin.Endian, comptime shift_key: bool) type {
89 const Selector = enum { lo, hi, hi_lo };89 const Selector = enum { lo, hi, hi_lo };
9090
91 // Carryless multiplication of two 64-bit integers for x86_64.91 // Carryless multiplication of two 64-bit integers for x86_64.
92 inline fn clmulPclmul(x: u128, y: u128, comptime half: Selector) u128 {92 fn clmulPclmul(x: u128, y: u128, comptime half: Selector) u128 {
93 switch (half) {93 switch (half) {
94 .hi => {94 .hi => {
95 const product = asm (95 const product = asm (
...@@ -122,7 +122,7 @@ fn Hash(comptime endian: std.builtin.Endian, comptime shift_key: bool) type {...@@ -122,7 +122,7 @@ fn Hash(comptime endian: std.builtin.Endian, comptime shift_key: bool) type {
122 }122 }
123123
124 // Carryless multiplication of two 64-bit integers for ARM crypto.124 // Carryless multiplication of two 64-bit integers for ARM crypto.
125 inline fn clmulPmull(x: u128, y: u128, comptime half: Selector) u128 {125 fn clmulPmull(x: u128, y: u128, comptime half: Selector) u128 {
126 switch (half) {126 switch (half) {
127 .hi => {127 .hi => {
128 const product = asm (128 const product = asm (
...@@ -231,7 +231,7 @@ fn Hash(comptime endian: std.builtin.Endian, comptime shift_key: bool) type {...@@ -231,7 +231,7 @@ fn Hash(comptime endian: std.builtin.Endian, comptime shift_key: bool) type {
231 mid: u128,231 mid: u128,
232 };232 };
233233
234 inline fn xor256(x: *I256, y: I256) void {234 fn xor256(x: *I256, y: I256) void {
235 x.* = I256{235 x.* = I256{
236 .hi = x.hi ^ y.hi,236 .hi = x.hi ^ y.hi,
237 .lo = x.lo ^ y.lo,237 .lo = x.lo ^ y.lo,
...@@ -249,7 +249,7 @@ fn Hash(comptime endian: std.builtin.Endian, comptime shift_key: bool) type {...@@ -249,7 +249,7 @@ fn Hash(comptime endian: std.builtin.Endian, comptime shift_key: bool) type {
249 }249 }
250250
251 // Multiply two 128-bit integers in GF(2^128).251 // Multiply two 128-bit integers in GF(2^128).
252 inline fn clmul128(x: u128, y: u128) I256 {252 fn clmul128(x: u128, y: u128) I256 {
253 if (mul_algorithm == .karatsuba) {253 if (mul_algorithm == .karatsuba) {
254 const x_hi = @as(u64, @truncate(x >> 64));254 const x_hi = @as(u64, @truncate(x >> 64));
255 const y_hi = @as(u64, @truncate(y >> 64));255 const y_hi = @as(u64, @truncate(y >> 64));
...@@ -273,7 +273,7 @@ fn Hash(comptime endian: std.builtin.Endian, comptime shift_key: bool) type {...@@ -273,7 +273,7 @@ fn Hash(comptime endian: std.builtin.Endian, comptime shift_key: bool) type {
273 // Reduce a 256-bit representative of a polynomial modulo the irreducible polynomial x^128 + x^127 + x^126 + x^121 + 1.273 // Reduce a 256-bit representative of a polynomial modulo the irreducible polynomial x^128 + x^127 + x^126 + x^121 + 1.
274 // This is done using Shay Gueron's black magic demysticated here:274 // This is done using Shay Gueron's black magic demysticated here:
275 // https://blog.quarkslab.com/reversing-a-finite-field-multiplication-optimization.html275 // https://blog.quarkslab.com/reversing-a-finite-field-multiplication-optimization.html
276 inline fn reduce(x: I256) u128 {276 fn reduce(x: I256) u128 {
277 const hi = x.hi ^ (x.mid >> 64);277 const hi = x.hi ^ (x.mid >> 64);
278 const lo = x.lo ^ (x.mid << 64);278 const lo = x.lo ^ (x.mid << 64);
279 const p64 = (((1 << 121) | (1 << 126) | (1 << 127)) >> 64);279 const p64 = (((1 << 121) | (1 << 126) | (1 << 127)) >> 64);
lib/std/crypto/pcurves/p256/p256_64.zig+4-4
...@@ -72,7 +72,7 @@ pub const NonMontgomeryDomainFieldElement = [4]u64;...@@ -72,7 +72,7 @@ pub const NonMontgomeryDomainFieldElement = [4]u64;
72/// Output Bounds:72/// Output Bounds:
73/// out1: [0x0 ~> 0xffffffffffffffff]73/// out1: [0x0 ~> 0xffffffffffffffff]
74/// out2: [0x0 ~> 0x1]74/// out2: [0x0 ~> 0x1]
75inline fn addcarryxU64(out1: *u64, out2: *u1, arg1: u1, arg2: u64, arg3: u64) void {75fn addcarryxU64(out1: *u64, out2: *u1, arg1: u1, arg2: u64, arg3: u64) void {
76 const x = @as(u128, arg2) +% arg3 +% arg1;76 const x = @as(u128, arg2) +% arg3 +% arg1;
77 out1.* = @truncate(x);77 out1.* = @truncate(x);
78 out2.* = @truncate(x >> 64);78 out2.* = @truncate(x >> 64);
...@@ -91,7 +91,7 @@ inline fn addcarryxU64(out1: *u64, out2: *u1, arg1: u1, arg2: u64, arg3: u64) vo...@@ -91,7 +91,7 @@ inline fn addcarryxU64(out1: *u64, out2: *u1, arg1: u1, arg2: u64, arg3: u64) vo
91/// Output Bounds:91/// Output Bounds:
92/// out1: [0x0 ~> 0xffffffffffffffff]92/// out1: [0x0 ~> 0xffffffffffffffff]
93/// out2: [0x0 ~> 0x1]93/// out2: [0x0 ~> 0x1]
94inline fn subborrowxU64(out1: *u64, out2: *u1, arg1: u1, arg2: u64, arg3: u64) void {94fn subborrowxU64(out1: *u64, out2: *u1, arg1: u1, arg2: u64, arg3: u64) void {
95 const x = @as(u128, arg2) -% arg3 -% arg1;95 const x = @as(u128, arg2) -% arg3 -% arg1;
96 out1.* = @truncate(x);96 out1.* = @truncate(x);
97 out2.* = @truncate(x >> 64);97 out2.* = @truncate(x >> 64);
...@@ -109,7 +109,7 @@ inline fn subborrowxU64(out1: *u64, out2: *u1, arg1: u1, arg2: u64, arg3: u64) v...@@ -109,7 +109,7 @@ inline fn subborrowxU64(out1: *u64, out2: *u1, arg1: u1, arg2: u64, arg3: u64) v
109/// Output Bounds:109/// Output Bounds:
110/// out1: [0x0 ~> 0xffffffffffffffff]110/// out1: [0x0 ~> 0xffffffffffffffff]
111/// out2: [0x0 ~> 0xffffffffffffffff]111/// out2: [0x0 ~> 0xffffffffffffffff]
112inline fn mulxU64(out1: *u64, out2: *u64, arg1: u64, arg2: u64) void {112fn mulxU64(out1: *u64, out2: *u64, arg1: u64, arg2: u64) void {
113 @setRuntimeSafety(mode == .Debug);113 @setRuntimeSafety(mode == .Debug);
114114
115 const x = @as(u128, arg1) * @as(u128, arg2);115 const x = @as(u128, arg1) * @as(u128, arg2);
...@@ -128,7 +128,7 @@ inline fn mulxU64(out1: *u64, out2: *u64, arg1: u64, arg2: u64) void {...@@ -128,7 +128,7 @@ inline fn mulxU64(out1: *u64, out2: *u64, arg1: u64, arg2: u64) void {
128/// arg3: [0x0 ~> 0xffffffffffffffff]128/// arg3: [0x0 ~> 0xffffffffffffffff]
129/// Output Bounds:129/// Output Bounds:
130/// out1: [0x0 ~> 0xffffffffffffffff]130/// out1: [0x0 ~> 0xffffffffffffffff]
131inline fn cmovznzU64(out1: *u64, arg1: u1, arg2: u64, arg3: u64) void {131fn cmovznzU64(out1: *u64, arg1: u1, arg2: u64, arg3: u64) void {
132 @setRuntimeSafety(mode == .Debug);132 @setRuntimeSafety(mode == .Debug);
133133
134 const mask = 0 -% @as(u64, arg1);134 const mask = 0 -% @as(u64, arg1);
lib/std/crypto/pcurves/p256/p256_scalar_64.zig+4-4
...@@ -72,7 +72,7 @@ pub const NonMontgomeryDomainFieldElement = [4]u64;...@@ -72,7 +72,7 @@ pub const NonMontgomeryDomainFieldElement = [4]u64;
72/// Output Bounds:72/// Output Bounds:
73/// out1: [0x0 ~> 0xffffffffffffffff]73/// out1: [0x0 ~> 0xffffffffffffffff]
74/// out2: [0x0 ~> 0x1]74/// out2: [0x0 ~> 0x1]
75inline fn addcarryxU64(out1: *u64, out2: *u1, arg1: u1, arg2: u64, arg3: u64) void {75fn addcarryxU64(out1: *u64, out2: *u1, arg1: u1, arg2: u64, arg3: u64) void {
76 const x = @as(u128, arg2) +% arg3 +% arg1;76 const x = @as(u128, arg2) +% arg3 +% arg1;
77 out1.* = @truncate(x);77 out1.* = @truncate(x);
78 out2.* = @truncate(x >> 64);78 out2.* = @truncate(x >> 64);
...@@ -91,7 +91,7 @@ inline fn addcarryxU64(out1: *u64, out2: *u1, arg1: u1, arg2: u64, arg3: u64) vo...@@ -91,7 +91,7 @@ inline fn addcarryxU64(out1: *u64, out2: *u1, arg1: u1, arg2: u64, arg3: u64) vo
91/// Output Bounds:91/// Output Bounds:
92/// out1: [0x0 ~> 0xffffffffffffffff]92/// out1: [0x0 ~> 0xffffffffffffffff]
93/// out2: [0x0 ~> 0x1]93/// out2: [0x0 ~> 0x1]
94inline fn subborrowxU64(out1: *u64, out2: *u1, arg1: u1, arg2: u64, arg3: u64) void {94fn subborrowxU64(out1: *u64, out2: *u1, arg1: u1, arg2: u64, arg3: u64) void {
95 const x = @as(u128, arg2) -% arg3 -% arg1;95 const x = @as(u128, arg2) -% arg3 -% arg1;
96 out1.* = @truncate(x);96 out1.* = @truncate(x);
97 out2.* = @truncate(x >> 64);97 out2.* = @truncate(x >> 64);
...@@ -109,7 +109,7 @@ inline fn subborrowxU64(out1: *u64, out2: *u1, arg1: u1, arg2: u64, arg3: u64) v...@@ -109,7 +109,7 @@ inline fn subborrowxU64(out1: *u64, out2: *u1, arg1: u1, arg2: u64, arg3: u64) v
109/// Output Bounds:109/// Output Bounds:
110/// out1: [0x0 ~> 0xffffffffffffffff]110/// out1: [0x0 ~> 0xffffffffffffffff]
111/// out2: [0x0 ~> 0xffffffffffffffff]111/// out2: [0x0 ~> 0xffffffffffffffff]
112inline fn mulxU64(out1: *u64, out2: *u64, arg1: u64, arg2: u64) void {112fn mulxU64(out1: *u64, out2: *u64, arg1: u64, arg2: u64) void {
113 @setRuntimeSafety(mode == .Debug);113 @setRuntimeSafety(mode == .Debug);
114114
115 const x = @as(u128, arg1) * @as(u128, arg2);115 const x = @as(u128, arg1) * @as(u128, arg2);
...@@ -128,7 +128,7 @@ inline fn mulxU64(out1: *u64, out2: *u64, arg1: u64, arg2: u64) void {...@@ -128,7 +128,7 @@ inline fn mulxU64(out1: *u64, out2: *u64, arg1: u64, arg2: u64) void {
128/// arg3: [0x0 ~> 0xffffffffffffffff]128/// arg3: [0x0 ~> 0xffffffffffffffff]
129/// Output Bounds:129/// Output Bounds:
130/// out1: [0x0 ~> 0xffffffffffffffff]130/// out1: [0x0 ~> 0xffffffffffffffff]
131inline fn cmovznzU64(out1: *u64, arg1: u1, arg2: u64, arg3: u64) void {131fn cmovznzU64(out1: *u64, arg1: u1, arg2: u64, arg3: u64) void {
132 @setRuntimeSafety(mode == .Debug);132 @setRuntimeSafety(mode == .Debug);
133133
134 const mask = 0 -% @as(u64, arg1);134 const mask = 0 -% @as(u64, arg1);
lib/std/crypto/pcurves/p384/p384_64.zig+4-4
...@@ -41,7 +41,7 @@ pub const NonMontgomeryDomainFieldElement = [6]u64;...@@ -41,7 +41,7 @@ pub const NonMontgomeryDomainFieldElement = [6]u64;
41/// Output Bounds:41/// Output Bounds:
42/// out1: [0x0 ~> 0xffffffffffffffff]42/// out1: [0x0 ~> 0xffffffffffffffff]
43/// out2: [0x0 ~> 0x1]43/// out2: [0x0 ~> 0x1]
44inline fn addcarryxU64(out1: *u64, out2: *u1, arg1: u1, arg2: u64, arg3: u64) void {44fn addcarryxU64(out1: *u64, out2: *u1, arg1: u1, arg2: u64, arg3: u64) void {
45 const x = @as(u128, arg2) +% arg3 +% arg1;45 const x = @as(u128, arg2) +% arg3 +% arg1;
46 out1.* = @truncate(x);46 out1.* = @truncate(x);
47 out2.* = @truncate(x >> 64);47 out2.* = @truncate(x >> 64);
...@@ -60,7 +60,7 @@ inline fn addcarryxU64(out1: *u64, out2: *u1, arg1: u1, arg2: u64, arg3: u64) vo...@@ -60,7 +60,7 @@ inline fn addcarryxU64(out1: *u64, out2: *u1, arg1: u1, arg2: u64, arg3: u64) vo
60/// Output Bounds:60/// Output Bounds:
61/// out1: [0x0 ~> 0xffffffffffffffff]61/// out1: [0x0 ~> 0xffffffffffffffff]
62/// out2: [0x0 ~> 0x1]62/// out2: [0x0 ~> 0x1]
63inline fn subborrowxU64(out1: *u64, out2: *u1, arg1: u1, arg2: u64, arg3: u64) void {63fn subborrowxU64(out1: *u64, out2: *u1, arg1: u1, arg2: u64, arg3: u64) void {
64 const x = @as(u128, arg2) -% arg3 -% arg1;64 const x = @as(u128, arg2) -% arg3 -% arg1;
65 out1.* = @truncate(x);65 out1.* = @truncate(x);
66 out2.* = @truncate(x >> 64);66 out2.* = @truncate(x >> 64);
...@@ -78,7 +78,7 @@ inline fn subborrowxU64(out1: *u64, out2: *u1, arg1: u1, arg2: u64, arg3: u64) v...@@ -78,7 +78,7 @@ inline fn subborrowxU64(out1: *u64, out2: *u1, arg1: u1, arg2: u64, arg3: u64) v
78/// Output Bounds:78/// Output Bounds:
79/// out1: [0x0 ~> 0xffffffffffffffff]79/// out1: [0x0 ~> 0xffffffffffffffff]
80/// out2: [0x0 ~> 0xffffffffffffffff]80/// out2: [0x0 ~> 0xffffffffffffffff]
81inline fn mulxU64(out1: *u64, out2: *u64, arg1: u64, arg2: u64) void {81fn mulxU64(out1: *u64, out2: *u64, arg1: u64, arg2: u64) void {
82 @setRuntimeSafety(mode == .Debug);82 @setRuntimeSafety(mode == .Debug);
8383
84 const x = @as(u128, arg1) * @as(u128, arg2);84 const x = @as(u128, arg1) * @as(u128, arg2);
...@@ -97,7 +97,7 @@ inline fn mulxU64(out1: *u64, out2: *u64, arg1: u64, arg2: u64) void {...@@ -97,7 +97,7 @@ inline fn mulxU64(out1: *u64, out2: *u64, arg1: u64, arg2: u64) void {
97/// arg3: [0x0 ~> 0xffffffffffffffff]97/// arg3: [0x0 ~> 0xffffffffffffffff]
98/// Output Bounds:98/// Output Bounds:
99/// out1: [0x0 ~> 0xffffffffffffffff]99/// out1: [0x0 ~> 0xffffffffffffffff]
100inline fn cmovznzU64(out1: *u64, arg1: u1, arg2: u64, arg3: u64) void {100fn cmovznzU64(out1: *u64, arg1: u1, arg2: u64, arg3: u64) void {
101 @setRuntimeSafety(mode == .Debug);101 @setRuntimeSafety(mode == .Debug);
102102
103 const mask = 0 -% @as(u64, arg1);103 const mask = 0 -% @as(u64, arg1);
lib/std/crypto/pcurves/p384/p384_scalar_64.zig+4-4
...@@ -41,7 +41,7 @@ pub const NonMontgomeryDomainFieldElement = [6]u64;...@@ -41,7 +41,7 @@ pub const NonMontgomeryDomainFieldElement = [6]u64;
41/// Output Bounds:41/// Output Bounds:
42/// out1: [0x0 ~> 0xffffffffffffffff]42/// out1: [0x0 ~> 0xffffffffffffffff]
43/// out2: [0x0 ~> 0x1]43/// out2: [0x0 ~> 0x1]
44inline fn addcarryxU64(out1: *u64, out2: *u1, arg1: u1, arg2: u64, arg3: u64) void {44fn addcarryxU64(out1: *u64, out2: *u1, arg1: u1, arg2: u64, arg3: u64) void {
45 const x = @as(u128, arg2) +% arg3 +% arg1;45 const x = @as(u128, arg2) +% arg3 +% arg1;
46 out1.* = @truncate(x);46 out1.* = @truncate(x);
47 out2.* = @truncate(x >> 64);47 out2.* = @truncate(x >> 64);
...@@ -60,7 +60,7 @@ inline fn addcarryxU64(out1: *u64, out2: *u1, arg1: u1, arg2: u64, arg3: u64) vo...@@ -60,7 +60,7 @@ inline fn addcarryxU64(out1: *u64, out2: *u1, arg1: u1, arg2: u64, arg3: u64) vo
60/// Output Bounds:60/// Output Bounds:
61/// out1: [0x0 ~> 0xffffffffffffffff]61/// out1: [0x0 ~> 0xffffffffffffffff]
62/// out2: [0x0 ~> 0x1]62/// out2: [0x0 ~> 0x1]
63inline fn subborrowxU64(out1: *u64, out2: *u1, arg1: u1, arg2: u64, arg3: u64) void {63fn subborrowxU64(out1: *u64, out2: *u1, arg1: u1, arg2: u64, arg3: u64) void {
64 const x = @as(u128, arg2) -% arg3 -% arg1;64 const x = @as(u128, arg2) -% arg3 -% arg1;
65 out1.* = @truncate(x);65 out1.* = @truncate(x);
66 out2.* = @truncate(x >> 64);66 out2.* = @truncate(x >> 64);
...@@ -78,7 +78,7 @@ inline fn subborrowxU64(out1: *u64, out2: *u1, arg1: u1, arg2: u64, arg3: u64) v...@@ -78,7 +78,7 @@ inline fn subborrowxU64(out1: *u64, out2: *u1, arg1: u1, arg2: u64, arg3: u64) v
78/// Output Bounds:78/// Output Bounds:
79/// out1: [0x0 ~> 0xffffffffffffffff]79/// out1: [0x0 ~> 0xffffffffffffffff]
80/// out2: [0x0 ~> 0xffffffffffffffff]80/// out2: [0x0 ~> 0xffffffffffffffff]
81inline fn mulxU64(out1: *u64, out2: *u64, arg1: u64, arg2: u64) void {81fn mulxU64(out1: *u64, out2: *u64, arg1: u64, arg2: u64) void {
82 @setRuntimeSafety(mode == .Debug);82 @setRuntimeSafety(mode == .Debug);
8383
84 const x = @as(u128, arg1) * @as(u128, arg2);84 const x = @as(u128, arg1) * @as(u128, arg2);
...@@ -97,7 +97,7 @@ inline fn mulxU64(out1: *u64, out2: *u64, arg1: u64, arg2: u64) void {...@@ -97,7 +97,7 @@ inline fn mulxU64(out1: *u64, out2: *u64, arg1: u64, arg2: u64) void {
97/// arg3: [0x0 ~> 0xffffffffffffffff]97/// arg3: [0x0 ~> 0xffffffffffffffff]
98/// Output Bounds:98/// Output Bounds:
99/// out1: [0x0 ~> 0xffffffffffffffff]99/// out1: [0x0 ~> 0xffffffffffffffff]
100inline fn cmovznzU64(out1: *u64, arg1: u1, arg2: u64, arg3: u64) void {100fn cmovznzU64(out1: *u64, arg1: u1, arg2: u64, arg3: u64) void {
101 @setRuntimeSafety(mode == .Debug);101 @setRuntimeSafety(mode == .Debug);
102102
103 const mask = 0 -% @as(u64, arg1);103 const mask = 0 -% @as(u64, arg1);
lib/std/crypto/pcurves/secp256k1/secp256k1_64.zig+4-4
...@@ -41,7 +41,7 @@ pub const NonMontgomeryDomainFieldElement = [4]u64;...@@ -41,7 +41,7 @@ pub const NonMontgomeryDomainFieldElement = [4]u64;
41/// Output Bounds:41/// Output Bounds:
42/// out1: [0x0 ~> 0xffffffffffffffff]42/// out1: [0x0 ~> 0xffffffffffffffff]
43/// out2: [0x0 ~> 0x1]43/// out2: [0x0 ~> 0x1]
44inline fn addcarryxU64(out1: *u64, out2: *u1, arg1: u1, arg2: u64, arg3: u64) void {44fn addcarryxU64(out1: *u64, out2: *u1, arg1: u1, arg2: u64, arg3: u64) void {
45 const x = @as(u128, arg2) +% arg3 +% arg1;45 const x = @as(u128, arg2) +% arg3 +% arg1;
46 out1.* = @truncate(x);46 out1.* = @truncate(x);
47 out2.* = @truncate(x >> 64);47 out2.* = @truncate(x >> 64);
...@@ -60,7 +60,7 @@ inline fn addcarryxU64(out1: *u64, out2: *u1, arg1: u1, arg2: u64, arg3: u64) vo...@@ -60,7 +60,7 @@ inline fn addcarryxU64(out1: *u64, out2: *u1, arg1: u1, arg2: u64, arg3: u64) vo
60/// Output Bounds:60/// Output Bounds:
61/// out1: [0x0 ~> 0xffffffffffffffff]61/// out1: [0x0 ~> 0xffffffffffffffff]
62/// out2: [0x0 ~> 0x1]62/// out2: [0x0 ~> 0x1]
63inline fn subborrowxU64(out1: *u64, out2: *u1, arg1: u1, arg2: u64, arg3: u64) void {63fn subborrowxU64(out1: *u64, out2: *u1, arg1: u1, arg2: u64, arg3: u64) void {
64 const x = @as(u128, arg2) -% arg3 -% arg1;64 const x = @as(u128, arg2) -% arg3 -% arg1;
65 out1.* = @truncate(x);65 out1.* = @truncate(x);
66 out2.* = @truncate(x >> 64);66 out2.* = @truncate(x >> 64);
...@@ -78,7 +78,7 @@ inline fn subborrowxU64(out1: *u64, out2: *u1, arg1: u1, arg2: u64, arg3: u64) v...@@ -78,7 +78,7 @@ inline fn subborrowxU64(out1: *u64, out2: *u1, arg1: u1, arg2: u64, arg3: u64) v
78/// Output Bounds:78/// Output Bounds:
79/// out1: [0x0 ~> 0xffffffffffffffff]79/// out1: [0x0 ~> 0xffffffffffffffff]
80/// out2: [0x0 ~> 0xffffffffffffffff]80/// out2: [0x0 ~> 0xffffffffffffffff]
81inline fn mulxU64(out1: *u64, out2: *u64, arg1: u64, arg2: u64) void {81fn mulxU64(out1: *u64, out2: *u64, arg1: u64, arg2: u64) void {
82 @setRuntimeSafety(mode == .Debug);82 @setRuntimeSafety(mode == .Debug);
8383
84 const x = @as(u128, arg1) * @as(u128, arg2);84 const x = @as(u128, arg1) * @as(u128, arg2);
...@@ -97,7 +97,7 @@ inline fn mulxU64(out1: *u64, out2: *u64, arg1: u64, arg2: u64) void {...@@ -97,7 +97,7 @@ inline fn mulxU64(out1: *u64, out2: *u64, arg1: u64, arg2: u64) void {
97/// arg3: [0x0 ~> 0xffffffffffffffff]97/// arg3: [0x0 ~> 0xffffffffffffffff]
98/// Output Bounds:98/// Output Bounds:
99/// out1: [0x0 ~> 0xffffffffffffffff]99/// out1: [0x0 ~> 0xffffffffffffffff]
100inline fn cmovznzU64(out1: *u64, arg1: u1, arg2: u64, arg3: u64) void {100fn cmovznzU64(out1: *u64, arg1: u1, arg2: u64, arg3: u64) void {
101 @setRuntimeSafety(mode == .Debug);101 @setRuntimeSafety(mode == .Debug);
102102
103 const mask = 0 -% @as(u64, arg1);103 const mask = 0 -% @as(u64, arg1);
lib/std/crypto/pcurves/secp256k1/secp256k1_scalar_64.zig+4-4
...@@ -41,7 +41,7 @@ pub const NonMontgomeryDomainFieldElement = [4]u64;...@@ -41,7 +41,7 @@ pub const NonMontgomeryDomainFieldElement = [4]u64;
41/// Output Bounds:41/// Output Bounds:
42/// out1: [0x0 ~> 0xffffffffffffffff]42/// out1: [0x0 ~> 0xffffffffffffffff]
43/// out2: [0x0 ~> 0x1]43/// out2: [0x0 ~> 0x1]
44inline fn addcarryxU64(out1: *u64, out2: *u1, arg1: u1, arg2: u64, arg3: u64) void {44fn addcarryxU64(out1: *u64, out2: *u1, arg1: u1, arg2: u64, arg3: u64) void {
45 const x = @as(u128, arg2) +% arg3 +% arg1;45 const x = @as(u128, arg2) +% arg3 +% arg1;
46 out1.* = @truncate(x);46 out1.* = @truncate(x);
47 out2.* = @truncate(x >> 64);47 out2.* = @truncate(x >> 64);
...@@ -60,7 +60,7 @@ inline fn addcarryxU64(out1: *u64, out2: *u1, arg1: u1, arg2: u64, arg3: u64) vo...@@ -60,7 +60,7 @@ inline fn addcarryxU64(out1: *u64, out2: *u1, arg1: u1, arg2: u64, arg3: u64) vo
60/// Output Bounds:60/// Output Bounds:
61/// out1: [0x0 ~> 0xffffffffffffffff]61/// out1: [0x0 ~> 0xffffffffffffffff]
62/// out2: [0x0 ~> 0x1]62/// out2: [0x0 ~> 0x1]
63inline fn subborrowxU64(out1: *u64, out2: *u1, arg1: u1, arg2: u64, arg3: u64) void {63fn subborrowxU64(out1: *u64, out2: *u1, arg1: u1, arg2: u64, arg3: u64) void {
64 const x = @as(u128, arg2) -% arg3 -% arg1;64 const x = @as(u128, arg2) -% arg3 -% arg1;
65 out1.* = @truncate(x);65 out1.* = @truncate(x);
66 out2.* = @truncate(x >> 64);66 out2.* = @truncate(x >> 64);
...@@ -78,7 +78,7 @@ inline fn subborrowxU64(out1: *u64, out2: *u1, arg1: u1, arg2: u64, arg3: u64) v...@@ -78,7 +78,7 @@ inline fn subborrowxU64(out1: *u64, out2: *u1, arg1: u1, arg2: u64, arg3: u64) v
78/// Output Bounds:78/// Output Bounds:
79/// out1: [0x0 ~> 0xffffffffffffffff]79/// out1: [0x0 ~> 0xffffffffffffffff]
80/// out2: [0x0 ~> 0xffffffffffffffff]80/// out2: [0x0 ~> 0xffffffffffffffff]
81inline fn mulxU64(out1: *u64, out2: *u64, arg1: u64, arg2: u64) void {81fn mulxU64(out1: *u64, out2: *u64, arg1: u64, arg2: u64) void {
82 @setRuntimeSafety(mode == .Debug);82 @setRuntimeSafety(mode == .Debug);
8383
84 const x = @as(u128, arg1) * @as(u128, arg2);84 const x = @as(u128, arg1) * @as(u128, arg2);
...@@ -97,7 +97,7 @@ inline fn mulxU64(out1: *u64, out2: *u64, arg1: u64, arg2: u64) void {...@@ -97,7 +97,7 @@ inline fn mulxU64(out1: *u64, out2: *u64, arg1: u64, arg2: u64) void {
97/// arg3: [0x0 ~> 0xffffffffffffffff]97/// arg3: [0x0 ~> 0xffffffffffffffff]
98/// Output Bounds:98/// Output Bounds:
99/// out1: [0x0 ~> 0xffffffffffffffff]99/// out1: [0x0 ~> 0xffffffffffffffff]
100inline fn cmovznzU64(out1: *u64, arg1: u1, arg2: u64, arg3: u64) void {100fn cmovznzU64(out1: *u64, arg1: u1, arg2: u64, arg3: u64) void {
101 @setRuntimeSafety(mode == .Debug);101 @setRuntimeSafety(mode == .Debug);
102102
103 const mask = 0 -% @as(u64, arg1);103 const mask = 0 -% @as(u64, arg1);
lib/std/crypto/poly1305.zig+2-2
...@@ -31,13 +31,13 @@ pub const Poly1305 = struct {...@@ -31,13 +31,13 @@ pub const Poly1305 = struct {
31 };31 };
32 }32 }
3333
34 inline fn add(a: u64, b: u64, c: u1) struct { u64, u1 } {34 fn add(a: u64, b: u64, c: u1) struct { u64, u1 } {
35 const v1 = @addWithOverflow(a, b);35 const v1 = @addWithOverflow(a, b);
36 const v2 = @addWithOverflow(v1[0], c);36 const v2 = @addWithOverflow(v1[0], c);
37 return .{ v2[0], v1[1] | v2[1] };37 return .{ v2[0], v1[1] | v2[1] };
38 }38 }
3939
40 inline fn sub(a: u64, b: u64, c: u1) struct { u64, u1 } {40 fn sub(a: u64, b: u64, c: u1) struct { u64, u1 } {
41 const v1 = @subWithOverflow(a, b);41 const v1 = @subWithOverflow(a, b);
42 const v2 = @subWithOverflow(v1[0], c);42 const v2 = @subWithOverflow(v1[0], c);
43 return .{ v2[0], v1[1] | v2[1] };43 return .{ v2[0], v1[1] | v2[1] };
lib/std/crypto/salsa20.zig+3-3
...@@ -41,7 +41,7 @@ fn SalsaVecImpl(comptime rounds: comptime_int) type {...@@ -41,7 +41,7 @@ fn SalsaVecImpl(comptime rounds: comptime_int) type {
41 };41 };
42 }42 }
4343
44 inline fn salsaCore(x: *BlockVec, input: BlockVec, comptime feedback: bool) void {44 fn salsaCore(x: *BlockVec, input: BlockVec, comptime feedback: bool) void {
45 const n1n2n3n0 = Lane{ input[3][1], input[3][2], input[3][3], input[3][0] };45 const n1n2n3n0 = Lane{ input[3][1], input[3][2], input[3][3], input[3][0] };
46 const n1n2 = Half{ n1n2n3n0[0], n1n2n3n0[1] };46 const n1n2 = Half{ n1n2n3n0[0], n1n2n3n0[1] };
47 const n3n0 = Half{ n1n2n3n0[2], n1n2n3n0[3] };47 const n3n0 = Half{ n1n2n3n0[2], n1n2n3n0[3] };
...@@ -203,7 +203,7 @@ fn SalsaNonVecImpl(comptime rounds: comptime_int) type {...@@ -203,7 +203,7 @@ fn SalsaNonVecImpl(comptime rounds: comptime_int) type {
203 d: u6,203 d: u6,
204 };204 };
205205
206 inline fn Rp(a: usize, b: usize, c: usize, d: u6) QuarterRound {206 fn Rp(a: usize, b: usize, c: usize, d: u6) QuarterRound {
207 return QuarterRound{207 return QuarterRound{
208 .a = a,208 .a = a,
209 .b = b,209 .b = b,
...@@ -212,7 +212,7 @@ fn SalsaNonVecImpl(comptime rounds: comptime_int) type {...@@ -212,7 +212,7 @@ fn SalsaNonVecImpl(comptime rounds: comptime_int) type {
212 };212 };
213 }213 }
214214
215 inline fn salsaCore(x: *BlockVec, input: BlockVec, comptime feedback: bool) void {215 fn salsaCore(x: *BlockVec, input: BlockVec, comptime feedback: bool) void {
216 const arx_steps = comptime [_]QuarterRound{216 const arx_steps = comptime [_]QuarterRound{
217 Rp(4, 0, 12, 7), Rp(8, 4, 0, 9), Rp(12, 8, 4, 13), Rp(0, 12, 8, 18),217 Rp(4, 0, 12, 7), Rp(8, 4, 0, 9), Rp(12, 8, 4, 13), Rp(0, 12, 8, 18),
218 Rp(9, 5, 1, 7), Rp(13, 9, 5, 9), Rp(1, 13, 9, 13), Rp(5, 1, 13, 18),218 Rp(9, 5, 1, 7), Rp(13, 9, 5, 9), Rp(1, 13, 9, 13), Rp(5, 1, 13, 18),
lib/std/crypto/tls.zig+3-3
...@@ -588,11 +588,11 @@ pub fn hmac(comptime Hmac: type, message: []const u8, key: [Hmac.key_length]u8)...@@ -588,11 +588,11 @@ pub fn hmac(comptime Hmac: type, message: []const u8, key: [Hmac.key_length]u8)
588 return result;588 return result;
589}589}
590590
591pub inline fn extension(et: ExtensionType, bytes: anytype) [2 + 2 + bytes.len]u8 {591pub fn extension(et: ExtensionType, bytes: anytype) [2 + 2 + bytes.len]u8 {
592 return int(u16, @intFromEnum(et)) ++ array(u16, u8, bytes);592 return int(u16, @intFromEnum(et)) ++ array(u16, u8, bytes);
593}593}
594594
595pub inline fn array(595pub fn array(
596 comptime Len: type,596 comptime Len: type,
597 comptime Elem: type,597 comptime Elem: type,
598 elems: anytype,598 elems: anytype,
...@@ -617,7 +617,7 @@ pub inline fn array(...@@ -617,7 +617,7 @@ pub inline fn array(
617 return arr;617 return arr;
618}618}
619619
620pub inline fn int(comptime Int: type, val: Int) [@divExact(@bitSizeOf(Int), 8)]u8 {620pub fn int(comptime Int: type, val: Int) [@divExact(@bitSizeOf(Int), 8)]u8 {
621 var arr: [@divExact(@bitSizeOf(Int), 8)]u8 = undefined;621 var arr: [@divExact(@bitSizeOf(Int), 8)]u8 = undefined;
622 std.mem.writeInt(Int, &arr, val, .big);622 std.mem.writeInt(Int, &arr, val, .big);
623 return arr;623 return arr;
lib/std/crypto/tls/Client.zig+1-1
...@@ -1576,7 +1576,7 @@ fn straddleByte(s1: []const u8, s2: []const u8, index: usize) u8 {...@@ -1576,7 +1576,7 @@ fn straddleByte(s1: []const u8, s2: []const u8, index: usize) u8 {
1576const builtin = @import("builtin");1576const builtin = @import("builtin");
1577const native_endian = builtin.cpu.arch.endian();1577const native_endian = builtin.cpu.arch.endian();
15781578
1579inline fn big(x: anytype) @TypeOf(x) {1579fn big(x: anytype) @TypeOf(x) {
1580 return switch (native_endian) {1580 return switch (native_endian) {
1581 .big => x,1581 .big => x,
1582 .little => @byteSwap(x),1582 .little => @byteSwap(x),