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

Cardano.Crypto.Seed

Description

Seeds for key generation.

Synopsis

Documentation

data Seed Source #

A seed contains a finite number of bytes, and is used for seeding cryptographic algorithms including key generation.

This is not itself a PRNG, but can be used to seed a PRNG.

Instances

Instances details
Monoid Seed Source # 
Instance details

Defined in Cardano.Crypto.Seed

Semigroup Seed Source # 
Instance details

Defined in Cardano.Crypto.Seed

Show Seed Source # 
Instance details

Defined in Cardano.Crypto.Seed

NFData Seed Source # 
Instance details

Defined in Cardano.Crypto.Seed

Methods

rnf :: Seed -> () Source #

Eq Seed Source # 
Instance details

Defined in Cardano.Crypto.Seed

Methods

(==) :: Seed -> Seed -> Bool Source #

(/=) :: Seed -> Seed -> Bool Source #

NoThunks Seed Source # 
Instance details

Defined in Cardano.Crypto.Seed

Constructing seeds

mkSeedFromBytes :: ByteString -> Seed Source #

Construct a Seed deterministically from a number of bytes.

getSeedBytes :: Seed -> ByteString Source #

Extract the full bytes from a seed. Note that this function does not guarantee that the result is sufficiently long for the desired seed size!

readSeedFromSystemEntropy :: Word -> IO Seed Source #

Obtain a Seed by reading n bytes of entropy from the operating system.

splitSeed :: Word -> Seed -> Maybe (Seed, Seed) Source #

Split a seed into two smaller seeds, the first of which is the given number of bytes large, and the second is the remaining. This will fail if not enough bytes are available. This can be chained multiple times provided the seed is big enough to cover each use.

expandSeed :: HashAlgorithm h => proxy h -> Seed -> (Seed, Seed) Source #

Expand a seed into a pair of seeds using a cryptographic hash function (in the role of a crypto PRNG). The whole input seed is consumed. The output seeds are the size of the hash output.

Using seeds

getBytesFromSeed :: Word -> Seed -> Maybe (ByteString, Seed) Source #

Get a number of bytes from the seed. This will fail if not enough bytes are available. This can be chained multiple times provided the seed is big enough to cover each use.

getBytesFromSeedT :: Word -> Seed -> (ByteString, Seed) Source #

A flavor of getBytesFromSeed that throws SeedBytesExhausted instead of returning Nothing.

runMonadRandomWithSeed :: Seed -> (forall m. MonadRandom m => m a) -> a Source #

Run an action in MonadRandom deterministically using a seed as a finite source of randomness. Note that this is not a PRNG, so like with getBytesFromSeed it will fail if more bytes are requested than are available.

So this is only really suitable for key generation where there is a known upper bound on the amount of entropy that will be requested.