-----------------------------------------------------------------------------
-- |
-- Module      :  Codec.Crypto.ECC.StandardCurves
-- Copyright   :  (c) Marcel Fourné 20[09..13]
-- License     :  BSD3
-- Maintainer  :  Marcel Fourné (hecc@bitrot.dyndns.org)
--
-- ECC Standard Curves, taken from Standard Documents found somewhere(tm)
--
-----------------------------------------------------------------------------

module Codec.Crypto.ECC.StandardCurves
    where

import qualified Data.F2 as F2
import Crypto.Types (BitLength)

-- | Datatype for Prime Curves
data StandardCurve = StandardCurve {stdc_l::BitLength,stdc_p::Integer,stdc_r::Integer,stdc_a::Integer,stdc_b::Integer,stdc_xp::Integer,stdc_yp::Integer}

-- | Datatype for Curves on Binary Fields (F2)
data StandardCurveF2 = StandardCurveF2 {stdcF_l::Int,stdcF_p::F2.F2,stdcF_r::F2.F2,stdcF_a::F2.F2,stdcF_b::F2.F2,stdcF_xp::F2.F2,stdcF_yp::F2.F2}

-- Curves over Prime Fields, NIST variety

-- | NIST Prime Curve P-256
p256:: StandardCurve
p256 = StandardCurve {
         stdc_l = 256,
         stdc_p = 115792089210356248762697446949407573530086143415290314195533631308867097853951,
         stdc_r = 0,
         stdc_a = 115792089210356248762697446949407573530086143415290314195533631308867097853948,
         stdc_b = 41058363725152142129326129780047268409114441015993725554835256314039467401291,
         stdc_xp = 48439561293906451759052585252797914202762949526041747995844080717082404635286,
         stdc_yp = 36134250956749795798585127919587881956611106672985015071877198253568414405109
       }

-- | NIST Prime Curve P-384
p384:: StandardCurve
p384 = StandardCurve {
         stdc_l = 384,
         stdc_p = 39402006196394479212279040100143613805079739270465446667948293404245721771496870329047266088258938001861606973112319,
         stdc_r = 0,         
         stdc_a = 39402006196394479212279040100143613805079739270465446667948293404245721771496870329047266088258938001861606973112316,
         stdc_b = 27580193559959705877849011840389048093056905856361568521428707301988689241309860865136260764883745107765439761230575,
         stdc_xp = 26247035095799689268623156744566981891852923491109213387815615900925518854738050089022388053975719786650872476732087,
         stdc_yp = 8325710961489029985546751289520108179287853048861315594709205902480503199884419224438643760392947333078086511627871
       }

-- | NIST Prime Curve P-521
p521:: StandardCurve
p521 = StandardCurve {
         stdc_l = 521,
         stdc_p = 6864797660130609714981900799081393217269435300143305409394463459185543183397656052122559640661454554977296311391480858037121987999716643812574028291115057151,
         stdc_r = 0,
         stdc_a = 6864797660130609714981900799081393217269435300143305409394463459185543183397656052122559640661454554977296311391480858037121987999716643812574028291115057148,
         stdc_b = 1093849038073734274511112390766805569936207598951683748994586394495953116150735016013708737573759623248592132296706313309438452531591012912142327488478985984,
         stdc_xp = 2661740802050217063228768716723360960729859168756973147706671368418802944996427808491545080627771902352094241225065558662157113545570916814161637315895999846,
         stdc_yp = 3757180025770020463545507224491183603594455134769762486694567779615544477440556316691234405012945539562144444537289428522585666729196580810124344277578376784
       }

-- | NIST Binary Field Curve K-283
k283:: StandardCurveF2
k283 = StandardCurveF2 {
  stdcF_l = 283,
  stdcF_p = F2.fromInteger 15541351137805832567355695254588151253139254712417116170014499277911234281641667989665,
  stdcF_r = F2.fromInteger 0,
  stdcF_a = F2.fromInteger 0,
  stdcF_b = F2.fromInteger 1,
  stdcF_xp = F2.fromInteger 9737095673315832344313391497449387731784428326114441977662399932694280557468376967222,
  stdcF_yp = F2.fromInteger 3497201781826516614681192670485202061196189998012192335594744939847890291586353668697
  }

-- | NIST Binary Field Curve B-283
b283:: StandardCurveF2
b283 = StandardCurveF2 {
  stdcF_l = 283,
  stdcF_p = F2.fromInteger 15541351137805832567355695254588151253139254712417116170014499277911234281641667989665,
  stdcF_r = F2.fromInteger 0,
  stdcF_a = F2.fromInteger 1,
  stdcF_b = F2.fromInteger 4821813576056072374006997780399081180312270030300601270120450341205914644378616963829,
  stdcF_xp = F2.fromInteger 11604587487407003699882500449177537465719784002620028212980871291231978603047872962643,
  stdcF_yp = F2.fromInteger 6612720053854191978412609357563545875491153188501906352980899759345275170452624446196
  }