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

package org.bouncycastle.crypto.threshold;

class PolynomialNative extends Polynomial
{
    private final int IRREDUCIBLE;
    
    public PolynomialNative(final ShamirSecretSplitter.Algorithm algorithm) {
        switch (algorithm) {
            case AES: {
                this.IRREDUCIBLE = 283;
                break;
            }
            case RSA: {
                this.IRREDUCIBLE = 285;
                break;
            }
            default: {
                throw new IllegalArgumentException("The algorithm is not correct");
            }
        }
    }
    
    @Override
    protected byte gfMul(int n, int i) {
        int j = 0;
        while (i > 0) {
            if ((i & 0x1) != 0x0) {
                j ^= n;
            }
            n <<= 1;
            if ((n & 0x100) != 0x0) {
                n ^= this.IRREDUCIBLE;
            }
            i >>= 1;
        }
        while (j >= 256) {
            if ((j & 0x100) != 0x0) {
                j ^= this.IRREDUCIBLE;
            }
            j <<= 1;
        }
        return (byte)(j & 0xFF);
    }
    
    @Override
    protected byte gfDiv(final int n, final int n2) {
        return this.gfMul(n, this.gfPow((byte)n2, (byte)(-2)) & 0xFF);
    }
}
