xof.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package kyber
  2. import (
  3. "crypto/cipher"
  4. "io"
  5. )
  6. // An XOF is an extendable output function, which is a cryptographic
  7. // primitive that can take arbitrary input in the same way a hash
  8. // function does, and then create a stream of output, up to a limit
  9. // determined by the size of the internal state of the hash function
  10. // the underlies the XOF.
  11. //
  12. // When XORKeyStream is called with zeros for the source, an XOF
  13. // also acts as a PRNG. If it is seeded with an appropriate amount
  14. // of keying material, it is a cryptographically secure source of random
  15. // bits.
  16. type XOF interface {
  17. // Write absorbs more data into the hash's state. It panics if called
  18. // after Read. Use Reseed() to reset the XOF into a state where more data
  19. // can be absorbed via Write.
  20. io.Writer
  21. // Read reads more output from the hash. It returns io.EOF if the
  22. // limit of available data for reading has been reached.
  23. io.Reader
  24. // An XOF implements cipher.Stream, so that callers can use XORKeyStream
  25. // to encrypt/decrypt data. The key stream is read from the XOF using
  26. // the io.Reader interface. If Read returns an error, then XORKeyStream
  27. // will panic.
  28. cipher.Stream
  29. // Reseed makes an XOF writeable again after it has been read from
  30. // by sampling a key from it's output and initializing a fresh XOF implementation
  31. // with that key.
  32. Reseed()
  33. // Clone returns a copy of the XOF in its current state.
  34. Clone() XOF
  35. }
  36. // An XOFFactory is an interface that can be mixed in to local suite definitions.
  37. type XOFFactory interface {
  38. // XOF creates a new XOF, feeding seed to it via it's Write method. If seed
  39. // is nil or []byte{}, the XOF is left unseeded, it will produce a fixed, predictable
  40. // stream of bits (Caution: this behavior is useful for testing but fatal for
  41. // production use).
  42. XOF(seed []byte) XOF
  43. }