org.bouncycastle.crypto.engines
Class ElGamalEngine

java.lang.Object
  extended by org.bouncycastle.crypto.engines.ElGamalEngine
All Implemented Interfaces:
AsymmetricBlockCipher

public class ElGamalEngine
extends java.lang.Object
implements AsymmetricBlockCipher

this does your basic ElGamal algorithm.


Field Summary
private  int bitSize
           
private  boolean forEncryption
           
private  ElGamalKeyParameters key
           
private static java.math.BigInteger ONE
           
private  java.security.SecureRandom random
           
private static java.math.BigInteger TWO
           
private static java.math.BigInteger ZERO
           
 
Constructor Summary
ElGamalEngine()
           
 
Method Summary
 int getInputBlockSize()
          Return the maximum size for an input block to this engine.
 int getOutputBlockSize()
          Return the maximum size for an output block to this engine.
 void init(boolean forEncryption, CipherParameters param)
          initialise the ElGamal engine.
 byte[] processBlock(byte[] in, int inOff, int inLen)
          Process a single block using the basic ElGamal algorithm.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

key

private ElGamalKeyParameters key

random

private java.security.SecureRandom random

forEncryption

private boolean forEncryption

bitSize

private int bitSize

ZERO

private static final java.math.BigInteger ZERO

ONE

private static final java.math.BigInteger ONE

TWO

private static final java.math.BigInteger TWO
Constructor Detail

ElGamalEngine

public ElGamalEngine()
Method Detail

init

public void init(boolean forEncryption,
                 CipherParameters param)
initialise the ElGamal engine.

Specified by:
init in interface AsymmetricBlockCipher
Parameters:
forEncryption - true if we are encrypting, false otherwise.
param - the necessary ElGamal key parameters.

getInputBlockSize

public int getInputBlockSize()
Return the maximum size for an input block to this engine. For ElGamal this is always one byte less than the size of P on encryption, and twice the length as the size of P on decryption.

Specified by:
getInputBlockSize in interface AsymmetricBlockCipher
Returns:
maximum size for an input block.

getOutputBlockSize

public int getOutputBlockSize()
Return the maximum size for an output block to this engine. For ElGamal this is always one byte less than the size of P on decryption, and twice the length as the size of P on encryption.

Specified by:
getOutputBlockSize in interface AsymmetricBlockCipher
Returns:
maximum size for an output block.

processBlock

public byte[] processBlock(byte[] in,
                           int inOff,
                           int inLen)
Process a single block using the basic ElGamal algorithm.

Specified by:
processBlock in interface AsymmetricBlockCipher
Parameters:
in - the input array.
inOff - the offset into the input buffer where the data starts.
inLen - the length of the data to be processed.
Returns:
the result of the ElGamal process.
Throws:
DataLengthException - the input block is too large.