From 5196ee992e496f41b95465840efcc9c96cb392af Mon Sep 17 00:00:00 2001 From: Didactic Drunk <1479616+didactic-drunk@users.noreply.github.com> Date: Tue, 3 Sep 2019 01:10:31 -0700 Subject: [PATCH] Sodium::Cipher::Chalsa Add #random_bytes for use as a CSPRNG. --- src/sodium/cipher/chalsa.cr | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/sodium/cipher/chalsa.cr b/src/sodium/cipher/chalsa.cr index 6f5754b..3b7f5fc 100644 --- a/src/sodium/cipher/chalsa.cr +++ b/src/sodium/cipher/chalsa.cr @@ -51,6 +51,21 @@ module Sodium::Cipher Bytes.new(0) 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... def edible? false