Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
vincenthz committed Oct 17, 2016
0 parents commit 638b5b1
Show file tree
Hide file tree
Showing 11 changed files with 875 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitignore
@@ -0,0 +1,6 @@
*.o
*.hi
*.tix
*.mix
.stack-work
dist
30 changes: 30 additions & 0 deletions LICENSE
@@ -0,0 +1,30 @@
Copyright IOHK (c) 2016

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 Author name here 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.
2 changes: 2 additions & 0 deletions Setup.hs
@@ -0,0 +1,2 @@
import Distribution.Simple
main = defaultMain
64 changes: 64 additions & 0 deletions app/Main.hs
@@ -0,0 +1,64 @@
{-# LANGUAGE BangPatterns #-}
module Main where

import System.Environment
import Control.Monad
import Control.DeepSeq
import Crypto.Random
import qualified Crypto.PVSS as PVSS
import Data.Hourglass
import Time.Types
import Time.System

toPk :: PVSS.KeyPair -> PVSS.Point
toPk (PVSS.KeyPair _ p) = p

timing f = do
t1 <- timeCurrentP
a <- f
t2 <- a `deepseq` timeCurrentP
return (a, t2 `timeDiffP` t1)

timingP n f = do
(a, t) <- timing f
putStrLn (n ++ ": " ++ show t)
return a

chunk _ [] = []
chunk n l =
let (l1,l2) = splitAt n l
in l1 : chunk n l2

go t n = do
participants <- replicateM n $ PVSS.keyPairGenerate

!e <- timingP "escrow-new" $ PVSS.escrowNew t

!commitments <- timingP "commitments" $ return $ PVSS.createCommitments e

-- !eshares <- timingP "shares" $ PVSS.sharesCreate e commitments (map toPk participants)
!esharesChunks <- timingP "shares" $ forM (chunk 200 $ zip [1..] (map toPk participants)) $ \c ->
timingP ("chunk-" ++ show (fst $ head c)) $ forM c $ uncurry (PVSS.shareCreate e commitments)
let eshares = mconcat esharesChunks


validated <- timingP "validating" $ forM (chunk 200 $ zip eshares (map toPk participants)) $ \c ->
timingP ("vchunk") $ forM c $ return . PVSS.verifyEncryptedShare (PVSS.escrowExtraGen e) commitments

!decryptedShares <- timingP "decrypting" $ mapM (\(kp,eshare) -> do
p <- PVSS.shareDecrypt kp eshare
return $! p
) (zip participants eshares)

!verifiedShares <- timingP "verifying" $ return $
PVSS.getValidRecoveryShares t (zip3 eshares (map toPk participants) decryptedShares)

recovered <- timingP "recovering" $ return $ PVSS.recover $ take (fromIntegral t+1) $ decryptedShares
putStrLn $ show recovered

main :: IO ()
main = do
args <- getArgs
case args of
[tS, nS] -> go (read tS) (read nS)
_ -> error "error: pvss <threshold> <number>"
57 changes: 57 additions & 0 deletions pvss.cabal
@@ -0,0 +1,57 @@
name: pvss
version: 0.1.0.0
synopsis: Public Verifiable Secret Sharing
description: Please see README.md
homepage: https://github.com/githubuser/pvss#readme
license: BSD3
license-file: LICENSE
author: Vincent Hanquez
maintainer: libraries@typed.io
copyright: 2016 IOHK
category: Crypto
build-type: Simple
-- extra-source-files:
cabal-version: >=1.10

library
hs-source-dirs: src
exposed-modules: Crypto.PVSS
other-modules: Crypto.PVSS.ECC
Crypto.PVSS.DLEQ
Crypto.PVSS.Polynomial
build-depends: base >= 4.7 && < 5
, memory
, deepseq
, bytestring
, cryptonite
, cryptonite-openssl
, integer-gmp
default-language: Haskell2010

executable pvss-exe
hs-source-dirs: app
main-is: Main.hs
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends: base
, deepseq
, memory
, hourglass
, cryptonite
, pvss
default-language: Haskell2010

test-suite pvss-test
type: exitcode-stdio-1.0
hs-source-dirs: test
main-is: Spec.hs
build-depends: base
, cryptonite
, pvss
, tasty
, tasty-quickcheck
ghc-options: -threaded -rtsopts -with-rtsopts=-N
default-language: Haskell2010

source-repository head
type: git
location: https://github.com/githubuser/pvss

0 comments on commit 638b5b1

Please sign in to comment.