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

package org.bouncycastle.crypto.engines;

import org.bouncycastle.util.Longs;
import org.bouncycastle.crypto.digests.ISAPDigest;

public class AsconPermutationFriend
{
    public static AsconPermutation getAsconPermutation(final ISAPDigest.Friend friend) {
        if (null == friend) {
            throw new NullPointerException("This method is only for use by ISAPDigest or Ascon Digest");
        }
        return new AsconPermutation();
    }
    
    public static class AsconPermutation
    {
        public long x0;
        public long x1;
        public long x2;
        public long x3;
        public long x4;
        
        AsconPermutation() {
        }
        
        public void round(final long n) {
            this.x2 ^= n;
            final long n2 = this.x0 ^ this.x4;
            final long n3 = this.x1 ^ this.x2;
            final long n4 = this.x1 | this.x2;
            final long n5 = this.x3 ^ n4 ^ this.x0 ^ (this.x1 & n2);
            final long n6 = n2 ^ (n4 | this.x3) ^ (this.x1 & this.x2 & this.x3);
            final long n7 = n3 ^ (this.x4 & ~this.x3);
            final long n8 = (this.x0 | (this.x3 ^ this.x4)) ^ n3;
            final long n9 = this.x3 ^ (this.x1 | this.x4) ^ (this.x0 & this.x1);
            this.x0 = (n5 ^ Longs.rotateRight(n5, 19) ^ Longs.rotateRight(n5, 28));
            this.x1 = (n6 ^ Longs.rotateRight(n6, 39) ^ Longs.rotateRight(n6, 61));
            this.x2 = ~(n7 ^ Longs.rotateRight(n7, 1) ^ Longs.rotateRight(n7, 6));
            this.x3 = (n8 ^ Longs.rotateRight(n8, 10) ^ Longs.rotateRight(n8, 17));
            this.x4 = (n9 ^ Longs.rotateRight(n9, 7) ^ Longs.rotateRight(n9, 41));
        }
        
        public void p(final int n) {
            if (n == 12) {
                this.round(240L);
                this.round(225L);
                this.round(210L);
                this.round(195L);
            }
            if (n >= 8) {
                this.round(180L);
                this.round(165L);
            }
            this.round(150L);
            this.round(135L);
            this.round(120L);
            this.round(105L);
            this.round(90L);
            this.round(75L);
        }
        
        public void set(final long x0, final long x2, final long x3, final long x4, final long x5) {
            this.x0 = x0;
            this.x1 = x2;
            this.x2 = x3;
            this.x3 = x4;
            this.x4 = x5;
        }
    }
}
