cardano-crypto-class-2.1.1.0: Type classes abstracting over cryptography primitives for Cardano
Safe HaskellSafe-Inferred
LanguageHaskell2010

Cardano.Crypto.KES.Class

Description

Abstract key evolving signatures.

Synopsis

KES algorithm class

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

Associated Types

data VerKeyKES v :: Type #

data SigKES v :: Type #

type SeedSizeKES v :: Nat #

type SizeVerKeyKES v :: Nat #

type SizeSignKeyKES v :: Nat #

type SizeSigKES v :: Nat #

type ContextKES v :: Type #

Context required to run the KES algorithm

Unit by default (no context required)

type ContextKES v = ()

type Signable v :: Type -> Constraint #

type Signable v = Empty

Methods

algorithmNameKES :: proxy v -> String #

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

verifyKES #

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.

totalPeriodsKES :: proxy v -> Word #

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.

rawSerialiseVerKeyKES :: VerKeyKES v -> ByteString #

rawSerialiseSigKES :: SigKES v -> ByteString #

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

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

Instances

Instances details
KESAlgorithm NeverKES # 
Instance details

Defined in Cardano.Crypto.KES.NeverUsed

(DSIGNMAlgorithmBase d, KnownNat (SizeSigDSIGNM d + SizeVerKeyDSIGNM d)) => KESAlgorithm (CompactSingleKES d) # 
Instance details

Defined in Cardano.Crypto.KES.CompactSingle

KnownNat t => KESAlgorithm (MockKES t) #

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

Associated Types

data VerKeyKES (MockKES t) #

data SigKES (MockKES t) #

type SeedSizeKES (MockKES t) :: Nat #

type SizeVerKeyKES (MockKES t) :: Nat #

type SizeSignKeyKES (MockKES t) :: Nat #

type SizeSigKES (MockKES t) :: Nat #

type ContextKES (MockKES t) #

type Signable (MockKES t) :: Type -> Constraint #

DSIGNMAlgorithmBase d => KESAlgorithm (SingleKES d) # 
Instance details

Defined in Cardano.Crypto.KES.Single

Associated Types

data VerKeyKES (SingleKES d) #

data SigKES (SingleKES d) #

type SeedSizeKES (SingleKES d) :: Nat #

type SizeVerKeyKES (SingleKES d) :: Nat #

type SizeSignKeyKES (SingleKES d) :: Nat #

type SizeSigKES (SingleKES d) :: Nat #

type ContextKES (SingleKES d) #

type Signable (SingleKES d) :: Type -> Constraint #

(OptimizedKESAlgorithm d, SodiumHashAlgorithm h, SizeHash h ~ SeedSizeKES d, NoThunks (VerKeyKES (CompactSumKES h d)), KnownNat (SizeVerKeyKES (CompactSumKES h d)), KnownNat (SizeSignKeyKES (CompactSumKES h d)), KnownNat (SizeSigKES (CompactSumKES h d))) => KESAlgorithm (CompactSumKES h d) # 
Instance details

Defined in Cardano.Crypto.KES.CompactSum

(DSIGNMAlgorithmBase d, KnownNat t, KnownNat (SeedSizeDSIGNM d * t), KnownNat (SizeVerKeyDSIGNM d * t), KnownNat (SizeSignKeyDSIGNM d * t)) => KESAlgorithm (SimpleKES d t) # 
Instance details

Defined in Cardano.Crypto.KES.Simple

Associated Types

data VerKeyKES (SimpleKES d t) #

data SigKES (SimpleKES d t) #

type SeedSizeKES (SimpleKES d t) :: Nat #

type SizeVerKeyKES (SimpleKES d t) :: Nat #

type SizeSignKeyKES (SimpleKES d t) :: Nat #

type SizeSigKES (SimpleKES d t) :: Nat #

type ContextKES (SimpleKES d t) #

type Signable (SimpleKES d t) :: Type -> Constraint #

(KESAlgorithm d, SodiumHashAlgorithm h, SizeHash h ~ SeedSizeKES d, KnownNat ((SizeSignKeyKES d + SeedSizeKES d) + (2 * SizeVerKeyKES d)), KnownNat (SizeSigKES d + (SizeVerKeyKES d * 2))) => KESAlgorithm (SumKES h d) # 
Instance details

Defined in Cardano.Crypto.KES.Sum

Associated Types

