{-# LANGUAGE DeriveDataTypeable, GeneralizedNewtypeDeriving, DeriveGeneric #-}
module Crypto.Saltine.Core.ScalarMult (
Scalar, GroupElement,
mult, multBase
) where
import Crypto.Saltine.Internal.Util
import Crypto.Saltine.Internal.ScalarMult
( c_scalarmult
, c_scalarmult_base
, GroupElement(..)
, Scalar(..)
)
import qualified Crypto.Saltine.Internal.ScalarMult as Bytes
mult :: Scalar -> GroupElement -> GroupElement
mult :: Scalar -> GroupElement -> GroupElement
mult (Sc ByteString
n) (GE ByteString
p) = ByteString -> GroupElement
GE (ByteString -> GroupElement)
-> ((Ptr CChar -> IO CInt) -> ByteString)
-> (Ptr CChar -> IO CInt)
-> GroupElement
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (CInt, ByteString) -> ByteString
forall a b. (a, b) -> b
snd ((CInt, ByteString) -> ByteString)
-> ((Ptr CChar -> IO CInt) -> (CInt, ByteString))
-> (Ptr CChar -> IO CInt)
-> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> (Ptr CChar -> IO CInt) -> (CInt, ByteString)
forall b. Int -> (Ptr CChar -> IO b) -> (b, ByteString)
buildUnsafeByteString Int
Bytes.scalarmult_bytes ((Ptr CChar -> IO CInt) -> GroupElement)
-> (Ptr CChar -> IO CInt) -> GroupElement
forall a b. (a -> b) -> a -> b
$ \Ptr CChar
pq ->
[ByteString] -> ([CStringLen] -> IO CInt) -> IO CInt
forall b. [ByteString] -> ([CStringLen] -> IO b) -> IO b
constByteStrings [ByteString
n, ByteString
p] (([CStringLen] -> IO CInt) -> IO CInt)
-> ([CStringLen] -> IO CInt) -> IO CInt
forall a b. (a -> b) -> a -> b
$ \[(Ptr CChar
pn, Int
_), (Ptr CChar
pp, Int
_)] ->
Ptr CChar -> Ptr CChar -> Ptr CChar -> IO CInt
c_scalarmult Ptr CChar
pq Ptr CChar
pn Ptr CChar
pp
multBase :: Scalar -> GroupElement
multBase :: Scalar -> GroupElement
multBase (Sc ByteString
n) = ByteString -> GroupElement
GE (ByteString -> GroupElement)
-> ((Ptr CChar -> IO CInt) -> ByteString)
-> (Ptr CChar -> IO CInt)
-> GroupElement
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (CInt, ByteString) -> ByteString
forall a b. (a, b) -> b
snd ((CInt, ByteString) -> ByteString)
-> ((Ptr CChar -> IO CInt) -> (CInt, ByteString))
-> (Ptr CChar -> IO CInt)
-> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> (Ptr CChar -> IO CInt) -> (CInt, ByteString)
forall b. Int -> (Ptr CChar -> IO b) -> (b, ByteString)
buildUnsafeByteString Int
Bytes.scalarmult_bytes ((Ptr CChar -> IO CInt) -> GroupElement)
-> (Ptr CChar -> IO CInt) -> GroupElement
forall a b. (a -> b) -> a -> b
$ \Ptr CChar
pq ->
[ByteString] -> ([CStringLen] -> IO CInt) -> IO CInt
forall b. [ByteString] -> ([CStringLen] -> IO b) -> IO b
constByteStrings [ByteString
n] (([CStringLen] -> IO CInt) -> IO CInt)
-> ([CStringLen] -> IO CInt) -> IO CInt
forall a b. (a -> b) -> a -> b
$ \[(Ptr CChar
pn, Int
_)] ->
Ptr CChar -> Ptr CChar -> IO CInt
c_scalarmult_base Ptr CChar
pq Ptr CChar
pn