{-|
Module      : Botan.Low.ElGamal
Description : Algorithm specific key operations: ElGamal
Copyright   : (c) Leo D, 2023
License     : BSD-3-Clause
Maintainer  : leo@apotheca.io
Stability   : experimental
Portability : POSIX
-}

module Botan.Low.PubKey.ElGamal where

import qualified Data.ByteString as ByteString

import Botan.Bindings.PubKey
import Botan.Bindings.PubKey.ElGamal

import Botan.Low.Error
import Botan.Low.Make
import Botan.Low.MPI
import Botan.Low.Prelude
import Botan.Low.PubKey
import Botan.Low.RNG

-- /*
-- * Algorithm specific key operations: ElGamal
-- */

privKeyCreateElGamal
    :: RNG          -- ^ __rng__: initialized PRNG
    -> Int          -- ^ __pbits__: length of the key in bits. Must be at least 1024
    -> Int          -- ^ __qbits__: order of the subgroup. Must be at least 160
    -> IO PrivKey   -- ^ __key__: handler to the resulting key
privKeyCreateElGamal :: RNG -> Int -> Int -> IO PrivKey
privKeyCreateElGamal RNG
rng Int
pbits Int
qbits = RNG -> (BotanRNG -> IO PrivKey) -> IO PrivKey
forall a. RNG -> (BotanRNG -> IO a) -> IO a
withRNG RNG
rng ((BotanRNG -> IO PrivKey) -> IO PrivKey)
-> (BotanRNG -> IO PrivKey) -> IO PrivKey
forall a b. (a -> b) -> a -> b
$ \ BotanRNG
botanRNG -> do
    (Ptr BotanPrivKey -> IO CInt) -> IO PrivKey
createPrivKey ((Ptr BotanPrivKey -> IO CInt) -> IO PrivKey)
-> (Ptr BotanPrivKey -> IO CInt) -> IO PrivKey
forall a b. (a -> b) -> a -> b
$ \ Ptr BotanPrivKey
out -> Ptr BotanPrivKey -> BotanRNG -> CSize -> CSize -> IO CInt
botan_privkey_create_elgamal
        Ptr BotanPrivKey
out
        BotanRNG
botanRNG
        (Int -> CSize
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
pbits)
        (Int -> CSize
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
qbits)

privKeyLoadElGamal
    :: MP           -- ^ __p__: prime order of a Z_p group
    -> MP           -- ^ __g__: group generator
    -> MP           -- ^ __x__: public key
    -> IO PrivKey   -- ^ __key__: variable populated with key material
privKeyLoadElGamal :: MP -> MP -> MP -> IO PrivKey
privKeyLoadElGamal = (Ptr BotanPrivKey -> BotanMP -> BotanMP -> BotanMP -> IO CInt)
-> MP -> MP -> MP -> IO PrivKey
mkPrivKeyLoad3 Ptr BotanPrivKey -> BotanMP -> BotanMP -> BotanMP -> IO CInt
botan_privkey_load_elgamal

pubKeyLoadElGamal
    :: MP           -- ^ __p__: prime order of a Z_p group
    -> MP           -- ^ __g__: group generator
    -> MP           -- ^ __y__: private key
    -> IO PubKey    -- ^ __key__: variable populated with key material
pubKeyLoadElGamal :: MP -> MP -> MP -> IO PubKey
pubKeyLoadElGamal = (Ptr BotanPubKey -> BotanMP -> BotanMP -> BotanMP -> IO CInt)
-> MP -> MP -> MP -> IO PubKey
mkPubKeyLoad3 Ptr BotanPubKey -> BotanMP -> BotanMP -> BotanMP -> IO CInt
botan_pubkey_load_elgamal