packages feed

hsblst 0.0.1 → 0.0.2

raw patch · 5 files changed

+32/−3 lines, 5 filesdep ~basePVP ok

version bump matches the API change (PVP)

Dependency ranges changed: base

API changes (from Hackage documentation)

Files

CHANGELOG.md view
@@ -3,6 +3,11 @@    - SPDX-License-Identifier: MPL-2.0    --> +## v0.0.2++* Prevent inlining of foreign calls. This fixes a potential efficiency issue,+  but it shouldn't affect correctness.+ ## v0.0.1  * Initial release
hsblst.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack  name:           hsblst-version:        0.0.1+version:        0.0.2 synopsis:       Haskell bindings to BLST description:    HsBLST is low-level Haskell bindings and a high-level interface to [BLST](https://github.com/supranational/blst) -- a multilingual BLS12-381 signature library. category:       Cryptography@@ -19,8 +19,8 @@ build-type:     Simple tested-with:     GHC == 9.0.2-  , GHC == 9.2.7-  , GHC == 9.4.4+  , GHC == 9.2.8+  , GHC == 9.4.5 extra-source-files:     README.md     CHANGELOG.md
src/Crypto/BLST.hs view
@@ -67,10 +67,12 @@ -- | Generate a secret key from bytes. keygen :: (ByteArrayAccess ba, 32 <= n, KnownNat n) => SizedByteArray n ba -> SecretKey keygen = SecretKey . unsafePerformIO . B.keygen . unSizedByteArray+{-# NOINLINE keygen #-}  -- | Convert a secret key to the corresponding public key on a given curve. skToPk :: forall c. IsCurve c => SecretKey -> PublicKey c skToPk (SecretKey sk) = PublicKey $ unsafePerformIO $ skToPkPoint sk >>= toAffine+{-# NOINLINE skToPk #-}  -- | Serialize public key. serializePk@@ -78,6 +80,7 @@   => PublicKey c   -> SizedByteArray (SerializedSize (CurveToPkPoint c)) Bytes serializePk (PublicKey pk) = unsafePerformIO $ affSerialize pk+{-# NOINLINE serializePk #-}  -- | Deserialize public key. deserializePk@@ -85,6 +88,7 @@   => SizedByteArray (SerializedSize (CurveToPkPoint c)) ba   -> Either B.BlstError (PublicKey c) deserializePk bs = unsafePerformIO $ fmap PublicKey <$> deserialize bs+{-# NOINLINE deserializePk #-}  -- | Compress public key. compressPk@@ -92,6 +96,7 @@   => PublicKey c   -> SizedByteArray (CompressedSize (CurveToPkPoint c)) Bytes compressPk (PublicKey pk) = unsafePerformIO $ affCompress pk+{-# NOINLINE compressPk #-}  -- | Decompress public key. decompressPk@@ -99,6 +104,7 @@   => SizedByteArray (CompressedSize (CurveToPkPoint c)) ba   -> Either B.BlstError (PublicKey c) decompressPk bs = unsafePerformIO $ fmap PublicKey <$> uncompress bs+{-# NOINLINE decompressPk #-}  -- | Sign a single message. sign@@ -110,6 +116,7 @@ sign (SecretKey sk) bytes dst = Signature $ unsafePerformIO $ do   encMsg <- toCurve @m bytes dst   signPk encMsg sk >>= toAffine+{-# NOINLINE sign #-}  -- | Serialize message signature. serializeSignature@@ -117,6 +124,7 @@   => Signature c m   -> SizedByteArray (SerializedSize (CurveToMsgPoint c)) Bytes serializeSignature (Signature sig) = unsafePerformIO $ affSerialize sig+{-# NOINLINE serializeSignature #-}  -- | Deserialize message signature. deserializeSignature@@ -124,6 +132,7 @@   => SizedByteArray (SerializedSize (CurveToMsgPoint c)) ba   -> Either B.BlstError (Signature c m) deserializeSignature bs = unsafePerformIO $ fmap Signature <$> deserialize bs+{-# NOINLINE deserializeSignature #-}  -- | Serialize and compress message signature. compressSignature@@ -131,6 +140,7 @@   => Signature c m   -> SizedByteArray (CompressedSize (CurveToMsgPoint c)) Bytes compressSignature (Signature sig) = unsafePerformIO $ affCompress sig+{-# NOINLINE compressSignature #-}  -- | Decompress and deserialize message signature. decompressSignature@@ -138,6 +148,7 @@   => SizedByteArray (CompressedSize (CurveToMsgPoint c)) ba   -> Either B.BlstError (Signature c m) decompressSignature bs = unsafePerformIO $ fmap Signature <$> uncompress bs+{-# NOINLINE decompressSignature #-}  -- | Verify message signature. verify@@ -151,6 +162,7 @@   unsafePerformIO $ coreVerifyPk pk sig meth bytes dst   where     meth = demote @m+{-# NOINLINE verify #-}  -- | Convenience synonym for 'Nothing'. Do not use domain separation tag. noDST :: Maybe Bytes@@ -159,10 +171,12 @@ -- | Serialize secret key. serializeSk :: SecretKey -> SizedByteArray B.SkSerializeSize ScrubbedBytes serializeSk (SecretKey sk) = unsafePerformIO $ B.lendianFromScalar sk+{-# NOINLINE serializeSk #-}  -- | Deserialize secret key. deserializeSk :: ByteArrayAccess ba => SizedByteArray B.SkSerializeSize ba -> SecretKey deserializeSk bs = SecretKey $ unsafePerformIO $ B.scalarFromLendian bs+{-# NOINLINE deserializeSk #-}  -- | Aggregate multiple signatures. aggregateSignatures :: forall c m. IsCurve c => NonEmpty (Signature c m) -> Signature c m@@ -171,6 +185,7 @@   foldlM add start xs >>= toAffine   where     add x' (Signature y) = addOrDoubleAffine x' y+{-# NOINLINE aggregateSignatures #-}  -- | Aggregate signature verification. aggregateVerify@@ -191,3 +206,4 @@     checkThrow = \case       B.BlstSuccess -> pure ()       x -> throwIO x+{-# NOINLINE aggregateVerify #-}
test/Test/BLST/Fixtures.hs view
@@ -51,6 +51,7 @@  expectedKey :: B.Scalar expectedKey = unsafePerformIO $ B.scalarFromLendian $ fromHex expectedSerKey+{-# NOINLINE expectedKey #-}  expectedSerKey :: Text expectedSerKey =@@ -155,6 +156,7 @@  expectedAffSignHash1 :: B.Affine 'B.P2 expectedAffSignHash1 = unsafePerformIO $ B.p2ToAffine expectedSignHash1+{-# NOINLINE expectedAffSignHash1 #-}  expectedSignHash2 :: B.Point 'B.P1 expectedSignHash2 = deserializePoint@@ -167,6 +169,7 @@  expectedAffSignHash2 :: B.Affine 'B.P1 expectedAffSignHash2 = unsafePerformIO $ B.p1ToAffine expectedSignHash2+{-# NOINLINE expectedAffSignHash2 #-}  expectedSignEnc1 :: B.Point 'B.P2 expectedSignEnc1 = deserializePoint@@ -185,6 +188,7 @@  expectedAffSignEnc1 :: B.Affine 'B.P2 expectedAffSignEnc1 = unsafePerformIO $ B.p2ToAffine expectedSignEnc1+{-# NOINLINE expectedAffSignEnc1 #-}  expectedSignEnc2 :: B.Point 'B.P1 expectedSignEnc2 = deserializePoint@@ -197,6 +201,7 @@  expectedAffSignEnc2 :: B.Affine 'B.P1 expectedAffSignEnc2 = unsafePerformIO $ B.p1ToAffine expectedSignEnc2+{-# NOINLINE expectedAffSignEnc2 #-}  expectedAffPk1 :: B.Affine 'B.P1 expectedAffPk1 = deserializeAffine' expectedSer1
test/Test/BLST/Util.hs view
@@ -40,12 +40,15 @@  deserializePoint :: C.IsPoint p => Text -> B.Point p deserializePoint = unsafePerformIO . C.fromAffine . deserializeAffine+{-# NOINLINE deserializePoint #-}  deserializePoint' :: C.IsPoint p => SizedByteArray (C.SerializedSize p) Bytes -> B.Point p deserializePoint' = unsafePerformIO . C.fromAffine . deserializeAffine'+{-# NOINLINE deserializePoint' #-}  deserializeAffine :: C.IsPoint p => Text -> B.Affine p deserializeAffine = deserializeAffine' . fromHex  deserializeAffine' :: C.IsPoint p => SizedByteArray (C.SerializedSize p) Bytes -> B.Affine p deserializeAffine' = unsafePerformIO . fmap (either (error . show) id) . C.deserialize+{-# NOINLINE deserializeAffine' #-}