Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add alternative Ed25519 switching #241

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion hackage-security/hackage-security.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ flag lukko
manual: True
default: True

flag use-eccrypto
description: Use pure Haskell cryptographic signing
manual: False
default: False

library
-- Most functionality is exported through the top-level entry points .Client
-- and .Server; the other exported modules are intended for qualified imports.
Expand Down Expand Up @@ -118,7 +123,6 @@ library
|| >= 2.0 && < 2.6
|| >= 3.0 && < 3.2,
containers >= 0.4 && < 0.7,
ed25519 >= 0.0 && < 0.1,
filepath >= 1.2 && < 1.5,
parsec >= 3.1 && < 3.2,
pretty >= 1.0 && < 1.2,
Expand All @@ -132,6 +136,10 @@ library
-- whatever versions are bundled with ghc:
template-haskell,
ghc-prim
if flag(use-eccrypto)
build-depends: eccrypto-ed25519-bindings >= 0.1.2 && < 0.2
else
build-depends: ed25519 >= 0.0 && < 0.1
if flag(old-directory)
build-depends: directory >= 1.1.0.2 && < 1.2,
old-time >= 1 && < 1.2
Expand Down
8 changes: 8 additions & 0 deletions hackage-security/src/Hackage/Security/Key.hs
Original file line number Diff line number Diff line change
Expand Up @@ -183,21 +183,29 @@ sign :: PrivateKey typ -> BS.L.ByteString -> BS.ByteString
sign (PrivateKeyEd25519 pri) =
Ed25519.unSignature . dsign pri . BS.concat . BS.L.toChunks
where
#ifdef MIN_VERSION_ed25519
#if MIN_VERSION_ed25519(0,0,4)
dsign = Ed25519.dsign
#else
dsign = Ed25519.sign'
#endif
#else
dsign = Ed25519.dsign
#endif

verify :: PublicKey typ -> BS.L.ByteString -> BS.ByteString -> Bool
verify (PublicKeyEd25519 pub) inp sig =
dverify pub (BS.concat $ BS.L.toChunks inp) (Ed25519.Signature sig)
where
#ifdef MIN_VERSION_ed25519
#if MIN_VERSION_ed25519(0,0,4)
dverify = Ed25519.dverify
#else
dverify = Ed25519.verify'
#endif
#else
dverify = Ed25519.dverify
#endif

{-------------------------------------------------------------------------------
JSON encoding and decoding
Expand Down