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
).
The second diagram shows two stages, one in a Direction#FORWARD
direction, while the other is wired in a Direction#REVERSED
direction.
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 validgnu.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:
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.
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:
Returns the
Set
of supported block sizes for this Stage. Each element in the returnedSet
is an instance ofInteger
.
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 anjava.security.InvalidKeyException
if the key data (used to initialize the underlying Mode or Cascade) is invalid.
Returns the current block size for this stage. Throws an
IllegalStateException
if the instance is not yet initialized.
Resets the stage for re-initialization and use with other characteristics. This method always succeeds.
Processes exactly one block of plaintext (if wired in the
Direction#FORWARD
direction) or ciphertext (if wired in theDirection#REVERSED
direction), from in starting at inOffset, and storing the resulting bytes in out, starting at outOffset. AnIllegalStateException
will be thrown if the stage has not yet been initialized.
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, andfalse
otherwise.