Test P256.pointMul

This commit is contained in:
Olivier Chéron 2018-04-16 19:47:49 +02:00
parent 2e92639679
commit e0b201b5e7

View File

@ -54,6 +54,9 @@ unP256Scalar (P256Scalar r) =
unP256 :: P256Scalar -> Integer
unP256 (P256Scalar r) = r
modP256Scalar :: P256Scalar -> P256Scalar
modP256Scalar (P256Scalar r) = P256Scalar (r `mod` curveN)
p256ScalarToInteger :: P256.Scalar -> Integer
p256ScalarToInteger s = os2ip (P256.scalarToBinary s :: Bytes)
@ -122,6 +125,7 @@ tests = testGroup "P256"
, testProperty "lift-to-curve" $ propertyLiftToCurve
, testProperty "point-add" $ propertyPointAdd
, testProperty "point-negate" $ propertyPointNegate
, testProperty "point-mul" $ propertyPointMul
]
]
where
@ -151,3 +155,14 @@ tests = testGroup "P256"
pe = ECC.pointMul curve (unP256 r) curveGen
pR = P256.pointNegate p
in ECC.pointNegate curve pe `propertyEq` (pointP256ToECC pR)
propertyPointMul s' r' =
let s = modP256Scalar s'
r = modP256Scalar r'
p = P256.toPoint (unP256Scalar r)
pe = ECC.pointMul curve (unP256 r) curveGen
pR = P256.toPoint (P256.scalarMul (unP256Scalar s) (unP256Scalar r))
peR = ECC.pointMul curve (unP256 s) pe
in propertyHold [ eqTest "p256" pR (P256.pointMul (unP256Scalar s) p)
, eqTest "ecc" peR (pointP256ToECC pR)
]