Skip to content

Instantly share code, notes, and snippets.

@aeris aeris/randomize.rb
Last active Mar 20, 2019

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

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
You can’t perform that action at this time.