⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 camelliaengine.java

📁 bouncycastle 是一个JAVA安全提供者
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    {        return BLOCK_SIZE;    }    public int processBlock(        byte[] in,        int inOff,        byte[] out,        int outOff)        throws DataLengthException, IllegalStateException    {        if (_keyIs128)        {            return processBlock128(in, inOff, out, outOff);        }        else        {            return processBlock192or256(in, inOff, out, outOff);        }    }    public void reset()    {        // nothing    }    private byte lRot8(        byte value,        int  rotation)    {        return (byte)((value << rotation) | ((value & 0xff) >>> (8 - rotation)));    }        private int lRot32(        int value,        int rotation)    {        return (value << rotation) | (value >>> (32 - rotation));    }        private long lRot128high(        long a,        long b,        int rotation)    {        if (rotation < 64)        {            a = (a << rotation) | (b >>> (64 - rotation));        }        else if (rotation == 64)        {            a = b;        }        else        {            a = (b << (rotation - 64)) | (a >>> (64 - (rotation - 64)));        }                return a;    }        private long lRot128low(        long a,        long b,        int rotation)    {        if (rotation < 64)        {            b = (b << rotation) | (a >>> (64 - rotation));        }        else if (rotation == 64)        {            b = a;        }        else        {            b = (a << (rotation - 64)) | (b >>> (64 - (rotation - 64)));        }                return b;    }        private long fl(        long in,        long ke)    {        int x1 = (int)(in >> 32);        int x2 = (int)in;        int k1 = (int)(ke >> 32);        int k2 = (int)ke;                x2 = x2 ^ lRot32((x1 & k1), 1);        x1 = x1 ^ (x2 | k2);                return ((long)x1 << 32) | (x2 & MASK32);    }    private long flInv(        long in,        long ke)    {        int y1 = (int)(in >> 32);        int y2 = (int)in;        int k1 = (int)(ke >> 32);        int k2 = (int)ke;                y1 = y1 ^ (y2 | k2);        y2 = y2 ^ lRot32((y1 & k1), 1);                return ((long)y1 << 32) | (y2 & MASK32);    }        private long f(        long in,        long ke)    {        long x;        int  a, b;        int  t1, t2, t3, t4, t5, t6, t7, t8;        int  y1, y2, y3, y4, y5, y6, y7, y8;                x  = in ^ ke;                a = (int)(x >> 32);        b = (int)x;                t1 = SBOX1[(a >> 24) & 0xff];        t2 = SBOX2[(a >> 16) & 0xff];        t3 = SBOX3[(a >>  8) & 0xff];        t4 = SBOX4[a & 0xff];        t5 = SBOX2[(b >> 24) & 0xff];        t6 = SBOX3[(b >> 16) & 0xff];        t7 = SBOX4[(b >>  8) & 0xff];        t8 = SBOX1[b & 0xff];        y1 = (t1 ^ t3 ^ t4 ^ t6 ^ t7 ^ t8);        y2 = (t1 ^ t2 ^ t4 ^ t5 ^ t7 ^ t8);        y3 = (t1 ^ t2 ^ t3 ^ t5 ^ t6 ^ t8);        y4 = (t2 ^ t3 ^ t4 ^ t5 ^ t6 ^ t7);        y5 = (t1 ^ t2 ^ t6 ^ t7 ^ t8);        y6 = (t2 ^ t3 ^ t5 ^ t7 ^ t8);        y7 = (t3 ^ t4 ^ t5 ^ t6 ^ t8);        y8 = (t1 ^ t4 ^ t5 ^ t6 ^ t7);                return ((long)y1 << 56) | (((long)y2 & MASK8) << 48) | (((long)y3 & MASK8) << 40)                 | (((long)y4 & MASK8) << 32) | (((long)y5 & MASK8) << 24) | (((long)y6 & MASK8) << 16)                 | (((long)y7 & MASK8) <<  8) | ((long)y8 & MASK8);    }    private long bytesToWord(        byte[]  src,        int     srcOff)    {        long    word = 0;        for (int i = 0; i < 8; i++)        {            word = (word << 8) + (src[i + srcOff] & 0xff);        }        return word;    }    private void wordToBytes(        long    word,        byte[]  dst,        int     dstOff)    {        for (int i = 0; i < 8; i++)        {            dst[(7 - i) + dstOff] = (byte)word;            word >>>= 8;        }    }        private int processBlock128(        byte[] in,        int inOff,        byte[] out,        int outOff)        throws DataLengthException, IllegalStateException    {        long d1 = bytesToWord(in, inOff);        long d2 = bytesToWord(in, inOff + 8);        d1 = d1 ^ _kw1;           // Prewhitening        d2 = d2 ^ _kw2;        d2 = d2 ^ f(d1, _k1);     // Round 1        d1 = d1 ^ f(d2, _k2);     // Round 2        d2 = d2 ^ f(d1, _k3);     // Round 3        d1 = d1 ^ f(d2, _k4);     // Round 4        d2 = d2 ^ f(d1, _k5);     // Round 5        d1 = d1 ^ f(d2, _k6);     // Round 6        d1 = fl   (d1, _ke1);     // FL        d2 = flInv(d2, _ke2);     // FLINV        d2 = d2 ^ f(d1, _k7);     // Round 7        d1 = d1 ^ f(d2, _k8);     // Round 8        d2 = d2 ^ f(d1, _k9);     // Round 9        d1 = d1 ^ f(d2, _k10);    // Round 10        d2 = d2 ^ f(d1, _k11);    // Round 11        d1 = d1 ^ f(d2, _k12);    // Round 12        d1 = fl   (d1, _ke3);     // FL        d2 = flInv(d2, _ke4);     // FLINV                d2 = d2 ^ f(d1, _k13);    // Round 13        d1 = d1 ^ f(d2, _k14);    // Round 14        d2 = d2 ^ f(d1, _k15);    // Round 15        d1 = d1 ^ f(d2, _k16);    // Round 16        d2 = d2 ^ f(d1, _k17);    // Round 17        d1 = d1 ^ f(d2, _k18);    // Round 18                d2 = d2 ^ _kw3;           // Postwhitening        d1 = d1 ^ _kw4;        wordToBytes(d2, out, outOff);        wordToBytes(d1, out, outOff + 8);                return BLOCK_SIZE;    }        private int processBlock192or256(        byte[] in,        int inOff,        byte[] out,        int outOff)        throws DataLengthException, IllegalStateException    {        long d1 = bytesToWord(in, inOff);        long d2 = bytesToWord(in, inOff + 8);        d1 = d1 ^ _kw1;           // Prewhitening        d2 = d2 ^ _kw2;                d2 = d2 ^ f(d1, _k1);     // Round 1        d1 = d1 ^ f(d2, _k2);     // Round 2        d2 = d2 ^ f(d1, _k3);     // Round 3        d1 = d1 ^ f(d2, _k4);     // Round 4        d2 = d2 ^ f(d1, _k5);     // Round 5        d1 = d1 ^ f(d2, _k6);     // Round 6        d1 = fl   (d1, _ke1);     // FL        d2 = flInv(d2, _ke2);     // FLINV        d2 = d2 ^ f(d1, _k7);     // Round 7        d1 = d1 ^ f(d2, _k8);     // Round 8        d2 = d2 ^ f(d1, _k9);     // Round 9        d1 = d1 ^ f(d2, _k10);    // Round 10        d2 = d2 ^ f(d1, _k11);    // Round 11        d1 = d1 ^ f(d2, _k12);    // Round 12        d1 = fl   (d1, _ke3);     // FL        d2 = flInv(d2, _ke4);     // FLINV        d2 = d2 ^ f(d1, _k13);    // Round 13        d1 = d1 ^ f(d2, _k14);    // Round 14        d2 = d2 ^ f(d1, _k15);    // Round 15        d1 = d1 ^ f(d2, _k16);    // Round 16        d2 = d2 ^ f(d1, _k17);    // Round 17        d1 = d1 ^ f(d2, _k18);    // Round 18        d1 = fl   (d1, _ke5);     // FL        d2 = flInv(d2, _ke6);     // FLINV        d2 = d2 ^ f(d1, _k19);    // Round 19        d1 = d1 ^ f(d2, _k20);    // Round 20        d2 = d2 ^ f(d1, _k21);    // Round 21        d1 = d1 ^ f(d2, _k22);    // Round 22        d2 = d2 ^ f(d1, _k23);    // Round 23        d1 = d1 ^ f(d2, _k24);    // Round 24                d2 = d2 ^ _kw3;           // Postwhitening        d1 = d1 ^ _kw4;                wordToBytes(d2, out, outOff);        wordToBytes(d1, out, outOff + 8);                return BLOCK_SIZE;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -