From 23b359d842dc7017187a8b70fbdbb6d6e92cf5c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Ch=C3=A9ron?= Date: Mon, 2 Jan 2017 11:35:14 +0100 Subject: [PATCH] Switch Haskell APIs to decaf implementation Module 'Curve448' now use decaf. --- Crypto/PubKey/Curve448.hs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/Crypto/PubKey/Curve448.hs b/Crypto/PubKey/Curve448.hs index a9237b1..1101a0f 100644 --- a/Crypto/PubKey/Curve448.hs +++ b/Crypto/PubKey/Curve448.hs @@ -7,6 +7,10 @@ -- -- Curve448 support -- +-- Internally uses Decaf point compression to omit the cofactor +-- and implementation by Mike Hamburg. Externally API and +-- data types are compatible with the encoding specified in RFC 7748. +-- {-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE MagicHash #-} module Crypto.PubKey.Curve448 @@ -81,7 +85,7 @@ dh (PublicKey pub) (SecretKey sec) = DhSecret <$> B.allocAndFreeze x448_bytes $ \result -> withByteArray sec $ \psec -> withByteArray pub $ \ppub -> - ccryptonite_ed448 result psec ppub + decaf_x448 result ppub psec {-# NOINLINE dh #-} -- | Create a public key from a secret key @@ -89,7 +93,7 @@ toPublic :: SecretKey -> PublicKey toPublic (SecretKey sec) = PublicKey <$> B.allocAndFreeze x448_bytes $ \result -> withByteArray sec $ \psec -> - ccryptonite_ed448 result psec basePoint + decaf_x448 result basePoint psec where basePoint = Ptr "\x05\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"# {-# NOINLINE toPublic #-} @@ -101,8 +105,8 @@ generateSecretKey = SecretKey <$> getRandomBytes x448_bytes x448_bytes :: Int x448_bytes = 448 `quot` 8 -foreign import ccall "cryptonite_x448" - ccryptonite_ed448 :: Ptr Word8 -- ^ public - -> Ptr Word8 -- ^ secret - -> Ptr Word8 -- ^ basepoint - -> IO () +foreign import ccall "cryptonite_decaf_x448" + decaf_x448 :: Ptr Word8 -- ^ public + -> Ptr Word8 -- ^ basepoint + -> Ptr Word8 -- ^ secret + -> IO ()