packages feed

eccrypto-ed25519-bindings (empty) → 0.1.0.0

raw patch · 5 files changed

+193/−0 lines, 5 filesdep +basedep +bytestringdep +eccryptosetup-changed

Dependencies added: base, bytestring, eccrypto

Files

+ ChangeLog.md view
@@ -0,0 +1,5 @@+# Revision history for eccrypto-ed25519-bindings++## 0.1.0.0 -- 2020-01-07++* First version. Released on an unsuspecting world.
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 20[19..], Marcel Fourné++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++    * Redistributions of source code must retain the above copyright+      notice, this list of conditions and the following disclaimer.++    * Redistributions in binary form must reproduce the above+      copyright notice, this list of conditions and the following+      disclaimer in the documentation and/or other materials provided+      with the distribution.++    * Neither the name of Marcel Fourné nor the names of other+      contributors may be used to endorse or promote products derived+      from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ eccrypto-ed25519-bindings.cabal view
@@ -0,0 +1,37 @@+-- Initial eccrypto-ed25519-bindings.cabal generated by cabal init.  For+-- further documentation, see http://haskell.org/cabal/users-guide/++name:                eccrypto-ed25519-bindings+version:             0.1.0.0+synopsis:            provides "ed25519" API using "eccrypto"+description:         These are bindings providing the functionality of the "ed25519" package using a pure Haskell implementation from the "eccrypto" package.+license:             BSD3+license-file:        LICENSE+author:              Marcel Fourné+maintainer:          haskell@marcelfourne.de+copyright:           Marcel Fourné+category:            Cryptography+build-type:          Simple+extra-source-files:  ChangeLog.md+cabal-version:       >=1.10++library+  exposed-modules:+        Crypto.Sign.Ed25519+  -- other-modules:+  -- other-extensions:+  build-depends:+                base >=4.11 && <4.13+              , bytestring >= 0.10 && < 0.11+              , eccrypto >=0.2.0 && <0.3++  hs-source-dirs:      src+  default-language:    Haskell2010+  ghc-options:+              -Wall+              -Wincomplete-uni-patterns+              -O2++source-repository head+  type:     git+  location: https://github.com/mfourne/eccrypto-ed25519-bindings.git
+ src/Crypto/Sign/Ed25519.hs view
@@ -0,0 +1,119 @@+-----------------------------------------------------------------------------+-- |+-- Module      :  Crypto.Sign.Ed25519+-- Copyright   :  (c) Marcel Fourné 20[19..]+-- License     :  BSD3+-- Maintainer  :  Marcel Fourné (haskell@marcelfourne.de)+-- Stability   :  stable+-- Portability :  Good+--+-- original implementation of this API is by Austin Seipp and can be found under: https://hackage.haskell.org/package/ed25519+--+-----------------------------------------------------------------------------++{-# LANGUAGE Safe #-}+{-# LANGUAGE DeriveGeneric #-}+{-# LANGUAGE NoImplicitPrelude #-}+{-# LANGUAGE ScopedTypeVariables #-}++module Crypto.Sign.Ed25519+       (+         PublicKey(..)+       , SecretKey(..)+       , createKeypair+       , createKeypairFromSeed_+       , createKeypairFromSeed+       , toPublicKey++       , sign+       , verify++       , Signature(..)+       , dsign+       , dverify++       , sign'+       , verify'++       ) where++import safe Prelude (Eq,Show, Ord, IO, Either(Right,Left), Maybe, Bool, return, undefined, error, (==))+import safe GHC.Generics (Generic)+import safe qualified Crypto.ECC.Ed25519.Sign as S+import safe qualified Crypto.ECC.Ed25519.Internal.Ed25519 as I+import safe qualified Data.ByteString as BS++-- | http://hackage.haskell.org/package/ed25519-0.0.5.0/docs/Crypto-Sign-Ed25519.html+newtype PublicKey = PublicKey { unPublicKey :: BS.ByteString+                              }+        deriving (Eq, Show, Ord, Generic)++-- | http://hackage.haskell.org/package/ed25519-0.0.5.0/docs/Crypto-Sign-Ed25519.html+newtype SecretKey = SecretKey { unSecretKey :: BS.ByteString+                              }+        deriving (Eq, Show, Ord, Generic)++-- | http://hackage.haskell.org/package/ed25519-0.0.5.0/docs/Crypto-Sign-Ed25519.html+createKeypair :: IO (PublicKey, SecretKey)+createKeypair = do+  a <- S.genkeys+  case a of+    Right (I.SecKeyBytes sk, pk) -> return (PublicKey pk, SecretKey sk)+    Left e -> error e++-- | http://hackage.haskell.org/package/ed25519-0.0.5.0/docs/Crypto-Sign-Ed25519.html+createKeypairFromSeed_ :: BS.ByteString -> Maybe (PublicKey, SecretKey)+createKeypairFromSeed_ = undefined++-- | http://hackage.haskell.org/package/ed25519-0.0.5.0/docs/Crypto-Sign-Ed25519.html+createKeypairFromSeed :: BS.ByteString -> (PublicKey, SecretKey)+createKeypairFromSeed = undefined++-- | http://hackage.haskell.org/package/ed25519-0.0.5.0/docs/Crypto-Sign-Ed25519.html+toPublicKey  :: SecretKey -> PublicKey+toPublicKey sk = let (SecretKey sk') = sk+                     sk'' = I.SecKeyBytes sk'+                     a = S.publickey sk''+  in case a of+       Right pk -> PublicKey pk+       Left e -> error e++-- | http://hackage.haskell.org/package/ed25519-0.0.5.0/docs/Crypto-Sign-Ed25519.html+sign :: SecretKey -> BS.ByteString -> BS.ByteString+sign sk m = let SecretKey sk' = sk+                a = S.sign (I.SecKeyBytes sk') m+            in case a of+                 Right sigm -> sigm+                 Left e -> error e++-- | http://hackage.haskell.org/package/ed25519-0.0.5.0/docs/Crypto-Sign-Ed25519.html+verify :: PublicKey -> BS.ByteString -> Bool+verify pk m = let PublicKey pk' = pk+              in S.verify pk' m == Right I.SigOK++-- | http://hackage.haskell.org/package/ed25519-0.0.5.0/docs/Crypto-Sign-Ed25519.html+newtype Signature = Signature { unSignature :: BS.ByteString+                              }+        deriving (Eq, Show, Ord)++-- | http://hackage.haskell.org/package/ed25519-0.0.5.0/docs/Crypto-Sign-Ed25519.html+dsign :: SecretKey -> BS.ByteString -> Signature+dsign sk m = let SecretKey sk' = sk+                 a = S.dsign (I.SecKeyBytes sk') m+             in case a of+                  Right sig -> Signature sig+                  Left e -> error e++-- | http://hackage.haskell.org/package/ed25519-0.0.5.0/docs/Crypto-Sign-Ed25519.html+dverify :: PublicKey -> BS.ByteString -> Signature -> Bool+dverify pk m sig = let PublicKey pk' = pk+                       Signature sig' = sig+                   in S.dverify pk' sig' m == Right I.SigOK++-- | http://hackage.haskell.org/package/ed25519-0.0.5.0/docs/Crypto-Sign-Ed25519.html+sign' :: SecretKey -> BS.ByteString -> Signature+sign' sk m = dsign sk m++-- | http://hackage.haskell.org/package/ed25519-0.0.5.0/docs/Crypto-Sign-Ed25519.html+verify' :: PublicKey -> BS.ByteString -> Signature -> Bool+verify' pk m sig = dverify pk m sig