commit
88e614b675
@ -100,8 +100,20 @@ instance EllipticCurve Curve_P256R1 where
|
|||||||
curveGenerateScalar _ = P256.scalarGenerate
|
curveGenerateScalar _ = P256.scalarGenerate
|
||||||
curveGenerateKeyPair _ = toKeyPair <$> P256.scalarGenerate
|
curveGenerateKeyPair _ = toKeyPair <$> P256.scalarGenerate
|
||||||
where toKeyPair scalar = KeyPair (P256.toPoint scalar) scalar
|
where toKeyPair scalar = KeyPair (P256.toPoint scalar) scalar
|
||||||
encodePoint _ p = P256.pointToBinary p
|
encodePoint _ p = mxy
|
||||||
decodePoint _ bs = P256.pointFromBinary bs
|
where
|
||||||
|
mxy :: forall bs. ByteArray bs => bs
|
||||||
|
mxy = B.concat [uncompressed, xy]
|
||||||
|
where
|
||||||
|
uncompressed, xy :: bs
|
||||||
|
uncompressed = B.singleton 4
|
||||||
|
xy = P256.pointToBinary p
|
||||||
|
decodePoint _ mxy = case B.uncons mxy of
|
||||||
|
Nothing -> CryptoFailed $ CryptoError_PointSizeInvalid
|
||||||
|
Just (m,xy)
|
||||||
|
-- uncompressed
|
||||||
|
| m == 4 -> P256.pointFromBinary xy
|
||||||
|
| otherwise -> CryptoFailed $ CryptoError_PointFormatInvalid
|
||||||
|
|
||||||
instance EllipticCurveArith Curve_P256R1 where
|
instance EllipticCurveArith Curve_P256R1 where
|
||||||
pointAdd _ a b = P256.pointAdd a b
|
pointAdd _ a b = P256.pointAdd a b
|
||||||
|
|||||||
@ -49,7 +49,7 @@ import Crypto.Internal.Compat
|
|||||||
import Crypto.Internal.Imports
|
import Crypto.Internal.Imports
|
||||||
import Crypto.Internal.ByteArray
|
import Crypto.Internal.ByteArray
|
||||||
import qualified Crypto.Internal.ByteArray as B
|
import qualified Crypto.Internal.ByteArray as B
|
||||||
import Data.Memory.PtrMethods (memSet, memCopy)
|
import Data.Memory.PtrMethods (memSet)
|
||||||
import Crypto.Error
|
import Crypto.Error
|
||||||
import Crypto.Random
|
import Crypto.Random
|
||||||
import Crypto.Number.Serialize.Internal (os2ip, i2ospOf)
|
import Crypto.Number.Serialize.Internal (os2ip, i2ospOf)
|
||||||
@ -119,7 +119,7 @@ pointDh scalar p =
|
|||||||
B.unsafeCreate scalarSize $ \dst -> withTempPoint $ \dx dy -> do
|
B.unsafeCreate scalarSize $ \dst -> withTempPoint $ \dx dy -> do
|
||||||
withScalar scalar $ \n -> withPoint p $ \px py -> withScalarZero $ \nzero ->
|
withScalar scalar $ \n -> withPoint p $ \px py -> withScalarZero $ \nzero ->
|
||||||
ccryptonite_p256_points_mul_vartime nzero n px py dx dy
|
ccryptonite_p256_points_mul_vartime nzero n px py dx dy
|
||||||
memCopy dst (castPtr dx) scalarSize
|
ccryptonite_p256_to_bin (castPtr dx) dst
|
||||||
|
|
||||||
-- | multiply the point @p with @n2 and add a lifted to curve value @n1
|
-- | multiply the point @p with @n2 and add a lifted to curve value @n1
|
||||||
--
|
--
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user