Xof

sealed class Xof<A : XofAlgorithm>(val delegate: A) : Algorithm, Copyable<Xof<A>> , Resettable, Updatable(source)

Extendable-Output Function (i.e. XOF)

FIPS PUB 202 introduced XOFs where output for certain cryptographic functions can be variable in length. This is an implementation which provides such functionality.

e.g.

val xof = SHAKE128.xOf()
xof.update(Random.Default.nextBytes(500))

val out1 = ByteArray(64)
val out2 = ByteArray(out1.size * 2)
xof.use(resetXof = false) { read(out1); read(out2) }

val out3 = ByteArray(out1.size)
val out4 = ByteArray(out2.size)
val reader = xof.reader()
reader.read(out3)
reader.use { read(out4, 0, out4.size) }

assertContentEquals(out1, out3)
assertContentEquals(out2, out4)

https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.202.pdf

See also

Inheritors

Constructors

Link copied to clipboard
protected constructor(delegate: A)

Types

Link copied to clipboard
object Companion
Link copied to clipboard
abstract inner class Reader

Reads the Xof snapshot.

Properties

Link copied to clipboard
@JvmField
protected val delegate: A

Functions

Link copied to clipboard
protected abstract fun newReader(): Xof.Reader<A>
Link copied to clipboard
@JvmOverloads
fun reader(resetXof: Boolean = true): Xof.Reader<A>

Takes a snapshot of the current Xof's state and produces a Reader.

Link copied to clipboard
@JvmStatic
fun <A : ReKeyableXofAlgorithm> Xof<A>.reset(newKey: ByteArray)

Helper to provide access to the instance backing Xof, if said instance can be re-keyed (such as a org.kotlincrypto.core.mac.Mac).

Link copied to clipboard
@JvmOverloads
inline fun <T> use(resetXof: Boolean = true, action: Xof.Reader<A>.() -> T): T

Takes a snapshot of the current Xof's state and produces a Reader.