cardano-crypto-class-2.0.0.0.1: Type classes abstracting over cryptography primitives for Cardano
Safe Haskell None
Language Haskell2010

Cardano.Crypto.KES.Class

Description

Abstract key evolving signatures.

Synopsis

KES algorithm class

class ( Typeable v, Show ( VerKeyKES v), Eq ( VerKeyKES v), Show ( SignKeyKES v), Show ( SigKES v), Eq ( SigKES v), NoThunks ( SigKES v), NoThunks ( SignKeyKES v), NoThunks ( VerKeyKES v), KnownNat ( SeedSizeKES v)) => KESAlgorithm v where Source #

Associated Types

type SeedSizeKES v :: Nat Source #

data VerKeyKES v :: Type Source #

data SignKeyKES v :: Type Source #

data SigKES v :: Type Source #

type ContextKES v :: Type Source #

Context required to run the KES algorithm

Unit by default (no context required)

type ContextKES v = ()

type Signable v :: Type -> Constraint Source #

Methods

algorithmNameKES :: proxy v -> String Source #

deriveVerKeyKES :: SignKeyKES v -> VerKeyKES v Source #

hashVerKeyKES :: HashAlgorithm h => VerKeyKES v -> Hash h ( VerKeyKES v) Source #

signKES Source #

Arguments

:: ( Signable v a, HasCallStack )
=> ContextKES v
-> Period

The current period for the key

-> a
-> SignKeyKES v
-> SigKES v

verifyKES Source #

Arguments

:: ( Signable v a, HasCallStack )
=> ContextKES v
-> VerKeyKES v
-> Period

The current period for the key

-> a
-> SigKES v
-> Either String ()

Full KES verification. This method checks that the signature itself checks out (as per verifySigKES ), and also makes sure that it matches the provided VerKey.

updateKES Source #

Arguments

:: HasCallStack
=> ContextKES v
-> SignKeyKES v
-> Period

The current period for the key, not the target period.

-> Maybe ( SignKeyKES v)

Update the KES signature key to the next period, given the current period.

It returns Nothing if the cannot be evolved any further.

The precondition (to get a Just result) is that the current KES period of the input key is not the last period. The given period must be the current KES period of the input key (not the next or target).

The postcondition is that in case a key is returned, its current KES period is incremented by one compared to before.

Note that you must track the current period separately, and to skip to a later period requires repeated use of this function, since it only increments one period at once.

totalPeriodsKES :: proxy v -> Word Source #

Return the total number of KES periods supported by this algorithm. The KES algorithm is assumed to support a fixed maximum number of periods, not a variable number.

Do note that this is the total number of periods not the total number of evolutions. The difference is off-by-one. For example if there are 2 periods (period 0 and 1) then there is only one evolution.

genKeyKES :: Seed -> SignKeyKES v Source #

seedSizeKES :: proxy v -> Word Source #

The upper bound on the Seed size needed by genKeyKES

forgetSignKeyKES :: SignKeyKES v -> IO () Source #

Forget a signing key synchronously, rather than waiting for GC. In some non-mock instances this provides a guarantee that the signing key is no longer in memory.

The precondition is that this key value will not be used again.

sizeVerKeyKES :: proxy v -> Word Source #

sizeSignKeyKES :: proxy v -> Word Source #

sizeSigKES :: proxy v -> Word Source #

rawSerialiseVerKeyKES :: VerKeyKES v -> ByteString Source #

rawSerialiseSignKeyKES :: SignKeyKES v -> ByteString Source #

rawSerialiseSigKES :: SigKES v -> ByteString Source #

rawDeserialiseVerKeyKES :: ByteString -> Maybe ( VerKeyKES v) Source #

rawDeserialiseSignKeyKES :: ByteString -> Maybe ( SignKeyKES v) Source #

rawDeserialiseSigKES :: ByteString -> Maybe ( SigKES v) Source #

Instances

Instances details
KESAlgorithm NeverKES Source #
Instance details

Defined in Cardano.Crypto.KES.NeverUsed

KnownNat t => KESAlgorithm ( MockKES t) Source #

Mock key evolving signatures.

