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

Hide discrete logarithm k such that H = kG #6

Merged
merged 3 commits into from
May 31, 2019
Merged
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
1 change: 1 addition & 0 deletions package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ dependencies:
- random
- memory
- mtl
- arithmoi

library:
source-dirs: src
Expand Down
32 changes: 27 additions & 5 deletions src/LSAG.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import qualified Data.ByteString as BS
import Data.Monoid
import Data.List
import Protolude hiding (hash, head)
import Math.NumberTheory.Moduli.Sqrt (sqrtModP)

-- | Generates a ring signature for a message given a specific set of
-- public keys and a signing key belonging to one of the public keys
Expand Down Expand Up @@ -82,8 +83,8 @@ sign pubKeys (pubKey, privKey) msg =

where
curve = ECDSA.public_curve pubKey
-- h = [Hash(L)] * g
h = ECC.pointBaseMul curve (hashPubKeys curve pubKeys)
-- h = H(L)
h = generateH g curve (show $ hashPubKeys curve pubKeys)
-- y = [x] * h
y = ECC.pointMul curve (ECDSA.private_d privKey) h
n = ECC.ecc_n (ECC.common_curve curve)
Expand Down Expand Up @@ -116,8 +117,9 @@ verify pubKeys (ch0, [s], y) msg = panic "Invalid input"
verify pubKeys (ch0, s0:s1:s2ToEnd, y) msg = ch0 == ch0'
where
curve0 = ECDSA.public_curve $ head pubKeys
-- h = [H(L)] * g
h = ECC.pointBaseMul curve0 (hashPubKeys curve0 pubKeys)
-- h = H(L)
h = generateH g curve0 (show $ hashPubKeys curve0 pubKeys)

y0 = ECDSA.public_q $ head pubKeys
-- z0' = [s0] * g + [ch0] * y0
z0' = ECC.pointAdd curve0
Expand Down Expand Up @@ -157,7 +159,7 @@ genChallenges pubKeys y msg ss = do
genChallenges pubKeys y msg ss
where
g curve = ECC.ecc_g (ECC.common_curve curve)
h curve = ECC.pointBaseMul curve (hashPubKeys curve pubKeys)
h curve = generateH (g curve) curve (show $ hashPubKeys curve pubKeys)
gs curve prevK prevS prevCh =
ECC.pointAdd curve
(ECC.pointMul curve prevS (g curve))
Expand Down Expand Up @@ -204,6 +206,26 @@ pointToBS (ECC.Point x y) = show x <> show y
pubKeysToBS :: [ECDSA.PublicKey] -> BS.ByteString
pubKeysToBS = foldMap (pointToBS . ECDSA.public_q)


-- | Iterative algorithm to generate H.
-- The important to hide its discrete logarithm "k" such that H = kG
generateH :: ECC.Point -> ECC.Curve -> [Char] -> ECC.Point
generateH g curve currHash =
case yM of
Nothing -> generateH g curve (noise:currHash)
Just y -> if ECC.isPointValid curve (ECC.Point x y)
then ECC.Point x y
else generateH g curve (noise:currHash)
where
x = oracle curve (pointToBS g <> toS currHash) `mod` p
yM = sqrtModP (x ^ 3 + 7) p
p = ECC.ecc_p cp
where
cp = case curve of
ECC.CurveFP c -> c
ECC.CurveF2m _ -> panic "Not a FP curve"
noise = '1'

-- | Hash list of public keys
hashPubKeys :: ECC.Curve -> [ECDSA.PublicKey] -> Integer
hashPubKeys c = oracle c . pubKeysToBS
Expand Down
3 changes: 2 additions & 1 deletion stack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ packages:
- .
# Dependency packages to be pulled from upstream that are not in the resolver
# (e.g., acme-missiles-0.3)
# extra-deps: []
extra-deps:
- arithmoi-0.8.0.0

# Override default flag values for local packages and extra-deps
# flags: {}
Expand Down