Pseudorandom Permutation (PRP)

Pseudorandom permutations are bijective pseudorandom functions that are efficiently invertible. As such, they are of the pseudorandom function type and their input length always equals their output length. In addition (and unlike general pseudorandom functions), they are efficiently invertible.

The PseudorandomPermutation Interface

The PseudorandomPermutation interface extends the PseudorandomFunction interface, and adds the following functionality.

public void invertBlock(byte[] inBytes, int inOff, byte[] outBytes, int outOff)

Inverts the permutation using the given key.

This function is a part of the PseudorandomPermutation interface since any PseudorandomPermutation must be efficiently invertible (given the key). For block ciphers, for example, the length is known in advance and so there is no need to specify the length.

Parameters:
  • inBytes – input bytes to invert.
  • inOff – input offset in the inBytes array
  • outBytes – output bytes. The resulted bytes of invert
  • outOff – output offset in the outBytes array to put the result from
Throws:
  • IllegalBlockSizeException
public void invertBlock(byte[] inBytes, int inOff, byte[] outBytes, int outOff, int len)

Inverts the permutation using the given key.

Since PseudorandomPermutation can also have varying input and output length (although the input and the output should be the same length), the common parameter len of the input and the output is needed.

Parameters:
  • inBytes – input bytes to invert.
  • inOff – input offset in the inBytes array
  • outBytes – output bytes. The resulted bytes of invert
  • outOff – output offset in the outBytes array to put the result from
  • len – the length of the input and the output
Throws:
  • IllegalBlockSizeException

Basic Usage

//Create secretKey and in, out, inv byte arrays
...

//call the PrfFactory and cast to prp
PseudorandomPermutation prp = (PseudorandomPermutation) PrfFactory.getInstance().getObject("OpenSSL", "AES");

//set the key
prp.setKey(secretKey);

//run the permutation on a block-size prefix of in[]
prp.computeBlock(in, 0, out, 0);

//invert the permutation
prp.invertBlock(out, 0, inv, 0);

Pseudorandom Permutation with Varying Input-Output Lengths

A pseudorandom permutation with varying input/output lengths does not have pre-defined input/output lengths. The input and output length (that must be equal) may be different for each function call. The length of the input/output is determined upon user request.

We implement the Luby-Rackoff algorithm as an example of PRP with varying I/O lengths. The class that implements the algorithm is LubyRackoffPrpFromPrfVarying.

How to use the Varying Input-Output Length PRP

//Create secretKey and in, out byte arrays
...

//call the PrfFactory and cast to prp
PseudorandomPermutation prp = (PseudorandomPermutation) PrfFactory.getInstance().getObject("LubyRackoffPrpFromPrfVarying");

//set the key
prp.setKey(secretKey);

//invert the permutation with input in and output out of common size 20.
prp.invertBlock(in, 0, out, 0, 20);