001package edu.boisestate.lowry.crypto;
002
003/**
004 * Defines a cryptographic block cipher. A BlockCipher operates on a
005 * fixed-length block of data. BlockCipher is deterministic, that is
006 * given the same key and block, it will produce the same output.
007 *
008 * @author Jayce Lowry
009 */
010public interface BlockCipher {
011    /**
012     * Enciphers a fixed-length block of plaintext.
013     *
014     * @param plaintext A block of data with length equivalent to getBlockSize().
015     * @param key The secret key for enciphering.
016     * @return The resulting enciphered block.
017     * @throws IllegalArgumentException If the input length does not match the block size.
018     */
019    byte[] encipher(byte[] plaintext, byte[] key);
020
021    /**
022     * Deciphers a fixed-length block of ciphertext.
023     *
024     * @param ciphertext A block of encrypted data with length equivalent to getBlockSize().
025     * @param key The secret key for deciphering.
026     * @return The resulting deciphered block.
027     * @throws IllegalArgumentException If the input length does not match the block size.
028     */
029    byte[] decipher(byte[] ciphertext, byte[] key);
030
031    /**
032     * Returns the fixed block size this cipher operates on.
033     *
034     * @return The block size in bytes.
035     */
036    int getBlockSize();
037}