Node:Stage, Next:, Previous:Direction, Up:Cascades



Stage

This class represents a Stage in a Cascade cipher.

Each stage may be either an implementation of a Block Cipher Mode of Operation (an instance of gnu.crypto.mode.IMode) or another Cascade cipher (an instance of Cascade). Each Stage has also a natural operational direction when constructed for inclusion within a Cascade. This natural direction dictates how data flows from one Stage into another when stages are chained together in a Cascade. One can think of a Stage and its natural direction as the specification of how to wire the Stage into the chain.

The following diagrams may help understand the paradigm. The first shows two stages chained together, each wired in the same direction (Direction#FORWARD). diagrams/stages_same_dir.png

Figure 5: Stages wired in same direction
The second diagram shows two stages, one in a Direction#FORWARD direction, while the other is wired in a Direction#REVERSED direction. diagrams/stages_diff_dir.png
Figure 6: Stages wired in different directions

gnu.crypto.assembly.Stage DIRECTION Variable
A property name in the attributes map that is passed to the init method, representing the stage's desired wiring direction. The mapped value should be a valid gnu.crypto.assembly.Direction value. If this attribute is omitted, Direction.FORWARD is used.

The following Factory methods, allow instantiation of concrete Stage class instances that adapt instances of either gnu.crypto.mode.IMode or (other) Cascade classes to operate as a Stage in a Cascade:

Stage getInstance (IMode mode, Direction forwardDirection) Function
Given a designated mode (an instance of gnu.crypto.mode.IMode, and a Direction, this method returns a Stage instance that adapts this designated mode to operate as a Stage in a Cascade.

Stage getInstance (Cascade cascade, Direction forwardDirection) Function
Given a designated cascade (an instance of gnu.crypto.assembly.Cascade, and a Direction, this method returns a Stage instance that adapts this designated cascade to operate as a Stage in another Cascade.

The following instance methods are also available:

java.util.Set blockSizes () Function
Returns the Set of supported block sizes for this Stage. Each element in the returned Set is an instance of Integer.

void init (java.util.Map attributes) throws java.security.InvalidKeyException Function
Initializes the stage for operation with specific characteristics. Those characteristics are defined in attributes: a set of name-value pairs that describes the desired future behavior of this instance. This method throws an IllegalStateException if the instance is already initialized. It throws an java.security.InvalidKeyException if the key data (used to initialize the underlying Mode or Cascade) is invalid.

int currentBlockSize () throws IllegalStateException Function
Returns the current block size for this stage. Throws an IllegalStateException if the instance is not yet initialized.

void reset () Function
Resets the stage for re-initialization and use with other characteristics. This method always succeeds.

void update (byte[] in, int inOffset, byte[] out, int outOffset) Function
Processes exactly one block of plaintext (if wired in the Direction#FORWARD direction) or ciphertext (if wired in the Direction#REVERSED direction), from in starting at inOffset, and storing the resulting bytes in out, starting at outOffset. An IllegalStateException will be thrown if the stage has not yet been initialized.

boolean selfTest () Function
Conducts a simple correctness test that consists of basic symmetric encryption / decryption test(s) for all supported block and key sizes of underlying block cipher(s) wrapped by Mode leafs. The test also includes one (1) variable key Known Answer Test (KAT) for each block cipher. It returns true if the tests succeed, and false otherwise.