Switch Haskell APIs to decaf implementation
Module 'Curve448' now use decaf.
This commit is contained in:
parent
efcae3ac11
commit
23b359d842
@ -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 ()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user