Skip to content

Instantly share code, notes, and snippets.

@aeris
Last active March 20, 2019 11:41
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save aeris/2a0f9beeed94102fd0cb2a8caad964d0 to your computer and use it in GitHub Desktop.
Save aeris/2a0f9beeed94102fd0cb2a8caad964d0 to your computer and use it in GitHub Desktop.
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
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).
https://gist.github.com/lolo32/8743fc74739887aa391f710036716cbb

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