diff options
author | Joey Hess <joeyh@joeyh.name> | 2017-04-18 16:35:38 -0400 |
---|---|---|
committer | Joey Hess <joeyh@joeyh.name> | 2017-04-18 16:35:38 -0400 |
commit | d73352f848b79224a94e531bb651897321064998 (patch) | |
tree | 4e4bb7f13113bfffc950a0451dd89b6ca8160070 /Crypto.hs | |
parent | a70548f6dade6d93d482510a1b68b99327ec7f4a (diff) | |
download | debug-me-d73352f848b79224a94e531bb651897321064998.tar.gz |
initial Crypto
Will use Ed25519 because it's from DJB and well regarded and in common
use now.
Diffstat (limited to 'Crypto.hs')
-rw-r--r-- | Crypto.hs | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/Crypto.hs b/Crypto.hs new file mode 100644 index 0000000..3d0529d --- /dev/null +++ b/Crypto.hs @@ -0,0 +1,24 @@ +module Crypto where + +import Val +import Hash +import Types + +import qualified Crypto.PubKey.Ed25519 as Ed25519 +import Data.ByteArray (convert) +import Crypto.Error + +dummySignature :: Signature +dummySignature = Unsigned + +-- | Sign any Hashable value. +sign :: Hashable v => Ed25519.SecretKey -> Ed25519.PublicKey -> v -> Signature +sign sk pk v = Ed25519 $ Val $ convert $ + Ed25519.sign sk pk $ val $ hashValue $ hash v + +-- | Verifiy a signature of any Hashable value. +verify :: Hashable v => Ed25519.PublicKey -> v -> Signature -> Bool +verify pk v (Ed25519 (Val s)) = case Ed25519.signature s of + CryptoPassed sig -> Ed25519.verify pk (val $ hashValue $ hash v) sig + CryptoFailed _ -> False +verify _ _ Unsigned = False |