// 
// Decompiled by Procyon v0.6.0
// 

package org.bouncycastle.crypto.digests;

import org.bouncycastle.util.Arrays;
import org.bouncycastle.crypto.engines.RomulusEngine;

public class RomulusDigest extends BufferBaseDigest
{
    private final byte[] h;
    private final byte[] g;
    
    public RomulusDigest() {
        super(ProcessingBufferType.Immediate, 32);
        this.h = new byte[16];
        this.g = new byte[16];
        this.DigestSize = 32;
        this.algorithmName = "Romulus Hash";
    }
    
    @Override
    protected void processBytes(final byte[] array, final int n) {
        RomulusEngine.hirose_128_128_256(Friend.INSTANCE, this.h, this.g, array, n);
    }
    
    @Override
    protected void finish(final byte[] array, final int n) {
        Arrays.fill(this.m_buf, this.m_bufPos, 31, (byte)0);
        this.m_buf[31] = (byte)(this.m_bufPos & 0x1F);
        final byte[] h = this.h;
        final int n2 = 0;
        h[n2] ^= 0x2;
        RomulusEngine.hirose_128_128_256(Friend.INSTANCE, this.h, this.g, this.m_buf, 0);
        System.arraycopy(this.h, 0, array, n, 16);
        System.arraycopy(this.g, 0, array, 16 + n, 16);
    }
    
    @Override
    public void reset() {
        super.reset();
        Arrays.clear(this.h);
        Arrays.clear(this.g);
    }
    
    public static class Friend
    {
        private static final Friend INSTANCE;
        
        private Friend() {
        }
        
        static {
            INSTANCE = new Friend();
        }
    }
}