What is the difference between Mock KES and Simple KES ( Cardano.Crypto.KES.Simple ), you may ask? Simple KES satisfies the outward appearance of a KES scheme through assembling a pre-generated list of keys and iterating through them. Mock KES, on the other hand, pretends to be KES but in fact does no key evolution whatsoever.

Simple KES is appropriate for testing, since it will for example reject old keys. Mock KES is more suitable for a basic testnet, since it doesn't suffer from the performance implications of shuffling a giant list of keys around

Instance details

Defined in Cardano.Crypto.KES.Mock

Methods

algorithmNameKES :: proxy ( MockKES t) -> String Source #

deriveVerKeyKES :: SignKeyKES ( MockKES t) -> VerKeyKES ( MockKES t) Source #

hashVerKeyKES :: HashAlgorithm h => VerKeyKES ( MockKES t) -> Hash h ( VerKeyKES ( MockKES t)) Source #

signKES :: ( Signable ( MockKES t) a, HasCallStack ) => ContextKES ( MockKES t) -> Period -> a -> SignKeyKES ( MockKES t) -> SigKES ( MockKES t) Source #

verifyKES :: ( Signable ( MockKES t) a, HasCallStack ) => ContextKES ( MockKES t) -> VerKeyKES ( MockKES t) -> Period -> a -> SigKES ( MockKES t) -> Either String () Source #

updateKES :: ContextKES ( MockKES t) -> SignKeyKES ( MockKES t) -> Period -> Maybe ( SignKeyKES ( MockKES t)) Source #

totalPeriodsKES :: proxy ( MockKES t) -> Word Source #

genKeyKES :: Seed -> SignKeyKES ( MockKES t) Source #

seedSizeKES :: proxy ( MockKES t) -> Word Source #

forgetSignKeyKES :: SignKeyKES ( MockKES t) -> IO () Source #

sizeVerKeyKES :: proxy ( MockKES t) -> Word Source #

sizeSignKeyKES :: proxy ( MockKES t) -> Word Source #

sizeSigKES :: proxy ( MockKES t) -> Word Source #

rawSerialiseVerKeyKES :: VerKeyKES ( MockKES t) -> ByteString Source #

rawSerialiseSignKeyKES :: SignKeyKES ( MockKES t) -> ByteString Source #

rawSerialiseSigKES :: SigKES ( MockKES t) -> ByteString Source #

rawDeserialiseVerKeyKES :: ByteString -> Maybe ( VerKeyKES ( MockKES t)) Source #

rawDeserialiseSignKeyKES :: ByteString -> Maybe ( SignKeyKES ( MockKES t)) Source #

rawDeserialiseSigKES :: ByteString -> Maybe ( SigKES ( MockKES t)) Source #

( DSIGNAlgorithm d, Typeable d) => KESAlgorithm ( SingleKES d) Source #
Instance details

Defined in Cardano.Crypto.KES.Single

Methods

algorithmNameKES :: proxy ( SingleKES d) -> String Source #

deriveVerKeyKES :: SignKeyKES ( SingleKES d) -> VerKeyKES ( SingleKES d) Source #

hashVerKeyKES :: HashAlgorithm h => VerKeyKES ( SingleKES d) -> Hash h ( VerKeyKES ( SingleKES d)) Source #

signKES :: ( Signable ( SingleKES d) a, HasCallStack ) => ContextKES ( SingleKES d) -> Period -> a -> SignKeyKES ( SingleKES d) -> SigKES ( SingleKES d) Source #

verifyKES :: ( Signable ( SingleKES d) a, HasCallStack ) => ContextKES ( SingleKES d) -> VerKeyKES ( SingleKES d) -> Period -> a -> SigKES ( SingleKES d) -> Either String () Source #

updateKES :: ContextKES ( SingleKES d) -> SignKeyKES ( SingleKES d) -> Period -> Maybe ( SignKeyKES ( SingleKES d)) Source #

totalPeriodsKES :: proxy ( SingleKES d) -> Word Source #

genKeyKES :: Seed -> SignKeyKES ( SingleKES d) Source #

seedSizeKES :: proxy ( SingleKES d) -> Word Source #

forgetSignKeyKES :: SignKeyKES ( SingleKES d) -> IO () Source #

sizeVerKeyKES :: proxy ( SingleKES d) -> Word Source #

