gnu.crypto.pad

Interface IPad

Known Implementing Classes:
BasePad, PKCS1_V1_5, PKCS7, SSL3, TBC, TLS1

public interface IPad

The basic visible methods of any padding algorithm.

Padding algorithms serve to pad and unpad byte arrays usually as the last step in an encryption or respectively a decryption operation. Their input buffers are usually those processed by instances of IMode and/or IBlockCipher.

Version:
$Revision: 1.4 $

Method Summary

void
init(int bs)
Initialises the padding scheme with a designated block size.
String
name()
byte[]
pad(byte[] in, int offset, int length)
Returns the byte sequence that should be appended to the designated input.
void
reset()
Resets the scheme instance for re-initialisation and use with other characteristics.
boolean
selfTest()
A basic symmetric pad/unpad test.
int
unpad(byte[] in, int offset, int length)
Returns the number of bytes to discard from a designated input buffer.

Method Details

init

public void init(int bs)
            throws IllegalStateException
Initialises the padding scheme with a designated block size.
Parameters:
bs - the designated block size.

name

public String name()
Returns:
the canonical name of this instance.

pad

public byte[] pad(byte[] in,
                  int offset,
                  int length)
Returns the byte sequence that should be appended to the designated input.
Parameters:
in - the input buffer containing the bytes to pad.
offset - the starting index of meaningful data in in.
length - the number of meaningful bytes in in.
Returns:
the possibly 0-byte long sequence to be appended to the designated input.

reset

public void reset()
Resets the scheme instance for re-initialisation and use with other characteristics. This method always succeeds.

selfTest

public boolean selfTest()
A basic symmetric pad/unpad test.
Returns:
true if the implementation passes a basic symmetric self-test. Returns false otherwise.

unpad

public int unpad(byte[] in,
                 int offset,
                 int length)
            throws WrongPaddingException
Returns the number of bytes to discard from a designated input buffer.
Parameters:
in - the input buffer containing the bytes to unpad.
offset - the starting index of meaningful data in in.
length - the number of meaningful bytes in in.
Returns:
the number of bytes to discard, to the left of index position offset + length in in. In other words, if the return value of a successful invocation of this method is result, then the unpadded byte sequence will be offset + length - result bytes in in, starting from index position offset.
Throws:
WrongPaddingException - if the data is not terminated with the expected padding bytes.

Copyright © 2001, 2002, 2003 Free Software Foundation, Inc. All Rights Reserved.