|
@@ -6,16 +6,22 @@ import Crypto.Random.DRBG
|
|
import Data.Binary
|
|
import Data.Binary
|
|
import qualified Data.ByteString.Lazy as BS
|
|
import qualified Data.ByteString.Lazy as BS
|
|
import Numeric (showHex)
|
|
import Numeric (showHex)
|
|
|
|
+import System.Environment (getArgs)
|
|
|
|
+import System.IO (hPutStrLn, stderr)
|
|
|
|
|
|
toHex :: (Binary a) => a -> String
|
|
toHex :: (Binary a) => a -> String
|
|
toHex = concat . map (flip showHex "") . BS.unpack . encode
|
|
toHex = concat . map (flip showHex "") . BS.unpack . encode
|
|
|
|
|
|
main :: IO ()
|
|
main :: IO ()
|
|
main = do
|
|
main = do
|
|
- (pub, priv) <- genPair
|
|
|
|
|
|
+ args <- getArgs
|
|
|
|
+ let size = case args of (s:_) -> read s
|
|
|
|
+ _ -> 1024
|
|
|
|
+ hPutStrLn stderr ("Generating key pair of size " ++ show size)
|
|
|
|
+ (pub, priv) <- genPair size
|
|
putStrLn ("pub: " ++ toHex pub)
|
|
putStrLn ("pub: " ++ toHex pub)
|
|
putStrLn ("priv: " ++ toHex priv)
|
|
putStrLn ("priv: " ++ toHex priv)
|
|
|
|
|
|
-genPair :: IO (PublicKey, PrivateKey)
|
|
|
|
-genPair = go `fmap` (newGenIO :: IO HashDRBG)
|
|
|
|
- where go g = let (pub, priv, _) = generateKeyPair g 1024 in (pub, priv)
|
|
|
|
|
|
+genPair :: Int -> IO (PublicKey, PrivateKey)
|
|
|
|
+genPair size = go `fmap` (newGenIO :: IO HashDRBG)
|
|
|
|
+ where go g = let (pub, priv, _) = generateKeyPair g size in (pub, priv)
|