sizeSignKeyKES :: proxy ( SingleKES d) -> Word Source #

sizeSigKES :: proxy ( SingleKES d) -> Word Source #

rawSerialiseVerKeyKES :: VerKeyKES ( SingleKES d) -> ByteString Source #

rawSerialiseSignKeyKES :: SignKeyKES ( SingleKES d) -> ByteString Source #

rawSerialiseSigKES :: SigKES ( SingleKES d) -> ByteString Source #

rawDeserialiseVerKeyKES :: ByteString -> Maybe ( VerKeyKES ( SingleKES d)) Source #

rawDeserialiseSignKeyKES :: ByteString -> Maybe ( SignKeyKES ( SingleKES d)) Source #

rawDeserialiseSigKES :: ByteString -> Maybe ( SigKES ( SingleKES d)) Source #

( DSIGNAlgorithm d, Typeable d) => KESAlgorithm ( CompactSingleKES d) Source #
Instance details

Defined in Cardano.Crypto.KES.CompactSingle

Methods

algorithmNameKES :: proxy ( CompactSingleKES d) -> String Source #

deriveVerKeyKES :: SignKeyKES ( CompactSingleKES d) -> VerKeyKES ( CompactSingleKES d) Source #

hashVerKeyKES :: HashAlgorithm h => VerKeyKES ( CompactSingleKES d) -> Hash h ( VerKeyKES ( CompactSingleKES d)) Source #

signKES :: ( Signable ( CompactSingleKES d) a, HasCallStack ) => ContextKES ( CompactSingleKES d) -> Period -> a -> SignKeyKES ( CompactSingleKES d) -> SigKES ( CompactSingleKES d) Source #

verifyKES :: ( Signable ( CompactSingleKES d) a, HasCallStack ) => ContextKES ( CompactSingleKES d) -> VerKeyKES ( CompactSingleKES d) -> Period -> a -> SigKES ( CompactSingleKES d) -> Either String () Source #

updateKES :: ContextKES ( CompactSingleKES d) -> SignKeyKES ( CompactSingleKES d) -> Period -> Maybe ( SignKeyKES ( CompactSingleKES d)) Source #

totalPeriodsKES :: proxy ( CompactSingleKES d) -> Word Source #

genKeyKES :: Seed -> SignKeyKES ( CompactSingleKES d) Source #

seedSizeKES :: proxy ( CompactSingleKES d) -> Word Source #

forgetSignKeyKES :: SignKeyKES ( CompactSingleKES d) -> IO () Source #

sizeVerKeyKES :: proxy ( CompactSingleKES d) -> Word Source #

sizeSignKeyKES :: proxy ( CompactSingleKES d) -> Word Source #

sizeSigKES :: proxy ( CompactSingleKES d) -> Word Source #

rawSerialiseVerKeyKES :: VerKeyKES ( CompactSingleKES d) -> ByteString Source #

rawSerialiseSignKeyKES :: SignKeyKES ( CompactSingleKES d) -> ByteString Source #

rawSerialiseSigKES :: SigKES ( CompactSingleKES d) -> ByteString Source #

rawDeserialiseVerKeyKES :: ByteString -> Maybe ( VerKeyKES ( CompactSingleKES d)) Source #

rawDeserialiseSignKeyKES :: ByteString -> Maybe ( SignKeyKES ( CompactSingleKES d)) Source #

rawDeserialiseSigKES :: ByteString -> Maybe ( SigKES ( CompactSingleKES d)) Source #

( KESAlgorithm d, HashAlgorithm h, Typeable d) => KESAlgorithm ( SumKES h d) Source #
Instance details

Defined in Cardano.Crypto.KES.Sum

Methods

algorithmNameKES :: proxy ( SumKES h d) -> String Source #

deriveVerKeyKES :: SignKeyKES ( SumKES h d) -> VerKeyKES ( SumKES h d) Source #

hashVerKeyKES :: HashAlgorithm h0 => VerKeyKES ( SumKES h d) -> Hash h0 ( VerKeyKES ( SumKES h d)) Source #

signKES :: ( Signable ( SumKES h d) a, HasCallStack ) => ContextKES ( SumKES h d) -> Period -> a -> SignKeyKES ( SumKES h d) -> SigKES ( SumKES h d) Source #

