net.ninthtest.crypto.helix
Class HelixEncryption

java.lang.Object
  extended by net.ninthtest.crypto.helix.HelixEncryption
All Implemented Interfaces:
HelixPrimitive

public class HelixEncryption
extends Object

A Helix primitive for a single encryption operation.

Version:
1.0
Author:
Matthew Zipay (mattz@ninthtest.info)

Constructor Summary
HelixEncryption(byte[] key, byte[] nonce)
          Creates a new HelixEncryption primitive using the specified key and nonce.
 
Method Summary
 int bufferSize()
          Returns the number of bytes that are currently buffered.
protected  void doBlock(int word)
          Applies a single Helix block to an input word.
 byte[] feed(byte[] part)
          Processes the next whole number of words (32-bit integers) from part.
 byte[] finish(byte[] part)
          Completes a Helix encryption/decryption operation.
 byte[] getGeneratedMac()
          Returns the MAC that was generated following a successful encryption/decryption operation.
protected  int nextStateWord()
          Returns the next state word for use in the main encryption/decryption loop.
protected  int[] transformWords(int[] plainTextWords, int mask)
          Performs the main encryption/decryption loop.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HelixEncryption

public HelixEncryption(byte[] key,
                       byte[] nonce)
Creates a new HelixEncryption primitive using the specified key and nonce.

Parameters:
key - the Helix key (cannot exceed 32 bytes in length)
nonce - the Helix nonce (must be exactly 16 bytes in length)
Method Detail

transformWords

protected int[] transformWords(int[] plainTextWords,
                               int mask)
Performs the main encryption/decryption loop.

Parameters:
plainTextWords - the next group of plaintext words to be encrypted
mask - (ignored)
Returns:
the encrypted words (ciphertext)

nextStateWord

protected final int nextStateWord()
Returns the next state word for use in the main encryption/decryption loop.

Returns:
the state word Z[0].

doBlock

protected final void doBlock(int word)
Applies a single Helix block to an input word.

Parameters:
word - a single word (32-bit integer) of plaintext or ciphertext

feed

public final byte[] feed(byte[] part)
Processes the next whole number of words (32-bit integers) from part.

Up to three bytes at the end of part may be buffered for the next call, in order to ensure that only a whole number of words are processed during this call.

Specified by:
feed in interface HelixPrimitive
Parameters:
part - the next sequence of bytes to be processed by this primitive
Returns:
an array of bytes representing plaintext or ciphertext, depending on the operation mode of this primitive

bufferSize

public final int bufferSize()
Returns the number of bytes that are currently buffered.

Specified by:
bufferSize in interface HelixPrimitive
Returns:
an integer in the range [0..3]

finish

public byte[] finish(byte[] part)
Completes a Helix encryption/decryption operation.

If this method completes successfully, the generated MAC can be retrieved using the HelixPrimitive.getGeneratedMac() method.

All remaining bytes (buffered + part) are processed. Up to three zero-bytes of padding are added to the remaining bytes to ensure that there is a whole number of words to process. Any padded bytes are masked off when the operation is completed.

If this method completes successfully, the generated MAC can be retrieved using the HelixPrimitive.getGeneratedMac() method.

Specified by:
finish in interface HelixPrimitive
Parameters:
part - the last input bytes to be fed
Returns:
the ciphertext (encryption) or plaintext (decryption) bytes

getGeneratedMac

public final byte[] getGeneratedMac()
Returns the MAC that was generated following a successful encryption/decryption operation.

Specified by:
getGeneratedMac in interface HelixPrimitive
Returns:
the generated MAC bytes
Throws:
IllegalStateException - if the encryption/decryption operation has not completed successfully


Copyright © 2010-2014 Matthew Zipay. All Rights Reserved.