Last active
January 12, 2020 11:16
-
-
Save schmee/7860d017ec791170c20db19c14229b5b to your computer and use it in GitHub Desktop.
DES
This file contains 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
cat /dev/urandom | head -c300000000 > random_test_data.bin | |
➜ zig-crypto git:(new-api) ✗ time openssl enc -des-ecb -in random_test_data.bin -out enc.bin -K 133457799BBCDFF1 -nopad | |
openssl enc -des-ecb -in src/random_test_data.bin -out enc.bin -K -nopad 3.59s user 0.41s system 95% cpu 4.195 total | |
➜ zig-crypto git:(new-api) ✗ zig build-exe main.zig --release-fast --main-pkg-path . && time ./des | |
78 | |
./des 3.52s user 0.21s system 99% cpu 3.741 total |
This file contains 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
pub fn main() !void { | |
var keyLong: u64 = 0x133457799BBCDFF1; | |
var keyBytes = mem.asBytes(&keyLong); | |
mem.reverse(u8, keyBytes); | |
const cipher = DES.init(keyBytes.*); | |
var allocator = std.heap.page_allocator; | |
const source = try std.fs.cwd().readFileAlloc(allocator, "src/random_test_data.bin", 1000 * 1000 * 1000 * 1000); | |
defer allocator.free(source); | |
var dest = try allocator.alloc(u8, source.len); | |
defer allocator.free(dest); | |
{ | |
var i: usize = 0; | |
while (i < source.len) : (i += block_size) { | |
cipher.crypt(.Encrypt, dest[i..(i + block_size)], source[i..(i + block_size)]); | |
} | |
} | |
std.debug.warn("{}\n", .{dest[dest.len - 1]}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment