org.logi.crypto.modes
Class EncryptOFB

java.lang.Object
  |
  +--org.logi.crypto.Crypto
        |
        +--org.logi.crypto.modes.EncryptMode
              |
              +--org.logi.crypto.modes.EncryptOFB
All Implemented Interfaces:
EncryptSession

public class EncryptOFB
extends org.logi.crypto.modes.EncryptMode

Output Fedback Mode iterates the encryption routine on the IV and xors the resulting stream with the plaintext to produce the ciphertext.

This requires as many encryptions as ECB or CBC mode, but can encrypt plaintext one byte at a time. A stream is calculated in a separate thread and xored with the plaintext. This gives fast response, since the final encryption is merely an xor operation.

However, since (with plaintext P, ciphertext C and xor-stream S)

P = C ^ S,

the opponent can alter the plaintext received by changing

C' = C ^ A,

so that

P' = C' ^ S = C ^ A ^ S = P ^ A

is seen. But the opponent will not be able to learn P or control what P' is.

An example of how the attacker can use this is to flip the most significant bit of the amount of money being deposited onto his bank account. OFB mode should be used with some sort of hashing or signing mechanism.

Version:
1.1.1
Author:
Logi Ragnarsson (logir@logi.org)
See Also:
DecryptOFB

Fields inherited from class org.logi.crypto.Crypto
BIT, cdsPath, EMPTY_ARRAY, FOUR, keySource, NIBBLE, ONE, primeCertainty, random, TWO, ZERO
 
Constructor Summary
EncryptOFB(EncryptionKey key, int bufSize)
          Create a new OFB-mode encrypt session with the specified key.
EncryptOFB(int bufSize)
          Create a new OFB-mode encrypt session with no key.
 
Method Summary
 void close()
          Close files and kill threads owned by the object.
 byte[] encrypt(byte[] source, int i, int length)
          Send bytes to the EncryptOFB object for encryption.
 void finalize()
           
 byte[] flush()
          Pads the internal buffer, encrypts it and returns the ciphertext.
 byte[] flush(byte[] source, int i, int length)
          Equivalent to calling encrypt(source,i,length) followed by flush().
 EncryptionKey getKey()
          Return the key used for encryption.
 int plainBlockSize()
          Return the size of the blocks of plaintext encrypted by this object.
 void setKey(EncryptionKey key)
          Set the key to use for encryption.
 
Methods inherited from class org.logi.crypto.Crypto
binString, binString, ensureArrayLength, ensureArrayLength, equal, equalRelaxed, equalSub, fromHexNibble, fromHexString, fromString, fromString, hexString, hexString, hexString, hexString, hexString, initRandom, initRandom, makeClass, makeInt, makeLong, makeSessionKey, pastSpace, pickBits, pickBits, prettyPrint, prettyPrint, readBlock, readInt, trimArrayLength, trimArrayLength, trimLeadingZeroes, writeBytes, writeBytes, writeInt
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EncryptOFB

public EncryptOFB(EncryptionKey key,
                  int bufSize)
           throws KeyException
Create a new OFB-mode encrypt session with the specified key. A buffer of bufSize bytes is created to hold a pre-calculated xor-stream.

EncryptOFB

public EncryptOFB(int bufSize)
Create a new OFB-mode encrypt session with no key. No encryption can be performed until the setKey() method has been called.

A buffer of bufSize bytes is created to hold a pre-calculated xor-stream.

Method Detail

getKey

public EncryptionKey getKey()
Return the key used for encryption.

setKey

public void setKey(EncryptionKey key)
Set the key to use for encryption. The key can only be set once in this version of the library. The 1.1.x and eventually 1.2.x series allows dynamic re-keying.
Following copied from interface: org.logi.crypto.modes.EncryptSession
Throws:
CryptoException - if there is data in the internal buffer which should be encrypted with the old key.

plainBlockSize

public int plainBlockSize()
Return the size of the blocks of plaintext encrypted by this object.

flush

public byte[] flush()
Pads the internal buffer, encrypts it and returns the ciphertext. Since OFB mode doesn't use an internal buffer, an empty array is returned.

encrypt

public byte[] encrypt(byte[] source,
                      int i,
                      int length)
Send bytes to the EncryptOFB object for encryption.

Encrypt length bytes from source, starting at i and return the ciphertext.


close

public void close()
Close files and kill threads owned by the object. This should be called to make sure all resources are freed.
Overrides:
close in class org.logi.crypto.modes.EncryptMode

flush

public byte[] flush(byte[] source,
                    int i,
                    int length)
             throws PaddingException
Equivalent to calling encrypt(source,i,length) followed by flush().
Specified by:
flush in interface EncryptSession

finalize

public void finalize()


Copyright (c) 1997-2001 Logi Ragnarsson - Distributed under the GPL