package com.m4gik;

import static com.m4gik.HavalAttributes.HAVAL_128_BIT;
import static com.m4gik.HavalAttributes.HAVAL_160_BIT;
import static com.m4gik.HavalAttributes.HAVAL_192_BIT;
import static com.m4gik.HavalAttributes.HAVAL_224_BIT;
import static com.m4gik.HavalAttributes.HAVAL_256_BIT;
import static com.m4gik.HavalAttributes.HAVAL_3_ROUND;
import static com.m4gik.HavalAttributes.HAVAL_HASH;

/**
 * The Haval (One-Way Hashing Algorithm) message-digest algorithm is a variable
 * output length, with variable number of rounds. By default, this
 * implementation allows Haval to be used as a drop-in replacement for md5.
 * 
 * @author Michał Szczygieł <michal.szczygiel@wp.pl>
 * 
 */
public class Haval extends BaseHash {

    /**
     * Inner block size in bytes.
     */
    private static final int BLOCK_SIZE = 128;

    /**
     * 
     */
    private int rounds = HAVAL_3_ROUND;

    /**
     * Calls the constructor with two argument using {@link
     * HavalAttributes.#HAVAL_128_BIT} as the value for the output size (i.e.
     * <code>128</code> bits, and {@link HavalAttributes.#HAVAL_3_ROUND} for the
     * value of number of rounds.
     */
    public Haval() {
        this(HAVAL_128_BIT, HAVAL_3_ROUND);
    }

    /**
     * Constructs a <code>Haval</code> instance with the designated output size
     * (in bytes). Valid output <code>size</code> values are <code>16</code>,
     * <code>20</code>, <code>24</code>, <code>28</code> and <code>32</code>.
     * Valid values for <code>rounds</code> are in the range <code>3..5</code>
     * inclusive.
     * 
     * @param size
     *            the output size in bytes of this instance.
     * @param rounds
     *            the number of rounds to apply when transforming data.
     * @throws IllegalArgumentException
     *             if the designated output size is invalid, or if the number of
     *             rounds is invalid.
     * @see HavalAttributes.#HAVAL_128_BIT
     * @see HavalAttributes.#HAVAL_160_BIT
     * @see HavalAttributes.#HAVAL_192_BIT
     * @see HavalAttributes.#HAVAL_224_BIT
     * @see HavalAttributes.#HAVAL_256_BIT
     * @see HavalAttributes.#HAVAL_3_ROUND
     * @see HavalAttributes.#HAVAL_4_ROUND
     * @see HavalAttributes.#HAVAL_5_ROUND
     */
    public Haval(int size, int rounds) {
        super(HAVAL_HASH, size, BLOCK_SIZE);
        checkHavalOutputSize(size);

        this.rounds = rounds;
    }

    protected Haval(String name, int hashSize, int blockSize) {
        super(name, hashSize, blockSize);
        // TODO Auto-generated constructor stub
    }

    /**
     * This method checks proper output size for Haval algorithm.
     * 
     * @param size
     *            The size to check.
     * @throws IllegalArgumentException
     */
    private void checkHavalOutputSize(int size) throws IllegalArgumentException {
        if (size != HAVAL_128_BIT && size != HAVAL_160_BIT
                && size != HAVAL_192_BIT && size != HAVAL_224_BIT
                && size != HAVAL_256_BIT) {
            throw new IllegalArgumentException("Invalid HAVAL output size");
        }
    }

    @Override
    public Object clone() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    protected byte[] getResult() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    protected byte[] padBuffer() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    protected void resetContext() {
        // TODO Auto-generated method stub

    }

    @Override
    protected void transform(byte[] in, int offset) {
        // TODO Auto-generated method stub

    }

}

@@ -343,16 +343,126 @@
 _ROUND;%0A
+import static com.m4gik.HavalAttributes.HAVAL_4_ROUND;%0Aimport static com.m4gik.HavalAttributes.HAVAL_5_ROUND;%0A
 import s
@@ -2496,16 +2496,49 @@
 (size);%0A
+        checkHavalRounds(rounds);
 %0A       
@@ -3251,32 +3251,506 @@
        %7D%0A    %7D%0A%0A
+    /**%0A     * This method checks proper amount of rounds.%0A     * %0A     * @param rounds%0A     *            The amount of rounds to check.%0A     * @throws IllegalArgumentException%0A     */%0A    private void checkHavalRounds(int rounds) throws IllegalArgumentException %7B%0A        if (rounds != HAVAL_3_ROUND && rounds != HAVAL_4_ROUND%0A                && rounds != HAVAL_5_ROUND) %7B%0A            throw new IllegalArgumentException(%22Invalid HAVAL number of rounds%22);%0A        %7D%0A%0A    %7D%0A%0A
     @Override%0A  

Implement method for check amount of rounds.