| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
Cardano.Crypto.KES.Class
Description
Abstract key evolving signatures.
Synopsis
- 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
- 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
- type Signable v :: Type -> Constraint
- algorithmNameKES :: proxy v -> String
- hashVerKeyKES :: HashAlgorithm h => VerKeyKES v -> Hash h (VerKeyKES v)
- verifyKES :: (Signable v a, HasCallStack) => ContextKES v -> VerKeyKES v -> Period -> a -> SigKES v -> Either String ()
- totalPeriodsKES :: proxy v -> Word
- rawSerialiseVerKeyKES :: VerKeyKES v -> ByteString
- rawSerialiseSigKES :: SigKES v -> ByteString
- rawDeserialiseVerKeyKES :: ByteString -> Maybe (VerKeyKES v)
- rawDeserialiseSigKES :: ByteString -> Maybe (SigKES v)
- class (KESAlgorithm v, Monad m) => KESSignAlgorithm m v where
- data SignKeyKES v :: Type
- deriveVerKeyKES :: SignKeyKES v -> m (VerKeyKES v)
- signKES :: forall a. (Signable v a, HasCallStack) => ContextKES v -> Period -> a -> SignKeyKES v -> m (SigKES v)
- updateKES :: HasCallStack => ContextKES v -> SignKeyKES v -> Period -> m (Maybe (SignKeyKES v))
- genKeyKES :: MLockedSeed (SeedSizeKES v) -> m (SignKeyKES v)
- forgetSignKeyKES :: SignKeyKES v -> m ()
- type Period = Word
- class KESAlgorithm v => OptimizedKESAlgorithm v where
- verifySigKES :: (Signable v a, HasCallStack) => ContextKES v -> Period -> a -> SigKES v -> Either String ()
- verKeyFromSigKES :: ContextKES v -> Period -> SigKES v -> VerKeyKES v
- verifyOptimizedKES :: (OptimizedKESAlgorithm v, Signable v a, HasCallStack) => ContextKES v -> VerKeyKES v -> Period -> a -> SigKES v -> Either String ()
- newtype SignedKES v a = SignedKES {}
- signedKES :: (KESSignAlgorithm m v, Signable v a) => ContextKES v -> Period -> a -> SignKeyKES v -> m (SignedKES v a)
- verifySignedKES :: (KESAlgorithm v, Signable v a) => ContextKES v -> VerKeyKES v -> Period -> a -> SignedKES v a -> Either String ()
- encodeVerKeyKES :: KESAlgorithm v => VerKeyKES v -> Encoding
- decodeVerKeyKES :: forall v s. KESAlgorithm v => Decoder s (VerKeyKES v)
- encodeSigKES :: KESAlgorithm v => SigKES v -> Encoding
- decodeSigKES :: forall v s. KESAlgorithm v => Decoder s (SigKES v)
- encodeSignedKES :: KESAlgorithm v => SignedKES v a -> Encoding
- decodeSignedKES :: KESAlgorithm v => Decoder s (SignedKES v a)
- encodedVerKeyKESSizeExpr :: forall v. KESAlgorithm v => Proxy (VerKeyKES v) -> Size
- encodedSignKeyKESSizeExpr :: forall v. KESAlgorithm v => Proxy (SignKeyKES v) -> Size
- encodedSigKESSizeExpr :: forall v. KESAlgorithm v => Proxy (SigKES v) -> Size
- 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
- class KESSignAlgorithm m v => UnsoundKESSignAlgorithm m v where
- rawDeserialiseSignKeyKES :: ByteString -> m (Maybe (SignKeyKES v))
- rawSerialiseSignKeyKES :: SignKeyKES v -> m ByteString
- encodeSignKeyKES :: forall v m. UnsoundKESSignAlgorithm m v => SignKeyKES v -> m Encoding
- decodeSignKeyKES :: forall v s m. UnsoundKESSignAlgorithm m v => Decoder s (m (Maybe (SignKeyKES v)))
- hashPairOfVKeys :: (KESAlgorithm d, HashAlgorithm h) => (VerKeyKES d, VerKeyKES d) -> Hash h (VerKeyKES d, VerKeyKES d)
- mungeName :: String -> String
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 #
Minimal complete definition
algorithmNameKES, verifyKES, totalPeriodsKES, rawSerialiseVerKeyKES, rawSerialiseSigKES, rawDeserialiseVerKeyKES, rawDeserialiseSigKES
Associated Types
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 #
Methods
algorithmNameKES :: proxy v -> String #
hashVerKeyKES :: HashAlgorithm h => VerKeyKES v -> Hash h (VerKeyKES v) #
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
class (KESAlgorithm v, Monad m) => KESSignAlgorithm m v where #
Associated Types
data SignKeyKES v :: Type #
Methods
deriveVerKeyKES :: SignKeyKES v -> m (VerKeyKES v) #
Arguments
| :: forall a. (Signable v a, HasCallStack) | |
| => ContextKES v | |
| -> Period | The current period for the key |
| -> a | |
| -> SignKeyKES v | |
| -> m (SigKES v) |
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
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
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).
Instances
| (KESAlgorithm (CompactSingleKES d), DSIGNMAlgorithmBase d) => OptimizedKESAlgorithm (CompactSingleKES d) # | |
Defined in Cardano.Crypto.KES.CompactSingle Methods verifySigKES :: (Signable (CompactSingleKES d) a, HasCallStack) => ContextKES (CompactSingleKES d) -> Period -> a -> SigKES (CompactSingleKES d) -> Either String () # verKeyFromSigKES :: ContextKES (CompactSingleKES d) -> Period -> SigKES (CompactSingleKES d) -> VerKeyKES (CompactSingleKES d) # | |
| (KESAlgorithm (CompactSumKES h d), OptimizedKESAlgorithm d, HashAlgorithm h) => OptimizedKESAlgorithm (CompactSumKES h d) # | |
Defined in Cardano.Crypto.KES.CompactSum Methods verifySigKES :: (Signable (CompactSumKES h d) a, HasCallStack) => ContextKES (CompactSumKES h d) -> Period -> a -> SigKES (CompactSumKES h d) -> Either String () # verKeyFromSigKES :: ContextKES (CompactSumKES h d) -> Period -> SigKES (CompactSumKES h d) -> VerKeyKES (CompactSumKES h d) # | |
verifyOptimizedKES :: (OptimizedKESAlgorithm v, Signable v a, HasCallStack) => ContextKES v -> VerKeyKES v -> Period -> a -> SigKES v -> Either String () #
SignedKES wrapper
Instances
| Generic (SignedKES v a) # | |
| KESAlgorithm v => Show (SignedKES v a) # | |
| KESAlgorithm v => Eq (SignedKES v a) # | |
| KESAlgorithm v => NoThunks (SignedKES v a) # | |
| type Rep (SignedKES v a) # | |
Defined in Cardano.Crypto.KES.Class | |
signedKES :: (KESSignAlgorithm m v, Signable v a) => ContextKES v -> Period -> a -> SignKeyKES v -> m (SignedKES v a) #
verifySignedKES :: (KESAlgorithm v, Signable v a) => ContextKES v -> VerKeyKES v -> Period -> a -> SignedKES v a -> Either String () #
CBOR encoding and decoding
encodeVerKeyKES :: KESAlgorithm v => VerKeyKES v -> Encoding #
decodeVerKeyKES :: forall v s. KESAlgorithm v => Decoder s (VerKeyKES v) #
encodeSigKES :: KESAlgorithm v => SigKES v -> Encoding #
decodeSigKES :: forall v s. KESAlgorithm v => Decoder s (SigKES v) #
encodeSignedKES :: KESAlgorithm v => SignedKES v a -> Encoding #
decodeSignedKES :: KESAlgorithm v => Decoder s (SignedKES v a) #
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.
Methods
rawDeserialiseSignKeyKES :: ByteString -> m (Maybe (SignKeyKES v)) #
rawSerialiseSignKeyKES :: SignKeyKES v -> m ByteString #
Instances
encodeSignKeyKES :: forall v m. UnsoundKESSignAlgorithm m v => SignKeyKES v -> m Encoding #
decodeSignKeyKES :: forall v s m. UnsoundKESSignAlgorithm m v => Decoder s (m (Maybe (SignKeyKES v))) #
Utility functions
hashPairOfVKeys :: (KESAlgorithm d, HashAlgorithm h) => (VerKeyKES d, VerKeyKES d) -> Hash h (VerKeyKES d, VerKeyKES d) #