verifyKES :: ( Signable ( SumKES h d) a, HasCallStack ) => ContextKES ( SumKES h d) -> VerKeyKES ( SumKES h d) -> Period -> a -> SigKES ( SumKES h d) -> Either String () Source #

updateKES :: ContextKES ( SumKES h d) -> SignKeyKES ( SumKES h d) -> Period -> Maybe ( SignKeyKES ( SumKES h d)) Source #

totalPeriodsKES :: proxy ( SumKES h d) -> Word Source #

genKeyKES :: Seed -> SignKeyKES ( SumKES h d) Source #

seedSizeKES :: proxy ( SumKES h d) -> Word Source #

forgetSignKeyKES :: SignKeyKES ( SumKES h d) -> IO () Source #

sizeVerKeyKES :: proxy ( SumKES h d) -> Word Source #

sizeSignKeyKES :: proxy ( SumKES h d) -> Word Source #

sizeSigKES :: proxy ( SumKES h d) -> Word Source #

rawSerialiseVerKeyKES :: VerKeyKES ( SumKES h d) -> ByteString Source #

rawSerialiseSignKeyKES :: SignKeyKES ( SumKES h d) -> ByteString Source #

rawSerialiseSigKES :: SigKES ( SumKES h d) -> ByteString Source #

rawDeserialiseVerKeyKES :: ByteString -> Maybe ( VerKeyKES ( SumKES h d)) Source #

rawDeserialiseSignKeyKES :: ByteString -> Maybe ( SignKeyKES ( SumKES h d)) Source #

rawDeserialiseSigKES :: ByteString -> Maybe ( SigKES ( SumKES h d)) Source #

( DSIGNAlgorithm d, Typeable d, KnownNat t, KnownNat ( SeedSizeDSIGN d * t)) => KESAlgorithm ( SimpleKES d t) Source #
Instance details

Defined in Cardano.Crypto.KES.Simple

Methods

algorithmNameKES :: proxy ( SimpleKES d t) -> String Source #

deriveVerKeyKES :: SignKeyKES ( SimpleKES d t) -> VerKeyKES ( SimpleKES d t) Source #

hashVerKeyKES :: HashAlgorithm h => VerKeyKES ( SimpleKES d t) -> Hash h ( VerKeyKES ( SimpleKES d t)) Source #

signKES :: ( Signable ( SimpleKES d t) a, HasCallStack ) => ContextKES ( SimpleKES d t) -> Period -> a -> SignKeyKES ( SimpleKES d t) -> SigKES ( SimpleKES d t) Source #

verifyKES :: ( Signable ( SimpleKES d t) a, HasCallStack ) => ContextKES ( SimpleKES d t) -> VerKeyKES ( SimpleKES d t) -> Period -> a -> SigKES ( SimpleKES d t) -> Either String () Source #

updateKES :: ContextKES ( SimpleKES d t) -> SignKeyKES ( SimpleKES d t) -> Period -> Maybe ( SignKeyKES ( SimpleKES d t)) Source #

totalPeriodsKES :: proxy ( SimpleKES d t) -> Word Source #

genKeyKES :: Seed -> SignKeyKES ( SimpleKES d t) Source #

seedSizeKES :: proxy ( SimpleKES d t) -> Word Source #

forgetSignKeyKES :: SignKeyKES ( SimpleKES d t) -> IO () Source #

sizeVerKeyKES :: proxy ( SimpleKES d t) -> Word Source #

sizeSignKeyKES :: proxy ( SimpleKES d t) -> Word Source #

sizeSigKES :: proxy ( SimpleKES d t) -> Word Source #

rawSerialiseVerKeyKES :: VerKeyKES ( SimpleKES d t) -> ByteString Source #

rawSerialiseSignKeyKES :: SignKeyKES ( SimpleKES d t) -> ByteString Source #

rawSerialiseSigKES :: SigKES ( SimpleKES d t) -> ByteString Source #

rawDeserialiseVerKeyKES :: ByteString -> Maybe ( VerKeyKES ( SimpleKES d t)) Source #

rawDeserialiseSignKeyKES :: ByteString -> Maybe ( SignKeyKES ( SimpleKES d t)) Source #

