File: Generate.hs

package info (click to toggle)
haskell-crypton 1.0.4-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 3,548 kB
  • sloc: haskell: 26,764; ansic: 22,294; makefile: 6
file content (34 lines) | stat: -rw-r--r-- 797 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
-- | Signature generation.
module Crypto.PubKey.ECC.Generate where

import Crypto.Number.Generate
import Crypto.PubKey.ECC.ECDSA
import Crypto.PubKey.ECC.Prim
import Crypto.PubKey.ECC.Types
import Crypto.Random.Types

-- | Generate Q given d.
--
-- /WARNING:/ Vulnerable to timing attacks.
generateQ
    :: Curve
    -> Integer
    -> Point
generateQ curve d = pointMul curve d g
  where
    g = ecc_g $ common_curve curve

-- | Generate a pair of (private, public) key.
--
-- /WARNING:/ Vulnerable to timing attacks.
generate
    :: MonadRandom m
    => Curve
    -- ^ Elliptic Curve
    -> m (PublicKey, PrivateKey)
generate curve = do
    d <- generateBetween 1 (n - 1)
    let q = generateQ curve d
    return (PublicKey curve q, PrivateKey curve d)
  where
    n = ecc_n $ common_curve curve