This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const std = @import("std"); | |
| const rotl = std.math.rotl; | |
| // zig fmt: off | |
| fn f1(x: u32, y: u32, z: u32) u32 { return x ^ y ^ z; } | |
| fn f2(x: u32, y: u32, z: u32) u32 { return (x & y) | (~x & z); } | |
| fn f3(x: u32, y: u32, z: u32) u32 { return (x | ~y) ^ z; } | |
| fn f4(x: u32, y: u32, z: u32) u32 { return (x & z) | (y & ~z); } | |
| fn f5(x: u32, y: u32, z: u32) u32 { return x ^ (y | ~z); } | |
| // zig fmt: on |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Mathlib | |
| open Finset | |
| -- The number of prisoners, exluding ourselves. | |
| variable {K : ℕ} | |
| /-- For a given ℕ, what prisoner is being interrogated at that time. -/ | |
| abbrev Schedule (K : ℕ) : Type := ℕ → Fin (K+1) | |
| -- A schedule chosen by the warden. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const std = @import("std"); | |
| const builtin = @import("builtin"); | |
| const L = if (builtin.cpu.has(.x86, .avx512f)) 64 else 32; | |
| const V = @Vector(L, u8); | |
| const pshufb = @extern(*const fn (V, V) callconv(.c) V, .{ .name = switch (L) { | |
| 64 => "llvm.x86.avx512.pshuf.b.512", | |
| 32 => "llvm.x86.avx2.pshuf.b", | |
| else => unreachable, | |
| } }).*; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //! Efficient computation of 32 parity shreds for 32 data shreds. | |
| //! | |
| //! Based on the O(n log n) algorithm described in: | |
| //! zS. -J. Lin, T. Y. Al-Naffouri, Y. S. Han and W. -H. Chung, "Novel | |
| //! Polynomial Basis With Fast Fourier Transform and Its Application to | |
| //! Reed–Solomon Erasure Codes," in IEEE Transactions on Information Theory, | |
| //! vol. 62, no. 11, pp. 6284-6299, Nov. 2016, doi: 10.1109/TIT.2016.2608892. | |
| //! | |
| //! Given 32 data shreds, we want to produce 32 parity shreds such that any | |
| //! 32 of the 64 total shreds can reconstruct the original data. The standard |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <string.h> | |
| #include <stdint.h> | |
| #include <stdlib.h> | |
| // Chunk size for tree hashing | |
| #define CHUNK_SIZE 8192 | |
| #define ALIGN __attribute__ ((aligned (128))) | |
| #define MODE 128 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const V = @Vector(8, u64); | |
| fn keccak(bytes: []const u8, comptime r: u32, comptime delim: u8, out: *[r]u8) void { | |
| var state: [144]u8 align(32) = @splat(0); | |
| var x: [5]V = @splat(@splat(0)); | |
| var input = bytes; | |
| const rsize = 200 - 2 * r; | |
| comptime std.debug.assert(rsize == 72); // TODO |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const std = @import("std"); | |
| const V = @Vector(8, u64); | |
| const S = @Vector(8, i64); | |
| const u64x4 = @Vector(4, u64); | |
| const avx512 = @import("src/curves/ed25519/avx512.zig"); | |
| extern fn @"llvm.x86.avx512.vpmadd52l.uq.512"(V, V, V) V; | |
| extern fn @"llvm.x86.avx512.vpmadd52h.uq.512"(V, V, V) V; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const std = @import("std"); | |
| /// A perfect hash table for N keys of the same `length`. Useful for public key maps. | |
| fn pht(K: type, V: type, entries: []const struct { K, V }) type { | |
| const LAMBDA = 5; | |
| const table_len = entries.len; | |
| const bucket_len = (table_len + LAMBDA - 1) / LAMBDA; | |
| const window = 4; | |
| const length = @typeInfo(std.meta.Child(K)).array.len; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const std = @import("std"); | |
| const iterations_per_byte = 1000; | |
| const warmup_iterations = 10; | |
| pub fn main() !void { | |
| const allocator = std.heap.smp_allocator; | |
| // Pin the process to a single core (1) | |
| const cpu0001: std.os.linux.cpu_set_t = [1]usize{0b0001} ++ ([_]usize{0} ** (16 - 1)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const std = @import("std"); | |
| const el: u256 = 0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed; | |
| const L = 1 * el; | |
| fn heea(v: u256) struct { u128, u128 } { | |
| std.debug.assert(len(L) == 253); | |
| std.debug.assert(v < L); | |
| std.debug.assert(v > 0); |
NewerOlder