Add P256.scalarMul
This commit is contained in:
parent
68c93ccbb1
commit
2e92639679
@ -34,6 +34,7 @@ module Crypto.PubKey.ECC.P256
|
||||
, scalarIsZero
|
||||
, scalarAdd
|
||||
, scalarSub
|
||||
, scalarMul
|
||||
, scalarInv
|
||||
, scalarCmp
|
||||
, scalarFromBinary
|
||||
@ -237,6 +238,14 @@ scalarSub a b =
|
||||
withNewScalarFreeze $ \d -> withScalar a $ \pa -> withScalar b $ \pb ->
|
||||
ccryptonite_p256e_modsub ccryptonite_SECP256r1_n pa pb d
|
||||
|
||||
-- | Perform multiplication between two scalars
|
||||
--
|
||||
-- > a * b
|
||||
scalarMul :: Scalar -> Scalar -> Scalar
|
||||
scalarMul a b =
|
||||
withNewScalarFreeze $ \d -> withScalar a $ \pa -> withScalar b $ \pb ->
|
||||
ccryptonite_p256_modmul ccryptonite_SECP256r1_n pa 0 pb d
|
||||
|
||||
-- | Give the inverse of the scalar
|
||||
--
|
||||
-- > 1 / a
|
||||
|
||||
@ -92,6 +92,10 @@ tests = testGroup "P256"
|
||||
let v = unP256 r `mod` curveN
|
||||
v' = P256.scalarSub (unP256Scalar r) P256.scalarZero
|
||||
in v `propertyEq` p256ScalarToInteger v'
|
||||
, testProperty "mul" $ \r1 r2 ->
|
||||
let r = (unP256 r1 * unP256 r2) `mod` curveN
|
||||
r' = P256.scalarMul (unP256Scalar r1) (unP256Scalar r2)
|
||||
in r `propertyEq` p256ScalarToInteger r'
|
||||
, testProperty "inv" $ \r' ->
|
||||
let inv = inverseCoprimes (unP256 r') curveN
|
||||
inv' = P256.scalarInv (unP256Scalar r')
|
||||
|
||||
Loading…
Reference in New Issue
Block a user