cryptix.provider.elgamal

Class RawElGamalCipher

Implemented Interfaces:
AsymmetricCipher, Cloneable, Parameterized

public class RawElGamalCipher
extends Cipher
implements AsymmetricCipher, Cloneable

The raw ElGamal encryption algorithm.

References:

  1. Bruce Schneier, "Section 19.6 ElGamal," Applied Cryptography, 2nd edition, John Wiley & Sons, 1996.

Copyright © 1997 Systemics Ltd on behalf of the Cryptix Development Team.
All rights reserved.

$Revision: 1.3 $

Author:
David Hopwood

Since:
Cryptix 2.2.2

Field Summary

Fields inherited from class xjava.security.Cipher

DECRYPT, ENCRYPT, UNINITIALIZED

Fields inherited from class xjava.security.IJCE_Traceable

tracing

Constructor Summary

RawElGamalCipher()
Constructor for a RawElGamalCipher.

Method Summary

protected int
engineCiphertextBlockSize()
SPI: Return the ciphertext block size, in bytes.
protected Object
engineGetParameter(String param)
SPI: Return an algorithm-specific parameter.
protected void
engineInitDecrypt(Key key)
SPI: Initializes the cipher for decryption, using the given private key.
protected void
engineInitEncrypt(Key key)
SPI: Initializes the cipher for encryption, using the given public key.
protected int
enginePlaintextBlockSize()
SPI: Return the plaintext block size, in bytes.
protected void
engineSetParameter(String param, Object value)
SPI: Set an algorithm-specific parameter.
protected int
engineUpdate(byte[] in, int inOffset, int inLen, byte[] out, int outOffset)
SPI: DOCUMENT ME
static void
main(String[] args)
Entry point for very basic self_test.
static void
self_test(PrintWriter out)

Methods inherited from class xjava.security.Cipher

blockSize, clone, crypt, crypt, crypt, doFinal, doFinal, doFinal, doFinal, engineBlockSize, engineCiphertextBlockSize, engineCrypt, engineGetParameter, engineInBufferSize, engineInitDecrypt, engineInitEncrypt, engineOutBufferSize, enginePlaintextBlockSize, engineSetPaddingScheme, engineSetParameter, engineUpdate, getAlgorithm, getAlgorithms, getAlgorithms, getCiphertextBlockSize, getInputBlockSize, getInstance, getInstance, getInstance, getMode, getOutputBlockSize, getPadding, getPaddingScheme, getParameter, getPlaintextBlockSize, getProvider, getState, inBufferSize, inBufferSizeFinal, initDecrypt, initEncrypt, isPaddingBlockCipher, outBufferSize, outBufferSizeFinal, setParameter, toString, update, update, update, update

Methods inherited from class xjava.security.IJCE_Traceable

disableTracing, enableTracing, traceMethod, traceResult, traceResult, traceVoidMethod

Constructor Details

RawElGamalCipher

public RawElGamalCipher()
Constructor for a RawElGamalCipher.

Method Details

engineCiphertextBlockSize

protected int engineCiphertextBlockSize()
Overrides:
engineCiphertextBlockSize in interface Cipher

Returns:
the ciphertext block size


engineGetParameter

protected Object engineGetParameter(String param)
SPI: Return an algorithm-specific parameter.

ElGamal has one algorithm-specific parameter called "random", as described above. It is guaranteed to be a subclass of java.util.Random. Calling this method with a param string other than "random" will return null.

Overrides:
engineGetParameter in interface Cipher

Parameters:
param - the string name of the parameter.

Returns:
the object that represents the parameter value, or null if there is none.


engineInitDecrypt

protected void engineInitDecrypt(Key key)
            throws KeyException
SPI: Initializes the cipher for decryption, using the given private key. The key object must implement java.security.interfaces.ElGamalPrivateKey.
Overrides:
engineInitDecrypt in interface Cipher

Parameters:
key - the private key


engineInitEncrypt

protected void engineInitEncrypt(Key key)
            throws KeyException
SPI: Initializes the cipher for encryption, using the given public key. The key object must implement java.security.interfaces.ElGamalPublicKey.
Overrides:
engineInitEncrypt in interface Cipher

Parameters:
key - the public key


enginePlaintextBlockSize

protected int enginePlaintextBlockSize()
Overrides:
enginePlaintextBlockSize in interface Cipher

Returns:
the plaintext block size


engineSetParameter

protected void engineSetParameter(String param,
                                  Object value)
SPI: Set an algorithm-specific parameter.

ElGamal has one algorithm-specific parameter called "random", of type java.util.Random, which specifies the source of random bits used to generate the k values needed for encryption. If this parameter is not set when initKey is called, the result of new SecureRandom() will be used.

You can set the "random" parameter using the following code:

   try {
       elgamal.setParameter("random", existingSecureRandom);
   } catch (InvalidParameterException e) { /* ignore */ }
   elgamal.initEncrypt(publicKey);
 

This is not useful if the cipher will only be used for decryption.

Overrides:
engineSetParameter in interface Cipher

Parameters:
param - the string identifier of the parameter.
value - the parameter value.


engineUpdate

protected int engineUpdate(byte[] in,
                           int inOffset,
                           int inLen,
                           byte[] out,
                           int outOffset)
SPI: DOCUMENT ME
Overrides:
engineUpdate in interface Cipher


main

public static final void main(String[] args)
Entry point for very basic self_test.


self_test

public static void self_test(PrintWriter out)
            throws KeyException