Skip to content

buildKey from CryptoRandomGen #9

Closed
singpolyma opened this Issue Dec 31, 2012 · 1 comment

2 participants

@singpolyma

Currently, the only high-level mechanism provided by crypto-api for key generation requires IO. I would like to propose the inclusion of something like:

buildKeyGen :: (BlockCipher k, CryptoRandomGen g) => g -> Either GenError (k, g)
buildKeyGen = runStateT (go (0::Int))
  where
  go 1000 = lift $ Left $ GenErrorOther
                  "Tried 1000 times to generate a key from the system entropy.\
                  \  No keys were returned! Perhaps the system entropy is broken\
                  \ or perhaps the BlockCipher instance being used has a non-flat\
                  \ keyspace."
  go i = do
   let bs = keyLength
   kd <- StateT $ genBytes ((7 + untag bs) `div` 8)
   case buildKey kd of
      Nothing -> go (i+1)
       Just k  -> return $ k `asTaggedTypeOf` bs
@TomMD
Owner
TomMD commented Dec 31, 2012

Such a patch would need to include all build*Key*Gen combinations (ex: stream key, key pair), but I would certainly accept it.

@TomMD TomMD closed this Jan 1, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.