Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

cryptix.jce.provider.cipher
Class ModeOpenpgpCFB  view ModeOpenpgpCFB download ModeOpenpgpCFB.java

java.lang.Object
  extended bycryptix.jce.provider.cipher.Mode
      extended bycryptix.jce.provider.cipher.ModeCFB
          extended bycryptix.jce.provider.cipher.ModeOpenpgpCFB

class ModeOpenpgpCFB
extends ModeCFB

This mode implements the special CFB mode used by the OpenPGP standard (RFC 2440)

Due to the design of the JCE, it is not completely the OpenPGP CFB mode though. OpenPGP specifies that blocksize+2 bytes need to be prefixed to the encrypted data, consisting of blocksize bytes of random data and then repeating the last two bytes of this random data to make it possible to check whether we're decrypting with the right key.

Now the question is, where should this data be added and thus also where should this check be done. Inside this mode object would be the obvious choice, such that applications need not to bother themselves with this quirk. However there's no way to throw an Exception if the check fails. The only possibility is a RuntimeException and that's not really how it should work.

So the application needs to do the check, which means the application has to pass in this random data on encryption and it needs to retrieve it back on decryption. For passing it in on encryption, JCE has so called AlgorithmParameterSpec objects which would be perfect for this job. However, there is no way for the application to retrieve it again at decryption time and therefore no way to check it.

So the only way to do this is if the application handles the prefix. This mode then only takes care of the resynchronization at blocksize+2 bytes. It's not ideal and not how is should work, but it's the only thing possible within the JCE.

Version:
$Revision: 1.2 $

Field Summary
protected  int bufCount
          How many bytes the buffer holds
protected  long byteCount
          How many bytes we have processed.
protected  BlockCipher cipher
          Underlying block cipher
protected  int CIPHER_BLOCK_SIZE
          Block size of underlying cipher
private  long extraCrankCount
          Holds byteCount where the OpenPGP CFB extra crank is required.
 
Constructor Summary
(package private) ModeOpenpgpCFB(BlockCipher cipher)
           
 
Method Summary
(package private)  byte[] coreGetIV()
           
(package private)  int coreGetOutputSize(int inputLen)
           
(package private)  java.security.spec.AlgorithmParameterSpec coreGetParamSpec()
           
(package private)  void coreInit(boolean decrypt, java.security.Key key, java.security.spec.AlgorithmParameterSpec params, java.security.SecureRandom random)
           
(package private)  int coreUpdate(byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset)
           
protected  byte[] extractIV(java.security.spec.AlgorithmParameterSpec params)
           
protected  byte[] generateIV()
           
(package private)  int getBlockSize()
           
(package private)  int getBufSize()
           
(package private) static Mode getInstance(java.lang.String mode, BlockCipher cipher)
           
(package private)  byte[] getIV()
           
(package private)  int getOutputSize(int inputLen)
           
(package private)  java.security.spec.AlgorithmParameterSpec getParamSpec()
           
(package private)  void init(boolean decrypt, java.security.Key key, java.security.spec.AlgorithmParameterSpec params, java.security.SecureRandom random)
           
protected  boolean needCrank()
          Sync policy, can be overridden in subclasses.
(package private)  boolean needsPadding()
           
(package private)  int update(byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

extraCrankCount

private final long extraCrankCount
Holds byteCount where the OpenPGP CFB extra crank is required. OpenPGP CFB mode specifies that an extra shift register encryption (crank) occurs at CIPHER_BLOCK_SIZE+2 bytes.


byteCount

protected long byteCount
How many bytes we have processed. Used to determine when to 'sync'.


cipher

protected final BlockCipher cipher
Underlying block cipher


CIPHER_BLOCK_SIZE

protected final int CIPHER_BLOCK_SIZE
Block size of underlying cipher


bufCount

protected int bufCount
How many bytes the buffer holds

Constructor Detail

ModeOpenpgpCFB

ModeOpenpgpCFB(BlockCipher cipher)
Method Detail

needCrank

protected boolean needCrank()
Description copied from class: ModeCFB
Sync policy, can be overridden in subclasses.

Overrides:
needCrank in class ModeCFB

coreGetOutputSize

final int coreGetOutputSize(int inputLen)
Specified by:
coreGetOutputSize in class Mode

coreInit

void coreInit(boolean decrypt,
              java.security.Key key,
              java.security.spec.AlgorithmParameterSpec params,
              java.security.SecureRandom random)
        throws java.security.InvalidKeyException,
               java.security.InvalidAlgorithmParameterException
Specified by:
coreInit in class Mode

coreUpdate

int coreUpdate(byte[] input,
               int inputOffset,
               int inputLen,
               byte[] output,
               int outputOffset)
Specified by:
coreUpdate in class Mode

coreGetIV

final byte[] coreGetIV()
Specified by:
coreGetIV in class Mode

coreGetParamSpec

final java.security.spec.AlgorithmParameterSpec coreGetParamSpec()
Specified by:
coreGetParamSpec in class Mode

needsPadding

final boolean needsPadding()
Specified by:
needsPadding in class Mode

getInstance

static Mode getInstance(java.lang.String mode,
                        BlockCipher cipher)
                 throws java.security.NoSuchAlgorithmException

init

void init(boolean decrypt,
          java.security.Key key,
          java.security.spec.AlgorithmParameterSpec params,
          java.security.SecureRandom random)
    throws java.security.InvalidKeyException,
           java.security.InvalidAlgorithmParameterException

getIV

final byte[] getIV()

getParamSpec

final java.security.spec.AlgorithmParameterSpec getParamSpec()

getOutputSize

final int getOutputSize(int inputLen)

getBlockSize

final int getBlockSize()

update

final int update(byte[] input,
                 int inputOffset,
                 int inputLen,
                 byte[] output,
                 int outputOffset)

getBufSize

final int getBufSize()

generateIV

protected byte[] generateIV()

extractIV

protected final byte[] extractIV(java.security.spec.AlgorithmParameterSpec params)
                          throws java.security.InvalidAlgorithmParameterException