rawDeserialiseSigKES :: ByteString -> Maybe ( SigKES ( SimpleKES d t)) Source #

( OptimizedKESAlgorithm d, HashAlgorithm h, Typeable d) => KESAlgorithm ( CompactSumKES h d) Source #
Instance details

Defined in Cardano.Crypto.KES.CompactSum

Methods

algorithmNameKES :: proxy ( CompactSumKES h d) -> String Source #

deriveVerKeyKES :: SignKeyKES ( CompactSumKES h d) -> VerKeyKES ( CompactSumKES h d) Source #

hashVerKeyKES :: HashAlgorithm h0 => VerKeyKES ( CompactSumKES h d) -> Hash h0 ( VerKeyKES ( CompactSumKES h d)) Source #

signKES :: ( Signable ( CompactSumKES h d) a, HasCallStack ) => ContextKES ( CompactSumKES h d) -> Period -> a -> SignKeyKES ( CompactSumKES h d) -> SigKES ( CompactSumKES h d) Source #

verifyKES :: ( Signable ( CompactSumKES h d) a, HasCallStack ) => ContextKES ( CompactSumKES h d) -> VerKeyKES ( CompactSumKES h d) -> Period -> a -> SigKES ( CompactSumKES h d) -> Either String () Source #

updateKES :: ContextKES ( CompactSumKES h d) -> SignKeyKES ( CompactSumKES h d) -> Period -> Maybe ( SignKeyKES ( CompactSumKES h d)) Source #

totalPeriodsKES :: proxy ( CompactSumKES h d) -> Word Source #

genKeyKES :: Seed -> SignKeyKES ( CompactSumKES h d) Source #

seedSizeKES :: proxy ( CompactSumKES h d) -> Word Source #

forgetSignKeyKES :: SignKeyKES ( CompactSumKES h d) -> IO () Source #

sizeVerKeyKES :: proxy ( CompactSumKES h d) -> Word Source #

sizeSignKeyKES :: proxy ( CompactSumKES h d) -> Word Source #

sizeSigKES :: proxy ( CompactSumKES h d) -> Word Source #

rawSerialiseVerKeyKES :: VerKeyKES ( CompactSumKES h d) -> ByteString Source #

rawSerialiseSignKeyKES :: SignKeyKES ( CompactSumKES h d) -> ByteString Source #

rawSerialiseSigKES :: SigKES ( CompactSumKES h d) -> ByteString Source #

rawDeserialiseVerKeyKES :: ByteString -> Maybe ( VerKeyKES ( CompactSumKES h d)) Source #

rawDeserialiseSignKeyKES :: ByteString -> Maybe ( SignKeyKES ( CompactSumKES h d)) Source #

rawDeserialiseSigKES :: ByteString -> Maybe ( SigKES ( CompactSumKES h d)) Source #

type Period = Word Source #

The KES period. Periods are enumerated from zero.

Be careful of fencepost errors: if there are 2 periods (period 0 and 1) then there is only one key evolution.

class KESAlgorithm v => OptimizedKESAlgorithm v where Source #

Subclass for KES algorithms that embed a copy of the VerKey into the signature itself, rather than relying on the externally supplied VerKey alone. Some optimizations made in the CompactSingleKES and CompactSumKES implementations require this additional interface in order to avoid redundant computations.

Methods

verifySigKES Source #

Arguments

:: ( Signable v a, HasCallStack )
=> ContextKES v
-> Period

The current period for the key

-> a
-> SigKES v
-> Either String ()

Partial verification: this method only verifies the signature itself, but it does not check it against any externally-provided VerKey. Use verifyKES for full KES verification.

verKeyFromSigKES :: ContextKES v -> Period -> SigKES v -> VerKeyKES v Source #

Extract a VerKey from a SigKES. Note that a VerKey embedded in or derived from a SigKES is effectively user-supplied, so it is not enough to validate a SigKES against this VerKey (like verifySigKES does); you must also compare the VerKey against an externally-provided key that you want to verify against (see verifyKES ).

SignedKES wrapper

newtype SignedKES v a Source #

Constructors

SignedKES

Fields

CBOR encoding and decoding

Encoded Size expressions

Utility functions