File tree Expand file tree Collapse file tree 1 file changed +12
-5
lines changed Expand file tree Collapse file tree 1 file changed +12
-5
lines changed Original file line number Diff line number Diff line change @@ -755,18 +755,25 @@ schnorrSign mGen KeyPair{..} bs
755
755
keyPairPtr <- ContT (withForeignPtr keyPairFPtr)
756
756
lift $ do
757
757
sigBuf <- mallocBytes 64
758
- let randomPtr = case mGen of
759
- Just gen -> castPtr . unsafePerformIO . BS. useAsCString (BS. pack $ Prelude. take 32 $ randoms gen) $ return
760
- Nothing -> nullPtr
761
- ret <- Prim. schnorrsigSign ctx sigBuf msgHashPtr keyPairPtr randomPtr
758
+ ret <- case mGen of
759
+ Just gen -> do
760
+ let randomBytes = BS. pack $ Prelude. take 32 $ randoms gen
761
+ BS. useAsCStringLen randomBytes $ \ (ptr, _) ->
762
+ Prim. schnorrsigSign ctx sigBuf msgHashPtr keyPairPtr (castPtr ptr)
763
+ Nothing ->
764
+ Prim. schnorrsigSign ctx sigBuf msgHashPtr keyPairPtr nullPtr
762
765
if isSuccess ret
763
766
then Just . SchnorrSignature <$> newForeignPtr finalizerFree sigBuf
764
- else free sigBuf $> Nothing
767
+ else do
768
+ free sigBuf
769
+ return Nothing
770
+
765
771
766
772
-- | Compute a deterministic schnorr signature using a 'KeyPair'.
767
773
schnorrSignDeterministic :: KeyPair -> ByteString -> Maybe SchnorrSignature
768
774
schnorrSignDeterministic = schnorrSign Nothing
769
775
776
+
770
777
-- | Compute a non-deterministic schnorr signature using a 'KeyPair'.
771
778
schnorrSignNondeterministic :: KeyPair -> ByteString -> IO (Maybe SchnorrSignature )
772
779
schnorrSignNondeterministic kp bs = newStdGen >>= \ gen -> pure $ schnorrSign (Just gen) kp bs
You can’t perform that action at this time.
0 commit comments