haskell-crypto / cryptonite

lowlevel set of cryptographic primitives for haskell
Other
226 stars 139 forks source link

Sign function taking way too much time #370

Closed sauraww closed 1 year ago

sauraww commented 2 years ago

I am trying to to create a signature for a random string of size about 500kb , it is getting stuck there and taking around 30-40 minutes. Am I doing anything wrong ?

Function Implementation :

 signData :: BS.ByteString -> IO (Maybe BS.ByteString)
signData message = do
  let privateKey = readKeyFileFromMemory (BSU.fromString getPrivateKey)
  case privateKey of
    [Unprotected (PrivKeyDSA dsaPvtKey)] -> do
      dataSign <- DSA.sign dsaPvtKey SHA1 message
      let signatureVal = BS64.encode $ encodeASN1' DER $
                            [Start Sequence,
                            IntVal (DSA.sign_r dataSign),
                            IntVal (DSA.sign_s dataSign),
                            End Sequence]
      pure $ Just $ signatureVal
    _ -> pure $ Nothing

can anybody suggest someway to improve the performance, or if there is anything wrong with this implementation.

ysangkok commented 2 years ago

You could check if it is due to this infinite loop: https://github.com/haskell-foundation/foundation/issues/569

sauraww commented 2 years ago

My GHC version is 8.8.4 @ysangkok