packages feed

eccrypto 0.1.0 → 0.2.0

raw patch · 5 files changed

+32/−35 lines, 5 filesdep +cryptohash-sha512dep +randomdep −MonadRandomdep −SHAdep −crypto-apiPVP ok

version bump matches the API change (PVP)

Dependencies added: cryptohash-sha512, random

Dependencies removed: MonadRandom, SHA, crypto-api

API changes (from Hackage documentation)

- Crypto.ECC.Ed25519.Sign: genkeysSimple :: IO (Either String (SecKey, PubKey))
- Crypto.ECC.Ed25519.Sign: genkeys :: CryptoRandomGen g => g -> Either String (SecKey, PubKey)
+ Crypto.ECC.Ed25519.Sign: genkeys :: IO (Either String (SecKey, PubKey))

Files

bench/bench.hs view
@@ -19,7 +19,7 @@ import Crypto.ECC.Weierstrass.StandardCurves import Crypto.ECC.Weierstrass.ECDSA import Crypto.ECC.Weierstrass.ECDH-import Control.Monad.Random+import qualified System.Random as R import Criterion import Criterion.Main import qualified Crypto.ECC.Ed25519.Sign as ED@@ -37,8 +37,8 @@       pkfix = C8.pack "\185`\134^:gJw\146E\137@dw1\243w\212\178\213ry\140\159\137\&7yT+Y\156\EM"       skfix = C8.pack "\131\190G\200\SYN\191&<\ETBd\223W\145}3\247#8\133\195\NUL\139\&8\138\197\132\191\255\SOC/\SOH"       sigfix = C8.pack "S\EM\199\149\135\DC4Zr\242=\227(\139D\US,\232\159\210m\131\176\145\155\189\166Gl\186X\157\149U(zhd\224\133\DC1\237\FS\DLE\DC3\223S\153\218\214)\219o\177\n\248F\223^A\236\196\175N\STX"-  k13' <- evalRandIO $ getRandomR (1,stdc_p p256)-  Right (sk,pk) <- ED.genkeysSimple+  k13' <- R.getStdRandom (R.randomR (1,stdc_p p256)) -- evalRandIO $ getRandomR (1,stdc_p p256)+  Right (sk,pk) <- ED.genkeys   defaultMain [ bgroup "NIST P-256" [ bench "ECDHp256" $ whnf (basicecdh c1 p1) k13'                                     , bench "ECDSAp256 sign" $ whnf (basicecdsa (BS.pack [0..255]) rand) rand                                     , bench "ECDSAp256 verify" $ whnf (\x -> basicecdsaVerify pub (r,x) (BS.pack [0..255])) s
eccrypto.cabal view
@@ -1,5 +1,5 @@ Name:                eccrypto-Version:             0.1.0+Version:             0.2.0 Synopsis:            Elliptic Curve Cryptography for Haskell Description:         Elliptic Curve Cryptography in Haskell, evolved for correctness and practical usability from higher-level libraries.                      .@@ -32,9 +32,9 @@   Build-Depends:                 base >= 4 && < 5               , bytestring >= 0.10 && < 0.11-              , crypto-api >= 0.13 && < 0.14+              , cryptohash-sha512 >= 0.11 && < 0.12               , integer-gmp >= 1.0 && < 1.1-              , SHA >= 1.6.4 && < 1.7+              , random >= 1.1 && < 1.2   Exposed-modules:                   Crypto.Common                   Crypto.Fi@@ -72,7 +72,7 @@                   , bytestring >= 0.10 && < 0.11                   , criterion >= 1.4 && < 1.6                   , eccrypto-                  , MonadRandom >= 0.5 && < 0.6+                  , random >= 1.1 && < 1.2   ghc-options: -O2                -feager-blackholing 
src/Crypto/ECC/Ed25519/Internal/Ed25519.hs view
@@ -16,7 +16,7 @@ -----------------------------------------------------------------------------  {-# OPTIONS_GHC -O2 -feager-blackholing #-}-{-# LANGUAGE Safe, ScopedTypeVariables, NoImplicitPrelude #-}+{-# LANGUAGE Trustworthy, ScopedTypeVariables, NoImplicitPrelude #-}  module Crypto.ECC.Ed25519.Internal.Ed25519 where @@ -25,8 +25,9 @@ import safe qualified Prelude as P (fromInteger,toInteger) import safe qualified Crypto.Fi as FP import safe qualified Data.ByteString as BS-import safe qualified Data.ByteString.Lazy as BSL-import safe qualified Data.Digest.Pure.SHA as H+-- import safe qualified Data.ByteString.Lazy as BSL+-- import safe qualified Data.Digest.Pure.SHA as H+import qualified Crypto.Hash.SHA512 as H import safe qualified Data.Word as W (Word8)  --  a point on the twisted Edwards curve, affine coordinates, neutral element (0,1)@@ -91,8 +92,8 @@  -- | wrapper for our hash function h :: BS.ByteString -> BS.ByteString-h bs = BSL.toStrict $ H.bytestringDigest $ H.sha512 $ BSL.fromStrict bs--- h = H.hash+-- h bs = BSL.toStrict $ H.bytestringDigest $ H.sha512 $ BSL.fromStrict bs+h = H.hash {-# INLINABLE h #-}  -- | the prehash function, id in PureEdDSA
src/Crypto/ECC/Ed25519/Sign.hs view
@@ -13,10 +13,9 @@ -----------------------------------------------------------------------------  {-# OPTIONS_GHC -O2 -feager-blackholing #-}-{-# LANGUAGE Trustworthy, ScopedTypeVariables, PackageImports, NoImplicitPrelude #-}+{-# LANGUAGE Safe, ScopedTypeVariables, NoImplicitPrelude #-}  module Crypto.ECC.Ed25519.Sign ( genkeys-                               , genkeysSimple                                , publickey                                , dsign                                , sign@@ -34,27 +33,22 @@  import safe Crypto.ECC.Ed25519.Internal.Ed25519 -import safe Prelude ((==),show,($),(<),IO,return,pure,Either(Left,Right),String,(&&))+import safe Prelude ((==),($),(<),IO,return,pure,Either(Left,Right),String,(&&),take) import safe qualified Crypto.Fi as FP import safe qualified Data.ByteString as BS-import qualified "crypto-api" Crypto.Random as CR+import safe qualified System.Random as R  -- | generate a new key pair (secret and derived public key) using some external entropy--- | This may be insecure, depending on your environment, so it's better to use the genkeys function and supply a random number generator which is secure for your usage case!-genkeysSimple :: IO (Either String (SecKey,PubKey))-genkeysSimple = do-  (g :: CR.SystemRandom) <- CR.newGenIO-  return $ genkeys g---- | generate a new key pair (secret and derived public key) using the supplied randomness-generator-genkeys :: (CR.CryptoRandomGen g) => g -> Either String (SecKey,PubKey)-genkeys g = case CR.genBytes 32 g of-  Left e -> Left (show e)-  Right (sk',_) -> let sk = SecKeyBytes sk'-                       derived = publickey sk-                  in case derived of-                       Left e -> Left e-                       Right pk -> Right (sk,pk)+-- | This may be insecure, depending on your environment, so for your usage case you may need to implement some better key generator!+genkeys :: IO (Either String (SecKey,PubKey))+genkeys = do+  g <- R.getStdGen+  let bytes = R.randoms g+      sk = SecKeyBytes $ BS.pack $ take 32 bytes+      derived = publickey sk+  return $ case derived of+    Left e -> Left e+    Right pk -> Right (sk,pk)  -- | derive public key from secret key publickey :: SecKey -> Either String PubKey
src/Crypto/ECC/Weierstrass/ECDSA.hs view
@@ -12,7 +12,7 @@ -----------------------------------------------------------------------------  {-# OPTIONS_GHC -O2 -feager-blackholing #-}-{-# LANGUAGE Safe #-}+{-# LANGUAGE Trustworthy #-}  module Crypto.ECC.Weierstrass.ECDSA ( basicecdsa                                     , basicecdsaVerify@@ -24,9 +24,10 @@ import safe Crypto.ECC.Weierstrass.StandardCurves import safe qualified Crypto.Fi as FP import safe qualified Crypto.ECC.Ed25519.Internal as Ed-import safe qualified Data.Digest.Pure.SHA as H+-- import safe qualified Data.Digest.Pure.SHA as H+import qualified Crypto.Hash.SHA512 as H import safe qualified Data.ByteString as BS-import safe qualified Data.ByteString.Lazy as BSL+-- import safe qualified Data.ByteString.Lazy as BSL  -- | basic ecdsa for testing basicecdsa :: BS.ByteString -> Integer -> Integer -> Either String (Integer,Integer)@@ -57,4 +58,5 @@  -- | using SHA-256 h :: BS.ByteString -> BS.ByteString-h bs = BSL.toStrict $ H.bytestringDigest $ H.sha256 $ BSL.fromStrict bs+-- h bs = BSL.toStrict $ H.bytestringDigest $ H.sha256 $ BSL.fromStrict bs+h = H.hash