Rename to Edwards25519

This commit is contained in:
Olivier Chéron 2017-12-10 20:00:35 +01:00
parent d472d9b74f
commit 45723e3542
5 changed files with 29 additions and 29 deletions

View File

@ -17,7 +17,7 @@ module Crypto.ECC
, Curve_P521R1(..) , Curve_P521R1(..)
, Curve_X25519(..) , Curve_X25519(..)
, Curve_X448(..) , Curve_X448(..)
, Curve_Ed25519(..) , Curve_Edwards25519(..)
, EllipticCurve(..) , EllipticCurve(..)
, EllipticCurveDH(..) , EllipticCurveDH(..)
, EllipticCurveArith(..) , EllipticCurveArith(..)
@ -26,7 +26,7 @@ module Crypto.ECC
) where ) where
import qualified Crypto.PubKey.ECC.P256 as P256 import qualified Crypto.PubKey.ECC.P256 as P256
import qualified Crypto.ECC.Ed25519 as Ed25519 import qualified Crypto.ECC.Edwards25519 as Edwards25519
import qualified Crypto.ECC.Simple.Types as Simple import qualified Crypto.ECC.Simple.Types as Simple
import qualified Crypto.ECC.Simple.Prim as Simple import qualified Crypto.ECC.Simple.Prim as Simple
import Crypto.Random import Crypto.Random
@ -233,23 +233,23 @@ instance EllipticCurveDH Curve_X448 where
where secret = X448.dh p s where secret = X448.dh p s
ecdh prx s p = checkNonZeroDH (ecdhRaw prx s p) ecdh prx s p = checkNonZeroDH (ecdhRaw prx s p)
data Curve_Ed25519 = Curve_Ed25519 data Curve_Edwards25519 = Curve_Edwards25519
deriving (Show,Data,Typeable) deriving (Show,Data,Typeable)
instance EllipticCurve Curve_Ed25519 where instance EllipticCurve Curve_Edwards25519 where
type Point Curve_Ed25519 = Ed25519.Point type Point Curve_Edwards25519 = Edwards25519.Point
type Scalar Curve_Ed25519 = Ed25519.Scalar type Scalar Curve_Edwards25519 = Edwards25519.Scalar
curveSizeBits _ = 255 curveSizeBits _ = 255
curveGenerateScalar _ = Ed25519.scalarGenerate curveGenerateScalar _ = Edwards25519.scalarGenerate
curveGenerateKeyPair _ = toKeyPair <$> Ed25519.scalarGenerate curveGenerateKeyPair _ = toKeyPair <$> Edwards25519.scalarGenerate
where toKeyPair scalar = KeyPair (Ed25519.toPoint scalar) scalar where toKeyPair scalar = KeyPair (Edwards25519.toPoint scalar) scalar
encodePoint _ point = Ed25519.pointEncode point encodePoint _ point = Edwards25519.pointEncode point
decodePoint _ bs = Ed25519.pointDecode bs decodePoint _ bs = Edwards25519.pointDecode bs
instance EllipticCurveArith Curve_Ed25519 where instance EllipticCurveArith Curve_Edwards25519 where
pointAdd _ a b = Ed25519.pointAdd a b pointAdd _ a b = Edwards25519.pointAdd a b
pointNegate _ p = Ed25519.pointNegate p pointNegate _ p = Edwards25519.pointNegate p
pointSmul _ s p = Ed25519.pointMul s p pointSmul _ s p = Edwards25519.pointMul s p
checkNonZeroDH :: SharedSecret -> CryptoFailable SharedSecret checkNonZeroDH :: SharedSecret -> CryptoFailable SharedSecret
checkNonZeroDH s@(SharedSecret b) checkNonZeroDH s@(SharedSecret b)

View File

