[ECC] add generate for ECC generic's scalar and point Base Multiplication helper.
This commit is contained in:
parent
08a8155f12
commit
b63dc38c49
@ -2,8 +2,10 @@
|
|||||||
--
|
--
|
||||||
-- /WARNING:/ These functions are vulnerable to timing attacks.
|
-- /WARNING:/ These functions are vulnerable to timing attacks.
|
||||||
module Crypto.PubKey.ECC.Prim
|
module Crypto.PubKey.ECC.Prim
|
||||||
( pointAdd
|
( scalarGenerate
|
||||||
|
, pointAdd
|
||||||
, pointDouble
|
, pointDouble
|
||||||
|
, pointBaseMul
|
||||||
, pointMul
|
, pointMul
|
||||||
, isPointAtInfinity
|
, isPointAtInfinity
|
||||||
, isPointValid
|
, isPointValid
|
||||||
@ -12,7 +14,14 @@ module Crypto.PubKey.ECC.Prim
|
|||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
import Crypto.Number.ModArithmetic
|
import Crypto.Number.ModArithmetic
|
||||||
import Crypto.Number.F2m
|
import Crypto.Number.F2m
|
||||||
|
import Crypto.Number.Generate (generateBetween)
|
||||||
import Crypto.PubKey.ECC.Types
|
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...`
|
--TODO: Extract helper function for `fromMaybe PointO...`
|
||||||
|
|
||||||
@ -74,6 +83,12 @@ pointDouble (CurveF2m (CurveBinary fx cc)) (Point xp yp)
|
|||||||
return $ Point xr yr
|
return $ Point xr yr
|
||||||
where a = ecc_a cc
|
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).
|
-- | Elliptic curve point multiplication (double and add algorithm).
|
||||||
--
|
--
|
||||||
-- /WARNING:/ Vulnerable to timing attacks.
|
-- /WARNING:/ Vulnerable to timing attacks.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user