{-# LINE 1 "OpenSSL/DH.hsc" #-}-- | Diffie-Hellman key exchange{-# LINE 2 "OpenSSL/DH.hsc" #-}moduleOpenSSL.DH(DHP,DH,DHGen(..),genDHParams,getDHLength,checkDHParams,genDH,getDHParams,getDHPublicKey,computeDHKey)whereimportData.Word(Word8)importData.ByteString(ByteString)importqualifiedData.ByteString.InternalasBSimportControl.Applicative((<$>))importForeign.Ptr(Ptr,nullPtr){-# LINE 21 "OpenSSL/DH.hsc" #-}importForeign.C.Types(CInt(..)){-# LINE 25 "OpenSSL/DH.hsc" #-}importForeign.Marshal.Alloc(alloca)importOpenSSL.BNimportOpenSSL.DH.InternalimportOpenSSL.UtilsdataDHGen=DHGen2|DHGen5deriving(Eq,Ord,Show)-- | @'genDHParams' gen n@ generates @n@-bit long DH parameters.genDHParams::DHGen->Int->IODHPgenDHParamsgenlen=do_DH_generate_parameters(fromIntegrallen)gen'nullPtrnullPtr>>=failIfNull>>=wrapDHPPtrwheregen'=casegenofDHGen2->2DHGen5->5-- | Get DH parameters length (in bits).getDHLength::DHP->IOIntgetDHLengthdh=fromIntegral<$>withDHPPtrdh_DH_length-- | Check that DH parameters are coherent.checkDHParams::DHP->IOBoolcheckDHParamsdh=alloca$\pErr->withDHPPtrdh$\dhPtr->_DH_checkdhPtrpErr-- | The first step of a key exchange. Public and private keys are generated.genDH::DHP->IODHgenDHdh=dodh'<-withDHPPtrdh_DH_dup>>=failIfNull>>=wrapDHPPtrwithDHPPtrdh'_DH_generate_key>>=failIf_(/=1)return$asDHdh'-- | Get parameters of a key exchange.getDHParams::DH->DHPgetDHParams=asDHP-- | Get the public key.getDHPublicKey::DH->IOIntegergetDHPublicKeydh=withDHPtrdh$\dhPtr->dopKey<-_DH_get_pub_keydhPtrbnToInteger(wrapBNpKey)-- | Compute the shared key using the other party's public key.computeDHKey::DH->Integer->IOByteStringcomputeDHKeydhpubKey=withDHPtrdh$\dhPtr->withBNpubKey$\bn->dosize<-fromIntegral<$>_DH_sizedhPtrBS.createAndTrimsize$\bsPtr->fromIntegral<$>_DH_compute_keybsPtr(unwrapBNbn)dhPtr>>=failIf(<0)foreignimportccall"DH_generate_parameters"_DH_generate_parameters::CInt->CInt->Ptr()->Ptr()->IO(PtrDH_)foreignimportccall"DH_generate_key"_DH_generate_key::PtrDH_->IOCIntforeignimportccall"DH_compute_key"_DH_compute_key::PtrWord8->PtrBIGNUM->PtrDH_->IOCIntforeignimportccall"DH_check"_DH_check::PtrDH_->PtrCInt->IOBoolforeignimportccallunsafe"DH_size"_DH_size::PtrDH_->IOCIntforeignimportccallunsafe"HsOpenSSL_DHparams_dup"_DH_dup::PtrDH_->IO(PtrDH_)foreignimportccallunsafe"HsOpenSSL_DH_get_pub_key"_DH_get_pub_key::PtrDH_->IO(PtrBIGNUM)foreignimportccallunsafe"HsOpenSSL_DH_length"_DH_length::PtrDH_->IOCInt