@ -1,14 +1,14 @@
-- | -- |
-- Module : Crypto.ECC.Ed25519 -- Module : Crypto.ECC.Edwards25519
-- License : BSD-style -- License : BSD-style
-- Maintainer : Olivier Chéron <olivier.cheron@gmail.com> -- Maintainer : Olivier Chéron <olivier.cheron@gmail.com>
-- Stability : experimental -- Stability : experimental
-- Portability : unknown -- Portability : unknown
-- --
-- Ed25519 arithmetic primitives. -- Arithmetic primitives over curve edwards25519.
-- --
{-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-}
module Crypto.ECC.Ed25519 module Crypto.ECC.Edwards25519
( Scalar ( Scalar
, Point , Point
-- * Scalars -- * Scalars
@ -47,7 +47,7 @@ import Crypto.Random
scalarArraySize :: Int scalarArraySize :: Int
scalarArraySize = 40 -- maximum [9 * 4 {- 32 bits -}, 5 * 8 {- 64 bits -}] scalarArraySize = 40 -- maximum [9 * 4 {- 32 bits -}, 5 * 8 {- 64 bits -}]
-- | A scalar modulo order of curve Ed25519. -- | A scalar modulo order of curve edwards25519.
newtype Scalar = Scalar ScrubbedBytes newtype Scalar = Scalar ScrubbedBytes
deriving (Show,NFData) deriving (Show,NFData)
@ -61,7 +61,7 @@ instance Eq Scalar where
pointArraySize :: Int pointArraySize :: Int
pointArraySize = 160 -- maximum [4 * 10 * 4 {- 32 bits -}, 4 * 5 * 8 {- 64 bits -}] pointArraySize = 160 -- maximum [4 * 10 * 4 {- 32 bits -}, 4 * 5 * 8 {- 64 bits -}]
-- | A point on curve Ed25519. -- | A point on curve edwards25519.
newtype Point = Point Bytes newtype Point = Point Bytes
deriving NFData deriving NFData
@ -156,7 +156,7 @@ pointEncode (Point p) =
ed25519_point_encode out pp ed25519_point_encode out pp
-- | Deserialize a 32-byte array as a point, ensuring the point is -- | Deserialize a 32-byte array as a point, ensuring the point is
-- valid on Ed25519. -- valid on edwards25519.
-- --
-- /WARNING:/ variable time -- /WARNING:/ variable time
pointDecode :: B.ByteArrayAccess bs => bs -> CryptoFailable Point pointDecode :: B.ByteArrayAccess bs => bs -> CryptoFailable Point
@ -197,7 +197,7 @@ pointDouble (Point a) =
withByteArray a $ \pa -> withByteArray a $ \pa ->
ed25519_point_double out pa ed25519_point_double out pa
-- | Scalar multiplication over Ed25519. -- | Scalar multiplication over curve edwards25519.
pointMul :: Scalar -> Point -> Point pointMul :: Scalar -> Point -> Point
pointMul (Scalar scalar) (Point base) = pointMul (Scalar scalar) (Point base) =
Point $ B.allocAndFreeze pointArraySize $ \out -> Point $ B.allocAndFreeze pointArraySize $ \out ->

View File

@ -121,7 +121,7 @@ Library
Crypto.Data.AFIS Crypto.Data.AFIS
Crypto.Data.Padding Crypto.Data.Padding
Crypto.ECC Crypto.ECC
Crypto.ECC.Ed25519 Crypto.ECC.Edwards25519
Crypto.Error Crypto.Error
Crypto.MAC.CMAC Crypto.MAC.CMAC
Crypto.MAC.Poly1305 Crypto.MAC.Poly1305
@ -371,7 +371,7 @@ Test-Suite test-cryptonite
ChaCha ChaCha
BCrypt BCrypt
ECC ECC
ECC.Ed25519 ECC.Edwards25519
Hash Hash
Imports Imports
KAT_AES.KATCBC KAT_AES.KATCBC

View File

@ -1,8 +1,8 @@
{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE OverloadedStrings #-}
module ECC.Ed25519 ( tests ) where module ECC.Edwards25519 ( tests ) where
import Crypto.Error import Crypto.Error
import Crypto.ECC.Ed25519 import Crypto.ECC.Edwards25519
import Imports import Imports
instance Arbitrary Scalar where instance Arbitrary Scalar where
@ -12,7 +12,7 @@ instance Arbitrary Scalar where
instance Arbitrary Point where instance Arbitrary Point where
arbitrary = toPoint `fmap` arbitrary arbitrary = toPoint `fmap` arbitrary
tests = testGroup "ECC.Ed25519" tests = testGroup "ECC.Edwards25519"
[ testGroup "vectors" [ testGroup "vectors"
[ testCase "11*G" $ p011 @=? toPoint s011 [ testCase "11*G" $ p011 @=? toPoint s011
, testCase "123*G" $ p123 @=? toPoint s123 , testCase "123*G" $ p123 @=? toPoint s123

View File

@ -7,7 +7,7 @@ import qualified Number
import qualified Number.F2m import qualified Number.F2m
import qualified BCrypt import qualified BCrypt
import qualified ECC import qualified ECC
import qualified ECC.Ed25519 import qualified ECC.Edwards25519
import qualified Hash import qualified Hash
import qualified Poly1305 import qualified Poly1305
import qualified Salsa import qualified Salsa
@ -84,7 +84,7 @@ tests = testGroup "cryptonite"
] ]
, KAT_AFIS.tests , KAT_AFIS.tests
, ECC.tests , ECC.tests
, ECC.Ed25519.tests , ECC.Edwards25519.tests
] ]
main = defaultMain tests main = defaultMain tests