Instantly share code, notes, and snippets.

Embed
What would you like to do?
Fast (>100MBps) CSPRNG to randomize hard drive before encryption
#!/usr/bin/env ruby
require 'openssl'
BLOCK_SIZE = 1024*1024 # 1M
CIPHER_BLOCK_SIZE = 128
loop do
n = 0
cipher = OpenSSL::Cipher::AES.new CIPHER_BLOCK_SIZE, :CBC
cipher.encrypt
cipher.key = OpenSSL::Random.pseudo_bytes CIPHER_BLOCK_SIZE / 8
cipher.iv = OpenSSL::Random.pseudo_bytes CIPHER_BLOCK_SIZE / 8
input = nil, 0
loop do
if n % (100*1024*1024/BLOCK_SIZE) == 0
# Change input each 100M
input = OpenSSL::Random.pseudo_bytes BLOCK_SIZE / 8
end
n += 1
print cipher.update input
if n % (10*1024*1024*1024/BLOCK_SIZE) == 0
# Change cipher each 10G
break
end
end
end
@lolo32

This comment has been minimized.

Copy link

lolo32 commented Aug 9, 2018

Hi, very interesting. I just ported it to Go (compiled one time, used without any dependency everywhere with static compilation).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment