newhope-0.1.0.0: Library implementing the NewHope cryptographic key-exchange protocol

Copyright© Jeremy Bornstein 2019
LicenseApache 2.0
Maintainerjeremy@bornstein.org
Stabilityexperimental
Portabilityportable
Safe HaskellSafe
LanguageHaskell2010

Crypto.NewHope.SeedExpander

Contents

Description

The "seed expander" is a facility specified by NIST for generating pseudorandom data given a seed. It is not used in the actual NewHope key exchange and is provided here for completeness/isomorphism with the NewHope C reference library.

This module contains the public interface. Implementation definitions are in the Crypto.NewHope.Internal.SeedExpander module.

  • Sample usage
   let maxLen' = case maxLen 256 of Right value -> value
                                    Left x      -> error (show x)

   let diversifier = case createDiversifier (BSC.pack "12345678") of Right value -> value
                                                                     Left x      -> error (show x)

   let seed = (Internals.makeSeed "32 bytes of seed data go here...")

   let ctx = case seedexpanderInit seed diversifier maxLen' of Right value -> value
                                                               Left x      -> error (show x)

   let (ctx', buf) = case seedexpander ctx 16 of Right value -> value
                                                 Left x    r -> error (show x)
 
Synopsis

Documentation

data RNGError Source #

Error conditions detected in creation and use of Context data

Instances
Show RNGError Source # 
Instance details

Defined in Crypto.NewHope.Internal.SeedExpander

Preparing parameters

makeSeed :: Seedable a => a -> Seed Source #

Uses external entropy (precisely 32 bytes) to create a Seed.

class Seedable a Source #

Seeds may be constructed using Strings or ByteStrings as source data.

Minimal complete definition

makeSeed

Instances
Seedable String Source # 
Instance details

Defined in Crypto.NewHope.Internals

Methods

makeSeed :: String -> Seed Source #

Seedable ByteString Source # 
Instance details

Defined in Crypto.NewHope.Internals

Methods

makeSeed :: ByteString -> Seed Source #

maxLen :: MonadError RNGError m => Word64 -> m MaxLen Source #

Specifies the maximum number of bytes that a Context will generate.

createDiversifier :: MonadError RNGError m => ByteString -> m Diversifier Source #

Specifies eight bytes of data for use as part of the seed material to be expanded.

Expanding a seed

seedexpanderInit :: MonadError RNGError m => Seed -> Diversifier -> MaxLen -> m Context Source #

Create a Context for generation of data.

seedexpander :: MonadError RNGError m => Context -> Word64 -> m (ByteString, Context) Source #

Generate pseudorandom data from the given Context. The returned pair contains the requested data and the next Context to use.