[ECC] add generate for ECC generic's scalar and point Base Multiplication helper.

This commit is contained in:
Vincent Hanquez 2015-09-22 17:23:22 +01:00
parent 08a8155f12
commit b63dc38c49

View File

@ -2,8 +2,10 @@
--
-- /WARNING:/ These functions are vulnerable to timing attacks.
module Crypto.PubKey.ECC.Prim
( pointAdd
( scalarGenerate
, pointAdd
, pointDouble
, pointBaseMul
, pointMul
, isPointAtInfinity
, isPointValid
@ -12,7 +14,14 @@ module Crypto.PubKey.ECC.Prim
import Data.Maybe
import Crypto.Number.ModArithmetic
import Crypto.Number.F2m
import Crypto.Number.Generate (generateBetween)
import Crypto.PubKey.ECC.Types
import Crypto.Random
scalarGenerate :: MonadRandom randomly => Curve -> randomly PrivateNumber
scalarGenerate curve = generateBetween 1 (n - 1)
where
n = ecc_n $ common_curve curve
--TODO: Extract helper function for `fromMaybe PointO...`
@ -74,6 +83,12 @@ pointDouble (CurveF2m (CurveBinary fx cc)) (Point xp yp)
return $ Point xr yr
where a = ecc_a cc
-- | Elliptic curve point multiplication using the base
--
-- /WARNING:/ Vulnerable to timing attacks.
pointBaseMul :: Curve -> Integer -> Point
pointBaseMul c n = pointMul c n (ecc_g $ common_curve c)
-- | Elliptic curve point multiplication (double and add algorithm).
--
-- /WARNING:/ Vulnerable to timing attacks.