diff --git a/Crypto/ECC.hs b/Crypto/ECC.hs index b3ec8ea..855ea60 100644 --- a/Crypto/ECC.hs +++ b/Crypto/ECC.hs @@ -166,11 +166,11 @@ instance EllipticCurve Curve_P256R1 where uncompressed = B.singleton 4 xy = P256.pointToBinary p decodePoint _ mxy = case B.uncons mxy of - Nothing -> CryptoFailed $ CryptoError_PointSizeInvalid + Nothing -> CryptoFailed CryptoError_PointSizeInvalid Just (m,xy) -- uncompressed | m == 4 -> P256.pointFromBinary xy - | otherwise -> CryptoFailed $ CryptoError_PointFormatInvalid + | otherwise -> CryptoFailed CryptoError_PointFormatInvalid instance EllipticCurveArith Curve_P256R1 where pointAdd _ a b = P256.pointAdd a b @@ -353,7 +353,7 @@ encodeECPoint (Simple.Point x y) = B.concat [uncompressed,xb,yb] decodeECPoint :: (Simple.Curve curve, ByteArray bs) => bs -> CryptoFailable (Simple.Point curve) decodeECPoint mxy = case B.uncons mxy of - Nothing -> CryptoFailed $ CryptoError_PointSizeInvalid + Nothing -> CryptoFailed CryptoError_PointSizeInvalid Just (m,xy) -- uncompressed | m == 4 -> @@ -362,7 +362,7 @@ decodeECPoint mxy = case B.uncons mxy of x = os2ip xb y = os2ip yb in Simple.pointFromIntegers (x,y) - | otherwise -> CryptoFailed $ CryptoError_PointFormatInvalid + | otherwise -> CryptoFailed CryptoError_PointFormatInvalid ecPointsMulVarTime :: forall curve . Simple.Curve curve => Simple.Scalar curve diff --git a/Crypto/PubKey/ECC/P256.hs b/Crypto/PubKey/ECC/P256.hs index 7b8c7c1..6edd8dd 100644 --- a/Crypto/PubKey/ECC/P256.hs +++ b/Crypto/PubKey/ECC/P256.hs @@ -110,7 +110,7 @@ pointAdd a b = withNewPoint $ \dx dy -> -- | Negate a point pointNegate :: Point -> Point pointNegate a = withNewPoint $ \dx dy -> - withPoint a $ \ax ay -> do + withPoint a $ \ax ay -> ccryptonite_p256e_point_negate ax ay dx dy -- | Multiply a point by a scalar @@ -188,12 +188,12 @@ pointFromBinary ba = unsafePointFromBinary ba >>= validatePoint validatePoint :: Point -> CryptoFailable Point validatePoint p | pointIsValid p = CryptoPassed p - | otherwise = CryptoFailed $ CryptoError_PointCoordinatesInvalid + | otherwise = CryptoFailed CryptoError_PointCoordinatesInvalid -- | Convert from binary to a point, possibly invalid unsafePointFromBinary :: ByteArrayAccess ba => ba -> CryptoFailable Point unsafePointFromBinary ba - | B.length ba /= pointSize = CryptoFailed $ CryptoError_PublicKeySizeInvalid + | B.length ba /= pointSize = CryptoFailed CryptoError_PublicKeySizeInvalid | otherwise = CryptoPassed $ withNewPoint $ \px py -> B.withByteArray ba $ \src -> do ccryptonite_p256_from_bin src (castPtr px) @@ -266,7 +266,7 @@ scalarCmp a b = unsafeDoIO $ -- | convert a scalar from binary scalarFromBinary :: ByteArrayAccess ba => ba -> CryptoFailable Scalar scalarFromBinary ba - | B.length ba /= scalarSize = CryptoFailed $ CryptoError_SecretKeySizeInvalid + | B.length ba /= scalarSize = CryptoFailed CryptoError_SecretKeySizeInvalid | otherwise = CryptoPassed $ withNewScalarFreeze $ \p -> B.withByteArray ba $ \b -> ccryptonite_p256_from_bin b p diff --git a/tests/ECC.hs b/tests/ECC.hs index 319a276..5faaf81 100644 --- a/tests/ECC.hs +++ b/tests/ECC.hs @@ -293,7 +293,7 @@ tests = testGroup "ECC" [ testGroup "decodePoint" $ map doPointDecodeTest (zip [katZero..] vectorsPoint) , testGroup "ECDH weak points" $ map doWeakPointECDHTest (zip [katZero..] vectorsWeakPoint) , testGroup "property" - [ testProperty "decodePoint.encodePoint==id" $ \testDRG (Curve curve) -> do + [ testProperty "decodePoint.encodePoint==id" $ \testDRG (Curve curve) -> let prx = Just curve -- using Maybe as Proxy keyPair = withTestDRG testDRG $ ECC.curveGenerateKeyPair prx p1 = ECC.keypairGetPublic keyPair diff --git a/tests/KAT_PubKey/P256.hs b/tests/KAT_PubKey/P256.hs index cd1356d..7dd508e 100644 --- a/tests/KAT_PubKey/P256.hs +++ b/tests/KAT_PubKey/P256.hs @@ -122,10 +122,10 @@ tests = testGroup "P256" t = P256.pointFromIntegers (xT, yT) r = P256.pointFromIntegers (xR, yR) in r @=? P256.pointAdd s t - , testProperty "lift-to-curve" $ propertyLiftToCurve - , testProperty "point-add" $ propertyPointAdd - , testProperty "point-negate" $ propertyPointNegate - , testProperty "point-mul" $ propertyPointMul + , testProperty "lift-to-curve" propertyLiftToCurve + , testProperty "point-add" propertyPointAdd + , testProperty "point-negate" propertyPointNegate + , testProperty "point-mul" propertyPointMul ] ] where @@ -154,7 +154,7 @@ tests = testGroup "P256" let p = P256.toPoint (unP256Scalar r) pe = ECC.pointMul curve (unP256 r) curveGen pR = P256.pointNegate p - in ECC.pointNegate curve pe `propertyEq` (pointP256ToECC pR) + in ECC.pointNegate curve pe `propertyEq` pointP256ToECC pR propertyPointMul s' r' = let s = modP256Scalar s'