Fast (>100MBps) CSPRNG to randomize hard drive before encryption
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
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, very interesting. I just ported it to Go (compiled one time, used without any dependency everywhere with static compilation).
https://gist.github.com/lolo32/8743fc74739887aa391f710036716cbb