Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
e65c12b
Add FFI for bls signatures, add `Dual` curve abstraction, `PointSize`…
perturbing Dec 8, 2025
79724d6
Add `BLS12381MinVerKeyDSIGN` and `BLS12381MinSigDSIGN` to the `DSIGN`…
perturbing Dec 8, 2025
eb45517
extend `DSIGNAlgorithm` with `DSIGNAggregatable` and implement it for…
perturbing Dec 9, 2025
501d142
Add utility function `HexBS` to `Cardano.Crypto.Util`
perturbing Dec 11, 2025
dcca823
Change `testDSIGNAlgorithm` to allow for other `ContextDSIGN` than `(…
perturbing Dec 11, 2025
252a9ad
Add BLS `BLS12381MinVerKeyDSIGN` and `BLS12381MinSigDSIGN` `DSIGN` to…
perturbing Dec 12, 2025
426f9d1
change bls `verifyDSIGN` to use C FFI interface
perturbing Dec 16, 2025
df5ed23
Add tests and bench for `DSIGNAGgregatable v` and impl for bls `MinSi…
perturbing Dec 17, 2025
430fdfa
add changes to CHANGELOG
perturbing Dec 18, 2025
a5934e4
Fix haddocks
ch1bo Jan 5, 2026
a32804e
Add newlines in instance DSIGN BLS12381 definition
ch1bo Jan 5, 2026
bd3cd9d
Add more newlines and fix commentary
ch1bo Jan 5, 2026
2ab0c54
add to changelog, refactore PoP naming, fix plural function name
perturbing Jan 7, 2026
f10130b
simplify `blsSigContextGen`, drop redudent test check, drop `hexBS`
perturbing Jan 7, 2026
d85d85b
redo G1/G2 type families, add haddock for `c_blst_core_verify`
perturbing Jan 7, 2026
3607e21
add type application fromIntegral, add error prefix, fix PoP deserial…
perturbing Jan 7, 2026
9caaf64
Rename WithoutPoPs functions and drop verifyAggregate methods
ch1bo Jan 8, 2026
4dac916
Add SignContext record type, encode points instead of psbs, fix small…
perturbing Jan 8, 2026
e23a917
fix ptr names, `INLINE` all functions, move `with*` in signing, cleanup
perturbing Jan 9, 2026
3f41c2a
fix `show` and `eq` for signing key over `Scalar`, remove `FinalVerif…
perturbing Jan 9, 2026
f1d9d84
add changelog entry for `genKeyDSIGNWithKeyInfo`
perturbing Jan 9, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cardano-crypto-class/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## 2.2.4.0

* Add `BLS12-381` aggregatable signature schemes
* Extend `DSIGNAlgorithm v` to also support optional `genKeyDSIGNWithKeyInfo`
* Introduce `DSIGNAggregatable v` class that extends `DSIGNAlgorithm v`
* Add Cabal components using code moved from `cardano-crypto-tests`:
- `lib:testlib`
- `lib:benchlib`
Expand Down
2 changes: 2 additions & 0 deletions cardano-crypto-class/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ This package defines type classes and mock instances for the following cryptogra

- A digital signature scheme

- An aggregatable signature scheme

- A cryptographic hashing function

- A key-evolving signature scheme
Expand Down
126 changes: 119 additions & 7 deletions cardano-crypto-class/bench/Bench/Crypto/DSIGN.hs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}

{- FOURMOLU_DISABLE -}

Expand All @@ -15,6 +14,7 @@ module Bench.Crypto.DSIGN

import Data.Proxy
import Data.ByteString (ByteString)
import qualified Data.Foldable as F

import Control.DeepSeq

Expand All @@ -29,11 +29,15 @@ import Cardano.Crypto.Hash.Blake2b
import Criterion

import Bench.Crypto.BenchData

import Cardano.Crypto.DSIGN.BLS12381 (BLS12381MinSigDSIGN, BLS12381MinVerKeyDSIGN, BLS12381DSIGN, BLS12381SignContext (..))

benchmarks :: Benchmark
benchmarks = bgroup "DSIGN"
[ benchDSIGN (Proxy :: Proxy Ed25519DSIGN) "Ed25519"
, benchDSIGN (Proxy :: Proxy BLS12381MinVerKeyDSIGN) "BLS12381MinVerKey"
, benchDSIGN (Proxy :: Proxy BLS12381MinSigDSIGN) "BLS12381MinSig"
, benchAggDSIGN (Proxy :: Proxy BLS12381MinVerKeyDSIGN) "BLS12381MinVerKey"
, benchAggDSIGN (Proxy :: Proxy BLS12381MinSigDSIGN) "BLS12381MinSig"
#ifdef SECP256K1_ENABLED
, benchDSIGN (Proxy :: Proxy EcdsaSecp256k1DSIGN) "EcdsaSecp256k1"
, benchDSIGN (Proxy :: Proxy SchnorrSecp256k1DSIGN) "SchnorrSecp256k1"
Expand All @@ -42,9 +46,9 @@ benchmarks = bgroup "DSIGN"

benchDSIGN :: forall v a
. ( DSIGNAlgorithm v
, ContextDSIGN v ~ ()
, Signable v a
, ExampleSignable v a
, ExampleContext v
, NFData (SignKeyDSIGN v)
, NFData (VerKeyDSIGN v)
, NFData (SigDSIGN v)
Expand All @@ -53,21 +57,24 @@ benchDSIGN :: forall v a
-> String
-> Benchmark
benchDSIGN _ lbl =
let msg = exampleSignable (Proxy @v)
ctx = exampleContext (Proxy @v)
in
bgroup lbl
[ bench "genKeyDSIGN" $
nf (genKeyDSIGN @v) testSeed

, env (return (genKeyDSIGN @v testSeed)) $ \signKey ->
bench "signDSIGN" $
nf (signDSIGN @v () (exampleSignable (Proxy @v))) signKey
nf (signDSIGN @v ctx msg) signKey

, env (let signKey = genKeyDSIGN @v testSeed
verKey = deriveVerKeyDSIGN signKey
sig = signDSIGN @v () (exampleSignable (Proxy @v)) signKey
sig = signDSIGN @v ctx msg signKey
in return (verKey, sig)
) $ \ ~(verKey, sig) ->
bench "verifyDSIGN" $
nf (verifyDSIGN @v () verKey (exampleSignable (Proxy @v))) sig
nf (verifyDSIGN @v ctx verKey msg) sig
]

-- | A helper class to gloss over the differences in the 'Signable' constraint
Expand All @@ -79,10 +86,115 @@ class ExampleSignable v a | v -> a where
instance ExampleSignable Ed25519DSIGN ByteString where
exampleSignable _ = typicalMsg

instance ExampleSignable (BLS12381DSIGN curve) ByteString where
exampleSignable _ = typicalMsg

#ifdef SECP256K1_ENABLED
instance ExampleSignable EcdsaSecp256k1DSIGN MessageHash where
exampleSignable _ = hashAndPack (Proxy @Blake2b_256) typicalMsg

instance ExampleSignable SchnorrSecp256k1DSIGN ByteString where
exampleSignable _ = typicalMsg
#endif

-- | Provide an example context for each DSIGN algorithm.
-- similar to 'ExampleSignable', this glosses over differences in the
-- 'ContextDSIGN' associated type.
class ExampleContext v where
exampleContext :: Proxy v -> ContextDSIGN v

instance ExampleContext Ed25519DSIGN where
exampleContext _ = ()

#ifdef SECP256K1_ENABLED
instance ExampleContext EcdsaSecp256k1DSIGN where
exampleContext _ = ()

instance ExampleContext SchnorrSecp256k1DSIGN where
exampleContext _ = ()
#endif

-- | This example context sets both the dst and augmentation to Nothing.
instance ExampleContext (BLS12381DSIGN curve) where
exampleContext _ = BLS12381SignContext Nothing Nothing

benchAggDSIGN :: forall v a
. ( DSIGNAggregatable v
, Signable v a
, ExampleSignable v a
, ExampleContext v
, NFData (SignKeyDSIGN v)
, NFData (VerKeyDSIGN v)
, NFData (SigDSIGN v)
, NFData (PossessionProofDSIGN v)
)
=> Proxy v
-> String
-> Benchmark
benchAggDSIGN _ lbl =
let msg = exampleSignable (Proxy @v)
ctx = exampleContext (Proxy @v)
ns = 1 : [100, 200 .. 1000]
in bgroup (lbl <> "/Aggregatable") $
[ bgroup ("n=" <> show n)
[ env (pure (mkCase @v ctx msg n)) $ \c ->
bench "provePoP (all)" $
nf (proveAllPoPs @v ctx) (caseSKs c)

, env (pure (mkCase @v ctx msg n)) $ \c ->
bench "verifyPoP (all)" $
nf (verifyAllPoPs @v ctx) (caseVKPoPs c)

, env (pure (mkCase @v ctx msg n)) $ \c ->
bench "aggregateVerKeys (with PoPs)" $
nf (aggregateVerKeysDSIGN @v ctx) (caseVKPoPs c)

, env (pure (mkCase @v ctx msg n)) $ \c ->
bench "aggregateVerKeys (no PoPs)" $
nf (uncheckedAggregateVerKeysDSIGN @v) (caseVKs c)

, env (pure (mkCase @v ctx msg n)) $ \c ->
bench "aggregateSig" $
nf (aggregateSigsDSIGN @v) (caseSigs c)
]
| n <- ns
]

data AggCase v = AggCase
{ caseSKs :: ![SignKeyDSIGN v]
, caseVKs :: ![VerKeyDSIGN v]
, caseVKPoPs :: ![(VerKeyDSIGN v, PossessionProofDSIGN v)]
, caseSigs :: ![SigDSIGN v]
}

instance
( NFData (SignKeyDSIGN v)
, NFData (VerKeyDSIGN v)
, NFData (PossessionProofDSIGN v)
, NFData (SigDSIGN v)
) => NFData (AggCase v) where
rnf (AggCase sks vks vkp sigs) =
rnf sks `seq`
rnf vks `seq`
rnf vkp `seq`
rnf sigs

mkCase :: forall v a. (DSIGNAggregatable v, Signable v a)
=> ContextDSIGN v -> a -> Int -> AggCase v
mkCase ctx msg n =
let sks = replicate n (genKeyDSIGN @v testSeed)
vks = map deriveVerKeyDSIGN sks
pops = map (createPossessionProofDSIGN @v ctx) sks
sigs = map (signDSIGN @v ctx msg) sks
vkp = zip vks pops
in AggCase sks vks vkp sigs

proveAllPoPs :: forall v. DSIGNAggregatable v
=> ContextDSIGN v -> [SignKeyDSIGN v] -> [PossessionProofDSIGN v]
proveAllPoPs ctx = map (createPossessionProofDSIGN @v ctx)

verifyAllPoPs :: forall v. DSIGNAggregatable v
=> ContextDSIGN v
-> [(VerKeyDSIGN v, PossessionProofDSIGN v)]
-> Either String ()
verifyAllPoPs ctx = F.foldl' (\acc (vk,pop) -> acc >> verifyPossessionProofDSIGN @v ctx vk pop) (Right ())
1 change: 1 addition & 0 deletions cardano-crypto-class/cardano-crypto-class.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ library
hs-source-dirs: src
exposed-modules:
Cardano.Crypto.DSIGN
Cardano.Crypto.DSIGN.BLS12381
Cardano.Crypto.DSIGN.Class
Cardano.Crypto.DSIGN.Ed25519
Cardano.Crypto.DSIGN.Ed448
Expand Down
1 change: 1 addition & 0 deletions cardano-crypto-class/src/Cardano/Crypto/DSIGN.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module Cardano.Crypto.DSIGN (
)
where

import Cardano.Crypto.DSIGN.BLS12381 as X
import Cardano.Crypto.DSIGN.Class as X
import Cardano.Crypto.DSIGN.Ed25519 as X
import Cardano.Crypto.DSIGN.Ed448 as X
Expand Down
Loading