From b63dc38c498f5a3c9e667e6262ed01ac4ad6e05f Mon Sep 17 00:00:00 2001 From: Vincent Hanquez Date: Tue, 22 Sep 2015 17:23:22 +0100 Subject: [PATCH] [ECC] add generate for ECC generic's scalar and point Base Multiplication helper. --- Crypto/PubKey/ECC/Prim.hs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/Crypto/PubKey/ECC/Prim.hs b/Crypto/PubKey/ECC/Prim.hs index e6b8092..cbb6cb0 100644 --- a/Crypto/PubKey/ECC/Prim.hs +++ b/Crypto/PubKey/ECC/Prim.hs @@ -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.