Sodium::Cipher::Chalsa Add #random_bytes for use as a CSPRNG.

master
Didactic Drunk 2019-09-03 01:10:31 -07:00
parent ed7ba20082
commit 5196ee992e
1 changed files with 15 additions and 0 deletions

View File

@ -51,6 +51,21 @@ module Sodium::Cipher
Bytes.new(0) Bytes.new(0)
end end
# Use as a CSPRNG.
def random_bytes(bytes : Bytes) : Bytes
# TODO: Switch to memset
Sodium.memzero bytes
update bytes, bytes
bytes
end
# Use as a CSPRNG.
def random_bytes(size : Int) : Bytes
bytes = Bytes.new size
update bytes, bytes
bytes
end
# Always returns false. Sadness... # Always returns false. Sadness...
def edible? def edible?
false false