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

package org.bouncycastle.pqc.crypto.crystals.dilithium;

class PolyVecK
{
    Poly[] vec;
    private DilithiumEngine engine;
    private int mode;
    private int polyVecBytes;
    private int dilithiumK;
    private int dilithiumL;
    
    public PolyVecK(final DilithiumEngine engine) {
        this.engine = engine;
        this.mode = engine.getDilithiumMode();
        this.dilithiumK = engine.getDilithiumK();
        this.dilithiumL = engine.getDilithiumL();
        this.vec = new Poly[this.dilithiumK];
        for (int i = 0; i < this.dilithiumK; ++i) {
            this.vec[i] = new Poly(engine);
        }
    }
    
    public PolyVecK() throws Exception {
        throw new Exception("Requires Parameter");
    }
    
    public Poly getVectorIndex(final int n) {
        return this.vec[n];
    }
    
    public void setVectorIndex(final int n, final Poly poly) {
        this.vec[n] = poly;
    }
    
    public void uniformEta(final byte[] array, final short n) {
        short n2 = n;
        for (int i = 0; i < this.dilithiumK; ++i) {
            final Poly vectorIndex = this.getVectorIndex(i);
            final short n3 = n2;
            ++n2;
            vectorIndex.uniformEta(array, n3);
        }
    }
    
    public void reduce() {
        for (int i = 0; i < this.dilithiumK; ++i) {
            this.getVectorIndex(i).reduce();
        }
    }
    
    public void invNttToMont() {
        for (int i = 0; i < this.dilithiumK; ++i) {
            this.getVectorIndex(i).invNttToMont();
        }
    }
    
    public void addPolyVecK(final PolyVecK polyVecK) {
        for (int i = 0; i < this.dilithiumK; ++i) {
            this.getVectorIndex(i).addPoly(polyVecK.getVectorIndex(i));
        }
    }
    
    public void conditionalAddQ() {
        for (int i = 0; i < this.dilithiumK; ++i) {
            this.getVectorIndex(i).conditionalAddQ();
        }
    }
    
    public void power2Round(final PolyVecK polyVecK) {
        for (int i = 0; i < this.dilithiumK; ++i) {
            this.getVectorIndex(i).power2Round(polyVecK.getVectorIndex(i));
        }
    }
    
    public void polyVecNtt() {
        for (int i = 0; i < this.dilithiumK; ++i) {
            this.vec[i].polyNtt();
        }
    }
    
    public void decompose(final PolyVecK polyVecK) {
        for (int i = 0; i < this.dilithiumK; ++i) {
            this.getVectorIndex(i).decompose(polyVecK.getVectorIndex(i));
        }
    }
    
    public byte[] packW1() {
        final byte[] array = new byte[this.dilithiumK * this.engine.getDilithiumPolyW1PackedBytes()];
        for (int i = 0; i < this.dilithiumK; ++i) {
            System.arraycopy(this.getVectorIndex(i).w1Pack(), 0, array, i * this.engine.getDilithiumPolyW1PackedBytes(), this.engine.getDilithiumPolyW1PackedBytes());
        }
        return array;
    }
    
    public void pointwisePolyMontgomery(final Poly poly, final PolyVecK polyVecK) {
        for (int i = 0; i < this.dilithiumK; ++i) {
            this.getVectorIndex(i).pointwiseMontgomery(poly, polyVecK.getVectorIndex(i));
        }
    }
    
    public void subtract(final PolyVecK polyVecK) {
        for (int i = 0; i < this.dilithiumK; ++i) {
            this.getVectorIndex(i).subtract(polyVecK.getVectorIndex(i));
        }
    }
    
    public boolean checkNorm(final int n) {
        for (int i = 0; i < this.dilithiumK; ++i) {
            if (this.getVectorIndex(i).checkNorm(n)) {
                return true;
            }
        }
        return false;
    }
    
    public int makeHint(final PolyVecK polyVecK, final PolyVecK polyVecK2) {
        int n = 0;
        for (int i = 0; i < this.dilithiumK; ++i) {
            n += this.getVectorIndex(i).polyMakeHint(polyVecK.getVectorIndex(i), polyVecK2.getVectorIndex(i));
        }
        return n;
    }
    
    public void useHint(final PolyVecK polyVecK, final PolyVecK polyVecK2) {
        for (int i = 0; i < this.dilithiumK; ++i) {
            this.getVectorIndex(i).polyUseHint(polyVecK.getVectorIndex(i), polyVecK2.getVectorIndex(i));
        }
    }
    
    public void shiftLeft() {
        for (int i = 0; i < this.dilithiumK; ++i) {
            this.getVectorIndex(i).shiftLeft();
        }
    }
    
    @Override
    public String toString() {
        String str = "[";
        for (int i = 0; i < this.dilithiumK; ++i) {
            str = str + i + " " + this.getVectorIndex(i).toString();
            if (i != this.dilithiumK - 1) {
                str += ",\n";
            }
        }
        return str + "]";
    }
    
    public String toString(final String str) {
        return str + ": " + this.toString();
    }
}
