@Immutable
public interface StreamingPrf
Pseudorandom functions provide a mapping from an input to an output string which is indistinguishable from a pure random function.
In Tink, the pseudorandom interface produces a stream of pseudorandom bytes, from which the
user can read. The resulting stream may be of (virtually) infinite length, producing bytes as
long as the user reads from it, or it may produce a finite length stream of a certain length.
More formally, ignoring timing, every implementation is indistinguishable in the input/output
behavior from the following ideal implementation, for some length LENGTH.
public class IdealPRF {
private Map<byte[], byte[]> cache = new ArrayMap<>();
private static final int LENGTH = ...; // Any value; conceptually, Infinite would also be ok.
public InputStream apply(final byte[] input) {
if (!cache.containsKey(input)) {
cache.put(input, Random.getBytes(LENGTH)));
}
return new ByteArrayInputStream(cache.get(input));
}
}
| Modifier and Type | Method and Description |
|---|---|
InputStream |
computePrf(byte[] input)
Returns an
InputStream which is indistinguishable from a stream returning random bytes
in the above sense. |
InputStream computePrf(byte[] input)
InputStream which is indistinguishable from a stream returning random bytes
in the above sense.