| ... | @@ -72,8 +72,10 @@ pub const Ghash = struct { | ... | @@ -72,8 +72,10 @@ pub const Ghash = struct { |
| 72 | return Ghash.initForBlockCount(key, math.maxInt(usize)); | 72 | return Ghash.initForBlockCount(key, math.maxInt(usize)); |
| 73 | } | 73 | } |
| 74 | | 74 | |
| | 75 | const Selector = enum { lo, hi }; |
| | 76 | |
| 75 | // Carryless multiplication of two 64-bit integers for x86_64. | 77 | // Carryless multiplication of two 64-bit integers for x86_64. |
| 76 | inline fn clmulPclmul(x: u128, y: u128, comptime half: enum { lo, hi }) u128 { | 78 | inline fn clmulPclmul(x: u128, y: u128, comptime half: Selector) u128 { |
| 77 | if (half == .hi) { | 79 | if (half == .hi) { |
| 78 | const product = asm ( | 80 | const product = asm ( |
| 79 | \\ vpclmulqdq $0x11, %[x], %[y], %[out] | 81 | \\ vpclmulqdq $0x11, %[x], %[y], %[out] |
| ... | @@ -94,7 +96,7 @@ pub const Ghash = struct { | ... | @@ -94,7 +96,7 @@ pub const Ghash = struct { |
| 94 | } | 96 | } |
| 95 | | 97 | |
| 96 | // Carryless multiplication of two 64-bit integers for ARM crypto. | 98 | // Carryless multiplication of two 64-bit integers for ARM crypto. |
| 97 | inline fn clmulPmull(x: u128, y: u128, comptime half: enum { lo, hi }) u128 { | 99 | inline fn clmulPmull(x: u128, y: u128, comptime half: Selector) u128 { |
| 98 | if (half == .hi) { | 100 | if (half == .hi) { |
| 99 | const product = asm ( | 101 | const product = asm ( |
| 100 | \\ pmull2 %[out].1q, %[x].2d, %[y].2d | 102 | \\ pmull2 %[out].1q, %[x].2d, %[y].2d |
| ... | @@ -115,7 +117,7 @@ pub const Ghash = struct { | ... | @@ -115,7 +117,7 @@ pub const Ghash = struct { |
| 115 | } | 117 | } |
| 116 | | 118 | |
| 117 | // Software carryless multiplication of two 64-bit integers. | 119 | // Software carryless multiplication of two 64-bit integers. |
| 118 | fn clmulSoft(x_: u128, y_: u128, comptime half: enum { lo, hi }) u128 { | 120 | fn clmulSoft(x_: u128, y_: u128, comptime half: Selector) u128 { |
| 119 | const x = @truncate(u64, if (half == .hi) x_ >> 64 else x_); | 121 | const x = @truncate(u64, if (half == .hi) x_ >> 64 else x_); |
| 120 | const y = @truncate(u64, if (half == .hi) y_ >> 64 else y_); | 122 | const y = @truncate(u64, if (half == .hi) y_ >> 64 else y_); |
| 121 | | 123 | |