Skip to content
Snippets Groups Projects
Commit dc795d44 authored by Jean-Paul Calderone's avatar Jean-Paul Calderone
Browse files

Merge remote-tracking branch 'origin/main' into 6.key-derivation

parents ef7bf432 d4b3e573
No related branches found
No related tags found
1 merge request!5Add a Keys module with types and derivation functions
...@@ -53,8 +53,18 @@ We want a library that: ...@@ -53,8 +53,18 @@ We want a library that:
* Mainly armeabi and armv7 * Mainly armeabi and armv7
* Is suitable for real-world security purposes * Is suitable for real-world security purposes
* not a demo or a toy library * not a demo or a toy library
* documents its limitations
* is well-tested
* avoids real-world pitfalls (side-channel attacks, etc), not just textbook issues * avoids real-world pitfalls (side-channel attacks, etc), not just textbook issues
* has more than a handful of other users * has more than a handful of other users
* is well-maintained
* developers are responsive to security reports
* has a channel for security-related disclosures
* has sound documentation for proper, safe usage
And,
of course,
implements the required functionality.
### SHA256 ### SHA256
......
module Main where module Main where
import Codec.Crypto.RSA (generateKeyPair) import qualified Crypto.PubKey.RSA as RSA
import Crypto.Random (CryptoRandomGen (newGenIO), SystemRandom)
import Data.ASN1.BinaryEncoding (DER (DER)) import Data.ASN1.BinaryEncoding (DER (DER))
import Data.ASN1.Encoding (ASN1Encoding (encodeASN1)) import Data.ASN1.Encoding (ASN1Encoding (encodeASN1))
import Data.ASN1.Types (ASN1Object (toASN1)) import Data.ASN1.Types (ASN1Object (toASN1))
import qualified Data.ByteString.Lazy as LB import qualified Data.ByteString.Lazy as LB
import Data.X509 (PrivKey (PrivKeyRSA))
-- | The size of the keys to generate. -- | The size of the keys to generate.
bits :: Int bits :: Int
...@@ -17,11 +17,12 @@ count = 5 ...@@ -17,11 +17,12 @@ count = 5
main :: IO () main :: IO ()
main = do main = do
g <- newGenIO :: IO SystemRandom mapM_ genKey [0 .. count - 1]
mapM_ (genKey g) [0 .. count - 1]
genKey :: (Show a, CryptoRandomGen c) => c -> a -> IO () genKey :: Show a => a -> IO ()
genKey g n = genKey n = do
let (_, priv, _) = generateKeyPair g bits (_, priv) <- RSA.generate bits e
bytes = encodeASN1 DER (toASN1 priv []) let bytes = encodeASN1 DER (toASN1 (PrivKeyRSA priv) [])
in LB.writeFile ("test/data/rsa-privkey-" <> show n <> ".der") bytes LB.writeFile ("test/data/rsa-privkey-" <> show n <> ".der") bytes
where
e = 0x10001
...@@ -149,3 +149,4 @@ executable make-keypairs ...@@ -149,3 +149,4 @@ executable make-keypairs
, base , base
, bytestring , bytestring
, cryptonite , cryptonite
, x509
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment