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

package org.bouncycastle.pqc.crypto.lms;

import org.bouncycastle.crypto.Digest;

class SeedDerive
{
    private final byte[] I;
    private final byte[] masterSeed;
    private final Digest digest;
    private int q;
    private int j;
    
    public SeedDerive(final byte[] i, final byte[] masterSeed, final Digest digest) {
        this.I = i;
        this.masterSeed = masterSeed;
        this.digest = digest;
    }
    
    public int getQ() {
        return this.q;
    }
    
    public void setQ(final int q) {
        this.q = q;
    }
    
    public int getJ() {
        return this.j;
    }
    
    public void setJ(final int j) {
        this.j = j;
    }
    
    public byte[] getI() {
        return this.I;
    }
    
    public byte[] getMasterSeed() {
        return this.masterSeed;
    }
    
    public byte[] deriveSeed(final byte[] array, final int n) {
        if (array.length - n < this.digest.getDigestSize()) {
            throw new IllegalArgumentException("target length is less than digest size.");
        }
        this.digest.update(this.I, 0, this.I.length);
        this.digest.update((byte)(this.q >>> 24));
        this.digest.update((byte)(this.q >>> 16));
        this.digest.update((byte)(this.q >>> 8));
        this.digest.update((byte)this.q);
        this.digest.update((byte)(this.j >>> 8));
        this.digest.update((byte)this.j);
        this.digest.update((byte)(-1));
        this.digest.update(this.masterSeed, 0, this.masterSeed.length);
        this.digest.doFinal(array, n);
        return array;
    }
    
    public void deriveSeed(final byte[] array, final boolean b) {
        this.deriveSeed(array, b, 0);
    }
    
    public void deriveSeed(final byte[] array, final boolean b, final int n) {
        this.deriveSeed(array, n);
        if (b) {
            ++this.j;
        }
    }
}