data VerKeyKES (SumKES h d) #

data SigKES (SumKES h d) #

type SeedSizeKES (SumKES h d) :: Nat #

type SizeVerKeyKES (SumKES h d) :: Nat #

type SizeSignKeyKES (SumKES h d) :: Nat #

type SizeSigKES (SumKES h d) :: Nat #

type ContextKES (SumKES h d) #

type Signable (SumKES h d) :: Type -> Constraint #

class (KESAlgorithm v, Monad m) => KESSignAlgorithm m v where #

Associated Types

data SignKeyKES v :: Type #

Methods

deriveVerKeyKES :: SignKeyKES v -> m (VerKeyKES v) #

signKES #

Arguments

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

The current period for the key

-> a 
-> SignKeyKES v 
-> m (SigKES v) 

updateKES #

Arguments

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

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

-> m (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.

genKeyKES :: MLockedSeed (SeedSizeKES v) -> m (SignKeyKES v) #

forgetSignKeyKES :: SignKeyKES v -> m () #

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.

Instances

Instances details
Monad m => KESSignAlgorithm m NeverKES # 
Instance details

Defined in Cardano.Crypto.KES.NeverUsed

Associated Types

data SignKeyKES NeverKES #

(DSIGNMAlgorithm m d, KnownNat (SizeSigDSIGNM d + SizeVerKeyDSIGNM d)) => KESSignAlgorithm m (CompactSingleKES d) # 
Instance details

Defined in Cardano.Crypto.KES.CompactSingle

Associated Types

data SignKeyKES (CompactSingleKES d) #

(Monad m, KnownNat t) => KESSignAlgorithm m (MockKES t) # 
Instance details

Defined in Cardano.Crypto.KES.Mock

Associated Types

data SignKeyKES (MockKES t) #

DSIGNMAlgorithm m d => KESSignAlgorithm m (SingleKES d) # 
Instance details

Defined in Cardano.Crypto.KES.Single

Associated Types

data SignKeyKES (SingleKES d) #

(OptimizedKESAlgorithm d, KESSignAlgorithm m d, SodiumHashAlgorithm h, SizeHash h ~ SeedSizeKES d, MonadSodium m, MonadST m, MonadThrow m, NoThunks (VerKeyKES (CompactSumKES h d)), KnownNat (SizeVerKeyKES (CompactSumKES h d)), KnownNat (SizeSignKeyKES (CompactSumKES h d)), KnownNat (SizeSigKES (CompactSumKES h d))) => KESSignAlgorithm m (CompactSumKES h d) # 
Instance details

Defined in Cardano.Crypto.KES.CompactSum

Associated Types

data SignKeyKES (CompactSumKES h d) #

(KESAlgorithm (SimpleKES d t), DSIGNMAlgorithm m d, KnownNat t, KnownNat (SeedSizeDSIGNM d * t), MonadEvaluate m, MonadSodium m, MonadST m) => KESSignAlgorithm m (SimpleKES d t) # 
Instance details

Defined in Cardano.Crypto.KES.Simple

Associated Types

data SignKeyKES (SimpleKES d t) #

(KESSignAlgorithm m d, SodiumHashAlgorithm h, SizeHash h ~ SeedSizeKES d, MonadSodium m, MonadST m, MonadThrow m, KnownNat ((SizeSignKeyKES d + SeedSizeKES d) + (2 * SizeVerKeyKES d)), KnownNat (SizeSigKES d + (SizeVerKeyKES d * 2))) => KESSignAlgorithm m (SumKES h d) # 
Instance details

Defined in Cardano.Crypto.KES.Sum

Associated Types

data SignKeyKES (SumKES h d) #

Methods

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

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

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

genKeyKES :: MLockedSeed (SeedSizeKES (SumKES h d)) -> m (SignKeyKES (SumKES h d)) #

forgetSignKeyKES :: SignKeyKES (SumKES h d) -> m () #

type Period = Word #

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 #

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 #

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 #

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 #

Constructors

SignedKES 

Fields

Instances

Instances details
Generic (SignedKES v a) # 
Instance details

Defined in Cardano.Crypto.KES.Class

Associated Types

type Rep (SignedKES v a) :: Type -> Type Source #

Methods

from :: SignedKES v a -> Rep (SignedKES v a) x Source #

to :: Rep (SignedKES v a) x -> SignedKES v a Source #

KESAlgorithm v => Show (SignedKES v a) # 
Instance details

Defined in Cardano.Crypto.KES.Class

KESAlgorithm v => Eq (SignedKES v a) # 
Instance details

Defined in Cardano.Crypto.KES.Class

Methods

(==) :: SignedKES v a -> SignedKES v a -> Bool Source #

(/=) :: SignedKES v a -> SignedKES v a -> Bool Source #

KESAlgorithm v => NoThunks (SignedKES v a) # 
Instance details

Defined in Cardano.Crypto.KES.Class

type Rep (SignedKES v a) # 
Instance details

Defined in Cardano.Crypto.KES.Class

type Rep (SignedKES v a) = D1 ('MetaData "SignedKES" "Cardano.Crypto.KES.Class" "cardano-crypto-class-2.1.1.0-inplace" 'True) (C1 ('MetaCons "SignedKES" 'PrefixI 'True) (S1 ('MetaSel ('Just "getSig") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (SigKES v))))

signedKES :: (KESSignAlgorithm m v, Signable v a) => ContextKES v -> Period -> a -> SignKeyKES v -> m (SignedKES v a) #

CBOR encoding and decoding

decodeVerKeyKES :: forall v s. KESAlgorithm v => Decoder s (VerKeyKES v) #

decodeSigKES :: forall v s. KESAlgorithm v => Decoder s (SigKES v) #

Encoded Size expressions

encodedVerKeyKESSizeExpr :: forall v. KESAlgorithm v => Proxy (VerKeyKES v) -> Size #

Size expression for VerKeyKES which is using sizeVerKeyKES encoded as Size.

encodedSignKeyKESSizeExpr :: forall v. KESAlgorithm v => Proxy (SignKeyKES v) -> Size #

Size expression for SignKeyKES which is using sizeSignKeyKES encoded as Size.

encodedSigKESSizeExpr :: forall v. KESAlgorithm v => Proxy (SigKES v) -> Size #

Size expression for SigKES which is using sizeSigKES encoded as Size.

Raw sizes

sizeVerKeyKES :: forall v proxy. KESAlgorithm v => proxy v -> Word #

sizeSigKES :: forall v proxy. KESAlgorithm v => proxy v -> Word #

sizeSignKeyKES :: forall v proxy. KESAlgorithm v => proxy v -> Word #

seedSizeKES :: forall v proxy. KESAlgorithm v => proxy v -> Word #

The upper bound on the Seed size needed by genKeyKES

Unsound API

class KESSignAlgorithm m v => UnsoundKESSignAlgorithm m v where #

Unsound operations on KES sign keys. These operations violate secure forgetting constraints by leaking secrets to unprotected memory. Consider using the DirectSerialise / DirectDeserialise APIs instead.

Instances

Instances details
Monad m => UnsoundKESSignAlgorithm m NeverKES # 
Instance details

Defined in Cardano.Crypto.KES.NeverUsed

(KESSignAlgorithm m (CompactSingleKES d), UnsoundDSIGNMAlgorithm m d) => UnsoundKESSignAlgorithm m (CompactSingleKES d) # 
Instance details

Defined in Cardano.Crypto.KES.CompactSingle

(Monad m, KnownNat t) => UnsoundKESSignAlgorithm m (MockKES t) # 
Instance details

Defined in Cardano.Crypto.KES.Mock

(KESSignAlgorithm m (SingleKES d), UnsoundDSIGNMAlgorithm m d) => UnsoundKESSignAlgorithm m (SingleKES d) # 
Instance details

Defined in Cardano.Crypto.KES.Single

(KESSignAlgorithm m (CompactSumKES h d), UnsoundKESSignAlgorithm m d, MonadSodium m, MonadST m) => UnsoundKESSignAlgorithm m (CompactSumKES h d) # 
Instance details

Defined in Cardano.Crypto.KES.CompactSum

(UnsoundDSIGNMAlgorithm m d, KnownNat t, KESSignAlgorithm m (SimpleKES d t)) => UnsoundKESSignAlgorithm m (SimpleKES d t) # 
Instance details

Defined in Cardano.Crypto.KES.Simple

(KESSignAlgorithm m (SumKES h d), UnsoundKESSignAlgorithm m d, MonadSodium m, MonadST m) => UnsoundKESSignAlgorithm m (SumKES h d) # 
Instance details

Defined in Cardano.Crypto.KES.Sum

Utility functions